openscenegraph
ClipNode
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
14#ifndef OSG_CLIPNODE
15#define OSG_CLIPNODE 1
16
17#include <osg/Group>
18#include <osg/ClipPlane>
19
20namespace osg {
21
22/** Node for defining the position of ClipPlanes in the scene.*/
23class OSG_EXPORT ClipNode : public Group
24{
25
26 public:
27
28 typedef std::vector<ref_ptr<ClipPlane> > ClipPlaneList;
29
30
31 ClipNode();
32
33 ClipNode(const ClipNode& es, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
34
35 META_Node(osg, ClipNode);
36
37 enum ReferenceFrame
38 {
39 RELATIVE_RF,
40 ABSOLUTE_RF
41 };
42
43 /** Set the ClipNode's ReferenceFrame, either to be relative to its
44 * parent reference frame, or relative to an absolute coordinate
45 * frame. RELATIVE_RF is the default.
46 * Note: setting the ReferenceFrame to be ABSOLUTE_RF will
47 * also set the CullingActive flag to false on the ClipNode (and
48 * consequently all of its parents), thereby disabling culling of it and
49 * all its parents. This is necessary to prevent inappropriate
50 * culling, but may impact cull times if the absolute ClipNode is
51 * deep in the scene graph. It is therefore recommended to only use
52 * absolute ClipNode at the top of the scene.
53 */
54 void setReferenceFrame(ReferenceFrame rf);
55
56 ReferenceFrame getReferenceFrame() const { return _referenceFrame; }
57
58
59 /** Creates six clip planes corresponding to the given BoundingBox. */
60 void createClipBox(const BoundingBox& bb,unsigned int clipPlaneNumberBase=0);
61
62 /** Adds the clipplane. Returns true on success, and false if the plane
63 * has already been added, or if clipplane is NULL. */
64 bool addClipPlane(ClipPlane* clipplane);
65
66 /** Removes the clipplane. Returns true on success, false if clipplane
67 * isn't in this ClipNode.*/
68 bool removeClipPlane(ClipPlane* clipplane);
69
70 /** Remove the ClipPlane with the given index. Returns true on success,
71 * false if pos is not a valid plane index. */
72 bool removeClipPlane(unsigned int pos);
73
74 /** Returns the number of ClipPlanes. */
75 inline unsigned int getNumClipPlanes() const { return _planes.size(); }
76
77
78 /** Get ClipPlane at the given index position. */
79 inline ClipPlane* getClipPlane(unsigned int pos) { return _planes[pos].get(); }
80
81 /** Get const ClipPlane at the given index position. */
82 inline const ClipPlane* getClipPlane(unsigned int pos) const { return _planes[pos].get(); }
83
84 /** Set the ClipPlaneList. */
85 inline void setClipPlaneList(const ClipPlaneList& cpl) { _planes=cpl; }
86
87 /** Get the ClipPlaneList. */
88 inline ClipPlaneList& getClipPlaneList() { return _planes; }
89
90 /** Get the const ClipPlaneList. */
91 inline const ClipPlaneList& getClipPlaneList() const { return _planes; }
92
93 /** Set the GLModes for all ClipPlanes, on the StateSet. */
94 void setStateSetModes(StateSet&,StateAttribute::GLModeValue) const;
95
96 /** Set up the local StateSet. */
97 void setLocalStateSetModes(StateAttribute::GLModeValue=StateAttribute::ON);
98
99 virtual BoundingSphere computeBound() const;
100
101 protected:
102
103 virtual ~ClipNode();
104
105 StateAttribute::GLModeValue _value;
106 ClipPlaneList _planes;
107
108 ReferenceFrame _referenceFrame;
109};
110
111}
112
113#endif