From c5023ff62395075505404a1ca02687848db87bb7 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 8 Feb 2013 13:29:49 +0100 Subject: [PATCH 1/6] Changed void* to uint8_t*. --- library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h | 2 +- library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h index e27b5b09..67932672 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h @@ -65,7 +65,7 @@ namespace PolyVox void compress(Compressor* pCompressor); void uncompress(Compressor* pCompressor); - void* m_pCompressedData; + uint8_t* m_pCompressedData; uint32_t m_uCompressedDataLength; VoxelType* m_tUncompressedData; uint16_t m_uSideLength; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index 85504b64..34e59898 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -167,7 +167,7 @@ namespace PolyVox uCompressedLength = pCompressor->compress(pSrcData, uSrcLength, pDstData, uDstLength); // Create new compressed data and copy across - m_pCompressedData = reinterpret_cast( new uint8_t[uCompressedLength] ); + m_pCompressedData = new uint8_t[uCompressedLength]; memcpy(m_pCompressedData, pDstData, uCompressedLength); m_uCompressedDataLength = uCompressedLength; } @@ -187,7 +187,7 @@ namespace PolyVox uCompressedLength = pCompressor->compress(pSrcData, uSrcLength, pDstData, uDstLength); // Create new compressed data and copy across - m_pCompressedData = reinterpret_cast( new uint8_t[uCompressedLength] ); + m_pCompressedData = new uint8_t[uCompressedLength]; memcpy(m_pCompressedData, pDstData, uCompressedLength); m_uCompressedDataLength = uCompressedLength; } From 7e08ed7aec33fe776dc7f4a2b2a3a85b8fc60ff3 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 8 Feb 2013 15:05:45 +0100 Subject: [PATCH 2/6] Updated the CubicSurfaceExtractor test to make it a bit more performance intensive, Cubiquity is showing a need for some improvements here. Also added a performance improvement to the CubicsurfaceExtractor. --- .../PolyVoxCore/CubicSurfaceExtractor.inl | 8 +-- tests/TestCubicSurfaceExtractor.cpp | 50 ++++++++++++++----- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index 72294e2c..d3f7f7a8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -79,11 +79,11 @@ namespace PolyVox { uint32_t regY = y - m_regSizeInVoxels.getLowerCorner().getY(); + volumeSampler.setPosition(m_regSizeInVoxels.getLowerCorner().getX(),y,z); + for(int32_t x = m_regSizeInVoxels.getLowerCorner().getX(); x <= m_regSizeInVoxels.getUpperCorner().getX(); x++) { - uint32_t regX = x - m_regSizeInVoxels.getLowerCorner().getX(); - - volumeSampler.setPosition(x,y,z); + uint32_t regX = x - m_regSizeInVoxels.getLowerCorner().getX(); uint32_t material; //Filled in by callback typename VolumeType::VoxelType currentVoxel = volumeSampler.getVoxel(); @@ -153,6 +153,8 @@ namespace PolyVox m_vecQuads[PositiveZ][regZ].push_back(Quad(v0, v3, v2, v1)); } + + volumeSampler.movePositiveX(); } } diff --git a/tests/TestCubicSurfaceExtractor.cpp b/tests/TestCubicSurfaceExtractor.cpp index d03b74c4..45919e85 100644 --- a/tests/TestCubicSurfaceExtractor.cpp +++ b/tests/TestCubicSurfaceExtractor.cpp @@ -27,7 +27,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/Material.h" #include "PolyVoxCore/MaterialDensityPair.h" #include "PolyVoxCore/SimpleVolume.h" -#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h" +#include "PolyVoxCore/CubicSurfaceExtractor.h" #include @@ -70,13 +70,14 @@ void writeMaterialValueToVoxel(int valueToWrite, MaterialDensityPair88& voxel) // Runs the surface extractor for a given type. template -void testForType(SurfaceMesh& result) +uint32_t testForType(void) { - const int32_t uVolumeSideLength = 32; + const int32_t uVolumeSideLength = 256; //Create empty volume - SimpleVolume volData(Region(Vector3DInt32(0,0,0), Vector3DInt32(uVolumeSideLength-1, uVolumeSideLength-1, uVolumeSideLength-1))); + SimpleVolume volData(Region(Vector3DInt32(0,0,0), Vector3DInt32(uVolumeSideLength-1, uVolumeSideLength-1, uVolumeSideLength-1)), 128); + //Fill the volume with data for (int32_t z = 0; z < uVolumeSideLength; z++) { for (int32_t y = 0; y < uVolumeSideLength; y++) @@ -94,20 +95,43 @@ void testForType(SurfaceMesh& result) } } - CubicSurfaceExtractorWithNormals< SimpleVolume > extractor(&volData, volData.getEnclosingRegion(), &result); - extractor.execute(); + uint32_t uTotalVertices = 0; + uint32_t uTotalIndices = 0; + + //Run the surface extractor a number of times over differnt regions of the volume. + const int32_t uRegionSideLength = 64; + for (int32_t z = 0; z < uVolumeSideLength; z += uRegionSideLength) + { + for (int32_t y = 0; y < uVolumeSideLength; y += uRegionSideLength) + { + for (int32_t x = 0; x < uVolumeSideLength; x += uRegionSideLength) + { + SurfaceMesh result; + Region regionToExtract(x, y, z, x + uRegionSideLength - 1, y + uRegionSideLength - 1, z + uRegionSideLength - 1); + CubicSurfaceExtractor< SimpleVolume > extractor(&volData, regionToExtract, &result); + extractor.execute(); + + uTotalVertices += result.getNoOfVertices(); + uTotalIndices += result.getNoOfIndices(); + } + } + } + + // Just some value which is representative of the work we've done. It doesn't + // matter what it is, just that it should be the same every time we run the test. + return uTotalVertices + uTotalIndices; } void TestCubicSurfaceExtractor::testExecute() { - const static uint32_t uExpectedVertices = 6624; + /*const static uint32_t uExpectedVertices = 6624; const static uint32_t uExpectedIndices = 9936; const static uint32_t uMaterialToCheck = 3000; const static float fExpectedMaterial = 42.0f; const static uint32_t uIndexToCheck = 2000; const static uint32_t uExpectedIndex = 1334; - SurfaceMesh mesh; + SurfaceMesh mesh;*/ /*testForType(mesh); QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices); @@ -154,13 +178,13 @@ void TestCubicSurfaceExtractor::testExecute() QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices); QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fNoMaterial);*/ + const static uint32_t uExpectedSumOfVerticesAndIndices = 704668; + //const static uint32_t uExpectedSumOfVerticesAndIndices = 2792332; + uint32_t result = 0; QBENCHMARK { - testForType(mesh); + result = testForType(); } - QCOMPARE(mesh.getNoOfVertices(), uExpectedVertices); - QCOMPARE(mesh.getNoOfIndices(), uExpectedIndices); - QCOMPARE(mesh.getVertices()[uMaterialToCheck].getMaterial(), fExpectedMaterial); - QCOMPARE(mesh.getIndices()[uIndexToCheck], uExpectedIndex); + QCOMPARE(result, uExpectedSumOfVerticesAndIndices); } QTEST_MAIN(TestCubicSurfaceExtractor) From 608777bb9ba13f7f07c782cb07796a7242285863 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 8 Feb 2013 15:14:15 +0100 Subject: [PATCH 3/6] Performance improvements for CubicSurfaceExtractor --- .../PolyVoxCore/CubicSurfaceExtractor.inl | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl index d3f7f7a8..1f3ee2cc 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractor.inl @@ -50,8 +50,8 @@ namespace PolyVox { m_meshCurrent->clear(); - uint32_t uArrayWidth = m_regSizeInVoxels.getUpperCorner().getX() - m_regSizeInVoxels.getLowerCorner().getX() + 2; - uint32_t uArrayHeight = m_regSizeInVoxels.getUpperCorner().getY() - m_regSizeInVoxels.getLowerCorner().getY() + 2; + uint32_t uArrayWidth = m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2; + uint32_t uArrayHeight = m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2; uint32_t arraySize[3]= {uArrayWidth, uArrayHeight, MaxVerticesPerPosition}; m_previousSliceVertices.resize(arraySize); @@ -59,31 +59,31 @@ namespace PolyVox memset(m_previousSliceVertices.getRawData(), 0xff, m_previousSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial)); memset(m_currentSliceVertices.getRawData(), 0xff, m_currentSliceVertices.getNoOfElements() * sizeof(IndexAndMaterial)); - m_vecQuads[NegativeX].resize(m_regSizeInVoxels.getUpperCorner().getX() - m_regSizeInVoxels.getLowerCorner().getX() + 2); - m_vecQuads[PositiveX].resize(m_regSizeInVoxels.getUpperCorner().getX() - m_regSizeInVoxels.getLowerCorner().getX() + 2); + m_vecQuads[NegativeX].resize(m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2); + m_vecQuads[PositiveX].resize(m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 2); - m_vecQuads[NegativeY].resize(m_regSizeInVoxels.getUpperCorner().getY() - m_regSizeInVoxels.getLowerCorner().getY() + 2); - m_vecQuads[PositiveY].resize(m_regSizeInVoxels.getUpperCorner().getY() - m_regSizeInVoxels.getLowerCorner().getY() + 2); + m_vecQuads[NegativeY].resize(m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2); + m_vecQuads[PositiveY].resize(m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 2); - m_vecQuads[NegativeZ].resize(m_regSizeInVoxels.getUpperCorner().getZ() - m_regSizeInVoxels.getLowerCorner().getZ() + 2); - m_vecQuads[PositiveZ].resize(m_regSizeInVoxels.getUpperCorner().getZ() - m_regSizeInVoxels.getLowerCorner().getZ() + 2); + m_vecQuads[NegativeZ].resize(m_regSizeInVoxels.getUpperZ() - m_regSizeInVoxels.getLowerZ() + 2); + m_vecQuads[PositiveZ].resize(m_regSizeInVoxels.getUpperZ() - m_regSizeInVoxels.getLowerZ() + 2); typename VolumeType::Sampler volumeSampler(m_volData); volumeSampler.setWrapMode(m_eWrapMode, m_tBorderValue); - for(int32_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z <= m_regSizeInVoxels.getUpperCorner().getZ(); z++) + for(int32_t z = m_regSizeInVoxels.getLowerZ(); z <= m_regSizeInVoxels.getUpperZ(); z++) { - uint32_t regZ = z - m_regSizeInVoxels.getLowerCorner().getZ(); + uint32_t regZ = z - m_regSizeInVoxels.getLowerZ(); - for(int32_t y = m_regSizeInVoxels.getLowerCorner().getY(); y <= m_regSizeInVoxels.getUpperCorner().getY(); y++) + for(int32_t y = m_regSizeInVoxels.getLowerY(); y <= m_regSizeInVoxels.getUpperY(); y++) { - uint32_t regY = y - m_regSizeInVoxels.getLowerCorner().getY(); + uint32_t regY = y - m_regSizeInVoxels.getLowerY(); - volumeSampler.setPosition(m_regSizeInVoxels.getLowerCorner().getX(),y,z); + volumeSampler.setPosition(m_regSizeInVoxels.getLowerX(),y,z); - for(int32_t x = m_regSizeInVoxels.getLowerCorner().getX(); x <= m_regSizeInVoxels.getUpperCorner().getX(); x++) + for(int32_t x = m_regSizeInVoxels.getLowerX(); x <= m_regSizeInVoxels.getUpperX(); x++) { - uint32_t regX = x - m_regSizeInVoxels.getLowerCorner().getX(); + uint32_t regX = x - m_regSizeInVoxels.getLowerX(); uint32_t material; //Filled in by callback typename VolumeType::VoxelType currentVoxel = volumeSampler.getVoxel(); From 66bdf0e5a935d2cd63328317abd8a612de77a864 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Fri, 8 Feb 2013 14:27:11 +0000 Subject: [PATCH 4/6] Add Compressor and subclasses to the bindings This relates to issue 20 and should fix the compilation error mentioned there. --- library/bindings/Compressor.i | 6 ++++++ library/bindings/MinizCompressor.i | 6 ++++++ library/bindings/PolyVoxCore.i | 3 +++ library/bindings/RLECompressor.i | 6 ++++++ 4 files changed, 21 insertions(+) create mode 100644 library/bindings/Compressor.i create mode 100644 library/bindings/MinizCompressor.i create mode 100644 library/bindings/RLECompressor.i diff --git a/library/bindings/Compressor.i b/library/bindings/Compressor.i new file mode 100644 index 00000000..78e5ef69 --- /dev/null +++ b/library/bindings/Compressor.i @@ -0,0 +1,6 @@ +%module Compressor +%{ +#include "Compressor.h" +%} + +%include "Compressor.h" diff --git a/library/bindings/MinizCompressor.i b/library/bindings/MinizCompressor.i new file mode 100644 index 00000000..f846265f --- /dev/null +++ b/library/bindings/MinizCompressor.i @@ -0,0 +1,6 @@ +%module MinizCompressor +%{ +#include "MinizCompressor.h" +%} + +%include "MinizCompressor.h" diff --git a/library/bindings/PolyVoxCore.i b/library/bindings/PolyVoxCore.i index 8c0d30c4..10a6b1ee 100644 --- a/library/bindings/PolyVoxCore.i +++ b/library/bindings/PolyVoxCore.i @@ -75,6 +75,9 @@ EXTRACTOR(shortname, LargeVolume) %include "Vector.i" %include "DefaultMarchingCubesController.i" %include "Region.i" +%include "Compressor.i" +%include "MinizCompressor.i" +%include "RLECompressor.i" %include "BaseVolume.i" %include "SimpleVolume.i" %include "RawVolume.i" diff --git a/library/bindings/RLECompressor.i b/library/bindings/RLECompressor.i new file mode 100644 index 00000000..01023c27 --- /dev/null +++ b/library/bindings/RLECompressor.i @@ -0,0 +1,6 @@ +%module RLECompressor +%{ +#include "RLECompressor.h" +%} + +%include "RLECompressor.h" From 7327220b1c9eaa33537b7e56c922109ad31f638e Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 8 Feb 2013 15:43:37 +0100 Subject: [PATCH 5/6] Performance enhancements identified through profiling. --- .../include/PolyVoxCore/LargeVolumeSampler.inl | 12 ++++++------ .../include/PolyVoxCore/RawVolumeSampler.inl | 12 ++++++------ .../include/PolyVoxCore/SimpleVolumeSampler.inl | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl index 024b3cdb..ee9e4a2c 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolumeSampler.inl @@ -21,12 +21,12 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) && (val % this->mVolume->m_uBlockSideLength != 0)) -#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) -#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) && (val % this->mVolume->m_uBlockSideLength != 0)) -#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) -#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) && (val % this->mVolume->m_uBlockSideLength != 0)) -#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerX()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperX()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerY()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperY()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerZ()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperZ()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) namespace PolyVox { diff --git a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl index 866a2f64..3124e4c8 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/RawVolumeSampler.inl @@ -21,12 +21,12 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#define CAN_GO_NEG_X(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) -#define CAN_GO_POS_X(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) -#define CAN_GO_NEG_Y(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) -#define CAN_GO_POS_Y(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) -#define CAN_GO_NEG_Z(val) (val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) -#define CAN_GO_POS_Z(val) (val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) +#define CAN_GO_NEG_X(val) (val > this->mVolume->getEnclosingRegion().getLowerX()) +#define CAN_GO_POS_X(val) (val < this->mVolume->getEnclosingRegion().getUpperX()) +#define CAN_GO_NEG_Y(val) (val > this->mVolume->getEnclosingRegion().getLowerY()) +#define CAN_GO_POS_Y(val) (val < this->mVolume->getEnclosingRegion().getUpperY()) +#define CAN_GO_NEG_Z(val) (val > this->mVolume->getEnclosingRegion().getLowerZ()) +#define CAN_GO_POS_Z(val) (val < this->mVolume->getEnclosingRegion().getUpperZ()) namespace PolyVox { diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl index 8e8deddf..117651a4 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolumeSampler.inl @@ -21,12 +21,12 @@ freely, subject to the following restrictions: distribution. *******************************************************************************/ -#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getX()) && (val % this->mVolume->m_uBlockSideLength != 0)) -#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getX()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) -#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getY()) && (val % this->mVolume->m_uBlockSideLength != 0)) -#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getY()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) -#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerCorner().getZ()) && (val % this->mVolume->m_uBlockSideLength != 0)) -#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperCorner().getZ()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_NEG_X(val) ((val > this->mVolume->getEnclosingRegion().getLowerX()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_X(val) ((val < this->mVolume->getEnclosingRegion().getUpperX()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_NEG_Y(val) ((val > this->mVolume->getEnclosingRegion().getLowerY()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_Y(val) ((val < this->mVolume->getEnclosingRegion().getUpperY()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_NEG_Z(val) ((val > this->mVolume->getEnclosingRegion().getLowerZ()) && (val % this->mVolume->m_uBlockSideLength != 0)) +#define CAN_GO_POS_Z(val) ((val < this->mVolume->getEnclosingRegion().getUpperZ()) && ((val + 1) % this->mVolume->m_uBlockSideLength != 0)) namespace PolyVox { From b7eeda33705cd7317f9e56be0e1fe33e5e6ff79a Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 8 Feb 2013 16:15:53 +0100 Subject: [PATCH 6/6] Find and replace all instance of getLowerCorner().getX(), etc with getLowerX(), etc has resulted in all tests now running in 120 seconds instead of 144 seconds because it avoids creating temporary objects. --- examples/Paging/main.cpp | 6 +- .../AmbientOcclusionCalculator.inl | 10 +-- .../include/PolyVoxCore/BaseVolume.inl | 6 +- .../CubicSurfaceExtractorWithNormals.inl | 12 +-- .../PolyVoxCore/IteratorController.inl | 10 +-- .../include/PolyVoxCore/LowPassFilter.inl | 24 +++--- .../MarchingCubesSurfaceExtractor.inl | 84 +++++++++---------- .../include/PolyVoxCore/SimpleVolume.inl | 12 +-- .../include/PolyVoxCore/VolumeResampler.inl | 36 ++++---- 9 files changed, 100 insertions(+), 100 deletions(-) diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index 4a6c3cfe..b4e60974 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -201,15 +201,15 @@ void load(const ConstVolumeProxy& volume, const PolyVox:: { Perlin perlin(2,2,1,234); - for(int x = reg.getLowerCorner().getX(); x <= reg.getUpperCorner().getX(); x++) + for(int x = reg.getLowerX(); x <= reg.getUpperX(); x++) { - for(int y = reg.getLowerCorner().getY(); y <= reg.getUpperCorner().getY(); y++) + for(int y = reg.getLowerY(); y <= reg.getUpperY(); y++) { float perlinVal = perlin.Get(x / static_cast(255-1), y / static_cast(255-1)); perlinVal += 1.0f; perlinVal *= 0.5f; perlinVal *= 255; - for(int z = reg.getLowerCorner().getZ(); z <= reg.getUpperCorner().getZ(); z++) + for(int z = reg.getLowerZ(); z <= reg.getUpperZ(); z++) { MaterialDensityPair44 voxel; if(z < perlinVal) diff --git a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl index 95c1410e..27ff3188 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/AmbientOcclusionCalculator.inl @@ -45,8 +45,8 @@ namespace PolyVox //Our initial indices. It doesn't matter exactly what we set here, but the code below makes //sure they are different for different regions which helps reduce tiling patterns in the results. - uRandomUnitVectorIndex += region.getLowerCorner().getX() + region.getLowerCorner().getY() + region.getLowerCorner().getZ(); - uRandomVectorIndex += region.getLowerCorner().getX() + region.getLowerCorner().getY() + region.getLowerCorner().getZ(); + uRandomUnitVectorIndex += region.getLowerX() + region.getLowerY() + region.getLowerZ(); + uRandomVectorIndex += region.getLowerX() + region.getLowerY() + region.getLowerZ(); //This value helps us jump around in the array a bit more, so the //nth 'random' value isn't always followed by the n+1th 'random' value. @@ -69,11 +69,11 @@ namespace PolyVox const Vector3DFloat v3dOffset(0.5f,0.5f,0.5f); //This loop iterates over the bottom-lower-left voxel in each of the cells in the output array - for(uint16_t z = region.getLowerCorner().getZ(); z <= region.getUpperCorner().getZ(); z += iRatioZ) + for(uint16_t z = region.getLowerZ(); z <= region.getUpperZ(); z += iRatioZ) { - for(uint16_t y = region.getLowerCorner().getY(); y <= region.getUpperCorner().getY(); y += iRatioY) + for(uint16_t y = region.getLowerY(); y <= region.getUpperY(); y += iRatioY) { - for(uint16_t x = region.getLowerCorner().getX(); x <= region.getUpperCorner().getX(); x += iRatioX) + for(uint16_t x = region.getLowerX(); x <= region.getUpperX(); x += iRatioX) { //Compute a start position corresponding to //the centre of the cell in the output array. diff --git a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl index 77949413..96c5ddf0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/BaseVolume.inl @@ -96,7 +96,7 @@ namespace PolyVox template int32_t BaseVolume::getWidth(void) const { - return m_regValidRegion.getUpperCorner().getX() - m_regValidRegion.getLowerCorner().getX() + 1; + return m_regValidRegion.getUpperX() - m_regValidRegion.getLowerX() + 1; } //////////////////////////////////////////////////////////////////////////////// @@ -106,7 +106,7 @@ namespace PolyVox template int32_t BaseVolume::getHeight(void) const { - return m_regValidRegion.getUpperCorner().getY() - m_regValidRegion.getLowerCorner().getY() + 1; + return m_regValidRegion.getUpperY() - m_regValidRegion.getLowerY() + 1; } //////////////////////////////////////////////////////////////////////////////// @@ -116,7 +116,7 @@ namespace PolyVox template int32_t BaseVolume::getDepth(void) const { - return m_regValidRegion.getUpperCorner().getZ() - m_regValidRegion.getLowerCorner().getZ() + 1; + return m_regValidRegion.getUpperZ() - m_regValidRegion.getLowerZ() + 1; } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl index 5e16d3b8..dca5f911 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/CubicSurfaceExtractorWithNormals.inl @@ -40,16 +40,16 @@ namespace PolyVox { m_meshCurrent->clear(); - for(int32_t z = m_regSizeInVoxels.getLowerCorner().getZ(); z < m_regSizeInVoxels.getUpperCorner().getZ(); z++) + for(int32_t z = m_regSizeInVoxels.getLowerZ(); z < m_regSizeInVoxels.getUpperZ(); z++) { - for(int32_t y = m_regSizeInVoxels.getLowerCorner().getY(); y < m_regSizeInVoxels.getUpperCorner().getY(); y++) + for(int32_t y = m_regSizeInVoxels.getLowerY(); y < m_regSizeInVoxels.getUpperY(); y++) { - for(int32_t x = m_regSizeInVoxels.getLowerCorner().getX(); x < m_regSizeInVoxels.getUpperCorner().getX(); x++) + for(int32_t x = m_regSizeInVoxels.getLowerX(); x < m_regSizeInVoxels.getUpperX(); x++) { // these are always positive anyway - float regX = static_cast(x - m_regSizeInVoxels.getLowerCorner().getX()); - float regY = static_cast(y - m_regSizeInVoxels.getLowerCorner().getY()); - float regZ = static_cast(z - m_regSizeInVoxels.getLowerCorner().getZ()); + float regX = static_cast(x - m_regSizeInVoxels.getLowerX()); + float regY = static_cast(y - m_regSizeInVoxels.getLowerY()); + float regZ = static_cast(z - m_regSizeInVoxels.getLowerZ()); uint32_t material = 0; diff --git a/library/PolyVoxCore/include/PolyVoxCore/IteratorController.inl b/library/PolyVoxCore/include/PolyVoxCore/IteratorController.inl index d5aef352..58246823 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/IteratorController.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/IteratorController.inl @@ -34,24 +34,24 @@ namespace PolyVox { Vector3DInt32 v3dInitialPosition(m_Iter->getPosition().getX(), m_Iter->getPosition().getY(), m_Iter->getPosition().getZ()); - if(v3dInitialPosition.getX() < m_regValid.getUpperCorner().getX()) + if(v3dInitialPosition.getX() < m_regValid.getUpperX()) { m_Iter->movePositiveX(); return true; } - v3dInitialPosition.setX(m_regValid.getLowerCorner().getX()); + v3dInitialPosition.setX(m_regValid.getLowerX()); - if(v3dInitialPosition.getY() < m_regValid.getUpperCorner().getY()) + if(v3dInitialPosition.getY() < m_regValid.getUpperY()) { v3dInitialPosition.setY(v3dInitialPosition.getY() + 1); m_Iter->setPosition(v3dInitialPosition); return true; } - v3dInitialPosition.setY(m_regValid.getLowerCorner().getY()); + v3dInitialPosition.setY(m_regValid.getLowerY()); - if(v3dInitialPosition.getZ() < m_regValid.getUpperCorner().getZ()) + if(v3dInitialPosition.getZ() < m_regValid.getUpperZ()) { v3dInitialPosition.setZ(v3dInitialPosition.getZ() + 1); m_Iter->setPosition(v3dInitialPosition); diff --git a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl index cb455921..e6093723 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LowPassFilter.inl @@ -53,21 +53,21 @@ namespace PolyVox template< typename SrcVolumeType, typename DstVolumeType, typename AccumulationType> void LowPassFilter::execute() { - int32_t iSrcMinX = m_regSrc.getLowerCorner().getX(); - int32_t iSrcMinY = m_regSrc.getLowerCorner().getY(); - int32_t iSrcMinZ = m_regSrc.getLowerCorner().getZ(); + int32_t iSrcMinX = m_regSrc.getLowerX(); + int32_t iSrcMinY = m_regSrc.getLowerY(); + int32_t iSrcMinZ = m_regSrc.getLowerZ(); - int32_t iSrcMaxX = m_regSrc.getUpperCorner().getX(); - int32_t iSrcMaxY = m_regSrc.getUpperCorner().getY(); - int32_t iSrcMaxZ = m_regSrc.getUpperCorner().getZ(); + int32_t iSrcMaxX = m_regSrc.getUpperX(); + int32_t iSrcMaxY = m_regSrc.getUpperY(); + int32_t iSrcMaxZ = m_regSrc.getUpperZ(); - int32_t iDstMinX = m_regDst.getLowerCorner().getX(); - int32_t iDstMinY = m_regDst.getLowerCorner().getY(); - int32_t iDstMinZ = m_regDst.getLowerCorner().getZ(); + int32_t iDstMinX = m_regDst.getLowerX(); + int32_t iDstMinY = m_regDst.getLowerY(); + int32_t iDstMinZ = m_regDst.getLowerZ(); - //int32_t iDstMaxX = m_regDst.getUpperCorner().getX(); - //int32_t iDstMaxY = m_regDst.getUpperCorner().getY(); - //int32_t iDstMaxZ = m_regDst.getUpperCorner().getZ(); + //int32_t iDstMaxX = m_regDst.getUpperX(); + //int32_t iDstMaxY = m_regDst.getUpperY(); + //int32_t iDstMaxZ = m_regDst.getUpperZ(); typename SrcVolumeType::Sampler srcSampler(m_pVolSrc); diff --git a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl index 78e90c0a..22e1373d 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl @@ -44,8 +44,8 @@ namespace PolyVox { m_meshCurrent->clear(); - const uint32_t uArrayWidth = m_regSizeInVoxels.getUpperCorner().getX() - m_regSizeInVoxels.getLowerCorner().getX() + 1; - const uint32_t uArrayHeight = m_regSizeInVoxels.getUpperCorner().getY() - m_regSizeInVoxels.getLowerCorner().getY() + 1; + const uint32_t uArrayWidth = m_regSizeInVoxels.getUpperX() - m_regSizeInVoxels.getLowerX() + 1; + const uint32_t uArrayHeight = m_regSizeInVoxels.getUpperY() - m_regSizeInVoxels.getLowerY() + 1; const uint32_t arraySizes[2]= {uArrayWidth, uArrayHeight}; // Array dimensions //For edge indices @@ -62,7 +62,7 @@ namespace PolyVox //Create a region corresponding to the first slice m_regSlicePrevious = m_regSizeInVoxels; Vector3DInt32 v3dUpperCorner = m_regSlicePrevious.getUpperCorner(); - v3dUpperCorner.setZ(m_regSlicePrevious.getLowerCorner().getZ()); //Set the upper z to the lower z to make it one slice thick. + v3dUpperCorner.setZ(m_regSlicePrevious.getLowerZ()); //Set the upper z to the lower z to make it one slice thick. m_regSlicePrevious.setUpperCorner(v3dUpperCorner); m_regSliceCurrent = m_regSlicePrevious; @@ -91,7 +91,7 @@ namespace PolyVox m_regSliceCurrent.shift(Vector3DInt32(0,0,1)); //Process the other slices (previous slice is available) - for(int32_t uSlice = 1; uSlice <= m_regSizeInVoxels.getUpperCorner().getZ() - m_regSizeInVoxels.getLowerCorner().getZ(); uSlice++) + for(int32_t uSlice = 1; uSlice <= m_regSizeInVoxels.getUpperZ() - m_regSizeInVoxels.getLowerZ(); uSlice++) { computeBitmaskForSlice(pPreviousBitmask, pCurrentBitmask); uNoOfNonEmptyCellsForSlice1 = m_uNoOfOccupiedCells; @@ -134,29 +134,29 @@ namespace PolyVox { m_uNoOfOccupiedCells = 0; - const int32_t iMaxXVolSpace = m_regSliceCurrent.getUpperCorner().getX(); - const int32_t iMaxYVolSpace = m_regSliceCurrent.getUpperCorner().getY(); + const int32_t iMaxXVolSpace = m_regSliceCurrent.getUpperX(); + const int32_t iMaxYVolSpace = m_regSliceCurrent.getUpperY(); - const int32_t iZVolSpace = m_regSliceCurrent.getLowerCorner().getZ(); + const int32_t iZVolSpace = m_regSliceCurrent.getLowerZ(); //Process the lower left corner - int32_t iYVolSpace = m_regSliceCurrent.getLowerCorner().getY(); - int32_t iXVolSpace = m_regSliceCurrent.getLowerCorner().getX(); + int32_t iYVolSpace = m_regSliceCurrent.getLowerY(); + int32_t iXVolSpace = m_regSliceCurrent.getLowerX(); - uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX(); - uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY(); + uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX(); + uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY(); m_sampVolume.setPosition(iXVolSpace,iYVolSpace,iZVolSpace); computeBitmaskForCell(pPreviousBitmask, pCurrentBitmask, uXRegSpace, uYRegSpace); //Process the edge where x is minimal. - iXVolSpace = m_regSliceCurrent.getLowerCorner().getX(); - m_sampVolume.setPosition(iXVolSpace, m_regSliceCurrent.getLowerCorner().getY(), iZVolSpace); - for(iYVolSpace = m_regSliceCurrent.getLowerCorner().getY() + 1; iYVolSpace <= iMaxYVolSpace; iYVolSpace++) + iXVolSpace = m_regSliceCurrent.getLowerX(); + m_sampVolume.setPosition(iXVolSpace, m_regSliceCurrent.getLowerY(), iZVolSpace); + for(iYVolSpace = m_regSliceCurrent.getLowerY() + 1; iYVolSpace <= iMaxYVolSpace; iYVolSpace++) { - uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX(); - uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY(); + uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX(); + uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY(); m_sampVolume.movePositiveY(); @@ -164,12 +164,12 @@ namespace PolyVox } //Process the edge where y is minimal. - iYVolSpace = m_regSliceCurrent.getLowerCorner().getY(); - m_sampVolume.setPosition(m_regSliceCurrent.getLowerCorner().getX(), iYVolSpace, iZVolSpace); - for(iXVolSpace = m_regSliceCurrent.getLowerCorner().getX() + 1; iXVolSpace <= iMaxXVolSpace; iXVolSpace++) + iYVolSpace = m_regSliceCurrent.getLowerY(); + m_sampVolume.setPosition(m_regSliceCurrent.getLowerX(), iYVolSpace, iZVolSpace); + for(iXVolSpace = m_regSliceCurrent.getLowerX() + 1; iXVolSpace <= iMaxXVolSpace; iXVolSpace++) { - uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX(); - uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY(); + uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX(); + uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY(); m_sampVolume.movePositiveX(); @@ -177,13 +177,13 @@ namespace PolyVox } //Process all remaining elemnents of the slice. In this case, previous x and y values are always available - for(iYVolSpace = m_regSliceCurrent.getLowerCorner().getY() + 1; iYVolSpace <= iMaxYVolSpace; iYVolSpace++) + for(iYVolSpace = m_regSliceCurrent.getLowerY() + 1; iYVolSpace <= iMaxYVolSpace; iYVolSpace++) { - m_sampVolume.setPosition(m_regSliceCurrent.getLowerCorner().getX(), iYVolSpace, iZVolSpace); - for(iXVolSpace = m_regSliceCurrent.getLowerCorner().getX() + 1; iXVolSpace <= iMaxXVolSpace; iXVolSpace++) + m_sampVolume.setPosition(m_regSliceCurrent.getLowerX(), iYVolSpace, iZVolSpace); + for(iXVolSpace = m_regSliceCurrent.getLowerX() + 1; iXVolSpace <= iMaxXVolSpace; iXVolSpace++) { - uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX(); - uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY(); + uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX(); + uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY(); m_sampVolume.movePositiveX(); @@ -400,17 +400,17 @@ namespace PolyVox Array2DInt32& m_pCurrentVertexIndicesY, Array2DInt32& m_pCurrentVertexIndicesZ) { - const int32_t iZVolSpace = m_regSliceCurrent.getLowerCorner().getZ(); + const int32_t iZVolSpace = m_regSliceCurrent.getLowerZ(); //Iterate over each cell in the region - for(int32_t iYVolSpace = m_regSliceCurrent.getLowerCorner().getY(); iYVolSpace <= m_regSliceCurrent.getUpperCorner().getY(); iYVolSpace++) + for(int32_t iYVolSpace = m_regSliceCurrent.getLowerY(); iYVolSpace <= m_regSliceCurrent.getUpperY(); iYVolSpace++) { - const uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY(); + const uint32_t uYRegSpace = iYVolSpace - m_regSizeInVoxels.getLowerY(); - for(int32_t iXVolSpace = m_regSliceCurrent.getLowerCorner().getX(); iXVolSpace <= m_regSliceCurrent.getUpperCorner().getX(); iXVolSpace++) + for(int32_t iXVolSpace = m_regSliceCurrent.getLowerX(); iXVolSpace <= m_regSliceCurrent.getUpperX(); iXVolSpace++) { //Current position - const uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX(); + const uint32_t uXRegSpace = iXVolSpace - m_regSizeInVoxels.getLowerX(); //Determine the index into the edge table which tells us which vertices are inside of the surface const uint8_t iCubeIndex = pCurrentBitmask[uXRegSpace][uYRegSpace]; @@ -437,7 +437,7 @@ namespace PolyVox const float fInterp = static_cast(m_tThreshold - m_controller.convertToDensity(v000)) / static_cast(m_controller.convertToDensity(v100) - m_controller.convertToDensity(v000)); - const Vector3DFloat v3dPosition(static_cast(iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()) + fInterp, static_cast(iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()), static_cast(iZVolSpace - m_regSizeInCells.getLowerCorner().getZ())); + const Vector3DFloat v3dPosition(static_cast(iXVolSpace - m_regSizeInVoxels.getLowerX()) + fInterp, static_cast(iYVolSpace - m_regSizeInVoxels.getLowerY()), static_cast(iZVolSpace - m_regSizeInCells.getLowerZ())); Vector3DFloat v3dNormal = (n100*fInterp) + (n000*(1-fInterp)); v3dNormal.normalise(); @@ -451,7 +451,7 @@ namespace PolyVox const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast(uMaterial)); const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); - m_pCurrentVertexIndicesX[iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()][iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()] = uLastVertexIndex; + m_pCurrentVertexIndicesX[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; m_sampVolume.moveNegativeX(); } @@ -463,7 +463,7 @@ namespace PolyVox const float fInterp = static_cast(m_tThreshold - m_controller.convertToDensity(v000)) / static_cast(m_controller.convertToDensity(v010) - m_controller.convertToDensity(v000)); - const Vector3DFloat v3dPosition(static_cast(iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()), static_cast(iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()) + fInterp, static_cast(iZVolSpace - m_regSizeInVoxels.getLowerCorner().getZ())); + const Vector3DFloat v3dPosition(static_cast(iXVolSpace - m_regSizeInVoxels.getLowerX()), static_cast(iYVolSpace - m_regSizeInVoxels.getLowerY()) + fInterp, static_cast(iZVolSpace - m_regSizeInVoxels.getLowerZ())); Vector3DFloat v3dNormal = (n010*fInterp) + (n000*(1-fInterp)); v3dNormal.normalise(); @@ -477,7 +477,7 @@ namespace PolyVox const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast(uMaterial)); const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); - m_pCurrentVertexIndicesY[iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()][iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()] = uLastVertexIndex; + m_pCurrentVertexIndicesY[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; m_sampVolume.moveNegativeY(); } @@ -489,7 +489,7 @@ namespace PolyVox const float fInterp = static_cast(m_tThreshold - m_controller.convertToDensity(v000)) / static_cast(m_controller.convertToDensity(v001) - m_controller.convertToDensity(v000)); - const Vector3DFloat v3dPosition(static_cast(iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()), static_cast(iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()), static_cast(iZVolSpace - m_regSizeInVoxels.getLowerCorner().getZ()) + fInterp); + const Vector3DFloat v3dPosition(static_cast(iXVolSpace - m_regSizeInVoxels.getLowerX()), static_cast(iYVolSpace - m_regSizeInVoxels.getLowerY()), static_cast(iZVolSpace - m_regSizeInVoxels.getLowerZ()) + fInterp); Vector3DFloat v3dNormal = (n001*fInterp) + (n000*(1-fInterp)); v3dNormal.normalise(); @@ -503,7 +503,7 @@ namespace PolyVox const PositionMaterialNormal surfaceVertex(v3dPosition, v3dNormal, static_cast(uMaterial)); const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); - m_pCurrentVertexIndicesZ[iXVolSpace - m_regSizeInVoxels.getLowerCorner().getX()][iYVolSpace - m_regSizeInVoxels.getLowerCorner().getY()] = uLastVertexIndex; + m_pCurrentVertexIndicesZ[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; m_sampVolume.moveNegativeZ(); } @@ -525,17 +525,17 @@ namespace PolyVox indlist[i] = -1; } - const int32_t iZVolSpace = m_regSlicePrevious.getLowerCorner().getZ(); + const int32_t iZVolSpace = m_regSlicePrevious.getLowerZ(); - for(int32_t iYVolSpace = m_regSlicePrevious.getLowerCorner().getY(); iYVolSpace <= m_regSizeInCells.getUpperCorner().getY(); iYVolSpace++) + for(int32_t iYVolSpace = m_regSlicePrevious.getLowerY(); iYVolSpace <= m_regSizeInCells.getUpperY(); iYVolSpace++) { - for(int32_t iXVolSpace = m_regSlicePrevious.getLowerCorner().getX(); iXVolSpace <= m_regSizeInCells.getUpperCorner().getX(); iXVolSpace++) + for(int32_t iXVolSpace = m_regSlicePrevious.getLowerX(); iXVolSpace <= m_regSizeInCells.getUpperX(); iXVolSpace++) { m_sampVolume.setPosition(iXVolSpace,iYVolSpace,iZVolSpace); //Current position - const uint32_t uXRegSpace = m_sampVolume.getPosition().getX() - m_regSizeInVoxels.getLowerCorner().getX(); - const uint32_t uYRegSpace = m_sampVolume.getPosition().getY() - m_regSizeInVoxels.getLowerCorner().getY(); + const uint32_t uXRegSpace = m_sampVolume.getPosition().getX() - m_regSizeInVoxels.getLowerX(); + const uint32_t uYRegSpace = m_sampVolume.getPosition().getY() - m_regSizeInVoxels.getLowerY(); //Determine the index into the edge table which tells us which vertices are inside of the surface const uint8_t iCubeIndex = pPreviousBitmask[uXRegSpace][uYRegSpace]; diff --git a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl index 938cd997..738ce7aa 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SimpleVolume.inl @@ -281,9 +281,9 @@ namespace PolyVox m_regValidRegionInBlocks.setUpperZ(this->m_regValidRegion.getUpperZ() >> m_uBlockSideLengthPower); //Compute the size of the volume in blocks (and note +1 at the end) - m_uWidthInBlocks = m_regValidRegionInBlocks.getUpperCorner().getX() - m_regValidRegionInBlocks.getLowerCorner().getX() + 1; - m_uHeightInBlocks = m_regValidRegionInBlocks.getUpperCorner().getY() - m_regValidRegionInBlocks.getLowerCorner().getY() + 1; - m_uDepthInBlocks = m_regValidRegionInBlocks.getUpperCorner().getZ() - m_regValidRegionInBlocks.getLowerCorner().getZ() + 1; + m_uWidthInBlocks = m_regValidRegionInBlocks.getUpperX() - m_regValidRegionInBlocks.getLowerX() + 1; + m_uHeightInBlocks = m_regValidRegionInBlocks.getUpperY() - m_regValidRegionInBlocks.getLowerY() + 1; + m_uDepthInBlocks = m_regValidRegionInBlocks.getUpperZ() - m_regValidRegionInBlocks.getLowerZ() + 1; m_uNoOfBlocksInVolume = m_uWidthInBlocks * m_uHeightInBlocks * m_uDepthInBlocks; //Allocate the data @@ -304,9 +304,9 @@ namespace PolyVox { //The lower left corner of the volume could be //anywhere, but array indices need to start at zero. - uBlockX -= m_regValidRegionInBlocks.getLowerCorner().getX(); - uBlockY -= m_regValidRegionInBlocks.getLowerCorner().getY(); - uBlockZ -= m_regValidRegionInBlocks.getLowerCorner().getZ(); + uBlockX -= m_regValidRegionInBlocks.getLowerX(); + uBlockY -= m_regValidRegionInBlocks.getLowerY(); + uBlockZ -= m_regValidRegionInBlocks.getLowerZ(); POLYVOX_ASSERT(uBlockX >= 0, "Block coordinate must not be negative."); POLYVOX_ASSERT(uBlockY >= 0, "Block coordinate must not be negative."); diff --git a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl index b76281b9..745a00bc 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl @@ -45,13 +45,13 @@ namespace PolyVox template< typename SrcVolumeType, typename DstVolumeType> void VolumeResampler::execute() { - int32_t uSrcWidth = m_regSrc.getUpperCorner().getX() - m_regSrc.getLowerCorner().getX() + 1; - int32_t uSrcHeight = m_regSrc.getUpperCorner().getY() - m_regSrc.getLowerCorner().getY() + 1; - int32_t uSrcDepth = m_regSrc.getUpperCorner().getZ() - m_regSrc.getLowerCorner().getZ() + 1; + int32_t uSrcWidth = m_regSrc.getUpperX() - m_regSrc.getLowerX() + 1; + int32_t uSrcHeight = m_regSrc.getUpperY() - m_regSrc.getLowerY() + 1; + int32_t uSrcDepth = m_regSrc.getUpperZ() - m_regSrc.getLowerZ() + 1; - int32_t uDstWidth = m_regDst.getUpperCorner().getX() - m_regDst.getLowerCorner().getX() + 1; - int32_t uDstHeight = m_regDst.getUpperCorner().getY() - m_regDst.getLowerCorner().getY() + 1; - int32_t uDstDepth = m_regDst.getUpperCorner().getZ() - m_regDst.getLowerCorner().getZ() + 1; + int32_t uDstWidth = m_regDst.getUpperX() - m_regDst.getLowerX() + 1; + int32_t uDstHeight = m_regDst.getUpperY() - m_regDst.getLowerY() + 1; + int32_t uDstDepth = m_regDst.getUpperZ() - m_regDst.getLowerZ() + 1; if((uSrcWidth == uDstWidth) && (uSrcHeight == uDstHeight) && (uSrcDepth == uDstDepth)) { @@ -66,11 +66,11 @@ namespace PolyVox template< typename SrcVolumeType, typename DstVolumeType> void VolumeResampler::resampleSameSize() { - for(int32_t sz = m_regSrc.getLowerCorner().getZ(), dz = m_regDst.getLowerCorner().getZ(); dz <= m_regDst.getUpperCorner().getZ(); sz++, dz++) + for(int32_t sz = m_regSrc.getLowerZ(), dz = m_regDst.getLowerZ(); dz <= m_regDst.getUpperZ(); sz++, dz++) { - for(int32_t sy = m_regSrc.getLowerCorner().getY(), dy = m_regDst.getLowerCorner().getY(); dy <= m_regDst.getUpperCorner().getY(); sy++, dy++) + for(int32_t sy = m_regSrc.getLowerY(), dy = m_regDst.getLowerY(); dy <= m_regDst.getUpperY(); sy++, dy++) { - for(int32_t sx = m_regSrc.getLowerCorner().getX(), dx = m_regDst.getLowerCorner().getX(); dx <= m_regDst.getUpperCorner().getX(); sx++,dx++) + for(int32_t sx = m_regSrc.getLowerX(), dx = m_regDst.getLowerX(); dx <= m_regDst.getUpperX(); sx++,dx++) { const typename SrcVolumeType::VoxelType& tSrcVoxel = m_pVolSrc->getVoxelAt(sx,sy,sz); const typename DstVolumeType::VoxelType& tDstVoxel = static_cast(tSrcVoxel); @@ -97,19 +97,19 @@ namespace PolyVox typename SrcVolumeType::Sampler sampler(m_pVolSrc); - for(int32_t dz = m_regDst.getLowerCorner().getZ(); dz <= m_regDst.getUpperCorner().getZ(); dz++) + for(int32_t dz = m_regDst.getLowerZ(); dz <= m_regDst.getUpperZ(); dz++) { - for(int32_t dy = m_regDst.getLowerCorner().getY(); dy <= m_regDst.getUpperCorner().getY(); dy++) + for(int32_t dy = m_regDst.getLowerY(); dy <= m_regDst.getUpperY(); dy++) { - for(int32_t dx = m_regDst.getLowerCorner().getX(); dx <= m_regDst.getUpperCorner().getX(); dx++) + for(int32_t dx = m_regDst.getLowerX(); dx <= m_regDst.getUpperX(); dx++) { - float sx = (dx - m_regDst.getLowerCorner().getX()) * fScaleX; - float sy = (dy - m_regDst.getLowerCorner().getY()) * fScaleY; - float sz = (dz - m_regDst.getLowerCorner().getZ()) * fScaleZ; + float sx = (dx - m_regDst.getLowerX()) * fScaleX; + float sy = (dy - m_regDst.getLowerY()) * fScaleY; + float sz = (dz - m_regDst.getLowerZ()) * fScaleZ; - sx += m_regSrc.getLowerCorner().getX(); - sy += m_regSrc.getLowerCorner().getY(); - sz += m_regSrc.getLowerCorner().getZ(); + sx += m_regSrc.getLowerX(); + sy += m_regSrc.getLowerY(); + sz += m_regSrc.getLowerZ(); sampler.setPosition(sx,sy,sz); const typename SrcVolumeType::VoxelType& voxel000 = sampler.peekVoxel0px0py0pz();