Debian Codegraph @

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

raw symbols SCIP
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))
9 #include <BALL/VIEW/RENDERING/RENDERERS/raytracingRenderer.h>
10
11 #include <BALL/VIEW/WIDGETS/scene.h>
12 #include <BALL/VIEW/KERNEL/stage.h>
13 #include <BALL/VIEW/KERNEL/representationManager.h>
14 #include <BALL/VIEW/PRIMITIVES/mesh.h>
15 #include <BALL/VIEW/KERNEL/mainControl.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 {
66 /** RTfactRenderer
67 Provides ray tracing through RTfact-RTRemote
68 \ingroup ViewRendering
69 */
70 class BALL_VIEW_EXPORT RTfactRenderer
71 : public RaytracingRenderer
72 {
73 public:
74
75 /** This class encapsulates RTfact's data structures per Representation.
76 */
77 class RTfactData
78 {
79 public:
80
81 /// The object handles (all objects)
82 std::vector<RTpieCpp::GeometryHandle> object_handles;
83
84 /// The meshes
85 std::vector<RTpieCpp::MeshHandle> mesh_handles;
86
87 /// The instances (visible objects)
88 std::vector<RTpieCpp::InstanceHandle> instance_handles;
89
90 /// The materials
91 std::vector<RTpieCpp::AppearanceHandle> material_handles;
92
93 /// Cut-plane geometries
94 std::vector<RTpieCpp::GeometryHandle> cutPlanes;
95
96 /// Cut-plane meshes
97 std::vector<RTpieCpp::MeshHandle> cutPlaneMeshes;
98
99 /// Cut-plane instances
100 std::vector<RTpieCpp::InstanceHandle> cutPlaneInstances;
101
102 /// Cut-planes material
103 RTpieCpp::AppearanceHandle cutPlaneShader;
104
105 /// Mark previously disabled representations
106 bool has_been_disabled;
107 };
108
109 /// Default Constructor.
110 RTfactRenderer()
111 : RaytracingRenderer(),
112 rtfact_needs_update_(false)
113 {
114 }
115
116 /// Destructor
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
139 virtual GeometricObject* pickObject(Position x, Position y);
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
157 void bufferRepresentation(const Representation& rep);
158 void bufferRepresentationDynamic(const Representation& rep);
159 void removeRepresentation(const Representation& rep);
160
161 void setLights(bool reset_all = false);
162
163 void updateCamera(const Camera* camera = 0);
164
165 void updateBackgroundColor();
166
167 void setupEnvironmentMap(const QImage& image);
168
169 void updateMaterialForRepresentation(Representation const* rep);
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
177 /** Raytracing-related functionality **/
178 //@{
179 /** Intersect a set of rays with the geometry buffered by this renderer.
180 *
181 * This function will intersect the rays
182 *
183 * origins[i] + l * directions[i]
184 *
185 * with the geometry that has been buffered by this renderer previously.
186 */
187 virtual std::vector<float> intersectRaysWithGeometry(const std::vector<Vector3>& origins, const std::vector<Vector3>& directions);
188
189 //@}
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
230 HashMap<Representation const*, RTfactData> objects_;
231 HashMap<RTpieCpp::InstanceHandle, GeometricObject*> geometric_objects_inst;
232 HashMap<RTpieCpp::MeshHandle, GeometricObject*> geometric_objects_;
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