Find vertices for each sub-face (shell inserted as tristrip)

The following is sample code uses ShellKey::ShowTristrips to find the vertices of a sub-face. Please run sample code using hps_mfc_sandbox.

Replace CHPSView::OnUserCode2() (CHPSView.cpp) with the following code:

class Face
{
public:
	Face(unsigned int v1, unsigned int v2, unsigned int v3)
	{
		_v1 = v1; _v2 = v2; _v3 = v3;
	}
	unsigned int GetV1() { return _v1; }
	unsigned int GetV2() { return _v2; }
	unsigned int GetV3() { return _v3; }
private:
	/*unsigned int _id;*/
	unsigned int _v1, _v2, _v3;
};

void CHPSView::OnUserCode2()
{

	HPS::SegmentKey ModelSegKey = GetDocument()->GetModel().GetSegmentKey();
	ModelSegKey.GetPerformanceControl().SetStaticModel(HPS::Performance::StaticModel::None);

	HPS::SegmentKey MarkKey = ModelSegKey.Subsegment("Vertices");
	ModelSegKey.GetVisibilityControl().SetMarkers(true).SetEdges(true);
	ModelSegKey.GetMaterialMappingControl().SetMarkerColor(RGBColor(1, 0, 0));
	ModelSegKey.GetMarkerAttributeControl().SetSymbol("circle in a circle");


	HPS::ShellKey shellKey;
	bool found = false;
	// Search the segment for Shell
	// cylinder_as_shell.hsf contain only one shell

	HPS::SearchResults searchResults;
	ModelSegKey.Find(HPS::Search::Type::Shell,
		HPS::Search::Space::Subsegments,
		searchResults);
	HPS::SearchResultsIterator it = searchResults.GetIterator();

	while (it.IsValid())
	{
		Key key = it.GetItem();

		if (key.Type() == HPS::Type::ShellKey)
		{
		
			shellKey = (HPS::ShellKey)key;
			found = true;

		}
		it.Next();
	}

	if (found)
	{

		HPS::SizeTArray out_faces, out_vertices, edges1, edges2;

		IntArray tristrips, face_indices;
		PointArray points;

		shellKey.ShowTristrips(tristrips, face_indices);
		shellKey.ShowPoints(points);

		//  assuming each face only contain 3 vertices (tri-strip)
		std::vector<Face> tri_strip_flist(face_indices.size(), Face(0, 0, 0));

		//  Generate facelist from tristrips and face_indices
		//  map shellface to tri_strip_flist

		size_t map_index = 0;

		for (int i = 0; i < tristrips.size(); i++)
		{
			int traverse_array = i;
			for (int j = 0; j < tristrips[i] - 2; j++)  // generate faces
			{
				Face shellface(tristrips[traverse_array + j + 1], tristrips[traverse_array + j + 2], tristrips[traverse_array + j + 3]);

				int face_number = face_indices[map_index++];
				tri_strip_flist[face_number] = shellface;

			}

			i = i + tristrips[i];  //  increment to end of facelist
		}

		// shellface is sorted



		//  Change sub-face color to red
		//  Insert markers separately using points found on shell

		tri_strip_flist.shrink_to_fit();
		size_t numFaces = tri_strip_flist.size();

		for (int x = 0; x < numFaces; x++)
		{

			size_t pointoffset1 = tri_strip_flist[x].GetV1();
			size_t pointoffset2 = tri_strip_flist[x].GetV2();
			size_t pointoffset3 = tri_strip_flist[x].GetV3();


			HPS::Point p1 = points[pointoffset1];
			HPS::Point p2 = points[pointoffset2];
			HPS::Point p3 = points[pointoffset3];


			RGBColorArray cols;
			cols.push_back(HPS::RGBColor(1, 0, 0));

			HPS::SizeTArray faceArrcol;
			faceArrcol.push_back(x);

			shellKey.SetFaceRGBColorsByList(faceArrcol, cols);


			MarkKey.InsertMarker(p1);
			MarkKey.InsertMarker(p2);
			MarkKey.InsertMarker(p3);

			GetCanvas().UpdateWithNotifier().Wait();


            
  			// Flush everything
			MarkKey.Flush();
			shellKey.UnsetFaceColors();



		}
	}
}
  1. Build and run hps_mfc_sandbox
  2. Load cylinder_as_shell.hsf
  3. Run OnUserCode2

cylinder_as_shell.zip (699 Bytes)