From 849f635d04cbc0420103fc05bdb6441e83fd6251 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 7 Jun 2008 21:21:14 +0000 Subject: [PATCH] Almost finished new marching cubes implementation. Just normal calculation and memory pool still to do. --- source/SurfaceExtractors.cpp | 141 ++++++++++++++++++++++++++++++----- 1 file changed, 123 insertions(+), 18 deletions(-) diff --git a/source/SurfaceExtractors.cpp b/source/SurfaceExtractors.cpp index 1a6fea56..8b50261d 100644 --- a/source/SurfaceExtractors.cpp +++ b/source/SurfaceExtractors.cpp @@ -149,27 +149,132 @@ namespace PolyVox const uint16_t x = volIter.getPosX() - offset.getX(); const uint16_t y = volIter.getPosY() - offset.getY(); - //Voxels values - const uint8_t v000 = volIter.getVoxel(); - const uint8_t v100 = volIter.peekVoxel1px0py0pz(); - const uint8_t v010 = volIter.peekVoxel0px1py0pz(); - const uint8_t v110 = volIter.peekVoxel1px1py0pz(); - const uint8_t v001 = volIter.peekVoxel0px0py1pz(); - const uint8_t v101 = volIter.peekVoxel1px0py1pz(); - const uint8_t v011 = volIter.peekVoxel0px1py1pz(); - const uint8_t v111 = volIter.peekVoxel1px1py1pz(); - //Determine the index into the edge table which tells us which vertices are inside of the surface uint8_t iCubeIndex = 0; - if (v000 == 0) iCubeIndex |= 1; - if (v100 == 0) iCubeIndex |= 2; - if (v110 == 0) iCubeIndex |= 4; - if (v010 == 0) iCubeIndex |= 8; - if (v001 == 0) iCubeIndex |= 16; - if (v101 == 0) iCubeIndex |= 32; - if (v111 == 0) iCubeIndex |= 64; - if (v011 == 0) iCubeIndex |= 128; + if((x==0) && (y==0)) + { + const uint8_t v000 = volIter.getVoxel(); + const uint8_t v100 = volIter.peekVoxel1px0py0pz(); + const uint8_t v010 = volIter.peekVoxel0px1py0pz(); + const uint8_t v110 = volIter.peekVoxel1px1py0pz(); + + const uint8_t v001 = volIter.peekVoxel0px0py1pz(); + const uint8_t v101 = volIter.peekVoxel1px0py1pz(); + const uint8_t v011 = volIter.peekVoxel0px1py1pz(); + const uint8_t v111 = volIter.peekVoxel1px1py1pz(); + + if (v000 == 0) iCubeIndex |= 1; + if (v100 == 0) iCubeIndex |= 2; + if (v110 == 0) iCubeIndex |= 4; + if (v010 == 0) iCubeIndex |= 8; + if (v001 == 0) iCubeIndex |= 16; + if (v101 == 0) iCubeIndex |= 32; + if (v111 == 0) iCubeIndex |= 64; + if (v011 == 0) iCubeIndex |= 128; + } + else if((x>0) && y==0) + { + const uint8_t v100 = volIter.peekVoxel1px0py0pz(); + const uint8_t v110 = volIter.peekVoxel1px1py0pz(); + + const uint8_t v101 = volIter.peekVoxel1px0py1pz(); + const uint8_t v111 = volIter.peekVoxel1px1py1pz(); + + //x + uint8_t iPreviousCubeIndexX = bitmask[getIndex(x-1,y)]; + uint8_t srcBit6 = iPreviousCubeIndexX & 64; + uint8_t destBit7 = srcBit6 << 1; + + uint8_t srcBit5 = iPreviousCubeIndexX & 32; + uint8_t destBit4 = srcBit5 >> 1; + + uint8_t srcBit2 = iPreviousCubeIndexX & 4; + uint8_t destBit3 = srcBit2 << 1; + + uint8_t srcBit1 = iPreviousCubeIndexX & 2; + uint8_t destBit0 = srcBit1 >> 1; + + iCubeIndex |= destBit0; + if (v100 == 0) iCubeIndex |= 2; + if (v110 == 0) iCubeIndex |= 4; + iCubeIndex |= destBit3; + iCubeIndex |= destBit4; + if (v101 == 0) iCubeIndex |= 32; + if (v111 == 0) iCubeIndex |= 64; + iCubeIndex |= destBit7; + } + else if((x==0) && (y>0)) + { + const uint8_t v010 = volIter.peekVoxel0px1py0pz(); + const uint8_t v110 = volIter.peekVoxel1px1py0pz(); + + const uint8_t v011 = volIter.peekVoxel0px1py1pz(); + const uint8_t v111 = volIter.peekVoxel1px1py1pz(); + + //y + uint8_t iPreviousCubeIndexY = bitmask[getIndex(x,y-1)]; + uint8_t srcBit7 = iPreviousCubeIndexY & 128; + uint8_t destBit4 = srcBit7 >> 3; + + uint8_t srcBit6 = iPreviousCubeIndexY & 64; + uint8_t destBit5 = srcBit6 >> 1; + + uint8_t srcBit3 = iPreviousCubeIndexY & 8; + uint8_t destBit0 = srcBit3 >> 3; + + uint8_t srcBit2 = iPreviousCubeIndexY & 4; + uint8_t destBit1 = srcBit2 >> 1; + + iCubeIndex |= destBit0; + iCubeIndex |= destBit1; + if (v110 == 0) iCubeIndex |= 4; + if (v010 == 0) iCubeIndex |= 8; + iCubeIndex |= destBit4; + iCubeIndex |= destBit5; + if (v111 == 0) iCubeIndex |= 64; + if (v011 == 0) iCubeIndex |= 128; + } + else + { + //const uint8_t v000 = volIter.getVoxel(); + //const uint8_t v100 = volIter.peekVoxel1px0py0pz(); + //const uint8_t v010 = volIter.peekVoxel0px1py0pz(); + const uint8_t v110 = volIter.peekVoxel1px1py0pz(); + + const uint8_t v111 = volIter.peekVoxel1px1py1pz(); + + //y + uint8_t iPreviousCubeIndexY = bitmask[getIndex(x,y-1)]; + uint8_t srcBit7 = iPreviousCubeIndexY & 128; + uint8_t destBit4 = srcBit7 >> 3; + + uint8_t srcBit6 = iPreviousCubeIndexY & 64; + uint8_t destBit5 = srcBit6 >> 1; + + uint8_t srcBit3 = iPreviousCubeIndexY & 8; + uint8_t destBit0 = srcBit3 >> 3; + + uint8_t srcBit2 = iPreviousCubeIndexY & 4; + uint8_t destBit1 = srcBit2 >> 1; + + //x + uint8_t iPreviousCubeIndexX = bitmask[getIndex(x-1,y)]; + srcBit6 = iPreviousCubeIndexX & 64; + uint8_t destBit7 = srcBit6 << 1; + + srcBit2 = iPreviousCubeIndexX & 4; + uint8_t destBit3 = srcBit2 << 1; + + iCubeIndex |= destBit0; + iCubeIndex |= destBit1; + if (v110 == 0) iCubeIndex |= 4; + iCubeIndex |= destBit3; + iCubeIndex |= destBit4; + iCubeIndex |= destBit5; + if (v111 == 0) iCubeIndex |= 64; + iCubeIndex |= destBit7; + } //Save the bitmask bitmask[getIndex(x,y)] = iCubeIndex;