OpenVDB  2.0.0
RayTracer.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2013 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
43 
44 #ifndef OPENVDB_TOOLS_RAYTRACER_HAS_BEEN_INCLUDED
45 #define OPENVDB_TOOLS_RAYTRACER_HAS_BEEN_INCLUDED
46 
47 #include <openvdb/Types.h>
48 #include <openvdb/math/Ray.h>
49 #include <openvdb/math/Math.h>
50 #include <openvdb/tools/RayIntersector.h>
51 #include <boost/scoped_ptr.hpp>
52 #include <vector>
53 
54 #ifdef OPENVDB_TOOLS_RAYTRACER_USE_EXR
55 #include <OpenEXR/ImfPixelType.h>
56 #include <OpenEXR/ImfChannelList.h>
57 #include <OpenEXR/ImfOutputFile.h>
58 #include <OpenEXR/ImfHeader.h>
59 #include <OpenEXR/ImfFrameBuffer.h>
60 #endif
61 
62 namespace openvdb {
64 namespace OPENVDB_VERSION_NAME {
65 namespace tools {
66 
67 // Forward declarations
68 class BaseCamera;
69 class BaseShader;
70 
72 template<typename GridT>
73 inline void rayTrace(const GridT&,
74  const BaseShader&,
75  BaseCamera&,
76  size_t pixelSamples = 1,
77  unsigned int seed = 0,
78  bool threaded = true);
79 
81 template<typename GridT, typename IntersectorT>
82 inline void rayTrace(const GridT&,
83  const IntersectorT&,
84  const BaseShader&,
85  BaseCamera&,
86  size_t pixelSamples = 1,
87  unsigned int seed = 0,
88  bool threaded = true);
89 
90 
92 
95 template<typename GridT, typename IntersectorT = tools::LevelSetRayIntersector<GridT> >
97 {
98 public:
99  typedef GridT GridType;
100  typedef typename IntersectorT::Vec3Type Vec3Type;
101  typedef typename IntersectorT::RayType RayType;
102 
103  LevelSetRayTracer(const GridT& grid,
104  const BaseShader& shader,
105  BaseCamera& camera,
106  size_t pixelSamples = 1,
107  unsigned int seed = 0);
108  LevelSetRayTracer(const IntersectorT& inter,
109  const BaseShader& shader,
110  BaseCamera& camera,
111  size_t pixelSamples = 1,
112  unsigned int seed = 0);
113  LevelSetRayTracer(const LevelSetRayTracer& other);
115  void setGrid(const GridT& grid);
116  void setIntersector(const IntersectorT& inter);
117  void setShader(const BaseShader& shader);
118  void setCamera(BaseCamera& camera);
119  void setPixelSamples(size_t pixelSamples, unsigned int seed = 0);
120  void trace(bool threaded = true);
121  void operator()(const tbb::blocked_range<size_t>& range) const;
122 
123 private:
124  const bool mIsMaster;
125  double* mRand;
126  IntersectorT mInter;
127  boost::scoped_ptr<const BaseShader> mShader;
128  BaseCamera* mCamera;
129  size_t mSubPixels;
130 };// LevelSetRayTracer
131 
132 
134 
137 class Film
138 {
139 public:
142  struct RGBA
143  {
144  typedef float ValueT;
145 
146  RGBA() : r(0), g(0), b(0), a(1) {}
147  explicit RGBA(ValueT intensity) : r(intensity), g(intensity), b(intensity), a(1) {}
148  RGBA(ValueT _r, ValueT _g, ValueT _b, ValueT _a=1.0f) : r(_r), g(_g), b(_b), a(_a) {}
149 
150  RGBA operator* (ValueT scale) const { return RGBA(r*scale, g*scale, b*scale);}
151  RGBA operator+ (const RGBA& rhs) const { return RGBA(r+rhs.r, g+rhs.g, b+rhs.b);}
152  RGBA operator* (const RGBA& rhs) const { return RGBA(r*rhs.r, g*rhs.g, b*rhs.b);}
153  RGBA& operator+=(const RGBA& rhs) { r+=rhs.r; g+=rhs.g; b+=rhs.b, a+=rhs.a; return *this;}
154 
155  void over(const RGBA& rhs)
156  {
157  const float s = rhs.a*(1.0f-a);
158  r = a*r+s*rhs.r;
159  g = a*g+s*rhs.g;
160  b = a*b+s*rhs.b;
161  a = a + s;
162  }
163 
164  ValueT r, g, b, a;
165  };
166 
167 
168  Film(size_t width, size_t height)
169  : mWidth(width), mHeight(height), mSize(width*height), mPixels(new RGBA[mSize])
170  {
171  }
172  Film(size_t width, size_t height, const RGBA& bg)
173  : mWidth(width), mHeight(height), mSize(width*height), mPixels(new RGBA[mSize])
174  {
175  this->fill(bg);
176  }
177  ~Film() { delete mPixels; }
178 
179  const RGBA& pixel(size_t w, size_t h) const
180  {
181  assert(w < mWidth);
182  assert(h < mHeight);
183  return mPixels[w + h*mWidth];
184  }
185 
186  RGBA& pixel(size_t w, size_t h)
187  {
188  assert(w < mWidth);
189  assert(h < mHeight);
190  return mPixels[w + h*mWidth];
191  }
192 
193  void fill(const RGBA& rgb=RGBA(0)) { for (size_t i=0; i<mSize; ++i) mPixels[i] = rgb; }
194  void checkerboard(const RGBA& c1=RGBA(0.3f), const RGBA& c2=RGBA(0.6f), size_t size=32)
195  {
196  RGBA *p = mPixels;
197  for (size_t j = 0; j < mHeight; ++j) {
198  for (size_t i = 0; i < mWidth; ++i, ++p) {
199  *p = ((i & size) ^ (j & size)) ? c1 : c2;
200  }
201  }
202  }
203 
204  void savePPM(const std::string& fileName)
205  {
206  std::string name(fileName + ".ppm");
207  unsigned char* tmp = new unsigned char[3*mSize], *q = tmp;
208  RGBA* p = mPixels;
209  size_t n = mSize;
210  while (n--) {
211  *q++ = static_cast<unsigned char>(255.0f*(*p ).r);
212  *q++ = static_cast<unsigned char>(255.0f*(*p ).g);
213  *q++ = static_cast<unsigned char>(255.0f*(*p++).b);
214  }
215 
216  std::ofstream os(name.c_str(), std::ios_base::binary);
217  if (!os.is_open()) {
218  std::cerr << "Error opening PPM file \"" << name << "\"" << std::endl;
219  return;
220  }
221 
222  os << "P6\n" << mWidth << " " << mHeight << "\n255\n";
223  os.write((const char *)&(*tmp), 3*mSize*sizeof(unsigned char));
224  delete [] tmp;
225  }
226 
227 #ifdef OPENVDB_TOOLS_RAYTRACER_USE_EXR
228  void saveEXR(const std::string& fileName, size_t compression = 2, size_t threads = 8)
229  {
230  std::string name(fileName + ".exr");
231 
232  if (threads>0) Imf::setGlobalThreadCount(threads);
233  Imf::Header header(mWidth, mHeight);
234  if (compression==0) header.compression() = Imf::NO_COMPRESSION;
235  if (compression==1) header.compression() = Imf::RLE_COMPRESSION;
236  if (compression>=2) header.compression() = Imf::ZIP_COMPRESSION;
237  header.channels().insert("R", Imf::Channel(Imf::FLOAT));
238  header.channels().insert("G", Imf::Channel(Imf::FLOAT));
239  header.channels().insert("B", Imf::Channel(Imf::FLOAT));
240  header.channels().insert("A", Imf::Channel(Imf::FLOAT));
241 
242  Imf::FrameBuffer framebuffer;
243  framebuffer.insert("R", Imf::Slice( Imf::FLOAT, (char *) &(mPixels[0].r),
244  sizeof (RGBA), sizeof (RGBA) * mWidth));
245  framebuffer.insert("G", Imf::Slice( Imf::FLOAT, (char *) &(mPixels[0].g),
246  sizeof (RGBA), sizeof (RGBA) * mWidth));
247  framebuffer.insert("B", Imf::Slice( Imf::FLOAT, (char *) &(mPixels[0].b),
248  sizeof (RGBA), sizeof (RGBA) * mWidth));
249  framebuffer.insert("A", Imf::Slice( Imf::FLOAT, (char *) &(mPixels[0].a),
250  sizeof (RGBA), sizeof (RGBA) * mWidth));
251 
252  Imf::OutputFile file(name.c_str(), header);
253  file.setFrameBuffer(framebuffer);
254  file.writePixels(mHeight);
255  }
256 #endif
257 
258  size_t width() const { return mWidth; }
259  size_t height() const { return mHeight; }
260  size_t numPixels() const { return mSize; }
261  const RGBA* pixels() const { return mPixels; }
262 
263 private:
264  size_t mWidth, mHeight, mSize;
265  RGBA* mPixels;
266 };// Film
267 
268 
270 
273 {
274 public:
275  BaseCamera(Film& film, const Vec3R& rotation, const Vec3R& translation,
276  double frameWidth, double nearPlane, double farPlane)
277  : mFilm(&film)
278  , mScaleWidth(frameWidth)
279  , mScaleHeight(frameWidth*film.height()/double(film.width()))
280  {
281  assert(nearPlane > 0 && farPlane > nearPlane);
282  mScreenToWorld.accumPostRotation(math::X_AXIS, rotation[0] * M_PI / 180.0);
283  mScreenToWorld.accumPostRotation(math::Y_AXIS, rotation[1] * M_PI / 180.0);
284  mScreenToWorld.accumPostRotation(math::Z_AXIS, rotation[2] * M_PI / 180.0);
285  mScreenToWorld.accumPostTranslation(translation);
286  this->initRay(nearPlane, farPlane);
287  }
288 
289  virtual ~BaseCamera() {}
290 
291  Film::RGBA& pixel(size_t i, size_t j) { return mFilm->pixel(i, j); }
292 
293  size_t width() const { return mFilm->width(); }
294  size_t height() const { return mFilm->height(); }
295 
300  void lookAt(const Vec3R& xyz, const Vec3R& up = Vec3R(0.0, 1.0, 0.0))
301  {
302  const Vec3R orig = mScreenToWorld.applyMap(Vec3R(0.0));
303  const Vec3R dir = orig - xyz;
304  try {
305  Mat4d xform = math::aim<Mat4d>(dir, up);
306  xform.postTranslate(orig);
307  mScreenToWorld = math::AffineMap(xform);
308  this->initRay(mRay.t0(), mRay.t1());
309  } catch (...) {}
310  }
311 
312  Vec3R rasterToScreen(double i, double j, double z) const
313  {
314  return Vec3R( (2 * i / mFilm->width() - 1) * mScaleWidth,
315  (1 - 2 * j / mFilm->height()) * mScaleHeight, z );
316  }
317 
321  virtual math::Ray<double> getRay(
322  size_t i, size_t j, double iOffset = 0.5, double jOffset = 0.5) const = 0;
323 
324 protected:
325  void initRay(double znear, double zfar)
326  {
327  mRay.setTimes(znear, zfar);
328  mRay.setEye(mScreenToWorld.applyMap(Vec3R(0.0)));
329  mRay.setDir(mScreenToWorld.applyJacobian(Vec3R(0.0, 0.0, -1.0)));
330  }
331 
333  double mScaleWidth, mScaleHeight;
336 };// BaseCamera
337 
338 
340 {
341  public:
358  const Vec3R& rotation = Vec3R(0.0),
359  const Vec3R& translation = Vec3R(0.0),
360  double focalLength = 50.0,
361  double aperture = 41.2136,
362  double nearPlane = 1e-3,
363  double farPlane = std::numeric_limits<double>::max())
364  : BaseCamera(film, rotation, translation, 0.5*aperture/focalLength, nearPlane, farPlane)
365  {
366  }
367 
368  virtual ~PerspectiveCamera() {}
369 
374  size_t i, size_t j, double iOffset = 0.5, double jOffset = 0.5) const
375  {
376  math::Ray<double> ray(mRay);
377  Vec3R dir = BaseCamera::rasterToScreen(i + iOffset, j + jOffset, -1.0);
378  dir = BaseCamera::mScreenToWorld.applyJacobian(dir);
379  dir.normalize();
380  ray.scaleTimes(1.0/dir.dot(ray.dir()));
381  ray.setDir(dir);
382  return ray;
383  }
384 
387  static double focalLengthToFieldOfView(double length, double aperture)
388  {
389  return 360.0 / M_PI * atan(aperture/(2.0*length));
390  }
393  static double fieldOfViewToFocalLength(double fov, double aperture)
394  {
395  return aperture/(2.0*(tan(fov * M_PI / 360.0)));
396  }
397 };// PerspectiveCamera
398 
399 
401 {
402 public:
416  const Vec3R& rotation = Vec3R(0.0),
417  const Vec3R& translation = Vec3R(0.0),
418  double frameWidth = 1.0,
419  double nearPlane = 1e-3,
420  double farPlane = std::numeric_limits<double>::max())
421  : BaseCamera(film, rotation, translation, 0.5*frameWidth, nearPlane, farPlane)
422  {
423  }
424  virtual ~OrthographicCamera() {}
425 
427  size_t i, size_t j, double iOffset = 0.5, double jOffset = 0.5) const
428  {
429  math::Ray<double> ray(mRay);
430  Vec3R eye = BaseCamera::rasterToScreen(i + iOffset, j + jOffset, 0.0);
431  ray.setEye(BaseCamera::mScreenToWorld.applyMap(eye));
432  return ray;
433  }
434 };// OrthographicCamera
435 
436 
438 
439 
442 {
443 public:
446  virtual ~BaseShader() {}
447  virtual Film::RGBA operator()(const Vec3R&, const Vec3R&, const RayT&) const = 0;
448  virtual BaseShader* copy() const = 0;
449 };
450 
451 
453 class MatteShader: public BaseShader
454 {
455 public:
456  MatteShader(const Film::RGBA& c = Film::RGBA(1.0f)): mRGBA(c) {}
457  virtual ~MatteShader() {}
458  virtual Film::RGBA operator()(const Vec3R&, const Vec3R&, const BaseShader::RayT&) const
459  {
460  return mRGBA;
461  }
462  virtual BaseShader* copy() const { return new MatteShader(*this); }
463 
464 private:
465  const Film::RGBA mRGBA;
466 };
467 
468 
471 {
472 public:
473  NormalShader(const Film::RGBA& c = Film::RGBA(1.0f)) : mRGBA(c*0.5f) {}
474  virtual ~NormalShader() {}
475  virtual Film::RGBA operator()(const Vec3R&, const Vec3R& normal, const BaseShader::RayT&) const
476  {
477  return mRGBA*Film::RGBA(normal[0]+1.0f, normal[1]+1.0f, normal[2]+1.0f);
478  }
479  virtual BaseShader* copy() const { return new NormalShader(*this); }
480 
481 private:
482  const Film::RGBA mRGBA;
483 };
484 
485 
492 {
493 public:
494  DiffuseShader(const Film::RGBA& d = Film::RGBA(1.0f)): mRGBA(d) {}
495  virtual Film::RGBA operator()(const Vec3R&, const Vec3R& normal,
496  const BaseShader::RayT& ray) const
497  {
498  // We assume a single directional light source at the camera,
499  // so the cosine of the angle between the surface normal and the
500  // direction of the light source becomes the dot product of the
501  // surface normal and inverse direction of the ray. We also ignore
502  // negative dot products, corresponding to strict one-sided shading.
503  //return mRGBA * math::Max(0.0, normal.dot(-ray.dir()));
504 
505  // We take the abs of the dot product corresponding to having
506  // light sources at +/- ray.dir(), i.e., two-sided shading.
507  return mRGBA * math::Abs(normal.dot(ray.dir()));
508  }
509  virtual BaseShader* copy() const { return new DiffuseShader(*this); }
510 
511 private:
512  const Film::RGBA mRGBA;
513 };
514 
515 
517 
518 template<typename GridT>
519 inline void rayTrace(const GridT& grid,
520  const BaseShader& shader,
521  BaseCamera& camera,
522  size_t pixelSamples,
523  unsigned int seed,
524  bool threaded)
525 {
527  tracer(grid, shader, camera, pixelSamples, seed);
528  tracer.trace(threaded);
529 }
530 
531 
532 template<typename GridT, typename IntersectorT>
533 inline void rayTrace(const GridT&,
534  const IntersectorT& inter,
535  const BaseShader& shader,
536  BaseCamera& camera,
537  size_t pixelSamples,
538  unsigned int seed,
539  bool threaded)
540 {
541  LevelSetRayTracer<GridT, IntersectorT> tracer(inter, shader, camera, pixelSamples, seed);
542  tracer.trace(threaded);
543 }
544 
545 
547 
548 
549 template<typename GridT, typename IntersectorT>
550 inline LevelSetRayTracer<GridT, IntersectorT>::
551 LevelSetRayTracer(const GridT& grid,
552  const BaseShader& shader,
553  BaseCamera& camera,
554  size_t pixelSamples,
555  unsigned int seed)
556  : mIsMaster(true),
557  mRand(NULL),
558  mInter(grid),
559  mShader(shader.copy()),
560  mCamera(&camera)
561 {
562  this->setPixelSamples(pixelSamples, seed);
563 }
564 
565 template<typename GridT, typename IntersectorT>
567 LevelSetRayTracer(const IntersectorT& inter,
568  const BaseShader& shader,
569  BaseCamera& camera,
570  size_t pixelSamples,
571  unsigned int seed)
572  : mIsMaster(true),
573  mRand(NULL),
574  mInter(inter),
575  mShader(shader.copy()),
576  mCamera(&camera)
577 {
578  this->setPixelSamples(pixelSamples, seed);
579 }
580 
581 template<typename GridT, typename IntersectorT>
584  mIsMaster(false),
585  mRand(other.mRand),
586  mInter(other.mInter),
587  mShader(other.mShader->copy()),
588  mCamera(other.mCamera),
589  mSubPixels(other.mSubPixels)
590 {
591 }
592 
593 template<typename GridT, typename IntersectorT>
596 {
597  if (mIsMaster) delete [] mRand;
598 }
599 
600 template<typename GridT, typename IntersectorT>
602 setGrid(const GridT& grid)
603 {
604  assert(mIsMaster);
605  mInter = IntersectorT(grid);
606 }
607 
608 template<typename GridT, typename IntersectorT>
610 setIntersector(const IntersectorT& inter)
611 {
612  assert(mIsMaster);
613  mInter = inter;
614 }
615 
616 template<typename GridT, typename IntersectorT>
618 setShader(const BaseShader& shader)
619 {
620  assert(mIsMaster);
621  mShader.reset(shader.copy());
622 }
623 
624 template<typename GridT, typename IntersectorT>
627 {
628  assert(mIsMaster);
629  mCamera = &camera;
630 }
631 
632 template<typename GridT, typename IntersectorT>
634 setPixelSamples(size_t pixelSamples, unsigned int seed)
635 {
636  assert(mIsMaster);
637  assert(pixelSamples>0);
638  mSubPixels = pixelSamples - 1;
639  delete [] mRand;
640  if (mSubPixels > 0) {
641  mRand = new double[16];
642  math::Rand01<double> rand(seed);//offsets for anti-aliaing by jittered super-sampling
643  for (size_t i=0; i<16; ++i) mRand[i] = rand();
644  } else {
645  mRand = NULL;
646  }
647 }
648 
649 template<typename GridT, typename IntersectorT>
651 trace(bool threaded)
652 {
653  tbb::blocked_range<size_t> range(0, mCamera->height());
654  threaded ? tbb::parallel_for(range, *this) : (*this)(range);
655 }
656 
657 template<typename GridT, typename IntersectorT>
659 operator()(const tbb::blocked_range<size_t>& range) const
660 {
661  Vec3Type xyz, nml;
662  const float frac = 1.0f / (1.0f + mSubPixels);
663  for (size_t j=range.begin(), n=0, je = range.end(); j<je; ++j) {
664  for (size_t i=0, ie = mCamera->width(); i<ie; ++i) {
665  Film::RGBA& bg = mCamera->pixel(i,j);
666  RayType ray = mCamera->getRay(i, j);//primary ray
667  Film::RGBA c = mInter.intersectsWS(ray, xyz, nml) ? (*mShader)(xyz, nml, ray) : bg;
668  for (size_t k=0; k<mSubPixels; ++k, n +=2 ) {
669  ray = mCamera->getRay(i, j, mRand[n & 15], mRand[n+1 & 15]);
670  c += mInter.intersectsWS(ray, xyz, nml) ? (*mShader)(xyz, nml, ray) : bg;
671  }//loop over sub-pixels
672  bg = c*frac;
673  }//loop over image height
674  }//loop over image width
675 }
676 
677 } // namespace tools
678 } // namespace OPENVDB_VERSION_NAME
679 } // namespace openvdb
680 
681 #endif // OPENVDB_TOOLS_RAYTRACER_HAS_BEEN_INCLUDED
682 
683 // Copyright (c) 2012-2013 DreamWorks Animation LLC
684 // All rights reserved. This software is distributed under the
685 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
virtual ~PerspectiveCamera()
Definition: RayTracer.h:368
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
void rayTrace(const GridT &, const BaseShader &, BaseCamera &, size_t pixelSamples=1, unsigned int seed=0, bool threaded=true)
Ray-trace a volume.
Definition: RayTracer.h:519
float ValueT
Definition: RayTracer.h:144
ValueT a
Definition: RayTracer.h:164
A simple class that allows for concurrent writes to pixels in an image, background initialization of ...
Definition: RayTracer.h:137
Floating-point RGBA components in the range [0, 1].
Definition: RayTracer.h:142
LevelSetRayTracer(const GridT &grid, const BaseShader &shader, BaseCamera &camera, size_t pixelSamples=1, unsigned int seed=0)
Definition: RayTracer.h:551
Film(size_t width, size_t height)
Definition: RayTracer.h:168
virtual Film::RGBA operator()(const Vec3R &, const Vec3R &normal, const BaseShader::RayT &) const
Definition: RayTracer.h:475
BaseShader()
Definition: RayTracer.h:445
virtual Film::RGBA operator()(const Vec3R &, const Vec3R &, const BaseShader::RayT &) const
Definition: RayTracer.h:458
void postTranslate(const Vec3< T0 > &tr)
Right multiplies by the specified translation matrix, i.e. (*this) * Trans.
Definition: Mat4.h:728
ValueT g
Definition: RayTracer.h:164
virtual BaseShader * copy() const =0
Abstract base class for the shaders.
Definition: RayTracer.h:441
virtual Film::RGBA operator()(const Vec3R &, const Vec3R &normal, const BaseShader::RayT &ray) const
Definition: RayTracer.h:495
RGBA(ValueT intensity)
Definition: RayTracer.h:147
void operator()(const tbb::blocked_range< size_t > &range) const
Definition: RayTracer.h:659
void over(const RGBA &rhs)
Definition: RayTracer.h:155
void lookAt(const Vec3R &xyz, const Vec3R &up=Vec3R(0.0, 1.0, 0.0))
Definition: RayTracer.h:300
double mScaleWidth
Definition: RayTracer.h:333
Abstract base class for the perspective and orthographic cameras.
Definition: RayTracer.h:272
size_t numPixels() const
Definition: RayTracer.h:260
RGBA()
Definition: RayTracer.h:146
GridT GridType
Definition: RayTracer.h:99
void setDir(const Vec3Type &dir)
Definition: Ray.h:69
void setShader(const BaseShader &shader)
Definition: RayTracer.h:618
MatteShader(const Film::RGBA &c=Film::RGBA(1.0f))
Definition: RayTracer.h:456
MatType rotation(const Quat< typename MatType::value_type > &q, typename MatType::value_type eps=1.0e-8)
Definition: Mat.h:157
A (very) simple multithreaded ray tracer specifically for narrow-band level sets. ...
Definition: RayTracer.h:96
void trace(bool threaded=true)
Definition: RayTracer.h:651
virtual math::Ray< double > getRay(size_t i, size_t j, double iOffset=0.5, double jOffset=0.5) const
Return a Ray in world space given the pixel indices and optional offsets in the range [0...
Definition: RayTracer.h:426
~Film()
Definition: RayTracer.h:177
virtual ~BaseCamera()
Definition: RayTracer.h:289
Definition: Math.h:764
virtual BaseShader * copy() const
Definition: RayTracer.h:479
Film * mFilm
Definition: RayTracer.h:332
~LevelSetRayTracer()
Definition: RayTracer.h:595
NormalShader(const Film::RGBA &c=Film::RGBA(1.0f))
Definition: RayTracer.h:473
void initRay(double znear, double zfar)
Definition: RayTracer.h:325
void setIntersector(const IntersectorT &inter)
Definition: RayTracer.h:610
const RGBA & pixel(size_t w, size_t h) const
Definition: RayTracer.h:179
math::Ray< Real > RayT
Definition: RayTracer.h:444
void setPixelSamples(size_t pixelSamples, unsigned int seed=0)
Definition: RayTracer.h:634
Definition: Math.h:763
static double focalLengthToFieldOfView(double length, double aperture)
Return the horizontal field of view in degrees given a focal lenth in mm and the specified aperture i...
Definition: RayTracer.h:387
size_t height() const
Definition: RayTracer.h:259
void checkerboard(const RGBA &c1=RGBA(0.3f), const RGBA &c2=RGBA(0.6f), size_t size=32)
Definition: RayTracer.h:194
ValueT r
Definition: RayTracer.h:164
BaseCamera(Film &film, const Vec3R &rotation, const Vec3R &translation, double frameWidth, double nearPlane, double farPlane)
Definition: RayTracer.h:275
#define OPENVDB_VERSION_NAME
Definition: version.h:45
IntersectorT::RayType RayType
Definition: RayTracer.h:101
Vec3R rasterToScreen(double i, double j, double z) const
Definition: RayTracer.h:312
math::Vec3< Real > Vec3R
Definition: Types.h:74
OrthographicCamera(Film &film, const Vec3R &rotation=Vec3R(0.0), const Vec3R &translation=Vec3R(0.0), double frameWidth=1.0, double nearPlane=1e-3, double farPlane=std::numeric_limits< double >::max())
Constructor.
Definition: RayTracer.h:415
Simple generator of random numbers over the range [0, 1)
Definition: Math.h:136
virtual ~OrthographicCamera()
Definition: RayTracer.h:424
void setCamera(BaseCamera &camera)
Definition: RayTracer.h:626
Simple diffuse Lambertian surface shader.
Definition: RayTracer.h:491
Vec3< typename promote< T, typename Coord::ValueType >::type > operator+(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be added to or subtracted from a Vec3.
Definition: Coord.h:382
A general linear transform using homogeneous coordinates to perform rotation, scaling, shear and translation.
Definition: Maps.h:323
T dot(const Vec3< T > &v) const
Dot product.
Definition: Vec3.h:199
bool normalize(T eps=T(1.0e-7))
this = normalized this
Definition: Vec3.h:328
math::Ray< double > mRay
Definition: RayTracer.h:334
IntersectorT::Vec3Type Vec3Type
Definition: RayTracer.h:100
Color shader that treats the surface normal (x, y, z) as an RGB color.
Definition: RayTracer.h:470
void savePPM(const std::string &fileName)
Definition: RayTracer.h:204
virtual BaseShader * copy() const
Definition: RayTracer.h:509
size_t height() const
Definition: RayTracer.h:294
void setGrid(const GridT &grid)
Definition: RayTracer.h:602
Definition: Math.h:765
ValueT b
Definition: RayTracer.h:164
math::AffineMap mScreenToWorld
Definition: RayTracer.h:335
static double fieldOfViewToFocalLength(double fov, double aperture)
Return the focal length in mm given a horizontal field of view in degrees and the specified aperture ...
Definition: RayTracer.h:393
RGBA & operator+=(const RGBA &rhs)
Definition: RayTracer.h:153
size_t width() const
Definition: RayTracer.h:293
MatType scale(const Vec3< typename MatType::value_type > &scaling)
Definition: Mat.h:595
RGBA & pixel(size_t w, size_t h)
Definition: RayTracer.h:186
PerspectiveCamera(Film &film, const Vec3R &rotation=Vec3R(0.0), const Vec3R &translation=Vec3R(0.0), double focalLength=50.0, double aperture=41.2136, double nearPlane=1e-3, double farPlane=std::numeric_limits< double >::max())
Constructor.
Definition: RayTracer.h:357
DiffuseShader(const Film::RGBA &d=Film::RGBA(1.0f))
Definition: RayTracer.h:494
const RGBA * pixels() const
Definition: RayTracer.h:261
const Vec3T & dir() const
Definition: Ray.h:93
void setEye(const Vec3Type &eye)
Definition: Ray.h:67
virtual ~BaseShader()
Definition: RayTracer.h:446
int32_t Abs(int32_t i)
Return the absolute value of the given quantity.
Definition: Math.h:246
void scaleTimes(RealT scale)
Definition: Ray.h:81
Film(size_t width, size_t height, const RGBA &bg)
Definition: RayTracer.h:172
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:56
Shader that produces a simple matte.
Definition: RayTracer.h:453
virtual math::Ray< double > getRay(size_t i, size_t j, double iOffset=0.5, double jOffset=0.5) const
Return a Ray in world space given the pixel indices and optional offsets in the range [0...
Definition: RayTracer.h:373
RGBA(ValueT _r, ValueT _g, ValueT _b, ValueT _a=1.0f)
Definition: RayTracer.h:148
virtual BaseShader * copy() const
Definition: RayTracer.h:462
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Matrix multiplication.
Definition: Mat3.h:608
virtual ~NormalShader()
Definition: RayTracer.h:474
size_t width() const
Definition: RayTracer.h:258
virtual ~MatteShader()
Definition: RayTracer.h:457
Film::RGBA & pixel(size_t i, size_t j)
Definition: RayTracer.h:291
void fill(const RGBA &rgb=RGBA(0))
Definition: RayTracer.h:193