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

Commit 4bd4963e authored by mmostajab's avatar mmostajab

# Make a pointer from datacontainerinspectorwidget into...

# Make a pointer from datacontainerinspectorwidget into datacontainerinspectorcanvas, as we need to call the updateInfoWidget() after updating the color.

# Make the updateInfoWidget() as public to be able to call it.

# Add the Capability to look up the color under the mouse button when one of the mouse buttons is pressed.
parent 848d765c
......@@ -42,6 +42,8 @@
#include "core/classification/tfgeometry1d.h"
#include "core/classification/geometry1dtransferfunction.h"
#include "datacontainerinspectorwidget.h"
namespace campvis {
......@@ -57,6 +59,7 @@ namespace campvis {
, _selectedTexture(0)
, _renderFullscreen(false)
, _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)));
......@@ -78,9 +81,11 @@ namespace campvis {
}
void DataContainerInspectorCanvas::init() {
void DataContainerInspectorCanvas::init(DataContainerInspectorWidget* _pWidget) {
initAllProperties();
_widget = _pWidget;
GLJobProc.registerContext(this);
_paintShader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "application/glsl/datacontainerinspector.frag", "", false);
_paintShader->setAttributeLocation(0, "in_Position");
......@@ -227,6 +232,34 @@ namespace campvis {
invalidate();
}
void DataContainerInspectorCanvas::mousePressEvent(tgt::MouseEvent* e)
{
/*if (_renderFullscreen) {
_renderFullscreen = false;
}
else {
tgt::ivec2 selectedIndex(e->x() / _quadSize.x, e->y() / _quadSize.y);
_selectedTexture = (selectedIndex.y * _numTiles.x) + selectedIndex.x;
_renderFullscreen = true;
}
e->ignore();
invalidate();*/
tgt::ivec2 dimCanvas = tgt::ivec2(_quadSize.x * _numTiles.x, _quadSize.y * _numTiles.y);
if(e->x() >= dimCanvas.x || e->y() >= dimCanvas.y)
return;
int texIndx = (e->y() / _quadSize.y) * _numTiles.x + (e->x() / _quadSize.x);
int cursorPosX = (float)(e->x() % _quadSize.x) / _quadSize.x * _textures[texIndx]->getWidth();
int cursorPosY = (float)(e->y() % _quadSize.y) / _quadSize.y * _textures[texIndx]->getHeight();
_color = _textures[texIndx]->texelAsFloat(cursorPosX, cursorPosY);
_widget->updateInfoWidget();
}
void DataContainerInspectorCanvas::wheelEvent(tgt::MouseEvent* e) {
if (_renderFullscreen) {
switch (e->button()) {
......@@ -278,8 +311,16 @@ namespace campvis {
invalidate();
}
tgt::Color DataContainerInspectorCanvas::getCapturedColor()
{
return _color;
}
void DataContainerInspectorCanvas::updateTextures() {
/// Clear the textures Array
_textures.clear();
/// Calculate the maximum slices of the textures and fill the textures array
int maxSlices = 1;
for (std::map<QString, QtDataHandle>::iterator it = _handles.begin(); it != _handles.end(); ++it) {
if (const ImageData* img = dynamic_cast<const ImageData*>(it->second.getData())) {
......
......@@ -57,6 +57,7 @@ namespace campvis {
class DataContainerTreeWidget;
class DataHandle;
class FaceGeometry;
class DataContainerInspectorWidget;
class DataContainerInspectorCanvas : public tgt::QtThreadedCanvas, tgt::Painter, public tgt::EventListener, public HasPropertyCollection {
Q_OBJECT;
......@@ -77,7 +78,7 @@ namespace campvis {
* Initializes the OpenGL stuff (e.g. shaders).
* Must be called with a valid and locked OpenGL context.
*/
virtual void init();
virtual void init(DataContainerInspectorWidget* _pWidget);
/**
* Deinitializes the OpenGL stuff (e.g. shaders).
......@@ -86,6 +87,7 @@ namespace campvis {
void deinit();
void setDataHandles(const std::vector< std::pair<QString, QtDataHandle> >& handles);
tgt::Color getCapturedColor();
/**
* Size hint for the default window size
......@@ -107,6 +109,12 @@ namespace campvis {
*/
virtual void mouseDoubleClickEvent(tgt::MouseEvent* e);
/**
* Called on mouse move event on this canvas
* \param e Mouse event arguments
*/
virtual void mousePressEvent(tgt::MouseEvent* e);
/**
* Called on mouse wheel even on this canvas.
* \param e Mouse event arguments
......@@ -172,6 +180,9 @@ 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::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
......
......@@ -141,6 +141,9 @@ namespace campvis {
_lblSize = new QLabel(tr("Size: "), _infoWidget);
_infoWidgetLayout->addWidget(_lblSize);
_lblColor = new QLabel(tr("Color: n/a"), _infoWidget);
_infoWidgetLayout->addWidget(_lblColor);
_lblBounds = new QLabel(tr("World Bounds:"), _infoWidget);
_infoWidgetLayout->addWidget(_lblBounds);
......@@ -186,7 +189,6 @@ namespace campvis {
for (QModelIndexList::const_iterator index = indices.begin(); index != indices.end(); ++index) {
if (! index->isValid())
continue;
// get DataHandle and Handle name
QVariant item = index->data(Qt::UserRole);
QtDataHandle handle = item.value<QtDataHandle>();
......@@ -215,11 +217,12 @@ namespace campvis {
ss.str("");
ss << tester->getWorldBounds();
_lblBounds->setText(tr("World Bounds: ") + QString::fromStdString(ss.str()));
}
else if (const GeometryData* tester = dynamic_cast<const GeometryData*>(handles.front().second.getData())) {
_lblSize->setText(tr("Size: n/a"));
std::ostringstream ss;
std::ostringstream ss;
ss << tester->getWorldBounds();
_lblBounds->setText(tr("World Bounds: ") + QString::fromStdString(ss.str()));
}
......@@ -235,6 +238,18 @@ namespace campvis {
}
#endif
else {
char bufferR[10];
char bufferG[10];
char bufferB[10];
tgt::Color color = _canvas->getCapturedColor();
itoa((int)(color.r * 255), bufferR, 10);
itoa((int)(color.g * 255), bufferG, 10);
itoa((int)(color.b * 255), bufferB, 10);
_lblColor->setText(QString("Color: ") + QString(bufferR) + QString(" ") + QString(bufferG) + QString(" ") + QString(bufferB));
_lblSize->setText(tr("Size: n/a"));
_lblBounds->setText(tr("World Bounds: n/a"));
}
......@@ -271,7 +286,7 @@ namespace campvis {
void DataContainerInspectorWidget::init() {
if (_canvas != 0)
_canvas->init();
_canvas->init(this);
_inited = true;
}
......
......@@ -89,6 +89,11 @@ namespace campvis {
*/
void onDataContainerDataAdded(const std::string&, const DataHandle&);
void mousePressEvent(QMouseEvent*)
{
updateInfoWidget();
}
/**
* Size hint for the default window size
* \return QSize(640, 480)
......@@ -107,6 +112,11 @@ namespace campvis {
*/
void deinit();
/**
* Updates _infoWidget
*/
void updateInfoWidget();
signals:
void dataContainerChanged(const QString&, QtDataHandle);
......@@ -130,11 +140,6 @@ namespace campvis {
*/
void setupGUI();
/**
* Updates _infoWidget
*/
void updateInfoWidget();
/**
* Saves the Image in \a handle to the file \a filename.
* \note This method must be called with a valid OpenGL context!
......@@ -168,6 +173,7 @@ namespace campvis {
QLabel* _lblTimestamp;
QLabel* _lblSize;
QLabel* _lblBounds;
QLabel* _lblColor;
QPushButton* _btnSaveToFile;
static const std::string loggerCat_;
......
......@@ -261,6 +261,9 @@ namespace campvis {
}
const tgt::Texture* ImageRepresentationGL::getTexture() const {
_texture->downloadTexture();
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