diff --git a/CMakeLists.txt b/CMakeLists.txt index f93b4668..bc49c696 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ SET(SRC_FILES source/AbstractSurfacePatch.cpp source/Block.cpp source/HalfEdgeSurfacePatch.cpp + source/IndexedSurfacePatch.cpp source/MarchingCubesTables.cpp source/MaterialMap.cpp source/MaterialMapManager.cpp @@ -26,6 +27,7 @@ SET(INC_FILES include/Block.h include/Constants.h include/HalfEdgeSurfacePatch.h + include/IndexedSurfacePatch.h include/IntegralVector3.h include/MarchingCubesTables.h include/MaterialMap.h diff --git a/include/AbstractSurfacePatch.h b/include/AbstractSurfacePatch.h new file mode 100644 index 00000000..8873daa0 --- /dev/null +++ b/include/AbstractSurfacePatch.h @@ -0,0 +1,26 @@ +#ifndef __AbstractSurfacePatch_H__ +#define __AbstractSurfacePatch_H__ + +#include "SurfaceTypes.h" +#include "Surfacevertex.h" + +namespace Ogre +{ + class AbstractSurfacePatch + { + public: + AbstractSurfacePatch(); + virtual ~AbstractSurfacePatch(); + + SurfaceVertexIterator getVerticesBegin(void); + SurfaceVertexIterator getVerticesEnd(void); + + virtual void addTriangle(const SurfaceVertex& v0,const SurfaceVertex& v1,const SurfaceVertex& v2) = 0; + virtual void fillVertexAndIndexData(std::vector& vecVertices, std::vector& vecIndices) = 0; + + protected: + std::set m_listVertices; + }; +} + +#endif /* __AbstractSurfacePatch_H__ */ diff --git a/include/HalfEdgeSurfacePatch.h b/include/HalfEdgeSurfacePatch.h index 2a61a741..014b9ee8 100644 --- a/include/HalfEdgeSurfacePatch.h +++ b/include/HalfEdgeSurfacePatch.h @@ -1,5 +1,5 @@ -#ifndef __SurfacePatch_H__ -#define __SurfacePatch_H__ +#ifndef __HalfEdgeSurfacePatch_H__ +#define __HalfEdgeSurfacePatch_H__ #include #include @@ -12,11 +12,11 @@ namespace Ogre { - class SurfacePatch : public AbstractSurfacePatch + class HalfEdgeSurfacePatch : public AbstractSurfacePatch { public: - SurfacePatch(); - ~SurfacePatch(); + HalfEdgeSurfacePatch(); + ~HalfEdgeSurfacePatch(); //This allow users of the class to iterate over its contents. SurfaceEdgeIterator getEdgesBegin(void); @@ -51,4 +51,4 @@ namespace Ogre }; } -#endif /* __SurfacePatch_H__ */ +#endif /* __HalfEdgeSurfacePatch_H__ */ diff --git a/include/IndexedSurfacePatch.h b/include/IndexedSurfacePatch.h new file mode 100644 index 00000000..638ee24b --- /dev/null +++ b/include/IndexedSurfacePatch.h @@ -0,0 +1,29 @@ +#ifndef __IndexedSurfacePatch_H__ +#define __IndexedSurfacePatch_H__ + +#include +#include + +#include "AbstractSurfacePatch.h" +#include "IntegralVector3.h" +#include "SurfaceTypes.h" +#include "VolumeIterator.h" + + +namespace Ogre +{ + class IndexedSurfacePatch : public AbstractSurfacePatch + { + public: + IndexedSurfacePatch(); + ~IndexedSurfacePatch(); + + void addTriangle(const SurfaceVertex& v0,const SurfaceVertex& v1,const SurfaceVertex& v2); + void fillVertexAndIndexData(std::vector& vecVertices, std::vector& vecIndices); + + private: + std::vector m_vecTriangleIndices; + }; +} + +#endif /* __IndexedSurfacePatch_H__ */ diff --git a/source/AbstractSurfacePatch.cpp b/source/AbstractSurfacePatch.cpp new file mode 100644 index 00000000..4061bdd4 --- /dev/null +++ b/source/AbstractSurfacePatch.cpp @@ -0,0 +1,22 @@ +#include "AbstractSurfacePatch.h" + +namespace Ogre +{ + AbstractSurfacePatch::AbstractSurfacePatch() + { + } + + AbstractSurfacePatch::~AbstractSurfacePatch() + { + } + + SurfaceVertexIterator AbstractSurfacePatch::getVerticesBegin(void) + { + return m_listVertices.begin(); + } + + SurfaceVertexIterator AbstractSurfacePatch::getVerticesEnd(void) + { + return m_listVertices.end(); + } +} \ No newline at end of file diff --git a/source/HalfEdgeSurfacePatch.cpp b/source/HalfEdgeSurfacePatch.cpp index 28162886..73886c60 100644 --- a/source/HalfEdgeSurfacePatch.cpp +++ b/source/HalfEdgeSurfacePatch.cpp @@ -12,53 +12,53 @@ namespace Ogre { - SurfacePatch::SurfacePatch() + HalfEdgeSurfacePatch::HalfEdgeSurfacePatch() { m_listVertices.clear(); m_listTriangles.clear(); m_listEdges.clear(); } - SurfacePatch::~SurfacePatch() + HalfEdgeSurfacePatch::~HalfEdgeSurfacePatch() { } - SurfaceEdgeIterator SurfacePatch::getEdgesBegin(void) + SurfaceEdgeIterator HalfEdgeSurfacePatch::getEdgesBegin(void) { return m_listEdges.begin(); } - SurfaceEdgeIterator SurfacePatch::getEdgesEnd(void) + SurfaceEdgeIterator HalfEdgeSurfacePatch::getEdgesEnd(void) { return m_listEdges.end(); } - SurfaceTriangleIterator SurfacePatch::getTrianglesBegin(void) + SurfaceTriangleIterator HalfEdgeSurfacePatch::getTrianglesBegin(void) { return m_listTriangles.begin(); } - SurfaceTriangleIterator SurfacePatch::getTrianglesEnd(void) + SurfaceTriangleIterator HalfEdgeSurfacePatch::getTrianglesEnd(void) { return m_listTriangles.end(); } - uint SurfacePatch::getNoOfEdges(void) const + uint HalfEdgeSurfacePatch::getNoOfEdges(void) const { return m_listEdges.size(); } - uint SurfacePatch::getNoOfTriangles(void) const + uint HalfEdgeSurfacePatch::getNoOfTriangles(void) const { return m_listTriangles.size(); } - uint SurfacePatch::getNoOfVertices(void) const + uint HalfEdgeSurfacePatch::getNoOfVertices(void) const { return m_listVertices.size(); } - void SurfacePatch::addTriangle(const SurfaceVertex& v0,const SurfaceVertex& v1,const SurfaceVertex& v2) + void HalfEdgeSurfacePatch::addTriangle(const SurfaceVertex& v0,const SurfaceVertex& v1,const SurfaceVertex& v2) { SurfaceVertexIterator v0Iter = findOrAddVertex(v0); SurfaceVertexIterator v1Iter = findOrAddVertex(v1); @@ -91,17 +91,17 @@ namespace Ogre const_cast(*v2v0Iter).setTriangle(iterTriangle); } - SurfaceVertexIterator SurfacePatch::findOrAddVertex(const SurfaceVertex& vertex) + SurfaceVertexIterator HalfEdgeSurfacePatch::findOrAddVertex(const SurfaceVertex& vertex) { return m_listVertices.insert(vertex).first; } - SurfaceEdgeIterator SurfacePatch::findEdge(const SurfaceVertexIterator& source, const SurfaceVertexIterator& target) + SurfaceEdgeIterator HalfEdgeSurfacePatch::findEdge(const SurfaceVertexIterator& source, const SurfaceVertexIterator& target) { return m_listEdges.find(SurfaceEdge(target,source)); } - SurfaceEdgeIterator SurfacePatch::findOrAddEdge(const SurfaceVertexIterator& source, const SurfaceVertexIterator& target) + SurfaceEdgeIterator HalfEdgeSurfacePatch::findOrAddEdge(const SurfaceVertexIterator& source, const SurfaceVertexIterator& target) { SurfaceEdge edge(target,source); std::pair insertionResult = m_listEdges.insert(edge); @@ -122,7 +122,7 @@ namespace Ogre return edgeIter; } - bool SurfacePatch::canRemoveVertexFrom(SurfaceVertexIterator vertexIter, std::list listConnectedIter, bool isEdge) + bool HalfEdgeSurfacePatch::canRemoveVertexFrom(SurfaceVertexIterator vertexIter, std::list listConnectedIter, bool isEdge) { bool allXMatch = true; bool allYMatch = true; @@ -172,7 +172,7 @@ namespace Ogre && (twoEdgesMatch); } - std::list SurfacePatch::findConnectedVertices(SurfaceVertexIterator vertexIter, bool& isEdge) + std::list HalfEdgeSurfacePatch::findConnectedVertices(SurfaceVertexIterator vertexIter, bool& isEdge) { isEdge = false; std::list result; @@ -234,7 +234,7 @@ namespace Ogre return result; } - uint SurfacePatch::decimate(void) + uint HalfEdgeSurfacePatch::decimate(void) { uint uNoRemoved = 0; //LogManager::getSingleton().logMessage("\n\nPerforming decimation"); @@ -333,7 +333,7 @@ namespace Ogre return uNoRemoved; } - void SurfacePatch::triangulate(std::list listVertices) + void HalfEdgeSurfacePatch::triangulate(std::list listVertices) { std::list::iterator v0IterIter = listVertices.begin(); std::list::iterator v1IterIter = listVertices.begin(); @@ -354,7 +354,7 @@ namespace Ogre } } - bool SurfacePatch::isPolygonConvex(std::list listVertices, Vector3 normal) + bool HalfEdgeSurfacePatch::isPolygonConvex(std::list listVertices, Vector3 normal) { std::list::iterator v0IterIter = listVertices.begin(); std::list::iterator v1IterIter = listVertices.begin(); @@ -387,7 +387,7 @@ namespace Ogre return true; } - void SurfacePatch::fillVertexAndIndexData(std::vector& vecVertices, std::vector& vecIndices) + void HalfEdgeSurfacePatch::fillVertexAndIndexData(std::vector& vecVertices, std::vector& vecIndices) { vecVertices.resize(m_listVertices.size()); std::copy(m_listVertices.begin(), m_listVertices.end(), vecVertices.begin()); diff --git a/source/IndexedSurfacePatch.cpp b/source/IndexedSurfacePatch.cpp new file mode 100644 index 00000000..a2092d00 --- /dev/null +++ b/source/IndexedSurfacePatch.cpp @@ -0,0 +1,38 @@ +#include "IndexedSurfacePatch.h" + +namespace Ogre +{ + IndexedSurfacePatch::IndexedSurfacePatch() + { + } + + IndexedSurfacePatch::~IndexedSurfacePatch() + { + } + + void IndexedSurfacePatch::addTriangle(const SurfaceVertex& v0,const SurfaceVertex& v1,const SurfaceVertex& v2) + { + SurfaceVertexIterator v0Iter = m_listVertices.insert(v0).first; + SurfaceVertexIterator v1Iter = m_listVertices.insert(v1).first; + SurfaceVertexIterator v2Iter = m_listVertices.insert(v2).first; + + m_vecTriangleIndices.push_back(v0Iter); + m_vecTriangleIndices.push_back(v1Iter); + m_vecTriangleIndices.push_back(v2Iter); + } + + void IndexedSurfacePatch::fillVertexAndIndexData(std::vector& vecVertices, std::vector& vecIndices) + { + vecVertices.resize(m_listVertices.size()); + std::copy(m_listVertices.begin(), m_listVertices.end(), vecVertices.begin()); + + //vecIndices.resize(m_listTriangles.size() * 3); + for(std::vector::iterator iterVertices = m_vecTriangleIndices.begin(); iterVertices != m_vecTriangleIndices.end(); ++iterVertices) + { + std::vector::iterator iterVertex; + + iterVertex = lower_bound(vecVertices.begin(), vecVertices.end(), **iterVertices); + vecIndices.push_back(iterVertex - vecVertices.begin()); + } + } +} \ No newline at end of file diff --git a/source/PolyVoxSceneManager.cpp b/source/PolyVoxSceneManager.cpp index 6f08e6ec..8a1b48bb 100644 --- a/source/PolyVoxSceneManager.cpp +++ b/source/PolyVoxSceneManager.cpp @@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "SurfaceVertex.h" #include "SurfaceEdge.h" #include "HalfEdgeSurfacePatch.h" +#include "IndexedSurfacePatch.h" #include "PolyVoxSceneManager.h" #include "VolumeIterator.h" #include "VolumeManager.h" @@ -622,15 +623,15 @@ namespace Ogre if(surfacePatchMapResult.find(material0) == surfacePatchMapResult.end()) { - surfacePatchMapResult.insert(std::make_pair(material0,new SurfacePatch)); + surfacePatchMapResult.insert(std::make_pair(material0,new IndexedSurfacePatch)); } if(surfacePatchMapResult.find(material1) == surfacePatchMapResult.end()) { - surfacePatchMapResult.insert(std::make_pair(material1,new SurfacePatch)); + surfacePatchMapResult.insert(std::make_pair(material1,new IndexedSurfacePatch)); } if(surfacePatchMapResult.find(material2) == surfacePatchMapResult.end()) { - surfacePatchMapResult.insert(std::make_pair(material2,new SurfacePatch)); + surfacePatchMapResult.insert(std::make_pair(material2,new IndexedSurfacePatch)); } SurfaceVertex surfaceVertex0Alpha1(vertex0,1.0); diff --git a/source/SurfacePatchRenderable.cpp b/source/SurfacePatchRenderable.cpp index e428ca40..cf16def1 100644 --- a/source/SurfacePatchRenderable.cpp +++ b/source/SurfacePatchRenderable.cpp @@ -51,6 +51,9 @@ namespace Ogre std::vector vecIndices; patchToRender->fillVertexAndIndexData(vecVertices,vecIndices); + LogManager::getSingleton().logMessage("No of Vertices = " + StringConverter::toString(vecVertices.size())); + LogManager::getSingleton().logMessage("No of Indices = " + StringConverter::toString(vecIndices.size())); + //Initialization stuff mRenderOp.vertexData->vertexCount = vecVertices.size(); mRenderOp.indexData->indexCount = vecIndices.size();