49 #ifndef OPENMESH_KERNEL_OSG_ATTRIBKERNEL_HH
50 #define OPENMESH_KENREL_OSG_ATTRIBKERNEL_HH
55 #include <OpenMesh/Core/Utils/GenProg.hh>
58 #include <OpenMesh/Tools/Kernel_OSG/PropertyT.hh>
59 #include <OpenMesh/Tools/Kernel_OSG/PropertyKernel.hh>
61 #include <osg/Geometry>
67 namespace Kernel_OSG {
74 template <
class MeshItems>
80 typedef typename MeshItems::Face::IsTriangle IsTriMesh;
91 typedef typename MeshItems::Vertex Vertex;
92 typedef typename MeshItems::Halfedge Halfedge;
93 typedef typename MeshItems::Edge Edge;
94 typedef typename MeshItems::Face Face;
96 typedef typename MeshItems::Point Point;
99 typedef typename MeshItems::TexCoord TexCoord;
101 typedef typename MeshItems::Scalar Scalar;
107 VAttribs = MeshItems::VAttribs,
108 HAttribs = MeshItems::HAttribs,
109 EAttribs = MeshItems::EAttribs,
110 FAttribs = MeshItems::FAttribs,
113 typedef GenProg::Bool2Type<(bool)(HAttribs & Attributes::PrevHalfedge)>
118 typedef typename _t2vp< Point >::prop GeoPositions;
119 typedef typename _t2vn< Normal >::prop GeoNormals;
120 typedef typename _t2vc< Color >::prop GeoColors;
121 typedef typename _t2vtc< TexCoord >::prop GeoTexCoords;
131 refcount_vnormals_(0),
132 refcount_vcolors_(0),
133 refcount_vtexcoords_(0),
134 refcount_vstatus_(0),
135 refcount_estatus_(0),
136 refcount_ecolors_(0),
137 refcount_hstatus_(0),
138 refcount_fnormals_(0),
139 refcount_fcolors_(0),
143 points_ = add_vpositions( Point(),
"v:points" );
145 face_types_ = add_fptypes();
146 face_lengths_ = add_fplengths();
147 face_indices_ = add_findices( face_types_, face_lengths_);
150 request_vertex_normals();
153 request_vertex_colors();
155 if (VAttribs & Attributes::TexCoord)
156 request_vertex_texcoords();
159 request_vertex_status();
161 if (EAttribs & Attributes::Status)
162 request_edge_status();
164 if (EAttribs & Attributes::Color)
165 request_edge_colors();
167 if (FAttribs & Attributes::Normal)
168 request_face_normals();
170 if (FAttribs & Attributes::Color)
171 request_face_colors();
173 if (FAttribs & Attributes::Status)
174 request_face_status();
208 BaseKernel::operator=(_rhs);
211 points_ = _rhs.points_;
212 vertex_normals_ = _rhs.vertex_normals_;
213 vertex_colors_ = _rhs.vertex_colors_;
214 vertex_texcoords_ = _rhs.vertex_texcoords_;
215 vertex_status_ = _rhs.vertex_status_;
216 halfedge_status_ = _rhs.halfedge_status_;
217 edge_status_ = _rhs.edge_status_;
218 edge_colors_ = _rhs.edge_colors_;
219 face_normals_ = _rhs.face_normals_;
220 face_colors_ = _rhs.face_colors_;
221 face_status_ = _rhs.face_status_;
224 refcount_vnormals_ = _rhs.refcount_vnormals_;
225 refcount_vcolors_ = _rhs.refcount_vcolors_;
226 refcount_vtexcoords_ = _rhs.refcount_vtexcoords_;
227 refcount_vstatus_ = _rhs.refcount_vstatus_;
228 refcount_hstatus_ = _rhs.refcount_hstatus_;
229 refcount_estatus_ = _rhs.refcount_estatus_;
230 refcount_ecolors_ = _rhs.refcount_ecolors_;
231 refcount_fnormals_ = _rhs.refcount_fnormals_;
232 refcount_fcolors_ = _rhs.refcount_fcolors_;
233 refcount_fstatus_ = _rhs.refcount_fstatus_;
242 typename GeoPositions::property_ptr_t osg_vpositions()
243 {
return vpositions(points_).osg_ptr(); }
245 typename GeoNormals::property_ptr_t osg_vnormals()
246 {
return vnormals(vertex_normals_).osg_ptr(); }
248 typename GeoColors::property_ptr_t osg_vcolors()
249 {
return vcolors(vertex_colors_).osg_ptr(); }
251 typename GeoTexCoords::property_ptr_t osg_vtexcoords()
252 {
return vtexcoords(vertex_texcoords_).osg_ptr(); }
256 typename GeoColors::property_ptr_t osg_ecolors()
257 {
return ecolors(edge_colors_).osg_ptr(); }
261 GeoPTypes::property_ptr_t osg_ptypes()
262 {
return fptypes( face_types_ ).osg_ptr(); }
264 GeoPLengths::property_ptr_t osg_plengths()
265 {
return fplengths( face_lengths_ ).osg_ptr(); }
267 typename GeoIndices::property_ptr_t osg_indices()
268 {
return findices( face_indices_ ).osg_ptr(); }
275 void set_face_types(
FaceHandle _fh, GeoPTypes::value_type _t)
276 { fptypes( face_types_, _fh ) = _t; }
278 void set_face_lengths(
FaceHandle _fh, GeoPLengths::value_type _l)
279 { fplengths( face_lengths_, _fh ) = _l; }
282 typename GeoIndices::value_type _i)
283 { findices( face_indices_, _fh ) = _i; }
289 const Point* points()
const
290 {
return vpositions( points_ ).data(); }
293 {
return vpositions( points_, _vh); }
296 { vpositions( points_, _vh ) = _p; }
301 const Normal* vertex_normals()
const {
302 return vnormals(vertex_normals_).data();
306 return vnormals(vertex_normals_, _vh);
310 vnormals(vertex_normals_, _vh) = _n;
316 const Color* vertex_colors()
const {
317 return vcolors(vertex_colors_).data();
321 return vcolors(vertex_colors_, _vh);
325 vcolors(vertex_colors_, _vh) = _c;
331 const TexCoord* texcoords()
const {
332 return vtexcoords(vertex_texcoords_).data();
336 return vtexcoords(vertex_texcoords_, _vh);
339 void set_texcoord(
VertexHandle _vh,
const TexCoord& _t) {
340 vtexcoords(vertex_texcoords_, _vh) = _t;
347 return property(vertex_status_, _vh);
351 return property(vertex_status_, _vh);
358 return property(halfedge_status_, _eh);
362 return property(halfedge_status_, _eh);
368 const StatusInfo& status(
EdgeHandle _eh)
const {
378 const Color* edge_colors()
const {
379 return ecolors(edge_colors_).data();
383 return ecolors(edge_colors_, _eh);
386 void set_color(
EdgeHandle _eh,
const Color& _c) {
387 ecolors(edge_colors_, _eh) = _c;
393 const StatusInfo& status(
FaceHandle _fh)
const {
405 return property(face_normals_, _fh);
408 void set_normal(
FaceHandle _fh,
const Normal& _n) {
419 void set_color(
FaceHandle _fh,
const Color& _c) {
427 void request_vertex_normals() {
428 if (!refcount_vnormals_++)
429 vertex_normals_ = add_vnormals( Normal(),
"v:normals" );
432 void request_vertex_colors() {
433 if (!refcount_vcolors_++)
434 vertex_colors_ = add_vcolors( Color(),
"v:colors" );
437 void request_vertex_texcoords() {
438 if (!refcount_vtexcoords_++)
439 vertex_texcoords_ = add_vtexcoords( TexCoord(),
"v:texcoords" );
442 void request_vertex_status() {
443 if (!refcount_vstatus_++)
447 void request_halfedge_status() {
448 if (!refcount_hstatus_++)
452 void request_edge_status() {
453 if (!refcount_estatus_++)
457 void request_edge_colors() {
458 if (!refcount_ecolors_++)
459 edge_colors_ = add_ecolors( Color(),
"e:colors" );
462 void request_face_normals() {
463 if (!refcount_fnormals_++)
467 void request_face_colors() {
468 if (!refcount_fcolors_++)
472 void request_face_status() {
473 if (!refcount_fstatus_++)
481 void release_vertex_normals() {
482 if ((refcount_vnormals_ > 0) && (! --refcount_vnormals_))
486 void release_vertex_colors() {
487 if ((refcount_vcolors_ > 0) && (! --refcount_vcolors_))
491 void release_vertex_texcoords() {
492 if ((refcount_vtexcoords_ > 0) && (! --refcount_vtexcoords_))
496 void release_vertex_status() {
497 if ((refcount_vstatus_ > 0) && (! --refcount_vstatus_))
501 void release_halfedge_status() {
502 if ((refcount_hstatus_ > 0) && (! --refcount_hstatus_))
506 void release_edge_status() {
507 if ((refcount_estatus_ > 0) && (! --refcount_estatus_))
511 void release_edge_colors() {
512 if ((refcount_ecolors_ > 0) && (! --refcount_ecolors_))
516 void release_face_normals() {
517 if ((refcount_fnormals_ > 0) && (! --refcount_fnormals_))
521 void release_face_colors() {
522 if ((refcount_fcolors_ > 0) && (! --refcount_fcolors_))
526 void release_face_status() {
527 if ((refcount_fstatus_ > 0) && (! --refcount_fstatus_))
535 GenProg::Bool2Type<(bool)(VAttribs & Attributes::Normal)>
539 GenProg::Bool2Type<(bool)(VAttribs & Attributes::Color)>
543 GenProg::Bool2Type<(bool)(VAttribs & Attributes::TexCoord)>
547 GenProg::Bool2Type<(bool)(VAttribs & Attributes::Status)>
552 GenProg::Bool2Type<(bool)(HAttribs & Attributes::PrevHalfedge)>
556 GenProg::Bool2Type<(bool)(HAttribs & Attributes::Status)>
561 GenProg::Bool2Type<(bool)(EAttribs & Attributes::Status)>
565 GenProg::Bool2Type<(bool)(EAttribs & Attributes::Color)>
570 GenProg::Bool2Type<(bool)(FAttribs & Attributes::Normal)>
574 GenProg::Bool2Type<(bool)(FAttribs & Attributes::Color)>
578 GenProg::Bool2Type<(bool)(FAttribs & Attributes::Status)>
584 bool has_vertex_normals()
const {
return vertex_normals_.
is_valid(); }
585 bool has_vertex_colors()
const {
return vertex_colors_.
is_valid(); }
586 bool has_vertex_texcoords()
const {
return vertex_texcoords_.
is_valid(); }
587 bool has_vertex_status()
const {
return vertex_status_.
is_valid(); }
588 bool has_edge_status()
const {
return edge_status_.
is_valid(); }
589 bool has_halfedge_status()
const {
return halfedge_status_.
is_valid(); }
590 bool has_edge_colors()
const {
return edge_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_status()
const {
return face_status_.
is_valid(); }
595 static bool has_prev_halfedge() {
602 osg::GeometryPtr createGeometryPtr()
605 GeometryPtr geo=Geometry::create();
606 return bind(geo) ? geo : NullFC;
610 bool bind( osg::GeometryPtr& _geo )
615 Geometry::TypesFieldMask |
616 Geometry::LengthsFieldMask |
617 Geometry::IndicesFieldMask |
618 Geometry::PositionsFieldMask;
620 if ( has_vertex_colors() )
621 Mask |= Geometry::ColorsFieldMask;
622 if ( has_vertex_normals() )
623 Mask |= Geometry::NormalsFieldMask;
624 if ( has_vertex_texcoords() )
625 Mask |= Geometry::TexCoordsFieldMask;
632 beginEditCP( _geo, Mask );
634 addRefCP( osg_ptypes() );
635 _geo->setTypes ( osg_ptypes() );
636 addRefCP( osg_plengths() );
637 _geo->setLengths ( osg_plengths() );
638 addRefCP( osg_indices() );
639 _geo->setIndices ( osg_indices() );
640 addRefCP( osg_vpositions() );
641 _geo->setPositions( osg_vpositions() );
643 if ( has_vertex_colors() )
645 addRefCP( osg_vcolors() );
646 _geo->setColors ( osg_vcolors() );
648 if ( has_vertex_normals() )
650 addRefCP( osg_vnormals() );
651 _geo->setNormals ( osg_vnormals() );
653 if ( has_vertex_texcoords() )
655 addRefCP( osg_vtexcoords() );
656 _geo->setTexCoords( osg_vtexcoords() );
659 endEditCP (_geo, Mask);
672 FPTypesHandle face_types_;
673 FPLengthsHandle face_lengths_;
674 FIndicesHandle face_indices_;
684 unsigned int refcount_vnormals_;
685 unsigned int refcount_vcolors_;
686 unsigned int refcount_vtexcoords_;
687 unsigned int refcount_vstatus_;
688 unsigned int refcount_estatus_;
689 unsigned int refcount_ecolors_;
690 unsigned int refcount_hstatus_;
691 unsigned int refcount_fnormals_;
692 unsigned int refcount_fcolors_;
693 unsigned int refcount_fstatus_;
702 #endif // OPENMESH_KERNEL_OSG_ATTRIBKERNEL_HH defined
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:88
This file provides some macros containing attribute usage.
Add status to mesh item (all items)
Definition: Attributes.hh:90
Add storage for previous halfedge (halfedges). The bit is set by default in the DefaultTraits.
Definition: Attributes.hh:89
Add status information to a base class.
Definition: Status.hh:99
Handle for a vertex entity.
Definition: Handles.hh:123
void remove_property(VPropHandleT< T > &_ph)
Remove a property.
Definition: BaseKernel.hh:188
bool is_valid() const
The handle is valid iff the index is not equal to -1.
Definition: Handles.hh:77
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)
Bind a OpenSG geometry to a mesh.
Definition: bindT.hh:106
Handle for a edge entity.
Definition: Handles.hh:137
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
This class adds the standard properties to the mesh type.
Definition: AttribKernelT.hh:75
Handle representing a face property.
Definition: Property.hh:529
Helper class, extending functionaliy of OpenMesh::BaseKernel to OpenSG specific property adaptors...
Definition: PropertyKernel.hh:73
void add_property(VPropHandleT< T > &_ph, const std::string &_name="<vprop>")
Adds a property.
Definition: BaseKernel.hh:138
Handle for a halfedge entity.
Definition: Handles.hh:130
PropertyT< T > & property(VPropHandleT< T > _ph)
Access a property.
Definition: BaseKernel.hh:294
Handle for a face entity.
Definition: Handles.hh:144