VR-Forces 4.0.4 Class Documentation
include/makOsgShadowFX/ConvexPolyhedron.h
Go to the documentation of this file.
00001 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 
00002  *
00003  * This library is open source and may be redistributed and/or modified under  
00004  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
00005  * (at your option) any later version.  The full license is in LICENSE file
00006  * included with this distribution, and on the openscenegraph.org website.
00007  * 
00008  * This library is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
00011  * OpenSceneGraph Public License for more details.
00012  *
00013  * ViewDependentShadow codes Copyright (C) 2008 Wojciech Lewandowski
00014  * Thanks to to my company http://www.ai.com.pl for allowing me free this work.
00015 */
00016 
00017 #ifndef OSGSHADOW_CONVEXPOLYHEDRON
00018 #define OSGSHADOW_CONVEXPOLYHEDRON 1
00019 
00020 #include <osg/Geometry>
00021 #include <osg/Polytope>
00022 
00024 // Class based on CustomPolytope defined and used in osgSim::OverlayNode.cpp.
00025 // Honors should go to Robert Osfield for writing such useful piece of code.
00026 // First incarnations of my ConvexPolyhedron were derived from CustomPolytope.
00027 // Later I made a number of modifications aimed at improving convex hull 
00028 // precision of intersection & extrusion operations and ended up with code 
00029 // so mixed that I decided to rewrite it as separate class.
00031 
00032 namespace makOsgShadowFX
00033 {
00034 
00035 class ConvexPolyhedron
00036 {
00037     public:
00038         typedef std::vector<osg::Vec3d> Vertices;
00039 
00040         static const osg::Matrix & defaultMatrix;
00041 
00042         struct Face
00043         {
00044             std::string name;
00045             osg::Plane  plane;
00046             Vertices    vertices;
00047         };
00048 
00049         typedef std::list<Face> Faces;
00050         Faces _faces;
00051 
00052         ConvexPolyhedron( void ) { }
00053 
00054         ConvexPolyhedron( const osg::Matrix& matrix, const osg::Matrix& inverse,
00055             const osg::BoundingBox& bb = osg::BoundingBox(-1,-1,-1,1,1,1));
00056 
00057         Face& createFace() { _faces.push_back(Face()); return _faces.back(); }
00058         void clear()       { _faces.clear(); }
00059 
00060 
00061         void setToUnitFrustum(bool withNear=true, bool withFar=true);
00062         void setToBoundingBox(const osg::BoundingBox& bb);
00063         void transform(const osg::Matrix& matrix, const osg::Matrix& inverse);
00064         void transformClip(const osg::Matrix& matrix, const osg::Matrix& inverse);
00065 
00066 
00067         bool mergeFaces
00068             ( const Face & face0, const Face & face1, Face & face );
00069 
00070         void mergeCoplanarFaces( const double & plane_normal_dot_tolerance = 0.0, 
00071             const double & plane_distance_tolerance = 0.0 );
00072 
00073         void removeDuplicateVertices( void );
00074 
00075 
00076         static int pointsColinear
00077             ( const osg::Vec3d & va, const osg::Vec3d & vb, const osg::Vec3d & vc,
00078             const double & edge_normal_dot_tolerance = 0.0, 
00079             const double & null_edge_length_tolerance = 0.0 );
00080 
00081         static int isFacePolygonConvex( Face & face, bool ignoreCollinearVertices = true );
00082 
00083         bool checkCoherency
00084             ( bool checkForNonConvexPolys = false, const char * errorPrefix = NULL );
00085 
00086 
00087         void cut(const osg::Polytope& polytope);
00088 
00089         void cut(const ConvexPolyhedron& polytope);
00090 
00091         void cut(const osg::Plane& plane, const std::string& name=std::string());
00092 
00093         void extrude( const osg::Vec3d & offset );
00094 
00095         void translate( const osg::Vec3d & offset );
00096 
00097 
00098         void getPolytope(osg::Polytope& polytope) const;
00099         void getPoints(Vertices& vertices) const;
00100         osg::BoundingBox computeBoundingBox( const osg::Matrix & m = makOsgShadowFX::ConvexPolyhedron::defaultMatrix ) const;
00101 
00102         osg::Geometry* buildGeometry( const osg::Vec4d& colorOutline,
00103             const osg::Vec4d& colorInside,
00104             osg::Geometry* useGeometry = NULL ) const;
00105 
00106 
00107         bool dumpGeometry( const Face * face = NULL,
00108             const osg::Plane * plane = NULL,
00109             ConvexPolyhedron * basehull = NULL,
00110             const char * filename = "convexpolyhedron.osg",
00111             const osg::Vec4d& colorOutline = osg::Vec4( 0,1,0,0.5 ),
00112             const osg::Vec4d& colorInside  = osg::Vec4( 0,1,0,0.25 ),
00113             const osg::Vec4d& faceColorOutline = osg::Vec4( 0,0,1,0.5 ),
00114             const osg::Vec4d& faceColorInside  = osg::Vec4( 0,0,1,0.25 ),
00115             const osg::Vec4d& planeColorOutline = osg::Vec4( 1,0,0,0.5 ),
00116             const osg::Vec4d& planeColorInside  = osg::Vec4( 1,0,0,0.25 ),
00117             const osg::Vec4d& baseColorOutline = osg::Vec4( 0,0,0,0.5 ),
00118             const osg::Vec4d& baseColorInside  = osg::Vec4( 0,0,0,0.25 ) ) const;
00119 };
00120 
00121 } //makOsgShadowFX::
00122 
00123 #endif

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)