Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
point.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Mitsuba is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #if !defined(__MITSUBA_CORE_POINT_H_)
21 #define __MITSUBA_CORE_POINT_H_
22 
23 #include <mitsuba/core/vector.h>
24 
26 
27 /**
28  * \headerfile mitsuba/core/point.h mitsuba/mitsuba.h
29  * \brief Parameterizable one-dimensional point data structure
30  *
31  * \ingroup libcore
32  */
33 template <typename T> struct TPoint1 {
34  typedef T Scalar;
36 
37  T x;
38 
39  /// Number of dimensions
40  const static int dim = 1;
41 
42  /** \brief Construct a new point without initializing it.
43  *
44  * This construtor is useful when the point will either not
45  * be used at all (it might be part of a larger data structure)
46  * or initialized at a later point in time. Always make sure
47  * that one of the two is the case! Otherwise your program will do
48  * computations involving uninitialized memory, which will probably
49  * lead to a difficult-to-find bug.
50  */
51 #if !defined(MTS_DEBUG_UNINITIALIZED)
52  TPoint1() { }
53 #else
54  TPoint1() { x = std::numeric_limits<T>::quiet_NaN(); }
55 #endif
56 
57  /// Initialize the point with the specified value
58  TPoint1(T x) : x(x) { }
59 
60  /// Initialize the point with the components of another point
61  template <typename T1> explicit TPoint1(const TPoint1<T1> &p)
62  : x((T) p.x) { }
63 
64  /// Initialize the point with the components of a vector data structure
65  template <typename T1> explicit TPoint1(const TVector1<T1> &v)
66  : x((T) v.x) { }
67 
68  /// Unserialize a point from a binary data stream
69  explicit TPoint1(Stream *stream) {
70  x = stream->readElement<T>();
71  }
72 
73  /// Add a vector to a point and return the result
74  TPoint1 operator+(const TVector1<T> &v) const {
75  return TPoint1(x + v.x);
76  }
77 
78  /// Add two points and return the result (e.g. to compute a weighted position)
79  TPoint1 operator+(const TPoint1 &p) const {
80  return TPoint1(x + p.x);
81  }
82 
83  /// Add a vector to this one (e.g. to compute a weighted position)
85  x += v.x;
86  return *this;
87  }
88 
89  /// Add a point to this one (e.g. to compute a weighted position)
90  TPoint1& operator+=(const TPoint1 &p) {
91  x += p.x;
92  return *this;
93  }
94 
95  /// Subtract a vector from this point
96  TPoint1 operator-(const TVector1<T> &v) const {
97  return TPoint1(x - v.x);
98  }
99 
100  /// Subtract two points from each other and return the difference as a vector
101  TVector1<T> operator-(const TPoint1 &p) const {
102  return TVector1<T>(x - p.x);
103  }
104 
105  /// Subtract a vector from this point
107  x -= v.x;
108  return *this;
109  }
110 
111  /// Scale the point's coordinates by the given scalar and return the result
112  TPoint1 operator*(T f) const {
113  return TPoint1(x * f);
114  }
115 
116  /// Scale the point's coordinates by the given scalar
118  x *= f;
119  return *this;
120  }
121 
122  /// Return a version of the point, which has been flipped along the origin
123  TPoint1 operator-() const {
124  return TPoint1(-x);
125  }
126 
127  /// Divide the point's coordinates by the given scalar and return the result
128  TPoint1 operator/(T f) const {
129 #ifdef MTS_DEBUG
130  if (f == 0)
131  SLog(EWarn, "Point1: Division by zero!");
132 #endif
133  return TPoint1(x / f);
134  }
135 
136  /// Divide the point's coordinates by the given scalar
138 #ifdef MTS_DEBUG
139  if (f == 0)
140  SLog(EWarn, "Point1: Division by zero!");
141 #endif
142  x /= f;
143  return *this;
144  }
145 
146  /// Index into the point's components
147  T &operator[](int i) {
148  return (&x)[i];
149  }
150 
151  /// Index into the point's components (const version)
152  T operator[](int i) const {
153  return (&x)[i];
154  }
155 
156  /// Return whether or not this point is identically zero
157  bool isZero() const {
158  return x == 0;
159  }
160 
161  /// Equality test
162  bool operator==(const TPoint1 &v) const {
163  return (v.x == x);
164  }
165 
166  /// Inequality test
167  bool operator!=(const TPoint1 &v) const {
168  return v.x != x;
169  }
170 
171  /// Serialize this point to a binary data stream
172  void serialize(Stream *stream) const {
173  stream->writeElement<T>(x);
174  }
175 
176  /// Implicit conversion to Scalar
177  operator Scalar() const { return x; }
178 
179  /// Return a readable string representation of this point
180  std::string toString() const {
181  std::ostringstream oss;
182  oss << "[" << x << "]";
183  return oss.str();
184  }
185 };
186 
187 template <typename T> inline TPoint1<T> operator*(T f, const TPoint1<T> &v) {
188  return v*f;
189 }
190 
191 template <typename T> inline T distance(const TPoint1<T> &p1, const TPoint1<T> &p2) {
192  return std::abs(p2.x-p2.x);
193 }
194 
195 template <typename T> inline T distanceSquared(const TPoint1<T> &p1, const TPoint1<T> &p2) {
196  return (p1-p2).lengthSquared();
197 }
198 
199 template <> inline TPoint1<int> TPoint1<int>::operator/(int s) const {
200 #ifdef MTS_DEBUG
201  if (s == 0)
202  SLog(EWarn, "Point1i: Division by zero!");
203 #endif
204  return TPoint1(x/s);
205 }
206 
207 template <> inline TPoint1<int> &TPoint1<int>::operator/=(int s) {
208 #ifdef MTS_DEBUG
209  if (s == 0)
210  SLog(EWarn, "Point1i: Division by zero!");
211 #endif
212  x /= s;
213  return *this;
214 }
215 
216 /**
217  * \headerfile mitsuba/core/point.h mitsuba/mitsuba.h
218  * \brief Parameterizable two-dimensional point data structure
219  *
220  * \ingroup libcore
221  */
222 template <typename T> struct TPoint2 {
223  typedef T Scalar;
225 
226  T x, y;
227 
228  /// Number of dimensions
229  const static int dim = 2;
230 
231  /** \brief Construct a new point without initializing it.
232  *
233  * This construtor is useful when the point will either not
234  * be used at all (it might be part of a larger data structure)
235  * or initialized at a later point in time. Always make sure
236  * that one of the two is the case! Otherwise your program will do
237  * computations involving uninitialized memory, which will probably
238  * lead to a difficult-to-find bug.
239  */
240 #if !defined(MTS_DEBUG_UNINITIALIZED)
241  TPoint2() { }
242 #else
243  TPoint2() { x = y = std::numeric_limits<T>::quiet_NaN(); }
244 #endif
245 
246  /// Initialize the point with the specified X, Y and Z components
247  TPoint2(T x, T y) : x(x), y(y) { }
248 
249  /// Initialize the point with the components of another point
250  template <typename T2> explicit TPoint2(const TPoint2<T2> &p)
251  : x((T) p.x), y((T) p.y) { }
252 
253  /// Initialize the point with the components of a vector data structure
254  template <typename T2> explicit TPoint2(const TVector2<T2> &v)
255  : x((T) v.x), y((T) v.y) { }
256 
257  /// Initialize all components of the the point with the specified value
258  explicit TPoint2(T val) : x(val), y(val) { }
259 
260  /// Unserialize a point from a binary data stream
261  explicit TPoint2(Stream *stream) {
262  x = stream->readElement<T>();
263  y = stream->readElement<T>();
264  }
265 
266  /// Add a vector to a point and return the result
267  TPoint2 operator+(const TVector2<T> &v) const {
268  return TPoint2(x + v.x, y + v.y);
269  }
270 
271  /// Add two points and return the result (e.g. to compute a weighted position)
272  TPoint2 operator+(const TPoint2 &p) const {
273  return TPoint2(x + p.x, y + p.y);
274  }
275 
276  /// Add a vector to this one (e.g. to compute a weighted position)
278  x += v.x; y += v.y;
279  return *this;
280  }
281 
282  /// Add a point to this one (e.g. to compute a weighted position)
284  x += p.x; y += p.y;
285  return *this;
286  }
287 
288  /// Subtract a vector from this point
289  TPoint2 operator-(const TVector2<T> &v) const {
290  return TPoint2(x - v.x, y - v.y);
291  }
292 
293  /// Subtract two points from each other and return the difference as a vector
294  TVector2<T> operator-(const TPoint2 &p) const {
295  return TVector2<T>(x - p.x, y - p.y);
296  }
297 
298  /// Subtract a vector from this point
300  x -= v.x; y -= v.y;
301  return *this;
302  }
303 
304  /// Scale the point's coordinates by the given scalar and return the result
305  TPoint2 operator*(T f) const {
306  return TPoint2(x * f, y * f);
307  }
308 
309  /// Scale the point's coordinates by the given scalar
311  x *= f; y *= f;
312  return *this;
313  }
314 
315  /// Return a version of the point, which has been flipped along the origin
316  TPoint2 operator-() const {
317  return TPoint2(-x, -y);
318  }
319 
320  /// Divide the point's coordinates by the given scalar and return the result
321  TPoint2 operator/(T f) const {
322 #ifdef MTS_DEBUG
323  if (f == 0)
324  SLog(EWarn, "Point2: Division by zero!");
325 #endif
326  T recip = (T) 1 / f;
327  return TPoint2(x * recip, y * recip);
328  }
329 
330  /// Divide the point's coordinates by the given scalar
332 #ifdef MTS_DEBUG
333  if (f == 0)
334  SLog(EWarn, "Point2: Division by zero!");
335 #endif
336  T recip = (T) 1 / f;
337  x *= recip; y *= recip;
338  return *this;
339  }
340 
341  /// Index into the point's components
342  T &operator[](int i) {
343  return (&x)[i];
344  }
345 
346  /// Index into the point's components (const version)
347  T operator[](int i) const {
348  return (&x)[i];
349  }
350 
351  /// Return whether or not this point is identically zero
352  bool isZero() const {
353  return x == 0 && y == 0;
354  }
355 
356  /// Equality test
357  bool operator==(const TPoint2 &v) const {
358  return (v.x == x && v.y == y);
359  }
360 
361  /// Inequality test
362  bool operator!=(const TPoint2 &v) const {
363  return v.x != x || v.y != y;
364  }
365 
366  /// Serialize this point to a binary data stream
367  void serialize(Stream *stream) const {
368  stream->writeElement<T>(x);
369  stream->writeElement<T>(y);
370  }
371 
372  /// Return a readable string representation of this point
373  std::string toString() const {
374  std::ostringstream oss;
375  oss << "[" << x << ", " << y << "]";
376  return oss.str();
377  }
378 };
379 
380 template <typename T> inline TPoint2<T> operator*(T f, const TPoint2<T> &v) {
381  return v*f;
382 }
383 
384 template <typename T> inline T distance(const TPoint2<T> &p1, const TPoint2<T> &p2) {
385  return (p1-p2).length();
386 }
387 
388 template <typename T> inline T distanceSquared(const TPoint2<T> &p1, const TPoint2<T> &p2) {
389  return (p1-p2).lengthSquared();
390 }
391 
392 template <> inline TPoint2<int> TPoint2<int>::operator/(int s) const {
393 #ifdef MTS_DEBUG
394  if (s == 0)
395  SLog(EWarn, "Point2i: Division by zero!");
396 #endif
397  return TPoint2(x/s, y/s);
398 }
399 
400 template <> inline TPoint2<int> &TPoint2<int>::operator/=(int s) {
401 #ifdef MTS_DEBUG
402  if (s == 0)
403  SLog(EWarn, "Point2i: Division by zero!");
404 #endif
405  x /= s;
406  y /= s;
407  return *this;
408 }
409 
410 /**
411  * \headerfile mitsuba/core/point.h mitsuba/mitsuba.h
412  * \brief Parameterizable three-dimensional point data structure
413  * \ingroup libcore
414  */
415 template <typename T> struct TPoint3 {
416  typedef T Scalar;
418 
419  T x, y, z;
420 
421  /// Number of dimensions
422  const static int dim = 3;
423 
424  /** \brief Construct a new point without initializing it.
425  *
426  * This construtor is useful when the point will either not
427  * be used at all (it might be part of a larger data structure)
428  * or initialized at a later point in time. Always make sure
429  * that one of the two is the case! Otherwise your program will do
430  * computations involving uninitialized memory, which will probably
431  * lead to a difficult-to-find bug.
432  */
433 #if !defined(MTS_DEBUG_UNINITIALIZED)
434  TPoint3() { }
435 #else
436  TPoint3() { x = y = z = std::numeric_limits<T>::quiet_NaN(); }
437 #endif
438 
439  /// Initialize the point with the specified X, Y and Z components
440  TPoint3(T x, T y, T z) : x(x), y(y), z(z) { }
441 
442  /// Initialize the point with the components of another point
443  template <typename T2> explicit TPoint3(const TPoint3<T2> &p)
444  : x((T) p.x), y((T) p.y), z((T) p.z) { }
445 
446  /// Initialize the point with the components of a vector data structure
447  template <typename T2> explicit TPoint3(const TVector3<T2> &v)
448  : x((T) v.x), y((T) v.y), z((T) v.z) { }
449 
450  /// Initialize all components of the the point with the specified value
451  explicit TPoint3(T val) : x(val), y(val), z(val) { }
452 
453  /// Unserialize a point from a binary data stream
454  explicit TPoint3(Stream *stream) {
455  x = stream->readElement<T>();
456  y = stream->readElement<T>();
457  z = stream->readElement<T>();
458  }
459 
460  /// Add a vector to a point and return the result
461  TPoint3 operator+(const TVector3<T> &v) const {
462  return TPoint3(x + v.x, y + v.y, z + v.z);
463  }
464 
465  /// Add two points and return the result (e.g. to compute a weighted position)
466  TPoint3 operator+(const TPoint3 &p) const {
467  return TPoint3(x + p.x, y + p.y, z + p.z);
468  }
469 
470  /// Add a vector to this one (e.g. to compute a weighted position)
472  x += v.x; y += v.y; z += v.z;
473  return *this;
474  }
475 
476  /// Add a point to this one (e.g. to compute a weighted position)
478  x += p.x; y += p.y; z += p.z;
479  return *this;
480  }
481 
482  /// Subtract a vector from this point
483  TPoint3 operator-(const TVector3<T> &v) const {
484  return TPoint3(x - v.x, y - v.y, z - v.z);
485  }
486 
487  /// Subtract two points from each other and return the difference as a vector
488  TVector3<T> operator-(const TPoint3 &p) const {
489  return TVector3<T>(x - p.x, y - p.y, z - p.z);
490  }
491 
492  /// Subtract a vector from this point
494  x -= v.x; y -= v.y; z -= v.z;
495  return *this;
496  }
497 
498  /// Scale the point's coordinates by the given scalar and return the result
499  TPoint3 operator*(T f) const {
500  return TPoint3(x * f, y * f, z * f);
501  }
502 
503  /// Scale the point's coordinates by the given scalar
505  x *= f; y *= f; z *= f;
506  return *this;
507  }
508 
509  /// Return a version of the point, which has been flipped along the origin
510  TPoint3 operator-() const {
511  return TPoint3(-x, -y, -z);
512  }
513 
514  /// Divide the point's coordinates by the given scalar and return the result
515  TPoint3 operator/(T f) const {
516 #ifdef MTS_DEBUG
517  if (f == 0)
518  SLog(EWarn, "Point3: Division by zero!");
519 #endif
520  T recip = (T) 1 / f;
521  return TPoint3(x * recip, y * recip, z * recip);
522  }
523 
524  /// Divide the point's coordinates by the given scalar
526 #ifdef MTS_DEBUG
527  if (f == 0)
528  SLog(EWarn, "Point3: Division by zero!");
529 #endif
530  T recip = (T) 1 / f;
531  x *= recip; y *= recip; z *= recip;
532  return *this;
533  }
534 
535  /// Index into the point's components
536  T &operator[](int i) {
537  return (&x)[i];
538  }
539 
540  /// Index into the point's components (const version)
541  T operator[](int i) const {
542  return (&x)[i];
543  }
544 
545  /// Return whether or not this point is identically zero
546  bool isZero() const {
547  return x == 0 && y == 0 && z == 0;
548  }
549 
550  /// Equality test
551  bool operator==(const TPoint3 &v) const {
552  return (v.x == x && v.y == y && v.z == z);
553  }
554 
555  /// Inequality test
556  bool operator!=(const TPoint3 &v) const {
557  return v.x != x || v.y != y || v.z != z;
558  }
559 
560  /// Serialize this point to a binary data stream
561  void serialize(Stream *stream) const {
562  stream->writeElement<T>(x);
563  stream->writeElement<T>(y);
564  stream->writeElement<T>(z);
565  }
566 
567 
568  /// Return a readable string representation of this point
569  std::string toString() const {
570  std::ostringstream oss;
571  oss << "[" << x << ", " << y << ", " << z << "]";
572  return oss.str();
573  }
574 };
575 
576 template <typename T> inline TPoint3<T> operator*(T f, const TPoint3<T> &v) {
577  return v*f;
578 }
579 
580 template <typename T> inline T distance(const TPoint3<T> &p1, const TPoint3<T> &p2) {
581  return (p1-p2).length();
582 }
583 
584 template <typename T> inline T distanceSquared(const TPoint3<T> &p1, const TPoint3<T> &p2) {
585  return (p1-p2).lengthSquared();
586 }
587 
588 template <> inline TPoint3<int> TPoint3<int>::operator/(int s) const {
589 #ifdef MTS_DEBUG
590  if (s == 0)
591  SLog(EWarn, "Point3i: Division by zero!");
592 #endif
593  return TPoint3(x/s, y/s, z/s);
594 }
595 
596 template <> inline TPoint3<int> &TPoint3<int>::operator/=(int s) {
597 #ifdef MTS_DEBUG
598  if (s == 0)
599  SLog(EWarn, "Point3i: Division by zero!");
600 #endif
601  x /= s;
602  y /= s;
603  z /= s;
604  return *this;
605 }
606 
607 /**
608  * \headerfile mitsuba/core/point.h mitsuba/mitsuba.h
609  * \brief Parameterizable four-dimensional point data structure
610  * \ingroup libcore
611  */
612 template <typename T> struct TPoint4 {
613  typedef T Scalar;
615 
616  T x, y, z, w;
617 
618  /// Number of dimensions
619  const static int dim = 4;
620 
621  /** \brief Construct a new point without initializing it.
622  *
623  * This construtor is useful when the point will either not
624  * be used at all (it might be part of a larger data structure)
625  * or initialized at a later point in time. Always make sure
626  * that one of the two is the case! Otherwise your program will do
627  * computations involving uninitialized memory, which will probably
628  * lead to a difficult-to-find bug.
629  */
630 #if !defined(MTS_DEBUG_UNINITIALIZED)
631  TPoint4() { }
632 #else
633  TPoint4() { x = y = z = w = std::numeric_limits<T>::quiet_NaN(); }
634 #endif
635 
636  /// Initialize the point with the specified X, Y and Z components
637  TPoint4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) { }
638 
639  /// Initialize the point with the components of another point
640  template <typename T2> explicit TPoint4(const TPoint4<T2> &p)
641  : x((T) p.x), y((T) p.y), z((T) p.z), w((T) p.w) { }
642 
643  /// Initialize the point with the components of a vector data structure
644  template <typename T2> explicit TPoint4(const TVector4<T2> &v)
645  : x((T) v.x), y((T) v.y), z((T) v.z), w((T) v.w) { }
646 
647  /// Initialize all components of the the point with the specified value
648  explicit TPoint4(T val) : x(val), y(val), z(val), w(val) { }
649 
650  /// Unserialize a point from a binary data stream
651  explicit TPoint4(Stream *stream) {
652  x = stream->readElement<T>();
653  y = stream->readElement<T>();
654  z = stream->readElement<T>();
655  w = stream->readElement<T>();
656  }
657 
658  /// Add a vector to a point and return the result
659  TPoint4 operator+(const TVector4<T> &v) const {
660  return TPoint4(x + v.x, y + v.y, z + v.z, w + v.w);
661  }
662 
663  /// Add two points and return the result (e.g. to compute a weighted position)
664  TPoint4 operator+(const TPoint4 &p) const {
665  return TPoint4(x + p.x, y + p.y, z + p.z, w + p.w);
666  }
667 
668  /// Add a vector to this one (e.g. to compute a weighted position)
670  x += v.x; y += v.y; z += v.z; w += v.w;
671  return *this;
672  }
673 
674  /// Add a point to this one (e.g. to compute a weighted position)
676  x += p.x; y += p.y; z += p.z; w += p.w;
677  return *this;
678  }
679 
680  /// Subtract a vector from this point
681  TPoint4 operator-(const TVector4<T> &v) const {
682  return TPoint4(x - v.x, y - v.y, z - v.z, w - v.w);
683  }
684 
685  /// Subtract two points from each other and return the difference as a vector
686  TVector4<T> operator-(const TPoint4 &p) const {
687  return TVector4<T>(x - p.x, y - p.y, z - p.z, w - p.w);
688  }
689 
690  /// Subtract a vector from this point
692  x -= v.x; y -= v.y; z -= v.z; w -= v.w;
693  return *this;
694  }
695 
696  /// Scale the point's coordinates by the given scalar and return the result
697  TPoint4 operator*(T f) const {
698  return TPoint4(x * f, y * f, z * f, w * f);
699  }
700 
701  /// Scale the point's coordinates by the given scalar
703  x *= f; y *= f; z *= f; w *= f;
704  return *this;
705  }
706 
707  /// Return a version of the point, which has been flipped along the origin
708  TPoint4 operator-() const {
709  return TPoint4(-x, -y, -z, -w);
710  }
711 
712  /// Divide the point's coordinates by the given scalar and return the result
713  TPoint4 operator/(T f) const {
714 #ifdef MTS_DEBUG
715  if (f == 0)
716  SLog(EWarn, "Point4: Division by zero!");
717 #endif
718  T recip = (T) 1 / f;
719  return TPoint4(x * recip, y * recip, z * recip, w * recip);
720  }
721 
722  /// Divide the point's coordinates by the given scalar
724 #ifdef MTS_DEBUG
725  if (f == 0)
726  SLog(EWarn, "Point4: Division by zero!");
727 #endif
728  T recip = (T) 1 / f;
729  x *= recip; y *= recip; z *= recip; w *= recip;
730  return *this;
731  }
732 
733  /// Index into the point's components
734  T &operator[](int i) {
735  return (&x)[i];
736  }
737 
738  /// Index into the point's components (const version)
739  T operator[](int i) const {
740  return (&x)[i];
741  }
742 
743  /// Return whether or not this point is identically zero
744  bool isZero() const {
745  return x == 0 && y == 0 && z == 0 && w == 0;
746  }
747 
748  /// Equality test
749  bool operator==(const TPoint4 &v) const {
750  return (v.x == x && v.y == y && v.z == z && v.w == w);
751  }
752 
753  /// Inequality test
754  bool operator!=(const TPoint4 &v) const {
755  return v.x != x || v.y != y || v.z != z || v.w != w;
756  }
757 
758  /// Serialize this point to a binary data stream
759  void serialize(Stream *stream) const {
760  stream->writeElement<T>(x);
761  stream->writeElement<T>(y);
762  stream->writeElement<T>(z);
763  stream->writeElement<T>(w);
764  }
765 
766  /// Return a readable string representation of this point
767  std::string toString() const {
768  std::ostringstream oss;
769  oss << "[" << x << ", " << y << ", " << z << ", " << w << "]";
770  return oss.str();
771  }
772 };
773 
774 template <typename T> inline TPoint4<T> operator*(T f, const TPoint4<T> &v) {
775  return v*f;
776 }
777 
778 template <typename T> inline T distance(const TPoint4<T> &p1, const TPoint4<T> &p2) {
779  return (p1-p2).length();
780 }
781 
782 template <typename T> inline T distanceSquared(const TPoint4<T> &p1, const TPoint4<T> &p2) {
783  return (p1-p2).lengthSquared();
784 }
785 
786 template <> inline TPoint4<int> TPoint4<int>::operator/(int s) const {
787 #ifdef MTS_DEBUG
788  if (s == 0)
789  SLog(EWarn, "Point4i: Division by zero!");
790 #endif
791  return TPoint4(x/s, y/s, z/s, w/s);
792 }
793 
794 template <> inline TPoint4<int> &TPoint4<int>::operator/=(int s) {
795 #ifdef MTS_DEBUG
796  if (s == 0)
797  SLog(EWarn, "Point4i: Division by zero!");
798 #endif
799 
800  x /= s;
801  y /= s;
802  z /= s;
803  w /= s;
804  return *this;
805 }
806 
808 
809 #endif /* __MITSUBA_CORE_POINT_H_ */
810 
TPoint2 & operator+=(const TVector2< T > &v)
Add a vector to this one (e.g. to compute a weighted position)
Definition: point.h:277
TPoint1 & operator/=(T f)
Divide the point&#39;s coordinates by the given scalar.
Definition: point.h:137
T operator[](int i) const
Index into the point&#39;s components (const version)
Definition: point.h:739
TPoint4 operator+(const TPoint4 &p) const
Add two points and return the result (e.g. to compute a weighted position)
Definition: point.h:664
TPoint3 operator+(const TPoint3 &p) const
Add two points and return the result (e.g. to compute a weighted position)
Definition: point.h:466
TPoint1(const TPoint1< T1 > &p)
Initialize the point with the components of another point.
Definition: point.h:61
T x
Definition: point.h:37
TPoint3(Stream *stream)
Unserialize a point from a binary data stream.
Definition: point.h:454
TPoint4 operator*(T f) const
Scale the point&#39;s coordinates by the given scalar and return the result.
Definition: point.h:697
TPoint2 & operator/=(T f)
Divide the point&#39;s coordinates by the given scalar.
Definition: point.h:331
TPoint4 operator-(const TVector4< T > &v) const
Subtract a vector from this point.
Definition: point.h:681
Definition: fwd.h:101
TPoint4 operator+(const TVector4< T > &v) const
Add a vector to a point and return the result.
Definition: point.h:659
TPoint4(const TVector4< T2 > &v)
Initialize the point with the components of a vector data structure.
Definition: point.h:644
std::string toString() const
Return a readable string representation of this point.
Definition: point.h:373
T readElement()
Read an element from the stream (uses partial template specialization to select a method appropriate ...
Definition: stream.h:508
TPoint2(Stream *stream)
Unserialize a point from a binary data stream.
Definition: point.h:261
T y
Definition: point.h:419
TPoint2< int > operator/(int s) const
Definition: point.h:392
TPoint1(const TVector1< T1 > &v)
Initialize the point with the components of a vector data structure.
Definition: point.h:65
TVector3< T > operator-(const TPoint3 &p) const
Subtract two points from each other and return the difference as a vector.
Definition: point.h:488
TPoint2(T val)
Initialize all components of the the point with the specified value.
Definition: point.h:258
T operator[](int i) const
Index into the point&#39;s components (const version)
Definition: point.h:152
T x
Definition: point.h:419
bool operator==(const TPoint2 &v) const
Equality test.
Definition: point.h:357
TPoint4 & operator/=(T f)
Divide the point&#39;s coordinates by the given scalar.
Definition: point.h:723
TPoint2()
Construct a new point without initializing it.
Definition: point.h:241
T & operator[](int i)
Index into the point&#39;s components.
Definition: point.h:342
TPoint2 operator+(const TVector2< T > &v) const
Add a vector to a point and return the result.
Definition: point.h:267
TPoint1()
Construct a new point without initializing it.
Definition: point.h:52
bool isZero() const
Return whether or not this point is identically zero.
Definition: point.h:352
T Scalar
Definition: point.h:613
T y
Definition: vector.h:455
T x
Definition: vector.h:667
TVector4< T > VectorType
Definition: point.h:614
TPoint1 & operator+=(const TVector1< T > &v)
Add a vector to this one (e.g. to compute a weighted position)
Definition: point.h:84
TPoint2 operator*(T f) const
Scale the point&#39;s coordinates by the given scalar and return the result.
Definition: point.h:305
TPoint4 & operator*=(T f)
Scale the point&#39;s coordinates by the given scalar.
Definition: point.h:702
T & operator[](int i)
Index into the point&#39;s components.
Definition: point.h:536
TPoint4< int > & operator/=(int s)
Definition: point.h:794
Parameterizable one-dimensional point data structure.
Definition: point.h:33
bool isZero() const
Return whether or not this point is identically zero.
Definition: point.h:546
TPoint2 & operator*=(T f)
Scale the point&#39;s coordinates by the given scalar.
Definition: point.h:310
TPoint4< int > operator/(int s) const
Definition: point.h:786
TPoint3< int > operator/(int s) const
Definition: point.h:588
TPoint3 operator/(T f) const
Divide the point&#39;s coordinates by the given scalar and return the result.
Definition: point.h:515
std::string toString() const
Return a readable string representation of this point.
Definition: point.h:767
TPoint3 & operator+=(const TPoint3 &p)
Add a point to this one (e.g. to compute a weighted position)
Definition: point.h:477
#define SLog(level, fmt,...)
Write a Log message to the console (static version - to be used outside of classes that derive from O...
Definition: logger.h:49
TPoint2< int > & operator/=(int s)
Definition: point.h:400
T z
Definition: vector.h:667
bool operator!=(const TPoint3 &v) const
Inequality test.
Definition: point.h:556
TPoint2 & operator-=(const TVector2< T > &v)
Subtract a vector from this point.
Definition: point.h:299
bool operator==(const TPoint3 &v) const
Equality test.
Definition: point.h:551
T & operator[](int i)
Index into the point&#39;s components.
Definition: point.h:147
TPoint4 operator-() const
Return a version of the point, which has been flipped along the origin.
Definition: point.h:708
TVector2< T > VectorType
Definition: point.h:224
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
TPoint1 & operator-=(const TVector1< T > &v)
Subtract a vector from this point.
Definition: point.h:106
TVector1< T > operator-(const TPoint1 &p) const
Subtract two points from each other and return the difference as a vector.
Definition: point.h:101
bool operator!=(const TPoint4 &v) const
Inequality test.
Definition: point.h:754
TPoint4(Stream *stream)
Unserialize a point from a binary data stream.
Definition: point.h:651
TPoint4()
Construct a new point without initializing it.
Definition: point.h:631
Definition: fwd.h:98
TPoint2 operator/(T f) const
Divide the point&#39;s coordinates by the given scalar and return the result.
Definition: point.h:321
T w
Definition: point.h:616
bool operator!=(const TPoint2 &v) const
Inequality test.
Definition: point.h:362
TPoint1 operator+(const TPoint1 &p) const
Add two points and return the result (e.g. to compute a weighted position)
Definition: point.h:79
T x
Definition: vector.h:251
TVector2< T > operator-(const TPoint2 &p) const
Subtract two points from each other and return the difference as a vector.
Definition: point.h:294
T x
Definition: point.h:226
T x
Definition: vector.h:35
Parameterizable two-dimensional point data structure.
Definition: point.h:222
TPoint4(T val)
Initialize all components of the the point with the specified value.
Definition: point.h:648
TPoint1 operator*(T f) const
Scale the point&#39;s coordinates by the given scalar and return the result.
Definition: point.h:112
TPoint4 operator/(T f) const
Divide the point&#39;s coordinates by the given scalar and return the result.
Definition: point.h:713
T z
Definition: vector.h:455
TPoint4< T > operator*(T f, const TPoint4< T > &v)
Definition: point.h:774
Parameterizable one-dimensional vector data structure.
Definition: vector.h:31
T operator[](int i) const
Index into the point&#39;s components (const version)
Definition: point.h:347
TPoint3 operator-(const TVector3< T > &v) const
Subtract a vector from this point.
Definition: point.h:483
TPoint3(const TVector3< T2 > &v)
Initialize the point with the components of a vector data structure.
Definition: point.h:447
bool operator==(const TPoint4 &v) const
Equality test.
Definition: point.h:749
Parameterizable three-dimensional vector data structure.
Definition: vector.h:450
TVector1< T > VectorType
Definition: point.h:35
TPoint1 & operator*=(T f)
Scale the point&#39;s coordinates by the given scalar.
Definition: point.h:117
void writeElement(T value)
Write an element to the stream (uses partial template specialization to select a method appropriate t...
Definition: stream.h:512
TPoint2(const TPoint2< T2 > &p)
Initialize the point with the components of another point.
Definition: point.h:250
TPoint3 & operator+=(const TVector3< T > &v)
Add a vector to this one (e.g. to compute a weighted position)
Definition: point.h:471
T operator[](int i) const
Index into the point&#39;s components (const version)
Definition: point.h:541
TPoint2 operator-(const TVector2< T > &v) const
Subtract a vector from this point.
Definition: point.h:289
TPoint3 operator-() const
Return a version of the point, which has been flipped along the origin.
Definition: point.h:510
TPoint1< int > operator/(int s) const
Definition: point.h:199
TPoint3< int > & operator/=(int s)
Definition: point.h:596
T Scalar
Definition: point.h:223
Abstract seekable stream class.
Definition: stream.h:58
Definition: fwd.h:99
Warning message.
Definition: formatter.h:32
T x
Definition: vector.h:455
T x
Definition: point.h:616
TPoint3 operator+(const TVector3< T > &v) const
Add a vector to a point and return the result.
Definition: point.h:461
T Scalar
Definition: point.h:416
void serialize(Stream *stream) const
Serialize this point to a binary data stream.
Definition: point.h:367
bool isZero() const
Return whether or not this point is identically zero.
Definition: point.h:157
TPoint4 & operator+=(const TVector4< T > &v)
Add a vector to this one (e.g. to compute a weighted position)
Definition: point.h:669
T & operator[](int i)
Index into the point&#39;s components.
Definition: point.h:734
Parameterizable three-dimensional point data structure.
Definition: point.h:415
T y
Definition: vector.h:251
bool operator==(const TPoint1 &v) const
Equality test.
Definition: point.h:162
void serialize(Stream *stream) const
Serialize this point to a binary data stream.
Definition: point.h:561
TPoint1 operator-() const
Return a version of the point, which has been flipped along the origin.
Definition: point.h:123
TPoint4 & operator+=(const TPoint4 &p)
Add a point to this one (e.g. to compute a weighted position)
Definition: point.h:675
Parameterizable two-dimensional vector data structure.
Definition: vector.h:246
T distance(const TPoint4< T > &p1, const TPoint4< T > &p2)
Definition: point.h:778
TPoint3 & operator/=(T f)
Divide the point&#39;s coordinates by the given scalar.
Definition: point.h:525
TPoint2 & operator+=(const TPoint2 &p)
Add a point to this one (e.g. to compute a weighted position)
Definition: point.h:283
Parameterizable four-dimensional vector data structure.
Definition: vector.h:662
TPoint1 operator+(const TVector1< T > &v) const
Add a vector to a point and return the result.
Definition: point.h:74
TVector4< T > operator-(const TPoint4 &p) const
Subtract two points from each other and return the difference as a vector.
Definition: point.h:686
void serialize(Stream *stream) const
Serialize this point to a binary data stream.
Definition: point.h:172
TPoint1 operator-(const TVector1< T > &v) const
Subtract a vector from this point.
Definition: point.h:96
TPoint2 operator-() const
Return a version of the point, which has been flipped along the origin.
Definition: point.h:316
T y
Definition: vector.h:667
T Scalar
Definition: point.h:34
TPoint1(T x)
Initialize the point with the specified value.
Definition: point.h:58
TPoint4 & operator-=(const TVector4< T > &v)
Subtract a vector from this point.
Definition: point.h:691
Definition: fwd.h:100
TPoint2 operator+(const TPoint2 &p) const
Add two points and return the result (e.g. to compute a weighted position)
Definition: point.h:272
TPoint1< int > & operator/=(int s)
Definition: point.h:207
void serialize(Stream *stream) const
Serialize this point to a binary data stream.
Definition: point.h:759
TPoint3(const TPoint3< T2 > &p)
Initialize the point with the components of another point.
Definition: point.h:443
TPoint3(T val)
Initialize all components of the the point with the specified value.
Definition: point.h:451
TPoint3()
Construct a new point without initializing it.
Definition: point.h:434
T z
Definition: point.h:616
T y
Definition: point.h:616
TPoint3(T x, T y, T z)
Initialize the point with the specified X, Y and Z components.
Definition: point.h:440
bool isZero() const
Return whether or not this point is identically zero.
Definition: point.h:744
TPoint1 & operator+=(const TPoint1 &p)
Add a point to this one (e.g. to compute a weighted position)
Definition: point.h:90
TPoint2(const TVector2< T2 > &v)
Initialize the point with the components of a vector data structure.
Definition: point.h:254
Parameterizable four-dimensional point data structure.
Definition: point.h:612
TPoint3 & operator*=(T f)
Scale the point&#39;s coordinates by the given scalar.
Definition: point.h:504
TPoint3 operator*(T f) const
Scale the point&#39;s coordinates by the given scalar and return the result.
Definition: point.h:499
bool operator!=(const TPoint1 &v) const
Inequality test.
Definition: point.h:167
TPoint3 & operator-=(const TVector3< T > &v)
Subtract a vector from this point.
Definition: point.h:493
T z
Definition: point.h:419
#define MTS_NAMESPACE_END
Definition: platform.h:138
TPoint1(Stream *stream)
Unserialize a point from a binary data stream.
Definition: point.h:69
TPoint2(T x, T y)
Initialize the point with the specified X, Y and Z components.
Definition: point.h:247
std::string toString() const
Return a readable string representation of this point.
Definition: point.h:569
T w
Definition: vector.h:667
TPoint4(T x, T y, T z, T w)
Initialize the point with the specified X, Y and Z components.
Definition: point.h:637
std::string toString() const
Return a readable string representation of this point.
Definition: point.h:180
T distanceSquared(const TPoint4< T > &p1, const TPoint4< T > &p2)
Definition: point.h:782
TPoint4(const TPoint4< T2 > &p)
Initialize the point with the components of another point.
Definition: point.h:640
TVector3< T > VectorType
Definition: point.h:417
TPoint1 operator/(T f) const
Divide the point&#39;s coordinates by the given scalar and return the result.
Definition: point.h:128
T y
Definition: point.h:226