Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __PolyVox_MeshDecimator_H__
00025 #define __PolyVox_MeshDecimator_H__
00026
00027 #include "PolyVoxCore/SurfaceMesh.h"
00028 #include "PolyVoxCore/Vector.h"
00029 #include "PolyVoxCore/VertexTypes.h"
00030
00031 #include <bitset>
00032 #include <vector>
00033
00034 namespace PolyVox
00035 {
00067 template <typename VertexType>
00068 class MeshDecimator
00069 {
00070
00071
00072 enum RegionFaceFlags
00073 {
00074 RFF_ON_REGION_FACE_NEG_X,
00075 RFF_ON_REGION_FACE_POS_X ,
00076 RFF_ON_REGION_FACE_NEG_Y ,
00077 RFF_ON_REGION_FACE_POS_Y ,
00078 RFF_ON_REGION_FACE_NEG_Z ,
00079 RFF_ON_REGION_FACE_POS_Z,
00080 RFF_NO_OF_REGION_FACE_FLAGS
00081 };
00082
00083
00084
00085 struct InitialVertexMetadata
00086 {
00087 Vector3DFloat normal;
00088 bool isOnMaterialEdge;
00089 std::bitset<RFF_NO_OF_REGION_FACE_FLAGS> isOnRegionFace;
00090 };
00091
00092
00093 struct Triangle
00094 {
00095 uint32_t v0;
00096 uint32_t v1;
00097 uint32_t v2;
00098 Vector3DFloat normal;
00099 };
00100
00101 struct IntVertex
00102 {
00103 int32_t x;
00104 int32_t y;
00105 int32_t z;
00106 uint32_t index;
00107
00108 IntVertex(int32_t xVal, int32_t yVal, int32_t zVal, uint32_t indexVal)
00109 :x(xVal)
00110 ,y(yVal)
00111 ,z(zVal)
00112 ,index(indexVal)
00113 {
00114 }
00115
00116 bool operator==(const IntVertex& rhs) const
00117 {
00118 return (x == rhs.x) && (y == rhs.y) && (z == rhs.z);
00119 }
00120
00121 bool operator<(const IntVertex& rhs) const
00122 {
00123 if (z < rhs.z)
00124 return true;
00125 if (rhs.z < z)
00126 return false;
00127
00128 if (y < rhs.y)
00129 return true;
00130 if (rhs.y < y)
00131 return false;
00132
00133 if (x < rhs.x)
00134 return true;
00135 if (rhs.x < x)
00136 return false;
00137
00138 return false;
00139 }
00140 };
00141
00142 public:
00144 MeshDecimator(const SurfaceMesh<VertexType>* pInputMesh, SurfaceMesh<VertexType>* pOutputMesh, float fEdgeCollapseThreshold = 0.95f);
00145
00147 void execute();
00148
00149 private:
00150
00151 void fillInitialVertexMetadata(std::vector<InitialVertexMetadata>& vecInitialVertexMetadata);
00152
00153 void buildConnectivityData(void);
00154
00155 bool attemptEdgeCollapse(uint32_t uSrc, uint32_t uDest);
00156
00157 const SurfaceMesh<VertexType>* m_pInputMesh;
00158 SurfaceMesh<VertexType>* m_pOutputMesh;
00159
00160 uint32_t performDecimationPass(float m_fMinDotProductForCollapse);
00161 bool isSubset(std::bitset<RFF_NO_OF_REGION_FACE_FLAGS> a, std::bitset<RFF_NO_OF_REGION_FACE_FLAGS> b);
00162
00163 bool canCollapseEdge(uint32_t uSrc, uint32_t uDest);
00164 bool canCollapseNormalEdge(uint32_t uSrc, uint32_t uDst);
00165 bool canCollapseRegionEdge(uint32_t uSrc, uint32_t uDst);
00166 bool canCollapseMaterialEdge(uint32_t uSrc, uint32_t uDst);
00167 bool collapseChangesFaceNormals(uint32_t uSrc, uint32_t uDst, float fThreshold);
00168
00169
00170
00171 std::vector<bool> vertexLocked;
00172 std::vector<uint32_t> vertexMapper;
00173
00174 std::vector<Triangle> m_vecTriangles;
00175 std::vector< std::vector<uint32_t> > trianglesUsingVertex;
00176
00177 std::vector<InitialVertexMetadata> m_vecInitialVertexMetadata;
00178
00179 float m_fMinDotProductForCollapse;
00180 };
00181 }
00182
00183 #include "PolyVoxCore/MeshDecimator.inl"
00184
00185 #endif //__PolyVox_MeshDecimator_H__