ConvexPolyhedron
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* 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
* OpenSceneGraph Public License for more details.
*
* ViewDependentShadow codes Copyright (C) 2008 Wojciech Lewandowski
* Thanks to to my company http://www.ai.com.pl for allowing me free this work.
*/
#ifndef OSGSHADOW_CONVEXPOLYHEDRON
#define OSGSHADOW_CONVEXPOLYHEDRON 1
#include <osg/Geometry>
#include <osg/Polytope>
#include <osgShadow/Export>
// Class based on CustomPolytope defined and used in osgSim::OverlayNode.cpp.
// Honors should go to Robert Osfield for writing such useful piece of code.
// First incarnations of my ConvexPolyhedron were derived from CustomPolytope.
// Later I made a number of modifications aimed at improving convex hull
// precision of intersection & extrusion operations and ended up with code
// so mixed that I decided to rewrite it as separate class.
namespace osgShadow {
class OSGSHADOW_EXPORT ConvexPolyhedron
{
public:
typedef std::vector<osg::Vec3d> Vertices;
static const osg::Matrix & defaultMatrix;
struct Face
{
std::string name;
osg::Plane plane;
Vertices vertices;
};
typedef std::list<Face> Faces;
Faces _faces;
ConvexPolyhedron( void ) { }
ConvexPolyhedron( const osg::Matrix& matrix, const osg::Matrix& inverse,
const osg::BoundingBox& bb = osg::BoundingBox(-1,-1,-1,1,1,1));
Face& createFace() { _faces.push_back(Face()); return _faces.back(); }
void clear() { _faces.clear(); }
void setToUnitFrustum(bool withNear=true, bool withFar=true);
void setToBoundingBox(const osg::BoundingBox& bb);
void transform(const osg::Matrix& matrix, const osg::Matrix& inverse);
void transformClip(const osg::Matrix& matrix, const osg::Matrix& inverse);
bool mergeFaces
( const Face & face0, const Face & face1, Face & face );
void mergeCoplanarFaces( const double & plane_normal_dot_tolerance = 0.0,
const double & plane_distance_tolerance = 0.0 );
void removeDuplicateVertices( void );
static int pointsColinear
( const osg::Vec3d & va, const osg::Vec3d & vb, const osg::Vec3d & vc,
const double & edge_normal_dot_tolerance = 0.0,
const double & null_edge_length_tolerance = 0.0 );
static int isFacePolygonConvex( Face & face, bool ignoreCollinearVertices = true );
bool checkCoherency
( bool checkForNonConvexPolys = false, const char * errorPrefix = NULL );
void cut(const osg::Polytope& polytope);
void cut(const ConvexPolyhedron& polytope);
void cut(const osg::Plane& plane, const std::string& name=std::string());
void extrude( const osg::Vec3d & offset );
void translate( const osg::Vec3d & offset );
void getPolytope(osg::Polytope& polytope) const;
void getPoints(Vertices& vertices) const;
osg::BoundingBox computeBoundingBox( const osg::Matrix & m = osgShadow::ConvexPolyhedron::defaultMatrix ) const;
osg::Geometry* buildGeometry( const osg::Vec4d& colorOutline,
const osg::Vec4d& colorInside,
osg::Geometry* useGeometry = NULL ) const;
bool dumpGeometry( const Face * face = NULL,
const osg::Plane * plane = NULL,
ConvexPolyhedron * basehull = NULL,
const char * filename = "convexpolyhedron.osg",
const osg::Vec4d& colorOutline = osg::Vec4( 0,1,0,0.5 ),
const osg::Vec4d& colorInside = osg::Vec4( 0,1,0,0.25 ),
const osg::Vec4d& faceColorOutline = osg::Vec4( 0,0,1,0.5 ),
const osg::Vec4d& faceColorInside = osg::Vec4( 0,0,1,0.25 ),
const osg::Vec4d& planeColorOutline = osg::Vec4( 1,0,0,0.5 ),
const osg::Vec4d& planeColorInside = osg::Vec4( 1,0,0,0.25 ),
const osg::Vec4d& baseColorOutline = osg::Vec4( 0,0,0,0.5 ),
const osg::Vec4d& baseColorInside = osg::Vec4( 0,0,0,0.25 ) ) const;
};
} // namespace osgShadow
#endif
Geometry
Polytope
osgShadow::ConvexPolyhedron::_faces
Faces _faces
Definition ConvexPolyhedron:50
osgShadow::ConvexPolyhedron::translate
void translate(const osg::Vec3d &offset)
osgShadow::ConvexPolyhedron::isFacePolygonConvex
static int isFacePolygonConvex(Face &face, bool ignoreCollinearVertices=true)
osgShadow::ConvexPolyhedron::checkCoherency
bool checkCoherency(bool checkForNonConvexPolys=false, const char *errorPrefix=NULL)
osgShadow::ConvexPolyhedron::getPoints
void getPoints(Vertices &vertices) const
osgShadow::ConvexPolyhedron::cut
void cut(const ConvexPolyhedron &polytope)
osgShadow::ConvexPolyhedron::removeDuplicateVertices
void removeDuplicateVertices(void)
osgShadow::ConvexPolyhedron::ConvexPolyhedron
ConvexPolyhedron(const osg::Matrix &matrix, const osg::Matrix &inverse, const osg::BoundingBox &bb=osg::BoundingBox(-1,-1,-1, 1, 1, 1))
osgShadow::ConvexPolyhedron::createFace
Face & createFace()
Definition ConvexPolyhedron:57
osgShadow::ConvexPolyhedron::defaultMatrix
static const osg::Matrix & defaultMatrix
Definition ConvexPolyhedron:40
osgShadow::ConvexPolyhedron::pointsColinear
static int pointsColinear(const osg::Vec3d &va, const osg::Vec3d &vb, const osg::Vec3d &vc, const double &edge_normal_dot_tolerance=0.0, const double &null_edge_length_tolerance=0.0)
osgShadow::ConvexPolyhedron::buildGeometry
osg::Geometry * buildGeometry(const osg::Vec4d &colorOutline, const osg::Vec4d &colorInside, osg::Geometry *useGeometry=NULL) const
osgShadow::ConvexPolyhedron::mergeFaces
bool mergeFaces(const Face &face0, const Face &face1, Face &face)
osgShadow::ConvexPolyhedron::mergeCoplanarFaces
void mergeCoplanarFaces(const double &plane_normal_dot_tolerance=0.0, const double &plane_distance_tolerance=0.0)
osgShadow::ConvexPolyhedron::transform
void transform(const osg::Matrix &matrix, const osg::Matrix &inverse)
osgShadow::ConvexPolyhedron::clear
void clear()
Definition ConvexPolyhedron:58
osgShadow::ConvexPolyhedron::computeBoundingBox
osg::BoundingBox computeBoundingBox(const osg::Matrix &m=osgShadow::ConvexPolyhedron::defaultMatrix) const
osgShadow::ConvexPolyhedron::transformClip
void transformClip(const osg::Matrix &matrix, const osg::Matrix &inverse)
osgShadow::ConvexPolyhedron::setToBoundingBox
void setToBoundingBox(const osg::BoundingBox &bb)
osgShadow::ConvexPolyhedron::getPolytope
void getPolytope(osg::Polytope &polytope) const
osgShadow::ConvexPolyhedron::Faces
std::list< Face > Faces
Definition ConvexPolyhedron:49
osgShadow::ConvexPolyhedron::Vertices
std::vector< osg::Vec3d > Vertices
Definition ConvexPolyhedron:38
osgShadow::ConvexPolyhedron::setToUnitFrustum
void setToUnitFrustum(bool withNear=true, bool withFar=true)
osgShadow::ConvexPolyhedron::dumpGeometry
bool dumpGeometry(const Face *face=NULL, const osg::Plane *plane=NULL, ConvexPolyhedron *basehull=NULL, const char *filename="convexpolyhedron.osg", const osg::Vec4d &colorOutline=osg::Vec4(0, 1, 0, 0.5), const osg::Vec4d &colorInside=osg::Vec4(0, 1, 0, 0.25), const osg::Vec4d &faceColorOutline=osg::Vec4(0, 0, 1, 0.5), const osg::Vec4d &faceColorInside=osg::Vec4(0, 0, 1, 0.25), const osg::Vec4d &planeColorOutline=osg::Vec4(1, 0, 0, 0.5), const osg::Vec4d &planeColorInside=osg::Vec4(1, 0, 0, 0.25), const osg::Vec4d &baseColorOutline=osg::Vec4(0, 0, 0, 0.5), const osg::Vec4d &baseColorInside=osg::Vec4(0, 0, 0, 0.25)) const
osgShadow::ConvexPolyhedron::extrude
void extrude(const osg::Vec3d &offset)
osgShadow::ConvexPolyhedron::cut
void cut(const osg::Polytope &polytope)
osgShadow::ConvexPolyhedron::ConvexPolyhedron
ConvexPolyhedron(void)
Definition ConvexPolyhedron:52
osgShadow::ConvexPolyhedron::cut
void cut(const osg::Plane &plane, const std::string &name=std::string())
osg::Geometry
Definition Geometry:31
osg::Plane
A plane class. It can be used to represent an infinite plane.
Definition Plane:34
osg::Polytope
Definition Polytope:26
osg::Vec3d
Definition Vec3d:30
osg::Vec4d
Definition Vec4d:29
osgShadow
Definition ConvexPolyhedron:33
osg::BoundingBox
BoundingBoxd BoundingBox
Definition BoundingBox:257
osg::Matrix
Matrixd Matrix
Definition Matrix:27
osg::Vec4
Vec4f Vec4
Definition Vec4:21
Export
OSGSHADOW_EXPORT
#define OSGSHADOW_EXPORT
Definition osgShadow/Export:39
NULL
#define NULL
Definition osg/Export:55
osgShadow::ConvexPolyhedron::Face
Definition ConvexPolyhedron:43
osgShadow::ConvexPolyhedron::Face::plane
osg::Plane plane
Definition ConvexPolyhedron:45
osgShadow::ConvexPolyhedron::Face::name
std::string name
Definition ConvexPolyhedron:44
osgShadow::ConvexPolyhedron::Face::vertices
Vertices vertices
Definition ConvexPolyhedron:46