Esempio n. 1
0
boolean ScanCellBox(IntPoint3 *vn, IntPoint3 *vp, Point3 *v,
	struct argGroup* args, int *index,float *MinRadius)
{
 Face *f = args->f;
 Line *Lc = args->Lc;
 Plane *p = args->p;
 UG *G  = args->G;
 int i,j,k;
 int CellIndex;
 Plist *P;
 Plane Mp;
 Point3 c;
 float Radius;
 int indpnt=-1;
 boolean Found=FALSE;

 for(i=vn->x; i<=vp->x; i++)
   for(j=vn->y; j<=vp->y; j++)
     for(k=vn->z; k<=vp->z; k++)
	{
	 CellIndex = i + j*G->x + k*G->y*G->x;
	 if(!UGIsMarked(G,CellIndex))
	   {
	    UGMark(G,CellIndex);
	    P=G->C[CellIndex];
	    while(P)
	      {
	       indpnt=P->p;
	       if(G->UsedPoint[indpnt]!=0)
	       if((indpnt!=f->v[0]) &&
		  (indpnt!=f->v[1]) &&
		  (indpnt!=f->v[2]) &&
		   RightSide(p,&(v[indpnt])) )
		   {
		    CalcMiddlePlane(&(v[indpnt]),&(v[f->v[0]]),&Mp);
		    if(CalcLinePlaneInter(Lc,&Mp,&c))
		      {
			Radius=V3SquaredDistanceBetween2Points(&c, &(v[indpnt]));
			if(!RightSide(p,&c)) Radius=-Radius;

			if(Radius==*MinRadius) Error("Cinque punti cocircolari!!\n",EXIT);
			if(Radius<*MinRadius)
				{
				 *MinRadius=Radius;
				 *index=indpnt;
				 Found=TRUE;
				}

		      }
		   }
	       P=P->next;
	      }  /* end while	     */
	   }	 /* end if !IsMarked */
	}	 /* end for	     */


 return Found;
}
Esempio n. 2
0
Tetra *MakeTetra(Face *f,Point3 *v[], int n)
{
 Plane p,Mp;
 boolean found=FALSE;
 double Radius=BIGNUMBER,  rad;
 Line Lc;
 int pind=0;
 Tetra *t;
 Point3 Center, c;
 int i;

 if(!CalcPlane(f->v[0],f->v[1],f->v[2],&p))
		Error("MakeTetra, Face with collinar vertices!\n",EXIT);

 CalcLineofCenter(f->v[0],f->v[1],f->v[2],&Lc);

 for(i=0;i<n;i++)
 {
  if((v[i]!=f->v[0]) &&
     (v[i]!=f->v[1]) &&
     (v[i]!=f->v[2]) &&
     RightSide(&p,v[i]) )
		{
		 CalcMiddlePlane(v[i],f->v[0],&Mp);
		 if(CalcLinePlaneInter(&Lc,&Mp,&c))
		      {
			rad=V3SquaredDistanceBetween2Points(&c, v[i]);

			if(!RightSide(&p,&c)) rad=-rad;
			if(rad==Radius) Error("MakeTetra, Five cocircular points!\n",EXIT);
			if(rad<Radius)
				{
				 found=TRUE;
				 Radius=rad;
				 Center=c;
				 pind=i;
				}
		      }
		}
 }

 if(!found) return NULL;

 t=BuildTetra(f,v[pind]);

 if(CheckFlag)	CheckTetra(t,v,n);

 if(StatFlag)
 {Point3 C;
  CalcSphereCenter(f->v[0], f->v[1], f->v[2], v[pind], &C);
  SI.Radius+=V3DistanceBetween2Points(&C, v[pind]);
 }

 return t;
}
int Intersect(Face *f, Plane *p)
{
 boolean v1,v2,v3;

 v1=RightSide(p,f->v[0]);
 v2=RightSide(p,f->v[1]);

 if(v1!=v2) return 0;

 v3=RightSide(p,f->v[2]);

 if(v1!=v3) return 0;
     else     if(v1) return  1;
		else return -1;

}
KnotVector splineknots::CurveDeboorKnotsGenerator::
GenerateKnots(const SurfaceDimension& dimension, double* calculation_time)
{
	StopWatch sw;
	
	KnotVector knots(dimension.knot_count);
	InitializeKnots(dimension, knots);
	auto dfirst = function_.Dx()(dimension.min, 0);
	auto dlast = function_.Dx()(dimension.max, 0);
	KnotVector result(knots.size());

	sw.Start();
	RightSide(knots, abs(dimension.max - dimension.min)
		/ (dimension.knot_count - 1), dfirst, dlast);
	
	auto& rhs = tridiagonal_.Solve(dimension.knot_count-2);
	result[0] = dfirst;
	result[result.size() - 1] = dlast;
	memcpy(&result.front() + 1, &rhs.front(), rhs.size());
	sw.Stop();
	
	if (calculation_time != nullptr)
	{
		*calculation_time = sw.EllapsedTime();
	}
	return result;
}
Esempio n. 5
0
ExpressionTreeElement* ExpressionParser::BuildValueElement(const wchar_t* input)
{
    if (!input || wcslen(input) == 0)
        return NULL;

    ExpressionTreeElement* tmp = new ExpressionTreeElement();

    // integer type
    if (IsNumeric(input))
    {
        tmp->valueType = VT_INTEGER;
        tmp->value.asLong = ToInt(input);
        return tmp;
    }

    // floating type
    wchar_t *left = NULL, *right = NULL;
    left = LeftSide(input, L'.');
    right = RightSide(input, L'.');

    if (left && right && IsNumeric(left) && IsNumeric(right))
    {
        tmp->valueType = VT_FLOAT;
        tmp->value.asDouble = atof(ToMultiByteString(input));
        return tmp;
    }

    // if it doesn't fit our defined integer or float pattern, let's call it string
    tmp->valueType = VT_STRING;
    tmp->value.asString = (wchar_t*)input;
    return tmp;
}
Esempio n. 6
0
boolean ExaminableCell(int x, int y, int z, Plane *p, UG *c)
{
 Point3 UGVertex;

 if(p->N.x>0) x++;
 if(p->N.y>0) y++;
 if(p->N.z>0) z++;

 UGVertex.x=x*c->side+c->vn.x;
 UGVertex.y=y*c->side+c->vn.y;
 UGVertex.z=z*c->side+c->vn.z;

 return RightSide(p, &UGVertex);

}
Esempio n. 7
0
Tetra *FirstTetra(Point3 *v[], int n)
{
 int i, MinIndex=0;
 double Radius, MinRadius=BIGNUMBER;

 Tetra *t;
 Plane p[3], Mp;
 Line Lc;
 Face f;
 Point3 c;

 boolean found=FALSE;

 f.v[0]=v[n/2-1];	/* The first point of the face is the	*/
			/* nearest to middle plane in negative	*/
			/* halfspace.				*/

			/* The 2nd point of the face is the	*/
			/* euclidean nearest to first point	*/
 for(i=n/2;i<n;i++)	/* that is in the positive halfspace	*/
    {
     Radius=V3SquaredDistanceBetween2Points(f.v[0], v[i]);
     if(Radius<MinRadius)
	{
	 MinRadius=Radius;
	 MinIndex=i;
	}
    }

 f.v[1]=v[MinIndex];
			/* The 3rd point is that with previous	*/
			/* ones builds the smallest circle.	*/

 CalcMiddlePlane(f.v[0],f.v[1], &(p[0]));

 MinRadius=BIGNUMBER;

 for(i=0;i<n;i++)
  if(v[i]!=f.v[0] && v[i]!=f.v[1])
   {
    CalcMiddlePlane(f.v[0], v[i],&(p[1]));
    if(CalcPlane(f.v[0],f.v[1],v[i],&(p[2])))
      if(CalcPlaneInter(&(p[0]), &(p[1]), &(p[2]), &c))
	{
	 Radius=V3DistanceBetween2Points(&c, f.v[0]);
	  if(Radius<MinRadius)
		{
		 MinRadius=Radius;
		 MinIndex=i;
		}
	}
   }

 f.v[2]=v[MinIndex];


 /* The first tetrahedron construction is analogous to normal */
 /* MakeTetra, only we dont limit search to an halfspace.     */

 MinRadius=BIGNUMBER;

 CalcPlane(f.v[0], f.v[1], f.v[2],&p[0]);
 CalcLineofCenter(f.v[0], f.v[1], f.v[2], &Lc);

 for(i=0;i<n;i++)
  if(v[i]!=f.v[0] && v[i]!=f.v[1] && v[i]!=f.v[2] )
   {
    CalcMiddlePlane(v[i], f.v[0], &Mp);
    if(CalcLinePlaneInter(&Lc, &Mp, &c))
	 {
	   Radius=V3SquaredDistanceBetween2Points(&c, v[i]);

	   if(MinRadius==Radius) Error("FirstTetra, Five cocircular points!\n",EXIT);
	   if(Radius<MinRadius)
		   {
		    found=TRUE;
		    MinRadius=Radius;
		    MinIndex=i;
		   }
	 }
   }

 if(!found) Error("FirstTetra, Planar dataset, unable to build first tetrahedron.\n",EXIT);

 if(!RightSide(&p[0],v[MinIndex]))	ReverseFace(&f);

 t=BuildTetra(&f, v[MinIndex]);

 CheckTetra(t,v,n);

 ReverseFace(t->f[0]); /* First Face in first Tetra   */
		       /* must be outward oriented    */
 return t;

}
Esempio n. 8
0
void MergePatternsAntiPar(STRIDE_PATTERN **Pat, int NPat)
{
  register int i, j;
  int DB, DW, MinDB1, MinDB2, MinDW1, MinDW2, Min, Lnk1A, Lnk1D;
  int I1A, I1D, I2A, I2D, J1A, J1D, J2A, J2D;
  char I1ACn, I1DCn, I2ACn, I2DCn, J1ACn, J1DCn, J2ACn, J2DCn;

  for( i=0; i<NPat; i++ ) {

    if( !Pat[i]->ExistPattern ) continue;

    MinDB1 = MinDB2 = MinDW1 = MinDW2 = 1000;
    Min = ERR;
    Lnk1D = Lnk1A = ERR;

    Alias(&I1D,&I1A,&I2D,&I2A,&I1DCn,&I1ACn,&I2DCn,&I2ACn,Pat[i]);

    for( j=0; j<NPat; j++ ) {

      if( i == j || !Pat[j]->ExistPattern ) continue;

      Alias(&J1D,&J1A,&J2D,&J2A,&J1DCn,&J1ACn,&J2DCn,&J2ACn,Pat[j]);
      
      if( Near(I1D,J1D,J1A,I1A,J2A,J2D,I2A,I2D,I1DCn,J1DCn,J1ACn,I1ACn,&DB,&DW) && 
	  ((DB < MinDB1 && DW <= MinDW1) || (DB <= MinDB1 && DW < MinDW1) ) && 
	 RightSide(J1A,J1D,I1A,I1D,I2A,I2D) )
	JoinNeighbours(&Lnk1A,J2D,&Lnk1D,J2A,&Pat[i]->Nei1,Pat[j],&MinDB1,DB,&MinDW1,DW,&Min,j);

      if( Near(I1D,J1A,J1D,I1A,J2D,J2A,I2A,I2D,I1DCn,J1ACn,J1DCn,I1ACn,&DB,&DW) && 
	  ((DB < MinDB1 && DW <= MinDW1) || (DB <= MinDB1 && DW < MinDW1) ) && 
	 RightSide(J1D,J1A,I1A,I1D,I2A,I2D) )
	JoinNeighbours(&Lnk1A,J2A,&Lnk1D,J2D,&Pat[i]->Nei1,Pat[j],&MinDB1,DB,&MinDW1,DW,&Min,j);

      if( Near(I1D,J2D,J2A,I1A,J1A,J1D,I2A,I2D,I1DCn,J2DCn,J2ACn,I1ACn,&DB,&DW) && 
	  ((DB < MinDB1 && DW <= MinDW1) || (DB <= MinDB1 && DW < MinDW1) ) && 
	 RightSide(J2A,J2D,I1A,I1D,I2A,I2D) )
	JoinNeighbours(&Lnk1A,J1D,&Lnk1D,J1A,&Pat[i]->Nei1,Pat[j],&MinDB1,DB,&MinDW1,DW,&Min,j);

      if( Near(I1D,J2A,J2D,I1A,J1D,J1A,I2A,I2D,I1DCn,J2ACn,J2DCn,I1ACn,&DB,&DW) && 
	  ((DB < MinDB1 && DW <= MinDW1) || (DB <= MinDB1 && DW < MinDW1) ) && 
	 RightSide(J2D,J2A,I1A,I1D,I2A,I2D) )
	JoinNeighbours(&Lnk1A,J1A,&Lnk1D,J1D,&Pat[i]->Nei1,Pat[j],&MinDB1,DB,&MinDW1,DW,&Min,j);

      if( Near(I1A,J1D,J1A,I1D,J2A,J2D,I2D,I2A,I1ACn,J1DCn,J1ACn,I1DCn,&DB,&DW) && 
	  ((DB < MinDB1 && DW <= MinDW1) || (DB <= MinDB1 && DW < MinDW1) ) && 
	 RightSide(J1A,J1D,I1A,I1D,I2A,I2D) )
	JoinNeighbours(&Lnk1A,J2A,&Lnk1D,J2D,&Pat[i]->Nei1,Pat[j],&MinDB1,DB,&MinDW1,DW,&Min,j);

      if( Near(I1A,J1A,J1D,I1D,J2D,J2A,I2D,I2A,I1ACn,J1ACn,J1DCn,I1DCn,&DB,&DW) && 
	  ((DB < MinDB1 && DW <= MinDW1) || (DB <= MinDB1 && DW < MinDW1) ) && 
	 RightSide(J1A,J1D,I1A,I1D,I2A,I2D) )
	JoinNeighbours(&Lnk1A,J2D,&Lnk1D,J2A,&Pat[i]->Nei1,Pat[j],&MinDB1,DB,&MinDW1,DW,&Min,j);

      if( Near(I1A,J2D,J2A,I1D,J1A,J1D,I2D,I2A,I1ACn,J2DCn,J2ACn,I1DCn,&DB,&DW) && 
	  ((DB < MinDB1 && DW <= MinDW1) || (DB <= MinDB1 && DW < MinDW1) ) && 
	 RightSide(J2D,J2A,I1A,I1D,I2A,I2D) )
	JoinNeighbours(&Lnk1A,J1A,&Lnk1D,J1D,&Pat[i]->Nei1,Pat[j],&MinDB1,DB,&MinDW1,DW,&Min,j);

      if( Near(I1A,J2A,J2D,I1D,J1D,J1A,I2D,I2A,I1ACn,J2ACn,J2DCn,I1DCn,&DB,&DW) && 
	  ((DB < MinDB1 && DW <= MinDW1) || (DB <= MinDB1 && DW < MinDW1) ) && 
	 RightSide(J2A,J2D,I1A,I1D,I2A,I2D) )
	JoinNeighbours(&Lnk1A,J1D,&Lnk1D,J2D,&Pat[i]->Nei1,Pat[j],&MinDB1,DB,&MinDW1,DW,&Min,j);

    }

    for( j=0; j<NPat; j++ ) {

      if( j == Min || j == i || !Pat[j]->ExistPattern ) continue;

      Alias(&J1D,&J1A,&J2D,&J2A,&J1DCn,&J1ACn,&J2DCn,&J2ACn,Pat[j]);

      if( Near(I2D,J1D,J1A,I2A,J2A,J2D,I1A,I1D,I2DCn,J1DCn,J1ACn,I2ACn,&DB,&DW) && 
	  (( DB < MinDB2 && DW <= MinDW2) || (DB <= MinDB2 && DW < MinDW2) ) &&
	 RightSide2(Lnk1A,Lnk1D,J2A,J2D,I1A,I1D,I2A,I2D) )
	JoinNeighb(&Pat[i]->Nei2,Pat[j],&MinDB2,DB,&MinDW2,DW);
      
      if( Near(I2D,J1A,J1D,I2A,J2D,J2A,I1A,I1D,I2DCn,J1ACn,J1DCn,I2ACn,&DB,&DW) && 
	  (( DB < MinDB2 && DW <= MinDW2) || (DB <= MinDB2 && DW < MinDW2) ) &&
	 RightSide2(Lnk1A,Lnk1D,J2D,J2A,I1A,I1D,I2A,I2D) )
	JoinNeighb(&Pat[i]->Nei2,Pat[j],&MinDB2,DB,&MinDW2,DW);
      
      if( Near(I2D,J2D,J2A,I2A,J1A,J1D,I1A,I1D,I2DCn,J2DCn,J2ACn,I2ACn,&DB,&DW) && 
	  (( DB < MinDB2 && DW <= MinDW2) || (DB <= MinDB2 && DW < MinDW2) ) &&
	 RightSide2(Lnk1A,Lnk1D,J1A,J1D,I1A,I1D,I2A,I2D) ) 
	JoinNeighb(&Pat[i]->Nei2,Pat[j],&MinDB2,DB,&MinDW2,DW);
      
      if( Near(I2D,J2A,J2D,I2A,J1D,J1A,I1A,I1D,I2DCn,J2ACn,J2DCn,I2ACn,&DB,&DW) && 
	  (( DB < MinDB2 && DW <= MinDW2) || (DB <= MinDB2 && DW < MinDW2) ) &&
	 RightSide2(Lnk1A,Lnk1D,J1D,J1A,I1A,I1D,I2A,I2D) )
	JoinNeighb(&Pat[i]->Nei2,Pat[j],&MinDB2,DB,&MinDW2,DW);
      
      if( Near(I2A,J1D,J1A,I2D,J2A,J2D,I1D,I1A,I2ACn,J1DCn,J1ACn,I2DCn,&DB,&DW) && 
	  (( DB < MinDB2 && DW <= MinDW2) || (DB <= MinDB2 && DW < MinDW2) ) &&
	 RightSide2(Lnk1A,Lnk1D,J2D,J2A,I1A,I1D,I2A,I2D) )
	JoinNeighb(&Pat[i]->Nei2,Pat[j],&MinDB2,DB,&MinDW2,DW);
      
      if( Near(I2A,J1A,J1D,I2D,J2D,J2A,I1D,I1A,I2ACn,J1ACn,J1DCn,I2DCn,&DB,&DW) && 
	  (( DB < MinDB2 && DW <= MinDW2) || (DB <= MinDB2 && DW < MinDW2) ) &&
	 RightSide2(Lnk1A,Lnk1D,J2A,J2D,I1A,I1D,I2A,I2D) )
	JoinNeighb(&Pat[i]->Nei2,Pat[j],&MinDB2,DB,&MinDW2,DW);
      
      if( Near(I2A,J2D,J2A,I2D,J1A,J1D,I1D,I1A,I2ACn,J2DCn,J2ACn,I2DCn,&DB,&DW) && 
	  (( DB < MinDB2 && DW <= MinDW2) || (DB <= MinDB2 && DW < MinDW2) ) &&
	 RightSide2(Lnk1A,Lnk1D,J1D,J1A,I1A,I1D,I2A,I2D) )
	JoinNeighb(&Pat[i]->Nei2,Pat[j],&MinDB2,DB,&MinDW2,DW);
      
      if( Near(I2A,J2A,J2D,I2D,J1D,J1A,I1D,I1A,I2ACn,J2ACn,J2DCn,I2DCn,&DB,&DW) && 
	  (( DB < MinDB2 && DW <= MinDW2) || (DB <= MinDB2 && DW < MinDW2) ) &&
	 RightSide2(Lnk1A,Lnk1D,J1A,J1D,I1A,I1D,I2A,I2D) )
	JoinNeighb(&Pat[i]->Nei2,Pat[j],&MinDB2,DB,&MinDW2,DW);
      }
  }
}
Esempio n. 9
0
boolean MakeLastScan(IntPoint3 *Start, IntPoint3 *End, IntPoint3 *Inc, Point3 *v,
	 struct argGroup* args, int *index, float *MinRadius)
{

 Face *f = args->f;
 Line *Lc = args->Lc;
 Plane *p = args->p;
 UG *G  = args->G;
 
 int i,j,k;
 int CellIndex;
 Plist *P;
 Plane Mp;
 Point3 c;
 float Radius;
 int indpnt=-1;

 for(i=Start->x; Inc->x*i <= Inc->x*End->x; i+=Inc->x)
   {
   // printf("LastScan cell x=%d\n",i);
    if(!ExaminableCell(i,Start->y,Start->z,p,G)) i=End->x;
    else for(j=Start->y; Inc->y*j<=Inc->y*End->y; j+=Inc->y)
	  {
//	   printf("LastScan cell y=%d\n",j);
	   if(!ExaminableCell(i,j,Start->z,p,G)) j=End->y;
	   else for(k=Start->z; Inc->z*k<=Inc->z*End->z; k+=Inc->z)
		 {
//		  printf("LastScan cell z=%d\n",k);
		  if(!ExaminableCell(i,j,k,p,G)) k=End->z;
		  else
		   {
		    CellIndex = i + j*G->x + k*G->y*G->x;
		    if(!UGIsMarked(G, CellIndex))
			{
			P=G->C[CellIndex];
//			printf("LastScan found cell x=%d y=%d z=%d\n",i,j,k);
			while(P)
			 {
			  indpnt=P->p;
		//	  printf("LastScan indpnt is: %d\n",indpnt);
			  if((indpnt!=f->v[0]) &&
			     (indpnt!=f->v[1]) &&
			     (indpnt!=f->v[2]) &&
			     RightSide(p,&(v[indpnt])) )
			   {
			    CalcMiddlePlane(&(v[indpnt]),&(v[f->v[0]]),&Mp);
			    if(CalcLinePlaneInter(Lc,&Mp,&c))
			     {
			      Radius=V3SquaredDistanceBetween2Points(&c, &(v[indpnt]));
//			      printf("LastScan Radius: %f\n",Radius);
			      if(!RightSide(p,&c)) Radius=-Radius;
			      if(Radius==*MinRadius) Error("Cinque punti cocircolari!!\n",EXIT);
			      if(Radius<*MinRadius)
				{
//				 printf("LastScan found Radius: %f\n",Radius);
				 *MinRadius=Radius;
				 *index=indpnt;
				}
			     }
			   }
			  P=P->next;
			 }   /* end while		  */
			}    /* end if IsMarked		  */
		   }	     /* end if examinable	  */
		 }  /* end for k      */
	  }	    /* end for j      */
   }		    /* end for i      */

 if(*index==-1) return FALSE;

 return TRUE;
}