Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
properties.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_PROPERTIES_H_)
21 #define __MITSUBA_CORE_PROPERTIES_H_
22 
23 #include <mitsuba/mitsuba.h>
24 #include <mitsuba/core/transform.h>
25 
27 
28 struct PropertyElement;
29 
30 /** \brief Associative parameter map for constructing
31  * subclasses of \ref ConfigurableObject.
32  *
33  * Note that the Python bindings for this class do not implement
34  * the various type-dependent getters and setters. Instead, they
35  * are accessed just like a normal Python map, e.g:
36  *
37  * \code
38  * myProps = mitsuba.core.Properties("pluginName")
39  * myProps["stringProperty"] = "hello"
40  * myProps["spectrumProperty"] = mitsuba.core.Spectrum(1.0)
41  * \endcode
42  *
43  * \ingroup libcore
44  * \ingroup libpython
45  */
47 public:
48  /// Supported types of properties
50  /// Boolean value (true/false)
51  EBoolean = 0,
52  /// 64-bit signed integer
54  /// Floating point value
56  /// 3D point
58  /// 3D vector
60  /// 4x4 transform for homogeneous coordinates
62  /// An animated 4x4 transformation
64  /// Discretized color spectrum
66  /// Arbitrary-length string
68  /// Arbitrary data (pointer+size)
69  EData
70  };
71 
72  /// Simple pointer-size pair for passing arbitrary data (e.g. between plugins)
73  struct Data {
75  size_t size;
76 
77  inline bool operator==(const Data &d) const {
78  return ptr == d.ptr && size == d.size;
79  }
80 
81  inline bool operator!=(const Data &d) const {
82  return !operator==(d);
83  }
84  };
85 
86  /// Construct an empty property container
87  Properties();
88 
89  /// Construct an empty property container and set the plugin name
90  Properties(const std::string &pluginName);
91 
92  /// Copy constructor
93  Properties(const Properties &props);
94 
95  /// Release all memory
96  ~Properties();
97 
98  /// Set the associated plugin name
99  inline void setPluginName(const std::string &name) { m_pluginName = name; }
100  /// Get the associated plugin name
101  inline const std::string &getPluginName() const { return m_pluginName; }
102 
103  /// Returns the associated identifier (or the string "unnamed")
104  inline const std::string &getID() const { return m_id; }
105  /// Set the associated identifier
106  inline void setID(const std::string &id) { m_id = id; }
107 
108  /// Set a boolean value
109  void setBoolean(const std::string &name, const bool &value, bool warnDuplicates = true);
110  /// Get an boolean value
111  bool getBoolean(const std::string &name) const;
112  /// Get an boolean value (with default);
113  bool getBoolean(const std::string &name, const bool &defVal) const;
114 
115  /// Set an integer value
116  void setInteger(const std::string &name, const int &value, bool warnDuplicates = true);
117  /// Get an integer value
118  int getInteger(const std::string &name) const;
119  /// Get an integer value (with default);
120  int getInteger(const std::string &name, const int &defVal) const;
121 
122  /// Set an integer value
123  void setLong(const std::string &name, const int64_t &value, bool warnDuplicates = true);
124  /// Get an integer value
125  int64_t getLong(const std::string &name) const;
126  /// Get an integer value (with default);
127  int64_t getLong(const std::string &name, const int64_t &defVal) const;
128 
129  /// Set a size value
130  void setSize(const std::string &name, const size_t &value, bool warnDuplicates = true);
131  /// Get a size value
132  size_t getSize(const std::string &name) const;
133  /// Get an size value (with default);
134  size_t getSize(const std::string &name, const size_t &defVal) const;
135 
136  /// Set a single precision floating point value
137  void setFloat(const std::string &name, const Float &value, bool warnDuplicates = true);
138  /// Get a single precision floating point value
139  Float getFloat(const std::string &name) const;
140  /// Get a single precision floating point value (with default)
141  Float getFloat(const std::string &name, const Float &defVal) const;
142 
143  /// Set an arbitrary data value
144  void setData(const std::string &name, const Data &value, bool warnDuplicates = true);
145  /// Get an arbitrary data value
146  Data getData(const std::string &name) const;
147  /// Get an arbitrary data value (with default)
148  Data getData(const std::string &name, const Data &defVal) const;
149 
150  /// Set a linear transformation
151  void setTransform(const std::string &name, const Transform &value, bool warnDuplicates = true);
152  /// Get a linear transformation
153  Transform getTransform(const std::string &name) const;
154  /// Get a linear transformation (with default)
155  Transform getTransform(const std::string &name, const Transform &defVal) const;
156 
157  /// Set an animated linear transformation
158  void setAnimatedTransform(const std::string &name, const AnimatedTransform *value, bool warnDuplicates = true);
159  /// Get an animated linear transformation
160  ref<const AnimatedTransform> getAnimatedTransform(const std::string &name) const;
161  /// Get an animated linear transformation (with default)
162  ref<const AnimatedTransform> getAnimatedTransform(const std::string &name, const AnimatedTransform *defVal) const;
163  /// Get an animated linear transformation (with default)
164  ref<const AnimatedTransform> getAnimatedTransform(const std::string &name, const Transform &defVal) const;
165 
166  /// Set a spectral power distribution
167  void setSpectrum(const std::string &name, const Spectrum &value, bool warnDuplicates = true);
168  /// Get a spectral power distribution
169  Spectrum getSpectrum(const std::string &name) const;
170  /// Get a spectral power distribution (with default)
171  Spectrum getSpectrum(const std::string &name, const Spectrum &defVal) const;
172 
173  /// Set a 3d point
174  void setPoint(const std::string &name, const Point &value, bool warnDuplicates = true);
175  /// Get a 3d point
176  Point getPoint(const std::string &name) const;
177  /// Get a 3d point (with default)
178  Point getPoint(const std::string &name, const Point &defVal) const;
179 
180  /// Set a 3d vector
181  void setVector(const std::string &name, const Vector &value, bool warnDuplicates = true);
182  /// Get a 3d vector
183  Vector getVector(const std::string &name) const;
184  /// Get a 3d vector (with default)
185  Vector getVector(const std::string &name, const Vector &defVal) const;
186 
187  /// Set a string
188  void setString(const std::string &name, const std::string &value, bool warnDuplicates = true);
189  /// Get a string
190  std::string getString(const std::string &name) const;
191  /// Get a string (with default)
192  std::string getString(const std::string &name, const std::string &defVal) const;
193 
194  /// Return one of the parameters (converting it to a string if necessary)
195  std::string getAsString(const std::string &name) const;
196  /// Return one of the parameters (converting it to a string if necessary, with default value)
197  std::string getAsString(const std::string &name, const std::string &defVal) const;
198 
199  /// Copy an attribute from another Properties object and potentially rename it
200  void copyAttribute(const Properties &properties,
201  const std::string &sourceName, const std::string &targetName);
202 
203  /// Store an array containing the names of all stored properties
204  void putPropertyNames(std::vector<std::string> &results) const;
205 
206  /// Return an array containing the names of all stored properties
207  inline std::vector<std::string> getPropertyNames() const {
208  std::vector<std::string> results;
209  putPropertyNames(results);
210  return results;
211  }
212 
213  /// Manually mark a certain property as queried
214  void markQueried(const std::string &name) const;
215 
216  /// Check if a certain property was queried
217  bool wasQueried(const std::string &name) const;
218 
219  /// Verify if a value with the specified name exists
220  bool hasProperty(const std::string &name) const;
221 
222  /**
223  * \brief Remove a property with the specified name
224  * \return \c true upon success
225  */
226  bool removeProperty(const std::string &name);
227 
228  /// Return the property of a type
229  EPropertyType getType(const std::string &name) const;
230 
231  /// Return the list of un-queried attributed
232  std::vector<std::string> getUnqueried() const;
233 
234  /// Assignment operator
235  void operator=(const Properties &props);
236 
237  /// Equality comparison operator
238  bool operator==(const Properties &props) const;
239 
240  /// Inequality comparision operator
241  inline bool operator!=(const Properties &props) const {
242  return !operator==(props);
243  }
244 
245  /// Merge a properties record into the current one
246  void merge(const Properties &props);
247 
248  /// Return a string representation
249  std::string toString() const;
250 private:
251  std::map<std::string, PropertyElement> *m_elements;
252  std::string m_pluginName, m_id;
253 };
254 
256 
257 #endif /* __MITSUBA_CORE_PROPERTIES_H_ */
bool operator!=(const Properties &props) const
Inequality comparision operator.
Definition: properties.h:241
3D vector
Definition: properties.h:59
std::vector< std::string > getPropertyNames() const
Return an array containing the names of all stored properties.
Definition: properties.h:207
EPropertyType
Supported types of properties.
Definition: properties.h:49
bool operator!=(const Data &d) const
Definition: properties.h:81
void setPluginName(const std::string &name)
Set the associated plugin name.
Definition: properties.h:99
void setID(const std::string &id)
Set the associated identifier.
Definition: properties.h:106
#define MTS_EXPORT_CORE
Definition: getopt.h:29
bool operator==(const Data &d) const
Definition: properties.h:77
4x4 transform for homogeneous coordinates
Definition: properties.h:61
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
3D point
Definition: properties.h:57
Discretized color spectrum.
Definition: properties.h:65
const std::string & getPluginName() const
Get the associated plugin name.
Definition: properties.h:101
const std::string & getID() const
Returns the associated identifier (or the string &quot;unnamed&quot;)
Definition: properties.h:104
Reference counting helper.
Definition: ref.h:40
Arbitrary-length string.
Definition: properties.h:67
Encapsulates a 4x4 linear transformation and its inverse.
Definition: transform.h:33
size_t size
Definition: properties.h:75
Definition: fwd.h:96
Animated transformation with an underlying keyframe representation.
Definition: track.h:335
uint8_t * ptr
Definition: properties.h:74
Simple pointer-size pair for passing arbitrary data (e.g. between plugins)
Definition: properties.h:73
64-bit signed integer
Definition: properties.h:53
Associative parameter map for constructing subclasses of ConfigurableObject.
Definition: properties.h:46
Definition: fwd.h:100
Discrete spectral power distribution based on a number of wavelength bins over the 360-830 nm range...
Definition: spectrum.h:663
#define MTS_NAMESPACE_END
Definition: platform.h:138
An animated 4x4 transformation.
Definition: properties.h:63
Floating point value.
Definition: properties.h:55