diff --git a/examples/Basic/OpenGLWidget.cpp b/examples/Basic/OpenGLWidget.cpp index 49c0f5c0..a3f6ad96 100644 --- a/examples/Basic/OpenGLWidget.cpp +++ b/examples/Basic/OpenGLWidget.cpp @@ -14,7 +14,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent) { } -void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh) +void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh) { //Convienient access to the vertices and indices const auto& vecIndices = surfaceMesh.getIndices(); @@ -27,7 +27,7 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh), vecVertices.data(), GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(CubicVertex), vecVertices.data(), GL_STATIC_DRAW); //and GL_ELEMENT_ARRAY_BUFFER will contain the indices glGenBuffers(1, &indexBuffer); @@ -36,7 +36,7 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh), 0); //take the first 3 floats from every sizeof(decltype(vecVertices)::value_type) + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(CubicVertex), 0); //take the first 3 floats from every sizeof(decltype(vecVertices)::value_type) glBindVertexArray(0); diff --git a/examples/Basic/OpenGLWidget.h b/examples/Basic/OpenGLWidget.h index 133c21eb..a7cac3ca 100644 --- a/examples/Basic/OpenGLWidget.h +++ b/examples/Basic/OpenGLWidget.h @@ -42,7 +42,7 @@ public: void mousePressEvent(QMouseEvent* event); //Convert a SurfaceMesh to OpenGL index/vertex buffers - void setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh); + void setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh); protected: //Qt OpenGL functions diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 9ec7e3a1..c66067df 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) createSphereInVolume(volData, 30); //A mesh object to hold the result of surface extraction - SurfaceMesh > mesh; + SurfaceMesh > mesh; //Create a surface extractor. Comment out one of the following two lines to decide which type gets created. CubicSurfaceExtractor< SimpleVolume > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); diff --git a/examples/OpenGL/OpenGLImmediateModeSupport.cpp b/examples/OpenGL/OpenGLImmediateModeSupport.cpp index 6c25b915..7aff64df 100644 --- a/examples/OpenGL/OpenGLImmediateModeSupport.cpp +++ b/examples/OpenGL/OpenGLImmediateModeSupport.cpp @@ -29,9 +29,9 @@ freely, subject to the following restrictions: using namespace PolyVox; using namespace std; -void renderRegionImmediateMode(PolyVox::SurfaceMesh >& mesh, unsigned int uLodLevel) +void renderRegionImmediateMode(PolyVox::SurfaceMesh >& mesh, unsigned int uLodLevel) { - const vector >& vecVertices = mesh.getVertices(); + const vector >& vecVertices = mesh.getVertices(); const vector& vecIndices = mesh.getIndices(); int beginIndex = mesh.m_vecLodRecords[uLodLevel].beginIndex; @@ -41,7 +41,7 @@ void renderRegionImmediateMode(PolyVox::SurfaceMesh::const_iterator iterIndex = vecIndices.begin(); iterIndex != vecIndices.end(); ++iterIndex) for(int index = beginIndex; index < endIndex; ++index) { - const PositionMaterialNormal & vertex = vecVertices[vecIndices[index]]; + const MarchingCubesVertex & vertex = vecVertices[vecIndices[index]]; const Vector3DFloat& v3dVertexPos = vertex.getPosition(); //const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength); const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast(mesh.m_Region.getLowerCorner()); diff --git a/examples/OpenGL/OpenGLImmediateModeSupport.h b/examples/OpenGL/OpenGLImmediateModeSupport.h index 671d53a5..9f5aea79 100644 --- a/examples/OpenGL/OpenGLImmediateModeSupport.h +++ b/examples/OpenGL/OpenGLImmediateModeSupport.h @@ -29,6 +29,6 @@ freely, subject to the following restrictions: #include "glew/glew.h" -void renderRegionImmediateMode(PolyVox::SurfaceMesh >& mesh, unsigned int uLodLevel); +void renderRegionImmediateMode(PolyVox::SurfaceMesh >& mesh, unsigned int uLodLevel); #endif //__OpenGLExample_OpenGLImmediateModeSupport_H__ diff --git a/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp b/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp index 7066523a..ae5afd15 100644 --- a/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp +++ b/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp @@ -30,7 +30,7 @@ freely, subject to the following restrictions: using namespace PolyVox; using namespace std; -OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh >& mesh) +OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh >& mesh) { //Represents our filled in OpenGL vertex and index buffer objects. OpenGLSurfaceMesh result; @@ -39,7 +39,7 @@ OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh >& vecVertices = mesh.getVertices(); + const vector >& vecVertices = mesh.getVertices(); const vector& vecIndices = mesh.getIndices(); //If we have any indices... @@ -63,9 +63,9 @@ OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh >::const_iterator iterVertex = vecVertices.begin(); iterVertex != vecVertices.end(); ++iterVertex) + for (vector >::const_iterator iterVertex = vecVertices.begin(); iterVertex != vecVertices.end(); ++iterVertex) { - const PositionMaterialNormal & vertex = *iterVertex; + const MarchingCubesVertex & vertex = *iterVertex; const Vector3DFloat& v3dVertexPos = vertex.getPosition(); //const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength); const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast(mesh.m_Region.getLowerCorner()); diff --git a/examples/OpenGL/OpenGLVertexBufferObjectSupport.h b/examples/OpenGL/OpenGLVertexBufferObjectSupport.h index 73a361f5..fc97dfb8 100644 --- a/examples/OpenGL/OpenGLVertexBufferObjectSupport.h +++ b/examples/OpenGL/OpenGLVertexBufferObjectSupport.h @@ -33,10 +33,10 @@ struct OpenGLSurfaceMesh GLulong noOfIndices; GLuint indexBuffer; GLuint vertexBuffer; - const PolyVox::SurfaceMesh >* sourceMesh; + const PolyVox::SurfaceMesh >* sourceMesh; }; -OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const PolyVox::SurfaceMesh >& mesh); +OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const PolyVox::SurfaceMesh >& mesh); void renderRegionVertexBufferObject(const OpenGLSurfaceMesh& openGLSurfaceMesh, unsigned int uLodLevel); #endif //__OpenGLExample_OpenGLVertexBufferObjectSupport_H__ diff --git a/examples/OpenGL/OpenGLWidget.cpp b/examples/OpenGL/OpenGLWidget.cpp index c761488b..475ba846 100644 --- a/examples/OpenGL/OpenGLWidget.cpp +++ b/examples/OpenGL/OpenGLWidget.cpp @@ -87,7 +87,7 @@ void OpenGLWidget::setVolume(PolyVox::LargeVolume* volDat //Extract the surface for this region //extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), meshCurrent); - std::shared_ptr< SurfaceMesh > > mesh(new SurfaceMesh >); + std::shared_ptr< SurfaceMesh > > mesh(new SurfaceMesh >); MarchingCubesSurfaceExtractor< LargeVolume > surfaceExtractor(volData, PolyVox::Region(regLowerCorner, regUpperCorner), mesh.get()); surfaceExtractor.execute(); @@ -193,7 +193,7 @@ void OpenGLWidget::paintGL() Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ); if(m_mapSurfaceMeshes.find(v3dRegPos) != m_mapSurfaceMeshes.end()) { - std::shared_ptr< SurfaceMesh > > meshCurrent = m_mapSurfaceMeshes[v3dRegPos]; + std::shared_ptr< SurfaceMesh > > meshCurrent = m_mapSurfaceMeshes[v3dRegPos]; unsigned int uLodLevel = 0; //meshCurrent->m_vecLodRecords.size() - 1; if(m_bUseOpenGLVertexBufferObjects) { diff --git a/examples/OpenGL/OpenGLWidget.h b/examples/OpenGL/OpenGLWidget.h index 873a5605..1b4b4612 100644 --- a/examples/OpenGL/OpenGLWidget.h +++ b/examples/OpenGL/OpenGLWidget.h @@ -88,7 +88,7 @@ class OpenGLWidget : public QGLWidget //Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region std::map m_mapOpenGLSurfaceMeshes; - std::map > >, Vector3DUint8Compare> m_mapSurfaceMeshes; + std::map > >, Vector3DUint8Compare> m_mapSurfaceMeshes; unsigned int m_uRegionSideLength; unsigned int m_uVolumeWidthInRegions; diff --git a/examples/Paging/OpenGLWidget.cpp b/examples/Paging/OpenGLWidget.cpp index 734ac02b..0227a66f 100644 --- a/examples/Paging/OpenGLWidget.cpp +++ b/examples/Paging/OpenGLWidget.cpp @@ -15,7 +15,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent) { } -void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh) +void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh) { if((surfaceMesh.getNoOfIndices() == 0) || (surfaceMesh.getNoOfVertices() == 0)) { @@ -25,7 +25,7 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh& vecIndices = surfaceMesh.getIndices(); - const vector >& vecVertices = surfaceMesh.getVertices(); + const vector >& vecVertices = surfaceMesh.getVertices(); //Build an OpenGL index buffer glGenBuffers(1, &indexBuffer); @@ -37,7 +37,7 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh(&(vecVertices[0])); - glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal), pVertices, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(CubicVertex), pVertices, GL_STATIC_DRAW); m_uBeginIndex = 0; m_uEndIndex = vecIndices.size(); @@ -109,8 +109,8 @@ void OpenGLWidget::paintGL() //Bind the vertex buffer glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); - glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal), 0); - //glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12); + glVertexPointer(3, GL_FLOAT, sizeof(CubicVertex), 0); + //glNormalPointer(GL_FLOAT, sizeof(CubicVertex), (GLvoid*)12); glDrawRangeElements(GL_TRIANGLES, m_uBeginIndex, m_uEndIndex-1, m_uEndIndex - m_uBeginIndex, GL_UNSIGNED_INT, 0); } diff --git a/examples/Paging/OpenGLWidget.h b/examples/Paging/OpenGLWidget.h index 1dcddd21..61702be1 100644 --- a/examples/Paging/OpenGLWidget.h +++ b/examples/Paging/OpenGLWidget.h @@ -42,7 +42,7 @@ public: void mousePressEvent(QMouseEvent* event); //Convert a SrfaceMesh to OpenGL index/vertex buffers - void setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh); + void setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh); protected: //Qt OpenGL functions diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index 9a625a6e..c1879427 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -186,7 +186,7 @@ int main(int argc, char *argv[]) std::cout << "Compression ratio: 1 to " << (1.0/(volData.calculateCompressionRatio())) << std::endl; //Extract the surface - SurfaceMesh > mesh; + SurfaceMesh > mesh; CubicSurfaceExtractor< LargeVolume > surfaceExtractor(&volData, reg, &mesh); //MarchingCubesSurfaceExtractor< LargeVolume > surfaceExtractor(&volData, reg, &mesh); //CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, reg, &mesh); diff --git a/examples/SmoothLOD/OpenGLWidget.cpp b/examples/SmoothLOD/OpenGLWidget.cpp index 812a287d..e804240b 100644 --- a/examples/SmoothLOD/OpenGLWidget.cpp +++ b/examples/SmoothLOD/OpenGLWidget.cpp @@ -21,11 +21,11 @@ OpenGLWidget::OpenGLWidget(QWidget *parent) { } -void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh) +void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh) { //Convienient access to the vertices and indices const vector& vecIndices = surfaceMesh.getIndices(); - const vector >& vecVertices = surfaceMesh.getVertices(); + const vector >& vecVertices = surfaceMesh.getVertices(); //Build an OpenGL index buffer glGenBuffers(1, &indexBuffer); @@ -37,17 +37,17 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh(&(vecVertices[0])); - glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal), pVertices, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(MarchingCubesVertex), pVertices, GL_STATIC_DRAW); m_uBeginIndex = 0; m_uEndIndex = vecIndices.size(); } -void OpenGLWidget::setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh >& surfaceMesh) +void OpenGLWidget::setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh >& surfaceMesh) { //Convienient access to the vertices and indices const vector& vecIndices = surfaceMesh.getIndices(); - const vector >& vecVertices = surfaceMesh.getVertices(); + const vector >& vecVertices = surfaceMesh.getVertices(); //Build an OpenGL index buffer glGenBuffers(1, &indexBufferLow); @@ -59,7 +59,7 @@ void OpenGLWidget::setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh(&(vecVertices[0])); - glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal), pVertices, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(MarchingCubesVertex), pVertices, GL_STATIC_DRAW); m_uBeginIndexLow = 0; m_uEndIndexLow = vecIndices.size(); @@ -152,8 +152,8 @@ void OpenGLWidget::paintGL() //Bind the vertex buffer glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); - glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal), 0); - glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12); + glVertexPointer(3, GL_FLOAT, sizeof(MarchingCubesVertex), 0); + glNormalPointer(GL_FLOAT, sizeof(MarchingCubesVertex), (GLvoid*)12); glDrawRangeElements(GL_TRIANGLES, m_uBeginIndex, m_uEndIndex-1, m_uEndIndex - m_uBeginIndex, GL_UNSIGNED_INT, 0); @@ -162,8 +162,8 @@ void OpenGLWidget::paintGL() //Bind the vertex buffer glBindBuffer(GL_ARRAY_BUFFER, vertexBufferLow); - glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal), 0); - glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12); + glVertexPointer(3, GL_FLOAT, sizeof(MarchingCubesVertex), 0); + glNormalPointer(GL_FLOAT, sizeof(MarchingCubesVertex), (GLvoid*)12); glDrawRangeElements(GL_TRIANGLES, m_uBeginIndexLow, m_uEndIndexLow-1, m_uEndIndexLow - m_uBeginIndexLow, GL_UNSIGNED_INT, 0); diff --git a/examples/SmoothLOD/OpenGLWidget.h b/examples/SmoothLOD/OpenGLWidget.h index e92a812a..895e9e74 100644 --- a/examples/SmoothLOD/OpenGLWidget.h +++ b/examples/SmoothLOD/OpenGLWidget.h @@ -41,8 +41,8 @@ public: void mousePressEvent(QMouseEvent* event); //Convert a SrfaceMesh to OpenGL index/vertex buffers - void setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh); - void setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh >& surfaceMesh); + void setSurfaceMeshToRender(const PolyVox::SurfaceMesh >& surfaceMesh); + void setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh >& surfaceMesh); protected: //Qt OpenGL functions diff --git a/examples/SmoothLOD/main.cpp b/examples/SmoothLOD/main.cpp index d42dd4a8..29e9cd25 100644 --- a/examples/SmoothLOD/main.cpp +++ b/examples/SmoothLOD/main.cpp @@ -90,13 +90,13 @@ int main(int argc, char *argv[]) volumeResampler.execute(); //Extract the surface - SurfaceMesh > meshLowLOD; + SurfaceMesh > meshLowLOD; MarchingCubesSurfaceExtractor< RawVolume > surfaceExtractor(&volDataLowLOD, volDataLowLOD.getEnclosingRegion(), &meshLowLOD); surfaceExtractor.execute(); meshLowLOD.scaleVertices(/*2.0f*/63.0f / 31.0f); //Extract the surface - SurfaceMesh > meshHighLOD; + SurfaceMesh > meshHighLOD; MarchingCubesSurfaceExtractor< SimpleVolume > surfaceExtractorHigh(&volData, PolyVox::Region(Vector3DInt32(30,0,0), Vector3DInt32(63, 63, 63)), &meshHighLOD); surfaceExtractorHigh.execute(); meshHighLOD.translateVertices(Vector3DFloat(30, 0, 0)); diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h index 6ec45eeb..bb349641 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.h @@ -113,9 +113,9 @@ namespace PolyVox // This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template // Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC? #if defined(_MSC_VER) - CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); + CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); #else - CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); + CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), bool bMergeQuads = true, IsQuadNeeded isQuadNeeded = IsQuadNeeded()); #endif @@ -135,7 +135,7 @@ namespace PolyVox Region m_regSizeInVoxels; //The surface patch we are currently filling. - SurfaceMesh >* m_meshCurrent; + SurfaceMesh >* m_meshCurrent; //Used to avoid creating duplicate vertices. Array<3, IndexAndMaterial> m_previousSliceVertices; diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index 03996a6b..822b9256 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -36,7 +36,7 @@ namespace PolyVox const uint32_t CubicSurfaceExtractor::MaxVerticesPerPosition = 8; template - CubicSurfaceExtractor::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded) + CubicSurfaceExtractor::CubicSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, bool bMergeQuads, IsQuadNeeded isQuadNeeded) :m_volData(volData) ,m_regSizeInVoxels(region) ,m_meshCurrent(result) @@ -214,7 +214,7 @@ namespace PolyVox if(rEntry.iIndex == -1) { //No vertices matched and we've now hit an empty space. Fill it by creating a vertex. The 0.5f offset is because vertices set between voxels in order to build cubes around them. - rEntry.iIndex = m_meshCurrent->addVertex(PositionMaterialNormal(Vector3DFloat(static_cast(uX)-0.5f, static_cast(uY)-0.5f, static_cast(uZ)-0.5f), uMaterialIn)); + rEntry.iIndex = m_meshCurrent->addVertex(CubicVertex(Vector3DFloat(static_cast(uX)-0.5f, static_cast(uY)-0.5f, static_cast(uZ)-0.5f), uMaterialIn)); rEntry.uMaterial = uMaterialIn; return rEntry.iIndex; diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h index b5a0b637..87c7df13 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.h @@ -41,9 +41,9 @@ namespace PolyVox // This is a bit ugly - it seems that the C++03 syntax is different from the C++11 syntax? See this thread: http://stackoverflow.com/questions/6076015/typename-outside-of-template // Long term we should probably come back to this and if the #ifdef is still needed then maybe it should check for C++11 mode instead of MSVC? #if defined(_MSC_VER) - MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), Controller controller = Controller()); + MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = VolumeType::VoxelType(), Controller controller = Controller()); #else - MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), Controller controller = Controller()); + MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode = WrapModes::Border, typename VolumeType::VoxelType tBorderValue = typename VolumeType::VoxelType(), Controller controller = Controller()); #endif void execute(); @@ -193,7 +193,7 @@ namespace PolyVox uint32_t m_uNoOfOccupiedCells; //The surface patch we are currently filling. - SurfaceMesh >* m_meshCurrent; + SurfaceMesh >* m_meshCurrent; //Information about the region we are currently processing Region m_regSizeInVoxels; diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl index e4a58f41..535060bb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl @@ -26,7 +26,7 @@ freely, subject to the following restrictions: namespace PolyVox { template - MarchingCubesSurfaceExtractor::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller) + MarchingCubesSurfaceExtractor::MarchingCubesSurfaceExtractor(VolumeType* volData, Region region, SurfaceMesh >* result, WrapMode eWrapMode, typename VolumeType::VoxelType tBorderValue, Controller controller) :m_volData(volData) ,m_sampVolume(volData) ,m_meshCurrent(result) @@ -459,7 +459,7 @@ namespace PolyVox // Allow the controller to decide how the material should be derived from the voxels. const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v100, fInterp); - const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, uMaterial); + const MarchingCubesVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial); const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); m_pCurrentVertexIndicesX[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; @@ -488,7 +488,7 @@ namespace PolyVox // Allow the controller to decide how the material should be derived from the voxels. const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v010, fInterp); - PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, uMaterial); + MarchingCubesVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial); uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); m_pCurrentVertexIndicesY[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; @@ -516,7 +516,7 @@ namespace PolyVox // Allow the controller to decide how the material should be derived from the voxels. const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v001, fInterp); - const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, uMaterial); + const MarchingCubesVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial); const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); m_pCurrentVertexIndicesZ[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; diff --git a/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h index 9af1a924..0d68b3e9 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h +++ b/library/PolyVoxCore/include/PolyVoxCore/PolyVoxForwardDeclarations.h @@ -78,6 +78,11 @@ namespace PolyVox template class DefaultIsQuadNeeded; template > class CubicSurfaceExtractor; + //////////////////////////////////////////////////////////////////////////////// + // CubicVertex + //////////////////////////////////////////////////////////////////////////////// + template class CubicVertex; + //////////////////////////////////////////////////////////////////////////////// // Density //////////////////////////////////////////////////////////////////////////////// @@ -103,6 +108,11 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// template class LargeVolume; + //////////////////////////////////////////////////////////////////////////////// + // MarchingCubesVertex + //////////////////////////////////////////////////////////////////////////////// + template class MarchingCubesVertex; + //////////////////////////////////////////////////////////////////////////////// // Material //////////////////////////////////////////////////////////////////////////////// @@ -129,11 +139,6 @@ namespace PolyVox //////////////////////////////////////////////////////////////////////////////// template class Pager; - //////////////////////////////////////////////////////////////////////////////// - // PositionMaterialNormal - //////////////////////////////////////////////////////////////////////////////// - template class PositionMaterialNormal; - //////////////////////////////////////////////////////////////////////////////// // RawVolume //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h b/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h index 3eb18072..a5a24d79 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h +++ b/library/PolyVoxCore/include/PolyVoxCore/VertexTypes.h @@ -34,74 +34,31 @@ freely, subject to the following restrictions: namespace PolyVox { #ifdef SWIG - class PositionMaterial + class CubicVertex #else - template - class POLYVOX_API PositionMaterial + template + class POLYVOX_API CubicVertex #endif { public: - PositionMaterial() + CubicVertex() { } - PositionMaterial(Vector3DFloat positionToSet, MaterialType materialToSet) + CubicVertex(Vector3DFloat positionToSet, VoxelType materialToSet) :position(positionToSet) ,material(materialToSet) { } - MaterialType getMaterial(void) const - { - return material; - } - - const Vector3DFloat& getPosition(void) const - { - return position; - } - - void setMaterial(MaterialType materialToSet) - { - material = materialToSet; - } - - void setPosition(const Vector3DFloat& positionToSet) - { - position = positionToSet; - } - public: - //Nicely fits into four floats. - Vector3DFloat position; - MaterialType material; - }; - -#ifdef SWIG - class PositionMaterialNormal -#else - template - class POLYVOX_API PositionMaterialNormal -#endif - { - public: - PositionMaterialNormal() - { - } - - PositionMaterialNormal(Vector3DFloat positionToSet, MaterialType materialToSet) - :position(positionToSet) - ,material(materialToSet) - { - } - - PositionMaterialNormal(Vector3DFloat positionToSet, Vector3DFloat normalToSet, MaterialType materialToSet) + CubicVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet, VoxelType materialToSet) :position(positionToSet) ,normal(normalToSet) ,material(materialToSet) { } - MaterialType getMaterial(void) const + VoxelType getMaterial(void) const { return material; } @@ -116,7 +73,7 @@ namespace PolyVox return position; } - void setMaterial(MaterialType materialToSet) + void setMaterial(VoxelType materialToSet) { material = materialToSet; } @@ -131,12 +88,71 @@ namespace PolyVox position = positionToSet; } - public: - //Nicely fits into seven floats, meaning we - //can squeeze in one more for material blending. + public: Vector3DFloat position; Vector3DFloat normal; - MaterialType material; //FIXME: This shouldn't be float on CPU? + VoxelType material; + }; + +#ifdef SWIG + class MarchingCubesVertex +#else + template + class POLYVOX_API MarchingCubesVertex +#endif + { + public: + MarchingCubesVertex() + { + } + + MarchingCubesVertex(Vector3DFloat positionToSet, VoxelType materialToSet) + :position(positionToSet) + , material(materialToSet) + { + } + + MarchingCubesVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet, VoxelType materialToSet) + :position(positionToSet) + , normal(normalToSet) + , material(materialToSet) + { + } + + VoxelType getMaterial(void) const + { + return material; + } + + const Vector3DFloat& getNormal(void) const + { + return normal; + } + + const Vector3DFloat& getPosition(void) const + { + return position; + } + + void setMaterial(VoxelType materialToSet) + { + material = materialToSet; + } + + void setNormal(const Vector3DFloat& normalToSet) + { + normal = normalToSet; + } + + void setPosition(const Vector3DFloat& positionToSet) + { + position = positionToSet; + } + + public: + Vector3DFloat position; + Vector3DFloat normal; + VoxelType material; }; } diff --git a/tests/TestCubicSurfaceExtractor.cpp b/tests/TestCubicSurfaceExtractor.cpp index ba04268a..7dc85571 100644 --- a/tests/TestCubicSurfaceExtractor.cpp +++ b/tests/TestCubicSurfaceExtractor.cpp @@ -106,7 +106,7 @@ uint32_t testForType(void) { for (int32_t x = 0; x < uVolumeSideLength; x += uRegionSideLength) { - SurfaceMesh > result; + SurfaceMesh > result; Region regionToExtract(x, y, z, x + uRegionSideLength - 1, y + uRegionSideLength - 1, z + uRegionSideLength - 1); CubicSurfaceExtractor< SimpleVolume > extractor(&volData, regionToExtract, &result); extractor.execute(); @@ -131,7 +131,7 @@ void TestCubicSurfaceExtractor::testExecute() const static uint32_t uIndexToCheck = 2000; const static uint32_t uExpectedIndex = 1334; - SurfaceMesh mesh;*/ + SurfaceMesh mesh;*/ /*testForType(mesh); QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices); diff --git a/tests/TestSurfaceExtractor.cpp b/tests/TestSurfaceExtractor.cpp index 74030b07..81610212 100644 --- a/tests/TestSurfaceExtractor.cpp +++ b/tests/TestSurfaceExtractor.cpp @@ -102,7 +102,7 @@ void writeMaterialValueToVoxel(int valueToWrite, MaterialDensityPair88& voxel) // Runs the surface extractor for a given type. template -void testForType(SurfaceMesh >& result) +void testForType(SurfaceMesh >& result) { const int32_t uVolumeSideLength = 32; @@ -131,7 +131,7 @@ void testForType(SurfaceMesh >& result) extractor.execute(); } -void testCustomController(SurfaceMesh >& result) +void testCustomController(SurfaceMesh >& result) { const int32_t uVolumeSideLength = 32; @@ -163,7 +163,7 @@ void TestSurfaceExtractor::testExecute() const static float fExpectedMaterial = 42.0f; const static float fNoMaterial = 1.0f; - SurfaceMesh > int8Mesh; + SurfaceMesh > int8Mesh; //Run the test for various voxel types. QBENCHMARK { testForType(int8Mesh); @@ -172,55 +172,55 @@ void TestSurfaceExtractor::testExecute() QCOMPARE(int8Mesh.getNoOfIndices(), uExpectedIndices); QCOMPARE(int8Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast(fNoMaterial)); - SurfaceMesh > uint8Mesh; + SurfaceMesh > uint8Mesh; testForType(uint8Mesh); QCOMPARE(uint8Mesh.getNoOfVertices(), uExpectedVertices); QCOMPARE(uint8Mesh.getNoOfIndices(), uExpectedIndices); QCOMPARE(uint8Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast(fNoMaterial)); - SurfaceMesh > int16Mesh; + SurfaceMesh > int16Mesh; testForType(int16Mesh); QCOMPARE(int16Mesh.getNoOfVertices(), uExpectedVertices); QCOMPARE(int16Mesh.getNoOfIndices(), uExpectedIndices); QCOMPARE(int16Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast(fNoMaterial)); - SurfaceMesh > uint16Mesh; + SurfaceMesh > uint16Mesh; testForType(uint16Mesh); QCOMPARE(uint16Mesh.getNoOfVertices(), uExpectedVertices); QCOMPARE(uint16Mesh.getNoOfIndices(), uExpectedIndices); QCOMPARE(uint16Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast(fNoMaterial)); - SurfaceMesh > int32Mesh; + SurfaceMesh > int32Mesh; testForType(int32Mesh); QCOMPARE(int32Mesh.getNoOfVertices(), uExpectedVertices); QCOMPARE(int32Mesh.getNoOfIndices(), uExpectedIndices); QCOMPARE(int32Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast(fNoMaterial)); - SurfaceMesh > uint32Mesh; + SurfaceMesh > uint32Mesh; testForType(uint32Mesh); QCOMPARE(uint32Mesh.getNoOfVertices(), uExpectedVertices); QCOMPARE(uint32Mesh.getNoOfIndices(), uExpectedIndices); QCOMPARE(uint32Mesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast(fNoMaterial)); - SurfaceMesh > floatMesh; + SurfaceMesh > floatMesh; testForType(floatMesh); QCOMPARE(floatMesh.getNoOfVertices(), uExpectedVertices); QCOMPARE(floatMesh.getNoOfIndices(), uExpectedIndices); QCOMPARE(floatMesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial); - SurfaceMesh > doubleMesh; + SurfaceMesh > doubleMesh; testForType(doubleMesh); QCOMPARE(doubleMesh.getNoOfVertices(), uExpectedVertices); QCOMPARE(doubleMesh.getNoOfIndices(), uExpectedIndices); QCOMPARE(doubleMesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast(fNoMaterial)); - SurfaceMesh > densityMesh; + SurfaceMesh > densityMesh; testForType(densityMesh); QCOMPARE(densityMesh.getNoOfVertices(), uExpectedVertices); QCOMPARE(densityMesh.getNoOfIndices(), uExpectedIndices); //QCOMPARE(densityMesh.getVertices()[uMaterialToCheck].getMaterial(), static_cast(fNoMaterial)); - SurfaceMesh > materialDensityMesh; + SurfaceMesh > materialDensityMesh; testForType(materialDensityMesh); QCOMPARE(materialDensityMesh.getNoOfVertices(), uExpectedVertices); QCOMPARE(materialDensityMesh.getNoOfIndices(), uExpectedIndices); diff --git a/tests/TestVolumeSubclass.cpp b/tests/TestVolumeSubclass.cpp index 87b57407..98bbe8c4 100644 --- a/tests/TestVolumeSubclass.cpp +++ b/tests/TestVolumeSubclass.cpp @@ -184,7 +184,7 @@ void TestVolumeSubclass::testExtractSurface() } } - SurfaceMesh > result; + SurfaceMesh > result; CubicSurfaceExtractor< VolumeSubclass > cubicSurfaceExtractor(&volumeSubclass, volumeSubclass.getEnclosingRegion(), &result); cubicSurfaceExtractor.execute();