Commit 52e64453 authored by mmostajab's avatar mmostajab
Browse files

# Apply the coding style to the code

# use 4 spaces instead of tab
# use QString operations instead of unsafe C String operations
# use static_cast casting instead of C casting
parent 4c17fa37
......@@ -60,7 +60,7 @@ namespace campvis {
, _selectedTexture(0)
, _renderFullscreen(false)
, _currentSlice(-1)
, _color(0.0f, 0.0f, 0.0f, 0.0f)
, _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)));
......@@ -85,7 +85,7 @@ namespace campvis {
void DataContainerInspectorCanvas::init(DataContainerInspectorWidget* _pWidget) {
initAllProperties();
_widget = _pWidget;
_widget = _pWidget;
GLJobProc.registerContext(this);
_paintShader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "application/glsl/datacontainerinspector.frag", "", false);
......@@ -233,8 +233,8 @@ namespace campvis {
invalidate();
}
void DataContainerInspectorCanvas::mouseMoveEvent(tgt::MouseEvent* e)
{
void DataContainerInspectorCanvas::mouseMoveEvent(tgt::MouseEvent* e)
{
/*if (_renderFullscreen) {
_renderFullscreen = false;
}
......@@ -245,33 +245,24 @@ namespace campvis {
}
e->ignore();
invalidate();*/
static clock_t lastRunTime = clock();
if(!(clock() - lastRunTime > 0))
{
return;
}
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;
int texIndx = (e->y() / _quadSize.y) * _numTiles.x + (e->x() / _quadSize.x);
const tgt::Texture* texturePtr = _textures[texIndx];
const int texWidth = texturePtr->getWidth();
const int texHeight = texturePtr->getHeight();
int cursorPosX = (float)(e->x() % _quadSize.x) / _quadSize.x * texWidth;
int cursorPosY = (float)(e->y() % _quadSize.y) / _quadSize.y * texHeight;
_color = _textures[texIndx]->texelAsFloat(cursorPosX, texHeight - cursorPosY - 1);
_widget->updateColor();
}
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;
int texIndx = (e->y() / _quadSize.y) * _numTiles.x + (e->x() / _quadSize.x);
const tgt::Texture* texturePtr = _textures[texIndx];
const int texWidth = texturePtr->getWidth();
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();
}
}
void DataContainerInspectorCanvas::wheelEvent(tgt::MouseEvent* e) {
......@@ -325,16 +316,16 @@ namespace campvis {
invalidate();
}
tgt::Color DataContainerInspectorCanvas::getCapturedColor()
{
return _color;
}
const tgt::Color& DataContainerInspectorCanvas::getCapturedColor()
{
return _color;
}
void DataContainerInspectorCanvas::updateTextures() {
/// Clear the textures Array
/// Clear the textures Array
_textures.clear();
/// Calculate the maximum slices of the textures and fill the textures array
/// 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())) {
......@@ -347,22 +338,28 @@ namespace campvis {
for (size_t i = 0; i < rd->getNumColorTextures(); ++i) {
const ImageRepresentationGL* imgGL = rd->getColorTexture(i)->getRepresentation<ImageRepresentationGL>();
if (imgGL)
{
imgGL->downloadTexture();
_textures.push_back(imgGL->getTexture());
}
}
if (rd->hasDepthTexture()) {
const ImageRepresentationGL* imgGL = rd->getDepthTexture()->getRepresentation<ImageRepresentationGL>();
if (imgGL)
{
imgGL->downloadTexture();
_textures.push_back(imgGL->getTexture());
}
}
}
else if(const campvis::MeshGeometry* mg = dynamic_cast<const campvis::MeshGeometry*>(it->second.getData())){
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.
// 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();
}
//mg->render(GL_POLYGON);
//const tgt::BufferObject* buffer = mg->getColorsBuffer();
}
}
if (maxSlices == 1)
......
......@@ -57,7 +57,7 @@ namespace campvis {
class DataContainerTreeWidget;
class DataHandle;
class FaceGeometry;
class DataContainerInspectorWidget;
class DataContainerInspectorWidget;
class DataContainerInspectorCanvas : public tgt::QtThreadedCanvas, tgt::Painter, public tgt::EventListener, public HasPropertyCollection {
Q_OBJECT;
......@@ -78,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(DataContainerInspectorWidget* _pWidget);
virtual void init(DataContainerInspectorWidget* _pWidget);
/**
* Deinitializes the OpenGL stuff (e.g. shaders).
......@@ -87,7 +87,7 @@ namespace campvis {
void deinit();
void setDataHandles(const std::vector< std::pair<QString, QtDataHandle> >& handles);
tgt::Color getCapturedColor();
const tgt::Color& getCapturedColor();
/**
* Size hint for the default window size
......@@ -109,11 +109,11 @@ namespace campvis {
*/
virtual void mouseDoubleClickEvent(tgt::MouseEvent* e);
/**
/**
* Called on mouse move event on this canvas
* \param e Mouse event arguments
*/
virtual void mouseMoveEvent(tgt::MouseEvent* e);
virtual void mouseMoveEvent(tgt::MouseEvent* e);
/**
* Called on mouse wheel even on this canvas.
......@@ -180,8 +180,8 @@ 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
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
......
......@@ -141,32 +141,27 @@ namespace campvis {
_lblSize = new QLabel(tr("Size: "), _infoWidget);
_infoWidgetLayout->addWidget(_lblSize);
_wdgtColor = new QWidget(this);
//_lblColor = new QLabel(tr("Color:"), _wdgtColor);
_lblColorVal = new QLabel(tr("Color: n/a"), _wdgtColor);
_wdgtColorVal = new QWidget(this);
_wdgtColorVal->setAutoFillBackground(true);
_wdgtColorVal->setFixedSize(16, 16);
_wdgtColorValPalette = new QPalette(palette());
_wdgtColorValPalette->setColor(QPalette::ColorRole::Background, Qt::gray);
_wdgtColorVal->setPalette(*(_wdgtColorValPalette));
_wdgtColorLayout = new QHBoxLayout();
_wdgtColorLayout->setSpacing(0);
_wdgtColorLayout->setMargin(0);
//_wdgtColorLayout->setAlignment(Qt::Alignment::enum_type::AlignLeft);
_wdgtColor->setLayout(_wdgtColorLayout);
//_wdgtColorLayout->addWidget(_lblColor);
_wdgtColorLayout->addWidget(_lblColorVal);
_wdgtColorLayout->addWidget(_wdgtColorVal);
_infoWidgetLayout->addWidget(_wdgtColor);
_colorWidget = new QWidget(this);
_lblColorVal = new QLabel(tr("Color: n/a"), _colorWidget);
_colorValWidget = new QWidget(_colorWidget);
_colorValWidget->setAutoFillBackground(true);
_colorValWidget->setFixedSize(16, 16);
_ColorValWidgetPalette = new QPalette(palette());
_ColorValWidgetPalette->setColor(QPalette::ColorRole::Background, Qt::gray);
_colorValWidget->setPalette(*(_ColorValWidgetPalette));
_colorWidgetLayout = new QHBoxLayout();
_colorWidgetLayout->setSpacing(0);
_colorWidgetLayout->setMargin(0);
_colorWidget->setLayout(_colorWidgetLayout);
_colorWidgetLayout->addWidget(_lblColorVal);
_colorWidgetLayout->addWidget(_colorValWidget);
_infoWidgetLayout->addWidget(_colorWidget);
_lblBounds = new QLabel(tr("World Bounds:"), _infoWidget);
_infoWidgetLayout->addWidget(_lblBounds);
......@@ -198,24 +193,15 @@ namespace campvis {
this, SLOT(onBtnSaveToFileClicked()));
}
void DataContainerInspectorWidget::updateColor(){
void DataContainerInspectorWidget::updateColor(){
char bufferR[10];
char bufferG[10];
char bufferB[10];
tgt::Color color = _canvas->getCapturedColor();
const 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);
_lblColorVal->setText(QString("Color: R = ") + QString(bufferR) + QString(" G = ") + QString(bufferG) + QString(" B = ") + QString(bufferB));
QColor qtColor;
qtColor.setRgb(color.r * 255, color.g * 255, color.b * 255);
_wdgtColorValPalette->setColor(QPalette::ColorRole::Background, qtColor);
_wdgtColorVal->setPalette(*_wdgtColorValPalette);
}
_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))));
_ColorValWidgetPalette->setColor(QPalette::ColorRole::Background, QColor(static_cast<int>(color.r * 255), static_cast<int>(color.g * 255), static_cast<int>(color.b * 255)));
_colorValWidget->setPalette(*_ColorValWidgetPalette);
}
void DataContainerInspectorWidget::updateInfoWidget() {
if (!_inited)
......@@ -264,11 +250,11 @@ namespace campvis {
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()));
//tester->render();
//tester->render();
}
#ifdef CAMPVIS_HAS_MODULE_COLUMBIA
else if (const FiberData* tester = dynamic_cast<const FiberData*>(handles.front().second.getData())) {
......@@ -283,7 +269,7 @@ namespace campvis {
#endif
else {
_lblSize->setText(tr("Size: n/a"));
_lblSize->setText(tr("Size: n/a"));
_lblBounds->setText(tr("World Bounds: n/a"));
}
}
......
......@@ -89,10 +89,10 @@ namespace campvis {
*/
void onDataContainerDataAdded(const std::string&, const DataHandle&);
void mousePressEvent(QMouseEvent*)
{
updateInfoWidget();
}
void mousePressEvent(QMouseEvent*)
{
updateInfoWidget();
}
/**
* Size hint for the default window size
......@@ -112,7 +112,7 @@ namespace campvis {
*/
void deinit();
/**
/**
* Updates color of the info widget
*/
void updateColor();
......@@ -155,7 +155,7 @@ namespace campvis {
*/
QString humanizeBytes(size_t numBytes) const;
/**
/**
* Updates _infoWidget
*/
void updateInfoWidget();
......@@ -178,11 +178,11 @@ namespace campvis {
QLabel* _lblTimestamp;
QLabel* _lblSize;
QLabel* _lblBounds;
QWidget* _wdgtColor; ///< The widget use to show the color value and the color in a single window
QHBoxLayout* _wdgtColorLayout; ///< Layout for the following widget
QLabel* _lblColorVal; ///< Color Label Value in text
QWidget* _wdgtColorVal; ///< Widget that shows the color value in color
QPalette* _wdgtColorValPalette; ///< Palette which will be used to colorize the color widget
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
QPushButton* _btnSaveToFile;
static const std::string loggerCat_;
......
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