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
62 #define UNUSED(p) ((p)=(p))
63 
64 //----------------------------------------------------------------------------//
65 
78 //----------------------------------------------------------------------------//
79 
80 template <class Data_T>
82  : public ResizableField<Data_T>
83 {
84 public:
85 
86  // Typedefs ------------------------------------------------------------------
87 
88  typedef boost::intrusive_ptr<EmptyField> Ptr;
89  typedef std::vector<Ptr> Vec;
90 
91  // Constructors --------------------------------------------------------------
92 
95 
97  EmptyField();
98 
99  // \}
100 
101  // Main methods --------------------------------------------------------------
102 
104  virtual void clear(const Data_T &value);
105 
107  const Data_T& constantvalue() const;
109  void setConstantvalue(const Data_T &val);
110 
111  // From Field base class -------------------------------------------------
112 
115  virtual Data_T value(int i, int j, int k) const;
116  virtual long long int memSize() const;
118 
119  // RTTI replacement ----------------------------------------------------------
120 
123 
125  static const char *classType()
126  {
127  return "EmptyField";
128  }
129 
130  // From WritableField base class -----------------------------------------
131 
134  virtual Data_T& lvalue(int i, int j, int k);
136 
137  // From FieldBase ------------------------------------------------------------
138 
141 
142  virtual std::string className() const
143  { return std::string(classType()); }
144 
145  virtual FieldBase::Ptr clone() const
146  { return Ptr(new EmptyField(*this)); }
147 
149 
150  protected:
151 
152  // Data members --------------------------------------------------------------
153 
155  Data_T m_default;
160 
161  private:
162 
163  // Typedefs ------------------------------------------------------------------
164 
166 
167 };
168 
169 //----------------------------------------------------------------------------//
170 // EmptyField implementations
171 //----------------------------------------------------------------------------//
172 
173 template <class Data_T>
175  : base()
176 {
177  // Empty
178 }
179 
180 //----------------------------------------------------------------------------//
181 
182 template <class Data_T>
183 void EmptyField<Data_T>::clear(const Data_T &value)
184 {
185  m_constantData = m_default = value;
186 }
187 
188 //----------------------------------------------------------------------------//
189 
190 template <class Data_T>
191 Data_T EmptyField<Data_T>::value(int i, int j, int k) const
192 {
193  assert (i >= base::m_dataWindow.min.x);
194  assert (i <= base::m_dataWindow.max.x);
195  assert (j >= base::m_dataWindow.min.y);
196  assert (j <= base::m_dataWindow.max.y);
197  assert (k >= base::m_dataWindow.min.z);
198  assert (k <= base::m_dataWindow.max.z);
199 
200  UNUSED(i);
201  UNUSED(j);
202  UNUSED(k);
203 
204  // Access data
205  return m_default;
206 }
207 
208 //----------------------------------------------------------------------------//
209 
210 template <class Data_T>
211 long long int EmptyField<Data_T>::memSize() const
212 {
213  long long int superClassMemSize = base::memSize();
214  return sizeof(*this) + superClassMemSize;
215 }
216 
217 //----------------------------------------------------------------------------//
218 
219 template <class Data_T>
220 Data_T& EmptyField<Data_T>::lvalue(int i, int j, int k)
221 {
222  assert (i >= base::m_dataWindow.min.x);
223  assert (i <= base::m_dataWindow.max.x);
224  assert (j >= base::m_dataWindow.min.y);
225  assert (j <= base::m_dataWindow.max.y);
226  assert (k >= base::m_dataWindow.min.z);
227  assert (k <= base::m_dataWindow.max.z);
228 
229  UNUSED(i);
230  UNUSED(j);
231  UNUSED(k);
232 
233  // Access data
234  return m_ignoredData;
235 }
236 
237 //----------------------------------------------------------------------------//
238 
239 template <class Data_T>
240 inline void EmptyField<Data_T>::setConstantvalue(const Data_T &val)
241 {
242  m_constantData = val;
243 }
244 
245 //----------------------------------------------------------------------------//
246 
247 template <class Data_T>
248 inline const Data_T& EmptyField<Data_T>::constantvalue() const
249 {
250  return m_constantData;
251 }
252 
253 //----------------------------------------------------------------------------//
254 // Typedefs
255 //----------------------------------------------------------------------------//
256 
259 typedef std::vector<ProxyPtr> Proxies;
260 
261 //----------------------------------------------------------------------------//
262 
264 
265 //----------------------------------------------------------------------------//
266 
267 #undef UNUSED
268 
269 //----------------------------------------------------------------------------//
270 
271 #endif // Include guard