50 #define OM_PROPERTY_VISUALIZER_VECTOR2_CC
52 #include "OMPropertyVisualizerVector2.hh"
53 #include <OpenMesh/Core/Utils/Property.hh>
55 template <
typename MeshT,
typename VectorType>
59 if (PropertyVisualizer::widget)
delete PropertyVisualizer::widget;
61 w->paramVector->setTitle(QString(
"2D Vector Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
62 PropertyVisualizer::widget = w;
66 if (!_propertyInfo.isFaceProp())
68 w->vectors_edges_rb->hide();
72 template <
typename MeshT,
typename VectorType>
79 template <
typename MeshT,
typename VectorType>
88 template<
typename PROPTYPE,
typename VectorType,
typename MeshT,
typename ENTITY_IT,
typename PROPINFO_TYPE>
89 void visualizeVectorAsColorForEntity2(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 VectorType v = mesh->property(prop, *e_it).normalized() * .5 + VectorType(0.5);
96 mesh->set_color(*e_it,
typename MeshT::Color(v[0], v[1], 0.0, 1.0));
100 template<
typename PROPTYPE,
typename MeshT,
typename ENTITY_IT,
typename PROPINFO_TYPE>
101 void visualizeVectorLengthAsColorForEntity2(
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()));
125 template <
typename VectorType>
ACG::Vec3d generateVec3AtLocation(VectorType uv,
ACG::Vec3d normal)
128 if(std::abs(normal[0]) > std::abs(normal[1]))
130 else tan =
ACG::Vec3d(0, normal[2], -normal[1]);
132 return double(uv[0]) * tan.normalize() + double(uv[1]) * bi.normalize();
137 template <
typename MeshT,
typename VectorType>
141 if (w->vectors_edges_rb->isChecked()) {
142 visualizeFacePropOnEdges();
143 }
else if (w->vectors_colors_rb->isChecked() ||
144 w->vectors_length_color_rb->isChecked()) {
148 if (w->vectors_colors_rb->isChecked()) {
149 visualizeVectorAsColorForEntity2<OpenMesh::FPropHandleT<VectorType>, VectorType >(
151 OMPropertyVisualizer<MeshT>::mesh->faces_begin(),
152 OMPropertyVisualizer<MeshT>::mesh->faces_end(),
153 PropertyVisualizer::propertyInfo);
155 visualizeVectorLengthAsColorForEntity2<OpenMesh::FPropHandleT<VectorType> >(
156 OMPropertyVisualizer<MeshT>::mesh,
157 OMPropertyVisualizer<MeshT>::mesh->faces_begin(),
158 OMPropertyVisualizer<MeshT>::mesh->faces_end(),
159 PropertyVisualizer::propertyInfo);
164 else visualizeFacePropAsStrokes();
167 template <
typename MeshT,
typename VectorType>
171 if (w->vectors_colors_rb->isChecked() ||
172 w->vectors_length_color_rb->isChecked()) {
173 if ( !OMPropertyVisualizer<MeshT>::mesh->has_edge_colors() )
174 OMPropertyVisualizer<MeshT>::mesh->request_edge_colors();
175 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
176 if ( !mesh->has_edge_colors() )
177 mesh->request_edge_colors();
178 if (w->vectors_colors_rb->isChecked()) {
179 visualizeVectorAsColorForEntity2<
184 PropertyVisualizer::propertyInfo);
186 visualizeVectorLengthAsColorForEntity2<
187 OpenMesh::EPropHandleT<VectorType> >(
191 PropertyVisualizer::propertyInfo);
196 else visualizeEdgePropAsStrokes();
199 template <
typename MeshT,
typename VectorType>
203 if (w->vectors_colors_rb->isChecked() ||
204 w->vectors_length_color_rb->isChecked()) {
205 if ( !OMPropertyVisualizer<MeshT>::mesh->has_halfedge_colors() )
206 OMPropertyVisualizer<MeshT>::mesh->request_halfedge_colors();
207 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
208 if ( ! mesh->has_halfedge_colors() )
209 mesh->request_halfedge_colors();
211 if (w->vectors_colors_rb->isChecked()) {
212 visualizeVectorAsColorForEntity2<
215 mesh->halfedges_begin(),
216 mesh->halfedges_end(),
217 PropertyVisualizer::propertyInfo);
219 visualizeVectorLengthAsColorForEntity2<
220 OpenMesh::HPropHandleT<VectorType> >(
222 mesh->halfedges_begin(),
223 mesh->halfedges_end(),
224 PropertyVisualizer::propertyInfo);
231 else visualizeHalfedgePropAsStrokes();
234 template <
typename MeshT,
typename VectorType>
238 if (w->vectors_colors_rb->isChecked() ||
239 w->vectors_length_color_rb->isChecked()) {
240 if ( !OMPropertyVisualizer<MeshT>::mesh->has_vertex_colors() )
241 OMPropertyVisualizer<MeshT>::mesh->request_vertex_colors();
243 if (w->vectors_colors_rb->isChecked()) {
244 visualizeVectorAsColorForEntity2<
246 OMPropertyVisualizer<MeshT>::mesh,
247 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
248 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
249 PropertyVisualizer::propertyInfo);
251 visualizeVectorLengthAsColorForEntity2<
252 OpenMesh::VPropHandleT<VectorType> >(
253 OMPropertyVisualizer<MeshT>::mesh,
254 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
255 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
256 PropertyVisualizer::propertyInfo);
262 else visualizeVertexPropAsStrokes();
265 template <
typename MeshT,
typename VectorType>
268 MeshT* _mesh = OMPropertyVisualizer<MeshT>::mesh;
271 const double thresh_1 = w->vectors_edges_alpha->value();
272 const double thresh_2 = std::min(thresh_1, w->vectors_edges_alpha->value());
275 if (!_mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName()))
276 throw VizException(
"Getting PropHandle from mesh for selected property failed.");
278 if (!_mesh->has_edge_colors())
279 _mesh->request_edge_colors();
280 const ACG::Vec4f cold(0, 0, 0, 1.0), hot(0, 1, 0, 1.0), degen(1, 1, 0, 1.0);
281 for (
typename MeshT::EdgeIter e_it = _mesh->edges_begin(), e_end = _mesh->edges_end();
282 e_it != e_end; ++e_it) {
283 VectorType p1 = _mesh->property(prop, _mesh->face_handle(_mesh->halfedge_handle(*e_it, 0)));
284 VectorType p2 = _mesh->property(prop, _mesh->face_handle(_mesh->halfedge_handle(*e_it, 1)));
288 const char degenerate = ((p1.sqrnorm() < 1e-6) ? 1 : 0) | ((p2.sqrnorm() < 1e-6) ? 2 : 0);
289 if (degenerate == 3) {
291 }
else if (degenerate == 0) {
292 p1.normalize(); p2.normalize();
293 const double alpha = std::min(1.0,
double(std::abs(p1 | p2)));
294 if (alpha < thresh_1)
296 else if (alpha > thresh_2)
299 const double beta = (alpha - thresh_1) / (thresh_2 - thresh_1);
300 color = cold * beta + hot * (1.0 - beta);
305 _mesh->set_color(*e_it, color);
310 template <
typename MeshT,
typename VectorType>
324 for (
typename MeshT::FaceIter f_it = OMPropertyVisualizer<MeshT>::mesh->faces_begin() ; f_it != OMPropertyVisualizer<MeshT>::mesh->faces_end() ; ++f_it){
326 typename MeshT::Point center(0.0, 0.0, 0.0);
329 for (
typename MeshT::FaceVertexIter fv_it(*(OMPropertyVisualizer<MeshT>::mesh),*f_it); fv_it.is_valid(); ++fv_it){
331 center += OMPropertyVisualizer<MeshT>::mesh->point(*fv_it);
336 VectorType v = (OMPropertyVisualizer<MeshT>::mesh->property(prop, *f_it));
337 ACG::Vec3d normal = OMPropertyVisualizer<MeshT>::mesh->normal(*f_it);
339 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
342 if(vectorWidget->scale->isChecked())
343 v *= vectorWidget->scaleBox->value();
345 lineNode->add_line( center, (center+generateVec3AtLocation<VectorType>(v, normal)) );
346 lineNode->add_color(color);
350 template <
typename MeshT,
typename VectorType>
365 for (
typename MeshT::EdgeIter e_it = OMPropertyVisualizer<MeshT>::mesh->edges_begin() ; e_it != OMPropertyVisualizer<MeshT>::mesh->edges_end() ; ++e_it){
367 typename MeshT::HalfedgeHandle hh = OMPropertyVisualizer<MeshT>::mesh->halfedge_handle( *e_it, 0 );
369 typename MeshT::VertexHandle vh0 = OMPropertyVisualizer<MeshT>::mesh->from_vertex_handle( hh );
370 typename MeshT::VertexHandle vh1 = OMPropertyVisualizer<MeshT>::mesh->to_vertex_handle( hh );
372 typename MeshT::Point v1 = OMPropertyVisualizer<MeshT>::mesh->point(vh0) + 0.5 * (OMPropertyVisualizer<MeshT>::mesh->point(vh1) - OMPropertyVisualizer<MeshT>::mesh->point(vh0));
373 VectorType v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *e_it);
374 ACG::Vec3d normal = OMPropertyVisualizer<MeshT>::mesh->normal(OMPropertyVisualizer<MeshT>::mesh->halfedge_handle(*e_it, 0));
376 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
379 if(vectorWidget->scale->isChecked())
380 v *= vectorWidget->scaleBox->value();
382 lineNode->add_line( v1, (v1+generateVec3AtLocation<VectorType>(v, normal)) );
383 lineNode->add_color(color);
387 template <
typename MeshT,
typename VectorType>
402 for (
typename MeshT::HalfedgeIter he_it = OMPropertyVisualizer<MeshT>::mesh->halfedges_begin() ; he_it != OMPropertyVisualizer<MeshT>::mesh->halfedges_end() ; ++he_it){
404 typename MeshT::VertexHandle vh0 = OMPropertyVisualizer<MeshT>::mesh->from_vertex_handle( *he_it );
405 typename MeshT::VertexHandle vh1 = OMPropertyVisualizer<MeshT>::mesh->to_vertex_handle( *he_it );
407 typename MeshT::Point v1 = OMPropertyVisualizer<MeshT>::mesh->point(vh0) + 0.5 * (OMPropertyVisualizer<MeshT>::mesh->point(vh1) - OMPropertyVisualizer<MeshT>::mesh->point(vh0));
408 VectorType v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *he_it);
409 ACG::Vec3d normal = OMPropertyVisualizer<MeshT>::mesh->normal(*he_it);
411 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
414 if(vectorWidget->scale->isChecked())
415 v *= vectorWidget->scaleBox->value();
417 lineNode->add_line( v1, (v1+generateVec3AtLocation<VectorType>(v, normal)) );
418 lineNode->add_color(color);
422 template <
typename MeshT,
typename VectorType>
437 for (
typename MeshT::VertexIter v_it = OMPropertyVisualizer<MeshT>::mesh->vertices_begin() ; v_it != OMPropertyVisualizer<MeshT>::mesh->vertices_end() ; ++v_it){
439 typename MeshT::Point v1 = OMPropertyVisualizer<MeshT>::mesh->point( *v_it );
440 VectorType v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *v_it);
441 ACG::Vec3d normal = OMPropertyVisualizer<MeshT>::mesh->normal(*v_it);
443 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
446 if(vectorWidget->scale->isChecked())
447 v *= vectorWidget->scaleBox->value();
449 lineNode->add_line( v1, (v1+generateVec3AtLocation<VectorType>(v, normal)) );
450 lineNode->add_color(color);
454 template <
typename MeshT,
typename VectorType>
458 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
460 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
461 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
464 typename MeshT::FaceHandle fh = mesh->face_handle(index);
466 mesh->property(prop, fh) = this->strToVec2f(text);
469 template <
typename MeshT,
typename VectorType>
473 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
475 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
476 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
479 typename MeshT::EdgeHandle eh = mesh->edge_handle(index);
481 mesh->property(prop, eh) = this->strToVec2f(text);
484 template <
typename MeshT,
typename VectorType>
488 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
490 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
491 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
494 typename MeshT::HalfedgeHandle heh = mesh->halfedge_handle(index);
496 mesh->property(prop, heh) = this->strToVec2f(text);
499 template <
typename MeshT,
typename VectorType>
503 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
505 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
506 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
509 typename MeshT::VertexHandle vh = mesh->vertex_handle(index);
511 mesh->property(prop, vh) = this->strToVec2f(text);
515 template <
typename MeshT,
typename VectorType>
521 template <
typename MeshT,
typename VectorType>
Add colors to mesh item (vertices/faces/edges)
DrawMode EDGES_COLORED
draw edges with colors (without shading)
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)
VectorT< double, 3 > Vec3d
virtual void clear()
Clears the property.
virtual void duplicateProperty()
Duplicates 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
virtual void clear()
Clears the property.
Class for generating nice colors for doubles.
virtual void removeProperty()
Removes the property.
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)
virtual QString getPropertyText(unsigned int index)
Returns the value of a property in text form.