50 #ifdef ENABLE_OPENVOLUMEMESH_SUPPORT 52 #define OVM_PROPERTY_VISUALIZER_CC 54 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT 57 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT 60 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT 64 #include "OVMPropertyVisualizer.hh" 66 template <
typename MeshT>
67 template <
typename InnerType>
68 QString OVMPropertyVisualizer<MeshT>::getPropertyText_(
unsigned int index)
70 if (PropertyVisualizer::propertyInfo.isCellProp())
75 else if (PropertyVisualizer::propertyInfo.isFaceProp())
80 else if (PropertyVisualizer::propertyInfo.isHalffaceProp())
85 else if (PropertyVisualizer::propertyInfo.isEdgeProp())
90 else if (PropertyVisualizer::propertyInfo.isHalfedgeProp())
102 template <
typename MeshT>
103 void OVMPropertyVisualizer<MeshT>::setPropertyFromText(
unsigned int index, QString text)
105 if (propertyInfo.isCellProp())
106 setCellPropertyFromText(index, text);
107 else if (propertyInfo.isFaceProp())
108 setFacePropertyFromText(index, text);
109 else if (propertyInfo.isHalffaceProp())
110 setHalffacePropertyFromText(index, text);
111 else if (propertyInfo.isEdgeProp())
112 setEdgePropertyFromText(index, text);
113 else if (propertyInfo.isHalfedgeProp())
114 setHalfedgePropertyFromText(index, text);
116 setVertexPropertyFromText(index, text);
119 template <
typename MeshT>
120 int OVMPropertyVisualizer<MeshT>::getEntityCount()
122 if (propertyInfo.isCellProp())
123 return mesh->n_cells();
124 if (propertyInfo.isFaceProp())
125 return mesh->n_faces();
126 if (propertyInfo.isHalffaceProp())
127 return mesh->n_halffaces();
128 else if (propertyInfo.isEdgeProp())
129 return mesh->n_edges();
130 else if (propertyInfo.isHalfedgeProp())
131 return mesh->n_halfedges();
133 return mesh->n_vertices();
136 template <
typename MeshT>
137 QString OVMPropertyVisualizer<MeshT>::getHeader()
141 QString header = QObject::tr(
"1");
142 header.append(QObject::tr(
", %1").arg(getEntityCount()));
143 header.append(QObject::tr(
", %1").arg(propertyInfo.entityType()));
144 header.append(
", ").append(propertyInfo.friendlyTypeName());
145 header.append(
", ").append(propertyInfo.propName().c_str());
149 template <
typename MeshT>
150 unsigned int OVMPropertyVisualizer<MeshT>::getClosestPrimitiveId(
unsigned int _face,
ACG::Vec3d& _hitPoint)
152 if (propertyInfo.isHalffaceProp())
153 return getClosestHalffaceId(_face, _hitPoint);
155 return getClosestHalfedgeId(_face, _hitPoint);
158 template <
typename MeshT>
159 unsigned int OVMPropertyVisualizer<MeshT>::getClosestHalffaceId(
unsigned int _face,
ACG::Vec3d& _hitPoint)
171 if ((direction | normal) < 0)
177 template <
typename MeshT>
178 unsigned int OVMPropertyVisualizer<MeshT>::getClosestHalfedgeId(
unsigned int _face,
ACG::Vec3d& _hitPoint)
180 unsigned int halfface = getClosestHalffaceId(_face, _hitPoint);
184 const std::vector<OpenVolumeMesh::HalfEdgeHandle> & halfedges = face.halfedges();
186 double min_distance = DBL_MAX;
189 for (std::vector<OpenVolumeMesh::HalfEdgeHandle>::const_iterator he_it = halfedges.begin(); he_it != halfedges.end(); ++he_it)
192 ACG::Vec3d v1 = mesh->vertex(edge.from_vertex());
193 ACG::Vec3d v2 = mesh->vertex(edge.to_vertex());
195 double distance = (p-_hitPoint).length();
196 if (distance < min_distance)
198 min_distance = distance;
199 closestHalfEdgeHandle = *he_it;
204 return closestHalfEdgeHandle.idx();
208 template <
typename MeshT>
209 void OVMPropertyVisualizer<MeshT>::visualize(
bool _setDrawMode, QWidget* _widget)
218 if (propertyInfo.isCellProp())
219 visualizeCellProp(_setDrawMode);
220 else if (propertyInfo.isFaceProp())
221 visualizeFaceProp(_setDrawMode);
222 else if (propertyInfo.isHalffaceProp())
223 visualizeHalffaceProp(_setDrawMode);
224 else if (propertyInfo.isEdgeProp())
225 visualizeEdgeProp(_setDrawMode);
226 else if (propertyInfo.isHalfedgeProp())
227 visualizeHalfedgeProp(_setDrawMode);
228 else if (propertyInfo.isVertexProp())
229 visualizeVertexProp(_setDrawMode);
237 template <
typename MeshT>
238 OpenMesh::Vec4f OVMPropertyVisualizer<MeshT>::convertColor(
const QColor _color){
242 color[0] = _color.redF();
243 color[1] = _color.greenF();
244 color[2] = _color.blueF();
245 color[3] = _color.alphaF();
250 template <
typename MeshT>
251 void OVMPropertyVisualizer<MeshT>::visualizeFaceProp(
bool )
253 emit log(
LOGERR,
"Visualizing FaceProp not implemented");
256 template <
typename MeshT>
257 void OVMPropertyVisualizer<MeshT>::visualizeEdgeProp(
bool )
259 emit log(
LOGERR,
"Visualizing EdgeProp not implemented");
262 template <
typename MeshT>
263 void OVMPropertyVisualizer<MeshT>::visualizeHalfedgeProp(
bool )
265 emit log(
LOGERR,
"Visualizing HalfedgeProp not implemented");
268 template <
typename MeshT>
269 void OVMPropertyVisualizer<MeshT>::visualizeVertexProp(
bool )
271 emit log(
LOGERR,
"Visualizing VertexProp not implemented");
274 template <
typename MeshT>
275 void OVMPropertyVisualizer<MeshT>::visualizeCellProp(
bool )
277 emit log(
LOGERR,
"Visualizing CellProp not implemented");
280 template <
typename MeshT>
281 void OVMPropertyVisualizer<MeshT>::visualizeHalffaceProp(
bool )
283 emit log(
LOGERR,
"Visualizing HalffaceProp not implemented");
286 template<
typename MeshT>
287 template<
typename PropType>
288 inline void OVMPropertyVisualizer<MeshT>::duplicateProperty_stage1() {
289 std::string newPropertyName;
290 for (
int i = 1;; ++i) {
291 std::ostringstream oss;
292 oss << propertyInfo.propName() <<
" Copy " << i;
293 newPropertyName = oss.str();
295 if (propertyInfo.isCellProp())
297 if(!mesh->template cell_property_exists<PropType>(newPropertyName))
break;
299 else if (propertyInfo.isFaceProp())
301 if(!mesh->template face_property_exists<PropType>(newPropertyName))
break;
303 else if (propertyInfo.isHalffaceProp())
305 if(!mesh->template halfface_property_exists<PropType>(newPropertyName))
break;
307 else if (propertyInfo.isEdgeProp())
309 if(!mesh->template edge_property_exists<PropType>(newPropertyName))
break;
311 else if (propertyInfo.isHalfedgeProp())
313 if(!mesh->template halfedge_property_exists<PropType>(newPropertyName))
break;
315 else if (propertyInfo.isVertexProp())
317 if(!mesh->template vertex_property_exists<PropType>(newPropertyName))
break;
321 if (propertyInfo.isCellProp())
325 mesh->set_persistent(newProp,
true);
326 std::for_each(mesh->cells_begin(), mesh->cells_end(), CopyProperty<OpenVolumeMesh::CellPropertyT<PropType> >(newProp, prop, mesh));
328 else if (propertyInfo.isFaceProp())
332 mesh->set_persistent(newProp,
true);
333 std::for_each(mesh->faces_begin(), mesh->faces_end(), CopyProperty<OpenVolumeMesh::FacePropertyT<PropType> >(newProp, prop, mesh));
335 else if (propertyInfo.isHalffaceProp())
339 mesh->set_persistent(newProp,
true);
340 std::for_each(mesh->halffaces_begin(), mesh->halffaces_end(), CopyProperty<OpenVolumeMesh::HalfFacePropertyT<PropType> >(newProp, prop, mesh));
342 else if (propertyInfo.isEdgeProp())
346 mesh->set_persistent(newProp,
true);
347 std::for_each(mesh->edges_begin(), mesh->edges_end(), CopyProperty<OpenVolumeMesh::EdgePropertyT<PropType> >(newProp, prop, mesh));
349 else if (propertyInfo.isHalfedgeProp())
353 mesh->set_persistent(newProp,
true);
354 std::for_each(mesh->halfedges_begin(), mesh->halfedges_end(), CopyProperty<OpenVolumeMesh::HalfEdgePropertyT<PropType> >(newProp, prop, mesh));
356 else if (propertyInfo.isVertexProp())
360 mesh->set_persistent(newProp,
true);
361 std::for_each(mesh->vertices_begin(), mesh->vertices_end(), CopyProperty<OpenVolumeMesh::VertexPropertyT<PropType> >(newProp, prop, mesh));
365 template <
typename MeshT>
366 void OVMPropertyVisualizer<MeshT>::clear()
371 if (propertyInfo.isCellProp())
372 object->
colors().clear_cell_colors();
373 else if (propertyInfo.isFaceProp())
374 object->
colors().clear_face_colors();
375 else if (propertyInfo.isHalffaceProp())
376 object->
colors().clear_halfface_colors();
377 else if (propertyInfo.isEdgeProp())
378 object->
colors().clear_edge_colors();
379 else if (propertyInfo.isHalfedgeProp())
380 object->
colors().clear_halfedge_colors();
381 else if (propertyInfo.isVertexProp())
382 object->
colors().clear_vertex_colors();
384 object->setObjectDrawMode(drawModes.cellsFlatShaded);
387 template <
typename MeshT>
388 void OVMPropertyVisualizer<MeshT>::setCellPropertyFromText(
unsigned int , QString )
390 emit log(
LOGERR,
"Setting CellProp not implemented for this property type");
393 template <
typename MeshT>
394 void OVMPropertyVisualizer<MeshT>::setFacePropertyFromText(
unsigned int , QString )
396 emit log(
LOGERR,
"Setting FaceProp not implemented for this property type");
399 template <
typename MeshT>
400 void OVMPropertyVisualizer<MeshT>::setHalffacePropertyFromText(
unsigned int , QString )
402 emit log(
LOGERR,
"Setting HalffaceProp not implemented for this property type");
405 template <
typename MeshT>
406 void OVMPropertyVisualizer<MeshT>::setEdgePropertyFromText(
unsigned int , QString )
408 emit log(
LOGERR,
"Setting EdgeProp not implemented for this property type");
411 template <
typename MeshT>
412 void OVMPropertyVisualizer<MeshT>::setHalfedgePropertyFromText(
unsigned int , QString )
414 emit log(
LOGERR,
"Setting HalfedgeProp not implemented for this property type");
417 template <
typename MeshT>
418 void OVMPropertyVisualizer<MeshT>::setVertexPropertyFromText(
unsigned int , QString )
420 emit log(
LOGERR,
"Setting VertexProp not implemented for this property type");
const ColorAttrib & colors() const
return a pointer to the mesh
bool getObject(int _identifier, BSplineCurveObject *&_object)
Property classes for the different entity types.
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up, int _viewer)
Set the viewing direction.