Developer Documentation
OVMPropertyVisualizerMatrix3x3_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 
45 #define OVM_PROPERTY_VISUALIZER_MAT3X3_CC
46 
47 #include <ACG/Utils/ColorConversion.hh>
48 #include "OVMPropertyVisualizerMatrix3x3.hh"
49 #include "ACG/Scenegraph/DrawModes.hh"
50 #include "EntityPosition.hh"
51 
53 static std::array<Color4f, 3> dim_color {
54  Color4f{1.f,0.f,0.f,1.f},
55  Color4f{0.f,1.f,0.f,1.f},
56  Color4f{0.f,0.f,1.f,1.f}
57 };
58 
59 template <typename MeshT>
61  : OVMPropertyVisualizer<MeshT>(_mesh, objectID, _propertyInfo)
62 {
63  if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
65  PropertyVisualizer::widget = w;
66 
67  BaseObjectData *bod;
68  PluginFunctions::getObject(objectID, bod);
69 
70  boxesNode = new ACG::SceneGraph::BoxesNode(bod->manipulatorNode());
71 
72  lineNode = new ACG::SceneGraph::LineNode(ACG::SceneGraph::LineNode::LineSegmentsMode, bod->manipulatorNode());
73  this->connect(w->lineWidth, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
74  [this](double value) {lineNode->set_line_width(value);});
75 }
76 
77 template <typename MeshT>
79 {
80  lineNode->clear();
81  boxesNode->clear();
83 }
84 
85 template <typename MeshT>
87 {
88  OVMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<ACG::Matrix3x3d>();
89 }
90 
91 template<typename MeshT>
92 template<typename EntityTag, typename Property, typename EntityIterator>
94 visualizeAsCrossesForEntity(Property prop, EntityIterator e_begin, EntityIterator e_end)
95 {
96  using ACG::Vec3d;
97  using ACG::Matrix3x3d;
98 
100  EntityPosition<MeshT> ep{m};
101 
102 
103  double scaleFactor = getMatWidget()->getScaleFactor();
104 
105  for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it) {
106  Matrix3x3d mat = prop[*e_it];
107  Vec3d center_pos = ep(*e_it);
108  for (unsigned char dim = 0; dim < 3; ++dim) {
109  ACG::Vec3d v = mat.getCol(dim) * scaleFactor;
110  lineNode->add_line(center_pos - v, center_pos + v);
111  lineNode->add_color(dim_color[dim]);
112  }
113  }
114 }
115 
116 template<typename MeshT>
117 template<typename EntityTag, typename Property, typename EntityIterator>
119 visualizeAsBoxesForEntity(Property prop, EntityIterator e_begin, EntityIterator e_end)
120 {
121  using ACG::Vec3d;
122  using ACG::Matrix3x3d;
124  EntityPosition<MeshT> ep{m};
125 
126 
127  for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it) {
128  const Matrix3x3d &mat = prop[*e_it];
129  Vec3d center_pos = ep(*e_it);
130  boxesNode->push_back({mat, center_pos});
131  }
132  boxesNode->setScaleFactor(getMatWidget()->getScaleFactor());
133 }
134 
135 template<typename MeshT>
136 template<typename EntityTag, typename EntityIterator>
138 visualizeForEntity(EntityIterator e_begin, EntityIterator e_end)
139 {
140  clear();
142  auto prop = m.template request_property<ACG::Matrix3x3d, EntityTag>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
143  if (!prop)
144  throw VizException("Getting PropHandle from mesh for selected property failed.");
145 
146  if (getMatWidget()->as_crosses->isChecked()) {
147  visualizeAsCrossesForEntity<EntityTag>(prop, e_begin, e_end);
148  } else if (getMatWidget()->as_boxes->isChecked()) {
149  visualizeAsBoxesForEntity<EntityTag>(prop, e_begin, e_end);
150  }
151 }
152 
153 template <typename MeshT>
155 {
157  visualizeForEntity<OpenVolumeMesh::Entity::Cell>(m.cells_begin(), m.cells_end());
158 }
159 
160 template <typename MeshT>
162 {
164  visualizeForEntity<OpenVolumeMesh::Entity::Face>(m.faces_begin(), m.faces_end());
165 }
166 
167 
168 template <typename MeshT>
170 {
172  visualizeForEntity<OpenVolumeMesh::Entity::HalfFace>(m.halffaces_begin(), m.halffaces_end());
173 }
174 
175 template <typename MeshT>
177 {
179  visualizeForEntity<OpenVolumeMesh::Entity::Edge>(m.edges_begin(), m.edges_end());
180 }
181 
182 template <typename MeshT>
184 {
186  visualizeForEntity<OpenVolumeMesh::Entity::HalfEdge>(m.halfedges_begin(), m.halfedges_end());
187 }
188 
189 template <typename MeshT>
191 {
193  visualizeForEntity<OpenVolumeMesh::Entity::Vertex>(m.vertices_begin(), m.vertices_end());
194 }
195 
196 template <typename MeshT>
198 {
199  return OVMPropertyVisualizer<MeshT>::template getPropertyText_<ACG::Matrix3x3d>(index);
200 }
201 
void push_back(const BoxElement &_v)
STL conformance.
Definition: BoxesNode.hh:81
virtual void clear()
Clears a property.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
void clear() override
Clears a property.
QtTranslationManipulatorNode * manipulatorNode()
Cellection of information about a property.
Definition: Utils.hh:109
void duplicateProperty() override
Duplicates a property.
QString getPropertyText(unsigned int index) override
Returns the value of a property in text form.
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121