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  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS ClippingNode
56 //
57 //=============================================================================
58 
59 
60 #ifndef ACG_CLIPPING_NODE_HH
61 #define ACG_CLIPPING_NODE_HH
62 
63 
64 //== INCLUDES =================================================================
65 
66 #include "BaseNode.hh"
67 
68 #include <ACG/GL/RenderObject.hh>
69 #include <string>
70 #include <fstream>
71 
72 //== NAMESPACES ===============================================================
73 
74 namespace ACG {
75 namespace SceneGraph {
76 
77 
78 //== CLASS DEFINITION =========================================================
79 
80 
88 class ACGDLLEXPORT ClippingNode : public BaseNode
89 {
90 public:
91 
93  ClippingNode( BaseNode* _parent = 0,
94  const std::string& _name = "<ClippingNode>" )
95  : BaseNode(_parent, _name),
96  slice_width_(0),
97  offset_(0),
98  mod_(this)
99  {
100  plane0_[0] = 0.0;
101  plane0_[1] = 0.0;
102  plane0_[2] = 0.0;
103  plane0_[3] = 0.0;
104 
105  plane1_[0] = 0.0;
106  plane1_[1] = 0.0;
107  plane1_[2] = 0.0;
108  plane1_[3] = 0.0;
109 
110  offset_plane0_[0] = 0.0;
111  offset_plane0_[1] = 0.0;
112  offset_plane0_[2] = 0.0;
113  offset_plane0_[3] = 0.0;
114 
115  offset_plane1_[0] = 0.0;
116  offset_plane1_[1] = 0.0;
117  offset_plane1_[2] = 0.0;
118  offset_plane1_[3] = 0.0;
119  }
120 
121 
123  virtual ~ClippingNode() {}
124 
126  ACG_CLASSNAME(ClippingNode);
127 
129  void enter(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawmode);
130 
132  void leave(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawmode);
133 
135  void enter(GLState& _state, const DrawModes::DrawMode& _drawmode);
136 
138  void leave(GLState& _state, const DrawModes::DrawMode& _drawmode);
139 
141  void set_plane(const Vec3f& _position, const Vec3f& _normal, float _eps=0.0);
142 
144  const Vec3f& position() const { return position_; }
145 
147  const Vec3f& normal() const { return normal_; }
148 
150  float slice_width() const { return slice_width_; }
151 
153  void set_offset(float _dist);
154 
156  Vec4d plane0() const { return Vec4d(offset_plane0_[0], offset_plane0_[1], offset_plane0_[2], offset_plane0_[3]); }
157 
159  Vec4d plane1() const { return Vec4d(offset_plane1_[0], offset_plane1_[1], offset_plane1_[2], offset_plane1_[3]); }
160 
161 private:
162 
163  Vec3f position_, normal_;
164  GLdouble plane0_[4], plane1_[4], offset_plane0_[4], offset_plane1_[4];
165  float slice_width_, offset_;
166 
167  // modifiers for RenderObject based rendering
168 
170  {
171  public:
172  // this modifier computes the vertex distance to the clip planes and writes them to the gl_ClipDistancei outputs
173  // it adds new uniforms:
174  // vec4 g_SlicePlane0;
175  // vec4 g_SlicePlane1;
176  // ..
177 
178  ClippingShaderModifier(int _numClipPlanes);
179  virtual ~ClippingShaderModifier() {}
180 
181  void modifyVertexIO(ShaderGenerator* _shader);
182 
183  void modifyVertexBeginCode(QStringList* _code);
184 
185  private:
186 
187  int numClipPlanes_;
188  };
189 
191  {
192  public:
193  ClippingObjectModifier(const ClippingNode* _node);
194  virtual ~ClippingObjectModifier() {}
195 
196  void apply(RenderObject* _obj);
197 
198  private:
199  const ClippingNode* node_;
200  };
201 
202 
204 
205  // shader mod for 1 clipping plane
206  static ClippingShaderModifier shaderMod1_;
207 
208  // shader mod for 2 clipping planes
209  static ClippingShaderModifier shaderMod2_;
210 };
211 
212 
213 //=============================================================================
214 } // namespace SceneGraph
215 } // namespace ACG
216 //=============================================================================
217 #endif // ACG_CLIPPING_NODE_HH defined
218 //=============================================================================
Interface for modifying render objects.
Vec4d plane1() const
get second plane equation
float slice_width() const
get slice width
const Vec3f & position() const
get position
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
VectorT< double, 4 > Vec4d
Definition: VectorT.hh:146
Vec4d plane0() const
get first plane equation
const Vec3f & normal() const
get normal
ClippingNode(BaseNode *_parent=0, const std::string &_name="<ClippingNode>")
Default constructor. Applies all properties.
Definition: ClippingNode.hh:93
Interface class between scenegraph and renderer.
virtual ~ClippingNode()
Destructor.