mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-23 20:50:59 -05:00
Cleanup in openspaceengine, added comments to volumeraycaster
This commit is contained in:
@@ -45,7 +45,7 @@ raycaster_stepsize 0.005
|
||||
raycaster_intensity 1.0
|
||||
|
||||
# Animation speed
|
||||
animator_refresh_interval 0.50
|
||||
animator_refresh_interval 0.05
|
||||
|
||||
# Various paths
|
||||
raycaster_kernel_filename ../kernels/RaycasterTSP.cl
|
||||
|
||||
+33
-15
@@ -1,3 +1,27 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 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 SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <flare/flare.h>
|
||||
|
||||
#include <flare/Renderer.h>
|
||||
@@ -29,7 +53,7 @@ Flare::Flare() {
|
||||
_oldTime = 0.f;
|
||||
_currentTime = 0.f;
|
||||
|
||||
init();
|
||||
initialize();
|
||||
}
|
||||
|
||||
Flare::~Flare() {
|
||||
@@ -40,11 +64,8 @@ Flare::~Flare() {
|
||||
}
|
||||
|
||||
void Flare::render() {
|
||||
// Go!
|
||||
// Reload config if flag is set
|
||||
if (_reloadFlag.getVal()) {
|
||||
_raycaster->Reload();
|
||||
}
|
||||
if (_reloadFlag.getVal()) _raycaster->Reload();
|
||||
|
||||
// Set model and view params
|
||||
_raycaster->SetModelParams(_pitch.getVal(),
|
||||
@@ -53,15 +74,12 @@ void Flare::render() {
|
||||
_raycaster->SetViewParams(_translateX.getVal(),
|
||||
_translateY.getVal(),
|
||||
_translateZ.getVal());
|
||||
|
||||
// Render
|
||||
if (!_raycaster->Render(_elapsedTime.getVal())) {
|
||||
exit(1);
|
||||
}
|
||||
if (!_raycaster->Render(_elapsedTime.getVal())) exit(1);
|
||||
|
||||
// Save screenshot
|
||||
if (_config->TakeScreenshot()) {
|
||||
sgct::Engine::instance()->takeScreenshot();
|
||||
}
|
||||
if (_config->TakeScreenshot()) sgct::Engine::instance()->takeScreenshot();
|
||||
|
||||
// Update animator with synchronized time
|
||||
_animator->SetPaused(_animationPaused.getVal());
|
||||
@@ -70,8 +88,9 @@ void Flare::render() {
|
||||
_animator->ManualTimestep(_manualTimestep.getVal());
|
||||
}
|
||||
|
||||
void Flare::initNavigation() {
|
||||
void Flare::setupNavigationParameters() {
|
||||
_animationPaused.setVal(false);
|
||||
_reloadFlag.setVal(false);
|
||||
|
||||
// FPS mode should be OFF for cluster syncing
|
||||
_fpsMode.setVal(true);
|
||||
@@ -87,13 +106,12 @@ void Flare::initNavigation() {
|
||||
_translateZ.setVal(_config->TranslateZ());
|
||||
}
|
||||
|
||||
void Flare::init() {
|
||||
void Flare::initialize() {
|
||||
// Start with reading a config file
|
||||
_config = Config::New(absPath("${BASE_PATH}/config/flareConfig.txt"));
|
||||
if (!_config) exit(1);
|
||||
|
||||
initNavigation();
|
||||
_reloadFlag.setVal(false);
|
||||
setupNavigationParameters();
|
||||
|
||||
// Get the viewport coordinates from OpenGL
|
||||
GLint currentViewPort[4];
|
||||
|
||||
+5
-2
@@ -38,9 +38,11 @@ public:
|
||||
Flare();
|
||||
~Flare();
|
||||
|
||||
// This is where the magic happens
|
||||
void render();
|
||||
void initNavigation();
|
||||
|
||||
// SGCT functions for cluster rendering and interaction.
|
||||
// Called from OpenspaceEngine.
|
||||
void keyboard(int key, int action);
|
||||
void mouse(int button, int action);
|
||||
void preSync();
|
||||
@@ -49,7 +51,8 @@ public:
|
||||
void decode();
|
||||
|
||||
private:
|
||||
void init();
|
||||
void initialize();
|
||||
void setupNavigationParameters();
|
||||
|
||||
osp::Config* _config;
|
||||
osp::Raycaster* _raycaster;
|
||||
|
||||
+14
-9
@@ -56,6 +56,8 @@ OpenSpaceEngine::OpenSpaceEngine()
|
||||
, _interactionHandler(nullptr)
|
||||
, _renderEngine(nullptr)
|
||||
, _scriptEngine(nullptr)
|
||||
, _flare(nullptr)
|
||||
, _volumeRaycaster(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -158,8 +160,10 @@ bool OpenSpaceEngine::initialize() {
|
||||
|
||||
_engine->_interactionHandler->connectDevices();
|
||||
|
||||
// Choose rendering
|
||||
// _volumeRaycaster = new VolumeRaycaster();
|
||||
_flare = new Flare();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -189,10 +193,10 @@ void OpenSpaceEngine::preSynchronization() {
|
||||
if (sgct::Engine::instance()->isMaster()) {
|
||||
const double dt = sgct::Engine::instance()->getDt();
|
||||
|
||||
if (_flare) _flare->preSync();
|
||||
|
||||
_interactionHandler->update(dt);
|
||||
_interactionHandler->lockControls();
|
||||
|
||||
_flare->preSync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,29 +205,30 @@ void OpenSpaceEngine::postSynchronizationPreDraw() {
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::render() {
|
||||
// _volumeRaycaster->render();
|
||||
_flare->render();
|
||||
if (_volumeRaycaster) _volumeRaycaster->render();
|
||||
if (_flare) _flare->render();
|
||||
|
||||
_renderEngine->render();
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::postDraw() {
|
||||
if (sgct::Engine::instance()->isMaster()) {
|
||||
_interactionHandler->unlockControls();
|
||||
_flare->postDraw();
|
||||
if (_flare) _flare->postDraw();
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::keyboardCallback(int key, int action) {
|
||||
if (sgct::Engine::instance()->isMaster()) {
|
||||
_interactionHandler->keyboardCallback(key, action);
|
||||
_flare->keyboard(key, action);
|
||||
if (_flare) _flare->keyboard(key, action);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::mouseButtonCallback(int key, int action) {
|
||||
if (sgct::Engine::instance()->isMaster()) {
|
||||
_interactionHandler->mouseButtonCallback(key, action);
|
||||
_flare->mouse(key, action);
|
||||
if (_flare) _flare->mouse(key, action);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,11 +241,11 @@ void OpenSpaceEngine::mouseScrollWheelCallback(int pos) {
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::encode() {
|
||||
_flare->encode();
|
||||
if (_flare) _flare->encode();
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::decode() {
|
||||
_flare->decode();
|
||||
if (_flare) _flare->decode();
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -34,15 +34,13 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
float _stepSize = 0.01f;
|
||||
float time = 0.0f;
|
||||
|
||||
VolumeRaycaster::VolumeRaycaster() {
|
||||
VolumeRaycaster::VolumeRaycaster() : _stepSize(0.01f) , _type(TWOPASS) {
|
||||
initialize();
|
||||
}
|
||||
|
||||
VolumeRaycaster::~VolumeRaycaster() {}
|
||||
|
||||
// Initializes the data and setups the correct type of ray caster
|
||||
void VolumeRaycaster::initialize() {
|
||||
// ------ VOLUME READING ----------------
|
||||
std::string filename = absPath("${BASE_PATH}/openspace-data/skull.raw");
|
||||
@@ -55,20 +53,23 @@ void VolumeRaycaster::initialize() {
|
||||
_volume = rawReader.read(filename);
|
||||
|
||||
// ------ SETUP RAYCASTER ---------------
|
||||
setupTwopassRaycaster();
|
||||
// setupSinglepassRaycaster();
|
||||
if (_type == SINGLEPASS) setupSinglepassRaycaster();
|
||||
if (_type == TWOPASS) setupTwopassRaycaster();
|
||||
}
|
||||
|
||||
// Calculate MVP and use it to render with the chosen raycaster
|
||||
void VolumeRaycaster::render() {
|
||||
float speed = 50.0f;
|
||||
time = sgct::Engine::getTime();
|
||||
float time = sgct::Engine::getTime();
|
||||
glm::mat4 yRotation = glm::rotate(glm::mat4(1.0f), time*speed, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
glm::mat4 MVP = sgct::Engine::instance()->getActiveModelViewProjectionMatrix()*yRotation;
|
||||
|
||||
renderWithTwopassRaycaster(MVP);
|
||||
// renderWithSinglepassRaycaster(MVP);
|
||||
if (_type == SINGLEPASS) renderWithSinglepassRaycaster(MVP);
|
||||
if (_type == TWOPASS) renderWithTwopassRaycaster(MVP);
|
||||
}
|
||||
|
||||
// Initialize the two pass raycaster by specifying the bounding box,
|
||||
// full screen quad, FBO and the constant uniforms needed.
|
||||
void VolumeRaycaster::setupTwopassRaycaster() {
|
||||
// ------ SETUP GEOMETRY ----------------
|
||||
const GLfloat size = 1.0f;
|
||||
@@ -145,6 +146,9 @@ void VolumeRaycaster::setupTwopassRaycaster() {
|
||||
_fbo->deactivate();
|
||||
}
|
||||
|
||||
|
||||
// Initialize the single pass raycaster by specifying the VBO for the
|
||||
// bounding box center, calculating the focallength and setting it as a uniform
|
||||
void VolumeRaycaster::setupSinglepassRaycaster() {
|
||||
float p[] = {0, 0, 0};
|
||||
glGenBuffers(1, &_cubeCenterVBO);
|
||||
@@ -181,9 +185,10 @@ void VolumeRaycaster::setupSinglepassRaycaster() {
|
||||
_singlepassProgram->setUniform("Density", 2);
|
||||
}
|
||||
|
||||
// First renders a SGCT box to a FBO and then uses it as entry and exit points
|
||||
// for the second pass which does the actual ray casting.
|
||||
void VolumeRaycaster::renderWithTwopassRaycaster(glm::mat4 modelViewProjectionMatrix) {
|
||||
// ------ DRAW TO FBO -------------------
|
||||
GLuint _sgctFBO = FramebufferObject::getActiveObject(); // Save SGCTs main FBO
|
||||
_fbo->activate();
|
||||
_fboProgram->activate();
|
||||
_fboProgram->setUniform("modelViewProjection", modelViewProjectionMatrix);
|
||||
@@ -210,7 +215,8 @@ void VolumeRaycaster::renderWithTwopassRaycaster(glm::mat4 modelViewProjectionMa
|
||||
_fbo->deactivate();
|
||||
|
||||
// ------ DRAW TO SCREEN ----------------
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _sgctFBO); // Re-bind SGCTs main FBO
|
||||
glBindFramebuffer(GL_FRAMEBUFFER,
|
||||
sgct::Engine::instance()->getActiveWindowPtr()->getFBOPtr()->getBufferID());
|
||||
_twopassProgram->activate();
|
||||
_twopassProgram->setUniform("stepSize", _stepSize);
|
||||
|
||||
@@ -232,6 +238,9 @@ void VolumeRaycaster::renderWithTwopassRaycaster(glm::mat4 modelViewProjectionMa
|
||||
_twopassProgram->deactivate();
|
||||
}
|
||||
|
||||
// FIXME Get it working
|
||||
// Uses the cube center VBO with a geometry shader to create a bounding box
|
||||
// and then does the ray casting in the same pass in the fragment shader.
|
||||
void VolumeRaycaster::renderWithSinglepassRaycaster(glm::mat4 modelViewProjectionMatrix) {
|
||||
glm::mat4 modelViewMatrix = sgct::Engine::instance()->getActiveModelViewMatrix();
|
||||
glm::vec3 eyePos = *sgct::Engine::instance()->getUserPtr()->getPosPtr();
|
||||
|
||||
@@ -36,6 +36,11 @@ using namespace ghoul::opengl;
|
||||
|
||||
class VolumeRaycaster {
|
||||
public:
|
||||
enum RaycasterType {
|
||||
SINGLEPASS,
|
||||
TWOPASS
|
||||
};
|
||||
|
||||
VolumeRaycaster();
|
||||
~VolumeRaycaster();
|
||||
void initialize();
|
||||
@@ -55,6 +60,9 @@ private:
|
||||
ProgramObject *_fboProgram, *_twopassProgram, *_singlepassProgram;
|
||||
sgct_utils::SGCTBox* _boundingBox;
|
||||
GLuint _screenQuad, _cubeCenterVBO;
|
||||
|
||||
float _stepSize;
|
||||
RaycasterType _type;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user