Rolled back some breaking changes.

This commit is contained in:
David Williams
2008-05-25 11:36:59 +00:00
parent 0ca93a7452
commit 05f709482a
5 changed files with 32 additions and 70 deletions

View File

@ -30,10 +30,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
namespace PolyVox namespace PolyVox
{ {
void generateRoughMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch); void generateRoughMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, boost::uint16_t regionX, boost::uint16_t regionY, boost::uint16_t regionZ, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch);
Vector3DFloat computeNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod); Vector3DFloat computeNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
void generateSmoothMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch); void generateSmoothMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, boost::uint16_t regionX, boost::uint16_t regionY, boost::uint16_t regionZ, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch);
Vector3DFloat computeSmoothNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod); Vector3DFloat computeSmoothNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
} }

View File

@ -50,7 +50,7 @@ namespace PolyVox
VoxelType getVoxel(void) const; VoxelType getVoxel(void) const;
void setPosition(boost::uint16_t xPos, boost::uint16_t yPos, boost::uint16_t zPos); void setPosition(boost::uint16_t xPos, boost::uint16_t yPos, boost::uint16_t zPos);
void setValidRegion(const Region& region); void setValidRegion(boost::uint16_t xFirst, boost::uint16_t yFirst, boost::uint16_t zFirst, boost::uint16_t xLast, boost::uint16_t yLast, boost::uint16_t zLast);
void setVoxel(VoxelType tValue); void setVoxel(VoxelType tValue);
bool isValidForRegion(void) const; bool isValidForRegion(void) const;

View File

@ -190,15 +190,15 @@ namespace PolyVox
} }
template <typename VoxelType> template <typename VoxelType>
void VolumeIterator<VoxelType>::setValidRegion(const Region& region) void VolumeIterator<VoxelType>::setValidRegion(boost::uint16_t xFirst, boost::uint16_t yFirst, boost::uint16_t zFirst, boost::uint16_t xLast, boost::uint16_t yLast, boost::uint16_t zLast)
{ {
mXRegionFirst = region.getLowerCorner().x(); mXRegionFirst = xFirst;
mYRegionFirst = region.getLowerCorner().y(); mYRegionFirst = yFirst;
mZRegionFirst = region.getLowerCorner().z(); mZRegionFirst = zFirst;
mXRegionLast = region.getUpperCorner().x(); mXRegionLast = xLast;
mYRegionLast = region.getUpperCorner().y(); mYRegionLast = yLast;
mZRegionLast = region.getUpperCorner().z(); mZRegionLast = zLast;
mXRegionFirstBlock = mXRegionFirst >> mVolume.m_uBlockSideLengthPower; mXRegionFirstBlock = mXRegionFirst >> mVolume.m_uBlockSideLengthPower;
mYRegionFirstBlock = mYRegionFirst >> mVolume.m_uBlockSideLengthPower; mYRegionFirstBlock = mYRegionFirst >> mVolume.m_uBlockSideLengthPower;

View File

@ -4,51 +4,36 @@
#include "GradientEstimators.h" #include "GradientEstimators.h"
#include "IndexedSurfacePatch.h" #include "IndexedSurfacePatch.h"
#include "MarchingCubesTables.h" #include "MarchingCubesTables.h"
#include "Region.h"
#include "VolumeIterator.h" #include "VolumeIterator.h"
using namespace boost; using namespace boost;
namespace PolyVox namespace PolyVox
{ {
void generateRoughMeshDataForRegion(BlockVolume<uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch) void generateRoughMeshDataForRegion(BlockVolume<uint8_t>* volumeData, uint16_t regionX, uint16_t regionY, uint16_t regionZ, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch)
{ {
//First and last voxels in the region //First and last voxels in the region
//const uint16_t firstX = regionX * POLYVOX_REGION_SIDE_LENGTH; const uint16_t firstX = regionX * POLYVOX_REGION_SIDE_LENGTH;
//const uint16_t firstY = regionY * POLYVOX_REGION_SIDE_LENGTH; const uint16_t firstY = regionY * POLYVOX_REGION_SIDE_LENGTH;
//const uint16_t firstZ = regionZ * POLYVOX_REGION_SIDE_LENGTH; const uint16_t firstZ = regionZ * POLYVOX_REGION_SIDE_LENGTH;
//const uint16_t lastX = (std::min)(firstX + POLYVOX_REGION_SIDE_LENGTH-1,volumeData->getSideLength()-2); const uint16_t lastX = (std::min)(firstX + POLYVOX_REGION_SIDE_LENGTH-1,volumeData->getSideLength()-2);
//const uint16_t lastY = (std::min)(firstY + POLYVOX_REGION_SIDE_LENGTH-1,volumeData->getSideLength()-2); const uint16_t lastY = (std::min)(firstY + POLYVOX_REGION_SIDE_LENGTH-1,volumeData->getSideLength()-2);
//const uint16_t lastZ = (std::min)(firstZ + POLYVOX_REGION_SIDE_LENGTH-1,volumeData->getSideLength()-2); const uint16_t lastZ = (std::min)(firstZ + POLYVOX_REGION_SIDE_LENGTH-1,volumeData->getSideLength()-2);
//We don't go right to the edge
Region regVolume = volumeData->getEnclosingRegion();
regVolume.setUpperCorner(regVolume.getUpperCorner() - Vector3DInt32(1,1,1));
region.cropTo(regVolume);
//const uint16_t firstX = (uint16_t)region.getLowerCorner().x();
//const uint16_t firstY = (uint16_t)region.getLowerCorner().y();
//const uint16_t firstZ = (uint16_t)region.getLowerCorner().z();
//FIXME - for this next step, define some operation to crop one region to another. We can then crop to the volume
//const uint16_t lastX = static_cast<uint16_t>(region.getUpperCorner().x());
//const uint16_t lastY = static_cast<uint16_t>(region.getUpperCorner().y());
//const uint16_t lastZ = static_cast<uint16_t>(region.getUpperCorner().z());
//Offset from lower block corner //Offset from lower block corner
const Vector3DFloat offset(region.getLowerCorner()); const Vector3DFloat offset(firstX,firstY,firstZ);
Vector3DFloat vertlist[12]; Vector3DFloat vertlist[12];
uint8_t vertMaterials[12]; uint8_t vertMaterials[12];
VolumeIterator<boost::uint8_t> volIter(*volumeData); VolumeIterator<boost::uint8_t> volIter(*volumeData);
volIter.setValidRegion(region); volIter.setValidRegion(firstX,firstY,firstZ,lastX,lastY,lastZ);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
//Get mesh data //Get mesh data
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
//Iterate over each cell in the region //Iterate over each cell in the region
for(volIter.setPosition(region.getLowerCorner().x(),region.getLowerCorner().y(),region.getLowerCorner().z());volIter.isValidForRegion();volIter.moveForwardInRegion()) for(volIter.setPosition(firstX,firstY,firstZ);volIter.isValidForRegion();volIter.moveForwardInRegion())
{ {
//Current position //Current position
const uint16_t x = volIter.getPosX(); const uint16_t x = volIter.getPosX();
@ -425,36 +410,23 @@ namespace PolyVox
return result; return result;
} }
void generateSmoothMeshDataForRegion(BlockVolume<uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch) void generateSmoothMeshDataForRegion(BlockVolume<uint8_t>* volumeData, uint16_t regionX, uint16_t regionY, uint16_t regionZ, IndexedSurfacePatch* singleMaterialPatch, IndexedSurfacePatch* multiMaterialPatch)
{ {
//First and last voxels in the region //First and last voxels in the region
//const uint16_t firstX = regionX * POLYVOX_REGION_SIDE_LENGTH; const uint16_t firstX = regionX * POLYVOX_REGION_SIDE_LENGTH;
//const uint16_t firstY = regionY * POLYVOX_REGION_SIDE_LENGTH; const uint16_t firstY = regionY * POLYVOX_REGION_SIDE_LENGTH;
//const uint16_t firstZ = regionZ * POLYVOX_REGION_SIDE_LENGTH; const uint16_t firstZ = regionZ * POLYVOX_REGION_SIDE_LENGTH;
//const uint16_t lastX = (std::min)(firstX + POLYVOX_REGION_SIDE_LENGTH-1,volumeData->getSideLength()-2); const uint16_t lastX = (std::min)(firstX + POLYVOX_REGION_SIDE_LENGTH-1,volumeData->getSideLength()-2);
//const uint16_t lastY = (std::min)(firstY + POLYVOX_REGION_SIDE_LENGTH-1,volumeData->getSideLength()-2); const uint16_t lastY = (std::min)(firstY + POLYVOX_REGION_SIDE_LENGTH-1,volumeData->getSideLength()-2);
//const uint16_t lastZ = (std::min)(firstZ + POLYVOX_REGION_SIDE_LENGTH-1,volumeData->getSideLength()-2); const uint16_t lastZ = (std::min)(firstZ + POLYVOX_REGION_SIDE_LENGTH-1,volumeData->getSideLength()-2);
//We don't go right to the edge
Region regVolume = volumeData->getEnclosingRegion();
regVolume.setUpperCorner(regVolume.getUpperCorner() - Vector3DInt32(1,1,1));
region.cropTo(regVolume);
//const uint16_t firstX = (uint16_t)region.getLowerCorner().x();
//const uint16_t firstY = (uint16_t)region.getLowerCorner().y();
//const uint16_t firstZ = (uint16_t)region.getLowerCorner().z();
//FIXME - for this next step, define some operation to crop one region to another. We can then crop to the volume
//const uint16_t lastX = static_cast<uint16_t>(region.getUpperCorner().x());
//const uint16_t lastY = static_cast<uint16_t>(region.getUpperCorner().y());
//const uint16_t lastZ = static_cast<uint16_t>(region.getUpperCorner().z());
//Offset from lower block corner //Offset from lower block corner
const Vector3DFloat offset(region.getLowerCorner()); const Vector3DFloat offset(firstX,firstY,firstZ);
Vector3DFloat vertlist[12]; Vector3DFloat vertlist[12];
uint8_t vertMaterials[12]; uint8_t vertMaterials[12];
VolumeIterator<boost::uint8_t> volIter(*volumeData); VolumeIterator<boost::uint8_t> volIter(*volumeData);
volIter.setValidRegion(region); volIter.setValidRegion(firstX,firstY,firstZ,lastX,lastY,lastZ);
const float threshold = 0.5f; const float threshold = 0.5f;
@ -463,7 +435,7 @@ namespace PolyVox
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
//Iterate over each cell in the region //Iterate over each cell in the region
for(volIter.setPosition(region.getLowerCorner().x(),region.getLowerCorner().y(),region.getLowerCorner().z());volIter.isValidForRegion();volIter.moveForwardInRegion()) for(volIter.setPosition(firstX,firstY,firstZ);volIter.isValidForRegion();volIter.moveForwardInRegion())
{ {
//Current position //Current position
const uint16_t x = volIter.getPosX(); const uint16_t x = volIter.getPosX();

View File

@ -24,7 +24,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "LinearVolume.h" #include "LinearVolume.h"
#include "MarchingCubesTables.h" #include "MarchingCubesTables.h"
#include "VolumeChangeTracker.h" #include "VolumeChangeTracker.h"
#include "Region.h"
#include "RegionGeometry.h" #include "RegionGeometry.h"
#include "SurfaceExtractors.h" #include "SurfaceExtractors.h"
#include "SurfaceVertex.h" #include "SurfaceVertex.h"
@ -84,16 +83,7 @@ namespace PolyVox
regionGeometry.m_patchMultiMaterial = new IndexedSurfacePatch(true); regionGeometry.m_patchMultiMaterial = new IndexedSurfacePatch(true);
regionGeometry.m_v3dRegionPosition = Vector3DInt32(regionX, regionY, regionZ); regionGeometry.m_v3dRegionPosition = Vector3DInt32(regionX, regionY, regionZ);
const uint16_t firstX = regionX * POLYVOX_REGION_SIDE_LENGTH; generateRoughMeshDataForRegion(volumeData, regionX,regionY,regionZ, regionGeometry.m_patchSingleMaterial, regionGeometry.m_patchMultiMaterial);
const uint16_t firstY = regionY * POLYVOX_REGION_SIDE_LENGTH;
const uint16_t firstZ = regionZ * POLYVOX_REGION_SIDE_LENGTH;
const uint16_t lastX = firstX + POLYVOX_REGION_SIDE_LENGTH-1;
const uint16_t lastY = firstY + POLYVOX_REGION_SIDE_LENGTH-1;
const uint16_t lastZ = firstZ + POLYVOX_REGION_SIDE_LENGTH-1;
Region region(Vector3DInt32(firstX,firstY,firstZ),Vector3DInt32(lastX,lastY,lastZ));
generateRoughMeshDataForRegion(volumeData, region, regionGeometry.m_patchSingleMaterial, regionGeometry.m_patchMultiMaterial);
regionGeometry.m_bContainsSingleMaterialPatch = regionGeometry.m_patchSingleMaterial->getVertices().size() > 0; regionGeometry.m_bContainsSingleMaterialPatch = regionGeometry.m_patchSingleMaterial->getVertices().size() > 0;
regionGeometry.m_bContainsMultiMaterialPatch = regionGeometry.m_patchMultiMaterial->getVertices().size() > 0; regionGeometry.m_bContainsMultiMaterialPatch = regionGeometry.m_patchMultiMaterial->getVertices().size() > 0;
@ -145,7 +135,7 @@ namespace PolyVox
lastZ = std::min(lastZ,int(volumeData->getSideLength()-1)); lastZ = std::min(lastZ,int(volumeData->getSideLength()-1));
VolumeIterator<boost::uint8_t> volIter(*volumeData); VolumeIterator<boost::uint8_t> volIter(*volumeData);
volIter.setValidRegion(Region(Vector3DInt32(firstX,firstY,firstZ),Vector3DInt32(lastX,lastY,lastZ))); volIter.setValidRegion(firstX,firstY,firstZ,lastX,lastY,lastZ);
volIter.setPosition(firstX,firstY,firstZ); volIter.setPosition(firstX,firstY,firstZ);
while(volIter.isValidForRegion()) while(volIter.isValidForRegion())
{ {