示例#1
0
Mesh MeshManipulation::smoothLength(Mesh &mesh, int iterations)
{
    std::vector<Mesh::Point>  cogs;
    std::vector<Mesh::Point>::iterator cog_it;
    cogs.reserve(mesh.n_vertices());

    Mesh::VertexIter vIt, vEnd(mesh.vertices_end());
    Mesh::VertexVertexIter vvIt;
    OpenMesh::Vec3f newP;
    float sum;

    for(int i = 0; i < iterations; i++) {
        cogs.clear();

        for( vIt = mesh.vertices_begin(); vIt != vEnd; ++vIt ) {
            newP[0] = newP[1] = newP[2] = sum = 0.0f;

            for(vvIt = mesh.vv_iter(*vIt); vvIt.is_valid(); ++vvIt) {
                OpenMesh::Vec3f vec = mesh.point(*vvIt) - mesh.point(*vIt);
                sum += (1.0f / vec.length());
                newP += (vec / vec.length());
            }
            OpenMesh::Vec3f l = sum * newP;
            cogs.push_back(l);
        }

        float lambda = 0.2f;
        Mesh::VertexIter v_it, v_end(mesh.vertices_end());
        for (v_it=mesh.vertices_begin(), cog_it=cogs.begin(); v_it!=v_end; ++v_it, ++cog_it){
            if ( !mesh.is_boundary( *v_it ) ) {
                OpenMesh::Vec3f oldP = mesh.point(*v_it);
                OpenMesh::Vec3f L = *cog_it;
                OpenMesh::Vec3f P = oldP + lambda * L;
                mesh.set_point( *v_it, P );
            }
        }
    }

    return mesh;
}
示例#2
0
文件: main.cpp 项目: alhunor/projects
// https://msdn.microsoft.com/en-us/library/ms182372.aspx -< Profiler
int main(int argc, char **argv)
{
	//ann_test();

	glutInit(&argc, argv);

	ValenceViewer window("Wireframe", 512, 512);

//	window.open_mesh("bunny.off");
	window.open_mesh("torus(10,3,50).off");

	glutMainLoop();
	
	
	/*
	cgal<myPoint> cg;
	pointSet<myPoint> ps("pentagram.pts");
	cg = ps;
	cg.polyStats();
	cout<<cg.inside(Point(15,0))<<endl; // yes
	cout<<cg.inside(Point(15,0.5))<<endl; // yes
	cout<<cg.inside(Point(1,1))<<endl; // yes
	cout<<cg.inside(Point(100,100))<<endl; // no
	return;
*/
	
//	testMyPolyTriangulation();
	

/*	LightVector<double> angles(7);
	angles.fill(0);
//	double lens[7] = {3, 6, 8, 10, 4, 9, 2};
	double lens[7] = {10, 3, 8, 10, 4, 9, 7};
	LightVector<double> edgeLengths(7, lens);
	mp.init(angles, edgeLengths);
	mp.list();
	mp.breakDown(1.618, true); // use the golden ratio, go clockwise
	mp.list();
	mp.breakDown(1.618, false); // use the golden ratio, go counter-clockwise
	mp.list();
	mp.head->clear();
	mp.head = NULL;
	return; */

	//tutorial1();
	//tutorial2("tetrahedron.off", "tetrahedron2.off",5);
	//tutorial1Hu();

//	Mat3 m(1,2,3,4,4,6,7,8,9);
//	Mat3 m2 = m.inverse();
//	cout<<m.determinant()<<endl;
//	cout<<m2;


	 TriMesh mesh2 = createTorus(10, 3, 50);
	 ring ri(mesh2);
	 LightVector<TriMesh::VertexHandle> vhv = ri.getRing(TriMesh::VertexHandle(0), 2);

	 for (unsigned int i= 0; i<vhv.size(); ++i)
	 {
		cout<< vhv[i]<<"  ";
	 }
	 OpenMesh::IO::write_mesh(mesh2, "torus.off");

	mesh2.request_face_normals();
	mesh2.request_vertex_normals();
	mesh2.update_normals();


	TriMesh::VertexHandle vh = TriMesh::VertexHandle(5);
	TriMesh::VertexFaceIter vfi = mesh2.vf_iter(vh);
	int cc=0;
	OpenMesh::Vec3f norm (0, 0, 0), normv;
	while (vfi)
	{
		cout<<"+"<<vfi.handle()<<endl;
		norm += mesh2.normal(*vfi);
		++cc;
		++vfi;
	}
	double len = norm.length();
	if (len != 0)
	{
		norm *= 1/len;
	}

	normv = mesh2.normal(vh);
	
	meshVolume(mesh2);

	return 0;

	TriMesh mesh;
	 //mesh = createSphere(2.0f,4); OpenMesh::IO::write_mesh(mesh, "tetraSphere.off");
	//mesh = createTetra(2); OpenMesh::IO::write_mesh(mesh, "tetra.off"); readmesh(mesh, "tetra.off");

//	readmesh(mesh, "sphereholes.off");
	readmesh(mesh, "lyukas.off");

	// suboptimal, add normals to all faces while we need it only for the 1-ring around the hole
	if ( ! mesh.has_face_normals())
		mesh.request_face_normals();
//	mesh.update_normals();

	holeFiller hf(mesh);
	hf.findHoles();
	hf.displayHoles();
//	hf.fill(0);

// Az emberkeben, i.e. readmesh(mesh, "lyukas.off");
//	hf.fill(0); // hat
//	hf.fill(1); // has
	hf.fill(2); // fej
//	printOff(mesh, holes[2]);

	mesh.release_face_normals(); // always release after request

//	closeHole(mesh, holes[1]);
//	closeHole(mesh, holes[0]);
//	closeHole(mesh, holes[2]);


/*	mesh.request_face_normals();
	if (mesh.has_vertex_normals() ) mesh.update_vertex_normals();

  for (; v_it!=v_end; ++v_it)
    this->set_normal(v_it.handle(), calc_vertex_normal(v_it.handle()));
*/



/*	readmesh(mesh, "icosahedron.off");
	OpenMesh::Vec3f P(-2,0.2,2);
	OpenMesh::FaceHandle fh = faceClosestToPoint(mesh,P);
	cout<<fh.idx();
	
	extendMesh(mesh, fh, P, true);
	OpenMesh::IO::write_mesh(mesh, "ico--.off");
	*/

	//cout<<"Volume = "<<meshVolume(mesh)<<endl;
//	OpenMesh::IO::write_mesh(mesh, "spherevolt.off");
	OpenMesh::IO::write_mesh(mesh, "lyukasvolt.off");
} // void main()