当前位置: 首页>>代码示例>>C++>>正文


C++ Solid::numVertices方法代码示例

本文整理汇总了C++中Solid::numVertices方法的典型用法代码示例。如果您正苦于以下问题:C++ Solid::numVertices方法的具体用法?C++ Solid::numVertices怎么用?C++ Solid::numVertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Solid的用法示例。


在下文中一共展示了Solid::numVertices方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[])
{
	// Read in the obj file
	Solid mesh;
	OBJFileReader of;
	std::ifstream in(argv[1]);
	of.readToSolid(&mesh, in);
	
	
	
	

	//answer part
	Solid meshCopy;
	mesh.copy(meshCopy);
	
	//storing all vertices
	int i=0;
	SolidVertexIterator veriter(&mesh);
	Vertex *allvert[mesh.numVertices()];
	for(i=0;!veriter.end();i++,++veriter)
	{
		allvert[i]=*veriter;
	}
	
	//storing all edges
	SolidEdgeIterator eiter(&mesh);
	Edge *alledges[mesh.numEdges()];
	for(i=0;!eiter.end();i++,++eiter)
	{
		alledges[i]=*eiter;
	}
	
	
	Edge *swapList[mesh.numFaces()];
	Edge *splitSwap[2]={NULL,NULL};
	
	//getting max face
	SolidFaceIterator fciter(&mesh);
	int maxfcid=-1;
	for(; !fciter.end(); ++fciter)
	{
		if((*fciter)->id()>maxfcid)
			maxfcid=(*fciter)->id();
	}
	
	//splitting and swapping by iterating through edges
	SolidEdgeIterator eitercpy(&meshCopy);
	int j;
	double x,y,z;
	for(i=0,j=0;i<(sizeof(alledges)/sizeof(*alledges));i++,++eitercpy)
	{
		splitSwap[0]=splitSwap[1]=NULL;
		Vertex *evert1= mesh.edgeVertex1(alledges[i]);
		Vertex *evert2= mesh.edgeVertex2(alledges[i]);
		Vertex *ver1=mesh.edgeSplit(alledges[i],splitSwap,maxfcid);
		if(splitSwap[0]!=NULL)
			swapList[j++]=splitSwap[0];
		if(splitSwap[1]!=NULL)
			swapList[j++]=splitSwap[1];
		
		//position of new vertex determined here
		if(mesh.isBoundary(*eitercpy))
		{
			//printf("Check");
			x=(evert1->point()(0)/2)+(evert2->point()(0)/2);
			y=(evert1->point()(1)/2)+(evert2->point()(1)/2);
			z=(evert1->point()(2)/2)+(evert2->point()(2)/2);
			//printf("\n%f %f %f\n",x,y,z);
		}
		else
		{
			x=((evert1->point()(0))+(evert2->point()(0)))*(3.0/8.0);
			y=((evert1->point()(1))+(evert2->point()(1)))*(3.0/8.0);
			z=((evert1->point()(2))+(evert2->point()(2)))*(3.0/8.0);
			x+=(((((*eitercpy)->halfedge(0))->he_next())->target())->point()(0)/8.0)+(((((*eitercpy)->halfedge(1))->he_next())->target())->point()(0)/8.0);
			y+=(((((*eitercpy)->halfedge(0))->he_next())->target())->point()(1)/8.0)+(((((*eitercpy)->halfedge(1))->he_next())->target())->point()(1)/8.0);
			z+=(((((*eitercpy)->halfedge(0))->he_next())->target())->point()(2)/8.0)+(((((*eitercpy)->halfedge(1))->he_next())->target())->point()(2)/8.0);
		}
		
		ver1->point()=Point(x,y,z);
	}
	
	
	for(i=0;i<(sizeof(swapList)/sizeof(*swapList));i++)
	{
		Edge *e=swapList[i];
		mesh.edgeSwap(e,((e->halfedge(0))->he_next())->target(),((e->halfedge(1))->he_next())->target());
	}
	
	
	
	
	//new position of old vertices determined here
	SolidVertexIterator veritercpy(&meshCopy);
	double tem1,tem2,tem3,alpha;
	for(i=0;i<(sizeof(allvert)/sizeof(*allvert));i++,++veritercpy)
	{
		Vertex *oldv=allvert[i];
		//printf("\n%f %f %f -> ",oldv->point()(0),oldv->point()(1),oldv->point()(2));
//.........这里部分代码省略.........
开发者ID:snrao310,项目名称:LoopSubdivition-for-HalfEdgeMesh-Library,代码行数:101,代码来源:Subdivision.cpp

示例2: main


//.........这里部分代码省略.........
			harmonicPoint[id] = hUpdate; //step 3

		}
		// compute mass center
		Point mass = { 0.0, 0.0, 0.0 };
		viter.reset();

		for (; !viter.end(); ++viter)//step2
		{
			Vertex *vertmp = *viter;
			mass += vertmp->point();
		}
		mass = mass / 2502;

		// h update w/ mass
		viter.reset();
		for (; !viter.end(); ++viter)//step2
		{
			Vertex *vertmp = *viter;
			int id = vertmp->id() - 1;
			Normal[id] += harmonicPoint[id];
			Normal[id] -= mass;
			Normal[id] = Normal[id] / Normal[id].norm();
		}

		//h energy
		edgeiter.reset();

		for (; !edgeiter.end(); ++edgeiter) {
			Edge *e = *edgeiter;

			Vertex *s = mesh.edgeVertex1(e);
			Vertex *t = mesh.edgeVertex2(e);

			std::unordered_map<Edge*, double>::const_iterator got = edgemap.find(e);
			double K = got->second;

			newHEnergy += (Normal[s->id() - 1] - Normal[t->id() - 1]).norm2()*K;

		}
		viter.reset();
		//h map update
		for (; !viter.end(); ++viter) {
			Vertex *vertmp = *viter;
			vertmp->point() = Normal[vertmp->id() - 1];
		}

	}

	/***conformal****/


	// Write out the resultant obj file
	int vObjID = 1;
	std::map<int, int> vidToObjID;

	std::ofstream os(argv[2]);

	SolidVertexIterator iter(&mesh);

	for (; !iter.end(); ++iter)
	{
		Vertex *v = *iter;
		Point p = v->point();
		os << "v " << p[0] << " " << p[1] << " " << p[2] << std::endl;
		vidToObjID[v->id()] = vObjID++;
	}
	os << "# " << (unsigned int)mesh.numVertices() << " vertices" << std::endl;


	//texture
	float u = 0.0, v = 0.0;
	for (iter.reset(); !iter.end(); ++iter)
	{
		Vertex *vv = *iter;
		std::string key("uv");
		std::string s = Trait::getTraitValue(vv->string(), key);
		if (s.length() > 0)
		{
			sscanf(s.c_str(), "%f %f", &u, &v);
		}
		os << "vt " << u << " " << v << std::endl;
	}
	os << "# " << (unsigned int)mesh.numVertices() << " texture coordinates" << std::endl;

	SolidFaceIterator fiter(&mesh);
	for (; !fiter.end(); ++fiter)
	{
		Face *f = *fiter;
		FaceVertexIterator viter(f);
		os << "f ";
		for (; !viter.end(); ++viter)
		{
			Vertex *v = *viter;
			os << vidToObjID[v->id()] << "/" << vidToObjID[v->id()] << " ";
		}
		os << std::endl;
	}
	os.close();
}
开发者ID:RadiumP,项目名称:Computer-Graphics,代码行数:101,代码来源:Conformal.cpp


注:本文中的Solid::numVertices方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。