Working on refactoring code into namespaces - DOES NOT BUILD

This commit is contained in:
David Williams
2008-07-02 21:36:56 +00:00
parent 0758f81b54
commit 4f546d1dc4
9 changed files with 68 additions and 69 deletions

View File

@ -19,7 +19,6 @@ SET(SRC_FILES
source/SurfaceExtractorsDecimated.cpp
source/SurfaceVertex.cpp
source/Utility.cpp
source/VolumeChangeTracker.cpp
source/VoxelFilters.cpp
)
@ -51,7 +50,6 @@ SET(INC_FILES
include/Utility.h
include/Vector.h
include/Vector.inl
include/VolumeChangeTracker.h
include/VoxelFilters.h
)

View File

@ -55,7 +55,6 @@ namespace PolyVox
typedef Vector<3,uint32> Vector3DUint32;
//----------------------------
class VolumeChangeTracker;
template <typename VoxelType> class BlockVolumeIterator;
}

View File

@ -34,8 +34,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
namespace PolyVox
{
POLYVOX_API std::list<RegionGeometry> getChangedRegionGeometry(VolumeChangeTracker& volume);
uint32 getIndex(uint32 x, uint32 y);
POLYVOX_API void generateRoughMeshDataForRegion(BlockVolume<uint8>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);

View File

@ -1,71 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
Copyright (C) 2006 David Williams
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
******************************************************************************/
#pragma endregion
#ifndef __PolyVox_VolumeChangeTracker_H__
#define __PolyVox_VolumeChangeTracker_H__
#include <list>
#include "PolyVoxCStdInt.h"
#include "Constants.h"
#include "PolyVoxForwardDeclarations.h"
#include "Region.h"
#include "TypeDef.h"
namespace PolyVox
{
/// Voxel scene manager
class POLYVOX_API VolumeChangeTracker
{
public:
//Constructors, etc
VolumeChangeTracker();
~VolumeChangeTracker();
//Getters
void getChangedRegions(std::list<Region>& listToFill) const;
Region getEnclosingRegion(void) const;
uint16 getSideLength(void);
BlockVolume<uint8>* getVolumeData(void) const;
uint8 getVoxelAt(const Vector3DUint16& pos);
uint8 getVoxelAt(uint16 uX, uint16 uY, uint16 uZ);
//Setters
void setAllRegionsUpToDate(bool newUpToDateValue);
void setLockedVoxelAt(uint16 x, uint16 y, uint16 z, uint8 value);
void setVolumeData(BlockVolume<uint8>* volumeDataToSet);
void setVoxelAt(uint16 x, uint16 y, uint16 z, uint8 value);
//Others
void lockRegion(const Region& regToLock);
void unlockRegion(void);
//void markRegionChanged(uint16 firstX, uint16 firstY, uint16 firstZ, uint16 lastX, uint16 lastY, uint16 lastZ);
private:
bool m_bIsLocked;
Region m_regLastLocked;
BlockVolume<uint8>* volumeData;
LinearVolume<bool>* volRegionUpToDate;
};
}
#endif

View File

@ -8,7 +8,6 @@
#include "RegionGeometry.h"
#include "SurfaceAdjusters.h"
#include "SurfaceExtractorsDecimated.h"
#include "VolumeChangeTracker.h"
#include "BlockVolumeIterator.h"
#include <algorithm>
@ -17,50 +16,6 @@ using namespace std;
namespace PolyVox
{
std::list<RegionGeometry> getChangedRegionGeometry(VolumeChangeTracker& volume)
{
std::list<Region> listChangedRegions;
volume.getChangedRegions(listChangedRegions);
std::list<RegionGeometry> listChangedRegionGeometry;
for(std::list<Region>::const_iterator iterChangedRegions = listChangedRegions.begin(); iterChangedRegions != listChangedRegions.end(); ++iterChangedRegions)
{
//Generate the surface
RegionGeometry regionGeometry;
regionGeometry.m_patchSingleMaterial = new IndexedSurfacePatch();
regionGeometry.m_v3dRegionPosition = iterChangedRegions->getLowerCorner();
//generateDecimatedMeshDataForRegion(volume.getVolumeData(), 1, *iterChangedRegions, regionGeometry.m_patchSingleMaterial);
generateReferenceMeshDataForRegion(volume.getVolumeData(), *iterChangedRegions, regionGeometry.m_patchSingleMaterial);
//for(int ct = 0; ct < 2; ct++)
Vector3DInt32 temp = regionGeometry.m_v3dRegionPosition;
//temp /= 16;
/*if(temp.getY() % 32 == 0)
{
//smoothRegionGeometry(volume.getVolumeData(), regionGeometry);
generateDecimatedMeshDataForRegion(volume.getVolumeData(), 0, *iterChangedRegions, regionGeometry.m_patchSingleMaterial);
}
else
{
generateDecimatedMeshDataForRegion(volume.getVolumeData(), 1, *iterChangedRegions, regionGeometry.m_patchSingleMaterial);
//adjustDecimatedGeometry(volume.getVolumeData(), regionGeometry, 1);
}*/
//computeNormalsForVertices(volume.getVolumeData(), regionGeometry, CENTRAL_DIFFERENCE);
//genMultiFromSingle(regionGeometry.m_patchSingleMaterial, regionGeometry.m_patchMultiMaterial);
regionGeometry.m_bContainsSingleMaterialPatch = regionGeometry.m_patchSingleMaterial->getVertices().size() > 0;
regionGeometry.m_bIsEmpty = (regionGeometry.m_patchSingleMaterial->getVertices().size() == 0) || (regionGeometry.m_patchSingleMaterial->getIndices().size() == 0);
listChangedRegionGeometry.push_back(regionGeometry);
}
return listChangedRegionGeometry;
}
uint32 getIndex(uint32 x, uint32 y)
{
return x + (y * (POLYVOX_REGION_SIDE_LENGTH+1));

View File

@ -6,9 +6,10 @@
#include "MarchingCubesTables.h"
#include "Region.h"
#include "RegionGeometry.h"
#include "VolumeChangeTracker.h"
#include "BlockVolumeIterator.h"
#include "../../PolyVoxUtil/include/VolumeChangeTracker.h"
#include <algorithm>
using namespace std;

View File

@ -1,230 +0,0 @@
#pragma region License
/******************************************************************************
This file is part of the PolyVox library
Copyright (C) 2006 David Williams
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
******************************************************************************/
#pragma endregion
#include "GradientEstimators.h"
#include "IndexedSurfacePatch.h"
#include "LinearVolume.h"
#include "MarchingCubesTables.h"
#include "VolumeChangeTracker.h"
#include "RegionGeometry.h"
#include "SurfaceExtractors.h"
#include "SurfaceVertex.h"
#include "Utility.h"
#include "Vector.h"
#include "BlockVolume.h"
#include "BlockVolumeIterator.h"
using namespace std;
namespace PolyVox
{
//////////////////////////////////////////////////////////////////////////
// VolumeChangeTracker
//////////////////////////////////////////////////////////////////////////
VolumeChangeTracker::VolumeChangeTracker()
:m_bIsLocked(false)
,volumeData(0)
{
}
VolumeChangeTracker::~VolumeChangeTracker()
{
}
void VolumeChangeTracker::setVolumeData(BlockVolume<uint8>* volumeDataToSet)
{
volumeData = volumeDataToSet;
volRegionUpToDate = new LinearVolume<bool>(PolyVox::logBase2(POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS));
}
void VolumeChangeTracker::getChangedRegions(std::list<Region>& listToFill) const
{
//Clear the list
listToFill.clear();
//Regenerate meshes.
for(uint16 regionZ = 0; regionZ < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionZ)
//for(uint16 regionZ = 0; regionZ < 1; ++regionZ)
{
for(uint16 regionY = 0; regionY < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionY)
//for(uint16 regionY = 0; regionY < 2; ++regionY)
{
for(uint16 regionX = 0; regionX < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++regionX)
//for(uint16 regionX = 0; regionX < 2; ++regionX)
{
if(volRegionUpToDate->getVoxelAt(regionX, regionY, regionZ) == false)
{
const uint16 firstX = regionX * POLYVOX_REGION_SIDE_LENGTH;
const uint16 firstY = regionY * POLYVOX_REGION_SIDE_LENGTH;
const uint16 firstZ = regionZ * POLYVOX_REGION_SIDE_LENGTH;
const uint16 lastX = firstX + POLYVOX_REGION_SIDE_LENGTH;
const uint16 lastY = firstY + POLYVOX_REGION_SIDE_LENGTH;
const uint16 lastZ = firstZ + POLYVOX_REGION_SIDE_LENGTH;
listToFill.push_back(Region(Vector3DInt32(firstX, firstY, firstZ), Vector3DInt32(lastX, lastY, lastZ)));
}
}
}
}
}
void VolumeChangeTracker::setAllRegionsUpToDate(bool newUpToDateValue)
{
for(uint16 blockZ = 0; blockZ < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++blockZ)
{
for(uint16 blockY = 0; blockY < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++blockY)
{
for(uint16 blockX = 0; blockX < POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS; ++blockX)
{
volRegionUpToDate->setVoxelAt(blockX, blockY, blockZ, newUpToDateValue);
}
}
}
}
uint16 VolumeChangeTracker::getSideLength(void)
{
return volumeData->getSideLength();
}
Region VolumeChangeTracker::getEnclosingRegion(void) const
{
return volumeData->getEnclosingRegion();
}
uint8 VolumeChangeTracker::getVoxelAt(const Vector3DUint16& pos)
{
return getVoxelAt(pos.getX(), pos.getY(), pos.getZ());
}
uint8 VolumeChangeTracker::getVoxelAt(uint16 uX, uint16 uY, uint16 uZ)
{
assert(uX < volumeData->getSideLength());
assert(uY < volumeData->getSideLength());
assert(uZ < volumeData->getSideLength());
BlockVolumeIterator<uint8> volIter(*volumeData);
volIter.setPosition(uX,uY,uZ);
return volIter.getVoxel();
}
BlockVolume<uint8>* VolumeChangeTracker::getVolumeData(void) const
{
return volumeData;
}
void VolumeChangeTracker::setVoxelAt(uint16 x, uint16 y, uint16 z, uint8 value)
{
//FIXME - rather than creating a iterator each time we should have one stored
BlockVolumeIterator<uint8> iterVol(*volumeData);
iterVol.setPosition(x,y,z);
iterVol.setVoxel(value);
//If we are not on a boundary, just mark one region.
if((x % POLYVOX_REGION_SIDE_LENGTH != 0) &&
(x % POLYVOX_REGION_SIDE_LENGTH != POLYVOX_REGION_SIDE_LENGTH-1) &&
(y % POLYVOX_REGION_SIDE_LENGTH != 0) &&
(y % POLYVOX_REGION_SIDE_LENGTH != POLYVOX_REGION_SIDE_LENGTH-1) &&
(z % POLYVOX_REGION_SIDE_LENGTH != 0) &&
(z % POLYVOX_REGION_SIDE_LENGTH != POLYVOX_REGION_SIDE_LENGTH-1))
{
volRegionUpToDate->setVoxelAt(x >> POLYVOX_REGION_SIDE_LENGTH_POWER, y >> POLYVOX_REGION_SIDE_LENGTH_POWER, z >> POLYVOX_REGION_SIDE_LENGTH_POWER, false);
}
else //Mark surrounding regions as well
{
const uint16 regionX = x >> POLYVOX_REGION_SIDE_LENGTH_POWER;
const uint16 regionY = y >> POLYVOX_REGION_SIDE_LENGTH_POWER;
const uint16 regionZ = z >> POLYVOX_REGION_SIDE_LENGTH_POWER;
const uint16 minRegionX = (std::max)(uint16(0),uint16(regionX-1));
const uint16 minRegionY = (std::max)(uint16(0),uint16(regionY-1));
const uint16 minRegionZ = (std::max)(uint16(0),uint16(regionZ-1));
const uint16 maxRegionX = (std::min)(uint16(POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS-1),uint16(regionX+1));
const uint16 maxRegionY = (std::min)(uint16(POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS-1),uint16(regionY+1));
const uint16 maxRegionZ = (std::min)(uint16(POLYVOX_VOLUME_SIDE_LENGTH_IN_REGIONS-1),uint16(regionZ+1));
for(uint16 zCt = minRegionZ; zCt <= maxRegionZ; zCt++)
{
for(uint16 yCt = minRegionY; yCt <= maxRegionY; yCt++)
{
for(uint16 xCt = minRegionX; xCt <= maxRegionX; xCt++)
{
volRegionUpToDate->setVoxelAt(xCt,yCt,zCt,false);
}
}
}
}
}
void VolumeChangeTracker::setLockedVoxelAt(uint16 x, uint16 y, uint16 z, uint8 value)
{
assert(m_bIsLocked);
//FIXME - rather than creating a iterator each time we should have one stored
BlockVolumeIterator<uint8> iterVol(*volumeData);
iterVol.setPosition(x,y,z);
iterVol.setVoxel(value);
}
void VolumeChangeTracker::lockRegion(const Region& regToLock)
{
if(m_bIsLocked)
{
throw std::logic_error("A region is already locked. Please unlock it before locking another.");
}
m_regLastLocked = regToLock;
m_bIsLocked = true;
}
void VolumeChangeTracker::unlockRegion(void)
{
if(!m_bIsLocked)
{
throw std::logic_error("No region is locked. You must lock a region before you can unlock it.");
}
const uint16 firstRegionX = m_regLastLocked.getLowerCorner().getX() >> POLYVOX_REGION_SIDE_LENGTH_POWER;
const uint16 firstRegionY = m_regLastLocked.getLowerCorner().getY() >> POLYVOX_REGION_SIDE_LENGTH_POWER;
const uint16 firstRegionZ = m_regLastLocked.getLowerCorner().getZ() >> POLYVOX_REGION_SIDE_LENGTH_POWER;
const uint16 lastRegionX = m_regLastLocked.getUpperCorner().getX() >> POLYVOX_REGION_SIDE_LENGTH_POWER;
const uint16 lastRegionY = m_regLastLocked.getUpperCorner().getY() >> POLYVOX_REGION_SIDE_LENGTH_POWER;
const uint16 lastRegionZ = m_regLastLocked.getUpperCorner().getZ() >> POLYVOX_REGION_SIDE_LENGTH_POWER;
for(uint16 zCt = firstRegionZ; zCt <= lastRegionZ; zCt++)
{
for(uint16 yCt = firstRegionY; yCt <= lastRegionY; yCt++)
{
for(uint16 xCt = firstRegionX; xCt <= lastRegionX; xCt++)
{
volRegionUpToDate->setVoxelAt(xCt,yCt,zCt,false);
}
}
}
m_bIsLocked = false;
}
}