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 MeshItems MeshItemsT;
77 typedef Connectivity ConnectivityT;
78 typedef typename Connectivity::Vertex Vertex;
79 typedef typename Connectivity::Halfedge Halfedge;
80 typedef typename Connectivity::Edge Edge;
81 typedef typename Connectivity::Face Face;
83 typedef typename MeshItems::Point Point;
89 typedef typename MeshItems::Scalar Scalar;
92 typedef typename MeshItems::VertexData VertexData;
93 typedef typename MeshItems::HalfedgeData HalfedgeData;
94 typedef typename MeshItems::EdgeData EdgeData;
95 typedef typename MeshItems::FaceData FaceData;
100 VAttribs = MeshItems::VAttribs,
101 HAttribs = MeshItems::HAttribs,
102 EAttribs = MeshItems::EAttribs,
103 FAttribs = MeshItems::FAttribs
116 : refcount_vnormals_(0),
117 refcount_vcolors_(0),
118 refcount_vtexcoords1D_(0),
119 refcount_vtexcoords2D_(0),
120 refcount_vtexcoords3D_(0),
121 refcount_htexcoords1D_(0),
122 refcount_htexcoords2D_(0),
123 refcount_htexcoords3D_(0),
124 refcount_henormals_(0),
125 refcount_hecolors_(0),
126 refcount_ecolors_(0),
127 refcount_fnormals_(0),
128 refcount_fcolors_(0),
129 refcount_ftextureIndex_(0)
131 this->add_property( points_,
"v:points" );
134 request_vertex_normals();
137 request_vertex_colors();
140 request_vertex_texcoords1D();
143 request_vertex_texcoords2D();
146 request_vertex_texcoords3D();
148 if (HAttribs & Attributes::TexCoord1D)
149 request_halfedge_texcoords1D();
151 if (HAttribs & Attributes::TexCoord2D)
152 request_halfedge_texcoords2D();
154 if (HAttribs & Attributes::TexCoord3D)
155 request_halfedge_texcoords3D();
157 if (HAttribs & Attributes::Color)
158 request_halfedge_colors();
161 Connectivity::request_vertex_status();
163 if (HAttribs & Attributes::Status)
164 Connectivity::request_halfedge_status();
166 if (HAttribs & Attributes::Normal)
167 request_halfedge_normals();
169 if (EAttribs & Attributes::Status)
170 Connectivity::request_edge_status();
172 if (EAttribs & Attributes::Color)
173 request_edge_colors();
175 if (FAttribs & Attributes::Normal)
176 request_face_normals();
178 if (FAttribs & Attributes::Color)
179 request_face_colors();
181 if (FAttribs & Attributes::Status)
182 Connectivity::request_face_status();
185 request_face_texture_index();
189 this->add_property(data_vpph_);
190 this->add_property(data_fpph_);
191 this->add_property(data_hpph_);
192 this->add_property(data_epph_);
209 template <
class _AttribKernel>
212 this->assign_connectivity(_other);
213 for (
typename Connectivity::VertexIter v_it = Connectivity::vertices_begin();
214 v_it != Connectivity::vertices_end(); ++v_it)
216 set_point(*v_it, (Point)_other.point(*v_it));
222 const Point* points()
const
223 {
return this->property(points_).data(); }
225 const Point& point(VertexHandle _vh)
const
226 {
return this->property(points_, _vh); }
228 Point& point(VertexHandle _vh)
229 {
return this->property(points_, _vh); }
231 void set_point(VertexHandle _vh,
const Point& _p)
232 { this->property(points_, _vh) = _p; }
237 const Normal* vertex_normals()
const
238 {
return this->property(vertex_normals_).data(); }
240 const Normal& normal(VertexHandle _vh)
const
241 {
return this->property(vertex_normals_, _vh); }
243 void set_normal(VertexHandle _vh,
const Normal& _n)
244 { this->property(vertex_normals_, _vh) = _n; }
249 const Color* vertex_colors()
const
250 {
return this->property(vertex_colors_).data(); }
252 const Color& color(VertexHandle _vh)
const
253 {
return this->property(vertex_colors_, _vh); }
255 void set_color(VertexHandle _vh,
const Color& _c)
256 { this->property(vertex_colors_, _vh) = _c; }
261 const TexCoord1D* texcoords1D()
const {
262 return this->property(vertex_texcoords1D_).data();
265 const TexCoord1D& texcoord1D(VertexHandle _vh)
const {
266 return this->property(vertex_texcoords1D_, _vh);
269 void set_texcoord1D(VertexHandle _vh,
const TexCoord1D& _t) {
270 this->property(vertex_texcoords1D_, _vh) = _t;
276 const TexCoord2D* texcoords2D()
const {
277 return this->property(vertex_texcoords2D_).data();
280 const TexCoord2D& texcoord2D(VertexHandle _vh)
const {
281 return this->property(vertex_texcoords2D_, _vh);
284 void set_texcoord2D(VertexHandle _vh,
const TexCoord2D& _t) {
285 this->property(vertex_texcoords2D_, _vh) = _t;
291 const TexCoord3D* texcoords3D()
const {
292 return this->property(vertex_texcoords3D_).data();
295 const TexCoord3D& texcoord3D(VertexHandle _vh)
const {
296 return this->property(vertex_texcoords3D_, _vh);
299 void set_texcoord3D(VertexHandle _vh,
const TexCoord3D& _t) {
300 this->property(vertex_texcoords3D_, _vh) = _t;
305 const TexCoord1D* htexcoords1D()
const {
306 return this->property(halfedge_texcoords1D_).data();
309 const TexCoord1D& texcoord1D(HalfedgeHandle _heh)
const {
310 return this->property(halfedge_texcoords1D_, _heh);
313 void set_texcoord1D(HalfedgeHandle _heh,
const TexCoord1D& _t) {
314 this->property(halfedge_texcoords1D_, _heh) = _t;
320 const TexCoord2D* htexcoords2D()
const {
321 return this->property(halfedge_texcoords2D_).data();
324 const TexCoord2D& texcoord2D(HalfedgeHandle _heh)
const {
325 return this->property(halfedge_texcoords2D_, _heh);
328 void set_texcoord2D(HalfedgeHandle _heh,
const TexCoord2D& _t) {
329 this->property(halfedge_texcoords2D_, _heh) = _t;
335 const TexCoord3D* htexcoords3D()
const {
336 return this->property(halfedge_texcoords3D_).data();
339 const TexCoord3D& texcoord3D(HalfedgeHandle _heh)
const {
340 return this->property(halfedge_texcoords3D_, _heh);
343 void set_texcoord3D(HalfedgeHandle _heh,
const TexCoord3D& _t) {
344 this->property(halfedge_texcoords3D_, _heh) = _t;
349 const Color* edge_colors()
const
350 {
return this->property(edge_colors_).data(); }
352 const Color& color(EdgeHandle _eh)
const
353 {
return this->property(edge_colors_, _eh); }
355 void set_color(EdgeHandle _eh,
const Color& _c)
356 { this->property(edge_colors_, _eh) = _c; }
361 const Normal& normal(HalfedgeHandle _heh)
const
362 {
return this->property(halfedge_normals_, _heh); }
364 void set_normal(HalfedgeHandle _heh,
const Normal& _n)
365 { this->property(halfedge_normals_, _heh) = _n; }
370 const Color* halfedge_colors()
const
371 {
return this->property(halfedge_colors_).data(); }
373 const Color& color(HalfedgeHandle _heh)
const
374 {
return this->property(halfedge_colors_, _heh); }
376 void set_color(HalfedgeHandle _heh,
const Color& _c)
377 { this->property(halfedge_colors_, _heh) = _c; }
381 const Normal& normal(FaceHandle _fh)
const
382 {
return this->property(face_normals_, _fh); }
384 void set_normal(FaceHandle _fh,
const Normal& _n)
385 { this->property(face_normals_, _fh) = _n; }
389 const TextureIndex& texture_index(FaceHandle _fh)
const
390 {
return this->property(face_texture_index_, _fh); }
392 void set_texture_index(FaceHandle _fh,
const TextureIndex& _t)
393 { this->property(face_texture_index_, _fh) = _t; }
397 const Color& color(FaceHandle _fh)
const
398 {
return this->property(face_colors_, _fh); }
400 void set_color(FaceHandle _fh,
const Color& _c)
401 { this->property(face_colors_, _fh) = _c; }
405 void request_vertex_normals()
407 if (!refcount_vnormals_++)
408 this->add_property( vertex_normals_,
"v:normals" );
411 void request_vertex_colors()
413 if (!refcount_vcolors_++)
414 this->add_property( vertex_colors_,
"v:colors" );
417 void request_vertex_texcoords1D()
419 if (!refcount_vtexcoords1D_++)
420 this->add_property( vertex_texcoords1D_,
"v:texcoords1D" );
423 void request_vertex_texcoords2D()
425 if (!refcount_vtexcoords2D_++)
426 this->add_property( vertex_texcoords2D_,
"v:texcoords2D" );
429 void request_vertex_texcoords3D()
431 if (!refcount_vtexcoords3D_++)
432 this->add_property( vertex_texcoords3D_,
"v:texcoords3D" );
435 void request_halfedge_texcoords1D()
437 if (!refcount_htexcoords1D_++)
438 this->add_property( halfedge_texcoords1D_,
"h:texcoords1D" );
441 void request_halfedge_texcoords2D()
443 if (!refcount_htexcoords2D_++)
444 this->add_property( halfedge_texcoords2D_,
"h:texcoords2D" );
447 void request_halfedge_texcoords3D()
449 if (!refcount_htexcoords3D_++)
450 this->add_property( halfedge_texcoords3D_,
"h:texcoords3D" );
453 void request_edge_colors()
455 if (!refcount_ecolors_++)
456 this->add_property( edge_colors_,
"e:colors" );
459 void request_halfedge_normals()
461 if (!refcount_henormals_++)
462 this->add_property( halfedge_normals_,
"h:normals" );
465 void request_halfedge_colors()
467 if (!refcount_hecolors_++)
468 this->add_property( halfedge_colors_,
"h:colors" );
471 void request_face_normals()
473 if (!refcount_fnormals_++)
474 this->add_property( face_normals_,
"f:normals" );
477 void request_face_colors()
479 if (!refcount_fcolors_++)
480 this->add_property( face_colors_,
"f:colors" );
483 void request_face_texture_index()
485 if (!refcount_ftextureIndex_++)
486 this->add_property( face_texture_index_,
"f:textureindex" );
491 void release_vertex_normals()
493 if ((refcount_vnormals_ > 0) && (! --refcount_vnormals_))
494 this->remove_property(vertex_normals_);
497 void release_vertex_colors()
499 if ((refcount_vcolors_ > 0) && (! --refcount_vcolors_))
500 this->remove_property(vertex_colors_);
503 void release_vertex_texcoords1D() {
504 if ((refcount_vtexcoords1D_ > 0) && (! --refcount_vtexcoords1D_))
505 this->remove_property(vertex_texcoords1D_);
508 void release_vertex_texcoords2D() {
509 if ((refcount_vtexcoords2D_ > 0) && (! --refcount_vtexcoords2D_))
510 this->remove_property(vertex_texcoords2D_);
513 void release_vertex_texcoords3D() {
514 if ((refcount_vtexcoords3D_ > 0) && (! --refcount_vtexcoords3D_))
515 this->remove_property(vertex_texcoords3D_);
518 void release_halfedge_texcoords1D() {
519 if ((refcount_htexcoords1D_ > 0) && (! --refcount_htexcoords1D_))
520 this->remove_property(halfedge_texcoords1D_);
523 void release_halfedge_texcoords2D() {
524 if ((refcount_htexcoords2D_ > 0) && (! --refcount_htexcoords2D_))
525 this->remove_property(halfedge_texcoords2D_);
528 void release_halfedge_texcoords3D() {
529 if ((refcount_htexcoords3D_ > 0) && (! --refcount_htexcoords3D_))
530 this->remove_property(halfedge_texcoords3D_);
533 void release_edge_colors()
535 if ((refcount_ecolors_ > 0) && (! --refcount_ecolors_))
536 this->remove_property(edge_colors_);
539 void release_halfedge_normals()
541 if ((refcount_henormals_ > 0) && (! --refcount_henormals_))
542 this->remove_property(halfedge_normals_);
545 void release_halfedge_colors()
547 if ((refcount_hecolors_ > 0) && (! --refcount_hecolors_))
548 this->remove_property(halfedge_colors_);
551 void release_face_normals()
553 if ((refcount_fnormals_ > 0) && (! --refcount_fnormals_))
554 this->remove_property(face_normals_);
557 void release_face_colors()
559 if ((refcount_fcolors_ > 0) && (! --refcount_fcolors_))
560 this->remove_property(face_colors_);
563 void release_face_texture_index()
565 if ((refcount_ftextureIndex_ > 0) && (! --refcount_ftextureIndex_))
566 this->remove_property(face_texture_index_);
571 bool has_vertex_normals()
const {
return vertex_normals_.
is_valid(); }
572 bool has_vertex_colors()
const {
return vertex_colors_.
is_valid(); }
573 bool has_vertex_texcoords1D()
const {
return vertex_texcoords1D_.
is_valid(); }
574 bool has_vertex_texcoords2D()
const {
return vertex_texcoords2D_.
is_valid(); }
575 bool has_vertex_texcoords3D()
const {
return vertex_texcoords3D_.
is_valid(); }
576 bool has_halfedge_texcoords1D()
const {
return halfedge_texcoords1D_.
is_valid();}
577 bool has_halfedge_texcoords2D()
const {
return halfedge_texcoords2D_.
is_valid();}
578 bool has_halfedge_texcoords3D()
const {
return halfedge_texcoords3D_.
is_valid();}
579 bool has_edge_colors()
const {
return edge_colors_.
is_valid(); }
580 bool has_halfedge_normals()
const {
return halfedge_normals_.
is_valid(); }
581 bool has_halfedge_colors()
const {
return halfedge_colors_.
is_valid(); }
582 bool has_face_normals()
const {
return face_normals_.
is_valid(); }
583 bool has_face_colors()
const {
return face_colors_.
is_valid(); }
584 bool has_face_texture_index()
const {
return face_texture_index_.
is_valid(); }
588 typedef VPropHandleT<Point> PointsPropertyHandle;
589 typedef VPropHandleT<Normal> VertexNormalsPropertyHandle;
590 typedef VPropHandleT<Color> VertexColorsPropertyHandle;
591 typedef VPropHandleT<TexCoord1D> VertexTexCoords1DPropertyHandle;
592 typedef VPropHandleT<TexCoord2D> VertexTexCoords2DPropertyHandle;
593 typedef VPropHandleT<TexCoord3D> VertexTexCoords3DPropertyHandle;
594 typedef HPropHandleT<TexCoord1D> HalfedgeTexCoords1DPropertyHandle;
595 typedef HPropHandleT<TexCoord2D> HalfedgeTexCoords2DPropertyHandle;
596 typedef HPropHandleT<TexCoord3D> HalfedgeTexCoords3DPropertyHandle;
597 typedef EPropHandleT<Color> EdgeColorsPropertyHandle;
598 typedef HPropHandleT<Normal> HalfedgeNormalsPropertyHandle;
599 typedef HPropHandleT<Color> HalfedgeColorsPropertyHandle;
600 typedef FPropHandleT<Normal> FaceNormalsPropertyHandle;
601 typedef FPropHandleT<Color> FaceColorsPropertyHandle;
602 typedef FPropHandleT<TextureIndex> FaceTextureIndexPropertyHandle;
606 PointsPropertyHandle points_pph()
const
609 VertexNormalsPropertyHandle vertex_normals_pph()
const
610 {
return vertex_normals_; }
612 VertexColorsPropertyHandle vertex_colors_pph()
const
613 {
return vertex_colors_; }
615 VertexTexCoords1DPropertyHandle vertex_texcoords1D_pph()
const
616 {
return vertex_texcoords1D_; }
618 VertexTexCoords2DPropertyHandle vertex_texcoords2D_pph()
const
619 {
return vertex_texcoords2D_; }
621 VertexTexCoords3DPropertyHandle vertex_texcoords3D_pph()
const
622 {
return vertex_texcoords3D_; }
625 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_pph()
const
626 {
return halfedge_texcoords1D_; }
628 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_pph()
const
629 {
return halfedge_texcoords2D_; }
631 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_pph()
const
632 {
return halfedge_texcoords3D_; }
635 HalfedgeNormalsPropertyHandle halfedge_normals_pph()
const
636 {
return halfedge_normals_; }
640 HalfedgeColorsPropertyHandle halfedge_colors_pph()
const
641 {
return halfedge_colors_; }
644 EdgeColorsPropertyHandle edge_colors_pph()
const
645 {
return edge_colors_; }
648 FaceNormalsPropertyHandle face_normals_pph()
const
649 {
return face_normals_; }
651 FaceColorsPropertyHandle face_colors_pph()
const
652 {
return face_colors_; }
654 FaceTextureIndexPropertyHandle face_texture_index_pph()
const
655 {
return face_texture_index_; }
657 VertexData& data(VertexHandle _vh)
658 {
return this->property(data_vpph_, _vh); }
660 const VertexData& data(VertexHandle _vh)
const
661 {
return this->property(data_vpph_, _vh); }
663 FaceData& data(FaceHandle _fh)
664 {
return this->property(data_fpph_, _fh); }
666 const FaceData& data(FaceHandle _fh)
const
667 {
return this->property(data_fpph_, _fh); }
669 EdgeData& data(EdgeHandle _eh)
670 {
return this->property(data_epph_, _eh); }
672 const EdgeData& data(EdgeHandle _eh)
const
673 {
return this->property(data_epph_, _eh); }
675 HalfedgeData& data(HalfedgeHandle _heh)
676 {
return this->property(data_hpph_, _heh); }
678 const HalfedgeData& data(HalfedgeHandle _heh)
const
679 {
return this->property(data_hpph_, _heh); }
683 PointsPropertyHandle points_;
684 VertexNormalsPropertyHandle vertex_normals_;
685 VertexColorsPropertyHandle vertex_colors_;
686 VertexTexCoords1DPropertyHandle vertex_texcoords1D_;
687 VertexTexCoords2DPropertyHandle vertex_texcoords2D_;
688 VertexTexCoords3DPropertyHandle vertex_texcoords3D_;
690 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_;
691 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_;
692 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_;
693 HalfedgeNormalsPropertyHandle halfedge_normals_;
694 HalfedgeColorsPropertyHandle halfedge_colors_;
696 EdgeColorsPropertyHandle edge_colors_;
698 FaceNormalsPropertyHandle face_normals_;
699 FaceColorsPropertyHandle face_colors_;
700 FaceTextureIndexPropertyHandle face_texture_index_;
702 DataVPropHandle data_vpph_;
703 DataHPropHandle data_hpph_;
704 DataEPropHandle data_epph_;
705 DataFPropHandle data_fpph_;
707 unsigned int refcount_vnormals_;
708 unsigned int refcount_vcolors_;
709 unsigned int refcount_vtexcoords1D_;
710 unsigned int refcount_vtexcoords2D_;
711 unsigned int refcount_vtexcoords3D_;
712 unsigned int refcount_htexcoords1D_;
713 unsigned int refcount_htexcoords2D_;
714 unsigned int refcount_htexcoords3D_;
715 unsigned int refcount_henormals_;
716 unsigned int refcount_hecolors_;
717 unsigned int refcount_ecolors_;
718 unsigned int refcount_fnormals_;
719 unsigned int refcount_fcolors_;
720 unsigned int refcount_ftextureIndex_;
726 #endif // OPENMESH_ATTRIBKERNEL_HH defined
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:80
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:81
Add 1D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:84
Add status to mesh item (all items)
Definition: Attributes.hh:83
Add 2D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:85
Add 3D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:86
This file provides some macros containing attribute usage.
void assign(const _AttribKernel &_other)
Assignment from another mesh of another type.
Definition: AttribKernelT.hh:210
Add texture index (faces)
Definition: Attributes.hh:87
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:56
The attribute kernel adds all standard properties to the kernel.
Definition: AttribKernelT.hh:70
bool is_valid() const
The handle is valid iff the index is not equal to -1.
Definition: Handles.hh:70