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> >(
146 OMPropertyVisualizer<MeshT>::mesh,
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()) {
163 if ( !OMPropertyVisualizer<MeshT>::mesh->has_edge_colors() )
164 OMPropertyVisualizer<MeshT>::mesh->request_edge_colors();
165 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
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()) {
195 if ( !OMPropertyVisualizer<MeshT>::mesh->has_halfedge_colors() )
196 OMPropertyVisualizer<MeshT>::mesh->request_halfedge_colors();
197 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
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()) {
230 if ( !OMPropertyVisualizer<MeshT>::mesh->has_vertex_colors() )
231 OMPropertyVisualizer<MeshT>::mesh->request_vertex_colors();
233 if (w->vectors_colors_rb->isChecked()) {
234 visualizeVectorAsColorForEntity<
236 OMPropertyVisualizer<MeshT>::mesh,
237 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
238 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
239 PropertyVisualizer::propertyInfo);
241 visualizeVectorLengthAsColorForEntity<
243 OMPropertyVisualizer<MeshT>::mesh,
244 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
245 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
246 PropertyVisualizer::propertyInfo);
252 else visualizeVertexPropAsStrokes();
255 template <
typename MeshT>
259 MeshT* _mesh = OMPropertyVisualizer<MeshT>::mesh;
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) {
283 p1.normalize(); p2.normalize();
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>
315 for (
typename MeshT::FaceIter f_it = OMPropertyVisualizer<MeshT>::mesh->faces_begin() ; f_it != OMPropertyVisualizer<MeshT>::mesh->faces_end() ; ++f_it){
317 typename MeshT::Point center(0.0, 0.0, 0.0);
320 for (
typename MeshT::FaceVertexIter fv_it(*(OMPropertyVisualizer<MeshT>::mesh),*f_it); fv_it.is_valid(); ++fv_it){
322 center += OMPropertyVisualizer<MeshT>::mesh->point(*fv_it);
327 typename MeshT::Point v = (OMPropertyVisualizer<MeshT>::mesh->property(prop, *f_it));
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>
355 for (
typename MeshT::EdgeIter e_it = OMPropertyVisualizer<MeshT>::mesh->edges_begin() ; e_it != OMPropertyVisualizer<MeshT>::mesh->edges_end() ; ++e_it){
357 typename MeshT::HalfedgeHandle hh = OMPropertyVisualizer<MeshT>::mesh->halfedge_handle( *e_it, 0 );
359 typename MeshT::VertexHandle vh0 = OMPropertyVisualizer<MeshT>::mesh->from_vertex_handle( hh );
360 typename MeshT::VertexHandle vh1 = OMPropertyVisualizer<MeshT>::mesh->to_vertex_handle( hh );
362 typename MeshT::Point v1 = OMPropertyVisualizer<MeshT>::mesh->point(vh0) + 0.5 * (OMPropertyVisualizer<MeshT>::mesh->point(vh1) - OMPropertyVisualizer<MeshT>::mesh->point(vh0));
363 typename MeshT::Point v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *e_it);
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>
391 for (
typename MeshT::HalfedgeIter he_it = OMPropertyVisualizer<MeshT>::mesh->halfedges_begin() ; he_it != OMPropertyVisualizer<MeshT>::mesh->halfedges_end() ; ++he_it){
393 typename MeshT::VertexHandle vh0 = OMPropertyVisualizer<MeshT>::mesh->from_vertex_handle( *he_it );
394 typename MeshT::VertexHandle vh1 = OMPropertyVisualizer<MeshT>::mesh->to_vertex_handle( *he_it );
396 typename MeshT::Point v1 = OMPropertyVisualizer<MeshT>::mesh->point(vh0) + 0.5 * (OMPropertyVisualizer<MeshT>::mesh->point(vh1) - OMPropertyVisualizer<MeshT>::mesh->point(vh0));
397 typename MeshT::Point v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *he_it);
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>
425 for (
typename MeshT::VertexIter v_it = OMPropertyVisualizer<MeshT>::mesh->vertices_begin() ; v_it != OMPropertyVisualizer<MeshT>::mesh->vertices_end() ; ++v_it){
427 typename MeshT::Point v1 = OMPropertyVisualizer<MeshT>::mesh->point( *v_it );
428 typename MeshT::Point v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *v_it);
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>
445 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
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>
460 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
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>
475 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
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>
490 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
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>
Add colors to mesh item (vertices/faces/edges)
DrawMode EDGES_COLORED
draw edges with colors (without shading)
virtual void removeProperty()
Removes the property.
virtual void duplicateProperty()
Duplicates the property.
virtual QString getPropertyText(unsigned int index)
Returns the value of a property in text form.
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
virtual void clear()
Clears the property.
virtual void clear()
Clears the property.
ACG::SceneGraph::BaseNode * getRootNode()
Get the root node for data objects.
DrawMode SOLID_POINTS_COLORED
draw colored, but not lighted faces using interpolated vertex colors
Class for generating nice colors for doubles.
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
Cellection of information about a property.
DrawMode HALFEDGES_COLORED
draw halfedges with colors (without shading)