SurfaceExtractor now returns shared pointer to surface.

This commit is contained in:
David Williams 2009-05-29 22:16:51 +00:00
parent b1e111d940
commit 358d07b234
4 changed files with 16 additions and 15 deletions

View File

@ -49,9 +49,6 @@ void OpenGLWidget::setVolume(PolyVox::Volume<PolyVox::uint8_t>* volData)
{ {
for(PolyVox::uint16_t uRegionX = 0; uRegionX < m_uVolumeWidthInRegions; ++uRegionX) for(PolyVox::uint16_t uRegionX = 0; uRegionX < m_uVolumeWidthInRegions; ++uRegionX)
{ {
//Create a new surface patch (which is basiaclly the PolyVox term for a mesh).
IndexedSurfacePatch* ispCurrent = new IndexedSurfacePatch();
//Compute the extents of the current region //Compute the extents of the current region
//FIXME - This is a little complex? PolyVox could //FIXME - This is a little complex? PolyVox could
//provide more functions for dealing with regions? //provide more functions for dealing with regions?
@ -68,23 +65,23 @@ void OpenGLWidget::setVolume(PolyVox::Volume<PolyVox::uint8_t>* volData)
//Extract the surface for this region //Extract the surface for this region
//extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), ispCurrent); //extractSurface(m_volData, 0, PolyVox::Region(regLowerCorner, regUpperCorner), ispCurrent);
surfaceExtractor.extractSurfaceForRegion(PolyVox::Region(regLowerCorner, regUpperCorner), ispCurrent); POLYVOX_SHARED_PTR<IndexedSurfacePatch> isp = surfaceExtractor.extractSurfaceForRegion(PolyVox::Region(regLowerCorner, regUpperCorner));
computeNormalsForVertices(m_volData, *ispCurrent, SOBEL_SMOOTHED); computeNormalsForVertices(m_volData, *(isp.get()), SOBEL_SMOOTHED);
//*ispCurrent = getSmoothedSurface(*ispCurrent); //*ispCurrent = getSmoothedSurface(*ispCurrent);
ispCurrent->smooth(0.3f); isp->smooth(0.3f);
//ispCurrent->generateAveragedFaceNormals(true); //ispCurrent->generateAveragedFaceNormals(true);
Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ); Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);
if(m_bUseOpenGLVertexBufferObjects) if(m_bUseOpenGLVertexBufferObjects)
{ {
OpenGLSurfacePatch openGLSurfacePatch = BuildOpenGLSurfacePatch(*ispCurrent); OpenGLSurfacePatch openGLSurfacePatch = BuildOpenGLSurfacePatch(*(isp.get()));
m_mapOpenGLSurfacePatches.insert(make_pair(v3dRegPos, openGLSurfacePatch)); m_mapOpenGLSurfacePatches.insert(make_pair(v3dRegPos, openGLSurfacePatch));
} }
else else
{ {
m_mapIndexedSurfacePatches.insert(make_pair(v3dRegPos, ispCurrent)); m_mapIndexedSurfacePatches.insert(make_pair(v3dRegPos, isp));
} }
//delete ispCurrent; //delete ispCurrent;
} }
@ -170,7 +167,7 @@ void OpenGLWidget::paintGL()
} }
else else
{ {
IndexedSurfacePatch* ispCurrent = m_mapIndexedSurfacePatches[v3dRegPos]; POLYVOX_SHARED_PTR<IndexedSurfacePatch> ispCurrent = m_mapIndexedSurfacePatches[v3dRegPos];
renderRegionImmediateMode(*ispCurrent); renderRegionImmediateMode(*ispCurrent);
} }

View File

@ -51,7 +51,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 //Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region
std::map<PolyVox::Vector3DUint8, OpenGLSurfacePatch> m_mapOpenGLSurfacePatches; std::map<PolyVox::Vector3DUint8, OpenGLSurfacePatch> m_mapOpenGLSurfacePatches;
std::map<PolyVox::Vector3DUint8, PolyVox::IndexedSurfacePatch*> m_mapIndexedSurfacePatches; std::map<PolyVox::Vector3DUint8, POLYVOX_SHARED_PTR<PolyVox::IndexedSurfacePatch> > m_mapIndexedSurfacePatches;
unsigned int m_uRegionSideLength; unsigned int m_uRegionSideLength;
unsigned int m_uVolumeWidthInRegions; unsigned int m_uVolumeWidthInRegions;

View File

@ -41,7 +41,7 @@ namespace PolyVox
void setLodLevel(uint8_t uLodLevel); void setLodLevel(uint8_t uLodLevel);
void extractSurfaceForRegion(Region region, IndexedSurfacePatch* singleMaterialPatch); POLYVOX_SHARED_PTR<IndexedSurfacePatch> extractSurfaceForRegion(Region region);
private: private:
uint8_t m_uLodLevel; uint8_t m_uLodLevel;

View File

@ -23,17 +23,21 @@ namespace PolyVox
m_uLodLevel = uLodLevel; m_uLodLevel = uLodLevel;
} }
void SurfaceExtractor::extractSurfaceForRegion(Region region, IndexedSurfacePatch* singleMaterialPatch) POLYVOX_SHARED_PTR<IndexedSurfacePatch> SurfaceExtractor::extractSurfaceForRegion(Region region)
{ {
POLYVOX_SHARED_PTR<IndexedSurfacePatch> result(new IndexedSurfacePatch());
if(m_uLodLevel == 0) if(m_uLodLevel == 0)
{ {
extractSurfaceForRegionLevel0(&m_volData, region, singleMaterialPatch); extractSurfaceForRegionLevel0(&m_volData, region, result.get());
} }
else else
{ {
extractDecimatedSurfaceImpl(&m_volData, m_uLodLevel, region, singleMaterialPatch); extractDecimatedSurfaceImpl(&m_volData, m_uLodLevel, region, result.get());
} }
singleMaterialPatch->m_Region = region; result->m_Region = region;
return result;
} }
uint32_t SurfaceExtractor::getIndex(uint32_t x, uint32_t y, uint32_t regionWidth) uint32_t SurfaceExtractor::getIndex(uint32_t x, uint32_t y, uint32_t regionWidth)