Initial commit of VolumeResampler and LOD demo.
This commit is contained in:
parent
3ab157dc3b
commit
ccfa7db1fa
@ -31,15 +31,18 @@ IF(ENABLE_EXAMPLES)
|
|||||||
ADD_SUBDIRECTORY(examples/Basic)
|
ADD_SUBDIRECTORY(examples/Basic)
|
||||||
ADD_SUBDIRECTORY(examples/Paging)
|
ADD_SUBDIRECTORY(examples/Paging)
|
||||||
ADD_SUBDIRECTORY(examples/OpenGL)
|
ADD_SUBDIRECTORY(examples/OpenGL)
|
||||||
|
ADD_SUBDIRECTORY(examples/SmoothLOD)
|
||||||
if(BUILD_STATIC_LIBRARIES)
|
if(BUILD_STATIC_LIBRARIES)
|
||||||
ADD_DEPENDENCIES(BasicExample PolyVoxCoreStatic PolyVoxUtilStatic)
|
ADD_DEPENDENCIES(BasicExample PolyVoxCoreStatic PolyVoxUtilStatic)
|
||||||
ADD_DEPENDENCIES(PagingExample PolyVoxCoreStatic PolyVoxUtilStatic)
|
ADD_DEPENDENCIES(PagingExample PolyVoxCoreStatic PolyVoxUtilStatic)
|
||||||
ADD_DEPENDENCIES(OpenGLExample PolyVoxCoreStatic PolyVoxUtilStatic)
|
ADD_DEPENDENCIES(OpenGLExample PolyVoxCoreStatic PolyVoxUtilStatic)
|
||||||
|
ADD_DEPENDENCIES(SmoothLODExample PolyVoxCoreStatic PolyVoxUtilStatic)
|
||||||
endif()
|
endif()
|
||||||
if(BUILD_DYNAMIC_LIBRARIES)
|
if(BUILD_DYNAMIC_LIBRARIES)
|
||||||
ADD_DEPENDENCIES(BasicExample PolyVoxCoreDynamic PolyVoxUtilDynamic)
|
ADD_DEPENDENCIES(BasicExample PolyVoxCoreDynamic PolyVoxUtilDynamic)
|
||||||
ADD_DEPENDENCIES(PagingExample PolyVoxCoreDynamic PolyVoxUtilDynamic)
|
ADD_DEPENDENCIES(PagingExample PolyVoxCoreDynamic PolyVoxUtilDynamic)
|
||||||
ADD_DEPENDENCIES(OpenGLExample PolyVoxCoreDynamic PolyVoxUtilDynamic)
|
ADD_DEPENDENCIES(OpenGLExample PolyVoxCoreDynamic PolyVoxUtilDynamic)
|
||||||
|
ADD_DEPENDENCIES(SmoothLODExample PolyVoxCoreDynamic PolyVoxUtilDynamic)
|
||||||
endif()
|
endif()
|
||||||
ENDIF(ENABLE_EXAMPLES)
|
ENDIF(ENABLE_EXAMPLES)
|
||||||
|
|
||||||
|
54
examples/SmoothLOD/CMakeLists.txt
Normal file
54
examples/SmoothLOD/CMakeLists.txt
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
|
||||||
|
|
||||||
|
PROJECT(SmoothLODExample)
|
||||||
|
|
||||||
|
#Projects source files
|
||||||
|
SET(SRC_FILES
|
||||||
|
glew/glew.cpp
|
||||||
|
|
||||||
|
main.cpp
|
||||||
|
OpenGLWidget.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
#Projects headers files
|
||||||
|
SET(INC_FILES
|
||||||
|
glew/glew.h
|
||||||
|
glew/glxew.h
|
||||||
|
glew/wglew.h
|
||||||
|
|
||||||
|
OpenGLWidget.h
|
||||||
|
)
|
||||||
|
|
||||||
|
ADD_DEFINITIONS(-DGLEW_STATIC)
|
||||||
|
|
||||||
|
#"Sources" and "Headers" are the group names in Visual Studio.
|
||||||
|
#They may have other uses too...
|
||||||
|
SOURCE_GROUP("Sources" FILES ${SRC_FILES})
|
||||||
|
SOURCE_GROUP("Headers" FILES ${INC_FILES})
|
||||||
|
|
||||||
|
FIND_PACKAGE(OpenGL REQUIRED)
|
||||||
|
|
||||||
|
#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
|
||||||
|
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_SOURCE_DIR}/include)
|
||||||
|
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR})
|
||||||
|
|
||||||
|
#Build
|
||||||
|
ADD_EXECUTABLE(SmoothLODExample ${SRC_FILES})
|
||||||
|
TARGET_LINK_LIBRARIES(SmoothLODExample ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore)
|
||||||
|
|
||||||
|
#Install - Only install the example in Windows
|
||||||
|
IF(WIN32)
|
||||||
|
INSTALL(TARGETS SmoothLODExample
|
||||||
|
RUNTIME DESTINATION Examples/OpenGL/bin
|
||||||
|
LIBRARY DESTINATION Examples/OpenGL/lib
|
||||||
|
ARCHIVE DESTINATION Examples/OpenGL/lib
|
||||||
|
COMPONENT example
|
||||||
|
)
|
||||||
|
|
||||||
|
#.dlls should be installed in shared builds.
|
||||||
|
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../release/PolyVoxCore.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Release)
|
||||||
|
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../release/PolyVoxUtil.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Release)
|
||||||
|
|
||||||
|
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../debug/PolyVoxCore.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Debug)
|
||||||
|
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../debug/PolyVoxUtil.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Debug)
|
||||||
|
ENDIF(WIN32)
|
154
examples/SmoothLOD/OpenGLWidget.cpp
Normal file
154
examples/SmoothLOD/OpenGLWidget.cpp
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
#include "OpenGLWidget.h"
|
||||||
|
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
using namespace PolyVox;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
OpenGLWidget::OpenGLWidget(QWidget *parent)
|
||||||
|
:QGLWidget(parent)
|
||||||
|
,m_xRotation(0)
|
||||||
|
,m_yRotation(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenGLWidget::setSurfaceMeshToRender(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, &indexBuffer);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
|
||||||
|
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, &vertexBuffer);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||||
|
const GLvoid* pVertices = static_cast<const GLvoid*>(&(vecVertices[0]));
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal), pVertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
m_uBeginIndex = 0;
|
||||||
|
m_uEndIndex = vecIndices.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenGLWidget::initializeGL()
|
||||||
|
{
|
||||||
|
//We need GLEW to access recent OpenGL functionality
|
||||||
|
std::cout << "Initialising GLEW...";
|
||||||
|
GLenum result = glewInit();
|
||||||
|
if (result == GLEW_OK)
|
||||||
|
{
|
||||||
|
std::cout << "success" << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Problem: glewInit failed, something is seriously wrong. */
|
||||||
|
std::cout << "failed" << std::endl;
|
||||||
|
std::cout << "Initialising GLEW failed with the following error: " << glewGetErrorString(result) << std::endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Print out some information about the OpenGL implementation.
|
||||||
|
std::cout << "OpenGL Implementation Details:" << std::endl;
|
||||||
|
if(glGetString(GL_VENDOR))
|
||||||
|
std::cout << "\tGL_VENDOR: " << glGetString(GL_VENDOR) << std::endl;
|
||||||
|
if(glGetString(GL_RENDERER))
|
||||||
|
std::cout << "\tGL_RENDERER: " << glGetString(GL_RENDERER) << std::endl;
|
||||||
|
if(glGetString(GL_VERSION))
|
||||||
|
std::cout << "\tGL_VERSION: " << glGetString(GL_VERSION) << std::endl;
|
||||||
|
if(glGetString(GL_SHADING_LANGUAGE_VERSION))
|
||||||
|
std::cout << "\tGL_SHADING_LANGUAGE_VERSION: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
|
||||||
|
|
||||||
|
//Check our version of OpenGL is recent enough.
|
||||||
|
//We need at least 1.5 for vertex buffer objects,
|
||||||
|
if (!GLEW_VERSION_1_5)
|
||||||
|
{
|
||||||
|
std::cout << "Error: You need OpenGL version 1.5 to run this example." << std::endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set up the clear colour
|
||||||
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
glClearDepth(1.0f);
|
||||||
|
|
||||||
|
//Enable the depth buffer
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
|
||||||
|
//Anable smooth lighting
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
glEnable(GL_LIGHT0);
|
||||||
|
glShadeModel(GL_SMOOTH);
|
||||||
|
|
||||||
|
//We'll be rendering with index/vertex arrays
|
||||||
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
|
glEnableClientState(GL_NORMAL_ARRAY);
|
||||||
|
|
||||||
|
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenGLWidget::resizeGL(int w, int h)
|
||||||
|
{
|
||||||
|
//Setup the viewport
|
||||||
|
glViewport(0, 0, w, h);
|
||||||
|
|
||||||
|
//Set up the projection matrix
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
float frustumSize = 32.0f; //Half the volume size
|
||||||
|
float aspect = static_cast<float>(width()) / static_cast<float>(height());
|
||||||
|
glOrtho(frustumSize*aspect, -frustumSize*aspect, frustumSize, -frustumSize, 1.0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenGLWidget::paintGL()
|
||||||
|
{
|
||||||
|
//Clear the screen
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
//Set up the viewing transformation
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glLoadIdentity();
|
||||||
|
glTranslatef(0.0f,0.0f,-100.0f); //Centre volume and move back
|
||||||
|
glRotatef(-m_xRotation, 0.0f, 1.0f, 0.0f);
|
||||||
|
glRotatef(-m_yRotation, 1.0f, 0.0f, 0.0f);
|
||||||
|
glTranslatef(-32.0f,-32.0f,-32.0f); //Centre volume and move back
|
||||||
|
|
||||||
|
//Bind the index buffer
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
|
||||||
|
|
||||||
|
//Bind the vertex buffer
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||||
|
glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal), 0);
|
||||||
|
glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12);
|
||||||
|
|
||||||
|
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndex, m_uEndIndex-1, m_uEndIndex - m_uBeginIndex, GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
|
GLenum errCode = glGetError();
|
||||||
|
if(errCode != GL_NO_ERROR)
|
||||||
|
{
|
||||||
|
//What has replaced getErrorString() in the latest OpenGL?
|
||||||
|
std::cout << "OpenGL Error: " << errCode << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenGLWidget::mousePressEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
m_CurrentMousePos = event->pos();
|
||||||
|
m_LastFrameMousePos = m_CurrentMousePos;
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenGLWidget::mouseMoveEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
m_CurrentMousePos = event->pos();
|
||||||
|
QPoint diff = m_CurrentMousePos - m_LastFrameMousePos;
|
||||||
|
m_xRotation += diff.x();
|
||||||
|
m_yRotation += diff.y();
|
||||||
|
m_LastFrameMousePos = m_CurrentMousePos;
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
67
examples/SmoothLOD/OpenGLWidget.h
Normal file
67
examples/SmoothLOD/OpenGLWidget.h
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
Copyright (c) 2005-2009 David Williams
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __BasicExample_OpenGLWidget_H__
|
||||||
|
#define __BasicExample_OpenGLWidget_H__
|
||||||
|
|
||||||
|
#include "PolyVoxCore/SurfaceMesh.h"
|
||||||
|
|
||||||
|
#include "glew/glew.h"
|
||||||
|
|
||||||
|
#include <QGLWidget>
|
||||||
|
|
||||||
|
class OpenGLWidget : public QGLWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//Constructor
|
||||||
|
OpenGLWidget(QWidget *parent);
|
||||||
|
|
||||||
|
//Mouse handling
|
||||||
|
void mouseMoveEvent(QMouseEvent* event);
|
||||||
|
void mousePressEvent(QMouseEvent* event);
|
||||||
|
|
||||||
|
//Convert a SrfaceMesh to OpenGL index/vertex buffers
|
||||||
|
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal>& surfaceMesh);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//Qt OpenGL functions
|
||||||
|
void initializeGL();
|
||||||
|
void resizeGL(int w, int h);
|
||||||
|
void paintGL();
|
||||||
|
|
||||||
|
private:
|
||||||
|
//Index/vertex buffer data
|
||||||
|
GLuint m_uBeginIndex;
|
||||||
|
GLuint m_uEndIndex;
|
||||||
|
GLuint noOfIndices;
|
||||||
|
GLuint indexBuffer;
|
||||||
|
GLuint vertexBuffer;
|
||||||
|
|
||||||
|
//Mouse data
|
||||||
|
QPoint m_LastFrameMousePos;
|
||||||
|
QPoint m_CurrentMousePos;
|
||||||
|
int m_xRotation;
|
||||||
|
int m_yRotation;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //__BasicExample_OpenGLWidget_H__
|
73
examples/SmoothLOD/glew/LICENSE.txt
Normal file
73
examples/SmoothLOD/glew/LICENSE.txt
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
The OpenGL Extension Wrangler Library
|
||||||
|
Copyright (C) 2002-2007, Milan Ikits <milan ikits[]ieee org>
|
||||||
|
Copyright (C) 2002-2007, Marcelo E. Magallon <mmagallo[]debian org>
|
||||||
|
Copyright (C) 2002, Lev Povalahev
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
* The name of the author may be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||||
|
THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
Mesa 3-D graphics library
|
||||||
|
Version: 7.0
|
||||||
|
|
||||||
|
Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of this software and associated documentation files (the "Software"),
|
||||||
|
to deal in the Software without restriction, including without limitation
|
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
Copyright (c) 2007 The Khronos Group Inc.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of this software and/or associated documentation files (the
|
||||||
|
"Materials"), to deal in the Materials without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Materials, and to
|
||||||
|
permit persons to whom the Materials are furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Materials.
|
||||||
|
|
||||||
|
THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
12180
examples/SmoothLOD/glew/glew.cpp
Normal file
12180
examples/SmoothLOD/glew/glew.cpp
Normal file
File diff suppressed because it is too large
Load Diff
12262
examples/SmoothLOD/glew/glew.h
Normal file
12262
examples/SmoothLOD/glew/glew.h
Normal file
File diff suppressed because it is too large
Load Diff
1397
examples/SmoothLOD/glew/glxew.h
Normal file
1397
examples/SmoothLOD/glew/glxew.h
Normal file
File diff suppressed because it is too large
Load Diff
1165
examples/SmoothLOD/glew/wglew.h
Normal file
1165
examples/SmoothLOD/glew/wglew.h
Normal file
File diff suppressed because it is too large
Load Diff
111
examples/SmoothLOD/main.cpp
Normal file
111
examples/SmoothLOD/main.cpp
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
Copyright (c) 2005-2009 David Williams
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "OpenGLWidget.h"
|
||||||
|
|
||||||
|
#include "PolyVoxCore/Density.h"
|
||||||
|
#include "PolyVoxCore/Filters.h"
|
||||||
|
#include "PolyVoxCore/SurfaceExtractor.h"
|
||||||
|
#include "PolyVoxCore/SurfaceMesh.h"
|
||||||
|
#include "PolyVoxCore/RawVolume.h"
|
||||||
|
#include "PolyVoxCore/SimpleVolume.h"
|
||||||
|
#include "PolyVoxCore/VolumeResampler.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
//Use the PolyVox namespace
|
||||||
|
using namespace PolyVox;
|
||||||
|
|
||||||
|
void createSphereInVolume(SimpleVolume<Density8>& volData, float fRadius)
|
||||||
|
{
|
||||||
|
//This vector hold the position of the center of the volume
|
||||||
|
Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2);
|
||||||
|
|
||||||
|
//This three-level for loop iterates over every voxel in the volume
|
||||||
|
for (int z = 0; z < volData.getWidth(); z++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < volData.getHeight(); y++)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < volData.getDepth(); x++)
|
||||||
|
{
|
||||||
|
//Store our current position as a vector...
|
||||||
|
Vector3DFloat v3dCurrentPos(x,y,z);
|
||||||
|
//And compute how far the current position is from the center of the volume
|
||||||
|
float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();
|
||||||
|
|
||||||
|
if(fDistToCenter <= fRadius)
|
||||||
|
{
|
||||||
|
//Our new density value
|
||||||
|
uint8_t uDensity = Density8::getMaxDensity();
|
||||||
|
|
||||||
|
//Get the old voxel
|
||||||
|
Density8 voxel = volData.getVoxelAt(x,y,z);
|
||||||
|
|
||||||
|
//Modify the density
|
||||||
|
voxel.setDensity(uDensity);
|
||||||
|
|
||||||
|
//Wrte the voxel value into the volume
|
||||||
|
volData.setVoxelAt(x, y, z, voxel);
|
||||||
|
}
|
||||||
|
|
||||||
|
//144 in the middle, (144 - 32) at the edges. Threshold of 128 is between these
|
||||||
|
//volData.setVoxelAt(x, y, z, 144 - fDistToCenter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
//Create and show the Qt OpenGL window
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
OpenGLWidget openGLWidget(0);
|
||||||
|
openGLWidget.show();
|
||||||
|
|
||||||
|
//Create an empty volume and then place a sphere in it
|
||||||
|
SimpleVolume<Density8> volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(63, 63, 63)));
|
||||||
|
createSphereInVolume(volData, 28);
|
||||||
|
|
||||||
|
//Smooth the data
|
||||||
|
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)));
|
||||||
|
|
||||||
|
VolumeResampler<SimpleVolume, RawVolume, Density8> volumeResampler(&volData, volData.getEnclosingRegion(), &volDataLowLOD, volDataLowLOD.getEnclosingRegion());
|
||||||
|
volumeResampler.execute();
|
||||||
|
|
||||||
|
//Extract the surface
|
||||||
|
SurfaceMesh<PositionMaterialNormal> mesh;
|
||||||
|
SurfaceExtractor<RawVolume, Density8 > surfaceExtractor(&volDataLowLOD, volDataLowLOD.getEnclosingRegion(), &mesh);
|
||||||
|
surfaceExtractor.execute();
|
||||||
|
|
||||||
|
mesh.scaleVertices(2.0f);
|
||||||
|
|
||||||
|
//Pass the surface to the OpenGL window
|
||||||
|
openGLWidget.setSurfaceMeshToRender(mesh);
|
||||||
|
|
||||||
|
//Run the message pump.
|
||||||
|
return app.exec();
|
||||||
|
}
|
@ -61,6 +61,8 @@ SET(CORE_INC_FILES
|
|||||||
include/PolyVoxCore/Vector.h
|
include/PolyVoxCore/Vector.h
|
||||||
include/PolyVoxCore/Vector.inl
|
include/PolyVoxCore/Vector.inl
|
||||||
include/PolyVoxCore/VertexTypes.h
|
include/PolyVoxCore/VertexTypes.h
|
||||||
|
include/PolyVoxCore/VolumeResampler.h
|
||||||
|
include/PolyVoxCore/VolumeResampler.inl
|
||||||
include/PolyVoxCore/VoxelFilters.h
|
include/PolyVoxCore/VoxelFilters.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
uint16_t& uDensity = temp[x-croppedRegion.getLowerCorner().getX()][y-croppedRegion.getLowerCorner().getY()][z-croppedRegion.getLowerCorner().getZ()];
|
uint16_t& uDensity = temp[x-croppedRegion.getLowerCorner().getX()][y-croppedRegion.getLowerCorner().getY()][z-croppedRegion.getLowerCorner().getZ()];
|
||||||
|
|
||||||
MaterialDensityPair44 val = volData.getVoxelAt(x,y,z);
|
VoxelType val = volData.getVoxelAt(x,y,z);
|
||||||
val.setDensity(uDensity);
|
val.setDensity(uDensity);
|
||||||
volData.setVoxelAt(x,y,z,val);
|
volData.setVoxelAt(x,y,z,val);
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,8 @@ namespace PolyVox
|
|||||||
void clear(void);
|
void clear(void);
|
||||||
bool isEmpty(void) const;
|
bool isEmpty(void) const;
|
||||||
|
|
||||||
|
void scaleVertices(float 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
|
||||||
//A VERTEX MIGHT NOT HAVE NORMALS. THE EXTRACT SUBSET FUNCTION SHOULD MAYBE BE APPLICATION CODE, AT ANY
|
//A VERTEX MIGHT NOT HAVE NORMALS. THE EXTRACT SUBSET FUNCTION SHOULD MAYBE BE APPLICATION CODE, AT ANY
|
||||||
|
@ -463,4 +463,16 @@ namespace PolyVox
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
template <typename VertexType>
|
||||||
|
void SurfaceMesh<VertexType>::scaleVertices(float 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
57
library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.h
Normal file
57
library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
Copyright (c) 2005-2009 David Williams
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __PolyVox_VolumeResampler_H__
|
||||||
|
#define __PolyVox_VolumeResampler_H__
|
||||||
|
|
||||||
|
#include "PolyVoxCore/PolyVoxForwardDeclarations.h"
|
||||||
|
|
||||||
|
namespace PolyVox
|
||||||
|
{
|
||||||
|
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
||||||
|
class VolumeResampler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VolumeResampler(SrcVolumeType<VoxelType>* pVolSrc, Region regSrc, DestVolumeType<VoxelType>* pVolDst, Region regDst);
|
||||||
|
|
||||||
|
void execute();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void resampleSameSize();
|
||||||
|
void resampleHalfSize();
|
||||||
|
|
||||||
|
//Source data
|
||||||
|
SrcVolumeType<VoxelType>* m_pVolSrc;
|
||||||
|
Region m_regSrc;
|
||||||
|
|
||||||
|
//Destination data
|
||||||
|
DestVolumeType<VoxelType>* m_pVolDst;
|
||||||
|
Region m_regDst;
|
||||||
|
};
|
||||||
|
|
||||||
|
}//namespace PolyVox
|
||||||
|
|
||||||
|
#include "PolyVoxCore/VolumeResampler.inl"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
95
library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl
Normal file
95
library/PolyVoxCore/include/PolyVoxCore/VolumeResampler.inl
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
Copyright (c) 2005-2009 David Williams
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
namespace PolyVox
|
||||||
|
{
|
||||||
|
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
||||||
|
VolumeResampler<SrcVolumeType, DestVolumeType, VoxelType>::VolumeResampler(SrcVolumeType<VoxelType>* pVolSrc, Region regSrc, DestVolumeType<VoxelType>* pVolDst, Region regDst)
|
||||||
|
:m_pVolSrc(pVolSrc)
|
||||||
|
,m_regSrc(regSrc)
|
||||||
|
,m_pVolDst(pVolDst)
|
||||||
|
,m_regDst(regDst)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
||||||
|
void VolumeResampler<SrcVolumeType, DestVolumeType, VoxelType>::execute()
|
||||||
|
{
|
||||||
|
//resampleSameSize();
|
||||||
|
resampleHalfSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
||||||
|
void VolumeResampler<SrcVolumeType, DestVolumeType, VoxelType>::resampleSameSize()
|
||||||
|
{
|
||||||
|
for(int32_t sz = m_regSrc.getLowerCorner().getZ(), dz = m_regDst.getLowerCorner().getZ(); dz <= m_regDst.getUpperCorner().getZ(); sz++, dz++)
|
||||||
|
{
|
||||||
|
for(int32_t sy = m_regSrc.getLowerCorner().getY(), dy = m_regDst.getLowerCorner().getY(); dy <= m_regDst.getUpperCorner().getY(); sy++, dy++)
|
||||||
|
{
|
||||||
|
for(int32_t sx = m_regSrc.getLowerCorner().getX(), dx = m_regDst.getLowerCorner().getX(); dx <= m_regDst.getUpperCorner().getX(); sx++,dx++)
|
||||||
|
{
|
||||||
|
VoxelType voxel = m_pVolSrc->getVoxelAt(sx,sy,sz);
|
||||||
|
m_pVolDst->setVoxelAt(dx,dy,dz,voxel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template< template<typename> class SrcVolumeType, template<typename> class DestVolumeType, typename VoxelType>
|
||||||
|
void VolumeResampler<SrcVolumeType, DestVolumeType, VoxelType>::resampleHalfSize()
|
||||||
|
{
|
||||||
|
for(int32_t sz = m_regSrc.getLowerCorner().getZ(), dz = m_regDst.getLowerCorner().getZ(); dz <= m_regDst.getUpperCorner().getZ(); sz+=2, dz++)
|
||||||
|
{
|
||||||
|
for(int32_t sy = m_regSrc.getLowerCorner().getY(), dy = m_regDst.getLowerCorner().getY(); dy <= m_regDst.getUpperCorner().getY(); sy+=2, dy++)
|
||||||
|
{
|
||||||
|
for(int32_t sx = m_regSrc.getLowerCorner().getX(), dx = m_regDst.getLowerCorner().getX(); dx <= m_regDst.getUpperCorner().getX(); sx+=2,dx++)
|
||||||
|
{
|
||||||
|
VoxelType voxel000 = m_pVolSrc->getVoxelAt(sx+0,sy+0,sz+0);
|
||||||
|
VoxelType voxel001 = m_pVolSrc->getVoxelAt(sx+0,sy+0,sz+1);
|
||||||
|
VoxelType voxel010 = m_pVolSrc->getVoxelAt(sx+0,sy+1,sz+0);
|
||||||
|
VoxelType voxel011 = m_pVolSrc->getVoxelAt(sx+0,sy+1,sz+1);
|
||||||
|
VoxelType voxel100 = m_pVolSrc->getVoxelAt(sx+1,sy+0,sz+0);
|
||||||
|
VoxelType voxel101 = m_pVolSrc->getVoxelAt(sx+1,sy+0,sz+1);
|
||||||
|
VoxelType voxel110 = m_pVolSrc->getVoxelAt(sx+1,sy+1,sz+0);
|
||||||
|
VoxelType voxel111 = m_pVolSrc->getVoxelAt(sx+1,sy+1,sz+1);
|
||||||
|
|
||||||
|
uint32_t averageDensity = 0;
|
||||||
|
averageDensity += voxel000.getDensity();
|
||||||
|
averageDensity += voxel001.getDensity();
|
||||||
|
averageDensity += voxel010.getDensity();
|
||||||
|
averageDensity += voxel011.getDensity();
|
||||||
|
averageDensity += voxel100.getDensity();
|
||||||
|
averageDensity += voxel101.getDensity();
|
||||||
|
averageDensity += voxel110.getDensity();
|
||||||
|
averageDensity += voxel111.getDensity();
|
||||||
|
averageDensity /= 8;
|
||||||
|
|
||||||
|
VoxelType result;
|
||||||
|
result.setDensity(averageDensity);
|
||||||
|
|
||||||
|
m_pVolDst->setVoxelAt(dx,dy,dz,result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user