50 #define OM_PROPERTY_VISUALIZER_VECTOR2_CC
52 #include "OMPropertyVisualizerVector2.hh"
53 #include <OpenMesh/Core/Utils/Property.hh>
54 #include <ACG/Utils/ColorConversion.hh>
56 template <
typename MeshT,
typename VectorType>
60 if (PropertyVisualizer::widget)
delete PropertyVisualizer::widget;
62 w->paramVector->setTitle(QString(
"2D Vector Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
63 PropertyVisualizer::widget = w;
67 if (!_propertyInfo.isFaceProp())
69 w->vectors_edges_rb->hide();
73 template <
typename MeshT,
typename VectorType>
80 template <
typename MeshT,
typename VectorType>
89 template<
typename PROPTYPE,
typename VectorType,
typename MeshT,
typename ENTITY_IT,
typename PROPINFO_TYPE>
90 void visualizeVectorAsColorForEntity2(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 VectorType v = mesh->property(prop, *e_it).normalized() * .5 + VectorType(0.5);
97 mesh->set_color(*e_it,
typename MeshT::Color(v[0], v[1], 0.0, 1.0));
101 template<
typename PROPTYPE,
typename MeshT,
typename ENTITY_IT,
typename PROPINFO_TYPE>
102 void visualizeVectorLengthAsColorForEntity2(
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()));
126 template <
typename VectorType>
ACG::Vec3d generateVec3AtLocation(VectorType uv,
ACG::Vec3d normal)
129 if(std::abs(normal[0]) > std::abs(normal[1]))
131 else tan =
ACG::Vec3d(0, normal[2], -normal[1]);
133 return double(uv[0]) * tan.normalize() + double(uv[1]) * bi.normalize();
138 template <
typename MeshT,
typename VectorType>
142 if (w->vectors_edges_rb->isChecked()) {
143 visualizeFacePropOnEdges();
144 }
else if (w->vectors_colors_rb->isChecked() ||
145 w->vectors_length_color_rb->isChecked()) {
149 if (w->vectors_colors_rb->isChecked()) {
150 visualizeVectorAsColorForEntity2<OpenMesh::FPropHandleT<VectorType>, VectorType >(
152 OMPropertyVisualizer<MeshT>::mesh->faces_begin(),
153 OMPropertyVisualizer<MeshT>::mesh->faces_end(),
154 PropertyVisualizer::propertyInfo);
156 visualizeVectorLengthAsColorForEntity2<OpenMesh::FPropHandleT<VectorType> >(
157 OMPropertyVisualizer<MeshT>::mesh,
158 OMPropertyVisualizer<MeshT>::mesh->faces_begin(),
159 OMPropertyVisualizer<MeshT>::mesh->faces_end(),
160 PropertyVisualizer::propertyInfo);
165 else visualizeFacePropAsStrokes();
168 template <
typename MeshT,
typename VectorType>
172 if (w->vectors_colors_rb->isChecked() ||
173 w->vectors_length_color_rb->isChecked()) {
174 if ( !OMPropertyVisualizer<MeshT>::mesh->has_edge_colors() )
175 OMPropertyVisualizer<MeshT>::mesh->request_edge_colors();
176 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
177 if ( !mesh->has_edge_colors() )
178 mesh->request_edge_colors();
179 if (w->vectors_colors_rb->isChecked()) {
180 visualizeVectorAsColorForEntity2<
185 PropertyVisualizer::propertyInfo);
187 visualizeVectorLengthAsColorForEntity2<
188 OpenMesh::EPropHandleT<VectorType> >(
192 PropertyVisualizer::propertyInfo);
197 else visualizeEdgePropAsStrokes();
200 template <
typename MeshT,
typename VectorType>
204 if (w->vectors_colors_rb->isChecked() ||
205 w->vectors_length_color_rb->isChecked()) {
206 if ( !OMPropertyVisualizer<MeshT>::mesh->has_halfedge_colors() )
207 OMPropertyVisualizer<MeshT>::mesh->request_halfedge_colors();
208 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
209 if ( ! mesh->has_halfedge_colors() )
210 mesh->request_halfedge_colors();
212 if (w->vectors_colors_rb->isChecked()) {
213 visualizeVectorAsColorForEntity2<
216 mesh->halfedges_begin(),
217 mesh->halfedges_end(),
218 PropertyVisualizer::propertyInfo);
220 visualizeVectorLengthAsColorForEntity2<
221 OpenMesh::HPropHandleT<VectorType> >(
223 mesh->halfedges_begin(),
224 mesh->halfedges_end(),
225 PropertyVisualizer::propertyInfo);
232 else visualizeHalfedgePropAsStrokes();
235 template <
typename MeshT,
typename VectorType>
239 if (w->vectors_colors_rb->isChecked() ||
240 w->vectors_length_color_rb->isChecked()) {
241 if ( !OMPropertyVisualizer<MeshT>::mesh->has_vertex_colors() )
242 OMPropertyVisualizer<MeshT>::mesh->request_vertex_colors();
244 if (w->vectors_colors_rb->isChecked()) {
245 visualizeVectorAsColorForEntity2<
247 OMPropertyVisualizer<MeshT>::mesh,
248 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
249 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
250 PropertyVisualizer::propertyInfo);
252 visualizeVectorLengthAsColorForEntity2<
253 OpenMesh::VPropHandleT<VectorType> >(
254 OMPropertyVisualizer<MeshT>::mesh,
255 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
256 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
257 PropertyVisualizer::propertyInfo);
263 else visualizeVertexPropAsStrokes();
266 template <
typename MeshT,
typename VectorType>
269 MeshT* _mesh = OMPropertyVisualizer<MeshT>::mesh;
272 const double thresh_1 = w->vectors_edges_alpha->value();
273 const double thresh_2 = std::min(thresh_1, w->vectors_edges_alpha->value());
276 if (!_mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName()))
277 throw VizException(
"Getting PropHandle from mesh for selected property failed.");
279 if (!_mesh->has_edge_colors())
280 _mesh->request_edge_colors();
281 const ACG::Vec4f cold(0, 0, 0, 1.0), hot(0, 1, 0, 1.0), degen(1, 1, 0, 1.0);
282 for (
typename MeshT::EdgeIter e_it = _mesh->edges_begin(), e_end = _mesh->edges_end();
283 e_it != e_end; ++e_it) {
284 VectorType p1 = _mesh->property(prop, _mesh->face_handle(_mesh->halfedge_handle(*e_it, 0)));
285 VectorType p2 = _mesh->property(prop, _mesh->face_handle(_mesh->halfedge_handle(*e_it, 1)));
289 const char degenerate = ((p1.sqrnorm() < 1e-6) ? 1 : 0) | ((p2.sqrnorm() < 1e-6) ? 2 : 0);
290 if (degenerate == 3) {
292 }
else if (degenerate == 0) {
293 p1.normalize(); p2.normalize();
294 const double alpha = std::min(1.0,
double(std::abs(p1 | p2)));
295 if (alpha < thresh_1)
297 else if (alpha > thresh_2)
300 const double beta = (alpha - thresh_1) / (thresh_2 - thresh_1);
301 color = cold * beta + hot * (1.0 - beta);
306 _mesh->set_color(*e_it, color);
311 template <
typename MeshT,
typename VectorType>
318 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
325 for (
typename MeshT::FaceIter f_it = OMPropertyVisualizer<MeshT>::mesh->faces_begin() ; f_it != OMPropertyVisualizer<MeshT>::mesh->faces_end() ; ++f_it){
327 typename MeshT::Point center(0.0, 0.0, 0.0);
330 for (
typename MeshT::FaceVertexIter fv_it(*(OMPropertyVisualizer<MeshT>::mesh),*f_it); fv_it.is_valid(); ++fv_it){
332 center += OMPropertyVisualizer<MeshT>::mesh->point(*fv_it);
337 VectorType v = (OMPropertyVisualizer<MeshT>::mesh->property(prop, *f_it));
338 ACG::Vec3d normal = OMPropertyVisualizer<MeshT>::mesh->normal(*f_it);
340 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
343 if(vectorWidget->scale->isChecked())
344 v *= vectorWidget->scaleBox->value();
346 lineNode->add_line( center, (center+generateVec3AtLocation<VectorType>(v, normal)) );
347 lineNode->add_color(color);
351 template <
typename MeshT,
typename VectorType>
358 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
366 for (
typename MeshT::EdgeIter e_it = OMPropertyVisualizer<MeshT>::mesh->edges_begin() ; e_it != OMPropertyVisualizer<MeshT>::mesh->edges_end() ; ++e_it){
368 typename MeshT::HalfedgeHandle hh = OMPropertyVisualizer<MeshT>::mesh->halfedge_handle( *e_it, 0 );
370 typename MeshT::VertexHandle vh0 = OMPropertyVisualizer<MeshT>::mesh->from_vertex_handle( hh );
371 typename MeshT::VertexHandle vh1 = OMPropertyVisualizer<MeshT>::mesh->to_vertex_handle( hh );
373 typename MeshT::Point v1 = OMPropertyVisualizer<MeshT>::mesh->point(vh0) + 0.5 * (OMPropertyVisualizer<MeshT>::mesh->point(vh1) - OMPropertyVisualizer<MeshT>::mesh->point(vh0));
374 VectorType v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *e_it);
375 ACG::Vec3d normal = OMPropertyVisualizer<MeshT>::mesh->normal(OMPropertyVisualizer<MeshT>::mesh->halfedge_handle(*e_it, 0));
377 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
380 if(vectorWidget->scale->isChecked())
381 v *= vectorWidget->scaleBox->value();
383 lineNode->add_line( v1, (v1+generateVec3AtLocation<VectorType>(v, normal)) );
384 lineNode->add_color(color);
388 template <
typename MeshT,
typename VectorType>
395 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
403 for (
typename MeshT::HalfedgeIter he_it = OMPropertyVisualizer<MeshT>::mesh->halfedges_begin() ; he_it != OMPropertyVisualizer<MeshT>::mesh->halfedges_end() ; ++he_it){
405 typename MeshT::VertexHandle vh0 = OMPropertyVisualizer<MeshT>::mesh->from_vertex_handle( *he_it );
406 typename MeshT::VertexHandle vh1 = OMPropertyVisualizer<MeshT>::mesh->to_vertex_handle( *he_it );
408 typename MeshT::Point v1 = OMPropertyVisualizer<MeshT>::mesh->point(vh0) + 0.5 * (OMPropertyVisualizer<MeshT>::mesh->point(vh1) - OMPropertyVisualizer<MeshT>::mesh->point(vh0));
409 VectorType v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *he_it);
410 ACG::Vec3d normal = OMPropertyVisualizer<MeshT>::mesh->normal(*he_it);
412 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
415 if(vectorWidget->scale->isChecked())
416 v *= vectorWidget->scaleBox->value();
418 lineNode->add_line( v1, (v1+generateVec3AtLocation<VectorType>(v, normal)) );
419 lineNode->add_color(color);
423 template <
typename MeshT,
typename VectorType>
430 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
438 for (
typename MeshT::VertexIter v_it = OMPropertyVisualizer<MeshT>::mesh->vertices_begin() ; v_it != OMPropertyVisualizer<MeshT>::mesh->vertices_end() ; ++v_it){
440 typename MeshT::Point v1 = OMPropertyVisualizer<MeshT>::mesh->point( *v_it );
441 VectorType v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *v_it);
442 ACG::Vec3d normal = OMPropertyVisualizer<MeshT>::mesh->normal(*v_it);
444 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
447 if(vectorWidget->scale->isChecked())
448 v *= vectorWidget->scaleBox->value();
450 lineNode->add_line( v1, (v1+generateVec3AtLocation<VectorType>(v, normal)) );
451 lineNode->add_color(color);
455 template <
typename MeshT,
typename VectorType>
459 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
461 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
462 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
465 typename MeshT::FaceHandle fh = mesh->face_handle(index);
467 mesh->property(prop, fh) = this->strToVec2f(text);
470 template <
typename MeshT,
typename VectorType>
474 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
476 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
477 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
480 typename MeshT::EdgeHandle eh = mesh->edge_handle(index);
482 mesh->property(prop, eh) = this->strToVec2f(text);
485 template <
typename MeshT,
typename VectorType>
489 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
491 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
492 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
495 typename MeshT::HalfedgeHandle heh = mesh->halfedge_handle(index);
497 mesh->property(prop, heh) = this->strToVec2f(text);
500 template <
typename MeshT,
typename VectorType>
504 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
506 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
507 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
510 typename MeshT::VertexHandle vh = mesh->vertex_handle(index);
512 mesh->property(prop, vh) = this->strToVec2f(text);
516 template <
typename MeshT,
typename VectorType>
522 template <
typename MeshT,
typename VectorType>
Class for generating nice colors for doubles.
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .
virtual QString getPropertyText(unsigned int index)
Returns the value of a property in text form.
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 removeProperty()
Removes the property.
virtual void duplicateProperty()
Duplicates the property.
virtual void clear()
Clears the property.
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
virtual void clear()
Clears the property.
Add colors to mesh item (vertices/faces/edges)
VectorT< double, 3 > Vec3d
Cellection of information about a property.
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors