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;
86 typedef typename MeshItems::Normal Normal;
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();
166 if (HAttribs & Attributes::TexCoord1D)
167 request_halfedge_texcoords1D();
169 if (HAttribs & Attributes::TexCoord2D)
170 request_halfedge_texcoords2D();
172 if (HAttribs & Attributes::TexCoord3D)
173 request_halfedge_texcoords3D();
175 if (HAttribs & Attributes::Color)
176 request_halfedge_colors();
179 Connectivity::request_vertex_status();
181 if (HAttribs & Attributes::Status)
182 Connectivity::request_halfedge_status();
184 if (HAttribs & Attributes::Normal)
185 request_halfedge_normals();
187 if (EAttribs & Attributes::Status)
188 Connectivity::request_edge_status();
190 if (EAttribs & Attributes::Color)
191 request_edge_colors();
193 if (FAttribs & Attributes::Normal)
194 request_face_normals();
196 if (FAttribs & Attributes::Color)
197 request_face_colors();
199 if (FAttribs & Attributes::Status)
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)
247 const Point* points()
const 248 {
return this->property(points_).data(); }
251 {
return this->property(points_, _vh); }
254 {
return this->property(points_, _vh); }
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(); }
269 {
return this->property(vertex_normals_, _vh); }
272 { this->property(vertex_normals_, _vh) = _n; }
277 const Color* vertex_colors()
const 278 {
return this->property(vertex_colors_).data(); }
281 {
return this->property(vertex_colors_, _vh); }
284 { this->property(vertex_colors_, _vh) = _c; }
289 const TexCoord1D* texcoords1D()
const {
290 return this->property(vertex_texcoords1D_).data();
294 return this->property(vertex_texcoords1D_, _vh);
297 void set_texcoord1D(
VertexHandle _vh,
const TexCoord1D& _t) {
298 this->property(vertex_texcoords1D_, _vh) = _t;
304 const TexCoord2D* texcoords2D()
const {
305 return this->property(vertex_texcoords2D_).data();
309 return this->property(vertex_texcoords2D_, _vh);
312 void set_texcoord2D(
VertexHandle _vh,
const TexCoord2D& _t) {
313 this->property(vertex_texcoords2D_, _vh) = _t;
319 const TexCoord3D* texcoords3D()
const {
320 return this->property(vertex_texcoords3D_).data();
324 return this->property(vertex_texcoords3D_, _vh);
327 void set_texcoord3D(
VertexHandle _vh,
const TexCoord3D& _t) {
328 this->property(vertex_texcoords3D_, _vh) = _t;
333 const TexCoord1D* htexcoords1D()
const {
334 return this->property(halfedge_texcoords1D_).data();
338 return this->property(halfedge_texcoords1D_, _heh);
342 this->property(halfedge_texcoords1D_, _heh) = _t;
348 const TexCoord2D* htexcoords2D()
const {
349 return this->property(halfedge_texcoords2D_).data();
353 return this->property(halfedge_texcoords2D_, _heh);
357 this->property(halfedge_texcoords2D_, _heh) = _t;
363 const TexCoord3D* htexcoords3D()
const {
364 return this->property(halfedge_texcoords3D_).data();
368 return this->property(halfedge_texcoords3D_, _heh);
372 this->property(halfedge_texcoords3D_, _heh) = _t;
377 const Color* edge_colors()
const 378 {
return this->property(edge_colors_).data(); }
381 {
return this->property(edge_colors_, _eh); }
383 void set_color(
EdgeHandle _eh,
const Color& _c)
384 { this->property(edge_colors_, _eh) = _c; }
390 {
return this->property(halfedge_normals_, _heh); }
393 { this->property(halfedge_normals_, _heh) = _n; }
398 const Color* halfedge_colors()
const 399 {
return this->property(halfedge_colors_).data(); }
402 {
return this->property(halfedge_colors_, _heh); }
405 { this->property(halfedge_colors_, _heh) = _c; }
410 {
return this->property(face_normals_, _fh); }
412 void set_normal(
FaceHandle _fh,
const Normal& _n)
413 { this->property(face_normals_, _fh) = _n; }
417 const TextureIndex& texture_index(
FaceHandle _fh)
const 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; }
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_; }
668 {
return this->property(data_vpph_, _vh); }
671 {
return this->property(data_vpph_, _vh); }
674 {
return this->property(data_fpph_, _fh); }
677 {
return this->property(data_fpph_, _fh); }
680 {
return this->property(data_epph_, _eh); }
683 {
return this->property(data_epph_, _eh); }
686 {
return this->property(data_hpph_, _heh); }
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_;
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 ;
777 #endif // OPENMESH_ATTRIBKERNEL_HH defined Handle for a edge entity.
Handle for a face entity.
Add 3D texture coordinates (vertices, halfedges)
Handle for a halfedge entity.
Add texture index (faces)
Add 2D texture coordinates (vertices, halfedges)
Handle for a vertex entity.
Add status to mesh item (all items)
bool is_valid() const
The handle is valid iff the index is not negative.
Add normals to mesh item (vertices/faces)
Add colors to mesh item (vertices/faces/edges)
void assign(const _AttribKernel &_other, bool copyStandardProperties=false)
Add 1D texture coordinates (vertices, halfedges)
void initializeStandardProperties()
initializeStandardProperties Initializes the standard properties and sets refcount to 1 if found...