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
52 using Color4f = ACG::SceneGraph::LineNode::Color4f;
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>
60 OVMPropertyVisualizerMatrix3x3<MeshT>::OVMPropertyVisualizerMatrix3x3(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo)
61 : OVMPropertyVisualizer<MeshT>(_mesh, objectID, _propertyInfo)
62 {
63 if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
64 Matrix3x3Widget* w = new Matrix3x3Widget();
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>
78 void OVMPropertyVisualizerMatrix3x3<MeshT>::clear()
79 {
80 lineNode->clear();
81 boxesNode->clear();
82 OVMPropertyVisualizer<MeshT>::clear();
83 }
84
85 template <typename MeshT>
86 void OVMPropertyVisualizerMatrix3x3<MeshT>::duplicateProperty()
87 {
88 OVMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<ACG::Matrix3x3d>();
89 }
90
91 template<typename MeshT>
92 template<typename EntityTag, typename Property, typename EntityIterator>
93 void OVMPropertyVisualizerMatrix3x3<MeshT>::
94 visualizeAsCrossesForEntity(Property prop, EntityIterator e_begin, EntityIterator e_end)
95 {
96 using ACG::Vec3d;
97 using ACG::Matrix3x3d;
98
99 MeshT &m = *OVMPropertyVisualizer<MeshT>::mesh;
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>
118 void OVMPropertyVisualizerMatrix3x3<MeshT>::
119 visualizeAsBoxesForEntity(Property prop, EntityIterator e_begin, EntityIterator e_end)
120 {
121 using ACG::Vec3d;
122 using ACG::Matrix3x3d;
123 MeshT &m = *OVMPropertyVisualizer<MeshT>::mesh;
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>
137 void OVMPropertyVisualizerMatrix3x3<MeshT>::
138 visualizeForEntity(EntityIterator e_begin, EntityIterator e_end)
139 {
140 clear();
141 MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
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>
154 void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeCellProp(bool /*_setDrawMode*/)
155 {
156 MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
157 visualizeForEntity<OpenVolumeMesh::Entity::Cell>(m.cells_begin(), m.cells_end());
158 }
159
160 template <typename MeshT>
161 void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeFaceProp(bool /*_setDrawMode*/)
162 {
163 MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
164 visualizeForEntity<OpenVolumeMesh::Entity::Face>(m.faces_begin(), m.faces_end());
165 }
166
167
168 template <typename MeshT>
169 void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeHalffaceProp(bool /*_setDrawMode*/)
170 {
171 MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
172 visualizeForEntity<OpenVolumeMesh::Entity::HalfFace>(m.halffaces_begin(), m.halffaces_end());
173 }
174
175 template <typename MeshT>
176 void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeEdgeProp(bool /*_setDrawMode*/)
177 {
178 MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
179 visualizeForEntity<OpenVolumeMesh::Entity::Edge>(m.edges_begin(), m.edges_end());
180 }
181
182 template <typename MeshT>
183 void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeHalfedgeProp(bool /*_setDrawMode*/)
184 {
185 MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
186 visualizeForEntity<OpenVolumeMesh::Entity::HalfEdge>(m.halfedges_begin(), m.halfedges_end());
187 }
188
189 template <typename MeshT>
190 void OVMPropertyVisualizerMatrix3x3<MeshT>::visualizeVertexProp(bool /*_setDrawMode*/)
191 {
192 MeshT &m = * OVMPropertyVisualizer<MeshT>::mesh;
193 visualizeForEntity<OpenVolumeMesh::Entity::Vertex>(m.vertices_begin(), m.vertices_end());
194 }
195
196 template <typename MeshT>
197 QString OVMPropertyVisualizerMatrix3x3<MeshT>::getPropertyText(unsigned int index)
198 {
199 return OVMPropertyVisualizer<MeshT>::template getPropertyText_<ACG::Matrix3x3d>(index);
200 }
201
ACG::SceneGraph::BoxesNode::push_back
void push_back(const BoxElement &_v)
STL conformance.
Definition: BoxesNode.hh:81
OVMPropertyVisualizer::clear
virtual void clear()
Clears a property.
Definition: OVMPropertyVisualizerT_impl.hh:347
OVMPropertyVisualizerMatrix3x3
Definition: OVMPropertyVisualizerMatrix3x3.hh:61
ACG::Matrix3x3T< double >
PluginFunctions::getObject
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Definition: PluginFunctions.cc:296
OVMPropertyVisualizer
Definition: OVMPropertyVisualizer.hh:61
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::SceneGraph::LineNode
Definition: LineNode.hh:84
ACG::SceneGraph::BoxesNode
Definition: BoxesNode.hh:60
OVMPropertyVisualizerMatrix3x3::clear
void clear() override
Clears a property.
Definition: OVMPropertyVisualizerMatrix3x3_impl.hh:78
BaseObjectData::manipulatorNode
QtTranslationManipulatorNode * manipulatorNode()
Definition: BaseObjectData.cc:255
PropertyInfo
Cellection of information about a property.
Definition: Utils.hh:109
BaseObjectData
Definition: BaseObjectData.hh:102
OVMPropertyVisualizerMatrix3x3::duplicateProperty
void duplicateProperty() override
Duplicates a property.
Definition: OVMPropertyVisualizerMatrix3x3_impl.hh:86
VizException
Definition: PropertyVisualizer.hh:63
OVMPropertyVisualizerMatrix3x3::getPropertyText
QString getPropertyText(unsigned int index) override
Returns the value of a property in text form.
Definition: OVMPropertyVisualizerMatrix3x3_impl.hh:197
EntityPosition
Definition: EntityPosition.hh:8
Matrix3x3Widget
Definition: Matrix3x3Widget.hh:51
ACG::Vec3d
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121