int main() 
{
#if DEBUG
    freopen("E:\\nyist_008.in", "r" ,stdin);
    freopen("E:\\nyist_008.out", "w", stdout);
#endif

    VR vec;
    Rect rt;
    int testCases, nNums;
    
    scanf("%d", &testCases);
    while (testCases--) {
        vec.clear();
        scanf("%d", &nNums);
        for (int i = 0; i < nNums; ++i) {
            scanf("%d %d %d", &rt.number, &rt.length, &rt.width);
            if (rt.length < rt.width)
                swap(rt.length, rt.width);
            vec.push_back(rt);
        }
        sort(vec.begin(), vec.end(), compare_1);
        
        for (VR::size_type ix = 0; ix < vec.size(); ++ix)
            printf("%d %d %d\n", vec[ix].number, vec[ix].length, vec[ix].width);
        
        unique(vec.begin(), vec.end(), compare_2);
        /*
        for (VR::size_type ix = 0; ix < vec.size(); ++ix)
            printf("%d %d %d\n", vec[ix].number, vec[ix].length, vec[ix].width);
            */
    }// End of while
    return 0;
}
Beispiel #2
0
void split_route(vector<Segment> &vs,VR &nodes,int idx, int n1, int n2){
   ParamEdge e=vs[idx].edge;
   debugline(e.from(),e.to(),255,0,0,true);
   double minp=DBL_MAX;
   int minidx=-1;
   for (int j=0,n=nodes.size();j<n;j++){
      if (j==n1 || j==n2) continue;
      if (e.cross(nodes[j])){
	 if (nodes[j].contains(e.from())) continue;
	 if (nodes[j].contains(e.to())) continue;
         double p=e.cross_param_smallest(nodes[j]);
         if (p<minp){
            minp=p;
            minidx=j;
         }
      }
   }
   if (minidx<0) return ;
   Point dc=e.dist_vec(nodes[minidx].center());
   if (dc.is_null()){
      dc=to_left(e.unit(),PI/2); // minidxust choose a side 
   }
   VP pts;
   Point r=e.dist_vec(nodes[minidx].TL());
   if (scalar(r,dc)<0) pts.push_back(nodes[minidx].TL());
   r=e.dist_vec(nodes[minidx].TR());
   if (scalar(r,dc)<0) pts.push_back(nodes[minidx].TR());
   r=e.dist_vec(nodes[minidx].BL());
   if (scalar(r,dc)<0) pts.push_back(nodes[minidx].BL());
   r=e.dist_vec(nodes[minidx].BR());
   if (scalar(r,dc)<0) pts.push_back(nodes[minidx].BR());
   if (pts.size()==0) {
      printf("Ups, no points on smaller side of edge/node cut area");
      return;
   }
   if (pts.size()>2 ) throw "expected 1 or 2 points";
   vector<Segment> vsnew;
   int idxlast=idx+1;
   if (pts.size()==1){
      vsnew.push_back(Segment(ParamEdge(e.from(),pts[0]),vs[idx].first,false));
      vsnew.push_back(Segment(ParamEdge(pts[0],e.to()),false,vs[idx].last));
   } else if (pts.size()==2) {
      if (norm(pts[0]-e.from())>norm(pts[1]-e.from())){ // do nearest point first
	swap(pts[0],pts[1]);
      }
      vsnew.push_back(Segment(ParamEdge(e.from(),pts[0]),vs[idx].first,false));
      vsnew.push_back(Segment(ParamEdge(pts[0],pts[1]),false,false));
      vsnew.push_back(Segment(ParamEdge(pts[1],e.to()),false,vs[idx].last));
      idxlast++;
   }
   vs.erase(vs.begin()+idx);
   vs.insert(vs.begin()+idx,vsnew.begin(),vsnew.end());
   split_route(vs,nodes,idxlast,minidx,n2);
   split_route(vs,nodes,idx,n1,minidx); // new overlaps could be introduced after makeing a kink into the line
}
static BOOL
LoadImplicitLittleEndian(DICOMDataObject* pDDO, CBufferedIO* pBufferedIO,
	int handle, unsigned int iVrSizeLimit)
{
	DICOMDataObject*	pNewDDO;
	VR*					pVR;
	char				Buf[2 + 2 + 4];

	while (pBufferedIO->read(handle, Buf, sizeof(Buf)) == sizeof(Buf))
	{
		/* Group, Element and Size could be read */
		pVR = new VR;
		if (!pVR)
			return FALSE;
#if NATIVE_ENDIAN == LITTLE_ENDIAN //Little Endian
		pVR->Group   = *((unsigned short*) Buf);
		pVR->Element = *((unsigned short*)(Buf + 2));
		pVR->Length  = *((unsigned int*)  (Buf + 2 + 2));
#else //Big Endian like Apple power pc
		pVR->Group   = SwitchEndian( *((UINT16*) Buf));
		pVR->Element = SwitchEndian( *((UINT16*)(Buf + 2)));
		pVR->Length  = SwitchEndian( *((UINT32*)  (Buf + 2 + 2)));
#endif //Big Endian

		if (pVR->Group == 0xfffe)
		{
			/* A deliminator */
			if ((pVR->Element == 0xe0dd) || (pVR->Element == 0xe00d))
			{
				delete pVR;
				return TRUE;
			}
			if (pVR->Length == 0xffffffff)
			{
				/* Implicit length... Go until deliminator */
				pVR->Length = 0;
				delete pVR;
				pNewDDO = new DICOMDataObject;
				if (LoadImplicitLittleEndian(pNewDDO, pBufferedIO, handle, iVrSizeLimit))
				{
					pDDO->Push(pNewDDO);
					continue;
				}
				else
				{
					delete pNewDDO;
					return FALSE;
				}
			}
			if (pVR->Element == 0xe000)
			{
				/* Sequence begin ? */
				pVR->Length = 0;
				delete pVR;
				pNewDDO = new DICOMDataObject;
				if (LoadImplicitLittleEndian(pNewDDO, pBufferedIO, handle, iVrSizeLimit))
				{
					pDDO->Push(pNewDDO);
					continue;
				}
				else
				{
					delete pNewDDO;
					return FALSE;
				}
			}
		}
		if (pVR->Length == 0xffffffff)
		{
			pVR->Length = 0;
			pDDO->Push(pVR);
			if (!LoadImplicitLittleEndian(pDDO, pBufferedIO, handle, iVrSizeLimit))
				return FALSE;
			continue;
		}
		/* Check whether the current VR has to be read.
		   NKI DicomNodes can restrict what has to be read
		   Following code assumes that reading is finished when pixeldata
		   are encountered. (Maybe a problem here!!!)
		*/
		if (pVR->Length > iVrSizeLimit)
		{
			if (((pVR->Group == 0x7fdf) || (pVR->Group == 0x7fe0)) &&
				(pVR->Element == 0x0010))
			{
				/* Ready !? */
				pVR->Length = 0;
				delete pVR;
				return TRUE;
			}
			else
			{	/* Read it, throw it away and continue */
//				pVR->Data = new char [pVR->Length];
				pVR->ReAlloc(pVR->Length);
				if (!pVR->Data)
					return FALSE;
				pBufferedIO->read(handle, pVR->Data, pVR->Length);
				delete pVR;
				continue;
			}
		}
		if (pVR->Length)
		{
//			pVR->Data = new char [pVR->Length];
			pVR->ReAlloc(pVR->Length);
			if (!pVR->Data)
				return FALSE;
			pBufferedIO->read(handle, pVR->Data, pVR->Length);
		}
		else
			pVR->Data = NULL;
		pDDO->Push(pVR);
	}
	return TRUE;
}
Beispiel #4
0
void route_edges2(Layouter &state,plugin& pg, double scale, int iter, double temp, int debug){
   VR nodes;
   double d=state.avgsize/5;
   int n=state.nw.nodes.size();
   for (int i=0;i<n;i++){
      nodes.push_back(state.nw.nodes[i].rect());
      nodes.back().extend(d);
      //debugrect(nodes.back(),0,0,255);
   }
   for (int i=0,m=state.nw.edges.size();i<m;i++){
      //if (i!=iter) continue;
      Edge &e=state.nw.edges[i];
      e.splinehandles.clear();
      e.splinepoints.clear();
      int n1=e.from;
      int n2=e.to;
      Point vec,p1,p2;
      double dir;
      switch(e.type){
         case substrate:
            dir=lim(state.nw.nodes[n1].dir+PI/2);
            vec=Point(dir);
            swap(n1,n2);
            p1=state.nw.nodes[n1];
            vec=state.nw.nodes[n2].rect().border_vec(vec);
            p2=state.nw.nodes[n2]+vec;
            break;
         case product:
            dir=lim(state.nw.nodes[n1].dir-PI/2);
            vec=Point(dir);
            vec=state.nw.nodes[n1].rect().border_vec(vec);
            p1=state.nw.nodes[n1]+vec;
            p2=state.nw.nodes[n2];
            break;
         case activator:
         case inhibitor:
         case catalyst:
            swap(n1,n2);
         default:
            p1=state.nw.nodes[n1];
            p2=state.nw.nodes[n2];
      }
      vector<Segment> vs;
      vs.push_back(Segment(ParamEdge(p1,p2),true,true));
      split_route(vs,nodes,0,n1,n2);
      Point vec1=state.nw.nodes[n1].rect().border_vec(vs.front().edge.to()-vs.front().edge.from());
      Point vec2=state.nw.nodes[n2].rect().border_vec(vs.back().edge.from()-vs.back().edge.to());
      switch(e.type){
         case activator:
         case inhibitor:
         case catalyst:
            dir=lim(state.nw.nodes[n2].dir);
            if (scalar(Point(dir),vs.back().edge.from()-vs.back().edge.to())<0) dir=lim(dir+PI);
            vec=Point(dir);
            vec=state.nw.nodes[n2].rect().border_vec(vec);
            p2=state.nw.nodes[n2]+vec;
         case substrate:
            e.splinehandles.push_back(vec1+d);
            e.splinehandles.push_back(vec+d);
            break;
         case product:
            e.splinehandles.push_back(vec+d);
            e.splinehandles.push_back(vec2+d);
            break;
         default:
            e.splinehandles.push_back(vec1+d);
            e.splinehandles.push_back(vec2+d);
      }
      for (int j=1,s=vs.size();j<s;j++){
         Point before=vs[j-1].edge.from();
         Point cur=vs[j-1].edge.to();
         //if (cur!=vs[j].edge.from()) throw "ups: edge segments not continious";
         Point after=vs[j].edge.to();
         Point dv=unit(before-cur)*d+unit(after-cur)*d;
	 debugline(cur,cur+dv,0,255,0,true);
         e.splinehandles.insert(--e.splinehandles.end(),unit(to_left(dv,PI/2))*sign(scalar(to_left(dv,PI/2),before-cur))*d);
         e.splinepoints.push_back(cur+dv);
      }
   }
}
static BOOL
OrgLoadImplicitLittleEndian(DICOMDataObject* pDDO, FILE* fp, unsigned int iVrSizeLimit)
{
	DICOMDataObject*	pNewDDO;
	VR*					pVR;
	char				Buf[2 + 2 + 4];

	while (fread(Buf, 1, sizeof(Buf), fp) == sizeof(Buf))
	{
		/* Group, Element and Size could be read */
		pVR = new VR;
		if (!pVR)
			return FALSE;
#if NATIVE_ENDIAN == LITTLE_ENDIAN //Little Endian
		pVR->Group   = *((unsigned short*) Buf);
		pVR->Element = *((unsigned short*)(Buf + 2));
		pVR->Length  = *((unsigned int*)  (Buf + 2 + 2));
#else //Big Endian like Apple power pc
		pVR->Group   = SwitchEndian( *((UINT16*) Buf));
		pVR->Element = SwitchEndian( *((UINT16*)(Buf + 2)));
		pVR->Length  = SwitchEndian( *((UINT32*)  (Buf + 2 + 2)));
#endif //Big Endian

		if (pVR->Group == 0xfffe)
		{
			/* A deliminator */
			if ((pVR->Element == 0xe0dd) || (pVR->Element == 0xe00d))
			{
				delete pVR;
				return TRUE;
			}
			if (pVR->Length == 0xffffffff)
			{
				/* Implicit length... Go until deliminator */
				pVR->Length = 0;
				delete pVR;
				pNewDDO = new DICOMDataObject;
				if (OrgLoadImplicitLittleEndian(pNewDDO, fp, iVrSizeLimit))
				{
					pDDO->Push(pNewDDO);
					continue;
				}
				else
				{
					delete pNewDDO;
					return FALSE;
				}
			}
			if (pVR->Element == 0xe000)
			{
				/* Sequence begin ? */
				pVR->Length = 0;
				delete pVR;
				pNewDDO = new DICOMDataObject;
				if (OrgLoadImplicitLittleEndian(pNewDDO, fp, iVrSizeLimit))
				{
					pDDO->Push(pNewDDO);
					continue;
				}
				else
				{
					delete pNewDDO;
					return FALSE;
				}
			}
		}
		if (pVR->Length == 0xffffffff)
		{
			pVR->Length = 0;
			pDDO->Push(pVR);
			if (!OrgLoadImplicitLittleEndian(pDDO, fp, iVrSizeLimit))
				return FALSE;
			continue;
		}
		/* Check whether the current VR has to be read.
		   NKI DicomNodes can restrict what has to be read
		   Following code assumes that reading is finished when pixeldata
		   are encountered. (Maybe a problem here!!!)
		*/
		if (pVR->Length > iVrSizeLimit)
		{
			if (((pVR->Group == 0x7fdf) || (pVR->Group == 0x7fe0)) &&
				(pVR->Element == 0x0010))
			{
				/* Ready !? */
				pVR->Length = 0;
				delete pVR;
				return TRUE;
			}
			else
			{	/* Read it, throw it away and continue */
//				pVR->Data = new char [pVR->Length];
				pVR->ReAlloc(pVR->Length);
				if (!pVR->Data)
					return FALSE;
				fread(pVR->Data, 1, pVR->Length, fp);
				delete pVR;
				continue;
			}
		}
		if (pVR->Length)
		{
//			pVR->Data = new char [pVR->Length];
			pVR->ReAlloc(pVR->Length);
			if (!pVR->Data)
				return FALSE;
			fread(pVR->Data, 1, pVR->Length, fp);
/*			if ((pVR->Group == 0x7fdf) && (pVR->Element == 0x0010))
			{ 
				VR* v;
				signed char *CompressedData = ((signed char *)(pVR->Data));
				int UncompressedLength = get_nki_private_decompressed_length(CompressedData);
				v = new VR(0x7fe0, 0x0010, UncompressedLength, TRUE);
     				nki_private_decompress((short *)(v->Data), CompressedData);
				delete pVR;
				pVR = v;
			}
*/		}
		else
			pVR->Data = NULL;
		pDDO->Push(pVR);
	}
	return TRUE;
}