Developer Documentation
OVMPropertyVisualizerDoubleT_impl.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 
44 #define OVM_PROPERTY_VISUALIZER_DOUBLE_CC
45 
46 #include "OVMPropertyVisualizerDouble.hh"
47 
48 #include <ACG/Utils/IColorCoder.hh>
49 #include <ACG/Utils/LinearTwoColorCoder.hh>
50 #include <ACG/Utils/ColorConversion.hh>
51 
52 #include <QObject>
53 
54 template <typename MeshT>
56  : OVMPropertyVisualizer<MeshT>(_mesh, objectID, _propertyInfo)
57 {
58  if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
59  DoubleWidget* w = new DoubleWidget();
60  w->paramDouble->setTitle(QString("Double Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
61  PropertyVisualizer::widget = w;
62 
63  this->connect(w->computeHistogramButton, &QPushButton::clicked,
64  [this, w](){this->template showHistogram<double>(w->histogram);});
65 
66 }
67 
68 template <typename MeshT>
69 template <typename PropType, typename HandleIterable>
70 void OVMPropertyVisualizerDouble<MeshT>::visualizeProp(PropType prop, HandleIterable handles)
71 {
72  using Handle = decltype(*begin(handles));
73  if (!prop) return;
74 
75  DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
76 
77  auto cc = doubleWidget->buildColorCoder();
78 
79  bool abs = doubleWidget->doubleAbsolute->isChecked();
80  auto transform_value = [abs](double v) {
81  if (abs) {
82  return std::fabs(v);
83  } else {
84  return v;
85  };
86  };
87 
88  auto get_value = [&](Handle handle)
89  {
90  return transform_value(prop[handle]);
91  };
92 
93  double min, max;
94  if( doubleWidget->doubleFixedRange->isChecked())
95  {
96  min = doubleWidget->doubleFixedRangeMin->value();
97  max = doubleWidget->doubleFixedRangeMax->value();
98  }
99  else
100  {
101  min = std::numeric_limits<double>::infinity();
102  max = -std::numeric_limits<double>::infinity();
103  for (const Handle &h: handles) {
104  auto value = get_value(h);
105  min = std::min(min, value);
106  max = std::max(max, value);
107  }
108  doubleWidget->doubleFixedRangeMin->setValue(min);
109  doubleWidget->doubleFixedRangeMax->setValue(max);
110  }
111 
112  const double range = max - min;
113 
114  VolumeMeshObject<MeshT>* object;
116  for (const Handle &h: handles)
117  {
118  double value = get_value(h);
119  double t = (value - min) / range;
120  object->colors()[h] = cc->color_float4(t);
121  }
122 }
123 CALLS_TO_VISUALIZE_PROP(OVMPropertyVisualizerDouble<MeshT>, typename MeshT, double)
124 
125 template <typename MeshT>
127 {
128  OVMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<double>();
129 }
130 
131 template <typename MeshT>
133 {
134  return OVMPropertyVisualizer<MeshT>::template getPropertyText_<double>(index);
135 }
136 
137 template <typename MeshT>
138 void OVMPropertyVisualizerDouble<MeshT>::setCellPropertyFromText(unsigned int index, QString text)
139 {
141 
142  OpenVolumeMesh::CellPropertyT<double> prop = mesh->template request_cell_property<double>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
143  if ( !prop )
144  {
145  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
146  return;
147  }
148 
149  OpenVolumeMesh::CellHandle ch(index);
150 
151  prop[ch] = this->strToDouble(text);
152 }
153 
154 template <typename MeshT>
155 void OVMPropertyVisualizerDouble<MeshT>::setFacePropertyFromText(unsigned int index, QString text)
156 {
158 
159  OpenVolumeMesh::FacePropertyT<double> prop = mesh->template request_face_property<double>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
160  if ( !prop )
161  {
162  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
163  return;
164  }
165 
166  OpenVolumeMesh::FaceHandle fh(index);
167 
168  prop[fh] = this->strToDouble(text);
169 }
170 
171 template <typename MeshT>
172 void OVMPropertyVisualizerDouble<MeshT>::setHalffacePropertyFromText(unsigned int index, QString text)
173 {
175 
176  OpenVolumeMesh::HalfFacePropertyT<double> prop = mesh->template request_halfface_property<double>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
177  if ( !prop )
178  {
179  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
180  return;
181  }
182 
184 
185  prop[hfh] = this->strToDouble(text);
186 }
187 
188 template <typename MeshT>
189 void OVMPropertyVisualizerDouble<MeshT>::setEdgePropertyFromText(unsigned int index, QString text)
190 {
192 
193  OpenVolumeMesh::EdgePropertyT<double> prop = mesh->template request_edge_property<double>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
194  if ( !prop )
195  {
196  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
197  return;
198  }
199 
200  OpenVolumeMesh::EdgeHandle eh(index);
201 
202  prop[eh] = this->strToDouble(text);
203 }
204 
205 template <typename MeshT>
206 void OVMPropertyVisualizerDouble<MeshT>::setHalfedgePropertyFromText(unsigned int index, QString text)
207 {
209 
210  OpenVolumeMesh::HalfEdgePropertyT<double> prop = mesh->template request_halfedge_property<double>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
211  if ( !prop )
212  {
213  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
214  return;
215  }
216 
218 
219  prop[heh] = this->strToDouble(text);
220 }
221 
222 template <typename MeshT>
223 void OVMPropertyVisualizerDouble<MeshT>::setVertexPropertyFromText(unsigned int index, QString text)
224 {
226 
227  OpenVolumeMesh::VertexPropertyT<double> prop = mesh->template request_vertex_property<double>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
228  if ( !prop )
229  {
230  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
231  return;
232  }
233 
235 
236  prop[vh] = this->strToDouble(text);
237 }
238 
239 template <typename MeshT>
240 std::unique_ptr<ACG::IColorCoder> OVMPropertyVisualizerDouble<MeshT>::buildColorCoder()
241 {
242  DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
243  return doubleWidget->buildColorCoder();
244 }
245 
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
std::unique_ptr< ACG::IColorCoder > buildColorCoder()
Builds a color coder according to UI settings.
Definition: DoubleWidget.cc:58
Cellection of information about a property.
Definition: Utils.hh:109
QString getPropertyText(unsigned int index) override
Returns the value of a property in text form.
void duplicateProperty() override
Duplicates a property.