44 #define OM_PROPERTY_VISUALIZER_VECTOR_CC 46 #include "OMPropertyVisualizerVector.hh" 47 #include <ACG/Utils/ColorConversion.hh> 49 template <
typename MeshT>
53 if (PropertyVisualizer::widget)
delete PropertyVisualizer::widget;
55 w->paramVector->setTitle(QString(
"3D Vector Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
56 PropertyVisualizer::widget = w;
63 if (!_propertyInfo.isFaceProp())
65 w->vectors_edges_rb->hide();
67 this->connect(w->lineWidth, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
68 [
this](
double value) {lineNode->set_line_width(value);});
71 template <
typename MeshT>
78 template <
typename MeshT>
87 template<
typename PROPTYPE,
typename MeshT,
typename ENTITY_IT,
typename PROPINFO_TYPE>
88 void visualizeVectorAsColorForEntity(MeshT *mesh,
const ENTITY_IT e_begin,
const ENTITY_IT e_end,
89 const PROPINFO_TYPE &propinfo,
bool normalized) {
91 if (!mesh->get_property_handle(prop, propinfo.propName()))
92 throw VizException(
"Getting PropHandle from mesh for selected property failed.");
93 for (ENTITY_IT e_it = e_begin; e_it != e_end; ++e_it) {
94 using point_t =
typename MeshT::Point;
95 point_t v = mesh->property(prop, *e_it);
97 v = v.normalized() * 0.5 + point_t(0.5);
99 v = v.min(point_t(1, 1, 1)).max(point_t(0, 0, 0));
100 mesh->set_color(*e_it,
typename MeshT::Color(v[0], v[1], v[2], 1.0));
104 template<
typename PROPTYPE,
typename MeshT,
typename ENTITY_IT,
typename PROPINFO_TYPE>
105 void visualizeVectorLengthAsColorForEntity(
106 MeshT *mesh,
const ENTITY_IT e_begin,
const ENTITY_IT e_end,
107 const PROPINFO_TYPE &propinfo) {
109 if (!mesh->get_property_handle(prop, propinfo.propName()))
110 throw VizException(
"Getting PropHandle from mesh for selected " 113 double min = std::numeric_limits<double>::infinity();
114 double max = -std::numeric_limits<double>::infinity();
116 for (ENTITY_IT e_it = e_begin; e_it != e_end; ++e_it) {
117 const double val = mesh->property(prop, *e_it).norm();
118 min = std::min(min, val);
119 max = std::max(max, val);
124 for (ENTITY_IT e_it = e_begin; e_it != e_end; ++e_it) {
125 mesh->set_color(*e_it, color_coder(mesh->property(prop, *e_it).norm()));
131 template <
typename MeshT>
135 if (w->vectors_edges_rb->isChecked()) {
136 visualizeFacePropOnEdges();
137 }
else if (w->vectors_colors_rb->isChecked() ||
138 w->vectors_length_color_rb->isChecked()) {
142 if (w->vectors_colors_rb->isChecked()) {
143 visualizeVectorAsColorForEntity<OpenMesh::FPropHandleT<typename MeshT::Point> >(
145 OMPropertyVisualizer<MeshT>::mesh->faces_begin(),
146 OMPropertyVisualizer<MeshT>::mesh->faces_end(),
147 PropertyVisualizer::propertyInfo,
148 w->normalize_colors->isChecked());
150 visualizeVectorLengthAsColorForEntity<OpenMesh::FPropHandleT<typename MeshT::Point> >(
152 OMPropertyVisualizer<MeshT>::mesh->faces_begin(),
153 OMPropertyVisualizer<MeshT>::mesh->faces_end(),
154 PropertyVisualizer::propertyInfo);
159 else visualizeFacePropAsStrokes();
162 template <
typename MeshT>
166 if (w->vectors_colors_rb->isChecked() ||
167 w->vectors_length_color_rb->isChecked()) {
171 if ( !mesh->has_edge_colors() )
172 mesh->request_edge_colors();
173 if (w->vectors_colors_rb->isChecked()) {
174 visualizeVectorAsColorForEntity<
179 PropertyVisualizer::propertyInfo,
180 w->normalize_colors->isChecked());
182 visualizeVectorLengthAsColorForEntity<
187 PropertyVisualizer::propertyInfo);
192 else visualizeEdgePropAsStrokes();
195 template <
typename MeshT>
199 if (w->vectors_colors_rb->isChecked() ||
200 w->vectors_length_color_rb->isChecked()) {
204 if ( ! mesh->has_halfedge_colors() )
205 mesh->request_halfedge_colors();
207 if (w->vectors_colors_rb->isChecked()) {
208 visualizeVectorAsColorForEntity<
211 mesh->halfedges_begin(),
212 mesh->halfedges_end(),
213 PropertyVisualizer::propertyInfo,
214 w->normalize_colors->isChecked());
216 visualizeVectorLengthAsColorForEntity<
219 mesh->halfedges_begin(),
220 mesh->halfedges_end(),
221 PropertyVisualizer::propertyInfo);
228 else visualizeHalfedgePropAsStrokes();
231 template <
typename MeshT>
235 if (w->vectors_colors_rb->isChecked() ||
236 w->vectors_length_color_rb->isChecked()) {
240 if (w->vectors_colors_rb->isChecked()) {
241 visualizeVectorAsColorForEntity<
244 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
245 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
246 PropertyVisualizer::propertyInfo,
247 w->normalize_colors->isChecked());
249 visualizeVectorLengthAsColorForEntity<
252 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
253 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
254 PropertyVisualizer::propertyInfo);
260 else visualizeVertexPropAsStrokes();
263 template <
typename MeshT>
270 const double thresh_1 = w->vectors_edges_alpha->value();
271 const double thresh_2 = std::min(thresh_1, w->vectors_edges_alpha->value());
274 if (!_mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName()))
275 throw VizException(
"Getting PropHandle from mesh for selected property failed.");
277 if (!_mesh->has_edge_colors())
278 _mesh->request_edge_colors();
279 const ACG::Vec4f cold(0, 0, 0, 1.0), hot(0, 1, 0, 1.0), degen(1, 1, 0, 1.0);
280 for (
typename MeshT::EdgeIter e_it = _mesh->edges_begin(), e_end = _mesh->edges_end();
281 e_it != e_end; ++e_it) {
282 typename MeshT::Point p1 = _mesh->property(prop, _mesh->face_handle(_mesh->halfedge_handle(*e_it, 0)));
283 typename MeshT::Point p2 = _mesh->property(prop, _mesh->face_handle(_mesh->halfedge_handle(*e_it, 1)));
287 const char degenerate = ((p1.sqrnorm() < 1e-6) ? 1 : 0) | ((p2.sqrnorm() < 1e-6) ? 2 : 0);
288 if (degenerate == 3) {
290 }
else if (degenerate == 0) {
292 const double alpha = std::min(1.0, std::abs(p1 | p2));
293 if (alpha < thresh_1)
295 else if (alpha > thresh_2)
298 const double beta = (alpha - thresh_1) / (thresh_2 - thresh_1);
299 color = cold * beta + hot * (1.0 - beta);
304 _mesh->set_color(*e_it, color);
309 template <
typename MeshT>
316 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
325 typename MeshT::Point center(0.0, 0.0, 0.0);
337 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
340 if(vectorWidget->scale->isChecked())
341 v *= vectorWidget->scaleBox->value();
343 lineNode->add_line( center, (center+v) );
344 lineNode->add_color(color);
348 template <
typename MeshT>
355 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
373 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
376 if(vectorWidget->scale->isChecked())
377 v *= vectorWidget->scaleBox->value();
379 lineNode->add_line( v1, (v1+v) );
380 lineNode->add_color(color);
384 template <
typename MeshT>
391 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
407 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
410 if(vectorWidget->scale->isChecked())
411 v *= vectorWidget->scaleBox->value();
413 lineNode->add_line( v1, (v1+v) );
414 lineNode->add_color(color);
418 template <
typename MeshT>
425 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
438 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
441 if(vectorWidget->scale->isChecked())
442 v *= vectorWidget->scaleBox->value();
444 lineNode->add_line( v1, (v1+v) );
445 lineNode->add_color(color);
449 template <
typename MeshT>
455 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
456 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
459 typename MeshT::FaceHandle fh = mesh->face_handle(index);
461 mesh->property(prop, fh) = this->strToVec3d(text);
464 template <
typename MeshT>
470 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
471 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
474 typename MeshT::EdgeHandle eh = mesh->edge_handle(index);
476 mesh->property(prop, eh) = this->strToVec3d(text);
479 template <
typename MeshT>
485 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
486 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
489 typename MeshT::HalfedgeHandle heh = mesh->halfedge_handle(index);
491 mesh->property(prop, heh) = this->strToVec3d(text);
494 template <
typename MeshT>
500 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
501 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
504 typename MeshT::VertexHandle vh = mesh->vertex_handle(index);
506 mesh->property(prop, vh) = this->strToVec3d(text);
510 template<
typename MeshT>
516 template<
typename MeshT>
void removeProperty() override
Removes the property.
SeparatorNode * baseNode()
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
QString getPropertyText(unsigned int index) override
Returns the value of a property in text form.
Add colors to mesh item (vertices/faces/edges)
DrawMode HALFEDGES_COLORED
draw halfedges with colors (without shading)
DrawMode SOLID_POINTS_COLORED
draw colored, but not lighted faces using interpolated vertex colors
Cellection of information about a property.
virtual void clear()
Clears the property.
void duplicateProperty() override
Duplicates the property.
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
DrawMode EDGES_COLORED
draw edges with colors (without shading)
virtual void clear() override
Clears the property.
Class for generating nice colors for doubles.
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())