50 #ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
52 #define OVM_PROPERTY_VISUALIZER_CC
54 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
57 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
61 #include "OVMPropertyVisualizer.hh"
63 template <
typename MeshT>
64 template <
typename InnerType>
65 QString OVMPropertyVisualizer<MeshT>::getPropertyText_(
unsigned int index)
67 if (PropertyVisualizer::propertyInfo.isCellProp())
72 else if (PropertyVisualizer::propertyInfo.isFaceProp())
77 else if (PropertyVisualizer::propertyInfo.isHalffaceProp())
82 else if (PropertyVisualizer::propertyInfo.isEdgeProp())
87 else if (PropertyVisualizer::propertyInfo.isHalfedgeProp())
99 template <
typename MeshT>
100 void OVMPropertyVisualizer<MeshT>::setPropertyFromText(
unsigned int index, QString text)
102 if (propertyInfo.isCellProp())
103 setCellPropertyFromText(index, text);
104 else if (propertyInfo.isFaceProp())
105 setFacePropertyFromText(index, text);
106 else if (propertyInfo.isHalffaceProp())
107 setHalffacePropertyFromText(index, text);
108 else if (propertyInfo.isEdgeProp())
109 setEdgePropertyFromText(index, text);
110 else if (propertyInfo.isHalfedgeProp())
111 setHalfedgePropertyFromText(index, text);
113 setVertexPropertyFromText(index, text);
116 template <
typename MeshT>
117 int OVMPropertyVisualizer<MeshT>::getEntityCount()
119 if (propertyInfo.isCellProp())
120 return mesh->n_cells();
121 if (propertyInfo.isFaceProp())
122 return mesh->n_faces();
123 if (propertyInfo.isHalffaceProp())
124 return mesh->n_halffaces();
125 else if (propertyInfo.isEdgeProp())
126 return mesh->n_edges();
127 else if (propertyInfo.isHalfedgeProp())
128 return mesh->n_halfedges();
130 return mesh->n_vertices();
133 template <
typename MeshT>
134 QString OVMPropertyVisualizer<MeshT>::getHeader()
138 QString header = QObject::tr(
"1");
139 header.append(QObject::tr(
", %1").arg(getEntityCount()));
140 header.append(QObject::tr(
", %1").arg(propertyInfo.entityType()));
141 header.append(
", ").append(propertyInfo.friendlyTypeName());
142 header.append(
", ").append(propertyInfo.propName().c_str());
146 template <
typename MeshT>
147 unsigned int OVMPropertyVisualizer<MeshT>::getClosestPrimitiveId(
unsigned int _face,
ACG::Vec3d& _hitPoint)
149 if (propertyInfo.isHalffaceProp())
150 return getClosestHalffaceId(_face, _hitPoint);
152 return getClosestHalfedgeId(_face, _hitPoint);
155 template <
typename MeshT>
156 unsigned int OVMPropertyVisualizer<MeshT>::getClosestHalffaceId(
unsigned int _face,
ACG::Vec3d& _hitPoint)
168 if ((direction | normal) < 0)
174 template <
typename MeshT>
175 unsigned int OVMPropertyVisualizer<MeshT>::getClosestHalfedgeId(
unsigned int _face,
ACG::Vec3d& _hitPoint)
177 unsigned int halfface = getClosestHalffaceId(_face, _hitPoint);
181 const std::vector<OpenVolumeMesh::HalfEdgeHandle> & halfedges = face.halfedges();
183 double min_distance = DBL_MAX;
186 for (std::vector<OpenVolumeMesh::HalfEdgeHandle>::const_iterator he_it = halfedges.begin(); he_it != halfedges.end(); ++he_it)
189 ACG::Vec3d v1 = mesh->vertex(edge.from_vertex());
190 ACG::Vec3d v2 = mesh->vertex(edge.to_vertex());
192 double distance = (p-_hitPoint).length();
193 if (distance < min_distance)
195 min_distance = distance;
196 closestHalfEdgeHandle = *he_it;
201 return closestHalfEdgeHandle.idx();
205 template <
typename MeshT>
206 void OVMPropertyVisualizer<MeshT>::visualize(
bool _setDrawMode, QWidget* _widget)
215 if (propertyInfo.isCellProp())
216 visualizeCellProp(_setDrawMode);
217 else if (propertyInfo.isFaceProp())
218 visualizeFaceProp(_setDrawMode);
219 else if (propertyInfo.isHalffaceProp())
220 visualizeHalffaceProp(_setDrawMode);
221 else if (propertyInfo.isEdgeProp())
222 visualizeEdgeProp(_setDrawMode);
223 else if (propertyInfo.isHalfedgeProp())
224 visualizeHalfedgeProp(_setDrawMode);
225 else if (propertyInfo.isVertexProp())
226 visualizeVertexProp(_setDrawMode);
234 template <
typename MeshT>
235 OpenMesh::Vec4f OVMPropertyVisualizer<MeshT>::convertColor(
const QColor _color){
239 color[0] = _color.redF();
240 color[1] = _color.greenF();
241 color[2] = _color.blueF();
242 color[3] = _color.alphaF();
247 template <
typename MeshT>
248 void OVMPropertyVisualizer<MeshT>::visualizeFaceProp(
bool )
250 emit log(
LOGERR,
"Visualizing FaceProp not implemented");
253 template <
typename MeshT>
254 void OVMPropertyVisualizer<MeshT>::visualizeEdgeProp(
bool )
256 emit log(
LOGERR,
"Visualizing EdgeProp not implemented");
259 template <
typename MeshT>
260 void OVMPropertyVisualizer<MeshT>::visualizeHalfedgeProp(
bool )
262 emit log(
LOGERR,
"Visualizing HalfedgeProp not implemented");
265 template <
typename MeshT>
266 void OVMPropertyVisualizer<MeshT>::visualizeVertexProp(
bool )
268 emit log(
LOGERR,
"Visualizing VertexProp not implemented");
271 template <
typename MeshT>
272 void OVMPropertyVisualizer<MeshT>::visualizeCellProp(
bool )
274 emit log(
LOGERR,
"Visualizing CellProp not implemented");
277 template <
typename MeshT>
278 void OVMPropertyVisualizer<MeshT>::visualizeHalffaceProp(
bool )
280 emit log(
LOGERR,
"Visualizing HalffaceProp not implemented");
283 template<
typename MeshT>
284 template<
typename PropType>
285 inline void OVMPropertyVisualizer<MeshT>::duplicateProperty_stage1() {
286 std::string newPropertyName;
287 for (
int i = 1;; ++i) {
288 std::ostringstream oss;
289 oss << propertyInfo.propName() <<
" Copy " << i;
290 newPropertyName = oss.str();
292 if (propertyInfo.isCellProp())
294 if(!mesh->template cell_property_exists<PropType>(newPropertyName))
break;
296 else if (propertyInfo.isFaceProp())
298 if(!mesh->template face_property_exists<PropType>(newPropertyName))
break;
300 else if (propertyInfo.isHalffaceProp())
302 if(!mesh->template halfface_property_exists<PropType>(newPropertyName))
break;
304 else if (propertyInfo.isEdgeProp())
306 if(!mesh->template edge_property_exists<PropType>(newPropertyName))
break;
308 else if (propertyInfo.isHalfedgeProp())
310 if(!mesh->template halfedge_property_exists<PropType>(newPropertyName))
break;
312 else if (propertyInfo.isVertexProp())
314 if(!mesh->template vertex_property_exists<PropType>(newPropertyName))
break;
318 if (propertyInfo.isCellProp())
322 mesh->set_persistent(newProp,
true);
323 std::for_each(mesh->cells_begin(), mesh->cells_end(), CopyProperty<OpenVolumeMesh::CellPropertyT<PropType> >(newProp, prop, mesh));
325 else if (propertyInfo.isFaceProp())
329 mesh->set_persistent(newProp,
true);
330 std::for_each(mesh->faces_begin(), mesh->faces_end(), CopyProperty<OpenVolumeMesh::FacePropertyT<PropType> >(newProp, prop, mesh));
332 else if (propertyInfo.isHalffaceProp())
336 mesh->set_persistent(newProp,
true);
337 std::for_each(mesh->halffaces_begin(), mesh->halffaces_end(), CopyProperty<OpenVolumeMesh::HalfFacePropertyT<PropType> >(newProp, prop, mesh));
339 else if (propertyInfo.isEdgeProp())
343 mesh->set_persistent(newProp,
true);
344 std::for_each(mesh->edges_begin(), mesh->edges_end(), CopyProperty<OpenVolumeMesh::EdgePropertyT<PropType> >(newProp, prop, mesh));
346 else if (propertyInfo.isHalfedgeProp())
350 mesh->set_persistent(newProp,
true);
351 std::for_each(mesh->halfedges_begin(), mesh->halfedges_end(), CopyProperty<OpenVolumeMesh::HalfEdgePropertyT<PropType> >(newProp, prop, mesh));
353 else if (propertyInfo.isVertexProp())
357 mesh->set_persistent(newProp,
true);
358 std::for_each(mesh->vertices_begin(), mesh->vertices_end(), CopyProperty<OpenVolumeMesh::VertexPropertyT<PropType> >(newProp, prop, mesh));
362 template <
typename MeshT>
363 void OVMPropertyVisualizer<MeshT>::clear()
368 if (propertyInfo.isCellProp())
369 object->
colors().clear_cell_colors();
370 else if (propertyInfo.isFaceProp())
371 object->
colors().clear_face_colors();
372 else if (propertyInfo.isHalffaceProp())
373 object->
colors().clear_halfface_colors();
374 else if (propertyInfo.isEdgeProp())
375 object->
colors().clear_edge_colors();
376 else if (propertyInfo.isHalfedgeProp())
377 object->
colors().clear_halfedge_colors();
378 else if (propertyInfo.isVertexProp())
379 object->
colors().clear_vertex_colors();
381 object->setObjectDrawMode(drawModes.cellsFlatShaded);
384 template <
typename MeshT>
385 void OVMPropertyVisualizer<MeshT>::setCellPropertyFromText(
unsigned int , QString )
387 emit log(
LOGERR,
"Setting CellProp not implemented for this property type");
390 template <
typename MeshT>
391 void OVMPropertyVisualizer<MeshT>::setFacePropertyFromText(
unsigned int , QString )
393 emit log(
LOGERR,
"Setting FaceProp not implemented for this property type");
396 template <
typename MeshT>
397 void OVMPropertyVisualizer<MeshT>::setHalffacePropertyFromText(
unsigned int , QString )
399 emit log(
LOGERR,
"Setting HalffaceProp not implemented for this property type");
402 template <
typename MeshT>
403 void OVMPropertyVisualizer<MeshT>::setEdgePropertyFromText(
unsigned int , QString )
405 emit log(
LOGERR,
"Setting EdgeProp not implemented for this property type");
408 template <
typename MeshT>
409 void OVMPropertyVisualizer<MeshT>::setHalfedgePropertyFromText(
unsigned int , QString )
411 emit log(
LOGERR,
"Setting HalfedgeProp not implemented for this property type");
414 template <
typename MeshT>
415 void OVMPropertyVisualizer<MeshT>::setVertexPropertyFromText(
unsigned int , QString )
417 emit log(
LOGERR,
"Setting VertexProp not implemented for this property type");
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up, int _viewer)
Set the viewing direction.
bool getObject(int _identifier, BSplineCurveObject *&_object)
const ColorAttrib & colors() const
return a pointer to the mesh
Property classes for the different entity types.