45 #define OM_PROPERTY_VISUALIZER_CC 47 #include "OMPropertyVisualizer.hh" 53 template <
typename EntityType,
typename Handle,
typename MeshT>
54 QString getPropertyText__(Handle handle, MeshT mesh,
const PropertyInfo& propInfo)
58 if ( !mesh->get_property_handle(prop, propInfo.propName() ) )
59 return QObject::tr(
"Error: No property with name ").append(propInfo.propName().c_str());
61 return PropertyVisualizer::toStr(mesh->property(prop, handle));
67 template <
typename MeshT>
68 template <
typename InnerType>
72 if (PropertyVisualizer::propertyInfo.isFaceProp())
74 else if (PropertyVisualizer::propertyInfo.isEdgeProp())
76 else if (PropertyVisualizer::propertyInfo.isHalfedgeProp())
83 template<
typename MeshT>
84 template<
typename PropHandle>
86 PropHandle propHandle;
87 if (!mesh->get_property_handle(propHandle, propertyInfo.propName()))
return;
88 mesh->remove_property(propHandle);
91 template<
typename MeshT>
92 template<
typename PropType>
94 if (propertyInfo.isEdgeProp())
96 else if (propertyInfo.isVertexProp())
98 else if (propertyInfo.isFaceProp())
100 else if (propertyInfo.isHalfedgeProp())
105 template<
typename MeshT>
106 template<
typename PropHandle,
typename Iterator>
108 PropHandle propHandle;
109 if (!mesh->get_property_handle(propHandle, propertyInfo.propName()))
return;
111 std::string newPropertyName;
112 for (
int i = 1;; ++i) {
113 std::ostringstream oss;
114 oss << propertyInfo.propName() <<
" Copy " << i;
115 newPropertyName = oss.str();
118 if (!mesh->get_property_handle(tmp, newPropertyName))
break;
121 PropHandle newProperty;
122 mesh->add_property(newProperty, newPropertyName);
123 std::for_each(first, last, CopyProperty<PropHandle>(newProperty, propHandle, mesh));
126 template<
typename MeshT>
127 template<
typename PropType>
129 if (propertyInfo.isEdgeProp())
131 else if (propertyInfo.isVertexProp())
133 else if (propertyInfo.isFaceProp())
135 else if (propertyInfo.isHalfedgeProp())
141 template <
typename MeshT>
148 template <
typename MeshT>
151 if (propertyInfo.isFaceProp())
152 setFacePropertyFromText(index, text);
153 else if (propertyInfo.isEdgeProp())
154 setEdgePropertyFromText(index, text);
155 else if (propertyInfo.isHalfedgeProp())
156 setHalfedgePropertyFromText(index, text);
158 setVertexPropertyFromText(index, text);
161 template <
typename MeshT>
164 if (propertyInfo.isFaceProp())
165 return mesh->n_faces();
166 else if (propertyInfo.isEdgeProp())
167 return mesh->n_edges();
168 else if (propertyInfo.isHalfedgeProp())
169 return mesh->n_halfedges();
171 return mesh->n_vertices();
174 template <
typename MeshT>
179 QString header = QObject::tr(
"1");
180 header.append(QObject::tr(
", %1").arg(getEntityCount()));
181 header.append(QObject::tr(
", %1").arg(propertyInfo.entityType()));
182 header.append(
", ").append(propertyInfo.friendlyTypeName());
183 header.append(
", ").append(propertyInfo.propName().c_str());
199 template <
typename MeshT>
202 if (propertyInfo.isFaceProp())
203 return getClosestFaceId(_face, _hitPoint);
204 else if (propertyInfo.isEdgeProp())
205 return getClosestEdgeId(_face, _hitPoint);
206 else if (propertyInfo.isHalfedgeProp())
207 return getClosestHalfedgeId(_face, _hitPoint);
209 return getClosestVertexId(_face, _hitPoint);
212 template <
typename MeshT>
218 template <
typename MeshT>
221 unsigned int closest_halfedge_id = getClosestHalfedgeId(_face, _hitPoint);
222 typename MeshT::HalfedgeHandle heh;
223 heh = mesh->halfedge_handle(closest_halfedge_id);
225 typename MeshT::EdgeHandle eh;
226 eh = mesh->edge_handle(heh);
231 template <
typename MeshT>
234 typename MeshT::FaceHalfedgeIter fh_it;
236 int closest_h_idx = 0;
237 double dist = DBL_MAX;
240 typename MeshT::Point p;
242 for (fh_it = mesh->fh_iter(mesh->face_handle(_face)); fh_it.is_valid(); ++fh_it){
244 typename MeshT::HalfedgeHandle heh;
247 typename MeshT::VertexHandle v1;
248 v1 = mesh->to_vertex_handle(heh);
249 typename MeshT::VertexHandle v2;
250 v2 = mesh->from_vertex_handle(heh);
252 p = 0.5* (mesh->point( v1 ) + mesh->point( v2 ));
256 const double temp_dist = (vTemp - _hitPoint).length();
258 if (temp_dist < dist) {
260 closest_h_idx = fh_it->idx();
264 return closest_h_idx;
267 template <
typename MeshT>
270 typename MeshT::FaceVertexIter fv_it;
272 int closest_v_idx = 0;
273 double dist = DBL_MAX;
276 typename MeshT::Point p;
278 for (fv_it = mesh->fv_iter(mesh->face_handle(_face)); fv_it.is_valid(); ++fv_it){
280 p = mesh->point( *fv_it );
284 const double temp_dist = (vTemp - _hitPoint).length();
286 if (temp_dist < dist) {
288 closest_v_idx = fv_it->idx();
292 return closest_v_idx;
302 template <
typename MeshT>
312 if (propertyInfo.isFaceProp())
313 visualizeFaceProp(_setDrawMode);
314 else if (propertyInfo.isEdgeProp())
315 visualizeEdgeProp(_setDrawMode);
316 else if (propertyInfo.isHalfedgeProp())
317 visualizeHalfedgeProp(_setDrawMode);
318 else if (propertyInfo.isVertexProp())
319 visualizeVertexProp(_setDrawMode);
332 template <
typename MeshT>
335 if (propertyInfo.isFaceProp())
337 else if (propertyInfo.isEdgeProp())
339 else if (propertyInfo.isHalfedgeProp())
341 else if (propertyInfo.isVertexProp())
345 template <
typename MeshT>
348 emit log(
LOGERR,
"Visualizing FaceProp not implemented");
351 template <
typename MeshT>
354 emit log(
LOGERR,
"Visualizing EdgeProp not implemented");
357 template <
typename MeshT>
360 emit log(
LOGERR,
"Visualizing HalfedgeProp not implemented");
363 template <
typename MeshT>
366 emit log(
LOGERR,
"Visualizing VertexProp not implemented");
369 template <
typename MeshT>
372 if ( mesh->has_face_colors() )
376 template <
typename MeshT>
379 if ( mesh->has_edge_colors() )
383 template <
typename MeshT>
386 if ( mesh->has_halfedge_colors() )
390 template <
typename MeshT>
393 if ( mesh->has_vertex_colors() )
397 template <
typename MeshT>
400 emit log(
LOGERR,
"Setting face property not implemented");
403 template <
typename MeshT>
406 emit log(
LOGERR,
"Settingedge property not implemented");
409 template <
typename MeshT>
412 emit log(
LOGERR,
"Setting halfedge property not implemented");
415 template <
typename MeshT>
418 emit log(
LOGERR,
"Setting vertex property not implemented");
422 template<
typename MeshT>
423 template<
typename Type>
426 const std::string &prop_name = PV::propertyInfo.propName();
430 switch (PropertyVisualizer::propertyInfo.entityType()) {
431 case PropertyInfo::EF_FACE:
434 if (!PV::mesh->get_property_handle(prop_handle, prop_name))
break;
435 PropertyVisualizer::template showHistogramT<Type>(
437 PV::mesh->property(prop_handle).data_vector());
440 case PropertyInfo::EF_EDGE:
443 if (!PV::mesh->get_property_handle(prop_handle, prop_name))
break;
444 PropertyVisualizer::template showHistogramT<Type>(
446 PV::mesh->property(prop_handle).data_vector());
449 case PropertyInfo::EF_HALFEDGE:
452 if (!PV::mesh->get_property_handle(prop_handle, prop_name))
break;
453 PropertyVisualizer::template showHistogramT<Type>(
455 PV::mesh->property(prop_handle).data_vector());
458 case PropertyInfo::EF_VERTEX:
461 if (!PV::mesh->get_property_handle(prop_handle, prop_name))
break;
462 PropertyVisualizer::template showHistogramT<Type>(
464 PV::mesh->property(prop_handle).data_vector());
unsigned int getClosestPrimitiveId(unsigned int _face, ACG::Vec3d &_hitPoint)
Returns the ID of the closest primitive.
virtual void setPropertyFromText(unsigned int index, QString text)
Returns the value of a property in text form.
virtual QString getHeader()
Returns the header for saving.
VectorT< double, 3 > Vec3d
virtual void clear()
Clears the property.
virtual void visualize(bool _setDrawMode, QWidget *_widget)
Visualizes the property.
virtual int getEntityCount()
Returns the number of entities.
Cellection of information about a property.
virtual QString getPropertyText(unsigned int index)
Returns the value of a property in text form.