42 #ifndef OPENMESH_ATTRIBKERNEL_HH
43 #define OPENMESH_ATTRIBKERNEL_HH
49 #include <OpenMesh/Core/Utils/GenProg.hh>
50 #include <OpenMesh/Core/Utils/vector_traits.hh>
69 template <
class MeshItems,
class Connectivity>
76 typedef typename Connectivity::Vertex Vertex;
77 typedef typename Connectivity::Halfedge Halfedge;
78 typedef typename Connectivity::Edge Edge;
79 typedef typename Connectivity::Face Face;
81 typedef typename MeshItems::Point Point;
87 typedef typename MeshItems::Scalar Scalar;
90 typedef typename MeshItems::VertexData VertexData;
91 typedef typename MeshItems::HalfedgeData HalfedgeData;
92 typedef typename MeshItems::EdgeData EdgeData;
93 typedef typename MeshItems::FaceData FaceData;
98 VAttribs = MeshItems::VAttribs,
99 HAttribs = MeshItems::HAttribs,
100 EAttribs = MeshItems::EAttribs,
101 FAttribs = MeshItems::FAttribs
114 : refcount_vnormals_(0),
115 refcount_vcolors_(0),
116 refcount_vtexcoords1D_(0),
117 refcount_vtexcoords2D_(0),
118 refcount_vtexcoords3D_(0),
119 refcount_htexcoords1D_(0),
120 refcount_htexcoords2D_(0),
121 refcount_htexcoords3D_(0),
122 refcount_henormals_(0),
123 refcount_hecolors_(0),
124 refcount_ecolors_(0),
125 refcount_fnormals_(0),
126 refcount_fcolors_(0),
127 refcount_ftextureIndex_(0)
129 this->add_property( points_,
"v:points" );
132 request_vertex_normals();
135 request_vertex_colors();
138 request_vertex_texcoords1D();
141 request_vertex_texcoords2D();
144 request_vertex_texcoords3D();
146 if (HAttribs & Attributes::TexCoord1D)
147 request_halfedge_texcoords1D();
149 if (HAttribs & Attributes::TexCoord2D)
150 request_halfedge_texcoords2D();
152 if (HAttribs & Attributes::TexCoord3D)
153 request_halfedge_texcoords3D();
155 if (HAttribs & Attributes::Color)
156 request_halfedge_colors();
159 Connectivity::request_vertex_status();
161 if (HAttribs & Attributes::Status)
162 Connectivity::request_halfedge_status();
164 if (HAttribs & Attributes::Normal)
165 request_halfedge_normals();
167 if (EAttribs & Attributes::Status)
168 Connectivity::request_edge_status();
170 if (EAttribs & Attributes::Color)
171 request_edge_colors();
173 if (FAttribs & Attributes::Normal)
174 request_face_normals();
176 if (FAttribs & Attributes::Color)
177 request_face_colors();
179 if (FAttribs & Attributes::Status)
180 Connectivity::request_face_status();
183 request_face_texture_index();
187 this->add_property(data_vpph_);
188 this->add_property(data_fpph_);
189 this->add_property(data_hpph_);
190 this->add_property(data_epph_);
207 template <
class _AttribKernel>
210 this->assign_connectivity(_other);
211 for (
typename Connectivity::VertexIter v_it = Connectivity::vertices_begin();
212 v_it != Connectivity::vertices_end(); ++v_it)
214 set_point(v_it, (Point)_other.point(v_it));
220 const Point* points()
const
221 {
return this->property(points_).data(); }
223 const Point& point(VertexHandle _vh)
const
224 {
return this->property(points_, _vh); }
226 Point& point(VertexHandle _vh)
227 {
return this->property(points_, _vh); }
229 void set_point(VertexHandle _vh,
const Point& _p)
230 { this->property(points_, _vh) = _p; }
235 const Normal* vertex_normals()
const
236 {
return this->property(vertex_normals_).data(); }
238 const Normal& normal(VertexHandle _vh)
const
239 {
return this->property(vertex_normals_, _vh); }
241 void set_normal(VertexHandle _vh,
const Normal& _n)
242 { this->property(vertex_normals_, _vh) = _n; }
247 const Color* vertex_colors()
const
248 {
return this->property(vertex_colors_).data(); }
250 const Color& color(VertexHandle _vh)
const
251 {
return this->property(vertex_colors_, _vh); }
253 void set_color(VertexHandle _vh,
const Color& _c)
254 { this->property(vertex_colors_, _vh) = _c; }
259 const TexCoord1D* texcoords1D()
const {
260 return this->property(vertex_texcoords1D_).data();
263 const TexCoord1D& texcoord1D(VertexHandle _vh)
const {
264 return this->property(vertex_texcoords1D_, _vh);
267 void set_texcoord1D(VertexHandle _vh,
const TexCoord1D& _t) {
268 this->property(vertex_texcoords1D_, _vh) = _t;
274 const TexCoord2D* texcoords2D()
const {
275 return this->property(vertex_texcoords2D_).data();
278 const TexCoord2D& texcoord2D(VertexHandle _vh)
const {
279 return this->property(vertex_texcoords2D_, _vh);
282 void set_texcoord2D(VertexHandle _vh,
const TexCoord2D& _t) {
283 this->property(vertex_texcoords2D_, _vh) = _t;
289 const TexCoord3D* texcoords3D()
const {
290 return this->property(vertex_texcoords3D_).data();
293 const TexCoord3D& texcoord3D(VertexHandle _vh)
const {
294 return this->property(vertex_texcoords3D_, _vh);
297 void set_texcoord3D(VertexHandle _vh,
const TexCoord3D& _t) {
298 this->property(vertex_texcoords3D_, _vh) = _t;
303 const TexCoord1D* htexcoords1D()
const {
304 return this->property(halfedge_texcoords1D_).data();
307 const TexCoord1D& texcoord1D(HalfedgeHandle _heh)
const {
308 return this->property(halfedge_texcoords1D_, _heh);
311 void set_texcoord1D(HalfedgeHandle _heh,
const TexCoord1D& _t) {
312 this->property(halfedge_texcoords1D_, _heh) = _t;
318 const TexCoord2D* htexcoords2D()
const {
319 return this->property(halfedge_texcoords2D_).data();
322 const TexCoord2D& texcoord2D(HalfedgeHandle _heh)
const {
323 return this->property(halfedge_texcoords2D_, _heh);
326 void set_texcoord2D(HalfedgeHandle _heh,
const TexCoord2D& _t) {
327 this->property(halfedge_texcoords2D_, _heh) = _t;
333 const TexCoord3D* htexcoords3D()
const {
334 return this->property(halfedge_texcoords3D_).data();
337 const TexCoord3D& texcoord3D(HalfedgeHandle _heh)
const {
338 return this->property(halfedge_texcoords3D_, _heh);
341 void set_texcoord3D(HalfedgeHandle _heh,
const TexCoord3D& _t) {
342 this->property(halfedge_texcoords3D_, _heh) = _t;
347 const Color* edge_colors()
const
348 {
return this->property(edge_colors_).data(); }
350 const Color& color(EdgeHandle _eh)
const
351 {
return this->property(edge_colors_, _eh); }
353 void set_color(EdgeHandle _eh,
const Color& _c)
354 { this->property(edge_colors_, _eh) = _c; }
359 const Normal& normal(HalfedgeHandle _heh)
const
360 {
return this->property(halfedge_normals_, _heh); }
362 void set_normal(HalfedgeHandle _heh,
const Normal& _n)
363 { this->property(halfedge_normals_, _heh) = _n; }
368 const Color* halfedge_colors()
const
369 {
return this->property(halfedge_colors_).data(); }
371 const Color& color(HalfedgeHandle _heh)
const
372 {
return this->property(halfedge_colors_, _heh); }
374 void set_color(HalfedgeHandle _heh,
const Color& _c)
375 { this->property(halfedge_colors_, _heh) = _c; }
379 const Normal& normal(FaceHandle _fh)
const
380 {
return this->property(face_normals_, _fh); }
382 void set_normal(FaceHandle _fh,
const Normal& _n)
383 { this->property(face_normals_, _fh) = _n; }
387 const TextureIndex& texture_index(FaceHandle _fh)
const
388 {
return this->property(face_texture_index_, _fh); }
390 void set_texture_index(FaceHandle _fh,
const TextureIndex& _t)
391 { this->property(face_texture_index_, _fh) = _t; }
395 const Color& color(FaceHandle _fh)
const
396 {
return this->property(face_colors_, _fh); }
398 void set_color(FaceHandle _fh,
const Color& _c)
399 { this->property(face_colors_, _fh) = _c; }
403 void request_vertex_normals()
405 if (!refcount_vnormals_++)
406 this->add_property( vertex_normals_,
"v:normals" );
409 void request_vertex_colors()
411 if (!refcount_vcolors_++)
412 this->add_property( vertex_colors_,
"v:colors" );
415 void request_vertex_texcoords1D()
417 if (!refcount_vtexcoords1D_++)
418 this->add_property( vertex_texcoords1D_,
"v:texcoords1D" );
421 void request_vertex_texcoords2D()
423 if (!refcount_vtexcoords2D_++)
424 this->add_property( vertex_texcoords2D_,
"v:texcoords2D" );
427 void request_vertex_texcoords3D()
429 if (!refcount_vtexcoords3D_++)
430 this->add_property( vertex_texcoords3D_,
"v:texcoords3D" );
433 void request_halfedge_texcoords1D()
435 if (!refcount_htexcoords1D_++)
436 this->add_property( halfedge_texcoords1D_,
"h:texcoords1D" );
439 void request_halfedge_texcoords2D()
441 if (!refcount_htexcoords2D_++)
442 this->add_property( halfedge_texcoords2D_,
"h:texcoords2D" );
445 void request_halfedge_texcoords3D()
447 if (!refcount_htexcoords3D_++)
448 this->add_property( halfedge_texcoords3D_,
"h:texcoords3D" );
451 void request_edge_colors()
453 if (!refcount_ecolors_++)
454 this->add_property( edge_colors_,
"e:colors" );
457 void request_halfedge_normals()
459 if (!refcount_henormals_++)
460 this->add_property( halfedge_normals_,
"h:normals" );
463 void request_halfedge_colors()
465 if (!refcount_hecolors_++)
466 this->add_property( halfedge_colors_,
"h:colors" );
469 void request_face_normals()
471 if (!refcount_fnormals_++)
472 this->add_property( face_normals_,
"f:normals" );
475 void request_face_colors()
477 if (!refcount_fcolors_++)
478 this->add_property( face_colors_,
"f:colors" );
481 void request_face_texture_index()
483 if (!refcount_ftextureIndex_++)
484 this->add_property( face_texture_index_,
"f:textureindex" );
489 void release_vertex_normals()
491 if ((refcount_vnormals_ > 0) && (! --refcount_vnormals_))
492 this->remove_property(vertex_normals_);
495 void release_vertex_colors()
497 if ((refcount_vcolors_ > 0) && (! --refcount_vcolors_))
498 this->remove_property(vertex_colors_);
501 void release_vertex_texcoords1D() {
502 if ((refcount_vtexcoords1D_ > 0) && (! --refcount_vtexcoords1D_))
503 this->remove_property(vertex_texcoords1D_);
506 void release_vertex_texcoords2D() {
507 if ((refcount_vtexcoords2D_ > 0) && (! --refcount_vtexcoords2D_))
508 this->remove_property(vertex_texcoords2D_);
511 void release_vertex_texcoords3D() {
512 if ((refcount_vtexcoords3D_ > 0) && (! --refcount_vtexcoords3D_))
513 this->remove_property(vertex_texcoords3D_);
516 void release_halfedge_texcoords1D() {
517 if ((refcount_htexcoords1D_ > 0) && (! --refcount_htexcoords1D_))
518 this->remove_property(halfedge_texcoords1D_);
521 void release_halfedge_texcoords2D() {
522 if ((refcount_htexcoords2D_ > 0) && (! --refcount_htexcoords2D_))
523 this->remove_property(halfedge_texcoords2D_);
526 void release_halfedge_texcoords3D() {
527 if ((refcount_htexcoords3D_ > 0) && (! --refcount_htexcoords3D_))
528 this->remove_property(halfedge_texcoords3D_);
531 void release_edge_colors()
533 if ((refcount_ecolors_ > 0) && (! --refcount_ecolors_))
534 this->remove_property(edge_colors_);
537 void release_halfedge_normals()
539 if ((refcount_henormals_ > 0) && (! --refcount_henormals_))
540 this->remove_property(halfedge_normals_);
543 void release_halfedge_colors()
545 if ((refcount_hecolors_ > 0) && (! --refcount_hecolors_))
546 this->remove_property(halfedge_colors_);
549 void release_face_normals()
551 if ((refcount_fnormals_ > 0) && (! --refcount_fnormals_))
552 this->remove_property(face_normals_);
555 void release_face_colors()
557 if ((refcount_fcolors_ > 0) && (! --refcount_fcolors_))
558 this->remove_property(face_colors_);
561 void release_face_texture_index()
563 if ((refcount_ftextureIndex_ > 0) && (! --refcount_ftextureIndex_))
564 this->remove_property(face_texture_index_);
569 bool has_vertex_normals()
const {
return vertex_normals_.
is_valid(); }
570 bool has_vertex_colors()
const {
return vertex_colors_.
is_valid(); }
571 bool has_vertex_texcoords1D()
const {
return vertex_texcoords1D_.
is_valid(); }
572 bool has_vertex_texcoords2D()
const {
return vertex_texcoords2D_.
is_valid(); }
573 bool has_vertex_texcoords3D()
const {
return vertex_texcoords3D_.
is_valid(); }
574 bool has_halfedge_texcoords1D()
const {
return halfedge_texcoords1D_.
is_valid();}
575 bool has_halfedge_texcoords2D()
const {
return halfedge_texcoords2D_.
is_valid();}
576 bool has_halfedge_texcoords3D()
const {
return halfedge_texcoords3D_.
is_valid();}
577 bool has_edge_colors()
const {
return edge_colors_.
is_valid(); }
578 bool has_halfedge_normals()
const {
return halfedge_normals_.
is_valid(); }
579 bool has_halfedge_colors()
const {
return halfedge_colors_.
is_valid(); }
580 bool has_face_normals()
const {
return face_normals_.
is_valid(); }
581 bool has_face_colors()
const {
return face_colors_.
is_valid(); }
582 bool has_face_texture_index()
const {
return face_texture_index_.
is_valid(); }
586 typedef VPropHandleT<Point> PointsPropertyHandle;
587 typedef VPropHandleT<Normal> VertexNormalsPropertyHandle;
588 typedef VPropHandleT<Color> VertexColorsPropertyHandle;
589 typedef VPropHandleT<TexCoord1D> VertexTexCoords1DPropertyHandle;
590 typedef VPropHandleT<TexCoord2D> VertexTexCoords2DPropertyHandle;
591 typedef VPropHandleT<TexCoord3D> VertexTexCoords3DPropertyHandle;
592 typedef HPropHandleT<TexCoord1D> HalfedgeTexCoords1DPropertyHandle;
593 typedef HPropHandleT<TexCoord2D> HalfedgeTexCoords2DPropertyHandle;
594 typedef HPropHandleT<TexCoord3D> HalfedgeTexCoords3DPropertyHandle;
595 typedef EPropHandleT<Color> EdgeColorsPropertyHandle;
596 typedef HPropHandleT<Normal> HalfedgeNormalsPropertyHandle;
597 typedef HPropHandleT<Color> HalfedgeColorsPropertyHandle;
598 typedef FPropHandleT<Normal> FaceNormalsPropertyHandle;
599 typedef FPropHandleT<Color> FaceColorsPropertyHandle;
600 typedef FPropHandleT<TextureIndex> FaceTextureIndexPropertyHandle;
604 PointsPropertyHandle points_pph()
const
607 VertexNormalsPropertyHandle vertex_normals_pph()
const
608 {
return vertex_normals_; }
610 VertexColorsPropertyHandle vertex_colors_pph()
const
611 {
return vertex_colors_; }
613 VertexTexCoords1DPropertyHandle vertex_texcoords1D_pph()
const
614 {
return vertex_texcoords1D_; }
616 VertexTexCoords2DPropertyHandle vertex_texcoords2D_pph()
const
617 {
return vertex_texcoords2D_; }
619 VertexTexCoords3DPropertyHandle vertex_texcoords3D_pph()
const
620 {
return vertex_texcoords3D_; }
623 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_pph()
const
624 {
return halfedge_texcoords1D_; }
626 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_pph()
const
627 {
return halfedge_texcoords2D_; }
629 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_pph()
const
630 {
return halfedge_texcoords3D_; }
633 HalfedgeNormalsPropertyHandle halfedge_normals_pph()
const
634 {
return halfedge_normals_; }
638 HalfedgeColorsPropertyHandle halfedge_colors_pph()
const
639 {
return halfedge_colors_; }
642 EdgeColorsPropertyHandle edge_colors_pph()
const
643 {
return edge_colors_; }
646 FaceNormalsPropertyHandle face_normals_pph()
const
647 {
return face_normals_; }
649 FaceColorsPropertyHandle face_colors_pph()
const
650 {
return face_colors_; }
652 FaceTextureIndexPropertyHandle face_texture_index_pph()
const
653 {
return face_texture_index_; }
655 VertexData& data(VertexHandle _vh)
656 {
return this->property(data_vpph_, _vh); }
658 const VertexData& data(VertexHandle _vh)
const
659 {
return this->property(data_vpph_, _vh); }
661 FaceData& data(FaceHandle _fh)
662 {
return this->property(data_fpph_, _fh); }
664 const FaceData& data(FaceHandle _fh)
const
665 {
return this->property(data_fpph_, _fh); }
667 EdgeData& data(EdgeHandle _eh)
668 {
return this->property(data_epph_, _eh); }
670 const EdgeData& data(EdgeHandle _eh)
const
671 {
return this->property(data_epph_, _eh); }
673 HalfedgeData& data(HalfedgeHandle _heh)
674 {
return this->property(data_hpph_, _heh); }
676 const HalfedgeData& data(HalfedgeHandle _heh)
const
677 {
return this->property(data_hpph_, _heh); }
681 PointsPropertyHandle points_;
682 VertexNormalsPropertyHandle vertex_normals_;
683 VertexColorsPropertyHandle vertex_colors_;
684 VertexTexCoords1DPropertyHandle vertex_texcoords1D_;
685 VertexTexCoords2DPropertyHandle vertex_texcoords2D_;
686 VertexTexCoords3DPropertyHandle vertex_texcoords3D_;
688 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_;
689 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_;
690 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_;
691 HalfedgeNormalsPropertyHandle halfedge_normals_;
692 HalfedgeColorsPropertyHandle halfedge_colors_;
694 EdgeColorsPropertyHandle edge_colors_;
696 FaceNormalsPropertyHandle face_normals_;
697 FaceColorsPropertyHandle face_colors_;
698 FaceTextureIndexPropertyHandle face_texture_index_;
700 DataVPropHandle data_vpph_;
701 DataHPropHandle data_hpph_;
702 DataEPropHandle data_epph_;
703 DataFPropHandle data_fpph_;
705 unsigned int refcount_vnormals_;
706 unsigned int refcount_vcolors_;
707 unsigned int refcount_vtexcoords1D_;
708 unsigned int refcount_vtexcoords2D_;
709 unsigned int refcount_vtexcoords3D_;
710 unsigned int refcount_htexcoords1D_;
711 unsigned int refcount_htexcoords2D_;
712 unsigned int refcount_htexcoords3D_;
713 unsigned int refcount_henormals_;
714 unsigned int refcount_hecolors_;
715 unsigned int refcount_ecolors_;
716 unsigned int refcount_fnormals_;
717 unsigned int refcount_fcolors_;
718 unsigned int refcount_ftextureIndex_;
724 #endif // OPENMESH_ATTRIBKERNEL_HH defined