简介

用到了上一个博客的,AddPolygon。
生成的是一个筒状物体。

代码

// CreateCylinder.cpp: 定义控制台应用程序的入口点。
//

//#include "stdafx.h"
#include <iostream>
#include "AddPolygon.h"
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
#include<cmath>

MyMesh* CreateCylinder(int edge, double height) {
	MyMesh * cylinder = new MyMesh;
	MyMesh::VertexHandle * top = AddPolygon(*cylinder, edge, height / 2, true);
	MyMesh::VertexHandle * bottom = AddPolygon(*cylinder, edge, -height / 2, false);
	for (int i = 0; i < edge; i++) {
		int next = (i + 1) % edge;
		std::vector<MyMesh::VertexHandle>face_vhandles;
		face_vhandles.push_back(bottom[i]);
		face_vhandles.push_back(top[next]);
		face_vhandles.push_back(top[i]);
		(*cylinder).add_face(face_vhandles);
		face_vhandles.clear();
		face_vhandles.push_back(bottom[i]);
		face_vhandles.push_back(bottom[next]);
		face_vhandles.push_back(top[next]);
		(*cylinder).add_face(face_vhandles);
	}
	return cylinder;
}


int main()
{
	cout << "Please input edge(int) height(double): \n";
	int edge;
	double height;
	cin >> edge >> height;
	MyMesh * mesh = CreateCylinder(edge, height);
	
	try
	{
		if (!OpenMesh::IO::write_mesh(*mesh, "output4 .off")) {
			std::cerr << "Cannot write mesh to file ' output4 .off ' " << std::endl;
			return 1;
		}
	}
	catch (std::exception&x) {
		std::cerr << x.what() << std::endl;
		return 1;
	}
    return 0;
}


posted on 2019-07-05 15:29  HDU李少帅  阅读(297)  评论(0编辑  收藏  举报