BALL  1.5.0
rtfactRenderer.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_VIEW_RENDERING_RENDERERS_RTFACTRENDERER_H
6 #define BALL_VIEW_RENDERING_RENDERERS_RTFACTRENDERER_H
7 
8 #define BALLVIEW_RTFACTRENDERER_THROW(exceptionName, message) (throw BALL::Exception::##exceptionName##(__FILE__, __LINE__, message))
10 
12 #include <BALL/VIEW/KERNEL/stage.h>
16 #include <BALL/MATHS/surface.h>
17 #include <BALL/MATHS/vector3.h>
18 #include <BALL/DATATYPE/hashMap.h>
19 
20 #include <RTpieCpp/RayTracerHandle.hpp>
21 #include <RTfact/Model/Image/BasicImage2D.hpp>
22 #include <RTfact/Model/Framebuffer/Image2DFramebuffer.hpp>
23 #include <RTfact/Utils/FPSMeter.hpp>
24 
25 namespace boost
26 {
27  template <>
28  struct hash< RTpieCpp::MeshHandle >
29  {
30  public:
31  union conv
32  {
33  size_t s;
34  const void *p;
35  };
36 
37  size_t operator()(const RTpieCpp::MeshHandle& x ) const throw() {
38  conv c;
39  c.p=x.get();
40  return c.s;
41  }
42  };
43 
44  template <>
45  struct hash< RTpieCpp::InstanceHandle >
46  {
47  public:
48  union conv
49  {
50  size_t s;
51  const void *p;
52  };
53 
54  size_t operator()(const RTpieCpp::InstanceHandle& x ) const throw() {
55  conv c;
56  c.p=x.get();
57  return c.s;
58  }
59  };
60 }
61 
62 namespace BALL
63 {
64  namespace VIEW
65  {
71  : public RaytracingRenderer
72  {
73  public:
74 
77  class RTfactData
78  {
79  public:
80 
82  std::vector<RTpieCpp::GeometryHandle> object_handles;
83 
85  std::vector<RTpieCpp::MeshHandle> mesh_handles;
86 
88  std::vector<RTpieCpp::InstanceHandle> instance_handles;
89 
91  std::vector<RTpieCpp::AppearanceHandle> material_handles;
92 
94  std::vector<RTpieCpp::GeometryHandle> cutPlanes;
95 
97  std::vector<RTpieCpp::MeshHandle> cutPlaneMeshes;
98 
100  std::vector<RTpieCpp::InstanceHandle> cutPlaneInstances;
101 
103  RTpieCpp::AppearanceHandle cutPlaneShader;
104 
107  };
108 
111  : RaytracingRenderer(),
112  rtfact_needs_update_(false)
113  {
114  }
115 
117  virtual ~RTfactRenderer()
118  {
119  }
120 
121  virtual bool hasFPScounter();
122 
123  virtual double getFPS();
124 
125  /************************************************************************/
126  /* RaytracingRenderer methods */
127  /************************************************************************/
128  virtual bool init(Scene& scene);
129 
130  virtual String getRenderer()
131  {
132  return "RTfact-RTRemote Ray Tracer";
133  }
134 
135  virtual void formatUpdated()
136  {
137  }
138 
140  virtual void pickObjects(Position x1, Position y1, Position x2, Position y2,
141  std::list<GeometricObject*>& objects);
142 
143 
144 
145  virtual void setSize(float width, float height);
146 
147  virtual void setupStereo(float eye_separation, float focal_length);
148 
149  virtual void getFrustum(float& near_f, float& far_f, float& left_f, float& right_f, float& top_f, float& bottom_f);
150  virtual void setFrustum(float near_f, float far_f, float left_f, float right_f, float top_f, float bottom_f);
151 
152  virtual void prepareBufferedRendering(const Stage& stage);
153  virtual void renderToBufferImpl(FrameBufferPtr buffer);
154 
155  virtual void useContinuousLoop(bool use_loop);
156 
160 
161  void setLights(bool reset_all = false);
162 
163  void updateCamera(const Camera* camera = 0);
164 
166 
167  void setupEnvironmentMap(const QImage& image);
168 
170 
171  void transformTube(const TwoColoredTube& tube, float *trafo);
172  void transformLine(const TwoColoredLine& line, float *trafo);
173 
174  void updateMaterialFromStage(RTpieCpp::AppearanceHandle& material);
175  void convertMaterial(Stage::Material const& rt_material, RTpieCpp::AppearanceHandle& material);
176 
187  virtual std::vector<float> intersectRaysWithGeometry(const std::vector<Vector3>& origins, const std::vector<Vector3>& directions);
188 
190 
191  private:
192 
193  static const float vectorDifferenceTolerance_;
194 
195  bool doVectorsDiffer(const Vector3& vecA, const Vector3& vecB);
196 
197  template<typename taPixelType>
198  void renderImpl(taPixelType* buffer, const unsigned int width, const unsigned int height, const unsigned int pitch);
199 
200  void renderImpl(float* buffer, const unsigned int width, const unsigned int height, const unsigned int pitch)
201  {
202  }
203 
204  std::vector<RTpieCpp::LightHandle> lights_;
205 
206  typedef RTfact::BasicImage2D<float> t_ColorImage;
207  typedef RTfact::BasicImage2D<float> t_DistanceImage;
208  typedef RTfact::Image2DFramebuffer<
209  t_ColorImage,
210  t_DistanceImage> t_Framebuffer;
211 
212  typedef RTfact::BasicImage2D<unsigned char> t_ByteColorImage;
213  typedef RTfact::BasicImage2D<unsigned char> t_ByteDistanceImage;
214  typedef RTfact::Image2DFramebuffer<
215  t_ByteColorImage,
216  t_ByteDistanceImage> t_ByteFramebuffer;
217 
218  RTpieCpp::SceneHandle sceneHandle;
219  RTpieCpp::RayTracerHandle rayTracer;
220  RTpieCpp::CameraHandle cameraHandle;
221  RTpieCpp::FrameBufferHandle renderBuffer;
222  RTpieCpp::RenderTaskHandle renderTask;
223  t_Framebuffer framebuffer;
224  t_ByteFramebuffer byteFramebuffer;
225 
226 
227  RTfact::FPSMeter fpsMeter;
228  RTpieCpp::PickTaskHandle pickTask;
229 
233 
234  Surface sphere_template_;
235  Surface tube_template_;
236 
237  bool rtfact_needs_update_;
238 
239  Vector3 last_camera_position;
240  Vector3 last_camera_view_vec;
241  Vector3 last_camera_lookup;
242 
243  float x_scale_;
244  float y_scale_;
245 
246  };
247 
248  } // namespace VIEW
249 } // namespace BALL
250 
251 #endif // BALL_VIEW_RENDERING_RTFACTRENDERER_H
Definition: constants.h:13
BALL_EXTERN_VARIABLE const double c
Definition: constants.h:149
boost::shared_ptr< FrameBuffer > FrameBufferPtr
Definition: renderTarget.h:222
HashMap class based on the STL map (containing serveral convenience functions)
Definition: hashMap.h:74
size_t operator()(const RTpieCpp::MeshHandle &x) const
size_t operator()(const RTpieCpp::InstanceHandle &x) const
void removeRepresentation(const Representation &rep)
void transformLine(const TwoColoredLine &line, float *trafo)
virtual void setFrustum(float near_f, float far_f, float left_f, float right_f, float top_f, float bottom_f)
virtual void pickObjects(Position x1, Position y1, Position x2, Position y2, std::list< GeometricObject * > &objects)
void transformTube(const TwoColoredTube &tube, float *trafo)
void updateCamera(const Camera *camera=0)
virtual bool hasFPScounter()
virtual ~RTfactRenderer()
Destructor.
void updateMaterialForRepresentation(Representation const *rep)
virtual void setSize(float width, float height)
Set the size of the display.
virtual std::vector< float > intersectRaysWithGeometry(const std::vector< Vector3 > &origins, const std::vector< Vector3 > &directions)
virtual void setupStereo(float eye_separation, float focal_length)
virtual String getRenderer()
void setLights(bool reset_all=false)
Set the light sources according to the stage.
void bufferRepresentationDynamic(const Representation &rep)
virtual void useContinuousLoop(bool use_loop)
void setupEnvironmentMap(const QImage &image)
Setup an environment map.
void updateBackgroundColor()
Update the background color from the stage.
virtual void prepareBufferedRendering(const Stage &stage)
void updateMaterialFromStage(RTpieCpp::AppearanceHandle &material)
void convertMaterial(Stage::Material const &rt_material, RTpieCpp::AppearanceHandle &material)
void bufferRepresentation(const Representation &rep)
virtual void getFrustum(float &near_f, float &far_f, float &left_f, float &right_f, float &top_f, float &bottom_f)
virtual void renderToBufferImpl(FrameBufferPtr buffer)
RTfactRenderer()
Default Constructor.
virtual double getFPS()
virtual bool init(Scene &scene)
virtual GeometricObject * pickObject(Position x, Position y)
std::vector< RTpieCpp::InstanceHandle > instance_handles
The instances (visible objects)
RTpieCpp::AppearanceHandle cutPlaneShader
Cut-planes material.
std::vector< RTpieCpp::GeometryHandle > cutPlanes
Cut-plane geometries.
std::vector< RTpieCpp::GeometryHandle > object_handles
The object handles (all objects)
std::vector< RTpieCpp::InstanceHandle > cutPlaneInstances
Cut-plane instances.
std::vector< RTpieCpp::MeshHandle > mesh_handles
The meshes.
std::vector< RTpieCpp::AppearanceHandle > material_handles
The materials.
std::vector< RTpieCpp::MeshHandle > cutPlaneMeshes
Cut-plane meshes.
bool has_been_disabled
Mark previously disabled representations.
#define BALL_VIEW_EXPORT
Definition: COMMON/global.h:52