{
  // EXERCISE 1.3 /////////////////////////////////////////////////////////////
  // Implement a color visualization of your choice that shows the valence of
  // each vertex of 'mesh_'. 
  // (hint: use Mesh::Color color type)
    
  // Implement something here
	Mesh::VertexIter v_end = mesh_.vertices_end();
	//OpenMesh::VPropHandleT<int> Valence;
	Mesh::Color Green = Mesh::Color(0, 255, 0);
	Mesh::Color Red = Mesh::Color(255, 0, 0);
	Mesh::Color Blue = Mesh::Color(0, 0, 255);
	int Valence;
	OpenMesh::VPropHandleT<int> vPH;
	for (Mesh::VertexIter v_it = mesh_.vertices_begin(); v_it != v_end; ++v_it)
	{
		mesh_.get_property_handle(vPH, 'Valence');
		Valence = mesh_.property(vPH, v_it.handle());
		if (Valence >= 4 && Valence < 6)
		{
			mesh_.set_color(v_it.handle(), Blue);
		}
		else if (Valence >= 7)
		{
			mesh_.set_color(v_it.handle(), Red);
		}
		else
		{
			mesh_.set_color(v_it.handle(), Green);
		}
		//mesh_.set_color(v_it.handle(),Green);		
	}
	//cout << "Edge:" << mesh_.n_edges() << "Face" << mesh_.n_faces() << "Vertex" << mesh_.n_vertices() << endl;
	
  /////////////////////////////////////////////////////////////////////////////
}

This function, color_coding(), provides a visual representation of vertex valences within an OpenMesh object named 'mesh_'. The process involves:

  1. Iterating through Vertices: The code obtains an iterator pointing to the end of the vertex list (mesh_.vertices_end()) and iterates through each vertex using Mesh::VertexIter from the beginning to the end.

  2. Defining Colors: Three distinct colors are defined: Green (0, 255, 0), Red (255, 0, 0), and Blue (0, 0, 255) using Mesh::Color data type.

  3. Retrieving Vertex Valence: A property handle (vPH) for the vertex valence property named 'Valence' is obtained. The actual valence value for each vertex is then retrieved using mesh_.property(vPH, v_it.handle()).

  4. Color Assignment based on Valence:

    • If the valence is greater than or equal to 4 but less than 6, the vertex is assigned the color Blue.
    • If the valence is greater than or equal to 7, the vertex is assigned the color Red.
    • For all other valences, the vertex is assigned the color Green.
  5. Applying Color to Vertices: The mesh_.set_color(v_it.handle(), color) function applies the determined color to the current vertex.

This function effectively visualizes the valence of each vertex in the mesh, offering a clear representation of vertex connectivity and neighborhood information.

OpenMesh Vertex Valence Color Visualization with color_coding() Function

原文地址: https://www.cveoy.top/t/topic/lPgE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录