PolyVox and Thermite3D now support the use of a density component as well as a material component for each voxel.
This commit is contained in:
@ -26,6 +26,7 @@ freely, subject to the following restrictions:
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "GradientEstimators.h"
|
||||
#include "MaterialDensityPair.h"
|
||||
#include "SurfaceExtractor.h"
|
||||
|
||||
#include "Mesh.h"
|
||||
@ -48,7 +49,7 @@ OpenGLWidget::OpenGLWidget(QWidget *parent)
|
||||
timer->start(0);
|
||||
}
|
||||
|
||||
void OpenGLWidget::setVolume(PolyVox::Volume<uint8_t>* volData)
|
||||
void OpenGLWidget::setVolume(PolyVox::Volume<MaterialDensityPair44>* volData)
|
||||
{
|
||||
//First we free anything from the previous volume (if there was one).
|
||||
m_mapOpenGLSurfaceMeshes.clear();
|
||||
@ -62,7 +63,7 @@ void OpenGLWidget::setVolume(PolyVox::Volume<uint8_t>* volData)
|
||||
m_uVolumeHeightInRegions = volData->getHeight() / m_uRegionSideLength;
|
||||
m_uVolumeDepthInRegions = volData->getDepth() / m_uRegionSideLength;
|
||||
|
||||
SurfaceExtractor surfaceExtractor(*volData);
|
||||
SurfaceExtractor<MaterialDensityPair44> surfaceExtractor(*volData);
|
||||
|
||||
//Our volume is broken down into cuboid regions, and we create one mesh for each region.
|
||||
//This three-level for loop iterates over each region.
|
||||
|
@ -45,7 +45,7 @@ class OpenGLWidget : public QGLWidget
|
||||
public:
|
||||
OpenGLWidget(QWidget *parent);
|
||||
|
||||
void setVolume(PolyVox::Volume<uint8_t>* volData);
|
||||
void setVolume(PolyVox::Volume<PolyVox::MaterialDensityPair44>* volData);
|
||||
|
||||
void mouseMoveEvent(QMouseEvent* event);
|
||||
void mousePressEvent(QMouseEvent* event);
|
||||
@ -69,7 +69,7 @@ class OpenGLWidget : public QGLWidget
|
||||
bool m_bUseOpenGLVertexBufferObjects;
|
||||
|
||||
//Creates a volume 128x128x128
|
||||
PolyVox::Volume<uint8_t>* m_volData;
|
||||
PolyVox::Volume<PolyVox::MaterialDensityPair44>* m_volData;
|
||||
|
||||
//Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region
|
||||
std::map<PolyVox::Vector3DUint8, OpenGLSurfaceMesh> m_mapOpenGLSurfaceMeshes;
|
||||
|
@ -23,9 +23,11 @@ freely, subject to the following restrictions:
|
||||
|
||||
#include "Shapes.h"
|
||||
|
||||
#include "MaterialDensityPair.h"
|
||||
|
||||
using namespace PolyVox;
|
||||
|
||||
void createSphereInVolume(Volume<uint8_t>& volData, float fRadius, uint8_t uValue)
|
||||
void createSphereInVolume(Volume<MaterialDensityPair44>& volData, float fRadius, uint8_t uValue)
|
||||
{
|
||||
//This vector hold the position of the center of the volume
|
||||
Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);
|
||||
@ -46,14 +48,14 @@ void createSphereInVolume(Volume<uint8_t>& volData, float fRadius, uint8_t uValu
|
||||
//then we make it solid, otherwise we make it empty space.
|
||||
if(fDistToCenter <= fRadius)
|
||||
{
|
||||
volData.setVoxelAt(x,y,z, uValue);
|
||||
volData.setVoxelAt(x,y,z, MaterialDensityPair44(uValue, uValue > 0 ? MaterialDensityPair44::getMaxDensity() : MaterialDensityPair44::getMinDensity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void createCubeInVolume(Volume<uint8_t>& volData, Vector3DUint16 lowerCorner, Vector3DUint16 upperCorner, uint8_t uValue)
|
||||
void createCubeInVolume(Volume<MaterialDensityPair44>& volData, Vector3DUint16 lowerCorner, Vector3DUint16 upperCorner, uint8_t uValue)
|
||||
{
|
||||
//This three-level for loop iterates over every voxel between the specified corners
|
||||
for (int z = lowerCorner.getZ(); z <= upperCorner.getZ(); z++)
|
||||
@ -62,7 +64,7 @@ void createCubeInVolume(Volume<uint8_t>& volData, Vector3DUint16 lowerCorner, Ve
|
||||
{
|
||||
for (int x = lowerCorner.getX() ; x <= upperCorner.getX(); x++)
|
||||
{
|
||||
volData.setVoxelAt(x,y,z, uValue);
|
||||
volData.setVoxelAt(x,y,z, MaterialDensityPair44(uValue, uValue > 0 ? MaterialDensityPair44::getMaxDensity() : MaterialDensityPair44::getMinDensity()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,9 +24,10 @@ freely, subject to the following restrictions:
|
||||
#ifndef __OpenGLExample_Shapes_H__
|
||||
#define __OpenGLExample_Shapes_H__
|
||||
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
#include "Volume.h"
|
||||
|
||||
void createSphereInVolume(PolyVox::Volume<uint8_t>& volData, float fRadius, uint8_t uValue);
|
||||
void createCubeInVolume(PolyVox::Volume<uint8_t>& volData, PolyVox::Vector3DUint16 lowerCorner, PolyVox::Vector3DUint16 upperCorner, uint8_t uValue);
|
||||
void createSphereInVolume(PolyVox::Volume<PolyVox::MaterialDensityPair44>& volData, float fRadius, uint8_t uValue);
|
||||
void createCubeInVolume(PolyVox::Volume<PolyVox::MaterialDensityPair44>& volData, PolyVox::Vector3DUint16 lowerCorner, PolyVox::Vector3DUint16 upperCorner, uint8_t uValue);
|
||||
|
||||
#endif //__OpenGLExample_Shapes_H__
|
@ -22,6 +22,7 @@ freely, subject to the following restrictions:
|
||||
*******************************************************************************/
|
||||
|
||||
#include "Log.h"
|
||||
#include "MaterialDensityPair.h"
|
||||
#include "Volume.h"
|
||||
#include "SurfaceMesh.h"
|
||||
#include "PolyVoxImpl/Utility.h"
|
||||
@ -70,7 +71,8 @@ void exampleLog(string message, int severity)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
logHandler = &exampleLog;
|
||||
Volume<uint8_t> volData(g_uVolumeSideLength, g_uVolumeSideLength, g_uVolumeSideLength);
|
||||
Volume<MaterialDensityPair44> volData(g_uVolumeSideLength, g_uVolumeSideLength, g_uVolumeSideLength);
|
||||
Volume<MaterialDensityPair44> volDataAveraged(g_uVolumeSideLength, g_uVolumeSideLength, g_uVolumeSideLength);
|
||||
|
||||
//Make our volume contain a sphere in the center.
|
||||
uint16_t minPos = 0;
|
||||
@ -106,14 +108,75 @@ int main(int argc, char *argv[])
|
||||
createCubeInVolume(volData, Vector3DUint16(midPos+1, minPos, midPos+1), Vector3DUint16(maxPos, midPos-1, maxPos), 0);
|
||||
createCubeInVolume(volData, Vector3DUint16(minPos, midPos+1, midPos+1), Vector3DUint16(midPos-1, maxPos, maxPos), 0);
|
||||
|
||||
createCubeInVolume(volData, Vector3DUint16(1, midPos-10, midPos-10), Vector3DUint16(maxPos-1, midPos+10, midPos+10), 255);
|
||||
createCubeInVolume(volData, Vector3DUint16(midPos-10, 1, midPos-10), Vector3DUint16(midPos+10, maxPos-1, midPos+10), 255);
|
||||
createCubeInVolume(volData, Vector3DUint16(midPos-10, midPos-10 ,1), Vector3DUint16(midPos+10, midPos+10, maxPos-1), 255);
|
||||
createCubeInVolume(volData, Vector3DUint16(1, midPos-10, midPos-10), Vector3DUint16(maxPos-1, midPos+10, midPos+10), MaterialDensityPair44::getMaxDensity());
|
||||
createCubeInVolume(volData, Vector3DUint16(midPos-10, 1, midPos-10), Vector3DUint16(midPos+10, maxPos-1, midPos+10), MaterialDensityPair44::getMaxDensity());
|
||||
createCubeInVolume(volData, Vector3DUint16(midPos-10, midPos-10 ,1), Vector3DUint16(midPos+10, midPos+10, maxPos-1), MaterialDensityPair44::getMaxDensity());
|
||||
|
||||
//createCubeInVolume(volData, Vector3DUint16(1, 1, 1), Vector3DUint16(maxPos-1, maxPos-1, midPos/4), 255);
|
||||
|
||||
for (int z = 1; z < volData.getWidth()-1; z++)
|
||||
{
|
||||
for (int y = 1; y < volData.getHeight()-1; y++)
|
||||
{
|
||||
for (int x = 1; x < volData.getDepth()-1; x++)
|
||||
{
|
||||
int uDensity = 0;
|
||||
uDensity += volData.getVoxelAt(x-1,y-1,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y-1,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y-1,z+1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y-0,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y-0,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y-0,z+1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y+1,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y+1,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-1,y+1,z+1).getDensity();
|
||||
|
||||
uDensity += volData.getVoxelAt(x-0,y-1,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y-1,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y-1,z+1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y-0,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y-0,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y-0,z+1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y+1,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y+1,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x-0,y+1,z+1).getDensity();
|
||||
|
||||
uDensity += volData.getVoxelAt(x+1,y-1,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y-1,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y-1,z+1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y-0,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y-0,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y-0,z+1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y+1,z-1).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y+1,z-0).getDensity();
|
||||
uDensity += volData.getVoxelAt(x+1,y+1,z+1).getDensity();
|
||||
uDensity /= 27;
|
||||
|
||||
MaterialDensityPair44 val = volData.getVoxelAt(x,y,z);
|
||||
val.setDensity(uDensity);
|
||||
|
||||
volDataAveraged.setVoxelAt(x,y,z,val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*std::vector<long int> counts(256);
|
||||
fill(counts.begin(), counts.end(), 0);
|
||||
|
||||
for (int z = 0; z < volData.getWidth(); z++)
|
||||
{
|
||||
for (int y = 0; y < volData.getHeight(); y++)
|
||||
{
|
||||
for (int x = 0; x < volData.getDepth(); x++)
|
||||
{
|
||||
counts[volData.getVoxelAt(x,y,z).getMaterial()]++;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
cout << "Tidying memory...";
|
||||
volData.tidyUpMemory(0);
|
||||
volDataAveraged.tidyUpMemory(0);
|
||||
cout << "done." << endl;
|
||||
|
||||
QApplication app(argc, argv);
|
||||
@ -125,7 +188,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
QTime time;
|
||||
time.start();
|
||||
openGLWidget.setVolume(&volData);
|
||||
openGLWidget.setVolume(&volDataAveraged);
|
||||
cout << endl << "Time taken = " << time.elapsed() / 1000.0f << "s" << endl << endl;
|
||||
|
||||
//return 0;
|
||||
|
Reference in New Issue
Block a user