SourceMaskCombine.h

Go to the documentation of this file.
00001 #ifndef __SOURCEMASKCOMBINE_H__
00002 #define __SOURCEMASKCOMBINE_H__
00003 
00004 // $Id$
00005 
00006 #include "Source.h"
00007 #include "Registry.h"
00008 #include "libRefCount.h"
00009 
00010 #undef DEBUG 
00011 #define DEBUG 0
00012 #include "libDebug.h"
00013 
00014 template<class DATA, int DIMENSIONALITY, class PRECISION, class SOURCEMASK,
00015     class SOURCECOMBINE>
00016 class SourceMaskCombineOf: public SourceOf<DATA, DIMENSIONALITY, PRECISION>
00017 {
00018   typedef VectorOf<SOURCECOMBINE*> VECPSRC;
00019 protected:
00020   SOURCEMASK* m_psourceMask;
00021   VECPSRC m_vecpsrc;
00022   mutable PointOf<DIMENSIONALITY, PRECISION> m_ptSize;
00023 
00024 protected:
00025   SourceMaskCombineOf() :
00026     SourceOf<DATA, DIMENSIONALITY, PRECISION> (), m_psourceMask(NULL),
00027         m_vecpsrc()
00028 
00029   {
00030   }
00031 
00032   SourceMaskCombineOf(SourceMaskCombineOf<DATA, DIMENSIONALITY, PRECISION,
00033       SOURCEMASK, SOURCECOMBINE>&src) :
00034     SourceOf<DATA, DIMENSIONALITY, PRECISION> (src), m_vecpsrc(src.m_vecpsrc)
00035   {
00036     m_psourceMask = src.m_psourceMask;
00037     ClaimPointer(m_psourceMask);
00038   }
00039 
00040   virtual ~SourceMaskCombineOf()
00041   {
00042     ReleasePointer(m_psourceMask);
00043     if (m_vecpsrc.AboutToDie())
00044       {
00045       for (int n = 0; n < m_vecpsrc.C(); n++)
00046         {
00047         ReleasePointer(m_vecpsrc[n]);
00048         }
00049       }
00050   }
00051 
00052 public:
00053 
00054   SOURCEMASK* PSourceMask()
00055   {
00056     return m_psourceMask;
00057   }
00058 
00059   const SOURCEMASK* PSourceMask() const
00060   {
00061     return m_psourceMask;
00062   }
00063 
00064   SOURCECOMBINE* PSourceCombine(int n)
00065   {
00066     return m_vecpsrc[n];
00067   }
00068 
00069   const SOURCECOMBINE* PSourceCombine(int n) const
00070   {
00071     return m_vecpsrc[n];
00072   }
00073 
00074   void SetSourceMask(SOURCEMASK* psourceMask)
00075   {
00076     ChangePointer(m_psourceMask, psourceMask);
00077   }
00078 
00079   void AddSourceCombine(SOURCECOMBINE* psource)
00080   {
00081     ClaimPointer(psource);
00082     m_vecpsrc.Append(psource);
00083   }
00084 
00085   const int& CSourceCombine() const
00086   {
00087     return m_vecpsrc.C();
00088   }
00089 
00090   void WipeSource()
00091   {
00092     m_psourceMask = NULL;
00093   }
00094 
00095   virtual String Describe() const
00096   {
00097     return (_LINE + "SourceMaskCombineOf(" + DIMENSIONALITY + "D)" + LINE_
00098         + this->DescribeCommon());
00099   }
00100 
00101   virtual String DescribeCommon() const
00102   {
00103     String s;
00104     for (int n = 0; n < m_vecpsrc.C(); n++)
00105       {
00106       s = s + (_INDENT + (_LINE + "sourcecombine: " + n + LINE_ + (_INDENT
00107           + this->m_vecpsrc[n]->Describe() + LINE_)));
00108       }
00109 
00110     return _INDENT + (_LINE + "size: " + this->Size().Describe() + LINE_
00111         + (_INDENT + "source mask:" + LINE_ + this->m_psourceMask->Describe())
00112         + s);
00113   }
00114 
00115   virtual void RegisterParameters(RegistryOfParameters& reg)
00116   {
00117   }
00118   ;
00119 
00120   virtual void RegisterDataAsParameters(RegistryOfParameters& reg)
00121   {
00122   }
00123 
00124   const PointOf<DIMENSIONALITY, PRECISION>& Size() const
00125   {
00126     return m_ptSize;
00127   }
00128 
00129   virtual PointOf<DIMENSIONALITY, PRECISION> Bound(const PointOf<
00130       DIMENSIONALITY, PRECISION>& pt) const
00131   {
00132     return pt.Bound(PointOf<DIMENSIONALITY, PRECISION> (PRECISION(0)),
00133         this->Size());
00134   }
00135 
00136   virtual void PrepareForAccessAction() const
00137   {
00138     this->m_ptSize = this->PSourceMask()->Size();
00139   }
00140 
00141   virtual void PrepareForAccess() const
00142   {
00143     // tell sources to prepare first
00144     m_psourceMask->PrepareForAccess();
00145 
00146     // tell each sourcecombine to prepare first
00147     for (int n = 0; n < m_vecpsrc.C(); n++)
00148       {
00149       PSourceCombine(n)->PrepareForAccess();
00150       }
00151 
00152     // the call the specific MaskCombine's AccessPreparation function
00153     this->PrepareForAccessAction();
00154   }
00155 };
00156 
00157 template<class DATA, class PRECISION, class SOURCEMASK, class SOURCECOMBINE>
00158 inline void Get(const SourceMaskCombineOf<DATA, 3, PRECISION, SOURCEMASK,
00159     SOURCECOMBINE>& src, DATA& dataOut, const PRECISION& nX, const PRECISION& nY)
00160 {
00161   src.VirtualGet(dataOut, nX, nY);
00162 }
00163 
00164 template<class DATA, class PRECISION, class SOURCEMASK, class SOURCECOMBINE>
00165 inline void Set(SourceMaskCombineOf<DATA, 3, PRECISION, SOURCEMASK,
00166     SOURCECOMBINE>& src, const PRECISION& nX, const PRECISION& nY, const DATA& data)
00167 {
00168   src.VirtualSet(nX, nY, data);
00169 }
00170 
00171 template<class DATA, class PRECISION, class SOURCEMASK, class SOURCECOMBINE>
00172 inline void Get(const SourceMaskCombineOf<DATA, 3, PRECISION, SOURCEMASK,
00173     SOURCECOMBINE>& src, DATA& dataOut, const PRECISION& nX, const PRECISION& nY, const PRECISION& nZ)
00174 {
00175   src.VirtualGet(dataOut, nX, nY, nZ);
00176 }
00177 
00178 template<class DATA, class PRECISION, class SOURCEMASK, class SOURCECOMBINE>
00179 inline void Set(SourceMaskCombineOf<DATA, 3, PRECISION, SOURCEMASK,
00180     SOURCECOMBINE>& src, const PRECISION& nX, const PRECISION& nY, const PRECISION& nZ, const DATA& data)
00181 {
00182   src.VirtualSet(nX, nY, nZ, data);
00183 }
00184 
00185 #define MAKE_MASKCOMBINE_ASSISTANT(                                                                                     \
00186     _name,_class,_data,_dims,_precision,_code,...                                                               \
00187 )                                                                                                                                                           \
00188     template <class SOURCEMASK,class SOURCECOMBINE>                                                         \
00189     inline _class<_data,_dims,_precision,SOURCEMASK,SOURCECOMBINE> *                        \
00190     _name(__VA_ARGS__ SOURCEMASK* psrcMask, SOURCECOMBINE* vsrcIn, int csrcIn)  \
00191     {                                                                                                                                                       \
00192         typedef _class<_data,_dims,_precision,SOURCEMASK,SOURCECOMBINE> SRC_OUT;    \
00193                                                                                                                                                             \
00194         SRC_OUT *psrcOut=new SRC_OUT;                                                                                           \
00195         psrcOut->SetSourceMask(psrcMask);                                                                                   \
00196         for (int n=0; n<csrcIn; n++){                                                                                           \
00197             psrcOut->AddSourceCombine(&vsrcIn[n]);                                                                  \
00198         }                                                                                                                                                   \
00199         _code;                                                                                                                                      \
00200         HandoffPointer(psrcOut);                                                                                                    \
00201         return psrcOut;                                                                                                                     \
00202     }                                                                                                                                                       \
00203                                                                                                                                                             \
00204     template <class SOURCEMASK,class SOURCECOMBINE>                                                         \
00205     inline _class<_data,_dims,_precision,SOURCEMASK,SOURCECOMBINE> *                        \
00206     _name(__VA_ARGS__ SOURCEMASK* psrcMask, SOURCECOMBINE** vpsrcIn, int csrcIn)    \
00207     {                                                                                                                                                       \
00208         typedef _class<_data,_dims,_precision,SOURCEMASK,SOURCECOMBINE> SRC_OUT;    \
00209                                                                                                                                                             \
00210         SRC_OUT *psrcOut=new SRC_OUT;                                                                                           \
00211         psrcOut->SetSourceMask(psrcMask);                                                                                   \
00212         for (int n=0; n<csrcIn; n++){                                                                                           \
00213             psrcOut->AddSourceCombine(vpsrcIn[n]);                                                                  \
00214         }                                                                                                                                                   \
00215         _code;                                                                                                                                      \
00216         HandoffPointer(psrcOut);                                                                                                    \
00217         return psrcOut;                                                                                                                     \
00218     }                                                                                                                                                       \
00219                                                                                                                                                             \
00220     template <class SOURCEMASK, class SOURCECOMBINE, class SOURCE_SUB>                  \
00221     inline _class<_data,_dims,_precision,SOURCEMASK,SOURCECOMBINE> *                        \
00222     _name(                                                                                                                                          \
00223         __VA_ARGS__                                                                                                                             \
00224         SOURCEMASK* psrcMask,                                                                                                           \
00225         SOURCE_SUB* vsrcIn, int csrcIn, SOURCECOMBINE*(*fxn)(SOURCE_SUB*) )             \
00226     {                                                                                                                                                       \
00227         typedef _class<_data,_dims,_precision,SOURCEMASK,SOURCECOMBINE> SRC_OUT;    \
00228                                                                                                                                                             \
00229         SRC_OUT *psrcOut=new SRC_OUT;                                                                                           \
00230         psrcOut->SetSourceMask(psrcMask);                                                                                   \
00231         for (int n=0; n<csrcIn; n++){                                                                                           \
00232             psrcOut->AddSourceCombine(fxn(&vsrcIn[n]));                                                         \
00233         }                                                                                                                                                   \
00234         _code;                                                                                                                                      \
00235         HandoffPointer(psrcOut);                                                                                                    \
00236         return psrcOut;                                                                                                                     \
00237     }
00238 
00239 #endif // __SOURCEMASKCOMBINE_H__

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1