50 #define OM_PROPERTY_VISUALIZER_VECTOR_CC
52 #include "OMPropertyVisualizerVector.hh"
53 #include <ACG/Utils/ColorConversion.hh>
55 template <
typename MeshT>
59 if (PropertyVisualizer::widget)
delete PropertyVisualizer::widget;
61 w->paramVector->setTitle(QString(
"3D Vector Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
62 PropertyVisualizer::widget = w;
66 if (!_propertyInfo.isFaceProp())
68 w->vectors_edges_rb->hide();
73 template <
typename MeshT>
80 template <
typename MeshT>
89 template<
typename PROPTYPE,
typename MeshT,
typename ENTITY_IT,
typename PROPINFO_TYPE>
90 void visualizeVectorAsColorForEntity(MeshT *mesh,
const ENTITY_IT e_begin,
const ENTITY_IT e_end,
91 const PROPINFO_TYPE &propinfo) {
93 if (!mesh->get_property_handle(prop, propinfo.propName()))
94 throw VizException(
"Getting PropHandle from mesh for selected property failed.");
95 for (ENTITY_IT e_it = e_begin; e_it != e_end; ++e_it) {
96 typename MeshT::Point v = mesh->property(prop, *e_it).normalized() * .5 +
typename MeshT::Point(.5, .5, .5);
97 mesh->set_color(*e_it,
typename MeshT::Color(v[0], v[1], v[2], 1.0));
101 template<
typename PROPTYPE,
typename MeshT,
typename ENTITY_IT,
typename PROPINFO_TYPE>
102 void visualizeVectorLengthAsColorForEntity(
103 MeshT *mesh,
const ENTITY_IT e_begin,
const ENTITY_IT e_end,
104 const PROPINFO_TYPE &propinfo) {
106 if (!mesh->get_property_handle(prop, propinfo.propName()))
107 throw VizException(
"Getting PropHandle from mesh for selected "
110 double min = std::numeric_limits<double>::infinity();
111 double max = -std::numeric_limits<double>::infinity();
113 for (ENTITY_IT e_it = e_begin; e_it != e_end; ++e_it) {
114 const double val = mesh->property(prop, *e_it).norm();
115 min = std::min(min, val);
116 max = std::max(max, val);
121 for (ENTITY_IT e_it = e_begin; e_it != e_end; ++e_it) {
122 mesh->set_color(*e_it, color_coder(mesh->property(prop, *e_it).norm()));
128 template <
typename MeshT>
132 if (w->vectors_edges_rb->isChecked()) {
133 visualizeFacePropOnEdges();
134 }
else if (w->vectors_colors_rb->isChecked() ||
135 w->vectors_length_color_rb->isChecked()) {
139 if (w->vectors_colors_rb->isChecked()) {
140 visualizeVectorAsColorForEntity<OpenMesh::FPropHandleT<typename MeshT::Point> >(
142 OMPropertyVisualizer<MeshT>::mesh->faces_begin(),
143 OMPropertyVisualizer<MeshT>::mesh->faces_end(),
144 PropertyVisualizer::propertyInfo);
146 visualizeVectorLengthAsColorForEntity<OpenMesh::FPropHandleT<typename MeshT::Point> >(
147 OMPropertyVisualizer<MeshT>::mesh,
148 OMPropertyVisualizer<MeshT>::mesh->faces_begin(),
149 OMPropertyVisualizer<MeshT>::mesh->faces_end(),
150 PropertyVisualizer::propertyInfo);
155 else visualizeFacePropAsStrokes();
158 template <
typename MeshT>
162 if (w->vectors_colors_rb->isChecked() ||
163 w->vectors_length_color_rb->isChecked()) {
164 if ( !OMPropertyVisualizer<MeshT>::mesh->has_edge_colors() )
165 OMPropertyVisualizer<MeshT>::mesh->request_edge_colors();
166 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
167 if ( !mesh->has_edge_colors() )
168 mesh->request_edge_colors();
169 if (w->vectors_colors_rb->isChecked()) {
170 visualizeVectorAsColorForEntity<
175 PropertyVisualizer::propertyInfo);
177 visualizeVectorLengthAsColorForEntity<
182 PropertyVisualizer::propertyInfo);
187 else visualizeEdgePropAsStrokes();
190 template <
typename MeshT>
194 if (w->vectors_colors_rb->isChecked() ||
195 w->vectors_length_color_rb->isChecked()) {
196 if ( !OMPropertyVisualizer<MeshT>::mesh->has_halfedge_colors() )
197 OMPropertyVisualizer<MeshT>::mesh->request_halfedge_colors();
198 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
199 if ( ! mesh->has_halfedge_colors() )
200 mesh->request_halfedge_colors();
202 if (w->vectors_colors_rb->isChecked()) {
203 visualizeVectorAsColorForEntity<
206 mesh->halfedges_begin(),
207 mesh->halfedges_end(),
208 PropertyVisualizer::propertyInfo);
210 visualizeVectorLengthAsColorForEntity<
213 mesh->halfedges_begin(),
214 mesh->halfedges_end(),
215 PropertyVisualizer::propertyInfo);
222 else visualizeHalfedgePropAsStrokes();
225 template <
typename MeshT>
229 if (w->vectors_colors_rb->isChecked() ||
230 w->vectors_length_color_rb->isChecked()) {
231 if ( !OMPropertyVisualizer<MeshT>::mesh->has_vertex_colors() )
232 OMPropertyVisualizer<MeshT>::mesh->request_vertex_colors();
234 if (w->vectors_colors_rb->isChecked()) {
235 visualizeVectorAsColorForEntity<
237 OMPropertyVisualizer<MeshT>::mesh,
238 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
239 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
240 PropertyVisualizer::propertyInfo);
242 visualizeVectorLengthAsColorForEntity<
244 OMPropertyVisualizer<MeshT>::mesh,
245 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
246 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
247 PropertyVisualizer::propertyInfo);
253 else visualizeVertexPropAsStrokes();
256 template <
typename MeshT>
260 MeshT* _mesh = OMPropertyVisualizer<MeshT>::mesh;
263 const double thresh_1 = w->vectors_edges_alpha->value();
264 const double thresh_2 = std::min(thresh_1, w->vectors_edges_alpha->value());
267 if (!_mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName()))
268 throw VizException(
"Getting PropHandle from mesh for selected property failed.");
270 if (!_mesh->has_edge_colors())
271 _mesh->request_edge_colors();
272 const ACG::Vec4f cold(0, 0, 0, 1.0), hot(0, 1, 0, 1.0), degen(1, 1, 0, 1.0);
273 for (
typename MeshT::EdgeIter e_it = _mesh->edges_begin(), e_end = _mesh->edges_end();
274 e_it != e_end; ++e_it) {
275 typename MeshT::Point p1 = _mesh->property(prop, _mesh->face_handle(_mesh->halfedge_handle(*e_it, 0)));
276 typename MeshT::Point p2 = _mesh->property(prop, _mesh->face_handle(_mesh->halfedge_handle(*e_it, 1)));
280 const char degenerate = ((p1.sqrnorm() < 1e-6) ? 1 : 0) | ((p2.sqrnorm() < 1e-6) ? 2 : 0);
281 if (degenerate == 3) {
283 }
else if (degenerate == 0) {
284 p1.normalize(); p2.normalize();
285 const double alpha = std::min(1.0, std::abs(p1 | p2));
286 if (alpha < thresh_1)
288 else if (alpha > thresh_2)
291 const double beta = (alpha - thresh_1) / (thresh_2 - thresh_1);
292 color = cold * beta + hot * (1.0 - beta);
297 _mesh->set_color(*e_it, color);
302 template <
typename MeshT>
309 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
316 for (
typename MeshT::FaceIter f_it = OMPropertyVisualizer<MeshT>::mesh->faces_begin() ; f_it != OMPropertyVisualizer<MeshT>::mesh->faces_end() ; ++f_it){
318 typename MeshT::Point center(0.0, 0.0, 0.0);
321 for (
typename MeshT::FaceVertexIter fv_it(*(OMPropertyVisualizer<MeshT>::mesh),*f_it); fv_it.is_valid(); ++fv_it){
323 center += OMPropertyVisualizer<MeshT>::mesh->point(*fv_it);
328 typename MeshT::Point v = (OMPropertyVisualizer<MeshT>::mesh->property(prop, *f_it));
330 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
333 if(vectorWidget->scale->isChecked())
334 v *= vectorWidget->scaleBox->value();
336 lineNode->add_line( center, (center+v) );
337 lineNode->add_color(color);
341 template <
typename MeshT>
348 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
356 for (
typename MeshT::EdgeIter e_it = OMPropertyVisualizer<MeshT>::mesh->edges_begin() ; e_it != OMPropertyVisualizer<MeshT>::mesh->edges_end() ; ++e_it){
358 typename MeshT::HalfedgeHandle hh = OMPropertyVisualizer<MeshT>::mesh->halfedge_handle( *e_it, 0 );
360 typename MeshT::VertexHandle vh0 = OMPropertyVisualizer<MeshT>::mesh->from_vertex_handle( hh );
361 typename MeshT::VertexHandle vh1 = OMPropertyVisualizer<MeshT>::mesh->to_vertex_handle( hh );
363 typename MeshT::Point v1 = OMPropertyVisualizer<MeshT>::mesh->point(vh0) + 0.5 * (OMPropertyVisualizer<MeshT>::mesh->point(vh1) - OMPropertyVisualizer<MeshT>::mesh->point(vh0));
364 typename MeshT::Point v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *e_it);
366 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
369 if(vectorWidget->scale->isChecked())
370 v *= vectorWidget->scaleBox->value();
372 lineNode->add_line( v1, (v1+v) );
373 lineNode->add_color(color);
377 template <
typename MeshT>
384 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
392 for (
typename MeshT::HalfedgeIter he_it = OMPropertyVisualizer<MeshT>::mesh->halfedges_begin() ; he_it != OMPropertyVisualizer<MeshT>::mesh->halfedges_end() ; ++he_it){
394 typename MeshT::VertexHandle vh0 = OMPropertyVisualizer<MeshT>::mesh->from_vertex_handle( *he_it );
395 typename MeshT::VertexHandle vh1 = OMPropertyVisualizer<MeshT>::mesh->to_vertex_handle( *he_it );
397 typename MeshT::Point v1 = OMPropertyVisualizer<MeshT>::mesh->point(vh0) + 0.5 * (OMPropertyVisualizer<MeshT>::mesh->point(vh1) - OMPropertyVisualizer<MeshT>::mesh->point(vh0));
398 typename MeshT::Point v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *he_it);
400 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
403 if(vectorWidget->scale->isChecked())
404 v *= vectorWidget->scaleBox->value();
406 lineNode->add_line( v1, (v1+v) );
407 lineNode->add_color(color);
411 template <
typename MeshT>
418 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
426 for (
typename MeshT::VertexIter v_it = OMPropertyVisualizer<MeshT>::mesh->vertices_begin() ; v_it != OMPropertyVisualizer<MeshT>::mesh->vertices_end() ; ++v_it){
428 typename MeshT::Point v1 = OMPropertyVisualizer<MeshT>::mesh->point( *v_it );
429 typename MeshT::Point v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *v_it);
431 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
434 if(vectorWidget->scale->isChecked())
435 v *= vectorWidget->scaleBox->value();
437 lineNode->add_line( v1, (v1+v) );
438 lineNode->add_color(color);
442 template <
typename MeshT>
446 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
448 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
449 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
452 typename MeshT::FaceHandle fh = mesh->face_handle(index);
454 mesh->property(prop, fh) = this->strToVec3d(text);
457 template <
typename MeshT>
461 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
463 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
464 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
467 typename MeshT::EdgeHandle eh = mesh->edge_handle(index);
469 mesh->property(prop, eh) = this->strToVec3d(text);
472 template <
typename MeshT>
476 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
478 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
479 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
482 typename MeshT::HalfedgeHandle heh = mesh->halfedge_handle(index);
484 mesh->property(prop, heh) = this->strToVec3d(text);
487 template <
typename MeshT>
491 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
493 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
494 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
497 typename MeshT::VertexHandle vh = mesh->vertex_handle(index);
499 mesh->property(prop, vh) = this->strToVec3d(text);
503 template<
typename MeshT>
509 template<
typename MeshT>
virtual QString getPropertyText(unsigned int index)
Returns the value of a property in text form.
Class for generating nice colors for doubles.
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .
DrawMode SOLID_POINTS_COLORED
draw colored, but not lighted faces using interpolated vertex colors
DrawMode EDGES_COLORED
draw edges with colors (without shading)
ACG::SceneGraph::BaseNode * getRootNode()
Get the root node for data objects.
DrawMode HALFEDGES_COLORED
draw halfedges with colors (without shading)
virtual void duplicateProperty()
Duplicates the property.
virtual void clear()
Clears the property.
virtual void clear()
Clears the property.
virtual void removeProperty()
Removes the property.
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Add colors to mesh item (vertices/faces/edges)
Cellection of information about a property.
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors