43 #define OM_PROPERTY_VISUALIZER_VECTOR2_CC 45 #include "OMPropertyVisualizerVector2.hh" 46 #include <OpenMesh/Core/Utils/Property.hh> 47 #include <ACG/Utils/ColorConversion.hh> 49 template <
typename MeshT,
typename VectorType>
53 if (PropertyVisualizer::widget)
delete PropertyVisualizer::widget;
55 w->paramVector->setTitle(QString(
"2D 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,
typename VectorType>
78 template <
typename MeshT,
typename VectorType>
87 template<
typename PROPTYPE,
typename VectorType,
typename MeshT,
typename ENTITY_IT,
typename PROPINFO_TYPE>
88 void visualizeVectorAsColorForEntity2(MeshT *mesh,
const ENTITY_IT e_begin,
const ENTITY_IT e_end,
89 const PROPINFO_TYPE &propinfo) {
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 VectorType v = mesh->property(prop, *e_it).normalized() * .5 + VectorType(0.5);
95 mesh->set_color(*e_it,
typename MeshT::Color(v[0], v[1], 0.0, 1.0));
99 template<
typename PROPTYPE,
typename MeshT,
typename ENTITY_IT,
typename PROPINFO_TYPE>
100 void visualizeVectorLengthAsColorForEntity2(
101 MeshT *mesh,
const ENTITY_IT e_begin,
const ENTITY_IT e_end,
102 const PROPINFO_TYPE &propinfo) {
104 if (!mesh->get_property_handle(prop, propinfo.propName()))
105 throw VizException(
"Getting PropHandle from mesh for selected " 108 double min = std::numeric_limits<double>::infinity();
109 double max = -std::numeric_limits<double>::infinity();
111 for (ENTITY_IT e_it = e_begin; e_it != e_end; ++e_it) {
112 const double val = mesh->property(prop, *e_it).norm();
113 min = std::min(min, val);
114 max = std::max(max, val);
119 for (ENTITY_IT e_it = e_begin; e_it != e_end; ++e_it) {
120 mesh->set_color(*e_it, color_coder(mesh->property(prop, *e_it).norm()));
124 template <
typename VectorType>
ACG::Vec3d generateVec3AtLocation(VectorType uv,
ACG::Vec3d normal)
127 if(std::abs(normal[0]) > std::abs(normal[1]))
129 else tan =
ACG::Vec3d(0, normal[2], -normal[1]);
136 template <
typename MeshT,
typename VectorType>
140 if (w->vectors_edges_rb->isChecked()) {
141 visualizeFacePropOnEdges();
142 }
else if (w->vectors_colors_rb->isChecked() ||
143 w->vectors_length_color_rb->isChecked()) {
147 if (w->vectors_colors_rb->isChecked()) {
148 visualizeVectorAsColorForEntity2<OpenMesh::FPropHandleT<VectorType>, VectorType >(
150 OMPropertyVisualizer<MeshT>::mesh->faces_begin(),
151 OMPropertyVisualizer<MeshT>::mesh->faces_end(),
152 PropertyVisualizer::propertyInfo);
154 visualizeVectorLengthAsColorForEntity2<OpenMesh::FPropHandleT<VectorType> >(
156 OMPropertyVisualizer<MeshT>::mesh->faces_begin(),
157 OMPropertyVisualizer<MeshT>::mesh->faces_end(),
158 PropertyVisualizer::propertyInfo);
163 else visualizeFacePropAsStrokes();
166 template <
typename MeshT,
typename VectorType>
170 if (w->vectors_colors_rb->isChecked() ||
171 w->vectors_length_color_rb->isChecked()) {
175 if ( !mesh->has_edge_colors() )
176 mesh->request_edge_colors();
177 if (w->vectors_colors_rb->isChecked()) {
178 visualizeVectorAsColorForEntity2<
183 PropertyVisualizer::propertyInfo);
185 visualizeVectorLengthAsColorForEntity2<
190 PropertyVisualizer::propertyInfo);
195 else visualizeEdgePropAsStrokes();
198 template <
typename MeshT,
typename VectorType>
202 if (w->vectors_colors_rb->isChecked() ||
203 w->vectors_length_color_rb->isChecked()) {
207 if ( ! mesh->has_halfedge_colors() )
208 mesh->request_halfedge_colors();
210 if (w->vectors_colors_rb->isChecked()) {
211 visualizeVectorAsColorForEntity2<
214 mesh->halfedges_begin(),
215 mesh->halfedges_end(),
216 PropertyVisualizer::propertyInfo);
218 visualizeVectorLengthAsColorForEntity2<
221 mesh->halfedges_begin(),
222 mesh->halfedges_end(),
223 PropertyVisualizer::propertyInfo);
230 else visualizeHalfedgePropAsStrokes();
233 template <
typename MeshT,
typename VectorType>
237 if (w->vectors_colors_rb->isChecked() ||
238 w->vectors_length_color_rb->isChecked()) {
242 if (w->vectors_colors_rb->isChecked()) {
243 visualizeVectorAsColorForEntity2<
246 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
247 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
248 PropertyVisualizer::propertyInfo);
250 visualizeVectorLengthAsColorForEntity2<
253 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
254 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
255 PropertyVisualizer::propertyInfo);
261 else visualizeVertexPropAsStrokes();
264 template <
typename MeshT,
typename VectorType>
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 VectorType p1 = _mesh->property(prop, _mesh->face_handle(_mesh->halfedge_handle(*e_it, 0)));
283 VectorType 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,
double(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,
typename VectorType>
316 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
325 typename MeshT::Point center(0.0, 0.0, 0.0);
338 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
341 if(vectorWidget->scale->isChecked())
342 v *= vectorWidget->scaleBox->value();
344 lineNode->
add_line( center, (center+generateVec3AtLocation<VectorType>(v, normal)) );
349 template <
typename MeshT,
typename VectorType>
356 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
375 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
378 if(vectorWidget->scale->isChecked())
379 v *= vectorWidget->scaleBox->value();
381 lineNode->
add_line( v1, (v1+generateVec3AtLocation<VectorType>(v, normal)) );
386 template <
typename MeshT,
typename VectorType>
393 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
410 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
413 if(vectorWidget->scale->isChecked())
414 v *= vectorWidget->scaleBox->value();
416 lineNode->
add_line( v1, (v1+generateVec3AtLocation<VectorType>(v, normal)) );
421 template <
typename MeshT,
typename VectorType>
428 typename MeshT::Color color = ACG::to_Vec4f(vectorWidget->lineColor->color());
442 if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
445 if(vectorWidget->scale->isChecked())
446 v *= vectorWidget->scaleBox->value();
448 lineNode->
add_line( v1, (v1+generateVec3AtLocation<VectorType>(v, normal)) );
453 template <
typename MeshT,
typename VectorType>
459 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
460 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
463 typename MeshT::FaceHandle fh = mesh->face_handle(index);
465 mesh->property(prop, fh) = this->strToVec2f(text);
468 template <
typename MeshT,
typename VectorType>
474 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
475 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
478 typename MeshT::EdgeHandle eh = mesh->edge_handle(index);
480 mesh->property(prop, eh) = this->strToVec2f(text);
483 template <
typename MeshT,
typename VectorType>
489 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
490 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
493 typename MeshT::HalfedgeHandle heh = mesh->halfedge_handle(index);
495 mesh->property(prop, heh) = this->strToVec2f(text);
498 template <
typename MeshT,
typename VectorType>
504 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
505 emit this->log(
LOGERR, QObject::tr(
"Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
508 typename MeshT::VertexHandle vh = mesh->vertex_handle(index);
510 mesh->property(prop, vh) = this->strToVec2f(text);
514 template <
typename MeshT,
typename VectorType>
520 template <
typename MeshT,
typename VectorType>
QString getPropertyText(unsigned int index) override
Returns the value of a property in text form.
SeparatorNode * baseNode()
void add_line(const Vec3d &_v0, const Vec3d &_v1)
add line (for LineMode == LineSegmentsMode)
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
void clear()
clear points/lines and colors
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.
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
void duplicateProperty() override
Duplicates the property.
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
void clear() override
Clears the property.
DrawMode EDGES_COLORED
draw edges with colors (without shading)
Class for generating nice colors for doubles.
void add_color(const ACG::Vec3uc &_c)
add color (only for LineMode == LineSegmentsMode)
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
void removeProperty() override
Removes the property.
VectorT< double, 3 > Vec3d