Exemplo n.º 1
0
void vtLevel::SetFootprint(const DPolygon2 &poly)
{
	int prev = m_Foot.NumTotalVertices();
	m_Foot = poly;
	int curr = m_Foot.NumTotalVertices();
	if (curr != prev)
		RebuildEdges(curr);
}
Exemplo n.º 2
0
void vtLevel::SetFootprint(const DLine2 &dl)
{
	// Safety check: Make sure there is at least an outer polygon
	if (m_Foot.size() == 0)
		m_Foot.resize(1);

	int prev = m_Foot[0].GetSize();
	m_Foot[0] = dl;
	int curr = dl.GetSize();
	if (curr != prev)
		RebuildEdges(curr);
}
Exemplo n.º 3
0
bool ON_Brep::Morph( const ON_SpaceMorph& morph )
{
  bool rc = IsMorphable();
  if ( rc )
  {
    ON_Surface* srf = const_cast<ON_Surface*>(m_F[0].SurfaceOf());
    
    if ( srf->IsMorphable() )
    {
      rc = srf->Morph(morph);
    }
    else
    {
      ON_NurbsSurface* new_srf = srf->NurbsSurface();
      if ( !new_srf )
        return false;
      rc = new_srf->Morph(morph);
      if (rc)
      {
        int si = m_F[0].m_si;
        m_F[0].SetProxySurface(new_srf);
        delete srf;
        srf = new_srf;
        m_S[si] = srf;
        DestroyMesh(ON::any_mesh,true);
      }
      else
      {
        delete new_srf;
        new_srf = 0;
      }
    }
    
    if ( rc )
    {
      double tol = 0.01; 
      rc = RebuildEdges( m_F[0], tol, true, true );

      DestroyMesh(ON::analysis_mesh);
      DestroyMesh(ON::preview_mesh);
      ON_Mesh* mesh = const_cast<ON_Mesh*>(m_F[0].Mesh(ON::render_mesh));
      if ( mesh )
        mesh->EvaluateMeshGeometry( *srf );
    }
  }
  return rc;
}
Exemplo n.º 4
0
void	UnwrapMod::fnUnfoldSelectedPolygons(int unfoldMethod, BOOL normalize)
	{		
// flatten selected polygons
	BailStart();
	BitArray *polySel = fnGetSelectedPolygons();
	BitArray holdPolySel;
	if (polySel == NULL) 
		return;
	if (TVMaps.f.Count() == 0) return;


	if (!theHold.Holding())
		{
		theHold.SuperBegin();
		theHold.Begin();
		}

	holdPolySel.SetSize(polySel->GetSize());
	holdPolySel = *polySel;

	HoldPointsAndFaces();	

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

	BitArray oldSel = *fnGetSelectedPolygons();

	Tab<Point3> mapNormal;
	mapNormal.SetCount(0);

	BOOL bContinue = BuildCluster( mapNormal, 5.0f, TRUE, TRUE);
	TSTR statusMessage;

	BitArray sel;
	sel.SetSize(TVMaps.f.Count());

	if (bContinue)
		{
			
		for (int i =0; i < clusterList.Count(); i++)
			{
			sel.ClearAll();
			for (int j = 0; j < clusterList[i]->faces.Count();j++)
				sel.Set(clusterList[i]->faces[j]);
			fnSelectPolygonsUpdate(&sel, FALSE);
			PlanarMapNoScale(clusterList[i]->normal);

			int per = (i * 100)/clusterList.Count();
			statusMessage.printf("%s %d%%.",GetString(IDS_PW_STATUS_MAPPING),per);
			if (Bail(ip,statusMessage))
				{
				i = clusterList.Count();
				bContinue =  FALSE;
				}

			}


		if ( (bContinue) && (clusterList.Count() > 1) )
			{

			if (!ip) return;
			ModContextList mcList;		
			INodeTab nodes;
			ip->GetModContexts(mcList,nodes);

			int objects = mcList.Count();

			MeshTopoData *md = (MeshTopoData*)mcList[0]->localData;

			if (md == NULL) 
				{
				theHold.Cancel();
				theHold.SuperCancel();
				return;
				}

			Tab<Point3> objNormList;
			BuildNormals(md,objNormList);

//remove internal edges
			BitArray *selectedPolygons = fnGetSelectedPolygons();
			Tab<int> clusterGroups;
			clusterGroups.SetCount(TVMaps.f.Count());
			for (i =0; i < clusterGroups.Count(); i++)
				{
				clusterGroups[i] = -1;
				}
		//loop through all tagged edges and remove any that onely have one edhes selected
			for (i = 0; i < clusterList.Count(); i++)
				{
				for (int j = 0; j < clusterList[i]->faces.Count(); j++)
					{
					int faceIndex = clusterList[i]->faces[j];
					clusterGroups[faceIndex] = i;
					}
				}
			BitArray processedClusters;
			processedClusters.SetSize(clusterList.Count());
			processedClusters.ClearAll();

			Tab<BorderClass> edgesToBeProcessed;

			BOOL done = FALSE;
			int currentCluster = 0;

			processedClusters.Set(0);
			clusterList[0]->newX = 0.0f;
			clusterList[0]->newY = 0.0f;
//		clusterList[0]->angle = 0.0f;
			for (int i = 0; i < clusterList[0]->borderData.Count(); i++)
				{
				int outerFaceIndex = clusterList[0]->borderData[i].outerFace;
				int connectedClusterIndex = clusterGroups[outerFaceIndex];
				if ((connectedClusterIndex != 0) && (connectedClusterIndex != -1))
					{
					edgesToBeProcessed.Append(1,&clusterList[0]->borderData[i]);
					}
				}
			BitArray seedFaceList;
			seedFaceList.SetSize(clusterGroups.Count());
			seedFaceList.ClearAll();
			for (i = 0; i < seedFaces.Count(); i++)
				{
				seedFaceList.Set(seedFaces[i]);
				}

			while (!done)
				{
				Tab<int> clustersJustProcessed;
				clustersJustProcessed.ZeroCount();
				done = TRUE;

				int edgeToAlign = -1;
				float angDist = PI*2;
				if (unfoldMethod == 1)
					angDist =  PI*2;
				else if (unfoldMethod == 2) angDist = 0;
				for (i = 0; i < edgesToBeProcessed.Count(); i++)
					{
					int outerFace = edgesToBeProcessed[i].outerFace;
					int connectedClusterIndex = clusterGroups[outerFace];
					if (!processedClusters[connectedClusterIndex])
						{
						int innerFaceIndex = edgesToBeProcessed[i].innerFace;
						int outerFaceIndex = edgesToBeProcessed[i].outerFace;
//get angle
						Point3 innerNorm, outerNorm;
						innerNorm = objNormList[innerFaceIndex];
						outerNorm = objNormList[outerFaceIndex];
						float dot = DotProd(innerNorm,outerNorm);

						float angle = 0.0f;

						if (dot == -1.0f)
							angle = PI;
						else if (dot == 1.0f)
							angle = 0.f;						
						else angle = acos(dot);

						if (unfoldMethod == 1)
							{
							if (seedFaceList[outerFaceIndex])
								angle = 0.0f;
							if (angle < angDist)
								{
								angDist = angle;
								edgeToAlign = i;
								}
							}

						else if (unfoldMethod == 2)
							{
							if (seedFaceList[outerFaceIndex])
								angle = 180.0f;
							if (angle > angDist)
								{
								angDist = angle;
								edgeToAlign = i;
								}
							}

						}
					}
				if (edgeToAlign != -1)
					{
					int innerFaceIndex = edgesToBeProcessed[edgeToAlign].innerFace;
					int outerFaceIndex = edgesToBeProcessed[edgeToAlign].outerFace;
					int edgeIndex = edgesToBeProcessed[edgeToAlign].edge;
					

					int connectedClusterIndex = clusterGroups[outerFaceIndex];

					seedFaceList.Set(outerFaceIndex, FALSE);

					processedClusters.Set(connectedClusterIndex);
					clustersJustProcessed.Append(1,&connectedClusterIndex);
					AlignCluster(i,connectedClusterIndex,innerFaceIndex, outerFaceIndex,edgeIndex);
					done = FALSE;
					}

//build new cluster list
				for (int j = 0; j < clustersJustProcessed.Count(); j++)
					{
					int clusterIndex = clustersJustProcessed[j];
					for (int i = 0; i < clusterList[clusterIndex]->borderData.Count(); i++)
						{
						int outerFaceIndex = clusterList[clusterIndex]->borderData[i].outerFace;
						int connectedClusterIndex = clusterGroups[outerFaceIndex];
						if ((!processedClusters[connectedClusterIndex]) && (connectedClusterIndex != 0) && (connectedClusterIndex != -1))
							{
							edgesToBeProcessed.Append(1,&clusterList[clusterIndex]->borderData[i]);
							}
						}
					}
				}
			}

		vsel.SetSize(TVMaps.v.Count());
		vsel.ClearAll();
		for (i = 0; i < clusterList.Count(); i++)
			{
			for (int j =0; j < clusterList[i]->faces.Count(); j++)
				{
				int faceIndex = clusterList[i]->faces[j];
				for (int k =0; k < TVMaps.f[faceIndex]->count; k++)
					{
					int vertexIndex = TVMaps.f[faceIndex]->t[k];
					vsel.Set(vertexIndex);
					}
				}
			}
//now weld the verts
		if (normalize)
			{
			NormalizeCluster();
			}

		float tempWeld = weldThreshold;
		weldThreshold = 0.001f;
		WeldSelected(FALSE);
		weldThreshold = tempWeld;


		}

	


	FreeClusterList();

	if (bContinue)
		{	
		theHold.Accept(_T(GetString(IDS_PW_PLANARMAP)));
		theHold.SuperAccept(_T(GetString(IDS_PW_PLANARMAP)));

		fnSelectPolygonsUpdate(&holdPolySel, FALSE);
		theHold.Suspend();
		fnSyncTVSelection();
		theHold.Resume();
		}
	else
		{
		theHold.Cancel();
		theHold.SuperCancel();
		}

	RebuildEdges();

	theHold.Suspend();
	fnSyncGeomSelection();
	theHold.Resume();


	NotifyDependents(FOREVER,PART_SELECT,REFMSG_CHANGE);
	InvalidateView();


	}
Exemplo n.º 5
0
void UnwrapMod::ApplyGizmoPrivate(Matrix3 *defaultTM)
{
	BOOL wasHolding = FALSE;
 	if (theHold.Holding())
		wasHolding = TRUE;


	if (!theHold.Holding())
	{
		theHold.Begin();
	}
	HoldPointsAndFaces();	


	//add vertices to our internal vertex list filling in dead spots where appropriate

	//get align normal
	//get fit data


	Matrix3 gtm(1);
	TimeValue t = 0;
	if (ip) t = ip->GetTime();
	if (defaultTM)
		gtm = *defaultTM;
	else
	{
		if (tmControl)
		{
			
			gtm = GetMapGizmoMatrix(t);

			if (!fnGetNormalizeMap())
			{
				for (int i = 0; i < 3; i++)
				{
					Point3 vec = gtm.GetRow(i);
					vec = Normalize(vec);
					gtm.SetRow(i,vec);
				}
			}

		}

	}

	for (int ldID = 0; ldID < mMeshTopoData.Count(); ldID++)
	{
		MeshTopoData *ld = mMeshTopoData[ldID];
		Matrix3 tm(1);
		tm = mMeshTopoData.GetNodeTM(t,ldID)* Inverse(gtm);
		ld->ApplyMap(fnGetMapMode(), fnGetNormalizeMap(), tm, this);
		ld->SetTVEdgeInvalid();
		ld->BuildTVEdges();
		ld->BuildVertexClusterList();
		
	}


	if (!wasHolding)
	{
		theHold.Accept(GetString(IDS_PW_PLANARMAP));
	}

	RebuildEdges();
	theHold.Suspend();
	fnFaceToEdgeSelect();
	theHold.Resume();

//	ConvertFaceToEdgeSel();
//	TVMaps.edgesValid= FALSE;
	//update our views to show new faces

	InvalidateView();

}