Beispiel #1
0
void ProgressiveMesh(std::vector<float3> &vert, std::vector<tridata> &tri,
                     std::vector<int> &map, std::vector<int> &permutation)
{
	AddVertex(vert);  // put input data into our data structures
	AddFaces(tri);
	ComputeAllEdgeCollapseCosts(); // cache all edge collapse costs
	permutation.resize(vertices.size());  // allocate space
	map.resize(vertices.size());          // allocate space
	// reduce the object down to nothing:
	while (vertices.size() > 0) {
		// get the next vertex to collapse
		Vertex *mn = MinimumCostEdge();
		// keep track of this vertex, i.e. the collapse ordering
		permutation[mn->id] = vertices.size() - 1;
		// keep track of vertex to which we collapse to
		map[vertices.size() - 1] = (mn->collapse) ? mn->collapse->id : -1;
		// Collapse this edge
		Collapse(mn,mn->collapse);
	}
	// reorder the map Array based on the collapse ordering
	for (unsigned int i = 0; i<map.size(); i++) {
		map[i] = (map[i]==-1)?0:permutation[map[i]];
	}
	// The caller of this function should reorder their vertices
	// according to the returned "permutation".
}
Beispiel #2
0
void Chopper::chop( Array< Vector3 > & vert, Array< Triangle > &tri, 
							Array< int > &map, Array< int > &permutation )
{
	AddVertex(vert);  // put input data into our data structures
	AddFaces(tri);

	ComputeAllEdgeCollapseCosts(); // cache all edge collapse costs

	permutation.allocate(s_Vertices.size());  // allocate space
	map.allocate(s_Vertices.size());          // allocate space

	// reduce the object down to nothing:
	while(s_Vertices.size() > 0) 
	{
		// get the next vertex to collapse
		Vertex *mn = MinimumCostEdge();
		// keep track of this vertex, i.e. the collapse ordering
		permutation[mn->id]=s_Vertices.size()-1;
		// keep track of vertex to which we collapse to
		map[s_Vertices.size()-1] = (mn->collapse)?mn->collapse->id:-1;
		// Collapse this edge
		Collapse(mn,mn->collapse);
	}
	// reorder the map list based on the collapse ordering
	for(int i=0;i<map.size();i++) {
		map[i] = (map[i]==-1)?0:permutation[map[i]];
	}
	// The caller of this function should reorder their vertices
	// according to the returned "permutation".
}