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
118 : refcount_vnormals_(0),
119 refcount_vcolors_(0),
120 refcount_vtexcoords1D_(0),
121 refcount_vtexcoords2D_(0),
122 refcount_vtexcoords3D_(0),
123 refcount_htexcoords1D_(0),
124 refcount_htexcoords2D_(0),
125 refcount_htexcoords3D_(0),
126 refcount_henormals_(0),
127 refcount_hecolors_(0),
128 refcount_ecolors_(0),
129 refcount_fnormals_(0),
130 refcount_fcolors_(0),
131 refcount_ftextureIndex_(0)
133 this->add_property( points_,
"v:points" );
136 request_vertex_normals();
139 request_vertex_colors();
142 request_vertex_texcoords1D();
145 request_vertex_texcoords2D();
148 request_vertex_texcoords3D();
150 if (HAttribs & Attributes::TexCoord1D)
151 request_halfedge_texcoords1D();
153 if (HAttribs & Attributes::TexCoord2D)
154 request_halfedge_texcoords2D();
156 if (HAttribs & Attributes::TexCoord3D)
157 request_halfedge_texcoords3D();
159 if (HAttribs & Attributes::Color)
160 request_halfedge_colors();
163 Connectivity::request_vertex_status();
165 if (HAttribs & Attributes::Status)
166 Connectivity::request_halfedge_status();
168 if (HAttribs & Attributes::Normal)
169 request_halfedge_normals();
171 if (EAttribs & Attributes::Status)
172 Connectivity::request_edge_status();
174 if (EAttribs & Attributes::Color)
175 request_edge_colors();
177 if (FAttribs & Attributes::Normal)
178 request_face_normals();
180 if (FAttribs & Attributes::Color)
181 request_face_colors();
183 if (FAttribs & Attributes::Status)
184 Connectivity::request_face_status();
187 request_face_texture_index();
191 this->add_property(data_vpph_);
192 this->add_property(data_fpph_);
193 this->add_property(data_hpph_);
194 this->add_property(data_epph_);
210 template <
class _AttribKernel>
211 void assign(
const _AttribKernel& _other,
bool copyStandardProperties =
false)
214 if(copyStandardProperties)
215 this->copy_all_kernel_properties(_other);
217 this->assign_connectivity(_other);
218 for (
typename Connectivity::VertexIter v_it = Connectivity::vertices_begin();
219 v_it != Connectivity::vertices_end(); ++v_it)
221 set_point(*v_it, (Point)_other.point(*v_it));
225 if(copyStandardProperties)
226 initializeStandardProperties();
231 const Point* points()
const 232 {
return this->property(points_).data(); }
235 {
return this->property(points_, _vh); }
238 {
return this->property(points_, _vh); }
241 { this->property(points_, _vh) = _p; }
246 const Normal* vertex_normals()
const 247 {
return this->property(vertex_normals_).data(); }
250 {
return this->property(vertex_normals_, _vh); }
253 { this->property(vertex_normals_, _vh) = _n; }
258 const Color* vertex_colors()
const 259 {
return this->property(vertex_colors_).data(); }
262 {
return this->property(vertex_colors_, _vh); }
265 { this->property(vertex_colors_, _vh) = _c; }
270 const TexCoord1D* texcoords1D()
const {
271 return this->property(vertex_texcoords1D_).data();
275 return this->property(vertex_texcoords1D_, _vh);
278 void set_texcoord1D(
VertexHandle _vh,
const TexCoord1D& _t) {
279 this->property(vertex_texcoords1D_, _vh) = _t;
285 const TexCoord2D* texcoords2D()
const {
286 return this->property(vertex_texcoords2D_).data();
290 return this->property(vertex_texcoords2D_, _vh);
293 void set_texcoord2D(
VertexHandle _vh,
const TexCoord2D& _t) {
294 this->property(vertex_texcoords2D_, _vh) = _t;
300 const TexCoord3D* texcoords3D()
const {
301 return this->property(vertex_texcoords3D_).data();
305 return this->property(vertex_texcoords3D_, _vh);
308 void set_texcoord3D(
VertexHandle _vh,
const TexCoord3D& _t) {
309 this->property(vertex_texcoords3D_, _vh) = _t;
314 const TexCoord1D* htexcoords1D()
const {
315 return this->property(halfedge_texcoords1D_).data();
319 return this->property(halfedge_texcoords1D_, _heh);
323 this->property(halfedge_texcoords1D_, _heh) = _t;
329 const TexCoord2D* htexcoords2D()
const {
330 return this->property(halfedge_texcoords2D_).data();
334 return this->property(halfedge_texcoords2D_, _heh);
338 this->property(halfedge_texcoords2D_, _heh) = _t;
344 const TexCoord3D* htexcoords3D()
const {
345 return this->property(halfedge_texcoords3D_).data();
349 return this->property(halfedge_texcoords3D_, _heh);
353 this->property(halfedge_texcoords3D_, _heh) = _t;
358 const Color* edge_colors()
const 359 {
return this->property(edge_colors_).data(); }
362 {
return this->property(edge_colors_, _eh); }
364 void set_color(
EdgeHandle _eh,
const Color& _c)
365 { this->property(edge_colors_, _eh) = _c; }
371 {
return this->property(halfedge_normals_, _heh); }
374 { this->property(halfedge_normals_, _heh) = _n; }
379 const Color* halfedge_colors()
const 380 {
return this->property(halfedge_colors_).data(); }
383 {
return this->property(halfedge_colors_, _heh); }
386 { this->property(halfedge_colors_, _heh) = _c; }
391 {
return this->property(face_normals_, _fh); }
393 void set_normal(
FaceHandle _fh,
const Normal& _n)
394 { this->property(face_normals_, _fh) = _n; }
398 const TextureIndex& texture_index(
FaceHandle _fh)
const 399 {
return this->property(face_texture_index_, _fh); }
401 void set_texture_index(
FaceHandle _fh,
const TextureIndex& _t)
402 { this->property(face_texture_index_, _fh) = _t; }
407 {
return this->property(face_colors_, _fh); }
409 void set_color(
FaceHandle _fh,
const Color& _c)
410 { this->property(face_colors_, _fh) = _c; }
414 void request_vertex_normals()
416 if (!refcount_vnormals_++)
417 this->add_property( vertex_normals_,
"v:normals" );
420 void request_vertex_colors()
422 if (!refcount_vcolors_++)
423 this->add_property( vertex_colors_,
"v:colors" );
426 void request_vertex_texcoords1D()
428 if (!refcount_vtexcoords1D_++)
429 this->add_property( vertex_texcoords1D_,
"v:texcoords1D" );
432 void request_vertex_texcoords2D()
434 if (!refcount_vtexcoords2D_++)
435 this->add_property( vertex_texcoords2D_,
"v:texcoords2D" );
438 void request_vertex_texcoords3D()
440 if (!refcount_vtexcoords3D_++)
441 this->add_property( vertex_texcoords3D_,
"v:texcoords3D" );
444 void request_halfedge_texcoords1D()
446 if (!refcount_htexcoords1D_++)
447 this->add_property( halfedge_texcoords1D_,
"h:texcoords1D" );
450 void request_halfedge_texcoords2D()
452 if (!refcount_htexcoords2D_++)
453 this->add_property( halfedge_texcoords2D_,
"h:texcoords2D" );
456 void request_halfedge_texcoords3D()
458 if (!refcount_htexcoords3D_++)
459 this->add_property( halfedge_texcoords3D_,
"h:texcoords3D" );
462 void request_edge_colors()
464 if (!refcount_ecolors_++)
465 this->add_property( edge_colors_,
"e:colors" );
468 void request_halfedge_normals()
470 if (!refcount_henormals_++)
471 this->add_property( halfedge_normals_,
"h:normals" );
474 void request_halfedge_colors()
476 if (!refcount_hecolors_++)
477 this->add_property( halfedge_colors_,
"h:colors" );
480 void request_face_normals()
482 if (!refcount_fnormals_++)
483 this->add_property( face_normals_,
"f:normals" );
486 void request_face_colors()
488 if (!refcount_fcolors_++)
489 this->add_property( face_colors_,
"f:colors" );
492 void request_face_texture_index()
494 if (!refcount_ftextureIndex_++)
495 this->add_property( face_texture_index_,
"f:textureindex" );
500 void release_vertex_normals()
502 if ((refcount_vnormals_ > 0) && (! --refcount_vnormals_))
503 this->remove_property(vertex_normals_);
506 void release_vertex_colors()
508 if ((refcount_vcolors_ > 0) && (! --refcount_vcolors_))
509 this->remove_property(vertex_colors_);
512 void release_vertex_texcoords1D() {
513 if ((refcount_vtexcoords1D_ > 0) && (! --refcount_vtexcoords1D_))
514 this->remove_property(vertex_texcoords1D_);
517 void release_vertex_texcoords2D() {
518 if ((refcount_vtexcoords2D_ > 0) && (! --refcount_vtexcoords2D_))
519 this->remove_property(vertex_texcoords2D_);
522 void release_vertex_texcoords3D() {
523 if ((refcount_vtexcoords3D_ > 0) && (! --refcount_vtexcoords3D_))
524 this->remove_property(vertex_texcoords3D_);
527 void release_halfedge_texcoords1D() {
528 if ((refcount_htexcoords1D_ > 0) && (! --refcount_htexcoords1D_))
529 this->remove_property(halfedge_texcoords1D_);
532 void release_halfedge_texcoords2D() {
533 if ((refcount_htexcoords2D_ > 0) && (! --refcount_htexcoords2D_))
534 this->remove_property(halfedge_texcoords2D_);
537 void release_halfedge_texcoords3D() {
538 if ((refcount_htexcoords3D_ > 0) && (! --refcount_htexcoords3D_))
539 this->remove_property(halfedge_texcoords3D_);
542 void release_edge_colors()
544 if ((refcount_ecolors_ > 0) && (! --refcount_ecolors_))
545 this->remove_property(edge_colors_);
548 void release_halfedge_normals()
550 if ((refcount_henormals_ > 0) && (! --refcount_henormals_))
551 this->remove_property(halfedge_normals_);
554 void release_halfedge_colors()
556 if ((refcount_hecolors_ > 0) && (! --refcount_hecolors_))
557 this->remove_property(halfedge_colors_);
560 void release_face_normals()
562 if ((refcount_fnormals_ > 0) && (! --refcount_fnormals_))
563 this->remove_property(face_normals_);
566 void release_face_colors()
568 if ((refcount_fcolors_ > 0) && (! --refcount_fcolors_))
569 this->remove_property(face_colors_);
572 void release_face_texture_index()
574 if ((refcount_ftextureIndex_ > 0) && (! --refcount_ftextureIndex_))
575 this->remove_property(face_texture_index_);
580 bool has_vertex_normals()
const {
return vertex_normals_.
is_valid(); }
581 bool has_vertex_colors()
const {
return vertex_colors_.
is_valid(); }
582 bool has_vertex_texcoords1D()
const {
return vertex_texcoords1D_.
is_valid(); }
583 bool has_vertex_texcoords2D()
const {
return vertex_texcoords2D_.
is_valid(); }
584 bool has_vertex_texcoords3D()
const {
return vertex_texcoords3D_.
is_valid(); }
585 bool has_halfedge_texcoords1D()
const {
return halfedge_texcoords1D_.
is_valid();}
586 bool has_halfedge_texcoords2D()
const {
return halfedge_texcoords2D_.
is_valid();}
587 bool has_halfedge_texcoords3D()
const {
return halfedge_texcoords3D_.
is_valid();}
588 bool has_edge_colors()
const {
return edge_colors_.
is_valid(); }
589 bool has_halfedge_normals()
const {
return halfedge_normals_.
is_valid(); }
590 bool has_halfedge_colors()
const {
return halfedge_colors_.
is_valid(); }
591 bool has_face_normals()
const {
return face_normals_.
is_valid(); }
592 bool has_face_colors()
const {
return face_colors_.
is_valid(); }
593 bool has_face_texture_index()
const {
return face_texture_index_.
is_valid(); }
615 PointsPropertyHandle points_pph()
const 618 VertexNormalsPropertyHandle vertex_normals_pph()
const 619 {
return vertex_normals_; }
621 VertexColorsPropertyHandle vertex_colors_pph()
const 622 {
return vertex_colors_; }
624 VertexTexCoords1DPropertyHandle vertex_texcoords1D_pph()
const 625 {
return vertex_texcoords1D_; }
627 VertexTexCoords2DPropertyHandle vertex_texcoords2D_pph()
const 628 {
return vertex_texcoords2D_; }
630 VertexTexCoords3DPropertyHandle vertex_texcoords3D_pph()
const 631 {
return vertex_texcoords3D_; }
634 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_pph()
const 635 {
return halfedge_texcoords1D_; }
637 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_pph()
const 638 {
return halfedge_texcoords2D_; }
640 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_pph()
const 641 {
return halfedge_texcoords3D_; }
644 HalfedgeNormalsPropertyHandle halfedge_normals_pph()
const 645 {
return halfedge_normals_; }
649 HalfedgeColorsPropertyHandle halfedge_colors_pph()
const 650 {
return halfedge_colors_; }
653 EdgeColorsPropertyHandle edge_colors_pph()
const 654 {
return edge_colors_; }
657 FaceNormalsPropertyHandle face_normals_pph()
const 658 {
return face_normals_; }
660 FaceColorsPropertyHandle face_colors_pph()
const 661 {
return face_colors_; }
663 FaceTextureIndexPropertyHandle face_texture_index_pph()
const 664 {
return face_texture_index_; }
667 {
return this->property(data_vpph_, _vh); }
670 {
return this->property(data_vpph_, _vh); }
673 {
return this->property(data_fpph_, _fh); }
676 {
return this->property(data_fpph_, _fh); }
679 {
return this->property(data_epph_, _eh); }
682 {
return this->property(data_epph_, _eh); }
685 {
return this->property(data_hpph_, _heh); }
688 {
return this->property(data_hpph_, _heh); }
692 PointsPropertyHandle points_;
693 VertexNormalsPropertyHandle vertex_normals_;
694 VertexColorsPropertyHandle vertex_colors_;
695 VertexTexCoords1DPropertyHandle vertex_texcoords1D_;
696 VertexTexCoords2DPropertyHandle vertex_texcoords2D_;
697 VertexTexCoords3DPropertyHandle vertex_texcoords3D_;
699 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_;
700 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_;
701 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_;
702 HalfedgeNormalsPropertyHandle halfedge_normals_;
703 HalfedgeColorsPropertyHandle halfedge_colors_;
705 EdgeColorsPropertyHandle edge_colors_;
707 FaceNormalsPropertyHandle face_normals_;
708 FaceColorsPropertyHandle face_colors_;
709 FaceTextureIndexPropertyHandle face_texture_index_;
711 DataVPropHandle data_vpph_;
712 DataHPropHandle data_hpph_;
713 DataEPropHandle data_epph_;
714 DataFPropHandle data_fpph_;
716 unsigned int refcount_vnormals_;
717 unsigned int refcount_vcolors_;
718 unsigned int refcount_vtexcoords1D_;
719 unsigned int refcount_vtexcoords2D_;
720 unsigned int refcount_vtexcoords3D_;
721 unsigned int refcount_htexcoords1D_;
722 unsigned int refcount_htexcoords2D_;
723 unsigned int refcount_htexcoords3D_;
724 unsigned int refcount_henormals_;
725 unsigned int refcount_hecolors_;
726 unsigned int refcount_ecolors_;
727 unsigned int refcount_fnormals_;
728 unsigned int refcount_fcolors_;
729 unsigned int refcount_ftextureIndex_;
735 void initializeStandardProperties()
737 if(!this->get_property_handle(points_,
742 refcount_vnormals_ = this->get_property_handle(vertex_normals_,
743 "v:normals") ? 1 : 0 ;
744 refcount_vcolors_ = this->get_property_handle(vertex_colors_,
745 "v:colors") ? 1 : 0 ;
746 refcount_vtexcoords1D_ = this->get_property_handle(vertex_texcoords1D_,
747 "v:texcoords1D") ? 1 : 0 ;
748 refcount_vtexcoords2D_ = this->get_property_handle(vertex_texcoords2D_,
749 "v:texcoords2D") ? 1 : 0 ;
750 refcount_vtexcoords3D_ = this->get_property_handle(vertex_texcoords3D_,
751 "v:texcoords3D") ? 1 : 0 ;
752 refcount_htexcoords1D_ = this->get_property_handle(halfedge_texcoords1D_,
753 "h:texcoords1D") ? 1 : 0 ;
754 refcount_htexcoords2D_ = this->get_property_handle(halfedge_texcoords2D_,
755 "h:texcoords2D") ? 1 : 0 ;
756 refcount_htexcoords3D_ = this->get_property_handle(halfedge_texcoords3D_,
757 "h:texcoords3D") ? 1 : 0 ;
758 refcount_henormals_ = this->get_property_handle(halfedge_normals_,
759 "h:normals") ? 1 : 0 ;
760 refcount_hecolors_ = this->get_property_handle(halfedge_colors_,
761 "h:colors") ? 1 : 0 ;
762 refcount_ecolors_ = this->get_property_handle(edge_colors_,
763 "e:colors") ? 1 : 0 ;
764 refcount_fnormals_ = this->get_property_handle(face_normals_,
765 "f:normals") ? 1 : 0 ;
766 refcount_fcolors_ = this->get_property_handle(face_colors_,
767 "f:colors") ? 1 : 0 ;
768 refcount_ftextureIndex_ = this->get_property_handle(face_texture_index_,
769 "f:textureindex") ? 1 : 0 ;
776 #endif // OPENMESH_ATTRIBKERNEL_HH defined Handle for a halfedge entity.
Definition: Handles.hh:127
Add 2D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:87
Add status to mesh item (all items)
Definition: Attributes.hh:85
Handle for a vertex entity.
Definition: Handles.hh:120
Handle for a edge entity.
Definition: Handles.hh:134
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:83
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:82
Add texture index (faces)
Definition: Attributes.hh:89
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
The attribute kernel adds all standard properties to the kernel.
Definition: AttribKernelT.hh:72
Handle for a face entity.
Definition: Handles.hh:141
void assign(const _AttribKernel &_other, bool copyStandardProperties=false)
Assignment from another mesh of another type.
Definition: AttribKernelT.hh:211
Add 1D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:86
Add 3D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:88
bool is_valid() const
The handle is valid iff the index is not negative.
Definition: Handles.hh:72