Commit 2ef42d4e authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

New features for DataContainerInspectorWidget:

* Support read-out of texel values also for 3D images
* introducing tgt::Texture::texelAsFloat() for 3D images
* Fixed Qt crashes in FloatPropertyWidget caused by changing GUI from non-GUI thread
parent 646f0194
......@@ -386,7 +386,7 @@ namespace campvis {
void DataContainerInspectorCanvas::mouseMoveEvent(tgt::MouseEvent* e)
{
if(e->button() == tgt::MouseEvent::MOUSE_BUTTON_LEFT) {
if (e->button() == tgt::MouseEvent::MOUSE_BUTTON_LEFT) {
tgt::MouseEvent* me = static_cast<tgt::MouseEvent*>(e);
tgt::MouseEvent adjustedMe(
......@@ -407,7 +407,8 @@ namespace campvis {
}
}
else if(e->button() == tgt::MouseEvent::MOUSE_BUTTON_RIGHT) {
{
tgt::ivec2 dimCanvas = tgt::ivec2(_quadSize.x * _numTiles.x, _quadSize.y * _numTiles.y);
if(e->x() >= dimCanvas.x || e->y() >= dimCanvas.y || e->x() < 0 || e->y() < 0)
return;
......@@ -425,8 +426,16 @@ namespace campvis {
_widget->updateDepth();
}
else {
_color = _textures[texIndx]->texelAsFloat(cursorPosX, texHeight - cursorPosY - 1);
_widget->updateColor();
if (_textures[texIndx]->getDimensions().z != 1) {
if (p_currentSlice.getValue() >= 0 && p_currentSlice.getValue() < _textures[texIndx]->getDimensions().z) {
_color = _textures[texIndx]->texelAsFloat(cursorPosX, texHeight - cursorPosY - 1, p_currentSlice.getValue());
_widget->updateColor();
}
}
else if (_textures[texIndx]->getDimensions().y != 1) {
_color = _textures[texIndx]->texelAsFloat(cursorPosX, texHeight - cursorPosY - 1);
_widget->updateColor();
}
}
}
}
......@@ -542,6 +551,7 @@ namespace campvis {
for (std::map<QString, QtDataHandle>::iterator it = _handles.begin(); it != _handles.end(); ++it) {
if (const ImageData* img = dynamic_cast<const ImageData*>(it->second.getData())) {
if (const ImageRepresentationGL* imgGL = img->getRepresentation<ImageRepresentationGL>()) {
imgGL->downloadTexture();
_textures.push_back(imgGL->getTexture());
maxSlices = std::max(maxSlices, imgGL->getTexture()->getDimensions().z);
}
......
......@@ -189,10 +189,10 @@ namespace campvis {
}
void DataContainerInspectorWidget::updateColor(){
const tgt::Color& color = _canvas->getCapturedColor();
const tgt::Color color = _canvas->getCapturedColor();
_lblColorVal->setText(QString("Color: R = %1 G = %2 B = %3").arg(QString::number(static_cast<int>(color.r * 255)), QString::number(static_cast<int>(color.g * 255)), QString::number(static_cast<int>(color.b * 255))));
_lblColorVal->setText(QString("Color: [%1, %2, %3, %4]").arg(QString::number(color.r), QString::number(color.g), QString::number(color.b), QString::number(color.a)));
_ColorValWidgetPalette->setColor(QPalette::Background, QColor(static_cast<int>(color.r * 255), static_cast<int>(color.g * 255), static_cast<int>(color.b * 255)));
_colorValWidget->setPalette(*_ColorValWidgetPalette);
......
......@@ -56,6 +56,10 @@ namespace campvis {
FloatProperty* prop = static_cast<FloatProperty*>(_property);
_adjuster->blockSignals(true);
_adjuster->setValue(prop->getValue());
_adjuster->setMinimum(prop->getMinValue());
_adjuster->setMaximum(prop->getMaxValue());
_adjuster->setSingleStep(prop->getStepValue());
_adjuster->setDecimals(prop->getDecimals());
_adjuster->blockSignals(false);
}
......@@ -67,24 +71,17 @@ namespace campvis {
}
void FloatPropertyWidget::onPropertyMinMaxChanged(const AbstractProperty* property) {
if (_ignorePropertyUpdates == 0) {
const FloatProperty* prop = static_cast<const FloatProperty*>(property);
_adjuster->setMinimum(prop->getMinValue());
_adjuster->setMaximum(prop->getMaxValue());
}
if (_ignorePropertyUpdates == 0)
emit s_propertyChanged(property);
}
void FloatPropertyWidget::onPropertyStepChanged(const AbstractProperty* property) {
if (_ignorePropertyUpdates == 0) {
const FloatProperty* prop = static_cast<const FloatProperty*>(property);
_adjuster->setSingleStep(prop->getStepValue());
}
if (_ignorePropertyUpdates == 0)
emit s_propertyChanged(property);
}
void FloatPropertyWidget::onPropertyDecimalsChanged(const AbstractProperty* property) {
if (_ignorePropertyUpdates == 0) {
const FloatProperty* prop = static_cast<const FloatProperty*>(property);
_adjuster->setDecimals(prop->getDecimals());
}
if (_ignorePropertyUpdates == 0)
emit s_propertyChanged(property);
}
}
......@@ -522,8 +522,7 @@ tgt::Color Texture::texelAsFloat(size_t x, size_t y) const {
LWARNINGC("tgt.texture", "texelAsFloat: Unknown data type!");
}
break;
case GL_LUMINANCE:
case GL_ALPHA:
case GL_RED:
switch(dataType_) {
case GL_UNSIGNED_BYTE: {
tgt::Vector3<uint8_t> t = tgt::vec3(texel<uint8_t>(x,y));
......@@ -560,6 +559,102 @@ tgt::Color Texture::texelAsFloat(size_t x, size_t y) const {
return ret;
}
tgt::Color Texture::texelAsFloat(size_t x, size_t y, size_t z) const {
tgt::Color ret = tgt::Color(0.0f);
switch(format_) {
case GL_RGBA:
switch(dataType_) {
case GL_UNSIGNED_BYTE: {
tgt::Vector4<uint8_t> t = texel< tgt::Vector4<uint8_t> >(x,y,z);
ret.x = (float )t.x / 0xFF;
ret.y = (float )t.y / 0xFF;
ret.z = (float )t.z / 0xFF;
ret.w = (float )t.w / 0xFF;
break;
}
case GL_UNSIGNED_SHORT: {
tgt::Vector4<uint16_t> t = texel< tgt::Vector4<uint16_t> >(x,y,z);
ret.x = (float )t.x / 0xFFFF;
ret.y = (float )t.y / 0xFFFF;
ret.z = (float )t.z / 0xFFFF;
ret.w = (float )t.w / 0xFFFF;
break;
}
case GL_FLOAT:
ret = texel<tgt::Color>(x,y,z);
break;
default:
LWARNINGC("tgt.texture", "texelAsFloat: Unknown data type!");
}
break;
case GL_RGB:
switch(dataType_) {
case GL_UNSIGNED_BYTE: {
tgt::Vector3<uint8_t> t = texel< tgt::Vector3<uint8_t> >(x,y,z);
ret.x = (float )t.x / 0xFF;
ret.y = (float )t.y / 0xFF;
ret.z = (float )t.z / 0xFF;
ret.w = 1.0f;
break;
}
case GL_UNSIGNED_SHORT: {
tgt::Vector3<uint16_t> t = texel< tgt::Vector3<uint16_t> >(x,y,z);
ret.x = (float )t.x / 0xFFFF;
ret.y = (float )t.y / 0xFFFF;
ret.z = (float )t.z / 0xFFFF;
ret.w = 1.0f;
break;
}
case GL_FLOAT: {
tgt::Vector3f t = texel<tgt::Vector3f>(x,y,z);
ret.x = t.x;
ret.y = t.y;
ret.z = t.z;
ret.w = 1.0f;
break;
}
default:
LWARNINGC("tgt.texture", "texelAsFloat: Unknown data type!");
}
break;
case GL_RED:
switch(dataType_) {
case GL_UNSIGNED_BYTE: {
tgt::Vector3<uint8_t> t = tgt::vec3(texel<uint8_t>(x,y,z));
ret.x = (float )t.x / 0xFF;
ret.y = (float )t.y / 0xFF;
ret.z = (float )t.z / 0xFF;
ret.w = 1.0f;
break;
}
case GL_UNSIGNED_SHORT: {
tgt::Vector3<uint16_t> t = tgt::vec3(texel<uint16_t>(x,y,z));
ret.x = (float )t.x / 0xFFFF;
ret.y = (float )t.y / 0xFFFF;
ret.z = (float )t.z / 0xFFFF;
ret.w = 1.0f;
break;
}
case GL_FLOAT: {
tgt::Vector3f t = tgt::vec3(texel<GLfloat>(x,y,z));
ret.x = t.x;
ret.y = t.y;
ret.z = t.z;
ret.w = 1.0f;
break;
}
default:
LWARNINGC("tgt.texture", "texelAsFloat: Unknown data type!");
}
break;
default:
LWARNINGC("tgt.texture", "texelAsFloat: Unknown format!");
}
return ret;
}
float Texture::depthAsFloat(size_t x, size_t y) const {
float ret = 0.0f;
......
......@@ -398,6 +398,7 @@ public:
///Return texel as tgt::Color (slow!), downloadTexture() needs to be called first
tgt::Color texelAsFloat(size_t x, size_t y) const;
tgt::Color texelAsFloat(size_t x, size_t y, size_t z) const;
float depthAsFloat(size_t x, size_t y) const;
tgt::Color texelAsFloat(tgt::svec2 p) const { return texelAsFloat(p.x, p.y); }
float depthAsFloat(tgt::svec2 p) const { return depthAsFloat(p.x, p.y); }
......
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