⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mesh.h

📁 此代码主要用于汽车车身的优化
💻 H
字号:
// Mesh.h: interface for the Mesh class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MESH_H__5BD4F6BC_11A9_46C6_A2F8_F0A232B03ECC__INCLUDED_)
#define AFX_MESH_H__5BD4F6BC_11A9_46C6_A2F8_F0A232B03ECC__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Edge.h"
#include "Vector.h"

class Face;
class Vertex;
class Edge;

#include <set>
#include <vector>
#include <functional>

using namespace std;

#define FOR_EACH_VERTEX(itr) 		for( VERTEXPOS itr = m_pVertexes->begin(); itr != m_pVertexes->end(); ++ itr)
#define FOR_EACH_SUBVERTEX(itr) 	for( VERTEXPOS itr = m_pSubdivVertexes->begin(); itr != m_pSubdivVertexes->end(); ++ itr)
#define FOR_EACH_EDGE(itr) 			for( EDGEPOS itr = m_edges.begin(); itr != m_edges.end(); ++ itr)
#define FOR_EACH_FACE(itr) 			for( FACEPOS itr = m_faces.begin(); itr != m_faces.end(); ++ itr)
#define FOR_EACH_CONST_VERTEX(itr) 		for( VERTEXSET::const_iterator itr = m_pVertexes->begin(); itr != m_pVertexes->end(); ++ itr)
#define FOR_EACH_CONST_SUBVERTEX(itr) 	for( VERTEXSET::const_iterator itr = m_pSubdivVertexes->begin(); itr != m_pSubdivVertexes->end(); ++ itr)
#define FOR_EACH_CONST_EDGE(itr) 			for( EDGESET::const_iterator itr = m_edges.begin(); itr != m_edges.end(); ++ itr)
#define FOR_EACH_CONST_FACE(itr) 			for( FACESET::const_iterator itr = m_faces.begin(); itr != m_faces.end(); ++ itr)
//#define FOR_EACH_ITEM(itr, itrset) 	for( itrset::iterator itr = itrset.begin(); itr != itrset.end(); ++ itr)


class Mesh  
{
public:
	bool load3dsFile(CString fname);
	Mesh* splitTriangleMesh();
	int addSubdivVertex( Vector3d &v );//添加细分顶点函数
	enum /*RenderType*/{ RenderVertex, RenderEdge, RenderFace};//枚举随即顶点,边,面
	
	typedef set< Edge, less< Edge > >			EDGESET;
	typedef set< Edge, less< Edge > >::iterator EDGEPOS;

	typedef vector<Face>				FACESET;
	typedef vector<Face>::iterator		FACEPOS;

	typedef vector<Vertex>				VERTEXSET;
	typedef vector<Vertex>::iterator	VERTEXPOS;//vector类的迭代器

	// problems with FACEPOS ...
	EDGEPOS findAndInsertEdgePos(int bgVertexIdx, int edVertexIdx);//寻找和插入边
	int		addFace(vector<int> & faceVertexsIdx);
	int		addVertex(double x, double y, double z);
	int		addVertex(Vector3d& d);
//	Face*	getAdjFace( const Face &f, const Edge &e );
	int		getAdjFace(int fidx, const Edge &e);	// return -1 for none获取邻接面
	Vertex&	getVertex( int idx );
	Edge&	getEdge(EDGEPOS ep);
	Face&	getFace(int idx);
	void	sortVertexAdjFace(int vi);
	void	saveObjFile( CString objFile );
	bool	loadObjFile( CString fname );
	void	printMeshInfo();
	void	dump() const;
	void	GLSetVertex( Vector3d &v );
	void	GLSetNormal( Vector3d &v );

	void	render( int type );
	void	reset();
	Mesh();
	virtual ~Mesh();

	Mesh*	calcDooSabinSubdivMesh();
	Mesh*	calcCatmallSubdivMesh();
	Mesh*	calcLoopSubdivMeshSep();
	Mesh*	calcLoopSubdivMesh(bool divBeforeLoop);
	Mesh*	calcsqrt3SubdivMeshSep();
	Mesh*   calcsqrt3SubdivMesh(bool divBeforeLoop);
	//Mesh*   preparesqrt3SubdivMesh()
	//Mesh*	sqrt3SubdivMesh(bool divBeforeLoop)
	//Mesh*   sqrt3SubdivMeshSep()
//	void	calcCatmullSubdivVertex();

private:
	void	prepareLoopSubdivMesh();
	void	prepareDooSabinSubdivMesh();
	void	prepareCatmullSubdivData();
    void	preparesqrt3SubdivMesh();
	FACESET		m_faces;//面类向量的对象
	VERTEXSET*	m_pVertexes;		//顶点类向量对象 assume that the vertex will not overlap..
	EDGESET		m_edges;         //边类向量对象
	VERTEXSET*	m_pSubdivVertexes;	//顶点类向量对象 use pointer such that vertex can be quickly copied from this to subdiv mesh
};

#endif // !defined(AFX_MESH_H__5BD4F6BC_11A9_46C6_A2F8_F0A232B03ECC__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -