Field3D
EmptyField.h
Go to the documentation of this file.
00001 //----------------------------------------------------------------------------//
00002 
00003 /*
00004  * Copyright (c) 2009 Sony Pictures Imageworks Inc
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * Redistributions of source code must retain the above copyright
00013  * notice, this list of conditions and the following disclaimer.
00014  * Redistributions in binary form must reproduce the above copyright
00015  * notice, this list of conditions and the following disclaimer in the
00016  * documentation and/or other materials provided with the
00017  * distribution.  Neither the name of Sony Pictures Imageworks nor the
00018  * names of its contributors may be used to endorse or promote
00019  * products derived from this software without specific prior written
00020  * permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
00026  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00028  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00029  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00031  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00033  * OF THE POSSIBILITY OF SUCH DAMAGE.
00034  */
00035 
00036 //----------------------------------------------------------------------------//
00037 
00042 //----------------------------------------------------------------------------//
00043 
00044 #ifndef _INCLUDED_Field3D_EmptyField_H_
00045 #define _INCLUDED_Field3D_EmptyField_H_
00046 
00047 #include <vector>
00048 
00049 #include <boost/lexical_cast.hpp>
00050 
00051 #include "Field.h"
00052 
00053 //----------------------------------------------------------------------------//
00054 
00055 #include "ns.h"
00056 
00057 FIELD3D_NAMESPACE_OPEN
00058 
00059 //----------------------------------------------------------------------------//
00060 
00061 // gets rid of warnings
00062 #define UNUSED(p) ((p)=(p))
00063 
00064 //----------------------------------------------------------------------------//
00065 
00078 //----------------------------------------------------------------------------//
00079 
00080 template <class Data_T>
00081 class EmptyField
00082   : public ResizableField<Data_T>
00083 {
00084 public:
00085 
00086   // Typedefs ------------------------------------------------------------------
00087   
00088   typedef boost::intrusive_ptr<EmptyField> Ptr;
00089   typedef std::vector<Ptr> Vec;
00090 
00091   // Constructors --------------------------------------------------------------
00092 
00095 
00097   EmptyField();
00098 
00099 #if 0 // These should be removed
00100 
00102   explicit EmptyField(const V3i &size);
00105   explicit EmptyField(const V3i &size, int padding);
00107   explicit EmptyField(const Box3i &extents);
00109   explicit EmptyField(const Box3i &extents, const Box3i &dataWindow);
00110 
00111 #endif
00112 
00113   // \}
00114 
00115   // Main methods --------------------------------------------------------------
00116 
00118   virtual void clear(const Data_T &value);
00119 
00121   const Data_T& constantvalue() const;
00123   void setConstantvalue(const Data_T &val);
00124 
00125   // From Field base class -------------------------------------------------
00126 
00129   virtual Data_T value(int i, int j, int k) const;
00130   virtual long long int memSize() const;
00132 
00133   // RTTI replacement ----------------------------------------------------------
00134 
00135   typedef EmptyField<Data_T> class_type;
00136   DEFINE_FIELD_RTTI_CONCRETE_CLASS
00137 
00138   // From WritableField base class -----------------------------------------
00139 
00142   virtual Data_T& lvalue(int i, int j, int k);
00144   
00145   // From FieldBase ------------------------------------------------------------
00146 
00149   virtual std::string className() const
00150   { return std::string("EmptyField"); }
00151 
00152   virtual FieldBase::Ptr clone() const
00153   { return Ptr(new EmptyField(*this)); }
00154 
00156 
00157  protected:
00158 
00159   // Data members --------------------------------------------------------------
00160 
00162   Data_T m_default;
00164   Data_T m_ignoredData;
00166   Data_T m_constantData;
00167 
00168  private:
00169 
00170   // Typedefs ------------------------------------------------------------------
00171 
00172   typedef ResizableField<Data_T> base;
00173 
00174 };
00175 
00176 //----------------------------------------------------------------------------//
00177 // EmptyField implementations
00178 //----------------------------------------------------------------------------//
00179 
00180 template <class Data_T>
00181 EmptyField<Data_T>::EmptyField()
00182   : base()
00183 { 
00184   // Empty
00185 }
00186 
00187 #if 0
00188 
00189 template <class Data_T>
00190 EmptyField<Data_T>::EmptyField()
00191 { 
00192   base::setSize(Box3i(V3i(0), V3i(-1))); 
00193 }
00194 
00195 //----------------------------------------------------------------------------//
00196 
00197 template <class Data_T>
00198 EmptyField<Data_T>::EmptyField(const V3i &size)
00199 { 
00200   base::setSize(size); 
00201 }
00202 
00203 //----------------------------------------------------------------------------//
00204 
00205 template <class Data_T>
00206 EmptyField<Data_T>::EmptyField(const V3i &size, int padding)
00207 { 
00208   base::setSize(Box3i(V3i(0), size - V3i(1)),
00209                 Box3i(V3i(-padding), 
00210                              size + V3i(padding - 1))); 
00211 }
00212 
00213 //----------------------------------------------------------------------------//
00214 
00215 template <class Data_T>
00216 EmptyField<Data_T>::EmptyField(const Box3i &extents)
00217 { 
00218   base::setSize(extents); 
00219 }
00220 
00221 //----------------------------------------------------------------------------//
00222 
00223 template <class Data_T>
00224 EmptyField<Data_T>::EmptyField(const Box3i &extents,
00225                                const Box3i &dataWindow)
00226 { 
00227   base::setSize(extents, dataWindow); 
00228 }
00229 
00230 #endif
00231 
00232 //----------------------------------------------------------------------------//
00233 
00234 template <class Data_T>
00235 void EmptyField<Data_T>::clear(const Data_T &value)
00236 {
00237   m_constantData = m_default = value;
00238 }
00239 
00240 //----------------------------------------------------------------------------//
00241 
00242 template <class Data_T>
00243 Data_T EmptyField<Data_T>::value(int i, int j, int k) const
00244 {
00245   assert (i >= base::m_dataWindow.min.x);
00246   assert (i <= base::m_dataWindow.max.x);
00247   assert (j >= base::m_dataWindow.min.y);
00248   assert (j <= base::m_dataWindow.max.y);
00249   assert (k >= base::m_dataWindow.min.z);
00250   assert (k <= base::m_dataWindow.max.z);
00251 
00252   UNUSED(i);
00253   UNUSED(j);
00254   UNUSED(k);
00255 
00256   // Access data
00257   return m_default;
00258 }
00259 
00260 //----------------------------------------------------------------------------//
00261 
00262 template <class Data_T>
00263 long long int EmptyField<Data_T>::memSize() const
00264 { 
00265   long long int superClassMemSize = base::memSize();
00266   return sizeof(*this) + superClassMemSize; 
00267 }
00268 
00269 //----------------------------------------------------------------------------//
00270 
00271 template <class Data_T>
00272 Data_T& EmptyField<Data_T>::lvalue(int i, int j, int k)
00273 {
00274   assert (i >= base::m_dataWindow.min.x);
00275   assert (i <= base::m_dataWindow.max.x);
00276   assert (j >= base::m_dataWindow.min.y);
00277   assert (j <= base::m_dataWindow.max.y);
00278   assert (k >= base::m_dataWindow.min.z);
00279   assert (k <= base::m_dataWindow.max.z);
00280 
00281   UNUSED(i);
00282   UNUSED(j);
00283   UNUSED(k);
00284 
00285   // Access data
00286   return m_ignoredData;
00287 }
00288 
00289 //----------------------------------------------------------------------------//
00290 
00291 template <class Data_T>
00292 inline void EmptyField<Data_T>::setConstantvalue(const Data_T &val)
00293 {
00294   m_constantData = val;
00295 }
00296 
00297 //----------------------------------------------------------------------------//
00298 
00299 template <class Data_T>
00300 inline const Data_T& EmptyField<Data_T>::constantvalue() const
00301 {
00302   return m_constantData;
00303 }
00304 
00305 //----------------------------------------------------------------------------//
00306 // Typedefs
00307 //----------------------------------------------------------------------------//
00308 
00309 typedef EmptyField<float> Proxy;
00310 typedef EmptyField<float>::Ptr ProxyPtr;
00311 typedef std::vector<ProxyPtr> Proxies;
00312 
00313 //----------------------------------------------------------------------------//
00314 
00315 FIELD3D_NAMESPACE_HEADER_CLOSE
00316 
00317 //----------------------------------------------------------------------------//
00318 
00319 #undef UNUSED
00320 
00321 //----------------------------------------------------------------------------//
00322 
00323 #endif // Include guard