51 #define OM_PROPERTY_VISUALIZER_CC 53 #include "OMPropertyVisualizer.hh" 59 template <
typename EntityType,
typename Handle,
typename MeshT>
60 QString getPropertyText__(Handle handle, MeshT mesh,
PropertyInfo propInfo)
64 if ( !mesh->get_property_handle(prop, propInfo.propName() ) )
65 return QObject::tr(
"Error: No property with name ").append(propInfo.propName().c_str());
67 return PropertyVisualizer::toStr(mesh->property(prop, handle));
73 template <
typename MeshT>
74 template <
typename InnerType>
78 if (PropertyVisualizer::propertyInfo.isFaceProp())
80 else if (PropertyVisualizer::propertyInfo.isEdgeProp())
82 else if (PropertyVisualizer::propertyInfo.isHalfedgeProp())
89 template<
typename MeshT>
90 template<
typename PropHandle>
92 PropHandle propHandle;
93 if (!mesh->get_property_handle(propHandle, propertyInfo.propName()))
return;
94 mesh->remove_property(propHandle);
97 template<
typename MeshT>
98 template<
typename PropType>
100 if (propertyInfo.isEdgeProp())
102 else if (propertyInfo.isVertexProp())
104 else if (propertyInfo.isFaceProp())
106 else if (propertyInfo.isHalfedgeProp())
111 template<
typename MeshT>
112 template<
typename PropHandle,
typename Iterator>
114 PropHandle propHandle;
115 if (!mesh->get_property_handle(propHandle, propertyInfo.propName()))
return;
117 std::string newPropertyName;
118 for (
int i = 1;; ++i) {
119 std::ostringstream oss;
120 oss << propertyInfo.propName() <<
" Copy " << i;
121 newPropertyName = oss.str();
124 if (!mesh->get_property_handle(tmp, newPropertyName))
break;
127 PropHandle newProperty;
128 mesh->add_property(newProperty, newPropertyName);
129 std::for_each(first, last, CopyProperty<PropHandle>(newProperty, propHandle, mesh));
132 template<
typename MeshT>
133 template<
typename PropType>
135 if (propertyInfo.isEdgeProp())
137 else if (propertyInfo.isVertexProp())
139 else if (propertyInfo.isFaceProp())
141 else if (propertyInfo.isHalfedgeProp())
147 template <
typename MeshT>
154 template <
typename MeshT>
157 if (propertyInfo.isFaceProp())
158 setFacePropertyFromText(index, text);
159 else if (propertyInfo.isEdgeProp())
160 setEdgePropertyFromText(index, text);
161 else if (propertyInfo.isHalfedgeProp())
162 setHalfedgePropertyFromText(index, text);
164 setVertexPropertyFromText(index, text);
167 template <
typename MeshT>
170 if (propertyInfo.isFaceProp())
171 return mesh->n_faces();
172 else if (propertyInfo.isEdgeProp())
173 return mesh->n_edges();
174 else if (propertyInfo.isHalfedgeProp())
175 return mesh->n_halfedges();
177 return mesh->n_vertices();
180 template <
typename MeshT>
185 QString header = QObject::tr(
"1");
186 header.append(QObject::tr(
", %1").arg(getEntityCount()));
187 header.append(QObject::tr(
", %1").arg(propertyInfo.entityType()));
188 header.append(
", ").append(propertyInfo.friendlyTypeName());
189 header.append(
", ").append(propertyInfo.propName().c_str());
205 template <
typename MeshT>
208 if (propertyInfo.isFaceProp())
209 return getClosestFaceId(_face, _hitPoint);
210 else if (propertyInfo.isEdgeProp())
211 return getClosestEdgeId(_face, _hitPoint);
212 else if (propertyInfo.isHalfedgeProp())
213 return getClosestHalfedgeId(_face, _hitPoint);
215 return getClosestVertexId(_face, _hitPoint);
218 template <
typename MeshT>
224 template <
typename MeshT>
227 unsigned int closest_halfedge_id = getClosestHalfedgeId(_face, _hitPoint);
228 typename MeshT::HalfedgeHandle heh;
229 heh = mesh->halfedge_handle(closest_halfedge_id);
231 typename MeshT::EdgeHandle eh;
232 eh = mesh->edge_handle(heh);
237 template <
typename MeshT>
240 typename MeshT::FaceHalfedgeIter fh_it;
242 int closest_h_idx = 0;
243 double dist = DBL_MAX;
246 typename MeshT::Point p;
248 for (fh_it = mesh->fh_iter(mesh->face_handle(_face)); fh_it.is_valid(); ++fh_it){
250 typename MeshT::HalfedgeHandle heh;
253 typename MeshT::VertexHandle v1;
254 v1 = mesh->to_vertex_handle(heh);
255 typename MeshT::VertexHandle v2;
256 v2 = mesh->from_vertex_handle(heh);
258 p = 0.5* (mesh->point( v1 ) + mesh->point( v2 ));
262 const double temp_dist = (vTemp - _hitPoint).length();
264 if (temp_dist < dist) {
266 closest_h_idx = fh_it->idx();
270 return closest_h_idx;
273 template <
typename MeshT>
276 typename MeshT::FaceVertexIter fv_it;
278 int closest_v_idx = 0;
279 double dist = DBL_MAX;
282 typename MeshT::Point p;
284 for (fv_it = mesh->fv_iter(mesh->face_handle(_face)); fv_it.is_valid(); ++fv_it){
286 p = mesh->point( *fv_it );
290 const double temp_dist = (vTemp - _hitPoint).length();
292 if (temp_dist < dist) {
294 closest_v_idx = fv_it->idx();
298 return closest_v_idx;
308 template <
typename MeshT>
318 if (propertyInfo.isFaceProp())
319 visualizeFaceProp(_setDrawMode);
320 else if (propertyInfo.isEdgeProp())
321 visualizeEdgeProp(_setDrawMode);
322 else if (propertyInfo.isHalfedgeProp())
323 visualizeHalfedgeProp(_setDrawMode);
324 else if (propertyInfo.isVertexProp())
325 visualizeVertexProp(_setDrawMode);
338 template <
typename MeshT>
341 if (propertyInfo.isFaceProp())
343 else if (propertyInfo.isEdgeProp())
345 else if (propertyInfo.isHalfedgeProp())
347 else if (propertyInfo.isVertexProp())
352 template <
typename MeshT>
357 color[0] = _color.redF();
358 color[1] = _color.greenF();
359 color[2] = _color.blueF();
360 color[3] = _color.alphaF();
365 template <
typename MeshT>
368 emit log(
LOGERR,
"Visualizing FaceProp not implemented");
371 template <
typename MeshT>
374 emit log(
LOGERR,
"Visualizing EdgeProp not implemented");
377 template <
typename MeshT>
380 emit log(
LOGERR,
"Visualizing HalfedgeProp not implemented");
383 template <
typename MeshT>
386 emit log(
LOGERR,
"Visualizing VertexProp not implemented");
389 template <
typename MeshT>
392 if ( mesh->has_face_colors() )
396 template <
typename MeshT>
399 if ( mesh->has_edge_colors() )
403 template <
typename MeshT>
406 if ( mesh->has_halfedge_colors() )
410 template <
typename MeshT>
413 if ( mesh->has_vertex_colors() )
417 template <
typename MeshT>
420 emit log(
LOGERR,
"Setting face property not implemented");
423 template <
typename MeshT>
426 emit log(
LOGERR,
"Settingedge property not implemented");
429 template <
typename MeshT>
432 emit log(
LOGERR,
"Setting halfedge property not implemented");
435 template <
typename MeshT>
438 emit log(
LOGERR,
"Setting vertex property not implemented");
virtual QString getPropertyText(unsigned int index)
Returns the value of a property in text form.
Cellection of information about a property.
virtual QString getHeader()
Returns the header for saving.
virtual void setPropertyFromText(unsigned int index, QString text)
Returns the value of a property in text form.
unsigned int getClosestPrimitiveId(unsigned int _face, ACG::Vec3d &_hitPoint)
Returns the ID of the closest primitive.
virtual int getEntityCount()
Returns the number of entities.
virtual void clear()
Clears the property.
VectorT< double, 3 > Vec3d
virtual void visualize(bool _setDrawMode, QWidget *_widget)
Visualizes the property.