44 #ifndef OPENMESH_KERNEL_OSG_ATTRIBKERNEL_HH 45 #define OPENMESH_KENREL_OSG_ATTRIBKERNEL_HH 50 #include <OpenMesh/Core/Utils/GenProg.hh> 53 #include <OpenMesh/Tools/Kernel_OSG/PropertyT.hh> 54 #include <OpenMesh/Tools/Kernel_OSG/PropertyKernel.hh> 56 #include <osg/Geometry> 62 namespace Kernel_OSG {
69 template <
class MeshItems>
75 typedef typename MeshItems::Face::IsTriangle IsTriMesh;
86 typedef typename MeshItems::Vertex Vertex;
87 typedef typename MeshItems::Halfedge Halfedge;
88 typedef typename MeshItems::Edge Edge;
89 typedef typename MeshItems::Face Face;
91 typedef typename MeshItems::Point Point;
94 typedef typename MeshItems::TexCoord TexCoord;
96 typedef typename MeshItems::Scalar Scalar;
102 VAttribs = MeshItems::VAttribs,
103 HAttribs = MeshItems::HAttribs,
104 EAttribs = MeshItems::EAttribs,
105 FAttribs = MeshItems::FAttribs,
108 typedef GenProg::Bool2Type<(bool)(HAttribs & Attributes::PrevHalfedge)>
113 typedef typename _t2vp< Point >::prop GeoPositions;
114 typedef typename _t2vn< Normal >::prop GeoNormals;
115 typedef typename _t2vc< Color >::prop GeoColors;
116 typedef typename _t2vtc< TexCoord >::prop GeoTexCoords;
126 refcount_vnormals_(0),
127 refcount_vcolors_(0),
128 refcount_vtexcoords_(0),
129 refcount_vstatus_(0),
130 refcount_estatus_(0),
131 refcount_ecolors_(0),
132 refcount_hstatus_(0),
133 refcount_fnormals_(0),
134 refcount_fcolors_(0),
138 points_ = add_vpositions( Point(),
"v:points" );
140 face_types_ = add_fptypes();
141 face_lengths_ = add_fplengths();
142 face_indices_ = add_findices( face_types_, face_lengths_);
145 request_vertex_normals();
148 request_vertex_colors();
150 if (VAttribs & Attributes::TexCoord)
151 request_vertex_texcoords();
154 request_vertex_status();
156 if (EAttribs & Attributes::Status)
157 request_edge_status();
159 if (EAttribs & Attributes::Color)
160 request_edge_colors();
162 if (FAttribs & Attributes::Normal)
163 request_face_normals();
165 if (FAttribs & Attributes::Color)
166 request_face_colors();
168 if (FAttribs & Attributes::Status)
169 request_face_status();
203 BaseKernel::operator=(_rhs);
206 points_ = _rhs.points_;
207 vertex_normals_ = _rhs.vertex_normals_;
208 vertex_colors_ = _rhs.vertex_colors_;
209 vertex_texcoords_ = _rhs.vertex_texcoords_;
210 vertex_status_ = _rhs.vertex_status_;
211 halfedge_status_ = _rhs.halfedge_status_;
212 edge_status_ = _rhs.edge_status_;
213 edge_colors_ = _rhs.edge_colors_;
214 face_normals_ = _rhs.face_normals_;
215 face_colors_ = _rhs.face_colors_;
216 face_status_ = _rhs.face_status_;
219 refcount_vnormals_ = _rhs.refcount_vnormals_;
220 refcount_vcolors_ = _rhs.refcount_vcolors_;
221 refcount_vtexcoords_ = _rhs.refcount_vtexcoords_;
222 refcount_vstatus_ = _rhs.refcount_vstatus_;
223 refcount_hstatus_ = _rhs.refcount_hstatus_;
224 refcount_estatus_ = _rhs.refcount_estatus_;
225 refcount_ecolors_ = _rhs.refcount_ecolors_;
226 refcount_fnormals_ = _rhs.refcount_fnormals_;
227 refcount_fcolors_ = _rhs.refcount_fcolors_;
228 refcount_fstatus_ = _rhs.refcount_fstatus_;
237 typename GeoPositions::property_ptr_t osg_vpositions()
238 {
return vpositions(points_).osg_ptr(); }
240 typename GeoNormals::property_ptr_t osg_vnormals()
241 {
return vnormals(vertex_normals_).osg_ptr(); }
243 typename GeoColors::property_ptr_t osg_vcolors()
244 {
return vcolors(vertex_colors_).osg_ptr(); }
246 typename GeoTexCoords::property_ptr_t osg_vtexcoords()
247 {
return vtexcoords(vertex_texcoords_).osg_ptr(); }
251 typename GeoColors::property_ptr_t osg_ecolors()
252 {
return ecolors(edge_colors_).osg_ptr(); }
256 GeoPTypes::property_ptr_t osg_ptypes()
257 {
return fptypes( face_types_ ).osg_ptr(); }
259 GeoPLengths::property_ptr_t osg_plengths()
260 {
return fplengths( face_lengths_ ).osg_ptr(); }
262 typename GeoIndices::property_ptr_t osg_indices()
263 {
return findices( face_indices_ ).osg_ptr(); }
270 void set_face_types(
FaceHandle _fh, GeoPTypes::value_type _t)
271 { fptypes( face_types_, _fh ) = _t; }
273 void set_face_lengths(
FaceHandle _fh, GeoPLengths::value_type _l)
274 { fplengths( face_lengths_, _fh ) = _l; }
277 typename GeoIndices::value_type _i)
278 { findices( face_indices_, _fh ) = _i; }
284 const Point* points()
const 285 {
return vpositions( points_ ).data(); }
288 {
return vpositions( points_, _vh); }
291 { vpositions( points_, _vh ) = _p; }
296 const Normal* vertex_normals()
const {
297 return vnormals(vertex_normals_).data();
301 return vnormals(vertex_normals_, _vh);
305 vnormals(vertex_normals_, _vh) = _n;
311 const Color* vertex_colors()
const {
312 return vcolors(vertex_colors_).data();
316 return vcolors(vertex_colors_, _vh);
320 vcolors(vertex_colors_, _vh) = _c;
326 const TexCoord* texcoords()
const {
327 return vtexcoords(vertex_texcoords_).data();
331 return vtexcoords(vertex_texcoords_, _vh);
334 void set_texcoord(
VertexHandle _vh,
const TexCoord& _t) {
335 vtexcoords(vertex_texcoords_, _vh) = _t;
342 return property(vertex_status_, _vh);
346 return property(vertex_status_, _vh);
353 return property(halfedge_status_, _eh);
357 return property(halfedge_status_, _eh);
363 const StatusInfo& status(
EdgeHandle _eh)
const {
373 const Color* edge_colors()
const {
374 return ecolors(edge_colors_).data();
378 return ecolors(edge_colors_, _eh);
381 void set_color(
EdgeHandle _eh,
const Color& _c) {
382 ecolors(edge_colors_, _eh) = _c;
388 const StatusInfo& status(
FaceHandle _fh)
const {
400 return property(face_normals_, _fh);
403 void set_normal(
FaceHandle _fh,
const Normal& _n) {
414 void set_color(
FaceHandle _fh,
const Color& _c) {
422 void request_vertex_normals() {
423 if (!refcount_vnormals_++)
424 vertex_normals_ = add_vnormals( Normal(),
"v:normals" );
427 void request_vertex_colors() {
428 if (!refcount_vcolors_++)
429 vertex_colors_ = add_vcolors( Color(),
"v:colors" );
432 void request_vertex_texcoords() {
433 if (!refcount_vtexcoords_++)
434 vertex_texcoords_ = add_vtexcoords( TexCoord(),
"v:texcoords" );
437 void request_vertex_status() {
438 if (!refcount_vstatus_++)
442 void request_halfedge_status() {
443 if (!refcount_hstatus_++)
447 void request_edge_status() {
448 if (!refcount_estatus_++)
452 void request_edge_colors() {
453 if (!refcount_ecolors_++)
454 edge_colors_ = add_ecolors( Color(),
"e:colors" );
457 void request_face_normals() {
458 if (!refcount_fnormals_++)
462 void request_face_colors() {
463 if (!refcount_fcolors_++)
467 void request_face_status() {
468 if (!refcount_fstatus_++)
476 void release_vertex_normals() {
477 if ((refcount_vnormals_ > 0) && (! --refcount_vnormals_))
481 void release_vertex_colors() {
482 if ((refcount_vcolors_ > 0) && (! --refcount_vcolors_))
486 void release_vertex_texcoords() {
487 if ((refcount_vtexcoords_ > 0) && (! --refcount_vtexcoords_))
491 void release_vertex_status() {
492 if ((refcount_vstatus_ > 0) && (! --refcount_vstatus_))
496 void release_halfedge_status() {
497 if ((refcount_hstatus_ > 0) && (! --refcount_hstatus_))
501 void release_edge_status() {
502 if ((refcount_estatus_ > 0) && (! --refcount_estatus_))
506 void release_edge_colors() {
507 if ((refcount_ecolors_ > 0) && (! --refcount_ecolors_))
511 void release_face_normals() {
512 if ((refcount_fnormals_ > 0) && (! --refcount_fnormals_))
516 void release_face_colors() {
517 if ((refcount_fcolors_ > 0) && (! --refcount_fcolors_))
521 void release_face_status() {
522 if ((refcount_fstatus_ > 0) && (! --refcount_fstatus_))
530 GenProg::Bool2Type<(bool)(VAttribs & Attributes::Normal)>
534 GenProg::Bool2Type<(bool)(VAttribs & Attributes::Color)>
538 GenProg::Bool2Type<(bool)(VAttribs & Attributes::TexCoord)>
542 GenProg::Bool2Type<(bool)(VAttribs & Attributes::Status)>
547 GenProg::Bool2Type<(bool)(HAttribs & Attributes::PrevHalfedge)>
551 GenProg::Bool2Type<(bool)(HAttribs & Attributes::Status)>
556 GenProg::Bool2Type<(bool)(EAttribs & Attributes::Status)>
560 GenProg::Bool2Type<(bool)(EAttribs & Attributes::Color)>
565 GenProg::Bool2Type<(bool)(FAttribs & Attributes::Normal)>
569 GenProg::Bool2Type<(bool)(FAttribs & Attributes::Color)>
573 GenProg::Bool2Type<(bool)(FAttribs & Attributes::Status)>
579 bool has_vertex_normals()
const {
return vertex_normals_.
is_valid(); }
580 bool has_vertex_colors()
const {
return vertex_colors_.
is_valid(); }
581 bool has_vertex_texcoords()
const {
return vertex_texcoords_.
is_valid(); }
582 bool has_vertex_status()
const {
return vertex_status_.
is_valid(); }
583 bool has_edge_status()
const {
return edge_status_.
is_valid(); }
584 bool has_halfedge_status()
const {
return halfedge_status_.
is_valid(); }
585 bool has_edge_colors()
const {
return edge_colors_.
is_valid(); }
586 bool has_face_normals()
const {
return face_normals_.
is_valid(); }
587 bool has_face_colors()
const {
return face_colors_.
is_valid(); }
588 bool has_face_status()
const {
return face_status_.
is_valid(); }
590 static bool has_prev_halfedge() {
597 osg::GeometryPtr createGeometryPtr()
600 GeometryPtr geo=Geometry::create();
601 return bind(geo) ? geo : NullFC;
605 bool bind( osg::GeometryPtr& _geo )
610 Geometry::TypesFieldMask |
611 Geometry::LengthsFieldMask |
612 Geometry::IndicesFieldMask |
613 Geometry::PositionsFieldMask;
615 if ( has_vertex_colors() )
616 Mask |= Geometry::ColorsFieldMask;
617 if ( has_vertex_normals() )
618 Mask |= Geometry::NormalsFieldMask;
619 if ( has_vertex_texcoords() )
620 Mask |= Geometry::TexCoordsFieldMask;
627 beginEditCP( _geo, Mask );
629 addRefCP( osg_ptypes() );
630 _geo->setTypes ( osg_ptypes() );
631 addRefCP( osg_plengths() );
632 _geo->setLengths ( osg_plengths() );
633 addRefCP( osg_indices() );
634 _geo->setIndices ( osg_indices() );
635 addRefCP( osg_vpositions() );
636 _geo->setPositions( osg_vpositions() );
638 if ( has_vertex_colors() )
640 addRefCP( osg_vcolors() );
641 _geo->setColors ( osg_vcolors() );
643 if ( has_vertex_normals() )
645 addRefCP( osg_vnormals() );
646 _geo->setNormals ( osg_vnormals() );
648 if ( has_vertex_texcoords() )
650 addRefCP( osg_vtexcoords() );
651 _geo->setTexCoords( osg_vtexcoords() );
654 endEditCP (_geo, Mask);
667 FPTypesHandle face_types_;
668 FPLengthsHandle face_lengths_;
669 FIndicesHandle face_indices_;
679 unsigned int refcount_vnormals_;
680 unsigned int refcount_vcolors_;
681 unsigned int refcount_vtexcoords_;
682 unsigned int refcount_vstatus_;
683 unsigned int refcount_estatus_;
684 unsigned int refcount_ecolors_;
685 unsigned int refcount_hstatus_;
686 unsigned int refcount_fnormals_;
687 unsigned int refcount_fcolors_;
688 unsigned int refcount_fstatus_;
697 #endif // OPENMESH_KERNEL_OSG_ATTRIBKERNEL_HH defined PropertyT< T > & property(VPropHandleT< T > _ph)
In most cases you should use the convenient PropertyManager wrapper and use of this function should n...
Definition: BaseKernel.hh:310
void remove_property(VPropHandleT< T > &_ph)
You should not use this function directly.
Definition: BaseKernel.hh:194
Handle for a halfedge entity.
Definition: Handles.hh:127
Handle representing a face property.
Definition: Property.hh:524
Add status information to a base class.
Definition: Status.hh:94
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)
Bind a OpenSG geometry to a mesh.
Definition: bindT.hh:101
void add_property(VPropHandleT< T > &_ph, const std::string &_name="<vprop>")
You should not use this function directly.
Definition: BaseKernel.hh:141
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
This class adds the standard properties to the mesh type.
Definition: AttribKernelT.hh:70
Add storage for previous halfedge (halfedges). The bit is set by default in the DefaultTraits.
Definition: Attributes.hh:84
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:83
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:82
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
Handle for a face entity.
Definition: Handles.hh:141
Helper class, extending functionaliy of OpenMesh::BaseKernel to OpenSG specific property adaptors...
Definition: PropertyKernel.hh:68
bool is_valid() const
The handle is valid iff the index is not negative.
Definition: Handles.hh:72