More work on Smooth LOD.
This commit is contained in:
parent
ccfa7db1fa
commit
46ac159ec1
@ -34,6 +34,28 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMat
|
|||||||
m_uEndIndex = vecIndices.size();
|
m_uEndIndex = vecIndices.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenGLWidget::setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<PositionMaterialNormal>& surfaceMesh)
|
||||||
|
{
|
||||||
|
//Convienient access to the vertices and indices
|
||||||
|
const vector<uint32_t>& vecIndices = surfaceMesh.getIndices();
|
||||||
|
const vector<PositionMaterialNormal>& vecVertices = surfaceMesh.getVertices();
|
||||||
|
|
||||||
|
//Build an OpenGL index buffer
|
||||||
|
glGenBuffers(1, &indexBufferLow);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferLow);
|
||||||
|
const GLvoid* pIndices = static_cast<const GLvoid*>(&(vecIndices[0]));
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vecIndices.size() * sizeof(uint32_t), pIndices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
//Build an OpenGL vertex buffer
|
||||||
|
glGenBuffers(1, &vertexBufferLow);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferLow);
|
||||||
|
const GLvoid* pVertices = static_cast<const GLvoid*>(&(vecVertices[0]));
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal), pVertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
m_uBeginIndexLow = 0;
|
||||||
|
m_uEndIndexLow = vecIndices.size();
|
||||||
|
}
|
||||||
|
|
||||||
void OpenGLWidget::initializeGL()
|
void OpenGLWidget::initializeGL()
|
||||||
{
|
{
|
||||||
//We need GLEW to access recent OpenGL functionality
|
//We need GLEW to access recent OpenGL functionality
|
||||||
@ -125,6 +147,16 @@ void OpenGLWidget::paintGL()
|
|||||||
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12);
|
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12);
|
||||||
|
|
||||||
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndex, m_uEndIndex-1, m_uEndIndex - m_uBeginIndex, GL_UNSIGNED_INT, 0);
|
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndex, m_uEndIndex-1, m_uEndIndex - m_uBeginIndex, GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
|
//Bind the index buffer
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferLow);
|
||||||
|
|
||||||
|
//Bind the vertex buffer
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferLow);
|
||||||
|
glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal), 0);
|
||||||
|
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12);
|
||||||
|
|
||||||
|
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndexLow, m_uEndIndexLow-1, m_uEndIndexLow - m_uBeginIndexLow, GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
GLenum errCode = glGetError();
|
GLenum errCode = glGetError();
|
||||||
if(errCode != GL_NO_ERROR)
|
if(errCode != GL_NO_ERROR)
|
||||||
|
@ -42,6 +42,7 @@ public:
|
|||||||
|
|
||||||
//Convert a SrfaceMesh to OpenGL index/vertex buffers
|
//Convert a SrfaceMesh to OpenGL index/vertex buffers
|
||||||
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& surfaceMesh);
|
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& surfaceMesh);
|
||||||
|
void setSurfaceMeshToRenderLowLOD(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& surfaceMesh);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//Qt OpenGL functions
|
//Qt OpenGL functions
|
||||||
@ -53,10 +54,16 @@ private:
|
|||||||
//Index/vertex buffer data
|
//Index/vertex buffer data
|
||||||
GLuint m_uBeginIndex;
|
GLuint m_uBeginIndex;
|
||||||
GLuint m_uEndIndex;
|
GLuint m_uEndIndex;
|
||||||
GLuint noOfIndices;
|
//GLuint noOfIndices;
|
||||||
GLuint indexBuffer;
|
GLuint indexBuffer;
|
||||||
GLuint vertexBuffer;
|
GLuint vertexBuffer;
|
||||||
|
|
||||||
|
GLuint m_uBeginIndexLow;
|
||||||
|
GLuint m_uEndIndexLow;
|
||||||
|
//GLuint noOfIndicesLow;
|
||||||
|
GLuint indexBufferLow;
|
||||||
|
GLuint vertexBufferLow;
|
||||||
|
|
||||||
//Mouse data
|
//Mouse data
|
||||||
QPoint m_LastFrameMousePos;
|
QPoint m_LastFrameMousePos;
|
||||||
QPoint m_CurrentMousePos;
|
QPoint m_CurrentMousePos;
|
||||||
|
@ -91,20 +91,26 @@ int main(int argc, char *argv[])
|
|||||||
smoothRegion<SimpleVolume, Density8>(volData, volData.getEnclosingRegion());
|
smoothRegion<SimpleVolume, Density8>(volData, volData.getEnclosingRegion());
|
||||||
smoothRegion<SimpleVolume, Density8>(volData, volData.getEnclosingRegion());
|
smoothRegion<SimpleVolume, Density8>(volData, volData.getEnclosingRegion());
|
||||||
|
|
||||||
RawVolume<Density8> volDataLowLOD(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 31, 31)));
|
RawVolume<Density8> volDataLowLOD(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(15, 31, 31)));
|
||||||
|
|
||||||
VolumeResampler<SimpleVolume, RawVolume, Density8> volumeResampler(&volData, volData.getEnclosingRegion(), &volDataLowLOD, volDataLowLOD.getEnclosingRegion());
|
VolumeResampler<SimpleVolume, RawVolume, Density8> volumeResampler(&volData, PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(31, 63, 63)), &volDataLowLOD, volDataLowLOD.getEnclosingRegion());
|
||||||
volumeResampler.execute();
|
volumeResampler.execute();
|
||||||
|
|
||||||
//Extract the surface
|
//Extract the surface
|
||||||
SurfaceMesh<PositionMaterialNormal> mesh;
|
SurfaceMesh<PositionMaterialNormal> meshLowLOD;
|
||||||
SurfaceExtractor<RawVolume, Density8 > surfaceExtractor(&volDataLowLOD, volDataLowLOD.getEnclosingRegion(), &mesh);
|
SurfaceExtractor<RawVolume, Density8 > surfaceExtractor(&volDataLowLOD, volDataLowLOD.getEnclosingRegion(), &meshLowLOD);
|
||||||
surfaceExtractor.execute();
|
surfaceExtractor.execute();
|
||||||
|
meshLowLOD.scaleVertices(2.0f);
|
||||||
|
|
||||||
mesh.scaleVertices(2.0f);
|
//Extract the surface
|
||||||
|
SurfaceMesh<PositionMaterialNormal> meshHighLOD;
|
||||||
|
SurfaceExtractor<SimpleVolume, Density8 > surfaceExtractorHigh(&volData, PolyVox::Region(Vector3DInt32(32,0,0), Vector3DInt32(63, 63, 63)), &meshHighLOD);
|
||||||
|
surfaceExtractorHigh.execute();
|
||||||
|
meshHighLOD.translateVertices(Vector3DFloat(32, 0, 0));
|
||||||
|
|
||||||
//Pass the surface to the OpenGL window
|
//Pass the surface to the OpenGL window
|
||||||
openGLWidget.setSurfaceMeshToRender(mesh);
|
openGLWidget.setSurfaceMeshToRender(meshHighLOD);
|
||||||
|
openGLWidget.setSurfaceMeshToRenderLowLOD(meshLowLOD);
|
||||||
|
|
||||||
//Run the message pump.
|
//Run the message pump.
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
@ -64,6 +64,7 @@ namespace PolyVox
|
|||||||
bool isEmpty(void) const;
|
bool isEmpty(void) const;
|
||||||
|
|
||||||
void scaleVertices(float amount);
|
void scaleVertices(float amount);
|
||||||
|
void translateVertices(const Vector3DFloat& amount);
|
||||||
|
|
||||||
//THESE FUNCTIONS TO BE REMOVED IN THE FUTURE. OR AT LEAST MOVED OUT OF THIS CLASS INTO FREE FUNCTIONS.
|
//THESE FUNCTIONS TO BE REMOVED IN THE FUTURE. OR AT LEAST MOVED OUT OF THIS CLASS INTO FREE FUNCTIONS.
|
||||||
//THEY ARE CAUSING PROBLEMS WITH THE SWIG BINDINGS. THE FUNCTIONS REGARDING NORMALS MAKE NO SENSE WHEN
|
//THEY ARE CAUSING PROBLEMS WITH THE SWIG BINDINGS. THE FUNCTIONS REGARDING NORMALS MAKE NO SENSE WHEN
|
||||||
|
@ -475,4 +475,16 @@ namespace PolyVox
|
|||||||
m_vecVertices[ct].setPosition(position);
|
m_vecVertices[ct].setPosition(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename VertexType>
|
||||||
|
void SurfaceMesh<VertexType>::translateVertices(const Vector3DFloat& amount)
|
||||||
|
{
|
||||||
|
for(uint32_t ct = 0; ct < m_vecVertices.size(); ct++)
|
||||||
|
{
|
||||||
|
//TODO: Should rethink accessors here to provide faster access
|
||||||
|
Vector3DFloat position = m_vecVertices[ct].getPosition();
|
||||||
|
position += amount;
|
||||||
|
m_vecVertices[ct].setPosition(position);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -39,6 +39,7 @@ namespace PolyVox
|
|||||||
private:
|
private:
|
||||||
void resampleSameSize();
|
void resampleSameSize();
|
||||||
void resampleHalfSize();
|
void resampleHalfSize();
|
||||||
|
void resampleArbitrary();
|
||||||
|
|
||||||
//Source data
|
//Source data
|
||||||
SrcVolumeType<VoxelType>* m_pVolSrc;
|
SrcVolumeType<VoxelType>* m_pVolSrc;
|
||||||
|
@ -35,8 +35,26 @@ namespace PolyVox
|
|||||||
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
||||||
void VolumeResampler<SrcVolumeType, DestVolumeType, VoxelType>::execute()
|
void VolumeResampler<SrcVolumeType, DestVolumeType, VoxelType>::execute()
|
||||||
{
|
{
|
||||||
//resampleSameSize();
|
int32_t uSrcWidth = m_regSrc.getUpperCorner().getX() - m_regSrc.getLowerCorner().getX() + 1;
|
||||||
resampleHalfSize();
|
int32_t uSrcHeight = m_regSrc.getUpperCorner().getY() - m_regSrc.getLowerCorner().getY() + 1;
|
||||||
|
int32_t uSrcDepth = m_regSrc.getUpperCorner().getZ() - m_regSrc.getLowerCorner().getZ() + 1;
|
||||||
|
|
||||||
|
int32_t uDstWidth = m_regDst.getUpperCorner().getX() - m_regDst.getLowerCorner().getX() + 1;
|
||||||
|
int32_t uDstHeight = m_regDst.getUpperCorner().getY() - m_regDst.getLowerCorner().getY() + 1;
|
||||||
|
int32_t uDstDepth = m_regDst.getUpperCorner().getZ() - m_regDst.getLowerCorner().getZ() + 1;
|
||||||
|
|
||||||
|
if((uSrcWidth == uDstWidth) && (uSrcHeight == uDstHeight) && (uSrcDepth == uDstDepth))
|
||||||
|
{
|
||||||
|
resampleSameSize();
|
||||||
|
}
|
||||||
|
else if((uSrcWidth == uDstWidth * 2) && (uSrcHeight == uDstHeight * 2) && (uSrcDepth == uDstDepth * 2))
|
||||||
|
{
|
||||||
|
resampleHalfSize();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
resampleArbitrary();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
||||||
@ -92,4 +110,11 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
||||||
|
void VolumeResampler<SrcVolumeType, DestVolumeType, VoxelType>::resampleArbitrary()
|
||||||
|
{
|
||||||
|
//ARBITRARY RESAMPLING NOT YET IMPLEMENTED.
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user