/*===========================================================================*\ * * * 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_DOUBLE_CC #include "OVMPropertyVisualizerDouble.hh" #include #include #include #include template OVMPropertyVisualizerDouble::OVMPropertyVisualizerDouble(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo) : OVMPropertyVisualizer(_mesh, objectID, _propertyInfo) { if (PropertyVisualizer::widget) delete PropertyVisualizer::widget; DoubleWidget* w = new DoubleWidget(); w->paramDouble->setTitle(QString("Double Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str())); PropertyVisualizer::widget = w; this->connect(w->computeHistogramButton, &QPushButton::clicked, [this, w](){this->template showHistogram(w->histogram);}); } template template void OVMPropertyVisualizerDouble::visualizeProp(PropType prop, HandleIterable handles) { using Handle = decltype(*begin(handles)); if (!prop) return; DoubleWidget* doubleWidget = static_cast(PropertyVisualizer::widget); auto cc = doubleWidget->buildColorCoder(); bool abs = doubleWidget->doubleAbsolute->isChecked(); auto transform_value = [abs](double v) { if (abs) { return std::fabs(v); } else { return v; }; }; auto get_value = [&](Handle handle) { return transform_value(prop[handle]); }; double min, max; if( doubleWidget->doubleFixedRange->isChecked()) { min = doubleWidget->doubleFixedRangeMin->value(); max = doubleWidget->doubleFixedRangeMax->value(); } else { min = std::numeric_limits::infinity(); max = -std::numeric_limits::infinity(); for (const Handle &h: handles) { auto value = get_value(h); min = std::min(min, value); max = std::max(max, value); } doubleWidget->doubleFixedRangeMin->setValue(min); doubleWidget->doubleFixedRangeMax->setValue(max); } const double range = max - min; VolumeMeshObject* object; PluginFunctions::getObject(OVMPropertyVisualizer::mObjectID, object); for (const Handle &h: handles) { double value = get_value(h); double t = (value - min) / range; object->colors()[h] = cc->color_float4(t); } } CALLS_TO_VISUALIZE_PROP(OVMPropertyVisualizerDouble, typename MeshT, double) template void OVMPropertyVisualizerDouble::duplicateProperty() { OVMPropertyVisualizer::template duplicateProperty_stage1(); } template QString OVMPropertyVisualizerDouble::getPropertyText(unsigned int index) { return OVMPropertyVisualizer::template getPropertyText_(index); } template void OVMPropertyVisualizerDouble::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->strToDouble(text); } template void OVMPropertyVisualizerDouble::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->strToDouble(text); } template void OVMPropertyVisualizerDouble::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->strToDouble(text); } template void OVMPropertyVisualizerDouble::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->strToDouble(text); } template void OVMPropertyVisualizerDouble::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->strToDouble(text); } template void OVMPropertyVisualizerDouble::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->strToDouble(text); } template std::unique_ptr OVMPropertyVisualizerDouble::buildColorCoder() { DoubleWidget* doubleWidget = static_cast(PropertyVisualizer::widget); return doubleWidget->buildColorCoder(); }