6.5.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit d53dbd6a authored by mmostajab's avatar mmostajab

# Adding the Geomtery Renderer to the Canvas

# Fixing the bugs of the Color Window in the Canvas
parent 613821c9
......@@ -62,7 +62,7 @@ namespace campvis {
, _currentSlice(-1)
, _color(0.0f, 0.0f, 0.0f, 0.0f)
{
static_cast<Geometry1DTransferFunction*>(p_transferFunction.getTF())->addGeometry(TFGeometry1D::createQuad(tgt::vec2(0.f, 1.f), tgt::col4(0, 0, 0, 255), tgt::col4(255, 255, 255, 255)));
static_cast<Geometry1DTransferFunction*>(p_transferFunction.getTF())->addGeometry(TFGeometry1D::createQuad(tgt::vec2(0.f, 1.f), tgt::col4(0, 0, 0, 255), tgt::col4(255, 255, 255, 255)));
makeCurrent();
// Init GLEW for this context
......@@ -89,6 +89,8 @@ namespace campvis {
GLJobProc.registerContext(this);
_paintShader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "application/glsl/datacontainerinspector.frag", "", false);
_geomteryRenderingShader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "modules/vis/glsl/geometryrenderer.frag", "", false);
_paintShader->setAttributeLocation(0, "in_Position");
_paintShader->setAttributeLocation(1, "in_TexCoords");
......@@ -263,9 +265,18 @@ namespace campvis {
const int texHeight = texturePtr->getHeight();
int cursorPosX = static_cast<int>(static_cast<float>(e->x() % _quadSize.x) / _quadSize.x * texWidth);
int cursorPosY = static_cast<int>(static_cast<float>(e->y() % _quadSize.y) / _quadSize.y * texHeight);
_color = _textures[texIndx]->texelAsFloat(cursorPosX, texHeight - cursorPosY - 1);
_widget->updateColor();
float f = 0.0;
if(_textures[texIndx]->isDepthTexture())
{
_depth = _textures[texIndx]->depthAsFloat(cursorPosX, texHeight - cursorPosY - 1);
_widget->updateDepth();
}
else
{
_color = _textures[texIndx]->texelAsFloat(cursorPosX, texHeight - cursorPosY - 1);
_widget->updateColor();
}
}
}
......@@ -327,6 +338,11 @@ namespace campvis {
return _color;
}
const float& DataContainerInspectorCanvas::getCapturedDepth()
{
return _depth;
}
void DataContainerInspectorCanvas::updateTextures() {
/// Clear the textures Array
_textures.clear();
......@@ -360,12 +376,90 @@ namespace campvis {
}
}
else if(const campvis::MeshGeometry* mg = dynamic_cast<const campvis::MeshGeometry*>(it->second.getData())){
// Here the object will be rendered into a texture and the texture will be shown on the output buffer.
//mg->render(GL_POLYGON);
//const tgt::BufferObject* buffer = mg->getColorsBuffer();
}
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();
LGL_ERROR;
_geomteryRenderingShader->setIgnoreUniformLocationError(true);
LGL_ERROR;
//decorateRenderProlog(data, _shader);
float dist = 3 * fabs(mg->getWorldBounds().getLLF().z - mg->getWorldBounds().getURB().z);
tgt::Camera cameraInfo(tgt::vec3(0.0f, 0.0f, dist), tgt::vec3(0, 0, -1));
cameraInfo.setFarDist(1000.0f);
campvis::CameraProperty* p_camera = new campvis::CameraProperty("camera", "Camera", cameraInfo);
campvis::IVec4Property* p_color = new campvis::IVec4Property("color", "Rendering Color", tgt::vec4(1.f), tgt::vec4(0.f), tgt::vec4(1.f));
_geomteryRenderingShader->setUniform("_projectionMatrix", p_camera->getValue().getProjectionMatrix());
LGL_ERROR;
_geomteryRenderingShader->setUniform("_viewMatrix", p_camera->getValue().getViewMatrix());
LGL_ERROR;
LGL_ERROR;
_geomteryRenderingShader->setUniform("_modelMatrix", tgt::mat4::createTranslation(-mg->getWorldBounds().center()));
LGL_ERROR;
LGL_ERROR;
//_geomteryRenderingShader->setUniform("_color", p_color->getValue());
// LGL_ERROR;
_geomteryRenderingShader->setUniform("_cameraPosition", p_camera->getValue().getPosition());
LGL_ERROR;
_geomteryRenderingShader->setIgnoreUniformLocationError(false);
LGL_ERROR;
tgt::FramebufferObject* frameBuffer = new tgt::FramebufferObject();
LGL_ERROR;
frameBuffer->activate();
LGL_ERROR;
// acqiure a new TextureUnit, so that we don't mess with other currently bound textures during texture upload...
//tgt::TextureUnit rtUnit;
//rtUnit.activate();
// Set OpenGL pixel alignment to 1 to avoid problems with NPOT textures
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
tgt::Texture* colorBuff = new tgt::Texture(0, tgt::ivec3(400, 100, 1), GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, tgt::Texture::LINEAR);
tgt::Texture* depthBuff = new tgt::Texture(0, tgt::ivec3(400, 100, 1), GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT24, GL_FLOAT, tgt::Texture::LINEAR);
colorBuff->uploadTexture();
colorBuff->setWrapping(tgt::Texture::CLAMP_TO_EDGE);
depthBuff->uploadTexture();
depthBuff->setWrapping(tgt::Texture::CLAMP_TO_EDGE);
LGL_ERROR;
frameBuffer->attachTexture(colorBuff, GL_COLOR_ATTACHMENT0);
frameBuffer->attachTexture(depthBuff, GL_DEPTH_ATTACHMENT);
frameBuffer->isComplete();
LGL_ERROR;
glViewport(0, 0, 400, 100);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
LGL_ERROR;
mg->render(GL_POLYGON);
LGL_ERROR;
colorBuff->downloadTexture();
frameBuffer->deactivate();
LGL_ERROR;
_geomteryRenderingShader->deactivate();
_textures.push_back(colorBuff);
glPopAttrib();
}else if(const campvis::FaceGeometry* fg = dynamic_cast<const campvis::FaceGeometry*>(it->second.getData())){
}
}
if (maxSlices == 1)
......
......@@ -44,6 +44,7 @@
#include "core/properties/numericproperty.h"
#include "core/properties/transferfunctionproperty.h"
#include "core/tools/opengljobprocessor.h"
#include "modules/vis/processors/geometryrenderer.h"
namespace tgt {
class Shader;
......@@ -87,7 +88,16 @@ namespace campvis {
void deinit();
void setDataHandles(const std::vector< std::pair<QString, QtDataHandle> >& handles);
const tgt::Color& getCapturedColor();
/**
* returns the color value which is captured with the mouse.
*/
const tgt::Color& getCapturedColor();
/**
* returns the depth value which is captured with the mouse.
*/
const float& getCapturedDepth();
/**
* Size hint for the default window size
......@@ -170,6 +180,13 @@ namespace campvis {
*/
void paintTexture(const tgt::Texture* texture, const tgt::TextureUnit& unit2d, const tgt::TextureUnit& unit3d);
/**
* Renders the given 2D texture.
* Binds the texture to the shader, sets the uniforms and renders the quad.
* \param texture The texture to render.
*/
void drawGeomtery();
/**
* Creates the quad used for rendering the textures.
*/
......@@ -185,16 +202,18 @@ namespace campvis {
tgt::Shader* _paintShader; ///< GLSL shader for rendering the textures
FaceGeometry* _quad; ///< Quad used for rendering
tgt::Color _color; ///< Color 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 for fullscreen view
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
};
}
......
......@@ -203,6 +203,16 @@ namespace campvis {
_colorValWidget->setPalette(*_ColorValWidgetPalette);
}
void DataContainerInspectorWidget::updateDepth(){
float depth = _canvas->getCapturedDepth();
_lblColorVal->setText(QString("Depth: %1").arg(QString::number(depth)));
_ColorValWidgetPalette->setColor(QPalette::ColorRole::Background, QColor(static_cast<int>(depth * 255), static_cast<int>(depth * 255), static_cast<int>(depth * 255)));
_colorValWidget->setPalette(*_ColorValWidgetPalette);
}
void DataContainerInspectorWidget::updateInfoWidget() {
if (!_inited)
return;
......@@ -254,7 +264,9 @@ namespace campvis {
ss << tester->getWorldBounds();
_lblBounds->setText(tr("World Bounds: ") + QString::fromStdString(ss.str()));
//tester->render();
//tester->render();
}
else if (const RenderData* tester = dynamic_cast<const RenderData*>(handles.front().second.getData())) {
const ImageData* id = tester->getNumColorTextures() > 0 ? tester->getColorTexture() : tester->getDepthTexture();
......
......@@ -117,6 +117,11 @@ namespace campvis {
*/
void updateColor();
/**
* Updates depth of the info widget
*/
void updateDepth();
signals:
void dataContainerChanged(const QString&, QtDataHandle);
......@@ -146,6 +151,9 @@ namespace campvis {
* \param handle DataHandle containing the image to save. Must contain ImageData or RenderData!
* \param filename Filename for the file to save.
*/
//protected:
public: // Only for Debuggin
static void saveToFile(DataHandle handle, std::string filename);
/**
......@@ -178,11 +186,11 @@ namespace campvis {
QLabel* _lblTimestamp;
QLabel* _lblSize;
QLabel* _lblBounds;
QWidget* _colorWidget; ///< The widget use to show the color value and the color in a single window
QWidget* _colorWidget; ///< The widget use to show the color value and the color in a single window
QHBoxLayout* _colorWidgetLayout; ///< Layout for the following widget
QLabel* _lblColorVal; ///< Color Label Value in text
QWidget* _colorValWidget; ///< Widget that shows the color value in color
QPalette* _ColorValWidgetPalette; ///< Palette which will be used to colorize the color widget
QLabel* _lblColorVal; ///< Color Label Value in text
QWidget* _colorValWidget; ///< Widget that shows the color value in color
QPalette* _ColorValWidgetPalette; ///< Palette which will be used to colorize the color widget
QPushButton* _btnSaveToFile;
static const std::string loggerCat_;
......
......@@ -260,9 +260,11 @@ namespace campvis {
LGL_ERROR;
}
const tgt::Texture* ImageRepresentationGL::getTexture() const {
void ImageRepresentationGL::downloadTexture() const {
_texture->downloadTexture();
}
_texture->downloadTexture();
const tgt::Texture* ImageRepresentationGL::getTexture() const {
return _texture;
}
......
......@@ -118,6 +118,12 @@ namespace campvis {
const std::string& texUniform = "_texture",
const std::string& texParamsUniform = "_textureParams") const;
/**
* Download the OpenGL texture from the GPU memory to the texture cpu buffer.
* \return _texture
*/
void downloadTexture() const;
/**
* Gets the OpenGL texture.
* \return _texture
......
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