Developer Documentation
OVMPropertyVisualizerVectorFieldDifferenceT.cc
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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
51 
52 #define OVM_PROPERTY_VISZUALIZTER_VECTOR_FIELD_DIFFERENCE_CC
53 
54 #include "OVMPropertyVisualizerVectorFieldDifference.hh"
55 
56 template <typename MeshT>
57 OVMPropertyVisualizerVectorFieldDifference<MeshT>::OVMPropertyVisualizerVectorFieldDifference(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo1, PropertyInfo _propertyInfo2)
58  : OVMPropertyVisualizer<MeshT>(_mesh, objectID, _propertyInfo1),
59  propertyInfo2(_propertyInfo2)
60 {
61  if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
63  w->paramVectorFieldDifference->setTitle(QString("3D Vector Field Difference Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
64  PropertyVisualizer::widget = w;
65 }
66 
67 namespace OVMPVVFD{ //OVMPVVFD = OpenMeshProeprtyVisualizerVectorFieldDifference
68 
69 template <typename MeshT>
70 float scalarFn_norm_of_diff(const ACG::Vec3d &a, const ACG::Vec3d &b) {
71  return (a - b).norm();
72 }
73 
74 template <typename MeshT>
75 float scalarFn_diff_of_norms(const ACG::Vec3d &a, const ACG::Vec3d &b) {
76  return std::fabs(a.norm() - b.norm());
77 }
78 
79 template <typename MeshT>
80 float scalarFn_4_symm_diff(const ACG::Vec3d &a, const ACG::Vec3d &b) {
81  double alpha = std::acos((a|b) / a.norm() / b.norm());
82  alpha -= std::floor((alpha + M_PI_4) / M_PI_2) * M_PI_2;
83  return std::fabs(alpha);
84 }
85 
86 
87 template<typename Prop1, typename Prop2, float (*ScalarFn)(const typename Prop1::value_type &, const typename Prop2::value_type &)>
88 class ScalarAssigner {
89  public:
90  ScalarAssigner(const Prop1 &prop1, const Prop2 &prop2) :
91  prop1(prop1), prop2(prop2) { }
92 
93  template<typename Handle>
94  float operator() (const Handle &handle) const {
95  return ScalarFn(prop1[handle], prop2[handle]);
96  }
97 
98  protected:
99  const Prop1 &prop1;
100  const Prop2 &prop2;
101 };
102 
103 template<typename MeshT, typename IteratorT, typename PropHandle, float (*ScalarFn)(const ACG::Vec3d &, const ACG::Vec3d &)>
104 void colorElements(int objectID,
105  PropHandle prop1,
106  PropHandle prop2,
107  IteratorT primitivesBegin,
108  IteratorT primitivesEnd)
109 {
110 
111  std::vector<float> scalars;
112  std::transform(primitivesBegin, primitivesEnd, std::back_inserter(scalars),
113  ScalarAssigner<PropHandle, PropHandle, ScalarFn >(prop1, prop2));
114 
115  const float min = *std::min_element(scalars.begin(), scalars.end());
116  const float max = *std::max_element(scalars.begin(), scalars.end());
117 
118  VolumeMeshObject<MeshT>* object;
119  PluginFunctions::getObject(objectID, object);
120 
121  ACG::ColorCoder colCod(min,max,false);
122  for (std::vector<float>::iterator i = scalars.begin(); i != scalars.end(); ++i)
123  object->colors()[*(primitivesBegin++)] = colCod(*i);
124 }
125 
126 }
127 
128 
129 template <typename MeshT>
130 void OVMPropertyVisualizerVectorFieldDifference<MeshT>::visualizeCellProp(bool _setDrawMode)
131 {
132  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
133 
134  OpenVolumeMesh::CellPropertyT<ACG::Vec3d> prop1 = mesh->template request_cell_property<ACG::Vec3d>(PropertyVisualizer::propertyInfo.propName());
135  OpenVolumeMesh::CellPropertyT<ACG::Vec3d> prop2 = mesh->template request_cell_property<ACG::Vec3d>(propertyInfo2.propName());
136 
137  VectorFieldDifferenceWidget* w = static_cast<VectorFieldDifferenceWidget*>(PropertyVisualizer::widget);
138 
139  if (w->vecFieldDiff_4symm_rb->isChecked())
140  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::CellIter, OpenVolumeMesh::CellPropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_4_symm_diff<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->cells_begin(), mesh->cells_end());
141  if (w->vecFieldDiff_diff_norm_rb->isChecked())
142  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::CellIter, OpenVolumeMesh::CellPropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_diff_of_norms<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->cells_begin(), mesh->cells_end());
143  if (w->vecFieldDiff_norm_diff_rb->isChecked())
144  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::CellIter, OpenVolumeMesh::CellPropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_norm_of_diff<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->cells_begin(), mesh->cells_end());
145  if (_setDrawMode)
146  {
147  VolumeMeshObject<MeshT>* object;
148  PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
149  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.cellsColoredPerCell);
150  }
151 }
152 
153 template <typename MeshT>
154 void OVMPropertyVisualizerVectorFieldDifference<MeshT>::visualizeFaceProp(bool _setDrawMode)
155 {
156  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
157 
158  OpenVolumeMesh::FacePropertyT<ACG::Vec3d> prop1 = mesh->template request_face_property<ACG::Vec3d>(PropertyVisualizer::propertyInfo.propName());
159  OpenVolumeMesh::FacePropertyT<ACG::Vec3d> prop2 = mesh->template request_face_property<ACG::Vec3d>(propertyInfo2.propName());
160 
161  VectorFieldDifferenceWidget* w = static_cast<VectorFieldDifferenceWidget*>(PropertyVisualizer::widget);
162 
163  if (w->vecFieldDiff_4symm_rb->isChecked())
164  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::FaceIter, OpenVolumeMesh::FacePropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_4_symm_diff<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->faces_begin(), mesh->faces_end());
165  if (w->vecFieldDiff_diff_norm_rb->isChecked())
166  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::FaceIter, OpenVolumeMesh::FacePropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_diff_of_norms<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->faces_begin(), mesh->faces_end());
167  if (w->vecFieldDiff_norm_diff_rb->isChecked())
168  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::FaceIter, OpenVolumeMesh::FacePropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_norm_of_diff<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->faces_begin(), mesh->faces_end());
169  if (_setDrawMode)
170  {
171  VolumeMeshObject<MeshT>* object;
172  PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
173  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.facesColoredPerFace);
174  }
175 }
176 
177 template <typename MeshT>
178 void OVMPropertyVisualizerVectorFieldDifference<MeshT>::visualizeHalffaceProp(bool _setDrawMode)
179 {
180  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
181 
182  OpenVolumeMesh::HalfFacePropertyT<ACG::Vec3d> prop1 = mesh->template request_halfface_property<ACG::Vec3d>(PropertyVisualizer::propertyInfo.propName());
183  OpenVolumeMesh::HalfFacePropertyT<ACG::Vec3d> prop2 = mesh->template request_halfface_property<ACG::Vec3d>(propertyInfo2.propName());
184 
185  VectorFieldDifferenceWidget* w = static_cast<VectorFieldDifferenceWidget*>(PropertyVisualizer::widget);
186 
187  if (w->vecFieldDiff_4symm_rb->isChecked())
188  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::HalfFaceIter, OpenVolumeMesh::HalfFacePropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_4_symm_diff<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->halffaces_begin(), mesh->halffaces_end());
189  if (w->vecFieldDiff_diff_norm_rb->isChecked())
190  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::HalfFaceIter, OpenVolumeMesh::HalfFacePropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_diff_of_norms<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->halffaces_begin(), mesh->halffaces_end());
191  if (w->vecFieldDiff_norm_diff_rb->isChecked())
192  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::HalfFaceIter, OpenVolumeMesh::HalfFacePropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_norm_of_diff<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->halffaces_begin(), mesh->halffaces_end());
193  if (_setDrawMode)
194  {
195  VolumeMeshObject<MeshT>* object;
196  PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
197  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.halffacesColoredPerHalfface);
198  }
199 }
200 
201 template <typename MeshT>
202 void OVMPropertyVisualizerVectorFieldDifference<MeshT>::visualizeEdgeProp(bool _setDrawMode)
203 {
204  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
205 
206  OpenVolumeMesh::EdgePropertyT<ACG::Vec3d> prop1 = mesh->template request_edge_property<ACG::Vec3d>(PropertyVisualizer::propertyInfo.propName());
207  OpenVolumeMesh::EdgePropertyT<ACG::Vec3d> prop2 = mesh->template request_edge_property<ACG::Vec3d>(propertyInfo2.propName());
208 
209  VectorFieldDifferenceWidget* w = static_cast<VectorFieldDifferenceWidget*>(PropertyVisualizer::widget);
210 
211  if (w->vecFieldDiff_4symm_rb->isChecked())
212  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::EdgeIter, OpenVolumeMesh::EdgePropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_4_symm_diff<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->edges_begin(), mesh->edges_end());
213  if (w->vecFieldDiff_diff_norm_rb->isChecked())
214  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::EdgeIter, OpenVolumeMesh::EdgePropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_diff_of_norms<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->edges_begin(), mesh->edges_end());
215  if (w->vecFieldDiff_norm_diff_rb->isChecked())
216  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::EdgeIter, OpenVolumeMesh::EdgePropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_norm_of_diff<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->edges_begin(), mesh->edges_end());
217  if (_setDrawMode)
218  {
219  VolumeMeshObject<MeshT>* object;
220  PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
221  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.edgesColoredPerEdge);
222  }
223 }
224 
225 template <typename MeshT>
226 void OVMPropertyVisualizerVectorFieldDifference<MeshT>::visualizeHalfedgeProp(bool _setDrawMode)
227 {
228  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
229 
230  OpenVolumeMesh::HalfEdgePropertyT<ACG::Vec3d> prop1 = mesh->template request_halfedge_property<ACG::Vec3d>(PropertyVisualizer::propertyInfo.propName());
231  OpenVolumeMesh::HalfEdgePropertyT<ACG::Vec3d> prop2 = mesh->template request_halfedge_property<ACG::Vec3d>(propertyInfo2.propName());
232 
233  VectorFieldDifferenceWidget* w = static_cast<VectorFieldDifferenceWidget*>(PropertyVisualizer::widget);
234 
235  if (w->vecFieldDiff_4symm_rb->isChecked())
236  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::HalfEdgeIter, OpenVolumeMesh::HalfEdgePropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_4_symm_diff<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->halfedges_begin(), mesh->halfedges_end());
237  if (w->vecFieldDiff_diff_norm_rb->isChecked())
238  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::HalfEdgeIter, OpenVolumeMesh::HalfEdgePropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_diff_of_norms<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->halfedges_begin(), mesh->halfedges_end());
239  if (w->vecFieldDiff_norm_diff_rb->isChecked())
240  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::HalfEdgeIter, OpenVolumeMesh::HalfEdgePropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_norm_of_diff<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->halfedges_begin(), mesh->halfedges_end());
241  if (_setDrawMode)
242  {
243  VolumeMeshObject<MeshT>* object;
244  PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
245  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.halfedgesColoredPerHalfedge);
246  }
247 }
248 
249 template <typename MeshT>
250 void OVMPropertyVisualizerVectorFieldDifference<MeshT>::visualizeVertexProp(bool _setDrawMode)
251 {
252  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
253 
254  OpenVolumeMesh::VertexPropertyT<ACG::Vec3d> prop1 = mesh->template request_vertex_property<ACG::Vec3d>(PropertyVisualizer::propertyInfo.propName());
255  OpenVolumeMesh::VertexPropertyT<ACG::Vec3d> prop2 = mesh->template request_vertex_property<ACG::Vec3d>(propertyInfo2.propName());
256 
257  VectorFieldDifferenceWidget* w = static_cast<VectorFieldDifferenceWidget*>(PropertyVisualizer::widget);
258 
259  if (w->vecFieldDiff_4symm_rb->isChecked())
260  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::VertexIter, OpenVolumeMesh::VertexPropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_4_symm_diff<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->vertices_begin(), mesh->vertices_end());
261  if (w->vecFieldDiff_diff_norm_rb->isChecked())
262  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::VertexIter, OpenVolumeMesh::VertexPropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_diff_of_norms<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->vertices_begin(), mesh->vertices_end());
263  if (w->vecFieldDiff_norm_diff_rb->isChecked())
264  OVMPVVFD::colorElements< MeshT, OpenVolumeMesh::VertexIter, OpenVolumeMesh::VertexPropertyT<ACG::Vec3d>, OVMPVVFD::scalarFn_norm_of_diff<MeshT> >(OVMPropertyVisualizer<MeshT>::mObjectID, prop1, prop2, mesh->vertices_begin(), mesh->vertices_end());
265  if (_setDrawMode)
266  {
267  VolumeMeshObject<MeshT>* object;
268  PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
269  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.verticesColored);
270  }
271 }
272 
273 #endif /* ENABLE_OPENVOLUMEMESH_SUPPORT */
Cellection of information about a property.
Definition: Utils.hh:115
bool getObject(int _identifier, BSplineCurveObject *&_object)
Property classes for the different entity types.
auto norm() const -> decltype(std::sqrt(std::declval< VectorT< S, DIM >>().sqrnorm()))
compute euclidean norm
Definition: Vector11T.hh:408
Class for generating nice colors for doubles.
Definition: ColorCoder.hh:75