Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
normal.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_NORMAL_H_)
21 #define __MITSUBA_CORE_NORMAL_H_
22 
23 #include <mitsuba/core/vector.h>
24 
26 
27 /**
28  * \headerfile mitsuba/core/normal.h mitsuba/mitsuba.h
29  * \brief Three-dimensional normal data structure
30  *
31  * Internally represented using floating point numbers of the chosen
32  * compile-time precision. The main difference of this data structure
33  * when compared to \ref TVector3<Float> is in how instances of
34  * \ref Normal are treated by linear transformations.
35  *
36  * \ingroup libcore
37  * \ingroup libpython
38  */
39 struct Normal : public TVector3<Float> {
40  /** \brief Construct a new normal without initializing it.
41  *
42  * This construtor is useful when the normal will either not
43  * be used at all (it might be part of a larger data structure)
44  * or initialized at a later point in time. Always make sure
45  * that one of the two is the case! Otherwise your program will do
46  * computations involving uninitialized memory, which will probably
47  * lead to a difficult-to-find bug.
48  */
49  Normal() { }
50 
51  /// Initialize the vector with the specified X and Z components
52  Normal(Float x, Float y, Float z) : TVector3<Float>(x, y, z) { }
53 
54  /// Initialize all components of the the normal with the specified value
55  explicit Normal(Float val) : TVector3<Float>(val) { }
56 
57  /// Unserialize a normal from a binary data stream
58  Normal(Stream *stream) {
59  x = stream->readElement<Float>();
60  y = stream->readElement<Float>();
61  z = stream->readElement<Float>();
62  }
63 
64  /// Construct a normal from a vector data structure
65  Normal(const TVector3<Float> &v) : TVector3<Float>(v.x, v.y, v.z) { }
66 
67  /// Assign a vector to this normal
68  void operator=(const TVector3<Float> &v) {
69  x = v.x; y = v.y; z = v.z;
70  }
71 };
72 
73 inline Normal normalize(const Normal &n) {
74  return n / n.length();
75 }
76 
78 
79 #endif /* __MITSUBA_CORE_NORMAL_H_ */
Three-dimensional normal data structure.
Definition: normal.h:39
T readElement()
Read an element from the stream (uses partial template specialization to select a method appropriate ...
Definition: stream.h:508
Normal(Float x, Float y, Float z)
Initialize the vector with the specified X and Z components.
Definition: normal.h:52
Normal(const TVector3< Float > &v)
Construct a normal from a vector data structure.
Definition: normal.h:65
T y
Definition: vector.h:455
void operator=(const TVector3< Float > &v)
Assign a vector to this normal.
Definition: normal.h:68
Normal(Stream *stream)
Unserialize a normal from a binary data stream.
Definition: normal.h:58
Normal normalize(const Normal &n)
Definition: normal.h:73
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
Normal(Float val)
Initialize all components of the the normal with the specified value.
Definition: normal.h:55
T z
Definition: vector.h:455
Parameterizable three-dimensional vector data structure.
Definition: vector.h:450
LengthType length() const
Return the 2-norm of this vector.
Definition: vector.h:571
Normal()
Construct a new normal without initializing it.
Definition: normal.h:49
Abstract seekable stream class.
Definition: stream.h:58
T x
Definition: vector.h:455
#define MTS_NAMESPACE_END
Definition: platform.h:138