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>
158 template <
typename MeshT>
161 if (propertyInfo.isFaceProp())
162 setFacePropertyFromText(index, text);
163 else if (propertyInfo.isEdgeProp())
164 setEdgePropertyFromText(index, text);
165 else if (propertyInfo.isHalfedgeProp())
166 setHalfedgePropertyFromText(index, text);
168 setVertexPropertyFromText(index, text);
171 template <
typename MeshT>
174 if (propertyInfo.isFaceProp())
175 return mesh->n_faces();
176 else if (propertyInfo.isEdgeProp())
177 return mesh->n_edges();
178 else if (propertyInfo.isHalfedgeProp())
179 return mesh->n_halfedges();
181 return mesh->n_vertices();
184 template <
typename MeshT>
189 QString header = QObject::tr(
"1");
190 header.append(QObject::tr(
", %1").arg(getEntityCount()));
191 header.append(QObject::tr(
", %1").arg(propertyInfo.entityType()));
192 header.append(
", ").append(propertyInfo.friendlyTypeName());
193 header.append(
", ").append(propertyInfo.propName().c_str());
209 template <
typename MeshT>
212 if (propertyInfo.isFaceProp())
213 return getClosestFaceId(_face, _hitPoint);
214 else if (propertyInfo.isEdgeProp())
215 return getClosestEdgeId(_face, _hitPoint);
216 else if (propertyInfo.isHalfedgeProp())
217 return getClosestHalfedgeId(_face, _hitPoint);
219 return getClosestVertexId(_face, _hitPoint);
222 template <
typename MeshT>
228 template <
typename MeshT>
231 unsigned int closest_halfedge_id = getClosestHalfedgeId(_face, _hitPoint);
232 typename MeshT::HalfedgeHandle heh;
233 heh = mesh->halfedge_handle(closest_halfedge_id);
235 typename MeshT::EdgeHandle eh;
236 eh = mesh->edge_handle(heh);
241 template <
typename MeshT>
244 typename MeshT::FaceHalfedgeIter fh_it;
246 int closest_h_idx = 0;
247 double dist = DBL_MAX;
250 typename MeshT::Point p;
252 for (fh_it = mesh->fh_iter(mesh->face_handle(_face)); fh_it.is_valid(); ++fh_it){
254 typename MeshT::HalfedgeHandle heh;
257 typename MeshT::VertexHandle v1;
258 v1 = mesh->to_vertex_handle(heh);
259 typename MeshT::VertexHandle v2;
260 v2 = mesh->from_vertex_handle(heh);
262 p = 0.5* (mesh->point( v1 ) + mesh->point( v2 ));
266 const double temp_dist = (vTemp - _hitPoint).length();
268 if (temp_dist < dist) {
270 closest_h_idx = fh_it->idx();
274 return closest_h_idx;
277 template <
typename MeshT>
280 typename MeshT::FaceVertexIter fv_it;
282 int closest_v_idx = 0;
283 double dist = DBL_MAX;
286 typename MeshT::Point p;
288 for (fv_it = mesh->fv_iter(mesh->face_handle(_face)); fv_it.is_valid(); ++fv_it){
290 p = mesh->point( *fv_it );
294 const double temp_dist = (vTemp - _hitPoint).length();
296 if (temp_dist < dist) {
298 closest_v_idx = fv_it->idx();
302 return closest_v_idx;
312 template <
typename MeshT>
322 if (propertyInfo.isFaceProp())
323 visualizeFaceProp(_setDrawMode);
324 else if (propertyInfo.isEdgeProp())
325 visualizeEdgeProp(_setDrawMode);
326 else if (propertyInfo.isHalfedgeProp())
327 visualizeHalfedgeProp(_setDrawMode);
328 else if (propertyInfo.isVertexProp())
329 visualizeVertexProp(_setDrawMode);
342 template <
typename MeshT>
345 if (propertyInfo.isFaceProp())
347 else if (propertyInfo.isEdgeProp())
349 else if (propertyInfo.isHalfedgeProp())
351 else if (propertyInfo.isVertexProp())
355 template <
typename MeshT>
358 emit log(
LOGERR,
"Visualizing FaceProp not implemented");
361 template <
typename MeshT>
364 emit log(
LOGERR,
"Visualizing EdgeProp not implemented");
367 template <
typename MeshT>
370 emit log(
LOGERR,
"Visualizing HalfedgeProp not implemented");
373 template <
typename MeshT>
376 emit log(
LOGERR,
"Visualizing VertexProp not implemented");
379 template <
typename MeshT>
382 if ( mesh->has_face_colors() )
386 template <
typename MeshT>
389 if ( mesh->has_edge_colors() )
393 template <
typename MeshT>
396 if ( mesh->has_halfedge_colors() )
400 template <
typename MeshT>
403 if ( mesh->has_vertex_colors() )
407 template <
typename MeshT>
410 emit log(
LOGERR,
"Setting face property not implemented");
413 template <
typename MeshT>
416 emit log(
LOGERR,
"Settingedge property not implemented");
419 template <
typename MeshT>
422 emit log(
LOGERR,
"Setting halfedge property not implemented");
425 template <
typename MeshT>
428 emit log(
LOGERR,
"Setting vertex property not implemented");
432 template<
typename MeshT>
433 template<
typename Type>
436 const std::string &prop_name = PV::propertyInfo.propName();
440 switch (PropertyVisualizer::propertyInfo.entityType()) {
441 case PropertyInfo::EF_FACE:
444 if (!PV::mesh->get_property_handle(prop_handle, prop_name))
break;
445 PropertyVisualizer::template showHistogramT<Type>(
447 PV::mesh->property(prop_handle).data_vector());
450 case PropertyInfo::EF_EDGE:
453 if (!PV::mesh->get_property_handle(prop_handle, prop_name))
break;
454 PropertyVisualizer::template showHistogramT<Type>(
456 PV::mesh->property(prop_handle).data_vector());
459 case PropertyInfo::EF_HALFEDGE:
462 if (!PV::mesh->get_property_handle(prop_handle, prop_name))
break;
463 PropertyVisualizer::template showHistogramT<Type>(
465 PV::mesh->property(prop_handle).data_vector());
468 case PropertyInfo::EF_VERTEX:
471 if (!PV::mesh->get_property_handle(prop_handle, prop_name))
break;
472 PropertyVisualizer::template showHistogramT<Type>(
474 PV::mesh->property(prop_handle).data_vector());
unsigned int getClosestPrimitiveId(unsigned int _face, ACG::Vec3d &_hitPoint)
Returns the ID of the closest primitive.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
virtual void visualize(bool _setDrawMode, QWidget *_widget)
Visualizes the property.
virtual void setPropertyFromText(unsigned int index, QString text)
Returns the value of a property in text form.
void setObjectDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, const bool &_force=false)
Set the draw mode for the object.
virtual int getEntityCount()
Returns the number of entities.
Cellection of information about a property.
virtual void clear()
Clears the property.
virtual QString getHeader()
Returns the header for saving.
virtual QString getPropertyText(unsigned int index)
Returns the value of a property in text form.
VectorT< double, 3 > Vec3d