Пример #1
0
int UVW_ChannelClass::EdgeIntersect(Point3 p, float threshold, int i1,int i2)
{

 static int startEdge = 0;
 if (startEdge >= ePtrList.Count()) startEdge = 0;
 if (ePtrList.Count() == 0) return -1;

 int ct = 0;
 BOOL done = FALSE;


 int hitEdge = -1;
 while (!done) 
	{
 //check bounding volumes

	Box3 bounds;
	bounds.Init();

	int index1 = ePtrList[startEdge]->a;
	int index2 = ePtrList[startEdge]->b;
	if (v[index1].IsHidden() && v[index2].IsHidden())
		{
		}
	else if (v[index1].IsFrozen() && v[index1].IsFrozen()) 
		{
		}
	else
		{
		Point3 p1(0.0f,0.0f,0.0f);
		p1[i1] = v[index1].GetP()[i1];
		p1[i2] = v[index1].GetP()[i2];
//		p1.z = 0.0f;
		bounds += p1;
		Point3 p2(0.0f,0.0f,0.0f);
		p2[i1] = v[index2].GetP()[i1];
		p2[i2] = v[index2].GetP()[i2];
//		p2.z = 0.0f;
		bounds += p2;
		bounds.EnlargeBy(threshold);
		if (bounds.Contains(p))
			{
//check edge distance
			if (LineToPoint(p, p1, p2) < threshold)
				{
				hitEdge = startEdge;
				done = TRUE;
//				LineToPoint(p, p1, p2);
				}
			}
		}
 	ct++;
	startEdge++;
	if (ct == ePtrList.Count()) done = TRUE;
	if (startEdge >= ePtrList.Count()) startEdge = 0;
	}
 
 return hitEdge;
}
Пример #2
0
void
UniformGrid::ClosestPoint(Point3 p, float radius, int &pindex, float &d)
{
	xHitList.ClearAll();
	yHitList.ClearAll();
	zHitList.ClearAll();
	hitList.SetCount(0);

	//find the cell in the XGrid
	TagCells(p,radius, 0);
	//find the cell in the YGrid
	TagCells(p,radius, 1);
	//find the cell in the ZGrid
	TagCells(p,radius, 2);

	BitArray usedList;
	usedList.SetSize(pointBase.Count());
	usedList.ClearAll();

	int closest = -1;
	d = 0.0f;
	Box3 localBounds;
	localBounds.Init();
	localBounds += p;
	localBounds.EnlargeBy(radius);


	for (int i = 0; i < hitList.Count(); i++)
	{
		int index = hitList[i];
		if (!usedList[index])  //check to see if we have processed this one or not
		{
			if (xHitList[index] && yHitList[index] && zHitList[index])
			{
				usedList.Set(index);
				Point3 source = pointBase[index];
				if (localBounds.Contains(source))
				{
					float dist = LengthSquared(source-p);
					if ((dist < d) || (closest == -1))
					{
						d = dist;
						closest = index;
					}
				}
			}
		}
	}
	pindex = closest;
	d = sqrt(d);


}
Пример #3
0
void
UniformGrid::InRadius(Point3 p,  Tab<int> &indexList)
{
	float radius = largestRadius;
	xHitList.ClearAll();
	yHitList.ClearAll();
	zHitList.ClearAll();
	hitList.SetCount(0);

	//find the cell in the XGrid
	TagCells(p,radius, 0);
	//find the cell in the YGrid
	TagCells(p,radius, 1);
	//find the cell in the ZGrid
	TagCells(p,radius, 2);

	BitArray usedList;
	usedList.SetSize(pointBase.Count());
	usedList.ClearAll();

	int closest = -1;
	float d = 0.0f;
	Box3 localBounds;
	localBounds.Init();
	localBounds += p;
	localBounds.EnlargeBy(radius);


	for (int i = 0; i < hitList.Count(); i++)
	{
		int index = hitList[i];
		if (!usedList[index])  //check to see if we have processed this one or not
		{
			if (xHitList[index] && yHitList[index] && zHitList[index])
			{
				usedList.Set(index);
				Point3 source = pointBase[index];
				if (localBounds.Contains(source))
				{
					indexList.Append(1,&index,1000);

				}
			}
		}
	}

}
Пример #4
0
void PointHelpObject::GetLocalBoundBox(
		TimeValue t, INode* inode, ViewExp* vpt, Box3& box ) 
	{
	
	if ( ! vpt || ! vpt->IsAlive() )
	{
		box.Init();
		return;
	}

	Matrix3 tm = inode->GetObjectTM(t);	
	
	float size;
	int screenSize;
	pblock2->GetValue(pointobj_size, t, size, FOREVER);
	pblock2->GetValue(pointobj_screensize, t, screenSize, FOREVER);

	float zoom = 1.0f;
	if (screenSize) {
		zoom = vpt->GetScreenScaleFactor(tm.GetTrans())*ZFACT;
		}
	if (zoom==0.0f) zoom = 1.0f;

	size *= zoom;
	box =  Box3(Point3(0,0,0), Point3(0,0,0));
	box += Point3(size*0.5f,  0.0f, 0.0f);
	box += Point3( 0.0f, size*0.5f, 0.0f);
	box += Point3( 0.0f, 0.0f, size*0.5f);
	box += Point3(-size*0.5f,   0.0f,  0.0f);
	box += Point3(  0.0f, -size*0.5f,  0.0f);
	box += Point3(  0.0f,  0.0f, -size*0.5f);

	//JH 6/18/03
	//This looks odd but I'm being conservative an only excluding it for
	//the case I care about which is when computing group boxes
	//	box.EnlargeBy(10.0f/zoom);
	if(!(extDispFlags & EXT_DISP_GROUP_EXT)) 
		box.EnlargeBy(10.0f/zoom);

	/*
	if (showAxis)
		box = GetAxisBox(vpt,tm,showAxis?axisLength:0.0f, TRUE);
	else
		box = Box3(Point3(0,0,0), Point3(0,0,0));
	*/
	}
Box3 SplineData::GetWorldsBounds()
{
	Box3 bounds;
	bounds.Init();

	mShapeCache.BuildBoundingBox();
	bounds = mShapeCache.bdgBox;
	float extraPadding = 0.0f;
	for (int i = 0; i < mSplineElementData.Count(); i++)
	{
		for (int j = 0; j < NumberOfCrossSections(i); j++)
		{
			SplineCrossSection *section = GetCrossSection(i,j);
			float d = section->GetLargestScale();
			if (d > extraPadding)
				extraPadding = d;
		}
	}
	
	bounds.EnlargeBy(extraPadding);


	return bounds;
}
Пример #6
0
Box3 GetAxisBox(ViewExp *vpt, const Matrix3 &tm,float length,int resetTM)
	{
	Matrix3 tmn = tm;
	Box3 box;
	float zoom;

	// Get width of viewport in world units:  --DS
	zoom = vpt->GetScreenScaleFactor(tmn.GetTrans())*ZFACT;
	if (zoom==0.0f) zoom = 1.0f;
//	tmn.Scale(Point3(zoom,zoom,zoom));
	length *= zoom;
	if(resetTM)
		tmn.IdentityMatrix();

	box += Point3(0.0f,0.0f,0.0f) * tmn;
	box += Point3(length,0.0f,0.0f) * tmn;
	box += Point3(0.0f,length,0.0f) * tmn;
	box += Point3(0.0f,0.0f,length) * tmn;	
	box += Point3(-length/5.f,0.0f,0.0f) * tmn;
	box += Point3(0.0f,-length/5.f,0.0f) * tmn;
	box += Point3(0.0f,0.0f,-length/5.0f) * tmn;
	box.EnlargeBy(10.0f/zoom);
	return box;
	}
Пример #7
0
void 
UniformGrid::Display(GraphicsWindow *gw)
{
	return;
	Matrix3 tm(1);
//	gw->setTransform(tm);
	DrawBounds(gw, bounds);

	float sx,sy,sz;
	float incx,incy,incz;

	sx = 0.0f;
	sy = bounds.pmin.y;
	sz = bounds.pmin.z;
	incx = 0.0f;
	incy = (bounds.pmax.y - bounds.pmin.y)/width;
	incz = (bounds.pmax.z - bounds.pmin.z)/width;


	int index =0;
	float x,y,z;

	sx = bounds.pmin.x;
	sy = 0.0f;
	sz = bounds.pmin.z;
	incx = (bounds.pmax.x - bounds.pmin.x)/width;
	incy = 0.0f;
	incz = (bounds.pmax.z - bounds.pmin.z)/width;


	index =0;
	z = sz;
	for (int i = 0; i < width; i++)
	{
		x = sx;
		y = 0.0;
		for (int j = 0; j < width; j++)
		{
			Box3 b;
			b.Init();
			Point3 p(x,y,z);
			b += p;
			p.x += incx;
			p.y += incy;
			p.z += incz; 
			b += p;

			if (yGrid[index]!=NULL)
				{
				if (index == whichLargestCell)
					{
					Point3 color (1.0f,0.0f,0.0f);
					gw->setColor(LINE_COLOR,color);
					}
				else
					{
					Point3 color (0.0f,1.0f,0.0f);
					gw->setColor(LINE_COLOR,color);
					}

				gw->marker(&b.Center(),CIRCLE_MRKR);
				DrawBounds(gw, b);
				}
			
			index++;
			x += incx;
		}
		z += incz;
	}

	gw->setColor(LINE_COLOR,GetUIColor(COLOR_SEL_GIZMOS));
	gw->marker(&debugP,BIG_BOX_MRKR);


	Point3 red (1.0f,0.0f,0.0f);

	gw->setColor(LINE_COLOR,red);
	gw->marker(&bounds.pmin,BIG_BOX_MRKR);
	Box3 cb;
	cb.Init();
	cb += bounds.pmin;
	cb.EnlargeBy(mRadius);
	DrawBounds(gw, cb);

}
Пример #8
0
IGeometryChecker::ReturnVal OverlappedUVWFacesChecker::GeometryCheckWithUVMesh(UVWChannel &uvmesh,TimeValue t,INode *nodeToCheck, BitArray &arrayOfFaces)
{
	LARGE_INTEGER	ups,startTime;
	QueryPerformanceFrequency(&ups);
	QueryPerformanceCounter(&startTime); //used to see if we need to pop up a dialog 
	bool checkTime = GetIGeometryCheckerManager()->GetAutoUpdate();//only check time for the dialog if auto update is active!
	//get our bounding box
	Box3 bounds;
	bounds.Init();

	int numVerts = uvmesh.GetNumTVVerts();
	int i;
	for (i = 0; i < numVerts; ++i)
	{
		Point3 tv = uvmesh.GetTVVert(i);
		if(_isnan(tv.x) || !_finite(tv.x)||_isnan(tv.y) || !_finite(tv.y)||_isnan(tv.z) || !_finite(tv.z))
			return IGeometryChecker::eFail; //if we have a bad tvert bail out...
		bounds += uvmesh.GetTVVert(i);
	}
	//put a small fudge to keep faces off the edge
	bounds.EnlargeBy(0.05f);
	//build our transform

	float xScale = bounds.pmax.x - bounds.pmin.x;
	float yScale = bounds.pmax.y - bounds.pmin.y;
	Point3 offset = bounds.pmin;

	//create our buffer
	OverlapMap overlapMap;
	overlapMap.Init();
	
	Interface *ip = GetCOREInterface();
	int numProcsToUse = omp_get_num_procs()-1;
	if(numProcsToUse<0)
		numProcsToUse = 1;
	TCHAR buf[256];
	TCHAR tmpBuf[64];
	_tcscpy(tmpBuf,GetString(IDS_CHECK_TIME_USED));
	_tcscpy(buf,GetString(IDS_RUNNING_GEOMETRY_CHECKER));
	ip->PushPrompt(buf);
	int total = 0;
	bool compute = true;
	EscapeChecker::theEscapeChecker.Setup();
	for (int i = 0; i < uvmesh.GetNumOfFaces(); ++i)
	{
		if(compute==true)
		{
			//loop through the faces
			int deg = uvmesh.GetFaceDegree(i);
			int index[4];
			index[0] = uvmesh.GetFaceTVVert(i,0);
			Point3 pa = uvmesh.GetTVVert(index[0]);
			pa.x -= offset.x;
			pa.x /= xScale;

			pa.y -= offset.y;
			pa.y /= yScale;

			for (int j = 0; j < deg -2; j++)
			{
				index[1] = uvmesh.GetFaceTVVert(i,j+1);
				index[2] = uvmesh.GetFaceTVVert(i,j+2);
				Point3 pb = uvmesh.GetTVVert(index[1]);
				Point3 pc = uvmesh.GetTVVert(index[2]);

				pb.x -= offset.x;
				pb.x /= xScale;
				pb.y -= offset.y;
				pb.y /= yScale;

				pc.x -= offset.x;
				pc.x /= xScale;
				pc.y -= offset.y;
				pc.y /= yScale;

				//add face to buffer
				//select anything that overlaps
				overlapMap.Map(uvmesh,i,pa,pb,pc,arrayOfFaces);
			}
		}
		total += 1;
		
		if(compute==true)
		{
			if(EscapeChecker::theEscapeChecker.Check())
			{
				compute = false;
				_tcscpy(buf,GetString(IDS_EXITING_GEOMETRY_CHECKER));
				ip->ReplacePrompt(buf);
				break; //can now break, no omp
			}
		
			if((total%100)==0)
			{
				{
					float percent = (float)total/(float)uvmesh.GetNumOfFaces()*100.0f;
					_stprintf(buf,tmpBuf,percent);
					ip->ReplacePrompt(buf);
				}     
			}
			if(checkTime==true)
			{
				DialogChecker::Check(checkTime,compute,uvmesh.GetNumOfFaces(),startTime,ups);
				if(compute==false)
					break;
			}
		}
		
	}
	ip->PopPrompt();
	

	return TypeReturned();

}
Пример #9
0
void PointGatherer::AddWeightFromSegment(Point3 a, float radiusA, float strA,
									Point3 b, float radiusB, float strB, ICurve *pCurve,
									BOOL additveMode, BOOL isMirror,
									float currentLength)
{

	float segLength = Length(a-b);

//get the bounding box from the segment
	Box3 bounds;

	bounds.Init();

	bounds += a;
	bounds += b;
	if (radiusA > radiusB)
		bounds.EnlargeBy(radiusA);
	else bounds.EnlargeBy(radiusB);
	int startX, endX;
	int startY, endY;
	int startZ, endZ;
	
	startX = (bounds.pmin.x - upperLeft.x)/xOffset;
	startY= (bounds.pmin.y - upperLeft.y)/yOffset;
	startZ= (bounds.pmin.z - upperLeft.z)/zOffset;

	endX = (bounds.pmax.x - upperLeft.x)/xOffset;
	endY= (bounds.pmax.y - upperLeft.y)/yOffset;
	endZ= (bounds.pmax.z - upperLeft.z)/zOffset;

//need to constrains the indices since a brush envelope can exist past our bounds
	if (startX < 0) startX = 0;
	if (startX >=  width) startX = width-1;
	if (endX < 0) endX = 0;
	if (endX >=  width) endX = width-1;

	if (startY < 0) startY = 0;
	if (startY >=  width) startY = width-1;
	if (endY < 0) endY = 0;
	if (endY >=  width) endY = width-1;

	if (startZ < 0) startZ = 0;
	if (startZ >=  width) startZ = width-1;
	if (endZ < 0) endZ = 0;
	if (endZ >=  width) endZ = width-1;


//get all the cells that intersect with the bounding box
//loop through those points adding weight to em if they are within the envelope
	float u = 0.0f;
	float dist = 0.0f;
	float envDist = 0.0f;
/*
//Brute force method checks against every point
	for (int i = 0; i < cellData.Count(); i++)
		{

		for (int j = 0; j < cellElementCount[i]; j++)
			{
			Point3 p = *cellData[i].p[j];

			dist = LineToPoint(p,a,b,u);
				envDist = radiusA + ((radiusB-radiusA) * u);
				if (dist <= envDist)
					{
//DebugPrint("dist %f envdist %f\n",dist,envDist);
					float weight = 1.0f - dist/envDist;
					float str = (strA + ((strB-strA) * u)) * weight;
					float listWeight = cellData[i].weight[j];
					if (weight > listWeight) 
						{
						cellData[i].str[j] = str;
						cellData[i].weight[j] = weight;
						}
					
					}

			}	
		}
*/
//checks against cells first then those points only within the hit cells
//2 d gather
/*
	for (int i = startY; i <= endY; i++)
		{
		int currentCell = i * width;
		
		for (int j = startX; j <= endX; j++)
			{
			if (CellDataXY[currentCell+j])
				{
				for (int k = 0; k < CellDataXY[currentCell+j]->whichPoint.Count(); k++)
					{
					int whichPoint = CellDataXY[currentCell+j]->whichPoint[k];
					int whichNode = CellDataXY[currentCell+j]->whichNode[k];
					Point3 p = *cellData[whichNode].p[whichPoint];
					dist = LineToPoint(p,a,b,u);
					envDist = radiusA + ((radiusB-radiusA) * u);
					if (dist <= envDist)
						{
//DebugPrint("dist %f envdist %f\n",dist,envDist);
						float weight = 1.0f - dist/envDist;
						float str = (strA + ((strB-strA) * u)) * weight;
						float listWeight = cellData[whichNode].weight[whichPoint];
						if (weight > listWeight) 
							{
			 				cellData[whichNode].str[whichPoint] = str;
							cellData[whichNode].weight[whichPoint] = weight;
							}
						
						}
					}
				}
			}
		}
		*/


	for (int i = 0; i < cellData.Count(); i++)
		{
		int* countAmount = cellData[i].count;
		
		memset(countAmount,0,cellElementCount[i]*sizeof(int));
/*		for (int j = 0; j < cellElementCount[i]; j++)
			{
			*countAmount = 0;
			countAmount++;
			}
*/

		}
// 3 d gather
//in xy

	for (i = startY; i <= endY; i++)
		{
		int currentCell = i * width;
		
		for (int j = startX; j <= endX; j++)
			{
			if (CellDataXY[currentCell+j])
				{
				for (int k = 0; k < CellDataXY[currentCell+j]->whichPoint.Count(); k++)
					{
					int whichPoint = CellDataXY[currentCell+j]->whichPoint[k];
					int whichNode = CellDataXY[currentCell+j]->whichNode[k];
					cellData[whichNode].count[whichPoint]++;
					}
				}
			}
		}

//in yz
	for (i = startZ; i <= endZ; i++)
		{
		int currentCell = i * width;
		
		for (int j = startY; j <= endY; j++)
			{
			if (CellDataYZ[currentCell+j])
				{
				for (int k = 0; k < CellDataYZ[currentCell+j]->whichPoint.Count(); k++)
					{
					int whichPoint = CellDataYZ[currentCell+j]->whichPoint[k];
					int whichNode = CellDataYZ[currentCell+j]->whichNode[k];
					cellData[whichNode].count[whichPoint]++;
					}
				}
			}
		}

//in xz
	for ( i = startZ; i <= endZ; i++)
		{
		int currentCell = i * width;
		
		for (int j = startX; j <= endX; j++)
			{
			if (CellDataXZ[currentCell+j])
				{
				for (int k = 0; k < CellDataXZ[currentCell+j]->whichPoint.Count(); k++)
					{
					int whichPoint = CellDataXZ[currentCell+j]->whichPoint[k];
					int whichNode = CellDataXZ[currentCell+j]->whichNode[k];
					cellData[whichNode].count[whichPoint]++;
					}
				}
			}
		}
		
	for ( i = 0; i < cellData.Count(); i++)
		{
		int* countAmount = cellData[i].count;
		for (int j = 0; j < cellElementCount[i]; j++)
			{
			if (*countAmount == 3)
				{

				int whichPoint = j;
				int whichNode =i;
				Point3 p = cellData[whichNode].p[whichPoint];
				dist = LineToPoint(p,a,b,u);
				envDist = radiusA + ((radiusB-radiusA) * u);
				if (dist <= envDist)
					{
					float weight = 1.0f - dist/envDist;
					float str = (strA + ((strB-strA) * u));
					float listWeight = cellData[whichNode].weight[whichPoint];
					if (additveMode)
						{
			 			pointGatherHitVerts[whichNode]->Set(whichPoint,TRUE);
						cellData[whichNode].weight[whichPoint] += weight;
						weight =  pCurve->GetValue(0,1.0f-weight);
						cellData[whichNode].str[whichPoint] += str*weight;
						cellData[whichNode].u[whichPoint] = (currentLength + (u*segLength));

						}
					else if (weight > listWeight) 
						{
			 			pointGatherHitVerts[whichNode]->Set(whichPoint,TRUE);
						cellData[whichNode].weight[whichPoint] = weight;
						weight =  pCurve->GetValue(0,1.0f-weight);
						cellData[whichNode].str[whichPoint] = str*weight;
						cellData[whichNode].u[whichPoint] = (currentLength + (u*segLength));
						}
//if first mirror						
					if ((isMirror) && (cellData[whichNode].isMirror[whichPoint] == NO_MIRRROR))
						cellData[whichNode].isMirror[whichPoint] = MIRRRORED;
					else if ((!isMirror) && (cellData[whichNode].isMirror[whichPoint] == MIRRRORED))
						cellData[whichNode].isMirror[whichPoint] = MIRRROR_SHARED;
//if mirrored and now appliying a non mirror weight

						
					}
				}
			countAmount++;
			}
		}

//DebugPrint("Solving Stroke %f %f %f \n",a.x,a.y,a.z);
//DebugPrint("               %f %f %f \n",b.x,b.y,b.z);

}