OpenSceneGraph 3.6.5
ConvexPolyhedron
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12 *
13 * ViewDependentShadow codes Copyright (C) 2008 Wojciech Lewandowski
14 * Thanks to to my company http://www.ai.com.pl for allowing me free this work.
15*/
16
17#ifndef OSGSHADOW_CONVEXPOLYHEDRON
18#define OSGSHADOW_CONVEXPOLYHEDRON 1
19
20#include <osg/Geometry>
21#include <osg/Polytope>
22#include <osgShadow/Export>
23
25// Class based on CustomPolytope defined and used in osgSim::OverlayNode.cpp.
26// Honors should go to Robert Osfield for writing such useful piece of code.
27// First incarnations of my ConvexPolyhedron were derived from CustomPolytope.
28// Later I made a number of modifications aimed at improving convex hull
29// precision of intersection & extrusion operations and ended up with code
30// so mixed that I decided to rewrite it as separate class.
32
33namespace osgShadow {
34
36{
37 public:
38 typedef std::vector<osg::Vec3d> Vertices;
39
40 static const osg::Matrix & defaultMatrix;
41
42 struct Face
43 {
44 std::string name;
47 };
48
49 typedef std::list<Face> Faces;
51
52 ConvexPolyhedron( void ) { }
53
54 ConvexPolyhedron( const osg::Matrix& matrix, const osg::Matrix& inverse,
55 const osg::BoundingBox& bb = osg::BoundingBox(-1,-1,-1,1,1,1));
56
57 Face& createFace() { _faces.push_back(Face()); return _faces.back(); }
58 void clear() { _faces.clear(); }
59
60
61 void setToUnitFrustum(bool withNear=true, bool withFar=true);
63 void transform(const osg::Matrix& matrix, const osg::Matrix& inverse);
64 void transformClip(const osg::Matrix& matrix, const osg::Matrix& inverse);
65
66
68 ( const Face & face0, const Face & face1, Face & face );
69
70 void mergeCoplanarFaces( const double & plane_normal_dot_tolerance = 0.0,
71 const double & plane_distance_tolerance = 0.0 );
72
74
75
76 static int pointsColinear
77 ( const osg::Vec3d & va, const osg::Vec3d & vb, const osg::Vec3d & vc,
78 const double & edge_normal_dot_tolerance = 0.0,
79 const double & null_edge_length_tolerance = 0.0 );
80
81 static int isFacePolygonConvex( Face & face, bool ignoreCollinearVertices = true );
82
84 ( bool checkForNonConvexPolys = false, const char * errorPrefix = NULL );
85
86
87 void cut(const osg::Polytope& polytope);
88
89 void cut(const ConvexPolyhedron& polytope);
90
91 void cut(const osg::Plane& plane, const std::string& name=std::string());
92
93 void extrude( const osg::Vec3d & offset );
94
95 void translate( const osg::Vec3d & offset );
96
97
98 void getPolytope(osg::Polytope& polytope) const;
99 void getPoints(Vertices& vertices) const;
101
103 const osg::Vec4d& colorInside,
104 osg::Geometry* useGeometry = NULL ) const;
105
106
107 bool dumpGeometry( const Face * face = NULL,
108 const osg::Plane * plane = NULL,
109 ConvexPolyhedron * basehull = NULL,
110 const char * filename = "convexpolyhedron.osg",
111 const osg::Vec4d& colorOutline = osg::Vec4( 0,1,0,0.5 ),
112 const osg::Vec4d& colorInside = osg::Vec4( 0,1,0,0.25 ),
113 const osg::Vec4d& faceColorOutline = osg::Vec4( 0,0,1,0.5 ),
114 const osg::Vec4d& faceColorInside = osg::Vec4( 0,0,1,0.25 ),
115 const osg::Vec4d& planeColorOutline = osg::Vec4( 1,0,0,0.5 ),
116 const osg::Vec4d& planeColorInside = osg::Vec4( 1,0,0,0.25 ),
117 const osg::Vec4d& baseColorOutline = osg::Vec4( 0,0,0,0.5 ),
118 const osg::Vec4d& baseColorInside = osg::Vec4( 0,0,0,0.25 ) ) const;
119};
120
121} // namespace osgShadow
122
123#endif
BoundingBoxd BoundingBox
Definition BoundingBox:257
Matrixd Matrix
Definition Matrix:27
Vec4f Vec4
Definition Vec4:21
The osgShadow library is a NodeKit that extends the core scene graph to add support for a range of sh...
Definition ConvexPolyhedron:33
Definition Geometry:31
A plane class.
Definition Plane:34
A Polytope class for representing convex clipping volumes made up of a set of planes.
Definition Polytope:26
General purpose double triple for use as vertices, vectors and normals.
Definition Vec3d:30
General purpose double quad.
Definition Vec4d:29
Faces _faces
Definition ConvexPolyhedron:50
void translate(const osg::Vec3d &offset)
static int isFacePolygonConvex(Face &face, bool ignoreCollinearVertices=true)
bool checkCoherency(bool checkForNonConvexPolys=false, const char *errorPrefix=NULL)
void getPoints(Vertices &vertices) const
void cut(const ConvexPolyhedron &polytope)
ConvexPolyhedron(const osg::Matrix &matrix, const osg::Matrix &inverse, const osg::BoundingBox &bb=osg::BoundingBox(-1,-1,-1, 1, 1, 1))
Face & createFace()
Definition ConvexPolyhedron:57
static const osg::Matrix & defaultMatrix
Definition ConvexPolyhedron:40
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)
osg::Geometry * buildGeometry(const osg::Vec4d &colorOutline, const osg::Vec4d &colorInside, osg::Geometry *useGeometry=NULL) const
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 transform(const osg::Matrix &matrix, const osg::Matrix &inverse)
void clear()
Definition ConvexPolyhedron:58
osg::BoundingBox computeBoundingBox(const osg::Matrix &m=osgShadow::ConvexPolyhedron::defaultMatrix) const
void transformClip(const osg::Matrix &matrix, const osg::Matrix &inverse)
void setToBoundingBox(const osg::BoundingBox &bb)
void getPolytope(osg::Polytope &polytope) const
std::list< Face > Faces
Definition ConvexPolyhedron:49
std::vector< osg::Vec3d > Vertices
Definition ConvexPolyhedron:38
void setToUnitFrustum(bool withNear=true, bool withFar=true)
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
void extrude(const osg::Vec3d &offset)
void cut(const osg::Polytope &polytope)
ConvexPolyhedron(void)
Definition ConvexPolyhedron:52
void cut(const osg::Plane &plane, const std::string &name=std::string())
Definition ConvexPolyhedron:43
osg::Plane plane
Definition ConvexPolyhedron:45
std::string name
Definition ConvexPolyhedron:44
Vertices vertices
Definition ConvexPolyhedron:46
#define NULL
Definition Export:55
#define OSGSHADOW_EXPORT
Definition Export:39

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.