renderer.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: renderer.h,v 1.11.16.1 2007/03/25 21:26:16 oliver Exp $
00005 
00006 #ifndef BALL_VIEW_RENDERING_RENDERER_H
00007 #define BALL_VIEW_RENDERING_RENDERER_H
00008 
00009 #ifndef BALL_VIEW_KERNEL_REPRESENTATION_H
00010 # include <BALL/VIEW/KERNEL/representation.h>
00011 #endif
00012 
00013 #ifndef BALL_CONCEPT_OBJECT_H
00014 # include <BALL/CONCEPT/object.h>
00015 #endif
00016 
00017 #ifndef BALL_VIEW_KERNEL_STAGE_H
00018 # include <BALL/VIEW/KERNEL/stage.h>
00019 #endif
00020 
00021 #ifndef BALL_MATHS_VECTOR2_H
00022 # include <BALL/MATHS/vector2.h>
00023 #endif
00024 
00025 namespace BALL
00026 {
00027   namespace VIEW
00028   {
00029     class Scene;
00030     class Line;
00031     class MultiLine;
00032     class Tube;
00033     class Mesh;
00034     class Label;
00035     class Point;
00036     class Sphere;
00037     class Disc;
00038     class Box;
00039     class SimpleBox;
00040     class TwoColoredLine;
00041     class TwoColoredTube;
00042     class ClippingPlane;
00043     class GridVisualisation;
00044     class QuadMesh;
00045 
00053     class BALL_VIEW_EXPORT Renderer
00054       : public Object
00055     {
00056       public:
00057 
00058       BALL_CREATE(Renderer)
00059 
00060       
00063 
00066       Renderer();
00067       
00070       Renderer(const Renderer& renderer);
00071 
00074       virtual ~Renderer() {}
00075 
00078       virtual void clear(){}
00079 
00083       virtual bool init(Scene& scene);
00084 
00088       virtual bool init(const Stage& stage, float height, float width);
00089 
00091       virtual void setLights(bool reset_all = false);
00092 
00095       virtual void updateCamera(const Camera* camera = 0);
00096 
00098       virtual void updateBackgroundColor();
00099 
00105       virtual void setupStereo(float eye_separation, float focal_length);
00106 
00109       virtual void useContinuousLoop(bool use_loop) 
00110       { 
00111         // TODO: mutex for use_continuous_loop_ just to be on the safe side
00112         use_continuous_loop_ = use_loop;
00113       };
00114 
00117       bool isContinuous() { return use_continuous_loop_; }
00118 
00120       virtual bool finish();
00121 
00125       virtual Vector3 mapViewportTo3D(Position x, Position y);
00126 
00130       virtual Vector2 map3DToViewport(const Vector3& vec);
00131 
00133 
00136       
00139       virtual bool renderOneRepresentation(const Representation& representation);
00140 
00141 
00144       virtual void bufferRepresentation(const Representation& /*rep*/) {};
00145 
00148       virtual void removeRepresentation(const Representation& /*rep*/) {};
00149 
00152       virtual const Stage& getStage() const
00153         { return *stage_;}
00154       
00157       virtual void setStage(const Stage& stage)
00158         { stage_ = &stage;}
00159 
00161       bool hasStage() const;
00162 
00164       virtual void setSize(float width, float height) { width_ = width; height_ = height;}
00165 
00167       virtual float getWidth() const { return width_;}
00168 
00170       virtual float getHeight() const { return height_;}
00171 
00176       virtual void setPreviewMode(bool show_preview) { show_preview_ = show_preview; }
00177 
00182       virtual void showLightSources(bool show_light_sources) { show_light_sources_ = show_light_sources; }
00183       
00191       virtual void renderRuler();
00192 
00194 
00197       
00199       bool operator == (const Renderer& /*renderer*/) const
00200         { return true; }
00201       
00203       virtual void render_(const GeometricObject* object);
00204 
00205       protected:
00206 
00208       virtual void renderClippingPlane_(const ClippingPlane&)
00209         {Log.error() << "renderClippingPlane_ not implemented in derived Renderer class" << std::endl;}
00210 
00211       // Render a text label
00212       virtual void renderLabel_(const Label& /*label*/)
00213         {Log.error() << "renderLabel_ not implemented in derived Renderer class" << std::endl;}
00214 
00216       virtual void renderLine_(const Line& /*line*/)
00217         {Log.error() << "renderLine_ not implemented in derived Renderer class" << std::endl;}
00218       
00220       virtual void renderMultiLine_(const MultiLine& /*line*/)
00221         {Log.error() << "renderMultiLine_ not implemented in derived Renderer class" << std::endl;}
00222 
00224       virtual void renderMesh_(const Mesh& /*mesh*/)
00225         {Log.error() << "renderMesh_ not implemented in derived Renderer class" << std::endl;}
00226  
00228       virtual void renderPoint_(const Point& /*point*/)
00229         {Log.error() << "renderPoint_ not implemented in derived Renderer class" << std::endl;}
00230 
00232       virtual void renderBox_(const Box& /*box*/)
00233         {Log.error() << "renderBox_ not implemented in derived Renderer class" << std::endl;}
00234 
00236       virtual void renderSimpleBox_(const SimpleBox& /*box*/)
00237         {Log.error() << "renderSimpleBox_ not implemented in derived Renderer class" << std::endl;}
00238 
00240       virtual void renderSphere_(const Sphere& /*sphere*/)
00241         {Log.error() << "renderSphere_ not implemented in derived Renderer class" << std::endl;}
00242 
00244       virtual void renderDisc_(const Disc& /*disc*/)
00245         {Log.error() << "renderDisc_ not implemented in derived Renderer class" << std::endl;}
00246 
00248       virtual void renderTube_(const Tube& /*tube*/)
00249         {Log.error() << "renderTube_ not implemented in derived Renderer class" << std::endl;}
00250 
00252       virtual void renderTwoColoredLine_(const TwoColoredLine& /*two_colored_line*/)
00253         {Log.error() << "renderTwoColoredLine_ not implemented in derived Renderer class" << std::endl;}
00254 
00256       virtual void renderTwoColoredTube_(const TwoColoredTube& /*two_colored_tube*/)
00257         {Log.error() << "renderTwoColoredTube_ not implemented in derived Renderer class" << std::endl;}
00258       
00260       virtual void renderGridVisualisation_(const GridVisualisation&)
00261         {Log.error() << "renderGridVisualisation_ not implemented in derived Renderer class" << std::endl;}
00263       virtual void renderQuadMesh_(const QuadMesh&)
00264         {Log.error() << "renderQuadMesh_ not implemented in derived Renderer class" << std::endl;}
00266       
00267       //_
00268       Scene* scene_;
00269 
00270       //_
00271       const Stage*    stage_;
00272 
00273       //_
00274       float           width_;
00275 
00276       //_
00277       float           height_;
00278 
00279       //_
00280       bool            show_preview_;
00281 
00282       //_
00283       float           volume_width_;
00284 
00285       //_
00286       bool            show_light_sources_;
00287 
00288       //_
00289       Camera          camera_;
00290 
00291       // An offset added to camera position and look at
00292       Vector3         camera_offset_;
00293 
00294       bool            use_continuous_loop_;
00295     };
00296 
00297   } // namespace VIEW
00298 } // namespace BALL
00299 
00300 #endif // BALL_VIEW_RENDERING_RENDERER_H