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 EntityIterator>
70 void OVMPropertyVisualizerDouble<MeshT>::visualizeProp(PropType prop, EntityIterator e_begin, EntityIterator e_end)
71 {
72  if (!prop) return;
73 
74  DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
75  ACG::Vec4f colorMin = ACG::to_Vec4f(doubleWidget->doubleMin->color());
76 
77  auto cc = doubleWidget->buildColorCoder();
78  double min, max;
79 
80  if ( doubleWidget->doubleAbsolute->isChecked() ){
81  min = FLT_MAX;
82  max = 0.0;
83  } else {
84  min = FLT_MAX;
85  max = FLT_MIN;
86  }
87 
88  for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it){
89  double value = prop[*e_it];
90  if ( doubleWidget->doubleAbsolute->isChecked() ){
91  min = std::min( min, fabs(value));
92  max = std::max( max, fabs(value));
93  } else {
94  min = std::min( min, value);
95  max = std::max( max, value);
96  }
97  }
98 
99  // fixed range?
100  if( doubleWidget->doubleFixedRange->isChecked())
101  {
102  min = doubleWidget->doubleFixedRangeMin->value();
103  max = doubleWidget->doubleFixedRangeMax->value();
104  }
105  else
106  {
107  doubleWidget->doubleFixedRangeMin->setValue(min);
108  doubleWidget->doubleFixedRangeMax->setValue(max);
109  }
110 
111  const double range = max - min;
112 
113  VolumeMeshObject<MeshT>* object;
115  for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it){
116 
117  if (range == 0.0)
118  object->colors()[*e_it] = colorMin;
119  else {
120 
121  double value = prop[*e_it];
122 
123  // absolut value?
124  if ( doubleWidget->doubleAbsolute->isChecked())
125  value = fabs(value);
126 
127  double t = (value-min)/range;
128  object->colors()[*e_it] = cc->color_float4(t);
129  }
130  }
131 }
132 CALLS_TO_VISUALIZE_PROP(OVMPropertyVisualizerDouble<MeshT>, typename MeshT, double)
133 
134 template <typename MeshT>
136 {
137  OVMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<double>();
138 }
139 
140 template <typename MeshT>
142 {
143  return OVMPropertyVisualizer<MeshT>::template getPropertyText_<double>(index);
144 }
145 
146 template <typename MeshT>
147 void OVMPropertyVisualizerDouble<MeshT>::setCellPropertyFromText(unsigned int index, QString text)
148 {
150 
151  OpenVolumeMesh::CellPropertyT<double> prop = mesh->template request_cell_property<double>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
152  if ( !prop )
153  {
154  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
155  return;
156  }
157 
158  OpenVolumeMesh::CellHandle ch(index);
159 
160  prop[ch] = this->strToDouble(text);
161 }
162 
163 template <typename MeshT>
164 void OVMPropertyVisualizerDouble<MeshT>::setFacePropertyFromText(unsigned int index, QString text)
165 {
167 
168  OpenVolumeMesh::FacePropertyT<double> prop = mesh->template request_face_property<double>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
169  if ( !prop )
170  {
171  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
172  return;
173  }
174 
175  OpenVolumeMesh::FaceHandle fh(index);
176 
177  prop[fh] = this->strToDouble(text);
178 }
179 
180 template <typename MeshT>
181 void OVMPropertyVisualizerDouble<MeshT>::setHalffacePropertyFromText(unsigned int index, QString text)
182 {
184 
185  OpenVolumeMesh::HalfFacePropertyT<double> prop = mesh->template request_halfface_property<double>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
186  if ( !prop )
187  {
188  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
189  return;
190  }
191 
193 
194  prop[hfh] = this->strToDouble(text);
195 }
196 
197 template <typename MeshT>
198 void OVMPropertyVisualizerDouble<MeshT>::setEdgePropertyFromText(unsigned int index, QString text)
199 {
201 
202  OpenVolumeMesh::EdgePropertyT<double> prop = mesh->template request_edge_property<double>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
203  if ( !prop )
204  {
205  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
206  return;
207  }
208 
209  OpenVolumeMesh::EdgeHandle eh(index);
210 
211  prop[eh] = this->strToDouble(text);
212 }
213 
214 template <typename MeshT>
215 void OVMPropertyVisualizerDouble<MeshT>::setHalfedgePropertyFromText(unsigned int index, QString text)
216 {
218 
219  OpenVolumeMesh::HalfEdgePropertyT<double> prop = mesh->template request_halfedge_property<double>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
220  if ( !prop )
221  {
222  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
223  return;
224  }
225 
227 
228  prop[heh] = this->strToDouble(text);
229 }
230 
231 template <typename MeshT>
232 void OVMPropertyVisualizerDouble<MeshT>::setVertexPropertyFromText(unsigned int index, QString text)
233 {
235 
236  OpenVolumeMesh::VertexPropertyT<double> prop = mesh->template request_vertex_property<double>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
237  if ( !prop )
238  {
239  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
240  return;
241  }
242 
244 
245  prop[vh] = this->strToDouble(text);
246 }
247 
248 template <typename MeshT>
249 std::unique_ptr<ACG::IColorCoder> OVMPropertyVisualizerDouble<MeshT>::buildColorCoder()
250 {
251  DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
252  return doubleWidget->buildColorCoder();
253 }
254 
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.