Field3D
EmptyField.h
Go to the documentation of this file.
1 //----------------------------------------------------------------------------//
2 
3 /*
4  * Copyright (c) 2009 Sony Pictures Imageworks Inc
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution. Neither the name of Sony Pictures Imageworks nor the
18  * names of its contributors may be used to endorse or promote
19  * products derived from this software without specific prior written
20  * permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33  * OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 //----------------------------------------------------------------------------//
37 
42 //----------------------------------------------------------------------------//
43 
44 #ifndef _INCLUDED_Field3D_EmptyField_H_
45 #define _INCLUDED_Field3D_EmptyField_H_
46 
47 #include <vector>
48 
49 #include <boost/lexical_cast.hpp>
50 
51 #include "Field.h"
52 
53 //----------------------------------------------------------------------------//
54 
55 #include "ns.h"
56 
58 
59 //----------------------------------------------------------------------------//
60 
61 // gets rid of warnings (N.B. not on clang, where self-assignment is warned!)
62 #ifdef __clang__
63 # define UNUSED(p)
64 #else
65 # define UNUSED(p) ((p)=(p))
66 #endif
67 
68 
69 //----------------------------------------------------------------------------//
70 
83 //----------------------------------------------------------------------------//
84 
85 template <class Data_T>
87  : public ResizableField<Data_T>
88 {
89 public:
90 
91  // Typedefs ------------------------------------------------------------------
92 
93  typedef boost::intrusive_ptr<EmptyField> Ptr;
94  typedef std::vector<Ptr> Vec;
95 
96  // Constructors --------------------------------------------------------------
97 
100 
102  EmptyField();
103 
104  // \}
105 
106  // Main methods --------------------------------------------------------------
107 
109  virtual void clear(const Data_T &value);
110 
112  const Data_T& constantvalue() const;
114  void setConstantvalue(const Data_T &val);
115 
116  // From Field base class -------------------------------------------------
117 
120  virtual Data_T value(int i, int j, int k) const;
121  virtual long long int memSize() const;
123 
124  // RTTI replacement ----------------------------------------------------------
125 
128 
129  static const char *staticClassName()
130  {
131  return staticClassType();
132  }
133 
134  static const char *staticClassType()
135  {
136  return "EmptyField";
137  }
138 
139  // From WritableField base class -----------------------------------------
140 
143  virtual Data_T& lvalue(int i, int j, int k);
145 
146  // From FieldBase ------------------------------------------------------------
147 
150 
152 
153  virtual FieldBase::Ptr clone() const
154  { return Ptr(new EmptyField(*this)); }
155 
157 
158  protected:
159 
160  // Data members --------------------------------------------------------------
161 
163  Data_T m_default;
168 
169  private:
170 
171  // Typedefs ------------------------------------------------------------------
172 
174 
175 };
176 
177 //----------------------------------------------------------------------------//
178 // EmptyField implementations
179 //----------------------------------------------------------------------------//
180 
181 template <class Data_T>
183  : base()
184 {
185  // Empty
186 }
187 
188 //----------------------------------------------------------------------------//
189 
190 template <class Data_T>
191 void EmptyField<Data_T>::clear(const Data_T &value)
192 {
193  m_constantData = m_default = value;
194 }
195 
196 //----------------------------------------------------------------------------//
197 
198 template <class Data_T>
199 Data_T EmptyField<Data_T>::value(int i, int j, int k) const
200 {
201  assert (i >= base::m_dataWindow.min.x);
202  assert (i <= base::m_dataWindow.max.x);
203  assert (j >= base::m_dataWindow.min.y);
204  assert (j <= base::m_dataWindow.max.y);
205  assert (k >= base::m_dataWindow.min.z);
206  assert (k <= base::m_dataWindow.max.z);
207 
208  UNUSED(i);
209  UNUSED(j);
210  UNUSED(k);
211 
212  // Access data
213  return m_default;
214 }
215 
216 //----------------------------------------------------------------------------//
217 
218 template <class Data_T>
219 long long int EmptyField<Data_T>::memSize() const
220 {
221  long long int superClassMemSize = base::memSize();
222  return sizeof(*this) + superClassMemSize;
223 }
224 
225 //----------------------------------------------------------------------------//
226 
227 template <class Data_T>
228 Data_T& EmptyField<Data_T>::lvalue(int i, int j, int k)
229 {
230  assert (i >= base::m_dataWindow.min.x);
231  assert (i <= base::m_dataWindow.max.x);
232  assert (j >= base::m_dataWindow.min.y);
233  assert (j <= base::m_dataWindow.max.y);
234  assert (k >= base::m_dataWindow.min.z);
235  assert (k <= base::m_dataWindow.max.z);
236 
237  UNUSED(i);
238  UNUSED(j);
239  UNUSED(k);
240 
241  // Access data
242  return m_ignoredData;
243 }
244 
245 //----------------------------------------------------------------------------//
246 
247 template <class Data_T>
248 inline void EmptyField<Data_T>::setConstantvalue(const Data_T &val)
249 {
250  m_constantData = val;
251 }
252 
253 //----------------------------------------------------------------------------//
254 
255 template <class Data_T>
256 inline const Data_T& EmptyField<Data_T>::constantvalue() const
257 {
258  return m_constantData;
259 }
260 
261 //----------------------------------------------------------------------------//
262 // Typedefs
263 //----------------------------------------------------------------------------//
264 
267 typedef std::vector<ProxyPtr> Proxies;
268 
269 //----------------------------------------------------------------------------//
270 
272 
273 //----------------------------------------------------------------------------//
274 
275 #undef UNUSED
276 
277 //----------------------------------------------------------------------------//
278 
279 #endif // Include guard
FIELD3D_NAMESPACE_HEADER_CLOSE
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition: ns.h:58
DEFINE_FIELD_RTTI_CONCRETE_CLASS
#define DEFINE_FIELD_RTTI_CONCRETE_CLASS
Definition: RefCount.h:84
Proxy
EmptyField< float > Proxy
Definition: EmptyField.h:265
EmptyField::setConstantvalue
void setConstantvalue(const Data_T &val)
Sets the constant value.
Definition: EmptyField.h:248
EmptyField::Vec
std::vector< Ptr > Vec
Definition: EmptyField.h:94
EmptyField::m_default
Data_T m_default
Field default value.
Definition: EmptyField.h:163
EmptyField::Ptr
boost::intrusive_ptr< EmptyField > Ptr
Definition: EmptyField.h:93
ProxyPtr
EmptyField< float >::Ptr ProxyPtr
Definition: EmptyField.h:266
EmptyField::constantvalue
const Data_T & constantvalue() const
Returns the constant value.
Definition: EmptyField.h:256
FieldBase::Ptr
boost::intrusive_ptr< FieldBase > Ptr
Definition: Field.h:97
EmptyField::staticClassType
static const char * staticClassType()
Definition: EmptyField.h:134
ns.h
EmptyField::value
virtual Data_T value(int i, int j, int k) const
Read access to a voxel. The coordinates are in integer voxel space .
Definition: EmptyField.h:199
UNUSED
#define UNUSED(p)
Definition: EmptyField.h:65
detail::max
T max(const T a, const T2 b)
Max operation on mixed types.
Definition: FieldSampler.h:32
EmptyField::m_constantData
Data_T m_constantData
Field constant value.
Definition: EmptyField.h:167
EmptyField::class_type
EmptyField< Data_T > class_type
Definition: EmptyField.h:126
EmptyField::memSize
virtual long long int memSize() const
Returns the memory usage (in bytes)
Definition: EmptyField.h:219
Field.h
Contains Field, WritableField and ResizableField classes.
Proxies
std::vector< ProxyPtr > Proxies
Definition: EmptyField.h:267
EmptyField
This subclass of Field does not store any data.
Definition: EmptyField.h:86
EmptyField::base
ResizableField< Data_T > base
Definition: EmptyField.h:173
FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION
#define FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION
Definition: Field.h:473
EmptyField::clone
virtual FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION FieldBase::Ptr clone() const
Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement i...
Definition: EmptyField.h:153
EmptyField::lvalue
virtual Data_T & lvalue(int i, int j, int k)
Write access to a voxel. The coordinates are global coordinates.
Definition: EmptyField.h:228
FIELD3D_NAMESPACE_OPEN
Definition: FieldMapping.cpp:74
EmptyField::clear
virtual void clear(const Data_T &value)
Clears all the voxels in the storage.
Definition: EmptyField.h:191
EmptyField::m_ignoredData
Data_T m_ignoredData
Dummy variable for assignment.
Definition: EmptyField.h:165
EmptyField::EmptyField
EmptyField()
Constructs an empty buffer.
Definition: EmptyField.h:182
detail::min
T min(const T a, const T2 b)
Min operation on mixed types.
Definition: FieldSampler.h:25
ResizableField
Definition: Field.h:833
EmptyField::staticClassName
static const DEFINE_FIELD_RTTI_CONCRETE_CLASS char * staticClassName()
Definition: EmptyField.h:129