44 #define OVM_PROPERTY_VISUALIZER_CC 46 #ifdef ENABLE_POLYHEDRALMESH_SUPPORT 49 #ifdef ENABLE_HEXAHEDRALMESH_SUPPORT 52 #ifdef ENABLE_TETRAHEDRALMESH_SUPPORT 56 #include "OVMPropertyVisualizer.hh" 58 #include <ACG/Utils/Histogram.hh> 60 template <
typename MeshT>
61 template <
typename InnerType>
64 if (PropertyVisualizer::propertyInfo.isCellProp())
69 else if (PropertyVisualizer::propertyInfo.isFaceProp())
74 else if (PropertyVisualizer::propertyInfo.isHalffaceProp())
79 else if (PropertyVisualizer::propertyInfo.isEdgeProp())
84 else if (PropertyVisualizer::propertyInfo.isHalfedgeProp())
96 template <
typename MeshT>
99 if (propertyInfo.isCellProp())
100 setCellPropertyFromText(index, text);
101 else if (propertyInfo.isFaceProp())
102 setFacePropertyFromText(index, text);
103 else if (propertyInfo.isHalffaceProp())
104 setHalffacePropertyFromText(index, text);
105 else if (propertyInfo.isEdgeProp())
106 setEdgePropertyFromText(index, text);
107 else if (propertyInfo.isHalfedgeProp())
108 setHalfedgePropertyFromText(index, text);
110 setVertexPropertyFromText(index, text);
113 template <
typename MeshT>
116 if (propertyInfo.isCellProp())
117 return mesh->n_cells();
118 if (propertyInfo.isFaceProp())
119 return mesh->n_faces();
120 if (propertyInfo.isHalffaceProp())
121 return mesh->n_halffaces();
122 else if (propertyInfo.isEdgeProp())
123 return mesh->n_edges();
124 else if (propertyInfo.isHalfedgeProp())
125 return mesh->n_halfedges();
127 return mesh->n_vertices();
130 template <
typename MeshT>
135 QString header = QObject::tr(
"1");
136 header.append(QObject::tr(
", %1").arg(getEntityCount()));
137 header.append(QObject::tr(
", %1").arg(propertyInfo.entityType()));
138 header.append(
", ").append(propertyInfo.friendlyTypeName());
139 header.append(
", ").append(propertyInfo.propName().c_str());
143 template <
typename MeshT>
146 if (propertyInfo.isHalffaceProp())
147 return getClosestHalffaceId(_face, _hitPoint);
149 return getClosestHalfedgeId(_face, _hitPoint);
152 template <
typename MeshT>
165 if ((direction | normal) < 0)
171 template <
typename MeshT>
178 const std::vector<OpenVolumeMesh::HalfEdgeHandle> & halfedges = face.halfedges();
180 double min_distance = DBL_MAX;
183 for (std::vector<OpenVolumeMesh::HalfEdgeHandle>::const_iterator he_it = halfedges.begin(); he_it != halfedges.end(); ++he_it)
186 ACG::Vec3d v1 = mesh->vertex(edge.from_vertex());
187 ACG::Vec3d v2 = mesh->vertex(edge.to_vertex());
189 double distance = (p-_hitPoint).length();
190 if (distance < min_distance)
192 min_distance = distance;
193 closestHalfEdgeHandle = *he_it;
198 return closestHalfEdgeHandle.idx();
202 template <
typename MeshT>
212 if (propertyInfo.isCellProp())
213 visualizeCellProp(_setDrawMode);
214 else if (propertyInfo.isFaceProp())
215 visualizeFaceProp(_setDrawMode);
216 else if (propertyInfo.isHalffaceProp())
217 visualizeHalffaceProp(_setDrawMode);
218 else if (propertyInfo.isEdgeProp())
219 visualizeEdgeProp(_setDrawMode);
220 else if (propertyInfo.isHalfedgeProp())
221 visualizeHalfedgeProp(_setDrawMode);
222 else if (propertyInfo.isVertexProp())
223 visualizeVertexProp(_setDrawMode);
231 template <
typename MeshT>
234 emit log(
LOGERR,
"Visualizing FaceProp not implemented");
237 template <
typename MeshT>
240 emit log(
LOGERR,
"Visualizing EdgeProp not implemented");
243 template <
typename MeshT>
246 emit log(
LOGERR,
"Visualizing HalfedgeProp not implemented");
249 template <
typename MeshT>
252 emit log(
LOGERR,
"Visualizing VertexProp not implemented");
255 template <
typename MeshT>
258 emit log(
LOGERR,
"Visualizing CellProp not implemented");
261 template <
typename MeshT>
264 emit log(
LOGERR,
"Visualizing HalffaceProp not implemented");
267 template<
typename MeshT>
268 template<
typename PropType>
270 std::string newPropertyName;
271 for (
int i = 1;; ++i) {
272 std::ostringstream oss;
273 oss << propertyInfo.propName() <<
" Copy " << i;
274 newPropertyName = oss.str();
276 if (propertyInfo.isCellProp())
278 if(!mesh->template cell_property_exists<PropType>(newPropertyName))
break;
280 else if (propertyInfo.isFaceProp())
282 if(!mesh->template face_property_exists<PropType>(newPropertyName))
break;
284 else if (propertyInfo.isHalffaceProp())
286 if(!mesh->template halfface_property_exists<PropType>(newPropertyName))
break;
288 else if (propertyInfo.isEdgeProp())
290 if(!mesh->template edge_property_exists<PropType>(newPropertyName))
break;
292 else if (propertyInfo.isHalfedgeProp())
294 if(!mesh->template halfedge_property_exists<PropType>(newPropertyName))
break;
296 else if (propertyInfo.isVertexProp())
298 if(!mesh->template vertex_property_exists<PropType>(newPropertyName))
break;
302 if (propertyInfo.isCellProp())
306 mesh->set_persistent(newProp,
true);
309 else if (propertyInfo.isFaceProp())
313 mesh->set_persistent(newProp,
true);
316 else if (propertyInfo.isHalffaceProp())
320 mesh->set_persistent(newProp,
true);
323 else if (propertyInfo.isEdgeProp())
327 mesh->set_persistent(newProp,
true);
330 else if (propertyInfo.isHalfedgeProp())
334 mesh->set_persistent(newProp,
true);
337 else if (propertyInfo.isVertexProp())
341 mesh->set_persistent(newProp,
true);
346 template <
typename MeshT>
352 if (propertyInfo.isCellProp())
353 object->
colors().clear_cell_colors();
354 else if (propertyInfo.isFaceProp())
355 object->
colors().clear_face_colors();
356 else if (propertyInfo.isHalffaceProp())
357 object->
colors().clear_halfface_colors();
358 else if (propertyInfo.isEdgeProp())
359 object->
colors().clear_edge_colors();
360 else if (propertyInfo.isHalfedgeProp())
361 object->
colors().clear_halfedge_colors();
362 else if (propertyInfo.isVertexProp())
363 object->
colors().clear_vertex_colors();
365 object->setObjectDrawMode(drawModes.cellsFlatShaded);
368 template <
typename MeshT>
371 emit log(
LOGERR,
"Setting CellProp not implemented for this property type");
374 template <
typename MeshT>
377 emit log(
LOGERR,
"Setting FaceProp not implemented for this property type");
380 template <
typename MeshT>
383 emit log(
LOGERR,
"Setting HalffaceProp not implemented for this property type");
386 template <
typename MeshT>
389 emit log(
LOGERR,
"Setting EdgeProp not implemented for this property type");
392 template <
typename MeshT>
395 emit log(
LOGERR,
"Setting HalfedgeProp not implemented for this property type");
398 template <
typename MeshT>
401 emit log(
LOGERR,
"Setting VertexProp not implemented for this property type");
404 template<
typename MeshT>
405 template<
typename Type>
409 const std::string &prop_name = PV::propertyInfo.propName();
411 switch (PropertyVisualizer::propertyInfo.entityType()) {
412 case PropertyInfo::EF_CELL:
413 this->showHistogramT<Type>(
415 PV::mesh->template request_cell_property<Type>(prop_name));
417 case PropertyInfo::EF_FACE:
418 this->showHistogramT<Type>(
420 PV::mesh->template request_face_property<Type>(prop_name));
422 case PropertyInfo::EF_HALFFACE:
423 this->showHistogramT<Type>(
425 PV::mesh->template request_halfface_property<Type>(prop_name));
427 case PropertyInfo::EF_EDGE:
428 this->showHistogramT<Type>(
430 PV::mesh->template request_edge_property<Type>(prop_name));
432 case PropertyInfo::EF_HALFEDGE:
433 this->showHistogramT<Type>(
435 PV::mesh->template request_halfedge_property<Type>(prop_name));
437 case PropertyInfo::EF_VERTEX:
438 this->showHistogramT<Type>(
440 PV::mesh->template request_vertex_property<Type>(prop_name));
442 case PropertyInfo::EF_ANY:
virtual QString getHeader()
Returns the header for saving.
virtual void clear()
Clears a property.
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up, int _viewer)
Set the viewing direction.
virtual int getEntityCount()
Returns the number of entities.
virtual void setPropertyFromText(unsigned int index, QString text)
Returns the value of a property in text form.
const ColorAttrib & colors() const
return a pointer to the mesh
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
unsigned int getClosestPrimitiveId(unsigned int _face, ACG::Vec3d &_hitPoint)
Returns the ID of the closest primitive.
virtual void visualize(bool _setDrawMode, QWidget *_widget)
Visualizes a property.