49 #ifndef OPENMESH_ATTRIBKERNEL_HH 50 #define OPENMESH_ATTRIBKERNEL_HH 56 #include <OpenMesh/Core/Utils/GenProg.hh> 57 #include <OpenMesh/Core/Utils/vector_traits.hh> 76 template <
class MeshItems,
class Connectivity>
83 typedef MeshItems MeshItemsT;
84 typedef Connectivity ConnectivityT;
85 typedef typename Connectivity::Vertex Vertex;
86 typedef typename Connectivity::Halfedge Halfedge;
87 typedef typename Connectivity::Edge Edge;
88 typedef typename Connectivity::Face Face;
90 typedef typename MeshItems::Point Point;
96 typedef typename MeshItems::Scalar Scalar;
99 typedef typename MeshItems::VertexData VertexData;
100 typedef typename MeshItems::HalfedgeData HalfedgeData;
101 typedef typename MeshItems::EdgeData EdgeData;
102 typedef typename MeshItems::FaceData FaceData;
107 VAttribs = MeshItems::VAttribs,
108 HAttribs = MeshItems::HAttribs,
109 EAttribs = MeshItems::EAttribs,
110 FAttribs = MeshItems::FAttribs
123 : refcount_vnormals_(0),
124 refcount_vcolors_(0),
125 refcount_vtexcoords1D_(0),
126 refcount_vtexcoords2D_(0),
127 refcount_vtexcoords3D_(0),
128 refcount_htexcoords1D_(0),
129 refcount_htexcoords2D_(0),
130 refcount_htexcoords3D_(0),
131 refcount_henormals_(0),
132 refcount_hecolors_(0),
133 refcount_ecolors_(0),
134 refcount_fnormals_(0),
135 refcount_fcolors_(0),
136 refcount_ftextureIndex_(0)
138 this->add_property( points_,
"v:points" );
141 request_vertex_normals();
144 request_vertex_colors();
147 request_vertex_texcoords1D();
150 request_vertex_texcoords2D();
153 request_vertex_texcoords3D();
155 if (HAttribs & Attributes::TexCoord1D)
156 request_halfedge_texcoords1D();
158 if (HAttribs & Attributes::TexCoord2D)
159 request_halfedge_texcoords2D();
161 if (HAttribs & Attributes::TexCoord3D)
162 request_halfedge_texcoords3D();
164 if (HAttribs & Attributes::Color)
165 request_halfedge_colors();
168 Connectivity::request_vertex_status();
170 if (HAttribs & Attributes::Status)
171 Connectivity::request_halfedge_status();
173 if (HAttribs & Attributes::Normal)
174 request_halfedge_normals();
176 if (EAttribs & Attributes::Status)
177 Connectivity::request_edge_status();
179 if (EAttribs & Attributes::Color)
180 request_edge_colors();
182 if (FAttribs & Attributes::Normal)
183 request_face_normals();
185 if (FAttribs & Attributes::Color)
186 request_face_colors();
188 if (FAttribs & Attributes::Status)
189 Connectivity::request_face_status();
192 request_face_texture_index();
196 this->add_property(data_vpph_);
197 this->add_property(data_fpph_);
198 this->add_property(data_hpph_);
199 this->add_property(data_epph_);
215 template <
class _AttribKernel>
216 void assign(
const _AttribKernel& _other,
bool copyStandardProperties =
false)
219 if(copyStandardProperties)
220 this->copy_all_kernel_properties(_other);
222 this->assign_connectivity(_other);
223 for (
typename Connectivity::VertexIter v_it = Connectivity::vertices_begin();
224 v_it != Connectivity::vertices_end(); ++v_it)
226 set_point(*v_it, (Point)_other.point(*v_it));
230 if(copyStandardProperties)
231 initializeStandardProperties();
236 const Point* points()
const 237 {
return this->property(points_).data(); }
240 {
return this->property(points_, _vh); }
243 {
return this->property(points_, _vh); }
246 { this->property(points_, _vh) = _p; }
251 const Normal* vertex_normals()
const 252 {
return this->property(vertex_normals_).data(); }
255 {
return this->property(vertex_normals_, _vh); }
258 { this->property(vertex_normals_, _vh) = _n; }
263 const Color* vertex_colors()
const 264 {
return this->property(vertex_colors_).data(); }
267 {
return this->property(vertex_colors_, _vh); }
270 { this->property(vertex_colors_, _vh) = _c; }
275 const TexCoord1D* texcoords1D()
const {
276 return this->property(vertex_texcoords1D_).data();
280 return this->property(vertex_texcoords1D_, _vh);
283 void set_texcoord1D(
VertexHandle _vh,
const TexCoord1D& _t) {
284 this->property(vertex_texcoords1D_, _vh) = _t;
290 const TexCoord2D* texcoords2D()
const {
291 return this->property(vertex_texcoords2D_).data();
295 return this->property(vertex_texcoords2D_, _vh);
298 void set_texcoord2D(
VertexHandle _vh,
const TexCoord2D& _t) {
299 this->property(vertex_texcoords2D_, _vh) = _t;
305 const TexCoord3D* texcoords3D()
const {
306 return this->property(vertex_texcoords3D_).data();
310 return this->property(vertex_texcoords3D_, _vh);
313 void set_texcoord3D(
VertexHandle _vh,
const TexCoord3D& _t) {
314 this->property(vertex_texcoords3D_, _vh) = _t;
319 const TexCoord1D* htexcoords1D()
const {
320 return this->property(halfedge_texcoords1D_).data();
324 return this->property(halfedge_texcoords1D_, _heh);
328 this->property(halfedge_texcoords1D_, _heh) = _t;
334 const TexCoord2D* htexcoords2D()
const {
335 return this->property(halfedge_texcoords2D_).data();
339 return this->property(halfedge_texcoords2D_, _heh);
343 this->property(halfedge_texcoords2D_, _heh) = _t;
349 const TexCoord3D* htexcoords3D()
const {
350 return this->property(halfedge_texcoords3D_).data();
354 return this->property(halfedge_texcoords3D_, _heh);
358 this->property(halfedge_texcoords3D_, _heh) = _t;
363 const Color* edge_colors()
const 364 {
return this->property(edge_colors_).data(); }
367 {
return this->property(edge_colors_, _eh); }
369 void set_color(
EdgeHandle _eh,
const Color& _c)
370 { this->property(edge_colors_, _eh) = _c; }
376 {
return this->property(halfedge_normals_, _heh); }
379 { this->property(halfedge_normals_, _heh) = _n; }
384 const Color* halfedge_colors()
const 385 {
return this->property(halfedge_colors_).data(); }
388 {
return this->property(halfedge_colors_, _heh); }
391 { this->property(halfedge_colors_, _heh) = _c; }
396 {
return this->property(face_normals_, _fh); }
398 void set_normal(
FaceHandle _fh,
const Normal& _n)
399 { this->property(face_normals_, _fh) = _n; }
403 const TextureIndex& texture_index(
FaceHandle _fh)
const 404 {
return this->property(face_texture_index_, _fh); }
406 void set_texture_index(
FaceHandle _fh,
const TextureIndex& _t)
407 { this->property(face_texture_index_, _fh) = _t; }
412 {
return this->property(face_colors_, _fh); }
414 void set_color(
FaceHandle _fh,
const Color& _c)
415 { this->property(face_colors_, _fh) = _c; }
419 void request_vertex_normals()
421 if (!refcount_vnormals_++)
422 this->add_property( vertex_normals_,
"v:normals" );
425 void request_vertex_colors()
427 if (!refcount_vcolors_++)
428 this->add_property( vertex_colors_,
"v:colors" );
431 void request_vertex_texcoords1D()
433 if (!refcount_vtexcoords1D_++)
434 this->add_property( vertex_texcoords1D_,
"v:texcoords1D" );
437 void request_vertex_texcoords2D()
439 if (!refcount_vtexcoords2D_++)
440 this->add_property( vertex_texcoords2D_,
"v:texcoords2D" );
443 void request_vertex_texcoords3D()
445 if (!refcount_vtexcoords3D_++)
446 this->add_property( vertex_texcoords3D_,
"v:texcoords3D" );
449 void request_halfedge_texcoords1D()
451 if (!refcount_htexcoords1D_++)
452 this->add_property( halfedge_texcoords1D_,
"h:texcoords1D" );
455 void request_halfedge_texcoords2D()
457 if (!refcount_htexcoords2D_++)
458 this->add_property( halfedge_texcoords2D_,
"h:texcoords2D" );
461 void request_halfedge_texcoords3D()
463 if (!refcount_htexcoords3D_++)
464 this->add_property( halfedge_texcoords3D_,
"h:texcoords3D" );
467 void request_edge_colors()
469 if (!refcount_ecolors_++)
470 this->add_property( edge_colors_,
"e:colors" );
473 void request_halfedge_normals()
475 if (!refcount_henormals_++)
476 this->add_property( halfedge_normals_,
"h:normals" );
479 void request_halfedge_colors()
481 if (!refcount_hecolors_++)
482 this->add_property( halfedge_colors_,
"h:colors" );
485 void request_face_normals()
487 if (!refcount_fnormals_++)
488 this->add_property( face_normals_,
"f:normals" );
491 void request_face_colors()
493 if (!refcount_fcolors_++)
494 this->add_property( face_colors_,
"f:colors" );
497 void request_face_texture_index()
499 if (!refcount_ftextureIndex_++)
500 this->add_property( face_texture_index_,
"f:textureindex" );
505 void release_vertex_normals()
507 if ((refcount_vnormals_ > 0) && (! --refcount_vnormals_))
508 this->remove_property(vertex_normals_);
511 void release_vertex_colors()
513 if ((refcount_vcolors_ > 0) && (! --refcount_vcolors_))
514 this->remove_property(vertex_colors_);
517 void release_vertex_texcoords1D() {
518 if ((refcount_vtexcoords1D_ > 0) && (! --refcount_vtexcoords1D_))
519 this->remove_property(vertex_texcoords1D_);
522 void release_vertex_texcoords2D() {
523 if ((refcount_vtexcoords2D_ > 0) && (! --refcount_vtexcoords2D_))
524 this->remove_property(vertex_texcoords2D_);
527 void release_vertex_texcoords3D() {
528 if ((refcount_vtexcoords3D_ > 0) && (! --refcount_vtexcoords3D_))
529 this->remove_property(vertex_texcoords3D_);
532 void release_halfedge_texcoords1D() {
533 if ((refcount_htexcoords1D_ > 0) && (! --refcount_htexcoords1D_))
534 this->remove_property(halfedge_texcoords1D_);
537 void release_halfedge_texcoords2D() {
538 if ((refcount_htexcoords2D_ > 0) && (! --refcount_htexcoords2D_))
539 this->remove_property(halfedge_texcoords2D_);
542 void release_halfedge_texcoords3D() {
543 if ((refcount_htexcoords3D_ > 0) && (! --refcount_htexcoords3D_))
544 this->remove_property(halfedge_texcoords3D_);
547 void release_edge_colors()
549 if ((refcount_ecolors_ > 0) && (! --refcount_ecolors_))
550 this->remove_property(edge_colors_);
553 void release_halfedge_normals()
555 if ((refcount_henormals_ > 0) && (! --refcount_henormals_))
556 this->remove_property(halfedge_normals_);
559 void release_halfedge_colors()
561 if ((refcount_hecolors_ > 0) && (! --refcount_hecolors_))
562 this->remove_property(halfedge_colors_);
565 void release_face_normals()
567 if ((refcount_fnormals_ > 0) && (! --refcount_fnormals_))
568 this->remove_property(face_normals_);
571 void release_face_colors()
573 if ((refcount_fcolors_ > 0) && (! --refcount_fcolors_))
574 this->remove_property(face_colors_);
577 void release_face_texture_index()
579 if ((refcount_ftextureIndex_ > 0) && (! --refcount_ftextureIndex_))
580 this->remove_property(face_texture_index_);
585 bool has_vertex_normals()
const {
return vertex_normals_.
is_valid(); }
586 bool has_vertex_colors()
const {
return vertex_colors_.
is_valid(); }
587 bool has_vertex_texcoords1D()
const {
return vertex_texcoords1D_.
is_valid(); }
588 bool has_vertex_texcoords2D()
const {
return vertex_texcoords2D_.
is_valid(); }
589 bool has_vertex_texcoords3D()
const {
return vertex_texcoords3D_.
is_valid(); }
590 bool has_halfedge_texcoords1D()
const {
return halfedge_texcoords1D_.
is_valid();}
591 bool has_halfedge_texcoords2D()
const {
return halfedge_texcoords2D_.
is_valid();}
592 bool has_halfedge_texcoords3D()
const {
return halfedge_texcoords3D_.
is_valid();}
593 bool has_edge_colors()
const {
return edge_colors_.
is_valid(); }
594 bool has_halfedge_normals()
const {
return halfedge_normals_.
is_valid(); }
595 bool has_halfedge_colors()
const {
return halfedge_colors_.
is_valid(); }
596 bool has_face_normals()
const {
return face_normals_.
is_valid(); }
597 bool has_face_colors()
const {
return face_colors_.
is_valid(); }
598 bool has_face_texture_index()
const {
return face_texture_index_.
is_valid(); }
620 PointsPropertyHandle points_pph()
const 623 VertexNormalsPropertyHandle vertex_normals_pph()
const 624 {
return vertex_normals_; }
626 VertexColorsPropertyHandle vertex_colors_pph()
const 627 {
return vertex_colors_; }
629 VertexTexCoords1DPropertyHandle vertex_texcoords1D_pph()
const 630 {
return vertex_texcoords1D_; }
632 VertexTexCoords2DPropertyHandle vertex_texcoords2D_pph()
const 633 {
return vertex_texcoords2D_; }
635 VertexTexCoords3DPropertyHandle vertex_texcoords3D_pph()
const 636 {
return vertex_texcoords3D_; }
639 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_pph()
const 640 {
return halfedge_texcoords1D_; }
642 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_pph()
const 643 {
return halfedge_texcoords2D_; }
645 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_pph()
const 646 {
return halfedge_texcoords3D_; }
649 HalfedgeNormalsPropertyHandle halfedge_normals_pph()
const 650 {
return halfedge_normals_; }
654 HalfedgeColorsPropertyHandle halfedge_colors_pph()
const 655 {
return halfedge_colors_; }
658 EdgeColorsPropertyHandle edge_colors_pph()
const 659 {
return edge_colors_; }
662 FaceNormalsPropertyHandle face_normals_pph()
const 663 {
return face_normals_; }
665 FaceColorsPropertyHandle face_colors_pph()
const 666 {
return face_colors_; }
668 FaceTextureIndexPropertyHandle face_texture_index_pph()
const 669 {
return face_texture_index_; }
672 {
return this->property(data_vpph_, _vh); }
675 {
return this->property(data_vpph_, _vh); }
678 {
return this->property(data_fpph_, _fh); }
681 {
return this->property(data_fpph_, _fh); }
684 {
return this->property(data_epph_, _eh); }
687 {
return this->property(data_epph_, _eh); }
690 {
return this->property(data_hpph_, _heh); }
693 {
return this->property(data_hpph_, _heh); }
697 PointsPropertyHandle points_;
698 VertexNormalsPropertyHandle vertex_normals_;
699 VertexColorsPropertyHandle vertex_colors_;
700 VertexTexCoords1DPropertyHandle vertex_texcoords1D_;
701 VertexTexCoords2DPropertyHandle vertex_texcoords2D_;
702 VertexTexCoords3DPropertyHandle vertex_texcoords3D_;
704 HalfedgeTexCoords1DPropertyHandle halfedge_texcoords1D_;
705 HalfedgeTexCoords2DPropertyHandle halfedge_texcoords2D_;
706 HalfedgeTexCoords3DPropertyHandle halfedge_texcoords3D_;
707 HalfedgeNormalsPropertyHandle halfedge_normals_;
708 HalfedgeColorsPropertyHandle halfedge_colors_;
710 EdgeColorsPropertyHandle edge_colors_;
712 FaceNormalsPropertyHandle face_normals_;
713 FaceColorsPropertyHandle face_colors_;
714 FaceTextureIndexPropertyHandle face_texture_index_;
716 DataVPropHandle data_vpph_;
717 DataHPropHandle data_hpph_;
718 DataEPropHandle data_epph_;
719 DataFPropHandle data_fpph_;
721 unsigned int refcount_vnormals_;
722 unsigned int refcount_vcolors_;
723 unsigned int refcount_vtexcoords1D_;
724 unsigned int refcount_vtexcoords2D_;
725 unsigned int refcount_vtexcoords3D_;
726 unsigned int refcount_htexcoords1D_;
727 unsigned int refcount_htexcoords2D_;
728 unsigned int refcount_htexcoords3D_;
729 unsigned int refcount_henormals_;
730 unsigned int refcount_hecolors_;
731 unsigned int refcount_ecolors_;
732 unsigned int refcount_fnormals_;
733 unsigned int refcount_fcolors_;
734 unsigned int refcount_ftextureIndex_;
740 void initializeStandardProperties()
742 if(!this->get_property_handle(points_,
747 refcount_vnormals_ = this->get_property_handle(vertex_normals_,
748 "v:normals") ? 1 : 0 ;
749 refcount_vcolors_ = this->get_property_handle(vertex_colors_,
750 "v:colors") ? 1 : 0 ;
751 refcount_vtexcoords1D_ = this->get_property_handle(vertex_texcoords1D_,
752 "v:texcoords1D") ? 1 : 0 ;
753 refcount_vtexcoords2D_ = this->get_property_handle(vertex_texcoords2D_,
754 "v:texcoords2D") ? 1 : 0 ;
755 refcount_vtexcoords3D_ = this->get_property_handle(vertex_texcoords3D_,
756 "v:texcoords3D") ? 1 : 0 ;
757 refcount_htexcoords1D_ = this->get_property_handle(halfedge_texcoords1D_,
758 "h:texcoords1D") ? 1 : 0 ;
759 refcount_htexcoords2D_ = this->get_property_handle(halfedge_texcoords2D_,
760 "h:texcoords2D") ? 1 : 0 ;
761 refcount_htexcoords3D_ = this->get_property_handle(halfedge_texcoords3D_,
762 "h:texcoords3D") ? 1 : 0 ;
763 refcount_henormals_ = this->get_property_handle(halfedge_normals_,
764 "h:normals") ? 1 : 0 ;
765 refcount_hecolors_ = this->get_property_handle(halfedge_colors_,
766 "h:colors") ? 1 : 0 ;
767 refcount_ecolors_ = this->get_property_handle(edge_colors_,
768 "e:colors") ? 1 : 0 ;
769 refcount_fnormals_ = this->get_property_handle(face_normals_,
770 "f:normals") ? 1 : 0 ;
771 refcount_fcolors_ = this->get_property_handle(face_colors_,
772 "f:colors") ? 1 : 0 ;
773 refcount_ftextureIndex_ = this->get_property_handle(face_texture_index_,
774 "f:textureindex") ? 1 : 0 ;
781 #endif // OPENMESH_ATTRIBKERNEL_HH defined Add texture index (faces)
Definition: Attributes.hh:94
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
Add status to mesh item (all items)
Definition: Attributes.hh:90
This file provides some macros containing attribute usage.
Handle for a halfedge entity.
Definition: Handles.hh:132
Add 3D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:93
Handle for a face entity.
Definition: Handles.hh:146
Add 1D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:91
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
Handle for a vertex entity.
Definition: Handles.hh:125
The attribute kernel adds all standard properties to the kernel.
Definition: AttribKernelT.hh:77
bool is_valid() const
The handle is valid iff the index is not negative.
Definition: Handles.hh:77
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:88
Handle for a edge entity.
Definition: Handles.hh:139
Add 2D texture coordinates (vertices, halfedges)
Definition: Attributes.hh:92
void assign(const _AttribKernel &_other, bool copyStandardProperties=false)
Assignment from another mesh of another type.
Definition: AttribKernelT.hh:216