• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

PolyVoxCore/include/PolyVoxCore/SurfaceMesh.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 Copyright (c) 2005-2009 David Williams
00003 
00004 This software is provided 'as-is', without any express or implied
00005 warranty. In no event will the authors be held liable for any damages
00006 arising from the use of this software.
00007 
00008 Permission is granted to anyone to use this software for any purpose,
00009 including commercial applications, and to alter it and redistribute it
00010 freely, subject to the following restrictions:
00011 
00012     1. The origin of this software must not be misrepresented; you must not
00013     claim that you wrote the original software. If you use this software
00014     in a product, an acknowledgment in the product documentation would be
00015     appreciated but is not required.
00016 
00017     2. Altered source versions must be plainly marked as such, and must not be
00018     misrepresented as being the original software.
00019 
00020     3. This notice may not be removed or altered from any source
00021     distribution.   
00022 *******************************************************************************/
00023 
00024 #ifndef __PolyVox_SurfaceMesh_H__
00025 #define __PolyVox_SurfaceMesh_H__
00026 
00027 #include "PolyVoxImpl/TypeDef.h"
00028 
00029 #include "PolyVoxCore/Region.h"
00030 #include "PolyVoxCore/VertexTypes.h" //Should probably do away with this on in the future...
00031 
00032 #include <algorithm>
00033 #include <cstdlib>
00034 #include <list>
00035 #include <memory>
00036 #include <set>
00037 #include <vector>
00038 
00039 namespace PolyVox
00040 {
00041     class LodRecord
00042     {
00043     public:
00044         int beginIndex;
00045         int endIndex; //Let's put it just past the end STL style
00046     };
00047 
00048     template <typename VertexType>
00049     class SurfaceMesh
00050     {
00051     public:
00052        SurfaceMesh();
00053        ~SurfaceMesh();     
00054 
00055        const std::vector<uint32_t>& getIndices(void) const;
00056        uint32_t getNoOfIndices(void) const;
00057        uint32_t getNoOfNonUniformTrianges(void) const;
00058        uint32_t getNoOfUniformTrianges(void) const;
00059        uint32_t getNoOfVertices(void) const;       
00060        std::vector<VertexType>& getRawVertexData(void); //FIXME - this should be removed
00061        const std::vector<VertexType>& getVertices(void) const;
00062 
00063        void addTriangle(uint32_t index0, uint32_t index1, uint32_t index2);
00064        void addTriangleCubic(uint32_t index0, uint32_t index1, uint32_t index2);
00065        uint32_t addVertex(const VertexType& vertex);
00066        void clear(void);
00067        bool isEmpty(void) const;
00068 
00069        void scaleVertices(float amount);
00070        void translateVertices(const Vector3DFloat& amount);
00071 
00072        //THESE FUNCTIONS TO BE REMOVED IN THE FUTURE. OR AT LEAST MOVED OUT OF THIS CLASS INTO FREE FUNCTIONS.
00073        //THEY ARE CAUSING PROBLEMS WITH THE SWIG BINDINGS. THE FUNCTIONS REGARDING NORMALS MAKE NO SENSE WHEN
00074        //A VERTEX MIGHT NOT HAVE NORMALS. THE EXTRACT SUBSET FUNCTION SHOULD MAYBE BE APPLICATION CODE, AT ANY
00075        //RATE THE STD::SET CAUSES PROBLEMS WITH SWIG. IF YOU UNCOMMENT ANY OF THESE FUNCTIONS, PLEASE POST ON
00076        //THE FORUM SO WE CAN KNOW THE FUNCTIONALITY IS STILL NEEDED IN SOME FORM.
00077        //void sumNearbyNormals(bool bNormaliseResult = true);
00078        //polyvox_shared_ptr< SurfaceMesh<VertexType> > extractSubset(std::set<uint8_t> setMaterials);
00079        //void generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices = false);
00080 
00081        int noOfDegenerateTris(void);
00082        void removeDegenerateTris(void);
00083        void removeUnusedVertices(void);
00084 
00085        Region m_Region;
00086 
00087        int32_t m_iTimeStamp;
00088 
00089        int32_t m_iNoOfLod0Tris;
00090     
00091     public:     
00092         std::vector<uint32_t> m_vecTriangleIndices;
00093         std::vector<VertexType> m_vecVertices;
00094 
00095         std::vector<LodRecord> m_vecLodRecords;
00096 
00097         //The set of materials which are in this mesh. Only those materials
00098         //which cover a whole triangle are counted. Materials which only
00099         //exist on a material boundary do not count.
00100         std::set<uint8_t> m_mapUsedMaterials;
00101     };  
00102 
00103     template <typename VertexType>
00104     polyvox_shared_ptr< SurfaceMesh<VertexType> > extractSubset(SurfaceMesh<VertexType>& inputMesh, std::set<uint8_t> setMaterials);
00105 }
00106 
00107 #include "PolyVoxCore/SurfaceMesh.inl"
00108 
00109 #endif /* __SurfaceMesh_H__ */

Generated on Sat Nov 19 2011 00:27:31 for PolyVox by  doxygen 1.7.1