Developer Documentation
ClippingNode.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 
43 
44 
45 
46 
47 //=============================================================================
48 //
49 // CLASS ClippingNode
50 //
51 //=============================================================================
52 
53 
54 #ifndef ACG_CLIPPING_NODE_HH
55 #define ACG_CLIPPING_NODE_HH
56 
57 
58 //== INCLUDES =================================================================
59 
60 #include "BaseNode.hh"
61 
62 #include <ACG/GL/RenderObject.hh>
63 #include <string>
64 #include <fstream>
65 
66 //== NAMESPACES ===============================================================
67 
68 namespace ACG {
69 namespace SceneGraph {
70 
71 
72 //== CLASS DEFINITION =========================================================
73 
74 
82 class ACGDLLEXPORT ClippingNode : public BaseNode
83 {
84 public:
85 
87  ClippingNode( BaseNode* _parent = 0,
88  const std::string& _name = "<ClippingNode>" )
89  : BaseNode(_parent, _name),
90  slice_width_(0),
91  offset_(0),
92  mod_(this)
93  {
94  plane0_[0] = 0.0;
95  plane0_[1] = 0.0;
96  plane0_[2] = 0.0;
97  plane0_[3] = 0.0;
98 
99  plane1_[0] = 0.0;
100  plane1_[1] = 0.0;
101  plane1_[2] = 0.0;
102  plane1_[3] = 0.0;
103 
104  offset_plane0_[0] = 0.0;
105  offset_plane0_[1] = 0.0;
106  offset_plane0_[2] = 0.0;
107  offset_plane0_[3] = 0.0;
108 
109  offset_plane1_[0] = 0.0;
110  offset_plane1_[1] = 0.0;
111  offset_plane1_[2] = 0.0;
112  offset_plane1_[3] = 0.0;
113  }
114 
115 
117  virtual ~ClippingNode() {}
118 
120  ACG_CLASSNAME(ClippingNode);
121 
123  void enter(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawmode);
124 
126  void leave(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawmode);
127 
129  void enter(GLState& _state, const DrawModes::DrawMode& _drawmode);
130 
132  void leave(GLState& _state, const DrawModes::DrawMode& _drawmode);
133 
135  void set_plane(const Vec3f& _position, const Vec3f& _normal, float _eps=0.0);
136 
138  const Vec3f& position() const { return position_; }
139 
141  const Vec3f& normal() const { return normal_; }
142 
144  float slice_width() const { return slice_width_; }
145 
147  void set_offset(float _dist);
148 
150  Vec4d plane0() const { return Vec4d(offset_plane0_[0], offset_plane0_[1], offset_plane0_[2], offset_plane0_[3]); }
151 
153  Vec4d plane1() const { return Vec4d(offset_plane1_[0], offset_plane1_[1], offset_plane1_[2], offset_plane1_[3]); }
154 
155 private:
156 
157  Vec3f position_, normal_;
158  GLdouble plane0_[4], plane1_[4], offset_plane0_[4], offset_plane1_[4];
159  float slice_width_, offset_;
160 
161  // modifiers for RenderObject based rendering
162 
163  class ACGDLLEXPORT ClippingShaderModifier : public ShaderModifier
164  {
165  public:
166  // this modifier computes the vertex distance to the clip planes and writes them to the gl_ClipDistancei outputs
167  // it adds new uniforms:
168  // vec4 g_SlicePlane0;
169  // vec4 g_SlicePlane1;
170  // ..
171 
172  explicit ClippingShaderModifier(int _numClipPlanes);
173  virtual ~ClippingShaderModifier() {}
174 
175  void modifyVertexIO(ShaderGenerator* _shader);
176 
177  void modifyVertexBeginCode(QStringList* _code);
178 
179  private:
180 
181  int numClipPlanes_;
182  };
183 
184  class ACGDLLEXPORT ClippingObjectModifier : public RenderObjectModifier
185  {
186  public:
187  explicit ClippingObjectModifier(const ClippingNode* _node);
188  virtual ~ClippingObjectModifier() {}
189 
190  void apply(RenderObject* _obj);
191 
192  private:
193  const ClippingNode* node_;
194  };
195 
196 
198 
199  // shader mod for 1 clipping plane
200  static ClippingShaderModifier shaderMod1_;
201 
202  // shader mod for 2 clipping planes
203  static ClippingShaderModifier shaderMod2_;
204 };
205 
206 
207 //=============================================================================
208 } // namespace SceneGraph
209 } // namespace ACG
210 //=============================================================================
211 #endif // ACG_CLIPPING_NODE_HH defined
212 //=============================================================================
Namespace providing different geometric functions concerning angles.
Interface class between scenegraph and renderer.
Definition: RenderObject.hh:98
Vec4d plane1() const
get second plane equation
virtual ~ClippingNode()
Destructor.
float slice_width() const
get slice width
Interface for modifying render objects.
const Vec3f & position() const
get position
Vec4d plane0() const
get first plane equation
VectorT< double, 4 > Vec4d
Definition: VectorT.hh:140
ClippingNode(BaseNode *_parent=0, const std::string &_name="<ClippingNode>")
Default constructor. Applies all properties.
Definition: ClippingNode.hh:87
const Vec3f & normal() const
get normal