/*===========================================================================*\ * * * OpenFlipper * * Copyright (c) 2001-2015, RWTH-Aachen University * * Department of Computer Graphics and Multimedia * * All rights reserved. * * www.openflipper.org * * * *---------------------------------------------------------------------------* * This file is part of OpenFlipper. * *---------------------------------------------------------------------------* * * * Redistribution and use in source and binary forms, with or without * * modification, are permitted provided that the following conditions * * are met: * * * * 1. Redistributions of source code must retain the above copyright notice, * * this list of conditions and the following disclaimer. * * * * 2. Redistributions in binary form must reproduce the above copyright * * notice, this list of conditions and the following disclaimer in the * * documentation and/or other materials provided with the distribution. * * * * 3. Neither the name of the copyright holder nor the names of its * * contributors may be used to endorse or promote products derived from * * this software without specific prior written permission. * * * * 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. * * * \*===========================================================================*/ #define OVM_PROPERTY_VISUALIZER_ITEGER_CC #include "OVMPropertyVisualizerInteger.hh" #include #include template OVMPropertyVisualizerInteger::OVMPropertyVisualizerInteger(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo, bool isUnsigned) : OVMPropertyVisualizer(_mesh, objectID, _propertyInfo) { if (PropertyVisualizer::widget) delete PropertyVisualizer::widget; IntegerWidget* w = new IntegerWidget(); w->paramInt->setTitle(QString("Integer Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str())); PropertyVisualizer::widget = w; if (isUnsigned) { w->intAbsolute->setChecked(false); //because we already have unsigned integers wo don't have to calculate their absolute value w->intAbsolute->setCheckable(false); } mNumericLimitMax = std::numeric_limits::max(); mNumericLimitMin = std::numeric_limits::min(); this->connect(w->computeHistogramButton, &QPushButton::clicked, [this, w](){this->template showHistogram(w->histogram);}); } template template void OVMPropertyVisualizerInteger::visualizeProp(PropType prop, HandleIterable handles) { if (!prop) return; IntegerWidget* integerWidget = static_cast(PropertyVisualizer::widget); ACG::Vec4f colorMin = ACG::to_Vec4f(integerWidget->intMin->color()); std::map< int, ACG::Vec4f> randomColor; if ( integerWidget->intRandom->isChecked() && integerWidget->intMapBlack->isChecked() ) randomColor[ integerWidget->intMapBlackValue->value() ] = ACG::Vec4f(0.0, 0.0, 0.0, 0.0); T min = mNumericLimitMax; T max = mNumericLimitMin; for (const auto &h: handles) { T value = prop[h]; min = std::min( min, value); max = std::max( max, value); } if( integerWidget->intFixedRange->isChecked()) { min = integerWidget->intFixedRangeMin->value(); max = integerWidget->intFixedRangeMax->value(); } else { integerWidget->intFixedRangeMin->setValue(min); integerWidget->intFixedRangeMax->setValue(max); } auto cc = integerWidget->buildColorCoder(); unsigned int range = max - min; VolumeMeshObject* object; PluginFunctions::getObject(OVMPropertyVisualizer::mObjectID, object); for (const auto &h: handles) { if (range == 0) object->colors()[h] = colorMin; else { T value = prop[h]; double pos = (value - min) / (double) range; ACG::Vec4f color; if ( integerWidget->intRandom->isChecked() ) { // TODO: build appropriate subclass of IColorCoder for this purpose if ( randomColor.find( value ) == randomColor.end() ) { color = mColorGenerator.generateNextColor(); color[3] = 1.0; randomColor[ value ] = color; } color = randomColor[ value ]; } else { color = cc->color_float4(pos); } object->colors()[h] = color; } } } #define KOMMA , CALLS_TO_VISUALIZE_PROP(OVMPropertyVisualizerInteger, typename MeshT KOMMA typename T, T) #undef KOMMA template void OVMPropertyVisualizerInteger::duplicateProperty() { OVMPropertyVisualizer::template duplicateProperty_stage1(); } template QString OVMPropertyVisualizerInteger::getPropertyText(unsigned int index) { return OVMPropertyVisualizer::template getPropertyText_(index); } template void OVMPropertyVisualizerInteger::setCellPropertyFromText(unsigned int index, QString text) { MeshT* mesh = OVMPropertyVisualizer::mesh; OpenVolumeMesh::CellPropertyT prop = mesh->template request_cell_property(OVMPropertyVisualizer::propertyInfo.propName()); if ( !prop ) { emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str())); return; } OpenVolumeMesh::CellHandle ch(index); prop[ch] = this->strToInt(text); } template void OVMPropertyVisualizerInteger::setFacePropertyFromText(unsigned int index, QString text) { MeshT* mesh = OVMPropertyVisualizer::mesh; OpenVolumeMesh::FacePropertyT prop = mesh->template request_face_property(OVMPropertyVisualizer::propertyInfo.propName()); if ( !prop ) { emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str())); return; } OpenVolumeMesh::FaceHandle fh(index); prop[fh] = this->strToInt(text); } template void OVMPropertyVisualizerInteger::setHalffacePropertyFromText(unsigned int index, QString text) { MeshT* mesh = OVMPropertyVisualizer::mesh; OpenVolumeMesh::HalfFacePropertyT prop = mesh->template request_halfface_property(OVMPropertyVisualizer::propertyInfo.propName()); if ( !prop ) { emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str())); return; } OpenVolumeMesh::HalfFaceHandle hfh(index); prop[hfh] = this->strToInt(text); } template void OVMPropertyVisualizerInteger::setEdgePropertyFromText(unsigned int index, QString text) { MeshT* mesh = OVMPropertyVisualizer::mesh; OpenVolumeMesh::EdgePropertyT prop = mesh->template request_edge_property(OVMPropertyVisualizer::propertyInfo.propName()); if ( !prop ) { emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str())); return; } OpenVolumeMesh::EdgeHandle eh(index); prop[eh] = this->strToInt(text); } template void OVMPropertyVisualizerInteger::setHalfedgePropertyFromText(unsigned int index, QString text) { MeshT* mesh = OVMPropertyVisualizer::mesh; OpenVolumeMesh::HalfEdgePropertyT prop = mesh->template request_halfedge_property(OVMPropertyVisualizer::propertyInfo.propName()); if ( !prop ) { emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str())); return; } OpenVolumeMesh::HalfEdgeHandle heh(index); prop[heh] = this->strToInt(text); } template void OVMPropertyVisualizerInteger::setVertexPropertyFromText(unsigned int index, QString text) { MeshT* mesh = OVMPropertyVisualizer::mesh; OpenVolumeMesh::VertexPropertyT prop = mesh->template request_vertex_property(OVMPropertyVisualizer::propertyInfo.propName()); if ( !prop ) { emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str())); return; } OpenVolumeMesh::VertexHandle vh(index); prop[vh] = this->strToInt(text); } template std::unique_ptr OVMPropertyVisualizerInteger::buildColorCoder() { IntegerWidget* integerWidget = static_cast(PropertyVisualizer::widget); return integerWidget->buildColorCoder(); }