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]);
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> >(
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()) {
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<
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()) {
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<
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()) {
243 if (w->vectors_colors_rb->isChecked()) {
244 visualizeVectorAsColorForEntity2<
247 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
248 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
249 PropertyVisualizer::propertyInfo);
251 visualizeVectorLengthAsColorForEntity2<
254 OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
255 OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
256 PropertyVisualizer::propertyInfo);
262 else visualizeVertexPropAsStrokes();
265 template <
typename MeshT,
typename VectorType>
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) {
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>
326 typename MeshT::Point center(0.0, 0.0, 0.0);
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)) );
350 template <
typename MeshT,
typename VectorType>
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)) );
387 template <
typename MeshT,
typename VectorType>
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)) );
422 template <
typename MeshT,
typename VectorType>
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)) );
454 template <
typename MeshT,
typename VectorType>
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>
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>
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>
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>
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Cellection of information about a property.
virtual void duplicateProperty()
Duplicates the property.
DrawMode HALFEDGES_COLORED
draw halfedges with colors (without shading)
ACG::SceneGraph::BaseNode * getRootNode()
Get the root node for data objects.
virtual void removeProperty()
Removes the property.
void clear()
clear points/lines and colors
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
DrawMode EDGES_COLORED
draw edges with colors (without shading)
Add colors to mesh item (vertices/faces/edges)
virtual QString getPropertyText(unsigned int index)
Returns the value of a property in text form.
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
DrawMode SOLID_POINTS_COLORED
draw colored, but not lighted faces using interpolated vertex colors
void add_color(const ACG::Vec3uc &_c)
add color (only for LineMode == LineSegmentsMode)
virtual void clear()
Clears the property.
virtual void clear()
Clears the property.
Class for generating nice colors for doubles.
void add_line(const Vec3d &_v0, const Vec3d &_v1)
add line (for LineMode == LineSegmentsMode)
VectorT< double, 3 > Vec3d
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .