Commit c8eb1d0e authored by mostajab's avatar mostajab
Browse files

+ Clearing the code

Bugs:
- Invalid Enumerator during the rendering mesh
- Problems in deleting the generated color and depth textures.
- Depth darkening still has problem :(
parent 4ca44049
......@@ -95,7 +95,7 @@ namespace campvis {
GLJobProc.registerContext(this);
_paintShader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "application/glsl/datacontainerinspector.frag", "", false);
_geomteryRenderingShader = ShdrMgr.loadSeparate("core/glsl/meshgeomteryrenderer.vert", "modules/vis/glsl/meshgeometryrenderer.frag", "", false);
_geometryRenderingShader = ShdrMgr.loadSeparate("core/glsl/meshgeometryrenderer.vert", "modules/vis/glsl/meshgeometryrenderer.frag", "", false);
_paintShader->setAttributeLocation(0, "in_Position");
_paintShader->setAttributeLocation(1, "in_TexCoords");
......@@ -118,6 +118,51 @@ namespace campvis {
GLJobProc.deregisterContext(this);
ShdrMgr.dispose(_paintShader);
delete _quad;
resetContent();
}
void DataContainerInspectorCanvas::resetContent()
{
/// Clear the textures Array and geometry textures indicies array
_textures.clear();
_geomTextureIndices.clear();
/// Clear the trackball navigation event listener array
/// - First delete the data that it contains
std::vector<TrackballNavigationEventListener*>::iterator trackballNavEHIterator = _trackballEHs.begin();
for(; trackballNavEHIterator != _trackballEHs.end(); trackballNavEHIterator++)
{
delete (*trackballNavEHIterator);
}
_trackballEHs.clear();
/// Clear the Camera properties related to the trackballs array
/// - First delete the data that it contains
std::vector<campvis::CameraProperty*>::iterator camPropertyIterator = _trackballCameraProperties.begin();
for(; camPropertyIterator != _trackballCameraProperties.end(); camPropertyIterator++)
{
delete (*camPropertyIterator);
}
_trackballCameraProperties.clear();
/// Clear the Color Buffers that the geometry has been rendered to.
/// - First delete the data that it contains
std::vector<tgt::Texture*>::iterator colorBufferIterator = _geometryRendering_ColorBuffers.begin();
for(; colorBufferIterator != _geometryRendering_ColorBuffers.end(); colorBufferIterator++)
{
//delete (*colorBufferIterator);
}
_geometryRendering_ColorBuffers.clear();
/// Clear the Depth Buffers that the geometry has been rendered to.
/// - First delete the data that it contains
std::vector<tgt::Texture*>::iterator depthBufferIterator = _geometryRendering_DepthBuffers.begin();
for(; depthBufferIterator != _geometryRendering_DepthBuffers.end(); depthBufferIterator++)
{
//delete (*depthBufferIterator);
}
_geometryRendering_DepthBuffers.clear();
}
QSize DataContainerInspectorCanvas::sizeHint() const {
......@@ -251,40 +296,39 @@ namespace campvis {
LGL_ERROR;
}
void DataContainerInspectorCanvas::drawMeshGeomtery(const campvis::MeshGeometry* mg, tgt::Texture* colorBuffer, tgt::Texture* depthBuffer, const unsigned int& meshIndex)
void DataContainerInspectorCanvas::drawMeshgeometry(const campvis::MeshGeometry* mg, tgt::Texture* colorBuffer, tgt::Texture* depthBuffer, const unsigned int& meshIndex)
{
LGL_ERROR;
// Here the object will be rendered into a texture and the texture will be shown on the output buffer
glPushAttrib(GL_ALL_ATTRIB_BITS);
_geomteryRenderingShader->activate();
/// Activate the shader for geometry Rendering.
_geometryRenderingShader->activate();
LGL_ERROR;
_geomteryRenderingShader->setIgnoreUniformLocationError(true);
_geometryRenderingShader->setIgnoreUniformLocationError(true);
LGL_ERROR;
//decorateRenderProlog(data, _shader);
//_trackballCamera->setPosition(tgt::vec3(0.0f, 0.0f, dist));
//_trackballCamera->setFocus(tgt::vec3(0, 0, -1));
//_trackballCamera->setFarDist(1000.0f);
_trackballEHs[meshIndex]->setSceneBounds(mg->getWorldBounds());
campvis::IVec4Property* p_color = new campvis::IVec4Property("myColor", "MyRenderingColor", tgt::vec4(1.f), tgt::vec4(0.f), tgt::vec4(1.f));
// setting the uniform data for rendering the geometry
campvis::IVec4Property* p_color = new campvis::IVec4Property("myColor", "MyRenderingColor", tgt::vec4(1.f), tgt::vec4(0.f), tgt::vec4(1.f));
_geomteryRenderingShader->setUniform("_projectionMatrix", _trackballEHs[meshIndex]->_trackball->getCamera()->getProjectionMatrix()/*_trackballCameraProperty->getValue().getProjectionMatrix()*/);
_geometryRenderingShader->setUniform("_projectionMatrix", _trackballEHs[meshIndex]->_trackball->getCamera()->getProjectionMatrix()/*_trackballCameraProperty->getValue().getProjectionMatrix()*/);
LGL_ERROR;
_geomteryRenderingShader->setUniform("_viewMatrix", _trackballEHs[meshIndex]->_trackball->getCamera()->getViewMatrix());
_geometryRenderingShader->setUniform("_viewMatrix", _trackballEHs[meshIndex]->_trackball->getCamera()->getViewMatrix());
LGL_ERROR;
// The color that will be used for rendering the object
tgt::Vector4<float> meshColor = static_cast<tgt::Vector4<float>>(p_meshSolidColor.getValue());
meshColor.r /= 255.0f;
meshColor.g /= 255.0f;
meshColor.b /= 255.0f;
meshColor.a /= 255.0f;
_geomteryRenderingShader->setUniform("_Color", meshColor);
_geometryRenderingShader->setUniform("_Color", meshColor);
LGL_ERROR;
_geomteryRenderingShader->setUniform("_cameraPosition", _trackballEHs[meshIndex]->_trackball->getCamera()->getPosition());
_geomteryRenderingShader->setIgnoreUniformLocationError(false);
_geometryRenderingShader->setUniform("_cameraPosition", _trackballEHs[meshIndex]->_trackball->getCamera()->getPosition());
_geometryRenderingShader->setIgnoreUniformLocationError(false);
LGL_ERROR;
tgt::FramebufferObject* frameBuffer = new tgt::FramebufferObject();
LGL_ERROR;
......@@ -316,22 +360,19 @@ namespace campvis {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
LGL_ERROR;
//for (std::map<QString, QtDataHandle>::iterator it = _handles.begin(); it != _handles.end(); ++it) {
// if (const campvis::MeshGeometry* mg = dynamic_cast<const campvis::MeshGeometry*>(it->second.getData())) {
// render the geometry into a polygon mesh.
glPolygonMode(GL_FRONT, GL_POLYGON);
mg->render(GL_POLYGON);
_geomteryRenderingShader->setUniform("_Color", 1.0f, 1.0f, 1.0f, 1.0f);
// Render wireframe around the object
// change the color to white for the wireframe.
_geometryRenderingShader->setUniform("_Color", 1.0f, 1.0f, 1.0f, 1.0f);
// Render wireframe around the geometry.
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
mg->render(GL_POLYGON);
// }
// }
LGL_ERROR;
colorBuffer->downloadTexture();
......@@ -340,11 +381,11 @@ namespace campvis {
frameBuffer->deactivate();
LGL_ERROR;
_geomteryRenderingShader->deactivate();
_geometryRenderingShader->deactivate();
glPopAttrib();
//delete frameBuffer;
delete frameBuffer;
}
void DataContainerInspectorCanvas::invalidate() {
......@@ -357,7 +398,6 @@ namespace campvis {
// only if inited
if (_quad != 0 && _paintShader != 0)
GLJobProc.enqueueJob(this, makeJobOnHeap(this, &DataContainerInspectorCanvas::paintMeshGeomTextures), OpenGLJobProcessor::PaintJob);
//paintMeshGeomTextures();
}
void DataContainerInspectorCanvas::createQuad() {
......@@ -578,24 +618,9 @@ namespace campvis {
}
void DataContainerInspectorCanvas::updateTextures() {
/// Clear the textures Array
_textures.clear();
_geomTextureIndices.clear();
/// Clear the geomtery rendered textures Array
std::vector<TrackballNavigationEventListener*>::iterator trackballNavEHIterator = _trackballEHs.begin();
for(; trackballNavEHIterator != _trackballEHs.end(); trackballNavEHIterator++)
{
delete (*trackballNavEHIterator);
}
_trackballEHs.clear();
std::vector<campvis::CameraProperty*>::iterator camPropertyIterator = _trackballCameraProperties.begin();
for(; camPropertyIterator != _trackballCameraProperties.end(); camPropertyIterator++)
{
delete (*camPropertyIterator);
}
_trackballCameraProperties.clear();
/// Reset the content of the Canvas.
resetContent();
/// Calculate the maximum slices of the textures and fill the textures array
int maxSlices = 1;
......@@ -632,30 +657,38 @@ namespace campvis {
static bool flag = false;
///
campvis::CameraProperty* cameraProperty = new CameraProperty("camera", "Camera");
_trackballCameraProperties.push_back(cameraProperty);
/// re-initialize the trackball navigation event listener to reset the object's pose
TrackballNavigationEventListener* trackballEH = new TrackballNavigationEventListener(cameraProperty, new IVec2Property("QuadSize", "Size", _renderingWndSize, tgt::ivec2(0), tgt::ivec2(1024)) );
//if(!flag)
//{
float dist = 3 * fabs(mg->getWorldBounds().getLLF().z - mg->getWorldBounds().getURB().z);
trackballEH->reinitializeCamera(mg->getWorldBounds());
trackballEH->_trackball->moveCameraBackward(dist);
LGL_ERROR;
flag = true;
//}
float dist = 3 * fabs(mg->getWorldBounds().getLLF().z - mg->getWorldBounds().getURB().z);
trackballEH->reinitializeCamera(mg->getWorldBounds());
trackballEH->_trackball->moveCameraBackward(dist);
LGL_ERROR;
flag = true;
/// store the trackball in the vector
_trackballEHs.push_back(trackballEH);
/// create color buffer and depth buffer.
tgt::Texture* colorBuffer = new tgt::Texture(0, tgt::ivec3(_renderingWndSize.x, _renderingWndSize.y, 1), GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, tgt::Texture::LINEAR);
tgt::Texture* depthBuffer = new tgt::Texture(0, tgt::ivec3(_renderingWndSize.x, _renderingWndSize.y, 1), GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT24, GL_FLOAT, tgt::Texture::LINEAR);
/// Render the object on the buffers.
glewExperimental = true;
drawMeshGeomtery(mg, colorBuffer, depthBuffer, nMeshGeometry++);
drawMeshgeometry(mg, colorBuffer, depthBuffer, nMeshGeometry++);
LGL_ERROR;
_geomteryRendering_ColorBuffers.push_back(colorBuffer);
_geomteryRendering_DepthBuffers.push_back(depthBuffer);
/// Store the buffers into array.
_geometryRendering_ColorBuffers.push_back(colorBuffer);
_geometryRendering_DepthBuffers.push_back(depthBuffer);
/// Store the rendered texture in textures.
_textures.push_back(colorBuffer);
/// Store the object index in the array in the geometry texture indices array.
_geomTextureIndices.push_back(_textures.size() - 1);
}else if(const campvis::FaceGeometry* fg = dynamic_cast<const campvis::FaceGeometry*>(it->second.getData())){
......@@ -698,27 +731,28 @@ namespace campvis {
}
}
}
else if(const campvis::MeshGeometry* mg = dynamic_cast<const campvis::MeshGeometry*>(it->second.getData())){
LGL_ERROR;
else if(const campvis::MeshGeometry* mg = dynamic_cast<const campvis::MeshGeometry*>(it->second.getData())){
/// Createa new color and depth buffer to render the new pose of the mesh object
tgt::Texture* colorBuffer = new tgt::Texture(0, tgt::ivec3(_renderingWndSize.x, _renderingWndSize.y, 1), GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, tgt::Texture::LINEAR);
tgt::Texture* depthBuffer = new tgt::Texture(0, tgt::ivec3(_renderingWndSize.x, _renderingWndSize.y, 1), GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT24, GL_FLOAT, tgt::Texture::LINEAR);
//_meshGeomteryPtr = mg;
/// delete the previous data in the
delete *(_textures.begin() + nElement);
std::vector<const tgt::Texture*>::iterator erased = _textures.erase(_textures.begin() + nElement);
_trackballCameraProperties[nMeshGeometry]->getValue();
//drawMeshGeomtery(mg, _geomteryRendering_ColorBuffers[nMeshGeometry], _geomteryRendering_DepthBuffers[nMeshGeometry], nMeshGeometry);
glewExperimental = true;
drawMeshGeomtery(mg, colorBuffer, depthBuffer, nMeshGeometry);
nMeshGeometry++;
/// render the mesh object
drawMeshgeometry(mg, colorBuffer, depthBuffer, nMeshGeometry);
/// insert it into the array of textures (in the
_textures.insert(_textures.begin() + nElement, colorBuffer);
/// increase the number of geomteries and number of elements
nMeshGeometry++;
nElement++;
/// delete the stored depth buffer
delete depthBuffer;
}else if(const campvis::FaceGeometry* fg = dynamic_cast<const campvis::FaceGeometry*>(it->second.getData())){
......
......@@ -90,6 +90,12 @@ namespace campvis {
*/
void deinit();
/**
* Reset the content of the canvas.
* It will clear the array of textures, rendered geomteries, color buffers, depth buffers and its content.
*/
void resetContent();
void setDataHandles(const std::vector< std::pair<QString, QtDataHandle> >& handles);
/**
......@@ -201,7 +207,7 @@ namespace campvis {
void invalidate();
/**
* To be called when the mesh geomtery parts of the scene is invalidated, issues new paint job.
* To be called when the mesh geometry parts of the scene is invalidated, issues new paint job only for textures that belong to mesh geomteries.
*/
void invalidateMeshGeomTextures();
......@@ -209,15 +215,20 @@ namespace campvis {
* Renders the given 2D texture.
* Binds the texture to the shader, sets the uniforms and renders the quad.
* \param texture The texture to render.
* \param uint2d The texture unit that will be attached to rendering pipeline (2D for 2D textures).
* \param uint2d The texture unit that will be attached to rendering pipeline (3D for 3D textures).
*/
void paintTexture(const tgt::Texture* texture, const tgt::TextureUnit& unit2d, const tgt::TextureUnit& unit3d);
/**
* Renders the MeshGeomtery into the geomtery renderer color buffer and depth buffer
* Binds the texture to the shader, sets the uniforms and renders the quad.
* \param meshGeomtery The mesh to be rendered.
* Renders the Meshgeometry into the geometry renderer color buffer and depth buffer.
* Binds the texture to the shader, sets the uniforms and renders the mesh geometry.
* \param meshgeometry The mesh to be rendered.
* \param colorBuffer The color buffer that the object will be rendered to.
* \param depthBuffer The depth buffer that the object will be rendered to.
* \param meshIndex The index of the rendered mesh in the texture array.
*/
void drawMeshGeomtery(const campvis::MeshGeometry* meshGeomtery, tgt::Texture* colorBuffer, tgt::Texture* depthBuffer, const unsigned int& meshIndex);
void drawMeshgeometry(const campvis::MeshGeometry* meshgeometry, tgt::Texture* colorBuffer, tgt::Texture* depthBuffer, const unsigned int& meshIndex);
/**
* Creates the quad used for rendering the textures.
......@@ -225,37 +236,37 @@ namespace campvis {
void createQuad();
std::map<QString, QtDataHandle> _handles;
std::vector<const tgt::Texture*> _textures;
bool _texturesDirty;
bool _meshGeomTexturesDirty;
std::vector<const tgt::Texture*> _textures; ///< vector of textures
bool _texturesDirty; ///< Flag that shows that the textures need update or not.
bool _meshGeomTexturesDirty; ///< Flag that shows that the mesh geometry textures need updare or not.
DataContainer* _dataContainer; ///< The DataContainer this widget is inspecting
tbb::mutex _localMutex; ///< Mutex protecting the local members
DataContainer* _dataContainer; ///< The DataContainer this widget is inspecting
tbb::mutex _localMutex; ///< Mutex protecting the local members
tgt::Shader* _paintShader; ///< GLSL shader for rendering the textures
FaceGeometry* _quad; ///< Quad used for rendering
tgt::Shader* _paintShader; ///< GLSL shader for rendering the textures
FaceGeometry* _quad; ///< Quad used for rendering
tgt::Color _color; ///< Color under the mouse cursor
float _depth; ///< Depth under the mouse cursor
DataContainerInspectorWidget* _widget; ///< Pointer to the widget which has access to this canvas
tgt::Color _color; ///< Color under the mouse cursor
float _depth; ///< Depth under the mouse cursor
DataContainerInspectorWidget* _widget; ///< Pointer to the widget which has access to this canvas
tgt::ivec2 _numTiles; ///< number of tiles on texture overview
tgt::ivec2 _quadSize; ///< size in pixels for each tile in overview
size_t _selectedTexture; ///< index of selected texture by mouse
tgt::ivec2 _numTiles; ///< number of tiles on texture overview
tgt::ivec2 _quadSize; ///< size in pixels for each tile in overview
size_t _selectedTexture; ///< index of selected texture by mouse
int _selectedTrackball; ///< index of selected trackball which will be updated currently
bool _renderFullscreen; ///< flag whether to render in full screen
bool _renderFullscreen; ///< flag whether to render in full screen
int _currentSlice; ///< current slice if rendering a 3D image fullscreen, render MIP if negative
int _currentSlice; ///< current slice if rendering a 3D image fullscreen, render MIP if negative
tgt::Shader* _geomteryRenderingShader; ///< GLSL shader for rendering the geomtery
std::vector<tgt::Texture*> _geomteryRendering_ColorBuffers; ///< Color Buffer used to render the Geomtery for the debugging mode
std::vector<tgt::Texture*> _geomteryRendering_DepthBuffers; ///< Depth Buffer used to render the Geomtery for the debugging mode
const campvis::MeshGeometry* _meshGeomteryPtr; ///<! Pointer to the mesh Geomtery objects
tgt::Shader* _geometryRenderingShader; ///< GLSL shader for rendering the mesh geomteries
std::vector<tgt::Texture*> _geometryRendering_ColorBuffers; ///< Color Buffer used to render the geometry for the debugging mode
std::vector<tgt::Texture*> _geometryRendering_DepthBuffers; ///< Depth Buffer used to render the geometry for the debugging mode
const campvis::MeshGeometry* _meshgeometryPtr; ///< Pointer to the mesh geometry objects
tgt::ivec2 _renderingWndSize;
std::vector<campvis::CameraProperty*> _trackballCameraProperties; ///< The property of the trackball camera. Used to pass the trackball camera to the shader.
std::vector<TrackballNavigationEventListener*> _trackballEHs; ///< TrackBall Event Handler for the camera rotating around the object in the canvas
std::vector<int> _geomTextureIndices;
std::vector<campvis::CameraProperty*> _trackballCameraProperties; ///< The property of the trackball camera. Used to pass the trackball camera to the shader.
std::vector<TrackballNavigationEventListener*> _trackballEHs; ///< TrackBall Event Handler for the camera rotating around the object in the canvas
std::vector<int> _geomTextureIndices; ///< Array of Indices in the texture which are achieved by rendering a geometry
};
}
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// 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 HOLDER 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.
//
// ================================================================================================
in vec3 in_Position; ///< incoming vertex position
in vec3 in_TexCoord; ///< incoming texture coordinate
in vec4 in_Color; ///< incoming color
out vec3 ex_TexCoord; ///< outgoing texture coordinate
out vec4 ex_Color; ///< outgoing color
out vec4 ex_Position; ///< outgoing world coordinates
out vec3 ex_Local_Position; ///< outgoing local coordinates
/// Matrix defining model-to-world transformation
uniform mat4 _modelMatrix = mat4(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
/// Matrix defining view transformation
uniform mat4 _viewMatrix = mat4(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
/// Matrix defining projection transformation
uniform mat4 _projectionMatrix = mat4(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
void main() {
ex_Local_Position = in_Position;
gl_Position = _projectionMatrix * (_viewMatrix * (_modelMatrix * vec4(in_Position, 1.0)));
ex_Position = gl_Position;
ex_TexCoord = in_TexCoord;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment