50 #define OM_PROPERTY_VISUALIZER_VECTOR_CC 52 #include "OMPropertyVisualizerVector.hh" 54 template <
typename MeshT>
58 if (PropertyVisualizer::widget)
delete PropertyVisualizer::widget;
60 w->paramVector->setTitle(QString(
"3D Vector Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
61 PropertyVisualizer::widget = w;
65 if (!_propertyInfo.isFaceProp())
67 w->vectors_edges_rb->hide();
72 template <
typename MeshT>
79 template <
typename MeshT>
88 template<
typename PROPTYPE,
typename MeshT,
typename ENTITY_IT,
typename PROPINFO_TYPE>
89 void visualizeVectorAsColorForEntity(MeshT *mesh,
const ENTITY_IT e_begin,
const ENTITY_IT e_end,
90 const PROPINFO_TYPE &propinfo) {
92 if (!mesh->get_property_handle(prop, propinfo.propName()))
93 throw VizException(
"Getting PropHandle from mesh for selected property failed.");
94 for (ENTITY_IT e_it = e_begin; e_it != e_end; ++e_it) {
95 typename MeshT::Point v = mesh->property(prop, *e_it).normalized() * .5 +
typename MeshT::Point(.5, .5, .5);
96 mesh->set_color(*e_it,
typename MeshT::Color(v[0], v[1], v[2], 1.0));
100 template<
typename PROPTYPE,
typename MeshT,
typename ENTITY_IT,
typename PROPINFO_TYPE>
101 void visualizeVectorLengthAsColorForEntity(
102 MeshT *mesh,
const ENTITY_IT e_begin,
const ENTITY_IT e_end,
103 const PROPINFO_TYPE &propinfo) {
105 if (!mesh->get_property_handle(prop, propinfo.propName()))
106 throw VizException(
"Getting PropHandle from mesh for selected " 109 double min = std::numeric_limits<double>::infinity();
110 double max = -std::numeric_limits<double>::infinity();
112 for (ENTITY_IT e_it = e_begin; e_it != e_end; ++e_it) {
113 const double val = mesh->property(prop, *e_it).norm();
114 min = std::min(min, val);
115 max = std::max(max, val);
120 for (ENTITY_IT e_it = e_begin; e_it != e_end; ++e_it) {
121 mesh->set_color(*e_it, color_coder(mesh->property(prop, *e_it).norm()));
127 template <
typename MeshT>
131 if (w->vectors_edges_rb->isChecked()) {
132 visualizeFacePropOnEdges();
133 }
else if (w->vectors_colors_rb->isChecked() ||
134 w->vectors_length_color_rb->isChecked()) {
138 if (w->vectors_colors_rb->isChecked()) {
139 visualizeVectorAsColorForEntity<OpenMesh::FPropHandleT<typename MeshT::Point> >(
141 OMPropertyVisualizer<MeshT>::mesh->faces_begin(),
142 OMPropertyVisualizer<MeshT>::mesh->faces_end(),
143 PropertyVisualizer::propertyInfo);
145 visualizeVectorLengthAsColorForEntity<OpenMesh::FPropHandleT<typename MeshT::Point> >(
147 OMPropertyVisualizer<MeshT>::mesh->faces_begin(),
148 OMPropertyVisualizer<MeshT>::mesh->faces_end(),
149 PropertyVisualizer::propertyInfo);
154 else visualizeFacePropAsStrokes();
157 template <
typename MeshT>
161 if (w->vectors_colors_rb->isChecked() ||
162 w->vectors_length_color_rb->isChecked()) {
166 if ( !mesh->has_edge_colors() )
167 mesh->request_edge_colors();
168 if (w->vectors_colors_rb->isChecked()) {
169 visualizeVectorAsColorForEntity<
174 PropertyVisualizer::propertyInfo);
176 visualizeVectorLengthAsColorForEntity<
181 PropertyVisualizer::propertyInfo);
186 else visualizeEdgePropAsStrokes();
189 template <
typename MeshT>
193 if (w->vectors_colors_rb->isChecked() ||
194 w->vectors_length_color_rb->isChecked()) {
198 if ( ! mesh->has_halfedge_colors() )
199 mesh->request_halfedge_colors();
201 if (w->vectors_colors_rb->isChecked()) {
202 visualizeVectorAsColorForEntity<
205 mesh->halfedges_begin(),
206 mesh->halfedges_end(),
207 PropertyVisualizer::propertyInfo);
209 visualizeVectorLengthAsColorForEntity<
212 mesh->halfedges_begin(),
213 mesh->halfedges_end(),
214 PropertyVisualizer::propertyInfo);
221 else visualizeHalfedgePropAsStrokes();
224 template <
typename MeshT>
228 if (w->vectors_colors_rb->isChecked() ||
229 w->vectors_length_color_rb->isChecked()) {
233 if (w->vectors_colors_rb->isChecked()) {
234 visualizeVectorAsColorForEntity<
237 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
238 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
239 PropertyVisualizer::propertyInfo);
241 visualizeVectorLengthAsColorForEntity<
244 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
245 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
246 PropertyVisualizer::propertyInfo);
252 else visualizeVertexPropAsStrokes();
255 template <
typename MeshT>
262 const double thresh_1 = w->vectors_edges_alpha->value();
263 const double thresh_2 = std::min(thresh_1, w->vectors_edges_alpha->value());
266 if (!_mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName()))
267 throw VizException(
"Getting PropHandle from mesh for selected property failed.");
269 if (!_mesh->has_edge_colors())
270 _mesh->request_edge_colors();
271 const ACG::Vec4f cold(0, 0, 0, 1.0), hot(0, 1, 0, 1.0), degen(1, 1, 0, 1.0);
272 for (
typename MeshT::EdgeIter e_it = _mesh->edges_begin(), e_end = _mesh->edges_end();
273 e_it != e_end; ++e_it) {
274 typename MeshT::Point p1 = _mesh->property(prop, _mesh->face_handle(_mesh->halfedge_handle(*e_it, 0)));
275 typename MeshT::Point p2 = _mesh->property(prop, _mesh->face_handle(_mesh->halfedge_handle(*e_it, 1)));
279 const char degenerate = ((p1.sqrnorm() < 1e-6) ? 1 : 0) | ((p2.sqrnorm() < 1e-6) ? 2 : 0);
280 if (degenerate == 3) {
282 }
else if (degenerate == 0) {
284 const double alpha = std::min(1.0, std::abs(p1 | p2));
285 if (alpha < thresh_1)
287 else if (alpha > thresh_2)
290 const double beta = (alpha - thresh_1) / (thresh_2 - thresh_1);
291 color = cold * beta + hot * (1.0 - beta);
296 _mesh->set_color(*e_it, color);
301 template <
typename MeshT>
317 typename MeshT::Point center(0.0, 0.0, 0.0);
329 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
332 if(vectorWidget->scale->isChecked())
333 v *= vectorWidget->scaleBox->value();
335 lineNode->add_line( center, (center+v) );
336 lineNode->add_color(color);
340 template <
typename MeshT>
365 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
368 if(vectorWidget->scale->isChecked())
369 v *= vectorWidget->scaleBox->value();
371 lineNode->add_line( v1, (v1+v) );
372 lineNode->add_color(color);
376 template <
typename MeshT>
399 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
402 if(vectorWidget->scale->isChecked())
403 v *= vectorWidget->scaleBox->value();
405 lineNode->add_line( v1, (v1+v) );
406 lineNode->add_color(color);
410 template <
typename MeshT>
430 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
433 if(vectorWidget->scale->isChecked())
434 v *= vectorWidget->scaleBox->value();
436 lineNode->add_line( v1, (v1+v) );
437 lineNode->add_color(color);
441 template <
typename MeshT>
447 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
448 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
451 typename MeshT::FaceHandle fh = mesh->face_handle(index);
453 mesh->property(prop, fh) = this->strToVec3d(text);
456 template <
typename MeshT>
462 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
463 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
466 typename MeshT::EdgeHandle eh = mesh->edge_handle(index);
468 mesh->property(prop, eh) = this->strToVec3d(text);
471 template <
typename MeshT>
477 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
478 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
481 typename MeshT::HalfedgeHandle heh = mesh->halfedge_handle(index);
483 mesh->property(prop, heh) = this->strToVec3d(text);
486 template <
typename MeshT>
492 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
493 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
496 typename MeshT::VertexHandle vh = mesh->vertex_handle(index);
498 mesh->property(prop, vh) = this->strToVec3d(text);
502 template<
typename MeshT>
508 template<
typename MeshT>
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Cellection of information about a property.
DrawMode HALFEDGES_COLORED
draw halfedges with colors (without shading)
virtual QString getPropertyText(unsigned int index)
Returns the value of a property in text form.
ACG::SceneGraph::BaseNode * getRootNode()
Get the root node for data objects.
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
DrawMode EDGES_COLORED
draw edges with colors (without shading)
Add colors to mesh item (vertices/faces/edges)
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
DrawMode SOLID_POINTS_COLORED
draw colored, but not lighted faces using interpolated vertex colors
virtual void clear()
Clears the property.
virtual void duplicateProperty()
Duplicates the property.
virtual void clear()
Clears the property.
Class for generating nice colors for doubles.
virtual void removeProperty()
Removes the property.
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .