First checkin for OpenMesh 2.0
git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@2 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
17
Tools/Kernel_OSG/ACGMakefile
Normal file
17
Tools/Kernel_OSG/ACGMakefile
Normal file
@@ -0,0 +1,17 @@
|
||||
#== SYSTEM PART -- DON'T TOUCH ==============================================
|
||||
include $(ACGMAKE)/Config
|
||||
#==============================================================================
|
||||
|
||||
|
||||
SUBDIRS = $(call find-subdirs)
|
||||
|
||||
PACKAGES := opensg boost
|
||||
|
||||
PROJ_LIBS := OpenMesh/Core
|
||||
|
||||
MODULES := cxxlib
|
||||
|
||||
|
||||
#== SYSTEM PART -- DON'T TOUCH ==============================================
|
||||
include $(ACGMAKE)/Rules
|
||||
#==============================================================================
|
||||
209
Tools/Kernel_OSG/ArrayKernelT.hh
Normal file
209
Tools/Kernel_OSG/ArrayKernelT.hh
Normal file
@@ -0,0 +1,209 @@
|
||||
//=============================================================================
|
||||
//
|
||||
// OpenMesh
|
||||
// Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen
|
||||
// www.openmesh.org
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// License
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation, version 2.1.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $Revision: 1802 $
|
||||
// $Date: 2008-05-19 11:55:07 +0200 (Mo, 19. Mai 2008) $
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// CLASS OSGArrayKernelT
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
#ifndef OPENMESH_KERNELOSG_ARRAY_KERNEL_HH
|
||||
#define OPENMEHS_KERNELOSG_ARRAY_KERNEL_HH
|
||||
|
||||
|
||||
//== INCLUDES =================================================================
|
||||
|
||||
#include <vector>
|
||||
// --------------------
|
||||
#include <OpenMesh/Core/System/config.h>
|
||||
#include <OpenMesh/Core/Utils/GenProg.hh>
|
||||
#include <OpenMesh/Core/Mesh/Kernels/ArrayKernel/ArrayKernelT.hh>
|
||||
// --------------------
|
||||
#include <OpenMesh/Tools/Kernel_OSG/AttribKernelT.hh>
|
||||
|
||||
|
||||
|
||||
//== NAMESPACES ===============================================================
|
||||
|
||||
|
||||
namespace OpenMesh {
|
||||
namespace Kernel_OSG {
|
||||
|
||||
//== CLASS DEFINITION =========================================================
|
||||
|
||||
|
||||
/** \ingroup mesh_kernels_group
|
||||
*
|
||||
* Mesh kernel using arrays for mesh item storage.
|
||||
*
|
||||
* This mesh kernel uses the OpenSG GeoProperties as container
|
||||
* to store the mesh items.
|
||||
*
|
||||
* \note You do not have to use this class directly, use the predefined
|
||||
* mesh-kernel combinations in \ref mesh_types_group.
|
||||
*/
|
||||
// \see OpenMesh::ArrayHandleT
|
||||
// \see \ref mesh_type
|
||||
|
||||
|
||||
template <class AttribKernel, class FinalMeshItems>
|
||||
class ArrayKernelT
|
||||
: public OpenMesh::ArrayKernelT<AttribKernel, FinalMeshItems>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ArrayKernelT<AttribKernel, FinalMeshItems> This;
|
||||
typedef OpenMesh::ArrayKernelT<AttribKernel, FinalMeshItems> Base;
|
||||
|
||||
// attributes
|
||||
// typedef typename Base::HasVertexNormals HasVertexNormals;
|
||||
// typedef typename Base::HasVertexColors HasVertexColors;
|
||||
// typedef typename Base::HasVertexTexCoords HasVertexTexCoords;
|
||||
// typedef typename Base::HasVertexStatus HasVertexStatus;
|
||||
typedef typename Base::HasPrevHalfedge HasPrevHalfedge;
|
||||
// typedef typename Base::HasEdgeStatus HasEdgeStatus;
|
||||
// typedef typename Base::HasFaceNormals HasFaceNormals;
|
||||
// typedef typename Base::HasFaceColors HasFaceColors;
|
||||
// typedef typename Base::HasFaceStatus HasFaceStatus;
|
||||
|
||||
// item types
|
||||
typedef typename FinalMeshItems::Vertex Vertex;
|
||||
typedef typename FinalMeshItems::Halfedge Halfedge;
|
||||
typedef typename FinalMeshItems::Edge Edge;
|
||||
typedef typename FinalMeshItems::Face Face;
|
||||
typedef typename FinalMeshItems::Point Point;
|
||||
typedef typename FinalMeshItems::Normal Normal;
|
||||
typedef typename FinalMeshItems::Color Color;
|
||||
typedef typename FinalMeshItems::TexCoord TexCoord;
|
||||
typedef typename FinalMeshItems::Scalar Scalar;
|
||||
|
||||
// // handles
|
||||
// typedef typename OpenMesh::VertexHandle VertexHandle;
|
||||
// typedef typename FinalMeshItems::HalfedgeHandle HalfedgeHandle;
|
||||
// typedef typename FinalMeshItems::EdgeHandle EdgeHandle;
|
||||
// typedef typename FinalMeshItems::FaceHandle FaceHandle;
|
||||
|
||||
// iterators
|
||||
typedef std::vector<Vertex> VertexContainer;
|
||||
typedef std::vector<Edge> EdgeContainer;
|
||||
typedef std::vector<Face> FaceContainer;
|
||||
typedef typename VertexContainer::iterator KernelVertexIter;
|
||||
typedef typename VertexContainer::const_iterator KernelConstVertexIter;
|
||||
typedef typename EdgeContainer::iterator KernelEdgeIter;
|
||||
typedef typename EdgeContainer::const_iterator KernelConstEdgeIter;
|
||||
typedef typename FaceContainer::iterator KernelFaceIter;
|
||||
typedef typename FaceContainer::const_iterator KernelConstFaceIter;
|
||||
|
||||
public:
|
||||
|
||||
ArrayKernelT() : Base()
|
||||
{ }
|
||||
|
||||
virtual ~ArrayKernelT()
|
||||
{ }
|
||||
|
||||
public: // replacements
|
||||
|
||||
void set_halfedge_handle(VertexHandle _vh, HalfedgeHandle _heh) {
|
||||
Base::set_halfedge_handle( _vh, _heh );
|
||||
}
|
||||
|
||||
void set_halfedge_handle(FaceHandle _fh, HalfedgeHandle _heh) {
|
||||
Base::set_halfedge_handle( _fh, _heh );
|
||||
osg_sync( _fh );
|
||||
}
|
||||
|
||||
void set_next_halfedge_handle(HalfedgeHandle _heh, HalfedgeHandle _nheh) {
|
||||
Base::set_next_halfedge_handle( _heh, _nheh );
|
||||
osg_sync( face_handle( _heh ) ); // ##Changed
|
||||
}
|
||||
|
||||
void garbage_collection(bool _v=true, bool _e=true, bool _f=true);
|
||||
|
||||
protected:
|
||||
|
||||
bool osg_sync( FaceHandle _fh )
|
||||
{
|
||||
return _fh.is_valid()
|
||||
? osg_sync( _fh, typename Face::IsTriangle() )
|
||||
: false;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
bool osg_sync( FaceHandle _fh, GenProg::Bool2Type<true> )
|
||||
{
|
||||
HalfedgeHandle hh( halfedge_handle(_fh) );
|
||||
if ( !hh.is_valid() ) return false;
|
||||
FaceHandle f1( _fh.idx() * 3 );
|
||||
set_face_indices( f1, to_vertex_handle(hh).idx() );
|
||||
|
||||
hh = next_halfedge_handle(hh);
|
||||
if ( !hh.is_valid() ) return false;
|
||||
FaceHandle f2( f1.idx()+1 );
|
||||
set_face_indices( f2, to_vertex_handle(hh).idx() );
|
||||
|
||||
hh = next_halfedge_handle(hh);
|
||||
if ( !hh.is_valid() ) return false;
|
||||
FaceHandle f3( f1.idx()+2 );
|
||||
set_face_indices( f3, to_vertex_handle(hh).idx() );
|
||||
|
||||
set_face_types ( _fh, GL_TRIANGLES );
|
||||
set_face_lengths( _fh, 3 );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool osg_sync( FaceHandle _fh, GenProg::Bool2Type<false> )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <class AttribKernel, class FinalMeshItems>
|
||||
void
|
||||
ArrayKernelT<AttribKernel, FinalMeshItems>::
|
||||
garbage_collection(bool _v, bool _e, bool _f)
|
||||
{
|
||||
Base::garbage_collection(_v, _e, _f);
|
||||
for (size_t fidx=0; fidx < n_faces(); ++fidx)
|
||||
osg_sync( FaceHandle(fidx) );
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
} // namespace Kernel_OSG
|
||||
} // namespace OpenMesh
|
||||
//=============================================================================
|
||||
#endif // OPENMESH_ARRAY_KERNEL_HH defined
|
||||
//=============================================================================
|
||||
638
Tools/Kernel_OSG/AttribKernelT.hh
Normal file
638
Tools/Kernel_OSG/AttribKernelT.hh
Normal file
@@ -0,0 +1,638 @@
|
||||
/*===========================================================================*\
|
||||
* *
|
||||
* OpenMesh *
|
||||
* Copyright (C) 2001-2003 by Computer Graphics Group, RWTH Aachen *
|
||||
* www.openmesh.org *
|
||||
* *
|
||||
*---------------------------------------------------------------------------*
|
||||
* *
|
||||
* License *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as published *
|
||||
* by the Free Software Foundation, version 2.1. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
|
||||
* *
|
||||
\*===========================================================================*/
|
||||
|
||||
#ifndef OPENMESH_KERNEL_OSG_ATTRIBKERNEL_HH
|
||||
#define OPENMESH_KENREL_OSG_ATTRIBKERNEL_HH
|
||||
|
||||
|
||||
//== INCLUDES =================================================================
|
||||
|
||||
#include <OpenMesh/Core/Utils/GenProg.hh>
|
||||
#include <OpenMesh/Core/Attributes/Attributes.hh>
|
||||
// --------------------
|
||||
#include <OpenMesh/Tools/Kernel_OSG/PropertyT.hh>
|
||||
#include <OpenMesh/Tools/Kernel_OSG/PropertyKernel.hh>
|
||||
// --------------------
|
||||
#include <OpenSG/OSGGeometry.h>
|
||||
|
||||
|
||||
//== NAMESPACES ===============================================================
|
||||
|
||||
namespace OpenMesh {
|
||||
namespace Kernel_OSG {
|
||||
|
||||
//== CLASS DEFINITION =========================================================
|
||||
|
||||
|
||||
|
||||
/// This class adds the standard properties to the mesh type.
|
||||
template <class MeshItems>
|
||||
class AttribKernelT
|
||||
: public PropertyKernel< typename MeshItems::Face::IsTriangle >
|
||||
{
|
||||
protected:
|
||||
|
||||
typedef typename MeshItems::Face::IsTriangle IsTriMesh;
|
||||
typedef PropertyKernel< IsTriMesh > Base;
|
||||
|
||||
typedef typename Base::FPTypesHandle FPTypesHandle;
|
||||
typedef typename Base::FPLengthsHandle FPLengthsHandle;
|
||||
typedef typename Base::FIndicesHandle FIndicesHandle;
|
||||
|
||||
public:
|
||||
|
||||
//---------------------------------------------------------------- item types
|
||||
|
||||
typedef typename MeshItems::Vertex Vertex;
|
||||
typedef typename MeshItems::Halfedge Halfedge;
|
||||
typedef typename MeshItems::Edge Edge;
|
||||
typedef typename MeshItems::Face Face;
|
||||
|
||||
typedef typename MeshItems::Point Point;
|
||||
typedef typename MeshItems::Normal Normal;
|
||||
typedef typename MeshItems::Color Color;
|
||||
typedef typename MeshItems::TexCoord TexCoord;
|
||||
|
||||
typedef typename MeshItems::Scalar Scalar;
|
||||
|
||||
typedef Attributes::StatusInfo StatusInfo;
|
||||
|
||||
|
||||
enum Attribs {
|
||||
VAttribs = MeshItems::VAttribs,
|
||||
HAttribs = MeshItems::HAttribs,
|
||||
EAttribs = MeshItems::EAttribs,
|
||||
FAttribs = MeshItems::FAttribs,
|
||||
};
|
||||
|
||||
typedef GenProg::Bool2Type<(bool)(HAttribs & Attributes::PrevHalfedge)>
|
||||
HasPrevHalfedge;
|
||||
|
||||
//
|
||||
|
||||
typedef typename _t2vp< Point >::prop GeoPositions;
|
||||
typedef typename _t2vn< Normal >::prop GeoNormals;
|
||||
typedef typename _t2vc< Color >::prop GeoColors;
|
||||
typedef typename _t2vtc< TexCoord >::prop GeoTexCoords;
|
||||
|
||||
// typedef typename Base::GeoPTypes GeoPTypes;
|
||||
// typedef typename Base::GeoPLengths GeoPLengths;
|
||||
// typedef typename Base::GeoIndices GeoIndices;
|
||||
|
||||
//-------------------------------------------------- constructor / destructor
|
||||
|
||||
AttribKernelT() :
|
||||
|
||||
refcount_vnormals_(0),
|
||||
refcount_vcolors_(0),
|
||||
refcount_vtexcoords_(0),
|
||||
refcount_vstatus_(0),
|
||||
refcount_estatus_(0),
|
||||
refcount_hstatus_(0),
|
||||
refcount_fnormals_(0),
|
||||
refcount_fcolors_(0),
|
||||
refcount_fstatus_(0)
|
||||
|
||||
{
|
||||
points_ = add_vpositions( Point(), "v:points" );
|
||||
|
||||
face_types_ = add_fptypes();
|
||||
face_lengths_ = add_fplengths();
|
||||
face_indices_ = add_findices( face_types_, face_lengths_);
|
||||
|
||||
if (VAttribs & Attributes::Normal)
|
||||
request_vertex_normals();
|
||||
|
||||
if (VAttribs & Attributes::Color)
|
||||
request_vertex_colors();
|
||||
|
||||
if (VAttribs & Attributes::TexCoord)
|
||||
request_vertex_texcoords();
|
||||
|
||||
if (VAttribs & Attributes::Status)
|
||||
request_vertex_status();
|
||||
|
||||
if (EAttribs & Attributes::Status)
|
||||
request_edge_status();
|
||||
|
||||
if (FAttribs & Attributes::Normal)
|
||||
request_face_normals();
|
||||
|
||||
if (FAttribs & Attributes::Color)
|
||||
request_face_colors();
|
||||
|
||||
if (FAttribs & Attributes::Status)
|
||||
request_face_status();
|
||||
}
|
||||
|
||||
~AttribKernelT()
|
||||
{
|
||||
// should remove properties, but this will be done in
|
||||
// BaseKernel's destructor anyway...
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------- copy & assignement
|
||||
|
||||
AttribKernelT( const AttribKernelT& _rhs )
|
||||
: Base( _rhs )
|
||||
{
|
||||
operator=(_rhs);
|
||||
}
|
||||
|
||||
AttribKernelT& operator = ( const AttribKernelT& _rhs )
|
||||
{
|
||||
// remove old properties
|
||||
remove_property(points_);
|
||||
remove_property(vertex_normals_);
|
||||
remove_property(vertex_colors_);
|
||||
remove_property(vertex_texcoords_);
|
||||
remove_property(vertex_status_);
|
||||
remove_property(halfedge_status_);
|
||||
remove_property(edge_status_);
|
||||
remove_property(face_normals_);
|
||||
remove_property(face_colors_);
|
||||
remove_property(face_status_);
|
||||
|
||||
// parent deep-copies properties
|
||||
BaseKernel::operator=(_rhs);
|
||||
|
||||
// copy property handles
|
||||
points_ = _rhs.points_;
|
||||
vertex_normals_ = _rhs.vertex_normals_;
|
||||
vertex_colors_ = _rhs.vertex_colors_;
|
||||
vertex_texcoords_ = _rhs.vertex_texcoords_;
|
||||
vertex_status_ = _rhs.vertex_status_;
|
||||
halfedge_status_ = _rhs.halfedge_status_;
|
||||
edge_status_ = _rhs.edge_status_;
|
||||
face_normals_ = _rhs.face_normals_;
|
||||
face_colors_ = _rhs.face_colors_;
|
||||
face_status_ = _rhs.face_status_;
|
||||
|
||||
// copy ref-counts
|
||||
refcount_vnormals_ = _rhs.refcount_vnormals_;
|
||||
refcount_vcolors_ = _rhs.refcount_vcolors_;
|
||||
refcount_vtexcoords_ = _rhs.refcount_vtexcoords_;
|
||||
refcount_vstatus_ = _rhs.refcount_vstatus_;
|
||||
refcount_hstatus_ = _rhs.refcount_hstatus_;
|
||||
refcount_estatus_ = _rhs.refcount_estatus_;
|
||||
refcount_fnormals_ = _rhs.refcount_fnormals_;
|
||||
refcount_fcolors_ = _rhs.refcount_fcolors_;
|
||||
refcount_fstatus_ = _rhs.refcount_fstatus_;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------ osg properties
|
||||
|
||||
//------------------------------ vertex property
|
||||
|
||||
typename GeoPositions::property_ptr_t osg_vpositions()
|
||||
{ return vpositions(points_).osg_ptr(); }
|
||||
|
||||
typename GeoNormals::property_ptr_t osg_vnormals()
|
||||
{ return vnormals(vertex_normals_).osg_ptr(); }
|
||||
|
||||
typename GeoColors::property_ptr_t osg_vcolors()
|
||||
{ return vcolors(vertex_colors_).osg_ptr(); }
|
||||
|
||||
typename GeoTexCoords::property_ptr_t osg_vtexcoords()
|
||||
{ return vtexcoords(vertex_texcoords_).osg_ptr(); }
|
||||
|
||||
//------------------------------ face property
|
||||
|
||||
GeoPTypes::property_ptr_t osg_ptypes()
|
||||
{ return fptypes( face_types_ ).osg_ptr(); }
|
||||
|
||||
GeoPLengths::property_ptr_t osg_plengths()
|
||||
{ return fplengths( face_lengths_ ).osg_ptr(); }
|
||||
|
||||
typename GeoIndices::property_ptr_t osg_indices()
|
||||
{ return findices( face_indices_ ).osg_ptr(); }
|
||||
|
||||
|
||||
//---------------------------------------- set osg geo property
|
||||
|
||||
//------------------------------ face property
|
||||
|
||||
void set_face_types( FaceHandle _fh, GeoPTypes::value_type _t)
|
||||
{ fptypes( face_types_, _fh ) = _t; }
|
||||
|
||||
void set_face_lengths( FaceHandle _fh, GeoPLengths::value_type _l)
|
||||
{ fplengths( face_lengths_, _fh ) = _l; }
|
||||
|
||||
void set_face_indices( FaceHandle _fh,
|
||||
typename GeoIndices::value_type _i)
|
||||
{ findices( face_indices_, _fh ) = _i; }
|
||||
|
||||
//--------------------------------------------------------- set/get properties
|
||||
|
||||
//---------------------------------------- points
|
||||
|
||||
const Point* points() const
|
||||
{ return vpositions( points_ ).data(); }
|
||||
|
||||
const Point& point(VertexHandle _vh) const
|
||||
{ return vpositions( points_, _vh); }
|
||||
|
||||
void set_point(VertexHandle _vh, const Point& _p)
|
||||
{ vpositions( points_, _vh ) = _p; }
|
||||
|
||||
|
||||
//---------------------------------------- vertex normals
|
||||
|
||||
const Normal* vertex_normals() const {
|
||||
return vnormals(vertex_normals_).data();
|
||||
}
|
||||
|
||||
const Normal& normal(VertexHandle _vh) const {
|
||||
return vnormals(vertex_normals_, _vh);
|
||||
}
|
||||
|
||||
void set_normal(VertexHandle _vh, const Normal& _n) {
|
||||
vnormals(vertex_normals_, _vh) = _n;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------- vertex colors
|
||||
|
||||
const Color* vertex_colors() const {
|
||||
return vcolors(vertex_colors_).data();
|
||||
}
|
||||
|
||||
const Color& color(VertexHandle _vh) const {
|
||||
return vcolors(vertex_colors_, _vh);
|
||||
}
|
||||
|
||||
void set_color(VertexHandle _vh, const Color& _c) {
|
||||
vcolors(vertex_colors_, _vh) = _c;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------- vertex texcoords
|
||||
|
||||
const TexCoord* texcoords() const {
|
||||
return vtexcoords(vertex_texcoords_).data();
|
||||
}
|
||||
|
||||
const TexCoord& texcoord(VertexHandle _vh) const {
|
||||
return vtexcoords(vertex_texcoords_, _vh);
|
||||
}
|
||||
|
||||
void set_texcoord(VertexHandle _vh, const TexCoord& _t) {
|
||||
vtexcoords(vertex_texcoords_, _vh) = _t;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------- vertex status
|
||||
|
||||
const StatusInfo& status(VertexHandle _vh) const {
|
||||
return property(vertex_status_, _vh);
|
||||
}
|
||||
|
||||
StatusInfo& status(VertexHandle _vh) {
|
||||
return property(vertex_status_, _vh);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------- edge status
|
||||
|
||||
const StatusInfo& status(HalfedgeHandle _eh) const {
|
||||
return property(halfedge_status_, _eh);
|
||||
}
|
||||
|
||||
StatusInfo& status(HalfedgeHandle _eh) {
|
||||
return property(halfedge_status_, _eh);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------- edge status
|
||||
|
||||
const StatusInfo& status(EdgeHandle _eh) const {
|
||||
return property(edge_status_, _eh);
|
||||
}
|
||||
|
||||
StatusInfo& status(EdgeHandle _eh) {
|
||||
return property(edge_status_, _eh);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------- face status
|
||||
|
||||
const StatusInfo& status(FaceHandle _fh) const {
|
||||
return property(face_status_, _fh);
|
||||
}
|
||||
|
||||
StatusInfo& status(FaceHandle _fh) {
|
||||
return property(face_status_, _fh);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------- face normals
|
||||
|
||||
const Normal& normal(FaceHandle _fh) const {
|
||||
return property(face_normals_, _fh);
|
||||
}
|
||||
|
||||
void set_normal(FaceHandle _fh, const Normal& _n) {
|
||||
property(face_normals_, _fh) = _n;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------- face colors
|
||||
|
||||
const Color& color(FaceHandle _fh) const {
|
||||
return property(face_colors_, _fh);
|
||||
}
|
||||
|
||||
void set_color(FaceHandle _fh, const Color& _c) {
|
||||
property(face_colors_, _fh) = _c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------ request / alloc properties
|
||||
|
||||
void request_vertex_normals() {
|
||||
if (!refcount_vnormals_++)
|
||||
vertex_normals_ = add_vnormals( Normal(), "v:normals" );
|
||||
}
|
||||
|
||||
void request_vertex_colors() {
|
||||
if (!refcount_vcolors_++)
|
||||
vertex_colors_ = add_vcolors( Color(), "v:colors" );
|
||||
}
|
||||
|
||||
void request_vertex_texcoords() {
|
||||
if (!refcount_vtexcoords_++)
|
||||
vertex_texcoords_ = add_vtexcoords( TexCoord(), "v:texcoords" );
|
||||
}
|
||||
|
||||
void request_vertex_status() {
|
||||
if (!refcount_vstatus_++)
|
||||
add_property( vertex_status_, "v:status" );
|
||||
}
|
||||
|
||||
void request_halfedge_status() {
|
||||
if (!refcount_hstatus_++)
|
||||
add_property( halfedge_status_, "h:status" );
|
||||
}
|
||||
|
||||
void request_edge_status() {
|
||||
if (!refcount_estatus_++)
|
||||
add_property( edge_status_, "e:status" );
|
||||
}
|
||||
|
||||
void request_face_normals() {
|
||||
if (!refcount_fnormals_++)
|
||||
add_property( face_normals_, "f:normals" );
|
||||
}
|
||||
|
||||
void request_face_colors() {
|
||||
if (!refcount_fcolors_++)
|
||||
add_property( face_colors_, "f:colors" );
|
||||
}
|
||||
|
||||
void request_face_status() {
|
||||
if (!refcount_fstatus_++)
|
||||
add_property( face_status_, "f:status" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------- release / free properties
|
||||
|
||||
void release_vertex_normals() {
|
||||
if ((refcount_vnormals_ > 0) && (! --refcount_vnormals_))
|
||||
remove_property(vertex_normals_);
|
||||
}
|
||||
|
||||
void release_vertex_colors() {
|
||||
if ((refcount_vcolors_ > 0) && (! --refcount_vcolors_))
|
||||
remove_property(vertex_colors_);
|
||||
}
|
||||
|
||||
void release_vertex_texcoords() {
|
||||
if ((refcount_vtexcoords_ > 0) && (! --refcount_vtexcoords_))
|
||||
remove_property(vertex_texcoords_);
|
||||
}
|
||||
|
||||
void release_vertex_status() {
|
||||
if ((refcount_vstatus_ > 0) && (! --refcount_vstatus_))
|
||||
remove_property(vertex_status_);
|
||||
}
|
||||
|
||||
void release_halfedge_status() {
|
||||
if ((refcount_hstatus_ > 0) && (! --refcount_hstatus_))
|
||||
remove_property(halfedge_status_);
|
||||
}
|
||||
|
||||
void release_edge_status() {
|
||||
if ((refcount_estatus_ > 0) && (! --refcount_estatus_))
|
||||
remove_property(edge_status_);
|
||||
}
|
||||
|
||||
void release_face_normals() {
|
||||
if ((refcount_fnormals_ > 0) && (! --refcount_fnormals_))
|
||||
remove_property(face_normals_);
|
||||
}
|
||||
|
||||
void release_face_colors() {
|
||||
if ((refcount_fcolors_ > 0) && (! --refcount_fcolors_))
|
||||
remove_property(face_colors_);
|
||||
}
|
||||
|
||||
void release_face_status() {
|
||||
if ((refcount_fstatus_ > 0) && (! --refcount_fstatus_))
|
||||
remove_property(face_status_);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------- static check for properties
|
||||
|
||||
typedef
|
||||
GenProg::Bool2Type<(bool)(VAttribs & Attributes::Normal)>
|
||||
HasVertexNormals;
|
||||
|
||||
typedef
|
||||
GenProg::Bool2Type<(bool)(VAttribs & Attributes::Color)>
|
||||
HasVertexColors;
|
||||
|
||||
typedef
|
||||
GenProg::Bool2Type<(bool)(VAttribs & Attributes::TexCoord)>
|
||||
HasVertexTexCoords;
|
||||
|
||||
typedef
|
||||
GenProg::Bool2Type<(bool)(VAttribs & Attributes::Status)>
|
||||
HasVertexStatus;
|
||||
|
||||
|
||||
typedef
|
||||
GenProg::Bool2Type<(bool)(HAttribs & Attributes::PrevHalfedge)>
|
||||
HasPrevHalfedge;
|
||||
|
||||
typedef
|
||||
GenProg::Bool2Type<(bool)(HAttribs & Attributes::Status)>
|
||||
HasHalfedgeStatus;
|
||||
|
||||
|
||||
typedef
|
||||
GenProg::Bool2Type<(bool)(EAttribs & Attributes::Status)>
|
||||
HasEdgeStatus;
|
||||
|
||||
|
||||
typedef
|
||||
GenProg::Bool2Type<(bool)(FAttribs & Attributes::Normal)>
|
||||
HasFaceNormals;
|
||||
|
||||
typedef
|
||||
GenProg::Bool2Type<(bool)(FAttribs & Attributes::Color)>
|
||||
HasFaceColors;
|
||||
|
||||
typedef
|
||||
GenProg::Bool2Type<(bool)(FAttribs & Attributes::Status)>
|
||||
HasFaceStatus;
|
||||
|
||||
|
||||
//---------------------------------------------- dynamic check for properties
|
||||
|
||||
bool has_vertex_normals() const { return vertex_normals_.is_valid(); }
|
||||
bool has_vertex_colors() const { return vertex_colors_.is_valid(); }
|
||||
bool has_vertex_texcoords() const { return vertex_texcoords_.is_valid(); }
|
||||
bool has_vertex_status() const { return vertex_status_.is_valid(); }
|
||||
bool has_edge_status() const { return edge_status_.is_valid(); }
|
||||
bool has_halfedge_status() const { return halfedge_status_.is_valid(); }
|
||||
bool has_face_normals() const { return face_normals_.is_valid(); }
|
||||
bool has_face_colors() const { return face_colors_.is_valid(); }
|
||||
bool has_face_status() const { return face_status_.is_valid(); }
|
||||
|
||||
static bool has_prev_halfedge() {
|
||||
return (HAttribs & Attributes::PrevHalfedge);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
osg::GeometryPtr createGeometryPtr()
|
||||
{
|
||||
using namespace osg;
|
||||
GeometryPtr geo=Geometry::create();
|
||||
return bind(geo) ? geo : NullFC;
|
||||
}
|
||||
|
||||
// create new geometry core from mesh
|
||||
bool bind( osg::GeometryPtr& _geo )
|
||||
{
|
||||
using namespace osg;
|
||||
|
||||
int Mask =
|
||||
Geometry::TypesFieldMask |
|
||||
Geometry::LengthsFieldMask |
|
||||
Geometry::IndicesFieldMask |
|
||||
Geometry::PositionsFieldMask;
|
||||
|
||||
if ( has_vertex_colors() )
|
||||
Mask |= Geometry::ColorsFieldMask;
|
||||
if ( has_vertex_normals() )
|
||||
Mask |= Geometry::NormalsFieldMask;
|
||||
if ( has_vertex_texcoords() )
|
||||
Mask |= Geometry::TexCoordsFieldMask;
|
||||
|
||||
// std::clog << "#ptypes : " << osg_ptypes()->getSize() << std::endl;
|
||||
// std::clog << "#plengths : " << osg_plengths()->getSize() << std::endl;
|
||||
// std::clog << "#indices : " << osg_indices()->getSize() << std::endl;
|
||||
// std::clog << "#points : " << osg_vpositions()->getSize() << std::endl;
|
||||
|
||||
beginEditCP( _geo, Mask );
|
||||
{
|
||||
addRefCP( osg_ptypes() );
|
||||
_geo->setTypes ( osg_ptypes() );
|
||||
addRefCP( osg_plengths() );
|
||||
_geo->setLengths ( osg_plengths() );
|
||||
addRefCP( osg_indices() );
|
||||
_geo->setIndices ( osg_indices() );
|
||||
addRefCP( osg_vpositions() );
|
||||
_geo->setPositions( osg_vpositions() );
|
||||
|
||||
if ( has_vertex_colors() )
|
||||
{
|
||||
addRefCP( osg_vcolors() );
|
||||
_geo->setColors ( osg_vcolors() );
|
||||
}
|
||||
if ( has_vertex_normals() )
|
||||
{
|
||||
addRefCP( osg_vnormals() );
|
||||
_geo->setNormals ( osg_vnormals() );
|
||||
}
|
||||
if ( has_vertex_texcoords() )
|
||||
{
|
||||
addRefCP( osg_vtexcoords() );
|
||||
_geo->setTexCoords( osg_vtexcoords() );
|
||||
}
|
||||
}
|
||||
endEditCP (_geo, Mask);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
VPropHandleT<Point> points_;
|
||||
VPropHandleT<Normal> vertex_normals_;
|
||||
VPropHandleT<Color> vertex_colors_;
|
||||
VPropHandleT<TexCoord> vertex_texcoords_;
|
||||
VPropHandleT<StatusInfo> vertex_status_;
|
||||
|
||||
FPTypesHandle face_types_;
|
||||
FPLengthsHandle face_lengths_;
|
||||
FIndicesHandle face_indices_;
|
||||
|
||||
EPropHandleT<StatusInfo> edge_status_;
|
||||
HPropHandleT<StatusInfo> halfedge_status_;
|
||||
|
||||
FPropHandleT<Normal> face_normals_;
|
||||
FPropHandleT<Color> face_colors_;
|
||||
FPropHandleT<StatusInfo> face_status_;
|
||||
|
||||
unsigned int refcount_vnormals_;
|
||||
unsigned int refcount_vcolors_;
|
||||
unsigned int refcount_vtexcoords_;
|
||||
unsigned int refcount_vstatus_;
|
||||
unsigned int refcount_estatus_;
|
||||
unsigned int refcount_hstatus_;
|
||||
unsigned int refcount_fnormals_;
|
||||
unsigned int refcount_fcolors_;
|
||||
unsigned int refcount_fstatus_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//=============================================================================
|
||||
} // namespace Kernel_OSG
|
||||
} // namespace OpenMesh
|
||||
//=============================================================================
|
||||
#endif // OPENMESH_KERNEL_OSG_ATTRIBKERNEL_HH defined
|
||||
//=============================================================================
|
||||
|
||||
249
Tools/Kernel_OSG/PropertyKernel.hh
Normal file
249
Tools/Kernel_OSG/PropertyKernel.hh
Normal file
@@ -0,0 +1,249 @@
|
||||
/*===========================================================================*\
|
||||
* *
|
||||
* OpenMesh *
|
||||
* Copyright (C) 2001-2003 by Computer Graphics Group, RWTH Aachen *
|
||||
* www.openmesh.org *
|
||||
* *
|
||||
*---------------------------------------------------------------------------*
|
||||
* *
|
||||
* License *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as published *
|
||||
* by the Free Software Foundation, version 2.1. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
|
||||
* *
|
||||
\*===========================================================================*/
|
||||
|
||||
#ifndef OPENMESH_KERNEL_OSG_PROPERTYKERNEL_HH
|
||||
#define OPENMESH_KENREL_OSG_PROPERTYKERNEL_HH
|
||||
|
||||
|
||||
//== INCLUDES =================================================================
|
||||
|
||||
#include <OpenMesh/Core/Utils/Property.hh>
|
||||
#include <OpenMesh/Core/Mesh/Kernels/Common/BaseKernel.hh>
|
||||
// --------------------
|
||||
#include <OpenMesh/Tools/Kernel_OSG/PropertyT.hh>
|
||||
|
||||
//== NAMESPACES ===============================================================
|
||||
|
||||
namespace OpenMesh {
|
||||
namespace Kernel_OSG {
|
||||
|
||||
//== CLASS DEFINITION =========================================================
|
||||
|
||||
/** Helper class, extending functionaliy of OpenMesh::BaseKernel to OpenSG
|
||||
* specific property adaptors.
|
||||
* \internal
|
||||
* \todo Follow coding convention and rename class to PropertyKernelT
|
||||
*/
|
||||
template < typename IsTriMesh >
|
||||
class PropertyKernel : public OpenMesh::BaseKernel
|
||||
{
|
||||
public:
|
||||
|
||||
// --------------------------------------------------------------- item types
|
||||
|
||||
typedef FPropHandleT<osg::UInt8> FPTypesHandle;
|
||||
typedef FPropHandleT<osg::UInt32> FPLengthsHandle;
|
||||
typedef FPropHandleT<osg::UInt32> FIndicesHandle;
|
||||
|
||||
typedef FP::GeoPTypesUI8 GeoPTypes;
|
||||
typedef FP::GeoPLengthsUI32 GeoPLengths;
|
||||
typedef FP::GeoIndicesUI32<IsTriMesh> GeoIndices;
|
||||
|
||||
// ------------------------------------------------- constructor / destructor
|
||||
|
||||
PropertyKernel() {}
|
||||
virtual ~PropertyKernel() { }
|
||||
|
||||
|
||||
protected: // ---------------------------------------------- add osg properties
|
||||
|
||||
// -------------------- vertex properties
|
||||
|
||||
template < typename T >
|
||||
VPropHandleT<T> add_vpositions( const T& _t, const std::string& _n )
|
||||
{ return VPropHandleT<T>(_add_vprop( new typename _t2vp<T>::prop(_n))); }
|
||||
|
||||
template < typename T >
|
||||
VPropHandleT<T> add_vnormals( const T& _t, const std::string& _n )
|
||||
{ return VPropHandleT<T>(_add_vprop( new typename _t2vn<T>::prop(_n) )); }
|
||||
|
||||
template < typename T >
|
||||
VPropHandleT<T> add_vcolors( const T& _t, const std::string& _n )
|
||||
{ return VPropHandleT<T>(_add_vprop( new typename _t2vc<T>::prop(_n) )); }
|
||||
|
||||
template < typename T >
|
||||
VPropHandleT<T> add_vtexcoords( const T& _t, const std::string& _n )
|
||||
{ return VPropHandleT<T>(_add_vprop( new typename _t2vtc<T>::prop(_n) )); }
|
||||
|
||||
|
||||
// -------------------- face properties
|
||||
|
||||
FPTypesHandle add_fptypes( )
|
||||
{ return FPTypesHandle(_add_fprop(new GeoPTypes)); }
|
||||
|
||||
FPLengthsHandle add_fplengths( )
|
||||
{ return FPLengthsHandle(_add_fprop(new GeoPLengths)); }
|
||||
|
||||
FIndicesHandle add_findices( FPTypesHandle _pht, FPLengthsHandle _phl )
|
||||
{
|
||||
GeoIndices *bp = new GeoIndices( fptypes(_pht), fplengths(_phl ) );
|
||||
return FIndicesHandle(_add_fprop( bp ) );
|
||||
}
|
||||
|
||||
protected: // ------------------------------------------- access osg properties
|
||||
|
||||
template < typename T >
|
||||
typename _t2vp<T>::prop& vpositions( VPropHandleT<T> _ph )
|
||||
{ return static_cast<typename _t2vp<T>::prop&>( _vprop( _ph ) ); }
|
||||
|
||||
template < typename T >
|
||||
const typename _t2vp<T>::prop& vpositions( VPropHandleT<T> _ph) const
|
||||
{ return static_cast<const typename _t2vp<T>::prop&>( _vprop( _ph ) ); }
|
||||
|
||||
|
||||
template < typename T >
|
||||
typename _t2vn<T>::prop& vnormals( VPropHandleT<T> _ph )
|
||||
{ return static_cast<typename _t2vn<T>::prop&>( _vprop( _ph ) ); }
|
||||
|
||||
template < typename T >
|
||||
const typename _t2vn<T>::prop& vnormals( VPropHandleT<T> _ph) const
|
||||
{ return static_cast<const typename _t2vn<T>::prop&>( _vprop( _ph ) ); }
|
||||
|
||||
|
||||
template < typename T >
|
||||
typename _t2vc<T>::prop& vcolors( VPropHandleT<T> _ph )
|
||||
{ return static_cast<typename _t2vc<T>::prop&>( _vprop( _ph ) ); }
|
||||
|
||||
template < typename T >
|
||||
const typename _t2vc<T>::prop& vcolors( VPropHandleT<T> _ph ) const
|
||||
{ return static_cast<const typename _t2vc<T>::prop&>( _vprop( _ph ) ); }
|
||||
|
||||
|
||||
template < typename T >
|
||||
typename _t2vtc<T>::prop& vtexcoords( VPropHandleT<T> _ph )
|
||||
{ return static_cast<typename _t2vtc<T>::prop&>( _vprop( _ph ) ); }
|
||||
|
||||
template < typename T >
|
||||
const typename _t2vtc<T>::prop& vtexcoords( VPropHandleT<T> _ph ) const
|
||||
{ return static_cast<const typename _t2vtc<T>::prop&>( _vprop( _ph ) ); }
|
||||
|
||||
|
||||
//
|
||||
GeoPTypes& fptypes( FPTypesHandle _ph )
|
||||
{ return static_cast<GeoPTypes&>( _fprop(_ph) ); }
|
||||
|
||||
const GeoPTypes& fptypes( FPTypesHandle _ph ) const
|
||||
{ return static_cast<const GeoPTypes&>( _fprop(_ph) ); }
|
||||
|
||||
|
||||
GeoPLengths& fplengths( FPLengthsHandle _ph )
|
||||
{ return static_cast<GeoPLengths&>( _fprop(_ph) ); }
|
||||
|
||||
const GeoPLengths& fplengths( FPLengthsHandle _ph ) const
|
||||
{ return static_cast<const GeoPLengths&>( _fprop(_ph) ); }
|
||||
|
||||
|
||||
GeoIndices& findices( FIndicesHandle _ph )
|
||||
{ return static_cast<GeoIndices&>( _fprop(_ph) ); }
|
||||
|
||||
const GeoIndices& findices( FIndicesHandle _ph ) const
|
||||
{ return static_cast<const GeoIndices&>( _fprop(_ph) ); }
|
||||
|
||||
|
||||
protected: // ------------------------------------ access osg property elements
|
||||
|
||||
template <typename T>
|
||||
T& vpositions( VPropHandleT<T> _ph, VertexHandle _vh )
|
||||
{ return vpositions(_ph)[_vh.idx()]; }
|
||||
|
||||
template <class T>
|
||||
const T& vpositions( VPropHandleT<T> _ph, VertexHandle _vh ) const
|
||||
{ return vpositions(_ph)[_vh.idx()]; }
|
||||
|
||||
|
||||
template < typename T>
|
||||
T& vnormals( VPropHandleT<T> _ph, VertexHandle _vh )
|
||||
{ return vnormals(_ph)[_vh.idx()]; }
|
||||
|
||||
template <class T>
|
||||
const T& vnormals( VPropHandleT<T> _ph, VertexHandle _vh ) const
|
||||
{ return vnormals(_ph)[_vh.idx()]; }
|
||||
|
||||
|
||||
template < typename T>
|
||||
T& vcolors( VPropHandleT<T> _ph, VertexHandle _vh )
|
||||
{ return vcolors(_ph)[_vh.idx()]; }
|
||||
|
||||
template <class T>
|
||||
const T& vcolors( VPropHandleT<T> _ph, VertexHandle _vh ) const
|
||||
{ return vcolors(_ph)[_vh.idx()]; }
|
||||
|
||||
|
||||
template < typename T>
|
||||
T& vtexcoords( VPropHandleT<T> _ph, VertexHandle _vh )
|
||||
{ return vtexcoords(_ph)[_vh.idx()]; }
|
||||
|
||||
template <class T>
|
||||
const T& vtexcoords( VPropHandleT<T> _ph, VertexHandle _vh ) const
|
||||
{ return vtexcoords(_ph)[_vh.idx()]; }
|
||||
|
||||
|
||||
// -------------------- access face property elements
|
||||
|
||||
FPTypesHandle::value_type&
|
||||
fptypes( FPTypesHandle _ph, FaceHandle _fh )
|
||||
{ return fptypes( _ph )[ _fh.idx()]; }
|
||||
|
||||
const FPTypesHandle::value_type&
|
||||
fptypes( FPTypesHandle _ph, FaceHandle _fh ) const
|
||||
{ return fptypes( _ph )[ _fh.idx()]; }
|
||||
|
||||
|
||||
FPLengthsHandle::value_type&
|
||||
fplengths( FPLengthsHandle _ph, FaceHandle _fh )
|
||||
{ return fplengths( _ph )[ _fh.idx()]; }
|
||||
|
||||
const FPLengthsHandle::value_type&
|
||||
fplengths( FPLengthsHandle _ph, FaceHandle _fh ) const
|
||||
{ return fplengths( _ph )[ _fh.idx()]; }
|
||||
|
||||
|
||||
FIndicesHandle::value_type&
|
||||
findices( FIndicesHandle _ph, FaceHandle _fh )
|
||||
{ return findices( _ph )[ _fh.idx()]; }
|
||||
|
||||
const FIndicesHandle::value_type&
|
||||
findices( FIndicesHandle _ph, FaceHandle _fh ) const
|
||||
{ return findices( _ph )[ _fh.idx()]; }
|
||||
|
||||
public:
|
||||
|
||||
void stats(void)
|
||||
{
|
||||
std::cout << "#V : " << n_vertices() << std::endl;
|
||||
std::cout << "#E : " << n_edges() << std::endl;
|
||||
std::cout << "#F : " << n_faces() << std::endl;
|
||||
property_stats();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//=============================================================================
|
||||
} // namespace Kernel_OSG
|
||||
} // namespace OpenMesh
|
||||
//=============================================================================
|
||||
#endif // OPENMESH_KERNEL_OSG_PROPERTYKERNEL_HH defined
|
||||
//=============================================================================
|
||||
|
||||
393
Tools/Kernel_OSG/PropertyT.hh
Normal file
393
Tools/Kernel_OSG/PropertyT.hh
Normal file
@@ -0,0 +1,393 @@
|
||||
/*===========================================================================*\
|
||||
* *
|
||||
* OpenMesh *
|
||||
* Copyright (C) 2001-2003 by Computer Graphics Group, RWTH Aachen *
|
||||
* www.openmesh.org *
|
||||
* *
|
||||
*---------------------------------------------------------------------------*
|
||||
* *
|
||||
* License *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as published *
|
||||
* by the Free Software Foundation, version 2.1. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
|
||||
* *
|
||||
\*===========================================================================*/
|
||||
|
||||
#ifndef OPENMESH_KERNEL_OSG_PROPERTYT_HH
|
||||
#define OPENMESH_KERNEL_OSG_PROPERTYT_HH
|
||||
|
||||
|
||||
//== INCLUDES =================================================================
|
||||
|
||||
#include <OpenMesh/Core/Attributes/Attributes.hh>
|
||||
#include <OpenMesh/Core/Mesh/Kernels/Common/BaseKernel.hh>
|
||||
#include <OpenMesh/Core/Utils/GenProg.hh>
|
||||
#include <OpenMesh/Core/Utils/Property.hh>
|
||||
//
|
||||
#include <OpenSG/OSGGeometry.h>
|
||||
//
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
|
||||
//== NAMESPACES ===============================================================
|
||||
|
||||
namespace OpenMesh {
|
||||
namespace Kernel_OSG {
|
||||
|
||||
|
||||
//== CLASS DEFINITION =========================================================
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/** Property adaptor for OpenSG GeoProperties
|
||||
*
|
||||
* This class bridges the interfaces of %OpenMesh properties and
|
||||
* OpenSG GeoProperties. The PropertyKernelT uses these adaptors to
|
||||
* add all necessary property functions to the kernel, while the
|
||||
* AttribKernelT extends the kernel with the standard properites.
|
||||
* Finally the ArrayKernelT completes the kernel build with a specialized
|
||||
* version of the garbage collections since the GeoIndices require
|
||||
* special handling.
|
||||
*
|
||||
* \attention Data will be shared with a geometry core when linking
|
||||
* a mesh with a OpenSG geometry node using Kernel_OSG::bind.
|
||||
* \internal
|
||||
*/
|
||||
template <typename GeoProperty>
|
||||
class oPropertyT : public BaseProperty
|
||||
{
|
||||
public:
|
||||
|
||||
// Type of the encapsulated OpenSG Geometry Property
|
||||
typedef GeoProperty property_t;
|
||||
typedef typename property_t::PtrType property_ptr_t;
|
||||
|
||||
typedef typename property_t::StoredFieldType field_t;
|
||||
typedef typename field_t::StoredType element_t;
|
||||
typedef typename field_t::StoredType value_type;
|
||||
|
||||
public:
|
||||
|
||||
//
|
||||
oPropertyT( property_ptr_t _geo_prop,
|
||||
const std::string& _name = "<unknown>" )
|
||||
: BaseProperty(_name), data_( _geo_prop )
|
||||
{
|
||||
osg_init_check();
|
||||
}
|
||||
|
||||
//
|
||||
oPropertyT( const std::string& _name = "<unknown>" )
|
||||
: BaseProperty(_name), data_(NULL)
|
||||
{
|
||||
data_ = property_t::create();
|
||||
|
||||
// make sure data_ is not null. In that case most probably
|
||||
// osg::osgInit() hasn't been executed!
|
||||
osg_init_check();
|
||||
}
|
||||
|
||||
///
|
||||
virtual ~oPropertyT()
|
||||
{ }
|
||||
|
||||
public:
|
||||
|
||||
oPropertyT& operator = (const oPropertyT& _rhs )
|
||||
{
|
||||
// Shallow copy! Remember, data_ is a osg pointer type, and the assign
|
||||
// operator makes a shallow copy!
|
||||
data_ = _rhs.data_;
|
||||
return *this;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public: // interface BaseProperty
|
||||
|
||||
virtual void reserve(size_t _n) { data_->getField().reserve( _n ); }
|
||||
virtual void resize(size_t _n) { data_->resize( _n ); }
|
||||
virtual void push_back() { data_->resize( data_->size()+1 ); }
|
||||
virtual void swap(size_t _i0, size_t _i1)
|
||||
{ std::swap( data_->getField()[_i0], data_->getField()[_i1] ); }
|
||||
|
||||
virtual oPropertyT<property_t>* clone() const
|
||||
{
|
||||
oPropertyT<property_t> *dolly = new oPropertyT<property_t>();
|
||||
if (n_elements() > 0)
|
||||
{
|
||||
// OSGGeoProperty does not provide a deep copy
|
||||
dolly->resize(n_elements());
|
||||
element_t *begin = const_cast<element_t*>(data());
|
||||
element_t *end = begin+n_elements();
|
||||
element_t *dst = const_cast<element_t*>(dolly->data());
|
||||
std::copy( begin, end, dst );
|
||||
}
|
||||
return dolly;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
virtual void set_persistent( bool _yn )
|
||||
{
|
||||
check_and_set_persistent<element_t>(_yn);
|
||||
}
|
||||
|
||||
virtual size_t n_elements() const
|
||||
{ return data_==osg::NullFC ? UnknownSize : data_->getSize(); }
|
||||
|
||||
virtual size_t element_size() const
|
||||
{ return UnknownSize; }
|
||||
|
||||
virtual size_t store( std::ostream& _ostr, bool _swap ) const
|
||||
{ return 0; }
|
||||
|
||||
virtual size_t restore( std::istream& _istr, bool _swap )
|
||||
{ return 0; }
|
||||
|
||||
|
||||
public: // OpenSG GeoPropertyInterface compatibility
|
||||
|
||||
void clear(void) { data_->clear(); }
|
||||
|
||||
|
||||
public: // access to OpenSG GeoProperty
|
||||
|
||||
property_ptr_t& osg_ptr()
|
||||
{ return data_; }
|
||||
|
||||
const property_ptr_t& osg_ptr() const
|
||||
{ return data_; }
|
||||
|
||||
|
||||
const element_t *data() const
|
||||
{ return &( (*this)[ 0 ] ); }
|
||||
|
||||
element_t& operator[](size_t idx)
|
||||
{ return data_->getField()[ idx ]; }
|
||||
|
||||
const element_t& operator[](size_t idx) const
|
||||
{ return data_->getField()[ idx ]; }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
property_ptr_t data_;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void osg_init_check(void)
|
||||
{
|
||||
// make sure data_ is not null. In that case most probably
|
||||
// osg::osgInit() hasn't been executed!
|
||||
if ( data_ == osg::NullFC )
|
||||
throw std::logic_error("OpenSG Runtime Environment is not initialized: " \
|
||||
"Use osg::osgInit()");
|
||||
}
|
||||
|
||||
oPropertyT( const oPropertyT& );
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------- class ----
|
||||
|
||||
|
||||
// ------------------------------------------------------------ properties ----
|
||||
|
||||
/// OpenSG Vertex Properties Adaptors.
|
||||
namespace VP {
|
||||
|
||||
// ---------------------------------------- Positions
|
||||
/// \name GeoPositions
|
||||
//@{
|
||||
/// Adaptor for osg::GeoPositions
|
||||
typedef oPropertyT< osg::GeoPositions2d > GeoPositions2d;
|
||||
typedef oPropertyT< osg::GeoPositions2f > GeoPositions2f;
|
||||
typedef oPropertyT< osg::GeoPositions3d > GeoPositions3d;
|
||||
typedef oPropertyT< osg::GeoPositions3f > GeoPositions3f;
|
||||
typedef oPropertyT< osg::GeoPositions4d > GeoPositions4d;
|
||||
typedef oPropertyT< osg::GeoPositions4f > GeoPositions4f;
|
||||
//@}
|
||||
|
||||
// ---------------------------------------- Normals
|
||||
/// \name GeoNormals
|
||||
//@{
|
||||
/// Adaptor for osg::GeoNormals
|
||||
typedef oPropertyT< osg::GeoNormals3f > GeoNormals3f;
|
||||
//@}
|
||||
|
||||
// ---------------------------------------- TexCoords
|
||||
/// \name GeoTexCoords
|
||||
//@{
|
||||
/// Adaptor for osg::GeoTexCoords
|
||||
typedef oPropertyT< osg::GeoTexCoords1f > GeoTexCoords1f;
|
||||
typedef oPropertyT< osg::GeoTexCoords2f > GeoTexCoords2f;
|
||||
typedef oPropertyT< osg::GeoTexCoords3f > GeoTexCoords3f;
|
||||
//@}
|
||||
|
||||
// ---------------------------------------- Colors
|
||||
/// \name GeoColors
|
||||
//@{
|
||||
/// Adaptor for osg::GeoColors
|
||||
typedef oPropertyT< osg::GeoColors3f > GeoColors3f;
|
||||
typedef oPropertyT< osg::GeoColors3ub > GeoColors3ub;
|
||||
typedef oPropertyT< osg::GeoColors4f > GeoColors4f;
|
||||
typedef oPropertyT< osg::GeoColors4ub > GeoColors4ub;
|
||||
//@}
|
||||
|
||||
} // namespace VP
|
||||
|
||||
|
||||
/// OpenSG Face Properties Adaptors.
|
||||
namespace FP {
|
||||
|
||||
// ---------------------------------------- Types
|
||||
/// Adaptor for osg::GeoPTypesUI8
|
||||
typedef oPropertyT< osg::GeoPTypesUI8 > GeoPTypesUI8;
|
||||
|
||||
// ---------------------------------------- Lengths
|
||||
/// Adaptor for osg::GeoPLengthsUI32
|
||||
typedef oPropertyT< osg::GeoPLengthsUI32 > GeoPLengthsUI32;
|
||||
|
||||
// ---------------------------------------- Indices
|
||||
|
||||
typedef oPropertyT< osg::GeoIndicesUI32 > _GeoIndicesUI32;
|
||||
|
||||
/// Adaptor for osg::GeoIndicesUI32
|
||||
template < typename IsTriMesh >
|
||||
class GeoIndicesUI32 : public _GeoIndicesUI32
|
||||
{
|
||||
public: // ---------------------------------------- typedefs
|
||||
|
||||
typedef _GeoIndicesUI32 inherited_t;
|
||||
typedef typename inherited_t::property_ptr_t property_ptr_t;
|
||||
|
||||
public: // ---------------------------------------- ctor/dtor
|
||||
|
||||
GeoIndicesUI32( property_ptr_t _geo_prop,
|
||||
GeoPTypesUI8& _types,
|
||||
GeoPLengthsUI32& _lengths)
|
||||
: inherited_t( _geo_prop ), types_(_types), length_(_lengths)
|
||||
{ }
|
||||
|
||||
GeoIndicesUI32( GeoPTypesUI8& _types,
|
||||
GeoPLengthsUI32& _lengths)
|
||||
: inherited_t(), types_(_types), length_(_lengths)
|
||||
{ }
|
||||
|
||||
virtual ~GeoIndicesUI32()
|
||||
{ }
|
||||
|
||||
public: // ---------------------------------------- inherited
|
||||
|
||||
void swap(size_t _i0, size_t _i1) { _swap( _i0, _i1, IsTriMesh() ); }
|
||||
virtual void reserve(size_t _n) { _reserve( _n, IsTriMesh() ); }
|
||||
virtual void resize(size_t _n) { _resize( _n, IsTriMesh() ); }
|
||||
|
||||
protected: // ------------------------------------- swap
|
||||
|
||||
void _swap(size_t _i0, size_t _i1, GenProg::False )
|
||||
{
|
||||
omerr() << "Unsupported mesh type!" << std::endl;
|
||||
assert(0);
|
||||
}
|
||||
|
||||
void _swap(size_t _i0, size_t _i1, GenProg::True )
|
||||
{
|
||||
size_t j0 = _i0 + _i0 + _i0;
|
||||
size_t j1 = _i1 + _i1 + _i1;
|
||||
|
||||
inherited_t::swap( j0, j1 );
|
||||
inherited_t::swap( ++j0, ++j1 );
|
||||
inherited_t::swap( ++j0, ++j1 );
|
||||
}
|
||||
|
||||
virtual void _reserve(size_t _n, GenProg::True )
|
||||
{ inherited_t::reserve( _n + _n + _n ); }
|
||||
|
||||
virtual void _reserve(size_t _n, GenProg::False )
|
||||
{ assert( false ); }
|
||||
|
||||
virtual void _resize(size_t _n, GenProg::True )
|
||||
{ inherited_t::resize( _n + _n + _n ); }
|
||||
|
||||
virtual void _resize(size_t _n, GenProg::False )
|
||||
{ assert( false ); }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
GeoPTypesUI8 &types_;
|
||||
GeoPLengthsUI32 &length_;
|
||||
|
||||
};
|
||||
|
||||
} // namespace FP
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef DOXY_IGNORE_THIS
|
||||
|
||||
template <typename T> struct _t2vp;
|
||||
template <> struct _t2vp< osg::Pnt2f >
|
||||
{ typedef osg::GeoPositions2f type; typedef VP::GeoPositions2f prop; };
|
||||
|
||||
template <> struct _t2vp< osg::Pnt3f >
|
||||
{ typedef osg::GeoPositions3f type; typedef VP::GeoPositions3f prop; };
|
||||
|
||||
template <> struct _t2vp< osg::Pnt4f >
|
||||
{ typedef osg::GeoPositions4f type; typedef VP::GeoPositions4f prop; };
|
||||
|
||||
template <> struct _t2vp< osg::Pnt2d >
|
||||
{ typedef osg::GeoPositions2d type; typedef VP::GeoPositions2d prop; };
|
||||
template <> struct _t2vp< osg::Pnt3d >
|
||||
{ typedef osg::GeoPositions3d type; typedef VP::GeoPositions3d prop; };
|
||||
template <> struct _t2vp< osg::Pnt4d >
|
||||
{ typedef osg::GeoPositions4d type; typedef VP::GeoPositions4d prop; };
|
||||
|
||||
template <typename T> struct _t2vn;
|
||||
template <> struct _t2vn< osg::Vec3f >
|
||||
{ typedef osg::GeoNormals3f type; typedef VP::GeoNormals3f prop; };
|
||||
|
||||
template <typename T> struct _t2vc;
|
||||
template <> struct _t2vc< osg::Color3f >
|
||||
{ typedef osg::GeoColors3f type; typedef VP::GeoColors3f prop; };
|
||||
|
||||
template <> struct _t2vc< osg::Color4f >
|
||||
{ typedef osg::GeoColors4f type; typedef VP::GeoColors4f prop; };
|
||||
|
||||
template <> struct _t2vc< osg::Color3ub >
|
||||
{ typedef osg::GeoColors3ub type; typedef VP::GeoColors3ub prop; };
|
||||
|
||||
template <> struct _t2vc< osg::Color4ub >
|
||||
{ typedef osg::GeoColors4ub type; typedef VP::GeoColors3ub prop; };
|
||||
|
||||
template <typename T> struct _t2vtc;
|
||||
template <> struct _t2vtc< osg::Vec2f >
|
||||
{ typedef osg::GeoTexCoords2f type; typedef VP::GeoTexCoords2f prop; };
|
||||
|
||||
template <> struct _t2vtc< osg::Vec3f >
|
||||
{ typedef osg::GeoTexCoords3f type; typedef VP::GeoTexCoords3f prop; };
|
||||
|
||||
#endif
|
||||
|
||||
//=============================================================================
|
||||
} // namespace Kernel_OSG
|
||||
} // namespace OpenMesh
|
||||
//=============================================================================
|
||||
#endif // OPENMESH_PROPERTYT_HH defined
|
||||
//=============================================================================
|
||||
|
||||
87
Tools/Kernel_OSG/Traits.hh
Normal file
87
Tools/Kernel_OSG/Traits.hh
Normal file
@@ -0,0 +1,87 @@
|
||||
//=============================================================================
|
||||
//
|
||||
// OpenMesh
|
||||
// Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen
|
||||
// www.openmesh.org
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// License
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation, version 2.1.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $Revision: 1802 $
|
||||
// $Date: 2008-05-19 11:55:07 +0200 (Mo, 19. Mai 2008) $
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
/** \file Tools/Kernel_OSG/Traits.hh
|
||||
This file defines the default traits and some convenienve macros.
|
||||
*/
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// CLASS Traits
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef OPENMESH_KERNEL_OSG_TRAITS_HH
|
||||
#define OPENMESH_KERNEL_OSG_TRAITS_HH
|
||||
|
||||
|
||||
//== INCLUDES =================================================================
|
||||
|
||||
|
||||
#include <OpenMesh/Core/Mesh/Traits.hh>
|
||||
#include <OpenMesh/Tools/Kernel_OSG/VectorAdapter.hh>
|
||||
//
|
||||
#include <OpenSG/OSGGeometry.h>
|
||||
|
||||
//== NAMESPACES ===============================================================
|
||||
|
||||
namespace OpenMesh {
|
||||
namespace Kernel_OSG {
|
||||
|
||||
//== CLASS DEFINITION =========================================================
|
||||
|
||||
|
||||
//== CLASS DEFINITION =========================================================
|
||||
|
||||
|
||||
/** Base class for all mesh traits using the OSGArrayKernelT.
|
||||
*
|
||||
* \see The Mesh docu section on \ref mesh_type.
|
||||
* \see Traits.hh for a list of macros for traits classes.
|
||||
*/
|
||||
struct Traits : DefaultTraits
|
||||
{
|
||||
typedef osg::Pnt3f Point;
|
||||
typedef osg::Color3ub Color;
|
||||
typedef osg::Vec3f Normal;
|
||||
typedef osg::Vec2f TexCoord;
|
||||
typedef osg::Vec3f::ValueType Scalar;
|
||||
|
||||
};
|
||||
|
||||
//=============================================================================
|
||||
} // namespace Kernel_OSG
|
||||
} // namespace OpenMesh
|
||||
//=============================================================================
|
||||
#endif // OPENMESH_TRAITS_HH defined
|
||||
//=============================================================================
|
||||
|
||||
99
Tools/Kernel_OSG/TriMesh_OSGArrayKernelT.hh
Normal file
99
Tools/Kernel_OSG/TriMesh_OSGArrayKernelT.hh
Normal file
@@ -0,0 +1,99 @@
|
||||
//=============================================================================
|
||||
//
|
||||
// OpenMesh
|
||||
// Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen
|
||||
// www.openmesh.org
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// License
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation, version 2.1.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $Revision: 1802 $
|
||||
// $Date: 2008-05-19 11:55:07 +0200 (Mo, 19. Mai 2008) $
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// CLASS TriMesh_OSGArrayKernelT
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
#ifndef OPENMESH_KERNEL_OSG_TRIMESH_OSGARRAYKERNEL_HH
|
||||
#define OPENMESH_KERNEL_OSG_TRIMESH_OSGARRAYKERNEL_HH
|
||||
|
||||
|
||||
//== INCLUDES =================================================================
|
||||
|
||||
|
||||
#include <OpenMesh/Core/System/config.h>
|
||||
// --------------------
|
||||
#include <OpenMesh/Core/Mesh/TriMeshT.hh>
|
||||
#include <OpenMesh/Core/Mesh/Traits.hh>
|
||||
#include <OpenMesh/Core/Mesh/Kernels/ArrayKernel/ArrayKernelT.hh>
|
||||
#include <OpenMesh/Core/Mesh/Kernels/ArrayKernel/ArrayItems.hh>
|
||||
#include <OpenMesh/Core/Mesh/Kernels/Common/Handles.hh>
|
||||
#include <OpenMesh/Core/Mesh/Kernels/Common/FinalMeshItemsT.hh>
|
||||
// --------------------
|
||||
#include <OpenMesh/Tools/Kernel_OSG/VectorAdapter.hh>
|
||||
#include <OpenMesh/Tools/Kernel_OSG/Traits.hh>
|
||||
#include <OpenMesh/Tools/Kernel_OSG/ArrayKernelT.hh>
|
||||
// --------------------
|
||||
#include <OpenSG/OSGGeometry.h>
|
||||
|
||||
|
||||
//== NAMESPACES ===============================================================
|
||||
|
||||
|
||||
namespace OpenMesh {
|
||||
namespace Kernel_OSG {
|
||||
|
||||
//== CLASS DEFINITION =========================================================
|
||||
|
||||
|
||||
/// Helper class to create a TriMesh-type based on Kernel_OSG::ArrayKernelT
|
||||
template <class Traits>
|
||||
struct TriMesh_OSGArrayKernel_GeneratorT
|
||||
{
|
||||
typedef FinalMeshItemsT<ArrayItems, Traits, true> MeshItems;
|
||||
typedef AttribKernelT<MeshItems> AttribKernel;
|
||||
typedef ArrayKernelT<AttribKernel, MeshItems> MeshKernel;
|
||||
typedef TriMeshT<MeshKernel> Mesh;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** \ingroup mesh_types_group
|
||||
Triangle mesh based on the Kernel_OSG::ArrayKernelT.
|
||||
\see OpenMesh::TriMeshT
|
||||
\see OpenMesh::ArrayKernelT
|
||||
*/
|
||||
template <class Traits = Kernel_OSG::Traits>
|
||||
class TriMesh_OSGArrayKernelT
|
||||
: public TriMesh_OSGArrayKernel_GeneratorT<Traits>::Mesh
|
||||
{};
|
||||
|
||||
|
||||
//=============================================================================
|
||||
} // namespace Kernel_OSG
|
||||
} // namespace OpenMesh
|
||||
//=============================================================================
|
||||
#endif // OPENMESH_KERNEL_OSG_TRIMESH_OSGARRAYKERNEL_HH
|
||||
//=============================================================================
|
||||
182
Tools/Kernel_OSG/VectorAdapter.hh
Normal file
182
Tools/Kernel_OSG/VectorAdapter.hh
Normal file
@@ -0,0 +1,182 @@
|
||||
/*===========================================================================*\
|
||||
* *
|
||||
* OpenMesh *
|
||||
* Copyright (C) 2001-2003 by Computer Graphics Group, RWTH Aachen *
|
||||
* www.openmesh.org *
|
||||
* *
|
||||
*---------------------------------------------------------------------------*
|
||||
* *
|
||||
* License *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as published *
|
||||
* by the Free Software Foundation, version 2.1. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
|
||||
* *
|
||||
\*===========================================================================*/
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef OPENMESH_KERNEL_OSG_VECTORADAPTER_HH
|
||||
#define OPENMESH_KERNEL_OSG_VECTORADAPTER_HH
|
||||
|
||||
|
||||
//== INCLUDES =================================================================
|
||||
|
||||
#include <OpenSG/OSGGeometry.h>
|
||||
#include <OpenMesh/Core/Utils/vector_cast.hh>
|
||||
|
||||
//== NAMESPACES ===============================================================
|
||||
|
||||
namespace OpenMesh {
|
||||
|
||||
//== CLASS DEFINITION =========================================================
|
||||
|
||||
// ----------------------------------------------------------------- class ----
|
||||
|
||||
#define OSG_VECTOR_TRAITS( VecType ) \
|
||||
template <> struct vector_traits< VecType > { \
|
||||
typedef VecType vector_type; \
|
||||
typedef vector_type::ValueType value_type; \
|
||||
typedef GenProg::Int2Type< vector_type::_iSize > typed_size; \
|
||||
\
|
||||
static const size_t size_ = vector_type::_iSize; \
|
||||
static size_t size() { return size_; } \
|
||||
}
|
||||
|
||||
/// Vector traits for OpenSG vector type
|
||||
OSG_VECTOR_TRAITS( osg::Pnt4f );
|
||||
/// Vector traits for OpenSG vector type
|
||||
OSG_VECTOR_TRAITS( osg::Pnt3f );
|
||||
/// Vector traits for OpenSG vector type
|
||||
OSG_VECTOR_TRAITS( osg::Pnt2f );
|
||||
|
||||
/// Vector traits for OpenSG vector type
|
||||
OSG_VECTOR_TRAITS( osg::Vec4f );
|
||||
/// Vector traits for OpenSG vector type
|
||||
OSG_VECTOR_TRAITS( osg::Vec3f );
|
||||
/// Vector traits for OpenSG vector type
|
||||
OSG_VECTOR_TRAITS( osg::Vec2f );
|
||||
|
||||
/// Vector traits for OpenSG vector type
|
||||
OSG_VECTOR_TRAITS( osg::Pnt4d );
|
||||
/// Vector traits for OpenSG vector type
|
||||
OSG_VECTOR_TRAITS( osg::Pnt3d );
|
||||
/// Vector traits for OpenSG vector type
|
||||
OSG_VECTOR_TRAITS( osg::Pnt2d );
|
||||
|
||||
/// Vector traits for OpenSG vector type
|
||||
OSG_VECTOR_TRAITS( osg::Vec4d );
|
||||
/// Vector traits for OpenSG vector type
|
||||
OSG_VECTOR_TRAITS( osg::Vec3d );
|
||||
|
||||
/// Vector traits for OpenSG vector type
|
||||
OSG_VECTOR_TRAITS( osg::Vec4ub );
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#define OSG_COLOR_TRAITS( VecType, N ) \
|
||||
template <> struct vector_traits< VecType > { \
|
||||
typedef VecType vector_type; \
|
||||
typedef vector_type::ValueType value_type; \
|
||||
typedef GenProg::Int2Type< N > typed_size; \
|
||||
\
|
||||
static const size_t size_ = N; \
|
||||
static size_t size() { return size_; } \
|
||||
}
|
||||
|
||||
|
||||
/// Vector traits for OpenSG color type
|
||||
OSG_COLOR_TRAITS( osg::Color3ub, 3 );
|
||||
/// Vector traits for OpenSG color type
|
||||
OSG_COLOR_TRAITS( osg::Color4ub, 4 );
|
||||
/// Vector traits for OpenSG color type
|
||||
OSG_COLOR_TRAITS( osg::Color3f, 3 );
|
||||
/// Vector traits for OpenSG color type
|
||||
OSG_COLOR_TRAITS( osg::Color4f, 4 );
|
||||
|
||||
#undef OSG_VECTOR_TRAITS
|
||||
|
||||
|
||||
// ----------------------------------------
|
||||
#if 1
|
||||
#define PNT2VEC_CASTER( DST, SRC ) \
|
||||
template <> struct vector_caster< DST, SRC > { \
|
||||
typedef DST dst_t; \
|
||||
typedef SRC src_t; \
|
||||
typedef const dst_t& return_type; \
|
||||
inline static return_type cast( const src_t& _src ) {\
|
||||
return _src.subZero(); \
|
||||
} \
|
||||
}
|
||||
|
||||
/// convert Pnt3f to Vec3f
|
||||
PNT2VEC_CASTER( osg::Vec3f, osg::Pnt3f );
|
||||
|
||||
/// convert Pnt4f to Vec4f
|
||||
PNT2VEC_CASTER( osg::Vec4f, osg::Pnt4f );
|
||||
|
||||
/// convert Pnt3d to Vec3d
|
||||
PNT2VEC_CASTER( osg::Vec3d, osg::Pnt3d );
|
||||
|
||||
/// convert Pnt4d to Vec4d
|
||||
PNT2VEC_CASTER( osg::Vec4d, osg::Pnt4d );
|
||||
|
||||
#undef PNT2VEC
|
||||
#else
|
||||
|
||||
template <>
|
||||
struct vector_caster< osg::Vec3f, osg::Pnt3f >
|
||||
{
|
||||
typedef osg::Vec3f dst_t;
|
||||
typedef osg::Pnt3f src_t;
|
||||
|
||||
typedef const dst_t& return_type;
|
||||
inline static return_type cast( const src_t& _src )
|
||||
{
|
||||
std::cout << "casting Pnt3f to Vec3f\n";
|
||||
return _src.subZero();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
// ----------------------------------------
|
||||
|
||||
//@{
|
||||
/// Adapter for osg vector member computing a scalar product
|
||||
inline
|
||||
osg::Vec3f::ValueType dot( const osg::Vec3f &_v1, const osg::Vec3f &_v2 )
|
||||
{ return _v1.dot(_v2); }
|
||||
|
||||
|
||||
inline
|
||||
osg::Vec3f::ValueType dot( const osg::Vec3f &_v1, const osg::Pnt3f &_v2 )
|
||||
{ return _v1.dot(_v2); }
|
||||
|
||||
|
||||
inline
|
||||
osg::Vec2f::ValueType dot( const osg::Vec2f &_v1, const osg::Vec2f &_v2 )
|
||||
{ return _v1.dot(_v2); }
|
||||
|
||||
|
||||
inline
|
||||
osg::Vec3f cross( const osg::Vec3f &_v1, const osg::Vec3f &_v2 )
|
||||
{ return _v1.cross(_v2); }
|
||||
//@}
|
||||
|
||||
//=============================================================================
|
||||
} // namespace OpenMesh
|
||||
//=============================================================================
|
||||
#endif // OPENMESH_VECTORADAPTER_HH defined
|
||||
//=============================================================================
|
||||
|
||||
301
Tools/Kernel_OSG/bindT.hh
Normal file
301
Tools/Kernel_OSG/bindT.hh
Normal file
@@ -0,0 +1,301 @@
|
||||
//=============================================================================
|
||||
//
|
||||
// OpenMesh
|
||||
// Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen
|
||||
// www.openmesh.org
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// License
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation, version 2.1.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $Revision: 1802 $
|
||||
// $Date: 2008-05-19 11:55:07 +0200 (Mo, 19. Mai 2008) $
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
|
||||
/** \file bindT.hh
|
||||
|
||||
Bind an OpenMesh to a OpenSG geometry node. Be aware that due to
|
||||
this link the geometry node maybe modified. For instance triangle
|
||||
strips are converted to regular triangles.
|
||||
*/
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// CLASS Traits
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef OPENMESH_KERNEL_OSG_BINDT_HH
|
||||
#define OPENMESH_KERNEL_OSG_BINDT_HH
|
||||
|
||||
|
||||
//== INCLUDES =================================================================
|
||||
|
||||
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
//
|
||||
#include <OpenMesh/Core/Mesh/TriMeshT.hh>
|
||||
#include <OpenMesh/Core/Utils/color_cast.hh>
|
||||
#include <OpenMesh/Tools/Utils/GLConstAsString.hh>
|
||||
#include <OpenSG/OSGGeometry.h>
|
||||
//
|
||||
#include "color_cast.hh"
|
||||
|
||||
//== NAMESPACES ===============================================================
|
||||
|
||||
namespace OpenMesh {
|
||||
namespace Kernel_OSG {
|
||||
|
||||
|
||||
//== CLASS DEFINITION =========================================================
|
||||
|
||||
inline
|
||||
bool type_is_valid( unsigned char _t )
|
||||
{
|
||||
return _t == GL_TRIANGLES
|
||||
|| _t == GL_TRIANGLE_STRIP
|
||||
|| _t == GL_QUADS
|
||||
|| _t == GL_POLYGON;
|
||||
}
|
||||
|
||||
|
||||
/** Bind a OpenSG geometry to a mesh.
|
||||
*
|
||||
* \param _mesh The mesh object to bind the geometry to.
|
||||
* \param _geo The geometry object to bind.
|
||||
* \return true if the connection has been established else false.
|
||||
*/
|
||||
template < typename Mesh > inline
|
||||
bool bind( osg::GeometryPtr& _geo, Mesh& _mesh )
|
||||
{
|
||||
_geo = _mesh.createGeometryPtr();
|
||||
}
|
||||
|
||||
/** Bind a mesh object to geometry. The binder is able to handle
|
||||
* non-indexed and indexed geometry. Multi-indexed geometry is not
|
||||
* supported.
|
||||
*
|
||||
* \param _mesh The mesh object to bind.
|
||||
* \param _geo The geometry object to bind to.
|
||||
* \return true if the connection has been established else false.
|
||||
*/
|
||||
template < typename Mesh > inline
|
||||
bool bind( Mesh& _mesh, osg::GeometryPtr& _geo )
|
||||
{
|
||||
using namespace OpenMesh;
|
||||
using namespace osg;
|
||||
using namespace std;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
// pre-check if types are supported
|
||||
|
||||
GeoPTypesPtr types = _geo->getTypes();
|
||||
|
||||
if ( (size_t)count_if( types->getData(), types->getData()+types->size(),
|
||||
ptr_fun(type_is_valid) ) != (size_t)types->size() )
|
||||
return false;
|
||||
|
||||
// pre-check if it is a multi-indexed geometry, which is not supported!
|
||||
|
||||
if ( _geo->getIndexMapping().getSize() > 1 )
|
||||
{
|
||||
omerr << "OpenMesh::Kernel_OSG::bind(): Multi-indexed geometry is not supported!\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// create shortcuts
|
||||
|
||||
GeoPLengthsPtr lengths = _geo->getLengths();
|
||||
GeoIndicesPtr indices = _geo->getIndices();
|
||||
GeoPositionsPtr pos = _geo->getPositions();
|
||||
GeoNormalsPtr normals = _geo->getNormals();
|
||||
GeoColorsPtr colors = _geo->getColors();
|
||||
|
||||
|
||||
// -------------------- now convert everything to polygon/triangles
|
||||
|
||||
size_t tidx, bidx; // types; base index into indices
|
||||
vector< VertexHandle > vhandles;
|
||||
|
||||
// ---------- initialize geometry
|
||||
|
||||
{
|
||||
VertexHandle vh;
|
||||
typedef typename Mesh::Color color_t;
|
||||
|
||||
bool bind_normal = (normals!=NullFC) && _mesh.has_vertex_normals();
|
||||
bool bind_color = (colors !=NullFC) && _mesh.has_vertex_colors();
|
||||
|
||||
for (bidx=0; bidx < pos->size(); ++bidx)
|
||||
{
|
||||
vh = _mesh.add_vertex( pos->getValue(bidx) );
|
||||
if ( bind_normal )
|
||||
_mesh.set_normal(vh, normals->getValue(bidx));
|
||||
if ( bind_color )
|
||||
_mesh.set_color(vh, color_cast<color_t>(colors->getValue(bidx)));
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- create topology
|
||||
|
||||
FaceHandle fh;
|
||||
|
||||
size_t max_bidx = indices != NullFC ? indices->size() : pos->size();
|
||||
|
||||
for (bidx=tidx=0; ok && tidx<types->size() && bidx < max_bidx; ++tidx)
|
||||
{
|
||||
switch( types->getValue(tidx) )
|
||||
{
|
||||
case GL_TRIANGLES:
|
||||
vhandles.resize(3);
|
||||
for(size_t lidx=0; lidx < lengths->getValue(tidx)-2; lidx+=3)
|
||||
{
|
||||
if (indices == NullFC ) {
|
||||
vhandles[0] = VertexHandle(bidx+lidx);
|
||||
vhandles[1] = VertexHandle(bidx+lidx+1);
|
||||
vhandles[2] = VertexHandle(bidx+lidx+2);
|
||||
}
|
||||
else {
|
||||
vhandles[0] = VertexHandle(indices->getValue(bidx+lidx ) );
|
||||
vhandles[1] = VertexHandle(indices->getValue(bidx+lidx+1) );
|
||||
vhandles[2] = VertexHandle(indices->getValue(bidx+lidx+2) );
|
||||
}
|
||||
|
||||
if ( !(fh = _mesh.add_face( vhandles )).is_valid() )
|
||||
{
|
||||
// if fh is complex try swapped order
|
||||
swap(vhandles[2], vhandles[1]);
|
||||
fh = _mesh.add_face( vhandles );
|
||||
}
|
||||
ok = fh.is_valid();
|
||||
}
|
||||
break;
|
||||
|
||||
case GL_TRIANGLE_STRIP:
|
||||
vhandles.resize(3);
|
||||
for (size_t lidx=0; lidx < lengths->getValue(tidx)-2; ++lidx)
|
||||
{
|
||||
if (indices == NullFC ) {
|
||||
vhandles[0] = VertexHandle(bidx+lidx);
|
||||
vhandles[1] = VertexHandle(bidx+lidx+1);
|
||||
vhandles[2] = VertexHandle(bidx+lidx+2);
|
||||
}
|
||||
else {
|
||||
vhandles[0] = VertexHandle(indices->getValue(bidx+lidx ) );
|
||||
vhandles[1] = VertexHandle(indices->getValue(bidx+lidx+1) );
|
||||
vhandles[2] = VertexHandle(indices->getValue(bidx+lidx+2) );
|
||||
}
|
||||
|
||||
if (vhandles[0]!=vhandles[2] &&
|
||||
vhandles[0]!=vhandles[1] &&
|
||||
vhandles[1]!=vhandles[2])
|
||||
{
|
||||
// if fh is complex try swapped order
|
||||
bool swapped(false);
|
||||
|
||||
if (lidx % 2) // odd numbered triplet must be reordered
|
||||
swap(vhandles[2], vhandles[1]);
|
||||
|
||||
if ( !(fh = _mesh.add_face( vhandles )).is_valid() )
|
||||
{
|
||||
omlog << "OpenMesh::Kernel_OSG::bind(): complex entity!\n";
|
||||
|
||||
swap(vhandles[2], vhandles[1]);
|
||||
fh = _mesh.add_face( vhandles );
|
||||
swapped = true;
|
||||
}
|
||||
ok = fh.is_valid();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GL_QUADS:
|
||||
vhandles.resize(4);
|
||||
for(size_t nf=_mesh.n_faces(), lidx=0;
|
||||
lidx < lengths->getValue(tidx)-3; lidx+=4)
|
||||
{
|
||||
if (indices == NullFC ) {
|
||||
vhandles[0] = VertexHandle(bidx+lidx);
|
||||
vhandles[1] = VertexHandle(bidx+lidx+1);
|
||||
vhandles[2] = VertexHandle(bidx+lidx+2);
|
||||
vhandles[3] = VertexHandle(bidx+lidx+3);
|
||||
}
|
||||
else {
|
||||
vhandles[0] = VertexHandle(indices->getValue(bidx+lidx ) );
|
||||
vhandles[1] = VertexHandle(indices->getValue(bidx+lidx+1) );
|
||||
vhandles[2] = VertexHandle(indices->getValue(bidx+lidx+2) );
|
||||
vhandles[3] = VertexHandle(indices->getValue(bidx+lidx+3) );
|
||||
}
|
||||
|
||||
fh = _mesh.add_face( vhandles );
|
||||
ok = ( Mesh::Face::is_triangle() && (_mesh.n_faces()==(nf+2)))
|
||||
|| fh.is_valid();
|
||||
nf = _mesh.n_faces();
|
||||
}
|
||||
break;
|
||||
|
||||
case GL_POLYGON:
|
||||
{
|
||||
size_t ne = lengths->getValue(tidx);
|
||||
size_t nf = _mesh.n_faces();
|
||||
|
||||
vhandles.resize(ne);
|
||||
|
||||
for(size_t lidx=0; lidx < ne; ++lidx)
|
||||
vhandles[lidx] = (indices == NullFC)
|
||||
? VertexHandle(bidx+lidx)
|
||||
: VertexHandle(indices->getValue(bidx+lidx) );
|
||||
|
||||
fh = _mesh.add_face( vhandles );
|
||||
ok = ( Mesh::Face::is_triangle() && (_mesh.n_faces()==nf+ne-2) )
|
||||
|| fh.is_valid();
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
cerr << "Warning! Skipping unsupported type "
|
||||
<< types->getValue(tidx) << " '"
|
||||
<< Utils::GLenum_as_string( types->getValue(tidx) ) << "'\n";
|
||||
}
|
||||
|
||||
// update base index into indices for next face type
|
||||
bidx += lengths->getValue(tidx);
|
||||
}
|
||||
|
||||
if (ok)
|
||||
ok=_mesh.bind(_geo);
|
||||
else
|
||||
_mesh.clear();
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
} // namespace Kernel_OSG
|
||||
} // namespace OpenMesh
|
||||
//=============================================================================
|
||||
#endif // OPENMESH_KERNEL_OSG_BINDT_HH defined
|
||||
//=============================================================================
|
||||
|
||||
43
Tools/Kernel_OSG/color_cast.hh
Normal file
43
Tools/Kernel_OSG/color_cast.hh
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef OPENMESH_KERNEL_OSG_COLOR_CAST_HH
|
||||
#define OPENMESH_KERNEL_OSG_COLOR_CAST_HH
|
||||
|
||||
#include <algorithm>
|
||||
#include <OpenMesh/Core/Utils/color_cast.hh>
|
||||
#include <OpenSG/OSGGeometry.h>
|
||||
|
||||
namespace OpenMesh {
|
||||
|
||||
/// Helper struct
|
||||
/// \internal
|
||||
template <>
|
||||
struct color_caster<osg::Color3ub,osg::Color3f>
|
||||
{
|
||||
typedef osg::Color3ub return_type;
|
||||
typedef unsigned char ub;
|
||||
|
||||
inline static return_type cast(const osg::Color3f& _src)
|
||||
{
|
||||
return return_type( (ub)std::min((_src[0]* 255.0f + 0.5f),255.0f),
|
||||
(ub)std::min((_src[1]* 255.0f + 0.5f),255.0f),
|
||||
(ub)std::min((_src[2]* 255.0f + 0.5f),255.0f) );
|
||||
}
|
||||
};
|
||||
|
||||
/// Helper struct
|
||||
/// \internal
|
||||
template <>
|
||||
struct color_caster<osg::Color3f,osg::Color3ub>
|
||||
{
|
||||
typedef osg::Color3f return_type;
|
||||
|
||||
inline static return_type cast(const osg::Color3ub& _src)
|
||||
{
|
||||
return return_type( (float)(_src[0] / 255.0f ),
|
||||
(float)(_src[1] / 255.0f ),
|
||||
(float)(_src[2] / 255.0f ) );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace OpenMesh
|
||||
|
||||
#endif // OPENMESH_KERNEL_OSG_COLOR_CAST_HH
|
||||
Reference in New Issue
Block a user