Debian Codegraph @

include/BALL/VIEW/RENDERING/RENDERERS/renderer.h

raw symbols SCIP
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4
5 #ifndef BALL_VIEW_RENDERING_RENDERERS_RENDERER_H
6 #define BALL_VIEW_RENDERING_RENDERERS_RENDERER_H
7
8 #ifndef BALL_VIEW_KERNEL_REPRESENTATION_H
9 # include <BALL/VIEW/KERNEL/representation.h>
10 #endif
11
12 #ifndef BALL_CONCEPT_OBJECT_H
13 # include <BALL/CONCEPT/object.h>
14 #endif
15
16 #ifndef BALL_VIEW_KERNEL_STAGE_H
17 # include <BALL/VIEW/KERNEL/stage.h>
18 #endif
19
20 #ifndef BALL_MATHS_VECTOR2_H
21 # include <BALL/MATHS/vector2.h>
22 #endif
23
24 class QImage;
25
26 namespace BALL
27 {
28 namespace VIEW
29 {
30 class Scene;
31 class Line;
32 class MultiLine;
33 class Tube;
34 class Mesh;
35 class Label;
36 class Point;
37 class Sphere;
38 class Disc;
39 class Box;
40 class SimpleBox;
41 class TwoColoredLine;
42 class TwoColoredTube;
43 class ClippingPlane;
44 class GridVisualisation;
45 class QuadMesh;
46
47 /** Renderer is just a generic base class.
48 Derived classes are GLRenderer and POVRenderer.
49 Every renderer has a pointer to a Stage object, which contains the viewpoint,
50 the LightSource, etc. The renderer also knows the width and height, of the display, it shall
51 render.
52 \ingroup ViewRendering
53 */
54 class BALL_VIEW_EXPORT Renderer
55 {
56 public:
57
58 ///
59 enum StereoMode
60 {
61 NO_STEREO = 0,
62
63 /// Stereo mode for shutter glasses
64 ACTIVE_STEREO,
65
66 /// Stereo mode for output on two projectors
67 DUAL_VIEW_STEREO,
68
69 /// Stereo mode for output on two projectors with one display per head
70 DUAL_VIEW_DIFFERENT_DISPLAY_STEREO,
71
72 /// Stereo mode for top bottom views
73 TOP_BOTTOM_STEREO,
74
75 /// Line interlaced stereo
76 INTERLACED_STEREO
77 };
78
79 BALL_CREATE(Renderer)
80
81 /** @name Constructors and Destructors
82 */
83 //@{
84
85 /** Default Constructor.
86 */
87 Renderer();
88
89 /** Copy constructor.
90 */
91 Renderer(const Renderer& renderer);
92
93 /** Destructor
94 */
95 virtual ~Renderer() {}
96
97 /** Explicit default initialization.
98 */
99 virtual void clear(){}
100
101 /** Initialization routines.
102 This method is called by Scene::initializeGL.
103 */
104 virtual bool init(Scene& scene);
105
106 /** Initialisation with the Stage.
107 Called by Scene::exportScene().
108 */
109 virtual bool init(const Stage& stage, float height, float width);
110
111 /// Set the light sources according to the stage
112 virtual void setLights(bool reset_all = false);
113
114 /** Update the camera position either from a given Camera, or from the default Stage.
115 */
116 virtual void updateCamera(const Camera* camera = 0);
117
118 /**
119 * Updates the material for the current representation
120 */
121 virtual void updateMaterialForRepresentation(Representation const*) {};
122
123 /// Update the background color from the stage
124 virtual void updateBackgroundColor();
125
126 /// Setup an environment map
127 virtual void setupEnvironmentMap(const QImage& image);
128
129 /** Sets this renderer as a part of a stereo setup.
130 *
131 * eye_separation denotes the distance along the right vector used
132 * by this "eye".
133 */
134 virtual void setupStereo(float eye_separation, float focal_length);
135
136 /** Decide between event based and (threaded) continuous loop rendering.
137 */
138 virtual void useContinuousLoop(bool use_loop)
139 {
140 // TODO: mutex for use_continuous_loop_ just to be on the safe side
141 use_continuous_loop_ = use_loop;
142 };
143
144 /** Returns the mode of the render loop.
145 */
146 bool isContinuous() { return use_continuous_loop_; }
147
148 /** Whether renderer has its own FPS counter.
149 */
150 virtual bool hasFPScounter() { return false; }
151
152 /** Internal renderer FPS if available, otherwise returns 0.
153 */
154 virtual double getFPS() { return 0; }
155
156 ///
157 virtual bool finish();
158
159 /** Compute the 3D position on the view plane corresponding
160 * to point (x,y) on the view port
161 */
162 virtual Vector3 mapViewportTo3D(Position x, Position y);
163
164 /** Compute the 2D position on the screen corresponding
165 * to the 3D point vec
166 */
167 virtual Vector2 map3DToViewport(const Vector3& vec);
168
169 /** Pick all objects in the given screen rectangle.
170 */
171 virtual void pickObjects(Position x1, Position y1, Position x2, Position y2,
172 std::list<GeometricObject*>& objects);
173
174 /** Return the frustum used by this renderer.
175 */
176 virtual void getFrustum(float& near_f, float& far_f, float& left_f, float& right_f,
177 float& top_f, float& bottom_f);
178
179 //@}
180 /** @name Accessors
181 */
182 //@{
183
184 /** Render a Representation.
185 */
186 virtual bool renderOneRepresentation(const Representation& representation);
187
188
189 /** Buffer a Representation for later rendering.
190 */
191 virtual void bufferRepresentation(const Representation& /*rep*/) {};
192
193 /** Remove a representation from the buffer.
194 */
195 virtual void removeRepresentation(const Representation& /*rep*/) {};
196
197 /** Get the stage for the renderer (const)
198 */
199 virtual const Stage& getStage() const
200 { return *stage_;}
201
202 /** Set the stage for the renderer
203 */
204 virtual void setStage(const Stage& stage)
205 { stage_ = &stage;}
206
207 /// Test if a Stage was assigned to the Renderer
208 bool hasStage() const;
209
210 /// Set the size of the display
211 virtual void setSize(float width, float height) {width_ = width; height_ = height;}
212
213 ///
214 virtual float getWidth() const { return width_;}
215
216 ///
217 virtual float getHeight() const { return height_;}
218
219 /** Decides whether the renderer should use a faster preview mode.
220 * Please note that not all renderers support previews and may choose
221 * just to ignore this setting.
222 */
223 virtual void setPreviewMode(bool show_preview) { show_preview_ = show_preview; }
224
225 /** Decides whether to draw light sources explicitly.
226 * Please note that not all renderers support this feature and may choose
227 * just to ignore this setting.
228 */
229 virtual void showLightSources(bool show_light_sources) { show_light_sources_ = show_light_sources; }
230
231 /** Render a ruler.
232 *
233 * If supported by the renderer implementation, this function will produce
234 * a simple ruler that is rendered together with the other representations.
235 * The main use of this function is in the edit mode, where it can help to
236 * straighten-up structures and to correctly estimate angles and distances.
237 */
238 virtual void renderRuler();
239
240 ///
241 virtual void setStereoMode(StereoMode state);
242
243 ///
244 virtual StereoMode getStereoMode() const;
245
246 ///
247 virtual void setStereoFrustumConversion(int width_factor, int height_factor);
248
249 //@}
250 /** @name Predicates
251 */
252 //@{
253
254 ///
255 bool operator == (const Renderer& /*renderer*/) const
256 { return true; }
257
258 /// Wrapper for the renderering of special GeometricObjects
259 virtual void render_(const GeometricObject* object);
260
261 protected:
262
263 ///
264 virtual void renderClippingPlane_(const ClippingPlane&)
265 {Log.error() << "renderClippingPlane_ not implemented in derived Renderer class" << std::endl;}
266
267 // Render a text label
268 virtual void renderLabel_(const Label& /*label*/)
269 {Log.error() << "renderLabel_ not implemented in derived Renderer class" << std::endl;}
270
271 /// Render a line
272 virtual void renderLine_(const Line& /*line*/)
273 {Log.error() << "renderLine_ not implemented in derived Renderer class" << std::endl;}
274
275 /// Render an illuminated line
276 virtual void renderMultiLine_(const MultiLine& /*line*/)
277 {Log.error() << "renderMultiLine_ not implemented in derived Renderer class" << std::endl;}
278
279 /// Render a surface mesh
280 virtual void renderMesh_(const Mesh& /*mesh*/)
281 {Log.error() << "renderMesh_ not implemented in derived Renderer class" << std::endl;}
282
283 /// Render a single point
284 virtual void renderPoint_(const Point& /*point*/)
285 {Log.error() << "renderPoint_ not implemented in derived Renderer class" << std::endl;}
286
287 /// Render a box
288 virtual void renderBox_(const Box& /*box*/)
289 {Log.error() << "renderBox_ not implemented in derived Renderer class" << std::endl;}
290
291 /// Render a simple box (parallel to the axes)
292 virtual void renderSimpleBox_(const SimpleBox& /*box*/)
293 {Log.error() << "renderSimpleBox_ not implemented in derived Renderer class" << std::endl;}
294
295 /// Render a sphere
296 virtual void renderSphere_(const Sphere& /*sphere*/)
297 {Log.error() << "renderSphere_ not implemented in derived Renderer class" << std::endl;}
298
299 /// Render a disc
300 virtual void renderDisc_(const Disc& /*disc*/)
301 {Log.error() << "renderDisc_ not implemented in derived Renderer class" << std::endl;}
302
303 /// Render a tube
304 virtual void renderTube_(const Tube& /*tube*/)
305 {Log.error() << "renderTube_ not implemented in derived Renderer class" << std::endl;}
306
307 /// Render a line with two colors
308 virtual void renderTwoColoredLine_(const TwoColoredLine& /*two_colored_line*/)
309 {Log.error() << "renderTwoColoredLine_ not implemented in derived Renderer class" << std::endl;}
310
311 /// Render a tube with two colors
312 virtual void renderTwoColoredTube_(const TwoColoredTube& /*two_colored_tube*/)
313 {Log.error() << "renderTwoColoredTube_ not implemented in derived Renderer class" << std::endl;}
314
315 /// Render a grid
316 virtual void renderGridVisualisation_(const GridVisualisation&)
317 {Log.error() << "renderGridVisualisation_ not implemented in derived Renderer class" << std::endl;}
318 /// Render a quad mesh
319 virtual void renderQuadMesh_(const QuadMesh&)
320 {Log.error() << "renderQuadMesh_ not implemented in derived Renderer class" << std::endl;}
321 //@}
322
323 //_
324 Scene* scene_;
325
326 //_
327 const Stage* stage_;
328
329 //_The width of the render area
330 float width_;
331
332 //_The height of the render area
333 float height_;
334
335 //_
336 bool show_preview_;
337
338 //_
339 float volume_width_;
340
341 //_
342 bool show_light_sources_;
343
344 //_
345 Camera camera_;
346
347 // An offset added to camera position and look at
348 Vector3 camera_offset_;
349
350 bool use_continuous_loop_;
351
352 Size stereo_frustum_conversion_width_;
353 Size stereo_frustum_conversion_height_;
354
355 StereoMode stereo_;
356 };
357
358 } // namespace VIEW
359 } // namespace BALL
360
361 #endif // BALL_VIEW_RENDERING_RENDERER_H