44 #ifndef OPENMESH_ATTRIBKERNEL_HH
45 #define OPENMESH_ATTRIBKERNEL_HH
51 #include <OpenMesh/Core/Utils/GenProg.hh>
52 #include <OpenMesh/Core/Utils/vector_traits.hh>
71 template <
class MeshItems,
class Connectivity>
78 typedef MeshItems MeshItemsT;
79 typedef Connectivity ConnectivityT;
80 typedef typename Connectivity::Vertex Vertex;
81 typedef typename Connectivity::Halfedge Halfedge;
82 typedef typename Connectivity::Edge Edge;
83 typedef typename Connectivity::Face Face;
85 typedef typename MeshItems::Point Point;
91 typedef typename MeshItems::Scalar Scalar;
94 typedef typename MeshItems::VertexData VertexData;
95 typedef typename MeshItems::HalfedgeData HalfedgeData;
96 typedef typename MeshItems::EdgeData EdgeData;
97 typedef typename MeshItems::FaceData FaceData;
102 VAttribs = MeshItems::VAttribs,
103 HAttribs = MeshItems::HAttribs,
104 EAttribs = MeshItems::EAttribs,
105 FAttribs = MeshItems::FAttribs
134 : refcount_vnormals_(0),
135 refcount_vcolors_(0),
136 refcount_vtexcoords1D_(0),
137 refcount_vtexcoords2D_(0),
138 refcount_vtexcoords3D_(0),
139 refcount_htexcoords1D_(0),
140 refcount_htexcoords2D_(0),
141 refcount_htexcoords3D_(0),
142 refcount_henormals_(0),
143 refcount_hecolors_(0),
144 refcount_ecolors_(0),
145 refcount_fnormals_(0),
146 refcount_fcolors_(0),
147 refcount_ftextureIndex_(0)
149 this->add_property( points_,
"v:points" );
152 request_vertex_normals();
155 request_vertex_colors();
158 request_vertex_texcoords1D();
161 request_vertex_texcoords2D();
164 request_vertex_texcoords3D();
167 request_halfedge_texcoords1D();
170 request_halfedge_texcoords2D();
173 request_halfedge_texcoords3D();
176 request_halfedge_colors();
179 Connectivity::request_vertex_status();
182 Connectivity::request_halfedge_status();
185 request_halfedge_normals();
188 Connectivity::request_edge_status();
191 request_edge_colors();
194 request_face_normals();
197 request_face_colors();
200 Connectivity::request_face_status();
203 request_face_texture_index();
207 this->add_property(data_vpph_);
208 this->add_property(data_fpph_);
209 this->add_property(data_hpph_);
210 this->add_property(data_epph_);
226 template <
class _AttribKernel>
227 void assign(
const _AttribKernel& _other,
bool copyStandardProperties =
false)
230 if(copyStandardProperties)
231 this->copy_all_kernel_properties(_other);
233 this->assign_connectivity(_other);
234 for (
typename Connectivity::VertexIter v_it = Connectivity::vertices_begin();
235 v_it != Connectivity::vertices_end(); ++v_it)
237 set_point(*v_it, (Point)_other.point(*v_it));
241 if(copyStandardProperties)
242 initializeStandardProperties();
247 const Point* points()
const
248 {
return this->property(points_).data(); }
250 const Point& point(VertexHandle _vh)
const
251 {
return this->property(points_, _vh); }
253 Point& point(VertexHandle _vh)
254 {
return this->property(points_, _vh); }
256 void set_point(VertexHandle _vh,
const Point& _p)
257 { this->property(points_, _vh) = _p; }
259 const PointsPropertyHandle& points_property_handle()
const
265 const Normal* vertex_normals()
const
266 {
return this->property(vertex_normals_).data(); }
268 const Normal& normal(VertexHandle _vh)
const
269 {
return this->property(vertex_normals_, _vh); }
271 void set_normal(VertexHandle _vh,
const Normal& _n)
272 { this->property(vertex_normals_, _vh) = _n; }
277 const Color* vertex_colors()
const
278 {
return this->property(vertex_colors_).data(); }
280 const Color& color(VertexHandle _vh)
const
281 {
return this->property(vertex_colors_, _vh); }
283 void set_color(VertexHandle _vh,
const Color& _c)
284 { this->property(vertex_colors_, _vh) = _c; }
290 return this->property(vertex_texcoords1D_).data();
293 const TexCoord1D& texcoord1D(VertexHandle _vh)
const {
294 return this->property(vertex_texcoords1D_, _vh);
297 void set_texcoord1D(VertexHandle _vh,
const TexCoord1D& _t) {
298 this->property(vertex_texcoords1D_, _vh) = _t;
305 return this->property(vertex_texcoords2D_).data();
308 const TexCoord2D& texcoord2D(VertexHandle _vh)
const {
309 return this->property(vertex_texcoords2D_, _vh);
312 void set_texcoord2D(VertexHandle _vh,
const TexCoord2D& _t) {
313 this->property(vertex_texcoords2D_, _vh) = _t;
320 return this->property(vertex_texcoords3D_).data();
323 const TexCoord3D& texcoord3D(VertexHandle _vh)
const {
324 return this->property(vertex_texcoords3D_, _vh);
327 void set_texcoord3D(VertexHandle _vh,
const TexCoord3D& _t) {
328 this->property(vertex_texcoords3D_, _vh) = _t;
334 return this->property(halfedge_texcoords1D_).data();
337 const TexCoord1D& texcoord1D(HalfedgeHandle _heh)
const {
338 return this->property(halfedge_texcoords1D_, _heh);
341 void set_texcoord1D(HalfedgeHandle _heh,
const TexCoord1D& _t) {
342 this->property(halfedge_texcoords1D_, _heh) = _t;
349 return this->property(halfedge_texcoords2D_).data();
352 const TexCoord2D& texcoord2D(HalfedgeHandle _heh)
const {
353 return this->property(halfedge_texcoords2D_, _heh);
356 void set_texcoord2D(HalfedgeHandle _heh,
const TexCoord2D& _t) {
357 this->property(halfedge_texcoords2D_, _heh) = _t;
364 return this->property(halfedge_texcoords3D_).data();
367 const TexCoord3D& texcoord3D(HalfedgeHandle _heh)
const {
368 return this->property(halfedge_texcoords3D_, _heh);
371 void set_texcoord3D(HalfedgeHandle _heh,
const TexCoord3D& _t) {
372 this->property(halfedge_texcoords3D_, _heh) = _t;
377 const Color* edge_colors()
const
378 {
return this->property(edge_colors_).data(); }
380 const Color& color(EdgeHandle _eh)
const
381 {
return this->property(edge_colors_, _eh); }
383 void set_color(EdgeHandle _eh,
const Color& _c)
384 { this->property(edge_colors_, _eh) = _c; }
389 const Normal& normal(HalfedgeHandle _heh)
const
390 {
return this->property(halfedge_normals_, _heh); }
392 void set_normal(HalfedgeHandle _heh,
const Normal& _n)
393 { this->property(halfedge_normals_, _heh) = _n; }
398 const Color* halfedge_colors()
const
399 {
return this->property(halfedge_colors_).data(); }
401 const Color& color(HalfedgeHandle _heh)
const
402 {
return this->property(halfedge_colors_, _heh); }
404 void set_color(HalfedgeHandle _heh,
const Color& _c)
405 { this->property(halfedge_colors_, _heh) = _c; }
409 const Normal& normal(FaceHandle _fh)
const
410 {
return this->property(face_normals_, _fh); }
412 void set_normal(FaceHandle _fh,
const Normal& _n)
413 { this->property(face_normals_, _fh) = _n; }
418 {
return this->property(face_texture_index_, _fh); }
420 void set_texture_index(FaceHandle _fh,
const TextureIndex& _t)
421 { this->property(face_texture_index_, _fh) = _t; }
425 const Color& color(FaceHandle _fh)
const
426 {
return this->property(face_colors_, _fh); }
428 void set_color(FaceHandle _fh,
const Color& _c)
429 { this->property(face_colors_, _fh) = _c; }
433 void request_vertex_normals()
435 if (!refcount_vnormals_++)
436 this->add_property( vertex_normals_,
"v:normals" );
439 void request_vertex_colors()
441 if (!refcount_vcolors_++)
442 this->add_property( vertex_colors_,
"v:colors" );
445 void request_vertex_texcoords1D()
447 if (!refcount_vtexcoords1D_++)
448 this->add_property( vertex_texcoords1D_,
"v:texcoords1D" );
451 void request_vertex_texcoords2D()
453 if (!refcount_vtexcoords2D_++)
454 this->add_property( vertex_texcoords2D_,
"v:texcoords2D" );
457 void request_vertex_texcoords3D()
459 if (!refcount_vtexcoords3D_++)
460 this->add_property( vertex_texcoords3D_,
"v:texcoords3D" );
463 void request_halfedge_texcoords1D()
465 if (!refcount_htexcoords1D_++)
466 this->add_property( halfedge_texcoords1D_,
"h:texcoords1D" );
469 void request_halfedge_texcoords2D()
471 if (!refcount_htexcoords2D_++)
472 this->add_property( halfedge_texcoords2D_,
"h:texcoords2D" );
475 void request_halfedge_texcoords3D()
477 if (!refcount_htexcoords3D_++)
478 this->add_property( halfedge_texcoords3D_,
"h:texcoords3D" );
481 void request_edge_colors()
483 if (!refcount_ecolors_++)
484 this->add_property( edge_colors_,
"e:colors" );
487 void request_halfedge_normals()
489 if (!refcount_henormals_++)
490 this->add_property( halfedge_normals_,
"h:normals" );
493 void request_halfedge_colors()
495 if (!refcount_hecolors_++)
496 this->add_property( halfedge_colors_,
"h:colors" );
499 void request_face_normals()
501 if (!refcount_fnormals_++)
502 this->add_property( face_normals_,
"f:normals" );
505 void request_face_colors()
507 if (!refcount_fcolors_++)
508 this->add_property( face_colors_,
"f:colors" );
511 void request_face_texture_index()
513 if (!refcount_ftextureIndex_++)
514 this->add_property( face_texture_index_,
"f:textureindex" );
519 void release_vertex_normals()
521 if ((refcount_vnormals_ > 0) && (! --refcount_vnormals_))
522 this->remove_property(vertex_normals_);
525 void release_vertex_colors()
527 if ((refcount_vcolors_ > 0) && (! --refcount_vcolors_))
528 this->remove_property(vertex_colors_);
531 void release_vertex_texcoords1D() {
532 if ((refcount_vtexcoords1D_ > 0) && (! --refcount_vtexcoords1D_))
533 this->remove_property(vertex_texcoords1D_);
536 void release_vertex_texcoords2D() {
537 if ((refcount_vtexcoords2D_ > 0) && (! --refcount_vtexcoords2D_))
538 this->remove_property(vertex_texcoords2D_);
541 void release_vertex_texcoords3D() {
542 if ((refcount_vtexcoords3D_ > 0) && (! --refcount_vtexcoords3D_))
543 this->remove_property(vertex_texcoords3D_);
546 void release_halfedge_texcoords1D() {
547 if ((refcount_htexcoords1D_ > 0) && (! --refcount_htexcoords1D_))
548 this->remove_property(halfedge_texcoords1D_);
551 void release_halfedge_texcoords2D() {
552 if ((refcount_htexcoords2D_ > 0) && (! --refcount_htexcoords2D_))
553 this->remove_property(halfedge_texcoords2D_);
556 void release_halfedge_texcoords3D() {
557 if ((refcount_htexcoords3D_ > 0) && (! --refcount_htexcoords3D_))
558 this->remove_property(halfedge_texcoords3D_);
561 void release_edge_colors()
563 if ((refcount_ecolors_ > 0) && (! --refcount_ecolors_))
564 this->remove_property(edge_colors_);
567 void release_halfedge_normals()
569 if ((refcount_henormals_ > 0) && (! --refcount_henormals_))
570 this->remove_property(halfedge_normals_);
573 void release_halfedge_colors()
575 if ((refcount_hecolors_ > 0) && (! --refcount_hecolors_))
576 this->remove_property(halfedge_colors_);
579 void release_face_normals()
581 if ((refcount_fnormals_ > 0) && (! --refcount_fnormals_))
582 this->remove_property(face_normals_);
585 void release_face_colors()
587 if ((refcount_fcolors_ > 0) && (! --refcount_fcolors_))
588 this->remove_property(face_colors_);
591 void release_face_texture_index()
593 if ((refcount_ftextureIndex_ > 0) && (! --refcount_ftextureIndex_))
594 this->remove_property(face_texture_index_);
599 bool has_vertex_normals()
const {
return vertex_normals_.
is_valid(); }
600 bool has_vertex_colors()
const {
return vertex_colors_.
is_valid(); }
601 bool has_vertex_texcoords1D()
const {
return vertex_texcoords1D_.
is_valid(); }
602 bool has_vertex_texcoords2D()
const {
return vertex_texcoords2D_.
is_valid(); }
603 bool has_vertex_texcoords3D()
const {
return vertex_texcoords3D_.
is_valid(); }
604 bool has_halfedge_texcoords1D()
const {
return halfedge_texcoords1D_.
is_valid();}
605 bool has_halfedge_texcoords2D()
const {
return halfedge_texcoords2D_.
is_valid();}
606 bool has_halfedge_texcoords3D()
const {
return halfedge_texcoords3D_.
is_valid();}
607 bool has_edge_colors()
const {
return edge_colors_.
is_valid(); }
608 bool has_halfedge_normals()
const {
return halfedge_normals_.
is_valid(); }
609 bool has_halfedge_colors()
const {
return halfedge_colors_.
is_valid(); }
610 bool has_face_normals()
const {
return face_normals_.
is_valid(); }
611 bool has_face_colors()
const {
return face_colors_.
is_valid(); }
612 bool has_face_texture_index()
const {
return face_texture_index_.
is_valid(); }
616 PointsPropertyHandle points_pph()
const
619 VertexNormalsPropertyHandle vertex_normals_pph()
const
620 {
return vertex_normals_; }
622 VertexColorsPropertyHandle vertex_colors_pph()
const
623 {
return vertex_colors_; }
625 VertexTexCoords1DPropertyHandle vertex_texcoords1D_pph()
const
626 {
return vertex_texcoords1D_; }
628 VertexTexCoords2DPropertyHandle vertex_texcoords2D_pph()
const
629 {
return vertex_texcoords2D_; }
631 VertexTexCoords3DPropertyHandle vertex_texcoords3D_pph()
const
632 {
return vertex_texcoords3D_; }
635 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_pph()
const
636 {
return halfedge_texcoords1D_; }
638 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_pph()
const
639 {
return halfedge_texcoords2D_; }
641 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_pph()
const
642 {
return halfedge_texcoords3D_; }
645 HalfedgeNormalsPropertyHandle halfedge_normals_pph()
const
646 {
return halfedge_normals_; }
650 HalfedgeColorsPropertyHandle halfedge_colors_pph()
const
651 {
return halfedge_colors_; }
654 EdgeColorsPropertyHandle edge_colors_pph()
const
655 {
return edge_colors_; }
658 FaceNormalsPropertyHandle face_normals_pph()
const
659 {
return face_normals_; }
661 FaceColorsPropertyHandle face_colors_pph()
const
662 {
return face_colors_; }
664 FaceTextureIndexPropertyHandle face_texture_index_pph()
const
665 {
return face_texture_index_; }
667 VertexData& data(VertexHandle _vh)
668 {
return this->property(data_vpph_, _vh); }
670 const VertexData& data(VertexHandle _vh)
const
671 {
return this->property(data_vpph_, _vh); }
673 FaceData& data(FaceHandle _fh)
674 {
return this->property(data_fpph_, _fh); }
676 const FaceData& data(FaceHandle _fh)
const
677 {
return this->property(data_fpph_, _fh); }
679 EdgeData& data(EdgeHandle _eh)
680 {
return this->property(data_epph_, _eh); }
682 const EdgeData& data(EdgeHandle _eh)
const
683 {
return this->property(data_epph_, _eh); }
685 HalfedgeData& data(HalfedgeHandle _heh)
686 {
return this->property(data_hpph_, _heh); }
688 const HalfedgeData& data(HalfedgeHandle _heh)
const
689 {
return this->property(data_hpph_, _heh); }
693 PointsPropertyHandle points_;
694 VertexNormalsPropertyHandle vertex_normals_;
695 VertexColorsPropertyHandle vertex_colors_;
696 VertexTexCoords1DPropertyHandle vertex_texcoords1D_;
697 VertexTexCoords2DPropertyHandle vertex_texcoords2D_;
698 VertexTexCoords3DPropertyHandle vertex_texcoords3D_;
700 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_;
701 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_;
702 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_;
703 HalfedgeNormalsPropertyHandle halfedge_normals_;
704 HalfedgeColorsPropertyHandle halfedge_colors_;
706 EdgeColorsPropertyHandle edge_colors_;
708 FaceNormalsPropertyHandle face_normals_;
709 FaceColorsPropertyHandle face_colors_;
710 FaceTextureIndexPropertyHandle face_texture_index_;
712 DataVPropHandle data_vpph_;
713 DataHPropHandle data_hpph_;
714 DataEPropHandle data_epph_;
715 DataFPropHandle data_fpph_;
717 unsigned int refcount_vnormals_;
718 unsigned int refcount_vcolors_;
719 unsigned int refcount_vtexcoords1D_;
720 unsigned int refcount_vtexcoords2D_;
721 unsigned int refcount_vtexcoords3D_;
722 unsigned int refcount_htexcoords1D_;
723 unsigned int refcount_htexcoords2D_;
724 unsigned int refcount_htexcoords3D_;
725 unsigned int refcount_henormals_;
726 unsigned int refcount_hecolors_;
727 unsigned int refcount_ecolors_;
728 unsigned int refcount_fnormals_;
729 unsigned int refcount_fcolors_;
730 unsigned int refcount_ftextureIndex_;
736 void initializeStandardProperties()
738 if(!this->get_property_handle(points_,
743 refcount_vnormals_ = this->get_property_handle(vertex_normals_,
744 "v:normals") ? 1 : 0 ;
745 refcount_vcolors_ = this->get_property_handle(vertex_colors_,
746 "v:colors") ? 1 : 0 ;
747 refcount_vtexcoords1D_ = this->get_property_handle(vertex_texcoords1D_,
748 "v:texcoords1D") ? 1 : 0 ;
749 refcount_vtexcoords2D_ = this->get_property_handle(vertex_texcoords2D_,
750 "v:texcoords2D") ? 1 : 0 ;
751 refcount_vtexcoords3D_ = this->get_property_handle(vertex_texcoords3D_,
752 "v:texcoords3D") ? 1 : 0 ;
753 refcount_htexcoords1D_ = this->get_property_handle(halfedge_texcoords1D_,
754 "h:texcoords1D") ? 1 : 0 ;
755 refcount_htexcoords2D_ = this->get_property_handle(halfedge_texcoords2D_,
756 "h:texcoords2D") ? 1 : 0 ;
757 refcount_htexcoords3D_ = this->get_property_handle(halfedge_texcoords3D_,
758 "h:texcoords3D") ? 1 : 0 ;
759 refcount_henormals_ = this->get_property_handle(halfedge_normals_,
760 "h:normals") ? 1 : 0 ;
761 refcount_hecolors_ = this->get_property_handle(halfedge_colors_,
762 "h:colors") ? 1 : 0 ;
763 refcount_ecolors_ = this->get_property_handle(edge_colors_,
764 "e:colors") ? 1 : 0 ;
765 refcount_fnormals_ = this->get_property_handle(face_normals_,
766 "f:normals") ? 1 : 0 ;
767 refcount_fcolors_ = this->get_property_handle(face_colors_,
768 "f:colors") ? 1 : 0 ;
769 refcount_ftextureIndex_ = this->get_property_handle(face_texture_index_,
770 "f:textureindex") ? 1 : 0 ;
This file provides some macros containing attribute usage.
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
@ TextureIndex
Add texture index (faces)
Definition: Attributes.hh:89
@ Normal
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:82
@ TexCoord2D
Add 2D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:87
@ TexCoord1D
Add 1D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:86
@ TexCoord3D
Add 3D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:88
@ Status
Add status to mesh item (all items)
Definition: Attributes.hh:85
@ Color
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:83
The attribute kernel adds all standard properties to the kernel.
Definition: AttribKernelT.hh:73
void assign(const _AttribKernel &_other, bool copyStandardProperties=false)
Assignment from another mesh of another type.
Definition: AttribKernelT.hh:227
bool is_valid() const
The handle is valid iff the index is not negative.
Definition: Handles.hh:72