42 #ifndef OPENMESH_KERNEL_OSG_ATTRIBKERNEL_HH
43 #define OPENMESH_KENREL_OSG_ATTRIBKERNEL_HH
48 #include <OpenMesh/Core/Utils/GenProg.hh>
51 #include <OpenMesh/Tools/Kernel_OSG/PropertyT.hh>
52 #include <OpenMesh/Tools/Kernel_OSG/PropertyKernel.hh>
54 #include <osg/Geometry>
60 namespace Kernel_OSG {
67 template <
class MeshItems>
73 typedef typename MeshItems::Face::IsTriangle IsTriMesh;
84 typedef typename MeshItems::Vertex Vertex;
85 typedef typename MeshItems::Halfedge Halfedge;
86 typedef typename MeshItems::Edge Edge;
87 typedef typename MeshItems::Face Face;
89 typedef typename MeshItems::Point Point;
92 typedef typename MeshItems::TexCoord TexCoord;
94 typedef typename MeshItems::Scalar Scalar;
100 VAttribs = MeshItems::VAttribs,
101 HAttribs = MeshItems::HAttribs,
102 EAttribs = MeshItems::EAttribs,
103 FAttribs = MeshItems::FAttribs,
106 typedef GenProg::Bool2Type<(bool)(HAttribs & Attributes::PrevHalfedge)>
111 typedef typename _t2vp< Point >::prop GeoPositions;
112 typedef typename _t2vn< Normal >::prop GeoNormals;
113 typedef typename _t2vc< Color >::prop GeoColors;
114 typedef typename _t2vtc< TexCoord >::prop GeoTexCoords;
124 refcount_vnormals_(0),
125 refcount_vcolors_(0),
126 refcount_vtexcoords_(0),
127 refcount_vstatus_(0),
128 refcount_estatus_(0),
129 refcount_ecolors_(0),
130 refcount_hstatus_(0),
131 refcount_fnormals_(0),
132 refcount_fcolors_(0),
136 points_ = add_vpositions( Point(),
"v:points" );
138 face_types_ = add_fptypes();
139 face_lengths_ = add_fplengths();
140 face_indices_ = add_findices( face_types_, face_lengths_);
143 request_vertex_normals();
146 request_vertex_colors();
148 if (VAttribs & Attributes::TexCoord)
149 request_vertex_texcoords();
152 request_vertex_status();
154 if (EAttribs & Attributes::Status)
155 request_edge_status();
157 if (EAttribs & Attributes::Color)
158 request_edge_colors();
160 if (FAttribs & Attributes::Normal)
161 request_face_normals();
163 if (FAttribs & Attributes::Color)
164 request_face_colors();
166 if (FAttribs & Attributes::Status)
167 request_face_status();
201 BaseKernel::operator=(_rhs);
204 points_ = _rhs.points_;
205 vertex_normals_ = _rhs.vertex_normals_;
206 vertex_colors_ = _rhs.vertex_colors_;
207 vertex_texcoords_ = _rhs.vertex_texcoords_;
208 vertex_status_ = _rhs.vertex_status_;
209 halfedge_status_ = _rhs.halfedge_status_;
210 edge_status_ = _rhs.edge_status_;
211 edge_colors_ = _rhs.edge_colors_;
212 face_normals_ = _rhs.face_normals_;
213 face_colors_ = _rhs.face_colors_;
214 face_status_ = _rhs.face_status_;
217 refcount_vnormals_ = _rhs.refcount_vnormals_;
218 refcount_vcolors_ = _rhs.refcount_vcolors_;
219 refcount_vtexcoords_ = _rhs.refcount_vtexcoords_;
220 refcount_vstatus_ = _rhs.refcount_vstatus_;
221 refcount_hstatus_ = _rhs.refcount_hstatus_;
222 refcount_estatus_ = _rhs.refcount_estatus_;
223 refcount_ecolors_ = _rhs.refcount_ecolors_;
224 refcount_fnormals_ = _rhs.refcount_fnormals_;
225 refcount_fcolors_ = _rhs.refcount_fcolors_;
226 refcount_fstatus_ = _rhs.refcount_fstatus_;
235 typename GeoPositions::property_ptr_t osg_vpositions()
236 {
return vpositions(points_).osg_ptr(); }
238 typename GeoNormals::property_ptr_t osg_vnormals()
239 {
return vnormals(vertex_normals_).osg_ptr(); }
241 typename GeoColors::property_ptr_t osg_vcolors()
242 {
return vcolors(vertex_colors_).osg_ptr(); }
244 typename GeoTexCoords::property_ptr_t osg_vtexcoords()
245 {
return vtexcoords(vertex_texcoords_).osg_ptr(); }
249 typename GeoColors::property_ptr_t osg_ecolors()
250 {
return ecolors(edge_colors_).osg_ptr(); }
254 GeoPTypes::property_ptr_t osg_ptypes()
255 {
return fptypes( face_types_ ).osg_ptr(); }
257 GeoPLengths::property_ptr_t osg_plengths()
258 {
return fplengths( face_lengths_ ).osg_ptr(); }
260 typename GeoIndices::property_ptr_t osg_indices()
261 {
return findices( face_indices_ ).osg_ptr(); }
268 void set_face_types(
FaceHandle _fh, GeoPTypes::value_type _t)
269 { fptypes( face_types_, _fh ) = _t; }
271 void set_face_lengths(
FaceHandle _fh, GeoPLengths::value_type _l)
272 { fplengths( face_lengths_, _fh ) = _l; }
275 typename GeoIndices::value_type _i)
276 { findices( face_indices_, _fh ) = _i; }
282 const Point* points()
const
283 {
return vpositions( points_ ).data(); }
286 {
return vpositions( points_, _vh); }
289 { vpositions( points_, _vh ) = _p; }
294 const Normal* vertex_normals()
const {
295 return vnormals(vertex_normals_).data();
299 return vnormals(vertex_normals_, _vh);
303 vnormals(vertex_normals_, _vh) = _n;
309 const Color* vertex_colors()
const {
310 return vcolors(vertex_colors_).data();
314 return vcolors(vertex_colors_, _vh);
318 vcolors(vertex_colors_, _vh) = _c;
324 const TexCoord* texcoords()
const {
325 return vtexcoords(vertex_texcoords_).data();
329 return vtexcoords(vertex_texcoords_, _vh);
332 void set_texcoord(
VertexHandle _vh,
const TexCoord& _t) {
333 vtexcoords(vertex_texcoords_, _vh) = _t;
340 return property(vertex_status_, _vh);
344 return property(vertex_status_, _vh);
351 return property(halfedge_status_, _eh);
355 return property(halfedge_status_, _eh);
371 const Color* edge_colors()
const {
372 return ecolors(edge_colors_).data();
376 return ecolors(edge_colors_, _eh);
379 void set_color(
EdgeHandle _eh,
const Color& _c) {
380 ecolors(edge_colors_, _eh) = _c;
398 return property(face_normals_, _fh);
401 void set_normal(
FaceHandle _fh,
const Normal& _n) {
412 void set_color(
FaceHandle _fh,
const Color& _c) {
420 void request_vertex_normals() {
421 if (!refcount_vnormals_++)
422 vertex_normals_ = add_vnormals( Normal(),
"v:normals" );
425 void request_vertex_colors() {
426 if (!refcount_vcolors_++)
427 vertex_colors_ = add_vcolors( Color(),
"v:colors" );
430 void request_vertex_texcoords() {
431 if (!refcount_vtexcoords_++)
432 vertex_texcoords_ = add_vtexcoords( TexCoord(),
"v:texcoords" );
435 void request_vertex_status() {
436 if (!refcount_vstatus_++)
440 void request_halfedge_status() {
441 if (!refcount_hstatus_++)
445 void request_edge_status() {
446 if (!refcount_estatus_++)
450 void request_edge_colors() {
451 if (!refcount_ecolors_++)
452 edge_colors_ = add_ecolors( Color(),
"e:colors" );
455 void request_face_normals() {
456 if (!refcount_fnormals_++)
460 void request_face_colors() {
461 if (!refcount_fcolors_++)
465 void request_face_status() {
466 if (!refcount_fstatus_++)
474 void release_vertex_normals() {
475 if ((refcount_vnormals_ > 0) && (! --refcount_vnormals_))
479 void release_vertex_colors() {
480 if ((refcount_vcolors_ > 0) && (! --refcount_vcolors_))
484 void release_vertex_texcoords() {
485 if ((refcount_vtexcoords_ > 0) && (! --refcount_vtexcoords_))
489 void release_vertex_status() {
490 if ((refcount_vstatus_ > 0) && (! --refcount_vstatus_))
494 void release_halfedge_status() {
495 if ((refcount_hstatus_ > 0) && (! --refcount_hstatus_))
499 void release_edge_status() {
500 if ((refcount_estatus_ > 0) && (! --refcount_estatus_))
504 void release_edge_colors() {
505 if ((refcount_ecolors_ > 0) && (! --refcount_ecolors_))
509 void release_face_normals() {
510 if ((refcount_fnormals_ > 0) && (! --refcount_fnormals_))
514 void release_face_colors() {
515 if ((refcount_fcolors_ > 0) && (! --refcount_fcolors_))
519 void release_face_status() {
520 if ((refcount_fstatus_ > 0) && (! --refcount_fstatus_))
528 GenProg::Bool2Type<(bool)(VAttribs & Attributes::Normal)>
532 GenProg::Bool2Type<(bool)(VAttribs & Attributes::Color)>
536 GenProg::Bool2Type<(bool)(VAttribs & Attributes::TexCoord)>
540 GenProg::Bool2Type<(bool)(VAttribs & Attributes::Status)>
545 GenProg::Bool2Type<(bool)(HAttribs & Attributes::PrevHalfedge)>
549 GenProg::Bool2Type<(bool)(HAttribs & Attributes::Status)>
554 GenProg::Bool2Type<(bool)(EAttribs & Attributes::Status)>
558 GenProg::Bool2Type<(bool)(EAttribs & Attributes::Color)>
563 GenProg::Bool2Type<(bool)(FAttribs & Attributes::Normal)>
567 GenProg::Bool2Type<(bool)(FAttribs & Attributes::Color)>
571 GenProg::Bool2Type<(bool)(FAttribs & Attributes::Status)>
577 bool has_vertex_normals()
const {
return vertex_normals_.
is_valid(); }
578 bool has_vertex_colors()
const {
return vertex_colors_.
is_valid(); }
579 bool has_vertex_texcoords()
const {
return vertex_texcoords_.
is_valid(); }
580 bool has_vertex_status()
const {
return vertex_status_.
is_valid(); }
581 bool has_edge_status()
const {
return edge_status_.
is_valid(); }
582 bool has_halfedge_status()
const {
return halfedge_status_.
is_valid(); }
583 bool has_edge_colors()
const {
return edge_colors_.
is_valid(); }
584 bool has_face_normals()
const {
return face_normals_.
is_valid(); }
585 bool has_face_colors()
const {
return face_colors_.
is_valid(); }
586 bool has_face_status()
const {
return face_status_.
is_valid(); }
588 static bool has_prev_halfedge() {
595 osg::GeometryPtr createGeometryPtr()
598 GeometryPtr geo=Geometry::create();
599 return bind(geo) ? geo : NullFC;
603 bool bind( osg::GeometryPtr& _geo )
608 Geometry::TypesFieldMask |
609 Geometry::LengthsFieldMask |
610 Geometry::IndicesFieldMask |
611 Geometry::PositionsFieldMask;
613 if ( has_vertex_colors() )
614 Mask |= Geometry::ColorsFieldMask;
615 if ( has_vertex_normals() )
616 Mask |= Geometry::NormalsFieldMask;
617 if ( has_vertex_texcoords() )
618 Mask |= Geometry::TexCoordsFieldMask;
625 beginEditCP( _geo, Mask );
627 addRefCP( osg_ptypes() );
628 _geo->setTypes ( osg_ptypes() );
629 addRefCP( osg_plengths() );
630 _geo->setLengths ( osg_plengths() );
631 addRefCP( osg_indices() );
632 _geo->setIndices ( osg_indices() );
633 addRefCP( osg_vpositions() );
634 _geo->setPositions( osg_vpositions() );
636 if ( has_vertex_colors() )
638 addRefCP( osg_vcolors() );
639 _geo->setColors ( osg_vcolors() );
641 if ( has_vertex_normals() )
643 addRefCP( osg_vnormals() );
644 _geo->setNormals ( osg_vnormals() );
646 if ( has_vertex_texcoords() )
648 addRefCP( osg_vtexcoords() );
649 _geo->setTexCoords( osg_vtexcoords() );
652 endEditCP (_geo, Mask);
677 unsigned int refcount_vnormals_;
678 unsigned int refcount_vcolors_;
679 unsigned int refcount_vtexcoords_;
680 unsigned int refcount_vstatus_;
681 unsigned int refcount_estatus_;
682 unsigned int refcount_ecolors_;
683 unsigned int refcount_hstatus_;
684 unsigned int refcount_fnormals_;
685 unsigned int refcount_fcolors_;
686 unsigned int refcount_fstatus_;
695 #endif // OPENMESH_KERNEL_OSG_ATTRIBKERNEL_HH defined
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:81
bool is_valid() const
The handle is valid iff the index is not equal to -1.
Definition: Handles.hh:70
Add status to mesh item (all items)
Definition: Attributes.hh:83
void add_property(VPropHandleT< T > &_ph, const std::string &_name="<vprop>")
Adds a property.
Definition: BaseKernel.hh:130
Handle for a halfedge entity.
Definition: Handles.hh:121
Add storage for previous halfedge (halfedges). The bit is set by default in the DefaultTraits.
Definition: Attributes.hh:82
void remove_property(VPropHandleT< T > &_ph)
Remove a property.
Definition: BaseKernel.hh:180
This file provides some macros containing attribute usage.
Handle for a edge entity.
Definition: Handles.hh:128
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)
Bind a OpenSG geometry to a mesh.
Definition: bindT.hh:99
Helper class, extending functionaliy of OpenMesh::BaseKernel to OpenSG specific property adaptors...
Definition: PropertyKernel.hh:66
Add status information to a base class.
Definition: Status.hh:92
Handle representing a face property.
Definition: Property.hh:518
Handle for a face entity.
Definition: Handles.hh:135
Handle for a vertex entity.
Definition: Handles.hh:114
This class adds the standard properties to the mesh type.
Definition: AttribKernelT.hh:68
PropertyT< T > & property(VPropHandleT< T > _ph)
Access a property.
Definition: BaseKernel.hh:286
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:80