BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
cudaVolumeRenderer.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_CUDARAYTRACINGRENDERER_H
6 #define BALL_VIEW_RENDERING_RENDERERS_CUDARAYTRACINGRENDERER_H
7 
8 #define BALLVIEW_CUDAVOLUMERENDERER_THROW(exceptionName, message) (throw BALL::Exception::##exceptionName##(__FILE__, __LINE__, message))
10 #include <cudamm/cuda.hpp>
11 
12 namespace BALL
13 {
14  namespace VIEW
15  {
17  : public RaytracingRenderer
18  {
19  public:
20 
21  /* RT renderer methods */
22  virtual bool init(const Scene& scene)
24  {
25  try
26  {
27  cuda::Cuda cudaCtx(0);
28  cuda::Module mod("../libVIEW/GeneratedFiles/Debug/raytracer_debug.cubin");
29  }
30  catch(cuda::Exception const &e)
31  {
32  BALL::Log.error() << "Initialization of CudaVolumeRenderer failed" << std::endl;
33  BALLVIEW_CUDAVOLUMERENDERER_THROW(CUDAError, e.what());
34  }
35 
36  return true;
37  }
38 
39  virtual String getRenderer()
40  throw()
41  {
42  return "CUDA Volume Renderer v1";
43  }
44 
45  virtual void formatUpdated()
46  {
47 
48  }
49 
50  virtual void prepareBufferedRendering(const Stage& stage)
51  {
52 
53  }
54 
55  virtual void renderToBufferImpl(FrameBufferPtr buffer)
56  {
57  FrameBufferFormat fmt = buffer->getFormat();
59  {
60  renderImpl<int>(reinterpret_cast<int*>(buffer->getData()), fmt.getWidth(), fmt.getHeight());
61  }
63  {
64  renderImpl<float>(reinterpret_cast<float*>(buffer->getData()), fmt.getWidth(), fmt.getHeight());
65  }
66  }
67 
68  private:
69 
70  template<typename taPixelType>
71  void renderImpl(taPixelType* buffer, const unsigned int width, const unsigned int height);
72 
73  template<>
74  void renderImpl(int* buffer, const unsigned int width, const unsigned int height)
75  {
76  for (unsigned int j = 0; j < height; j++)
77  {
78  for (unsigned int i = 0; i < width; i++)
79  {
80  if ( (((i / 64) % 2) == 0) && (((j / 64) % 2) == 0))
81  {
82  buffer[j*width + i] = (0 << 24) | (255 << 16) | (0 << 8) | (0);
83  }
84  else
85  {
86  buffer[j*width + i] = (0 << 24) | (0 << 16) | (0 << 8) | (255);
87  }
88 
89  }
90  }
91  }
92 
93  template<>
94  void renderImpl(float* buffer, const unsigned int width, const unsigned int height)
95  {
96  for (unsigned int j = 0; j < height; j++)
97  {
98  for (unsigned int i = 0; i < width; i++)
99  {
100  if ( (((i / 64) % 2) == 0) && (((j / 64) % 2) == 0))
101  {
102  buffer[3 * (j*width + i) + 0] = 1;
103  buffer[3 * (j*width + i) + 1] = 0;
104  buffer[3 * (j*width + i) + 2] = 0;
105  }
106  else
107  {
108  buffer[3 * (j*width + i) + 0] = 0;
109  buffer[3 * (j*width + i) + 1] = 1;
110  buffer[3 * (j*width + i) + 2] = 0;
111  }
112 
113  }
114  }
115  }
116 
117  };
118 
119 
120  } // namespace VIEW
121 
122 } // namespace BALL
123 
124 #endif // BALL_VIEW_RENDERING_CUDARAYTRACINGRENDERER_H
virtual void prepareBufferedRendering(const Stage &stage)
#define BALLVIEW_CUDAVOLUMERENDERER_THROW(exceptionName, message)
virtual void renderToBufferImpl(FrameBufferPtr buffer)
boost::shared_ptr< FrameBuffer > FrameBufferPtr
Definition: renderTarget.h:222
BALL_EXPORT LogStream Log
unsigned int getHeight() const
Definition: renderTarget.h:100
const PixelFormat & getPixelFormat() const
Definition: renderTarget.h:112
static const PixelFormat RGBF_96
Definition: pixelFormat.h:201
unsigned int getWidth() const
Definition: renderTarget.h:92
LogStream & error(int n=0)
static const PixelFormat RGBA_32
Definition: pixelFormat.h:193
virtual bool init(const Scene &scene)