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>
71template <
class MeshItems,
class Connectivity>
79 VAttribs = MeshItems::VAttribs,
80 HAttribs = MeshItems::HAttribs,
81 EAttribs = MeshItems::EAttribs,
82 FAttribs = MeshItems::FAttribs
85 typedef MeshItems MeshItemsT;
86 typedef Connectivity ConnectivityT;
87 typedef typename Connectivity::Vertex Vertex;
90 typedef typename GenProg::IF<
92 typename Connectivity::Halfedge,
93 typename Connectivity::HalfedgeNoPrev
95 typedef typename GenProg::IF<
97 GenProg::Bool2Type<true>,
98 GenProg::Bool2Type<false>
99 >::Result HasPrevHalfedge;
102 typedef typename Connectivity::Edge Edge;
103 typedef typename Connectivity::Face Face;
105 typedef typename MeshItems::Point Point;
111 typedef typename MeshItems::Scalar Scalar;
114 typedef typename MeshItems::VertexData VertexData;
115 typedef typename MeshItems::HalfedgeData HalfedgeData;
116 typedef typename MeshItems::EdgeData EdgeData;
117 typedef typename MeshItems::FaceData FaceData;
148 : refcount_vnormals_(0),
149 refcount_vcolors_(0),
150 refcount_vtexcoords1D_(0),
151 refcount_vtexcoords2D_(0),
152 refcount_vtexcoords3D_(0),
153 refcount_htexcoords1D_(0),
154 refcount_htexcoords2D_(0),
155 refcount_htexcoords3D_(0),
156 refcount_henormals_(0),
157 refcount_hecolors_(0),
158 refcount_ecolors_(0),
159 refcount_fnormals_(0),
160 refcount_fcolors_(0),
161 refcount_ftextureIndex_(0)
163 this->add_property( points_,
"v:points" );
166 request_vertex_normals();
169 request_vertex_colors();
172 request_vertex_texcoords1D();
175 request_vertex_texcoords2D();
178 request_vertex_texcoords3D();
181 request_halfedge_texcoords1D();
184 request_halfedge_texcoords2D();
187 request_halfedge_texcoords3D();
190 request_halfedge_colors();
193 Connectivity::request_vertex_status();
196 Connectivity::request_halfedge_status();
199 request_halfedge_normals();
202 Connectivity::request_edge_status();
205 request_edge_colors();
208 request_face_normals();
211 request_face_colors();
214 Connectivity::request_face_status();
217 request_face_texture_index();
221 this->add_property(data_vpph_);
222 this->add_property(data_fpph_);
223 this->add_property(data_hpph_);
224 this->add_property(data_epph_);
240 template <
class _AttribKernel>
241 void assign(
const _AttribKernel& _other,
bool copyStandardProperties =
false)
244 if(copyStandardProperties)
245 this->copy_all_kernel_properties(_other);
247 this->assign_connectivity(_other);
248 for (
typename Connectivity::VertexIter v_it = Connectivity::vertices_begin();
249 v_it != Connectivity::vertices_end(); ++v_it)
251 set_point(*v_it, (Point)_other.point(*v_it));
255 if(copyStandardProperties)
256 initializeStandardProperties();
261 const Point* points()
const
262 {
return this->property(points_).data(); }
264 const Point& point(VertexHandle _vh)
const
265 {
return this->property(points_, _vh); }
267 Point& point(VertexHandle _vh)
268 {
return this->property(points_, _vh); }
270 void set_point(VertexHandle _vh,
const Point& _p)
271 { this->property(points_, _vh) = _p; }
273 const PointsPropertyHandle& points_property_handle()
const
279 const Normal* vertex_normals()
const
280 {
return this->property(vertex_normals_).data(); }
282 const Normal& normal(VertexHandle _vh)
const
283 {
return this->property(vertex_normals_, _vh); }
285 void set_normal(VertexHandle _vh,
const Normal& _n)
286 { this->property(vertex_normals_, _vh) = _n; }
291 const Color* vertex_colors()
const
292 {
return this->property(vertex_colors_).data(); }
294 const Color& color(VertexHandle _vh)
const
295 {
return this->property(vertex_colors_, _vh); }
297 void set_color(VertexHandle _vh,
const Color& _c)
298 { this->property(vertex_colors_, _vh) = _c; }
304 return this->property(vertex_texcoords1D_).data();
307 const TexCoord1D& texcoord1D(VertexHandle _vh)
const {
308 return this->property(vertex_texcoords1D_, _vh);
311 void set_texcoord1D(VertexHandle _vh,
const TexCoord1D& _t) {
312 this->property(vertex_texcoords1D_, _vh) = _t;
319 return this->property(vertex_texcoords2D_).data();
322 const TexCoord2D& texcoord2D(VertexHandle _vh)
const {
323 return this->property(vertex_texcoords2D_, _vh);
326 void set_texcoord2D(VertexHandle _vh,
const TexCoord2D& _t) {
327 this->property(vertex_texcoords2D_, _vh) = _t;
334 return this->property(vertex_texcoords3D_).data();
337 const TexCoord3D& texcoord3D(VertexHandle _vh)
const {
338 return this->property(vertex_texcoords3D_, _vh);
341 void set_texcoord3D(VertexHandle _vh,
const TexCoord3D& _t) {
342 this->property(vertex_texcoords3D_, _vh) = _t;
348 return this->property(halfedge_texcoords1D_).data();
351 const TexCoord1D& texcoord1D(HalfedgeHandle _heh)
const {
352 return this->property(halfedge_texcoords1D_, _heh);
355 void set_texcoord1D(HalfedgeHandle _heh,
const TexCoord1D& _t) {
356 this->property(halfedge_texcoords1D_, _heh) = _t;
363 return this->property(halfedge_texcoords2D_).data();
366 const TexCoord2D& texcoord2D(HalfedgeHandle _heh)
const {
367 return this->property(halfedge_texcoords2D_, _heh);
370 void set_texcoord2D(HalfedgeHandle _heh,
const TexCoord2D& _t) {
371 this->property(halfedge_texcoords2D_, _heh) = _t;
378 return this->property(halfedge_texcoords3D_).data();
381 const TexCoord3D& texcoord3D(HalfedgeHandle _heh)
const {
382 return this->property(halfedge_texcoords3D_, _heh);
385 void set_texcoord3D(HalfedgeHandle _heh,
const TexCoord3D& _t) {
386 this->property(halfedge_texcoords3D_, _heh) = _t;
391 const Color* edge_colors()
const
392 {
return this->property(edge_colors_).data(); }
394 const Color& color(EdgeHandle _eh)
const
395 {
return this->property(edge_colors_, _eh); }
397 void set_color(EdgeHandle _eh,
const Color& _c)
398 { this->property(edge_colors_, _eh) = _c; }
403 const Normal& normal(HalfedgeHandle _heh)
const
404 {
return this->property(halfedge_normals_, _heh); }
406 void set_normal(HalfedgeHandle _heh,
const Normal& _n)
407 { this->property(halfedge_normals_, _heh) = _n; }
412 const Color* halfedge_colors()
const
413 {
return this->property(halfedge_colors_).data(); }
415 const Color& color(HalfedgeHandle _heh)
const
416 {
return this->property(halfedge_colors_, _heh); }
418 void set_color(HalfedgeHandle _heh,
const Color& _c)
419 { this->property(halfedge_colors_, _heh) = _c; }
423 const Normal& normal(FaceHandle _fh)
const
424 {
return this->property(face_normals_, _fh); }
426 void set_normal(FaceHandle _fh,
const Normal& _n)
427 { this->property(face_normals_, _fh) = _n; }
432 {
return this->property(face_texture_index_, _fh); }
434 void set_texture_index(FaceHandle _fh,
const TextureIndex& _t)
435 { this->property(face_texture_index_, _fh) = _t; }
439 const Color& color(FaceHandle _fh)
const
440 {
return this->property(face_colors_, _fh); }
442 void set_color(FaceHandle _fh,
const Color& _c)
443 { this->property(face_colors_, _fh) = _c; }
447 void request_vertex_normals()
449 if (!refcount_vnormals_++)
450 this->add_property( vertex_normals_,
"v:normals" );
453 void request_vertex_colors()
455 if (!refcount_vcolors_++)
456 this->add_property( vertex_colors_,
"v:colors" );
459 void request_vertex_texcoords1D()
461 if (!refcount_vtexcoords1D_++)
462 this->add_property( vertex_texcoords1D_,
"v:texcoords1D" );
465 void request_vertex_texcoords2D()
467 if (!refcount_vtexcoords2D_++)
468 this->add_property( vertex_texcoords2D_,
"v:texcoords2D" );
471 void request_vertex_texcoords3D()
473 if (!refcount_vtexcoords3D_++)
474 this->add_property( vertex_texcoords3D_,
"v:texcoords3D" );
477 void request_halfedge_texcoords1D()
479 if (!refcount_htexcoords1D_++)
480 this->add_property( halfedge_texcoords1D_,
"h:texcoords1D" );
483 void request_halfedge_texcoords2D()
485 if (!refcount_htexcoords2D_++)
486 this->add_property( halfedge_texcoords2D_,
"h:texcoords2D" );
489 void request_halfedge_texcoords3D()
491 if (!refcount_htexcoords3D_++)
492 this->add_property( halfedge_texcoords3D_,
"h:texcoords3D" );
495 void request_edge_colors()
497 if (!refcount_ecolors_++)
498 this->add_property( edge_colors_,
"e:colors" );
501 void request_halfedge_normals()
503 if (!refcount_henormals_++)
504 this->add_property( halfedge_normals_,
"h:normals" );
507 void request_halfedge_colors()
509 if (!refcount_hecolors_++)
510 this->add_property( halfedge_colors_,
"h:colors" );
513 void request_face_normals()
515 if (!refcount_fnormals_++)
516 this->add_property( face_normals_,
"f:normals" );
519 void request_face_colors()
521 if (!refcount_fcolors_++)
522 this->add_property( face_colors_,
"f:colors" );
525 void request_face_texture_index()
527 if (!refcount_ftextureIndex_++)
528 this->add_property( face_texture_index_,
"f:textureindex" );
533 void release_vertex_normals()
535 if ((refcount_vnormals_ > 0) && (! --refcount_vnormals_))
536 this->remove_property(vertex_normals_);
539 void release_vertex_colors()
541 if ((refcount_vcolors_ > 0) && (! --refcount_vcolors_))
542 this->remove_property(vertex_colors_);
545 void release_vertex_texcoords1D() {
546 if ((refcount_vtexcoords1D_ > 0) && (! --refcount_vtexcoords1D_))
547 this->remove_property(vertex_texcoords1D_);
550 void release_vertex_texcoords2D() {
551 if ((refcount_vtexcoords2D_ > 0) && (! --refcount_vtexcoords2D_))
552 this->remove_property(vertex_texcoords2D_);
555 void release_vertex_texcoords3D() {
556 if ((refcount_vtexcoords3D_ > 0) && (! --refcount_vtexcoords3D_))
557 this->remove_property(vertex_texcoords3D_);
560 void release_halfedge_texcoords1D() {
561 if ((refcount_htexcoords1D_ > 0) && (! --refcount_htexcoords1D_))
562 this->remove_property(halfedge_texcoords1D_);
565 void release_halfedge_texcoords2D() {
566 if ((refcount_htexcoords2D_ > 0) && (! --refcount_htexcoords2D_))
567 this->remove_property(halfedge_texcoords2D_);
570 void release_halfedge_texcoords3D() {
571 if ((refcount_htexcoords3D_ > 0) && (! --refcount_htexcoords3D_))
572 this->remove_property(halfedge_texcoords3D_);
575 void release_edge_colors()
577 if ((refcount_ecolors_ > 0) && (! --refcount_ecolors_))
578 this->remove_property(edge_colors_);
581 void release_halfedge_normals()
583 if ((refcount_henormals_ > 0) && (! --refcount_henormals_))
584 this->remove_property(halfedge_normals_);
587 void release_halfedge_colors()
589 if ((refcount_hecolors_ > 0) && (! --refcount_hecolors_))
590 this->remove_property(halfedge_colors_);
593 void release_face_normals()
595 if ((refcount_fnormals_ > 0) && (! --refcount_fnormals_))
596 this->remove_property(face_normals_);
599 void release_face_colors()
601 if ((refcount_fcolors_ > 0) && (! --refcount_fcolors_))
602 this->remove_property(face_colors_);
605 void release_face_texture_index()
607 if ((refcount_ftextureIndex_ > 0) && (! --refcount_ftextureIndex_))
608 this->remove_property(face_texture_index_);
613 bool has_vertex_normals()
const {
return vertex_normals_.
is_valid(); }
614 bool has_vertex_colors()
const {
return vertex_colors_.
is_valid(); }
615 bool has_vertex_texcoords1D()
const {
return vertex_texcoords1D_.
is_valid(); }
616 bool has_vertex_texcoords2D()
const {
return vertex_texcoords2D_.
is_valid(); }
617 bool has_vertex_texcoords3D()
const {
return vertex_texcoords3D_.
is_valid(); }
618 bool has_halfedge_texcoords1D()
const {
return halfedge_texcoords1D_.
is_valid();}
619 bool has_halfedge_texcoords2D()
const {
return halfedge_texcoords2D_.
is_valid();}
620 bool has_halfedge_texcoords3D()
const {
return halfedge_texcoords3D_.
is_valid();}
621 bool has_edge_colors()
const {
return edge_colors_.
is_valid(); }
622 bool has_halfedge_normals()
const {
return halfedge_normals_.
is_valid(); }
623 bool has_halfedge_colors()
const {
return halfedge_colors_.
is_valid(); }
624 bool has_face_normals()
const {
return face_normals_.
is_valid(); }
625 bool has_face_colors()
const {
return face_colors_.
is_valid(); }
626 bool has_face_texture_index()
const {
return face_texture_index_.
is_valid(); }
630 PointsPropertyHandle points_pph()
const
633 VertexNormalsPropertyHandle vertex_normals_pph()
const
634 {
return vertex_normals_; }
636 VertexColorsPropertyHandle vertex_colors_pph()
const
637 {
return vertex_colors_; }
639 VertexTexCoords1DPropertyHandle vertex_texcoords1D_pph()
const
640 {
return vertex_texcoords1D_; }
642 VertexTexCoords2DPropertyHandle vertex_texcoords2D_pph()
const
643 {
return vertex_texcoords2D_; }
645 VertexTexCoords3DPropertyHandle vertex_texcoords3D_pph()
const
646 {
return vertex_texcoords3D_; }
649 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_pph()
const
650 {
return halfedge_texcoords1D_; }
652 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_pph()
const
653 {
return halfedge_texcoords2D_; }
655 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_pph()
const
656 {
return halfedge_texcoords3D_; }
659 HalfedgeNormalsPropertyHandle halfedge_normals_pph()
const
660 {
return halfedge_normals_; }
664 HalfedgeColorsPropertyHandle halfedge_colors_pph()
const
665 {
return halfedge_colors_; }
668 EdgeColorsPropertyHandle edge_colors_pph()
const
669 {
return edge_colors_; }
672 FaceNormalsPropertyHandle face_normals_pph()
const
673 {
return face_normals_; }
675 FaceColorsPropertyHandle face_colors_pph()
const
676 {
return face_colors_; }
678 FaceTextureIndexPropertyHandle face_texture_index_pph()
const
679 {
return face_texture_index_; }
681 VertexData& data(VertexHandle _vh)
682 {
return this->property(data_vpph_, _vh); }
684 const VertexData& data(VertexHandle _vh)
const
685 {
return this->property(data_vpph_, _vh); }
687 FaceData& data(FaceHandle _fh)
688 {
return this->property(data_fpph_, _fh); }
690 const FaceData& data(FaceHandle _fh)
const
691 {
return this->property(data_fpph_, _fh); }
693 EdgeData& data(EdgeHandle _eh)
694 {
return this->property(data_epph_, _eh); }
696 const EdgeData& data(EdgeHandle _eh)
const
697 {
return this->property(data_epph_, _eh); }
699 HalfedgeData& data(HalfedgeHandle _heh)
700 {
return this->property(data_hpph_, _heh); }
702 const HalfedgeData& data(HalfedgeHandle _heh)
const
703 {
return this->property(data_hpph_, _heh); }
707 PointsPropertyHandle points_;
708 VertexNormalsPropertyHandle vertex_normals_;
709 VertexColorsPropertyHandle vertex_colors_;
710 VertexTexCoords1DPropertyHandle vertex_texcoords1D_;
711 VertexTexCoords2DPropertyHandle vertex_texcoords2D_;
712 VertexTexCoords3DPropertyHandle vertex_texcoords3D_;
714 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_;
715 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_;
716 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_;
717 HalfedgeNormalsPropertyHandle halfedge_normals_;
718 HalfedgeColorsPropertyHandle halfedge_colors_;
720 EdgeColorsPropertyHandle edge_colors_;
722 FaceNormalsPropertyHandle face_normals_;
723 FaceColorsPropertyHandle face_colors_;
724 FaceTextureIndexPropertyHandle face_texture_index_;
726 DataVPropHandle data_vpph_;
727 DataHPropHandle data_hpph_;
728 DataEPropHandle data_epph_;
729 DataFPropHandle data_fpph_;
731 unsigned int refcount_vnormals_;
732 unsigned int refcount_vcolors_;
733 unsigned int refcount_vtexcoords1D_;
734 unsigned int refcount_vtexcoords2D_;
735 unsigned int refcount_vtexcoords3D_;
736 unsigned int refcount_htexcoords1D_;
737 unsigned int refcount_htexcoords2D_;
738 unsigned int refcount_htexcoords3D_;
739 unsigned int refcount_henormals_;
740 unsigned int refcount_hecolors_;
741 unsigned int refcount_ecolors_;
742 unsigned int refcount_fnormals_;
743 unsigned int refcount_fcolors_;
744 unsigned int refcount_ftextureIndex_;
750 void initializeStandardProperties()
752 if(!this->get_property_handle(points_,
757 refcount_vnormals_ = this->get_property_handle(vertex_normals_,
758 "v:normals") ? 1 : 0 ;
759 refcount_vcolors_ = this->get_property_handle(vertex_colors_,
760 "v:colors") ? 1 : 0 ;
761 refcount_vtexcoords1D_ = this->get_property_handle(vertex_texcoords1D_,
762 "v:texcoords1D") ? 1 : 0 ;
763 refcount_vtexcoords2D_ = this->get_property_handle(vertex_texcoords2D_,
764 "v:texcoords2D") ? 1 : 0 ;
765 refcount_vtexcoords3D_ = this->get_property_handle(vertex_texcoords3D_,
766 "v:texcoords3D") ? 1 : 0 ;
767 refcount_htexcoords1D_ = this->get_property_handle(halfedge_texcoords1D_,
768 "h:texcoords1D") ? 1 : 0 ;
769 refcount_htexcoords2D_ = this->get_property_handle(halfedge_texcoords2D_,
770 "h:texcoords2D") ? 1 : 0 ;
771 refcount_htexcoords3D_ = this->get_property_handle(halfedge_texcoords3D_,
772 "h:texcoords3D") ? 1 : 0 ;
773 refcount_henormals_ = this->get_property_handle(halfedge_normals_,
774 "h:normals") ? 1 : 0 ;
775 refcount_hecolors_ = this->get_property_handle(halfedge_colors_,
776 "h:colors") ? 1 : 0 ;
777 refcount_ecolors_ = this->get_property_handle(edge_colors_,
778 "e:colors") ? 1 : 0 ;
779 refcount_fnormals_ = this->get_property_handle(face_normals_,
780 "f:normals") ? 1 : 0 ;
781 refcount_fcolors_ = this->get_property_handle(face_colors_,
782 "f:colors") ? 1 : 0 ;
783 refcount_ftextureIndex_ = this->get_property_handle(face_texture_index_,
784 "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
@ PrevHalfedge
Add storage for previous halfedge (halfedges). The bit is set by default in the DefaultTraits.
Definition: Attributes.hh:84
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:241
bool is_valid() const
The handle is valid iff the index is not negative.
Definition: Handles.hh:72