contrib/tbl/vepl/accessors/vipl_accessors_vil_image_view_base.txx
Go to the documentation of this file.
00001 #ifndef vipl_accessors_vil_image_view_base_txx_
00002 #define vipl_accessors_vil_image_view_base_txx_
00003 
00004 #include "vipl_accessors_vil_image_view_base.h"
00005 #include <vepl/section/vipl_filterable_section_container_generator_vil_image_view_base.txx>
00006 #include <vil/vil_rgb.h>
00007 #include <vil/vil_image_view.h>
00008 #include <vcl_config_compiler.h>
00009 
00010 template <class DataType>
00011 inline DataType fgetpixel(vil_image_view_base const& i, int x, int y, DataType /* dummy */)
00012 {
00013   vil_image_view<DataType> const& im = static_cast<vil_image_view<DataType>const&>(i);
00014   return im(x,y);
00015 }
00016 template <class DataType>
00017 inline void fsetpixel(vil_image_view_base& i, int x, int y, DataType const e)
00018 {
00019   vil_image_view<DataType>& im = static_cast<vil_image_view<DataType>&>(i);
00020   im(x,y) = e;
00021 }
00022 template <class DataType>
00023 inline DataType getpixel(vil_image_view_base const& i, int x, int y, DataType /* dummy */)
00024 {
00025   if (x<0 || y<0 || x>=(int)i.ni() || y>=(int)i.nj()) return DataType();
00026   vil_image_view<DataType> const& im = static_cast<vil_image_view<DataType>const&>(i);
00027   return im(x,y);
00028 }
00029 template <class DataType>
00030 inline void setpixel(vil_image_view_base& i, int x, int y, DataType const e)
00031 {
00032   if (x<0 || y<0 || x>=(int)i.ni() || y>=(int)i.nj()) return;
00033   vil_image_view<DataType>& im = static_cast<vil_image_view<DataType>&>(i);
00034   im(x,y) = e;
00035 }
00036 
00037 #if VCL_HAS_TEMPLATE_SYMBOLS
00038 template <class DataType>
00039 inline vil_rgb<DataType> fgetpixel(vil_image_view_base const& i, int x, int y, vil_rgb<DataType> /* dummy */)
00040 {
00041   if (i.nplanes() == 3)
00042   {
00043     vil_image_view<DataType> const& im = static_cast<vil_image_view<DataType>const&>(i);
00044     return vil_rgb<DataType>(im(x,y,0),im(x,y,1),im(x,y,2));
00045   }
00046   else
00047   {
00048     vil_image_view<vil_rgb<DataType> > const& im = static_cast<vil_image_view<vil_rgb<DataType> >const&>(i);
00049     return im(x,y);
00050   }
00051 }
00052 template <class DataType>
00053 inline void fsetpixel(vil_image_view_base& i, int x, int y, vil_rgb<DataType> const e)
00054 {
00055   if (i.nplanes() == 3)
00056   {
00057     vil_image_view<DataType>& im = static_cast<vil_image_view<DataType>&>(i);
00058     im(x,y,0) = e.r; im(x,y,1) = e.g; im(x,y,2) = e.b;
00059   }
00060   else
00061   {
00062     vil_image_view<vil_rgb<DataType> >& im = static_cast<vil_image_view<vil_rgb<DataType> >&>(i);
00063     im(x,y) = e;
00064   }
00065 }
00066 template <class DataType>
00067 inline vil_rgb<DataType> getpixel(vil_image_view_base const& i, int x, int y, vil_rgb<DataType> /* dummy */)
00068 {
00069   if (x<0 || y<0 || x>=(int)i.ni() || y>=(int)i.nj()) return vil_rgb<DataType>();
00070   if (i.nplanes() == 3)
00071   {
00072     vil_image_view<DataType> const& im = static_cast<vil_image_view<DataType>const&>(i);
00073     return vil_rgb<DataType>(im(x,y,0),im(x,y,1),im(x,y,2));
00074   }
00075   else
00076   {
00077     vil_image_view<vil_rgb<DataType> > const& im = static_cast<vil_image_view<vil_rgb<DataType> >const&>(i);
00078     return im(x,y);
00079   }
00080 }
00081 template <class DataType>
00082 inline void setpixel(vil_image_view_base& i, int x, int y, vil_rgb<DataType> const e)
00083 {
00084   if (x<0 || y<0 || x>=(int)i.ni() || y>=(int)i.nj()) return;
00085   if (i.nplanes() == 3)
00086   {
00087     vil_image_view<DataType>& im = static_cast<vil_image_view<DataType>&>(i);
00088     im(x,y,0) = e.r; im(x,y,1) = e.g; im(x,y,2) = e.b;
00089   }
00090   else
00091   {
00092     vil_image_view<vil_rgb<DataType> >& im = static_cast<vil_image_view<vil_rgb<DataType> >&>(i);
00093     im(x,y) = e;
00094   }
00095 }
00096 #else // compilers with overload problems ...
00097 inline vil_rgb<vxl_byte> fgetpixel(vil_image_view_base const& i, int x, int y, vil_rgb<vxl_byte> /* dummy */)
00098 {
00099   if (i.nplanes() == 3)
00100   {
00101     vil_image_view<vxl_byte> const& im = static_cast<vil_image_view<vxl_byte>const&>(i);
00102     return vil_rgb<vxl_byte>(im(x,y,0),im(x,y,1),im(x,y,2));
00103   }
00104   else
00105   {
00106     vil_image_view<vil_rgb<vxl_byte> > const& im = static_cast<vil_image_view<vil_rgb<vxl_byte> >const&>(i);
00107     return im(x,y);
00108   }
00109 }
00110 inline void fsetpixel(vil_image_view_base& i, int x, int y, vil_rgb<vxl_byte> const e)
00111 {
00112   if (i.nplanes() == 3)
00113   {
00114     vil_image_view<vxl_byte>& im = static_cast<vil_image_view<vxl_byte>&>(i);
00115     im(x,y,0) = e.r; im(x,y,1) = e.g; im(x,y,2) = e.b;
00116   }
00117   else
00118   {
00119     vil_image_view<vil_rgb<vxl_byte> >& im = static_cast<vil_image_view<vil_rgb<vxl_byte> >&>(i);
00120     im(x,y) = e;
00121   }
00122 }
00123 inline vil_rgb<vxl_byte> getpixel(vil_image_view_base const& i, int x, int y, vil_rgb<vxl_byte> /* dummy */)
00124 {
00125   if (x<0 || y<0 || x>=(int)i.ni() || y>=(int)i.nj()) return vil_rgb<vxl_byte>();
00126   if (i.nplanes() == 3)
00127   {
00128     vil_image_view<vxl_byte> const& im = static_cast<vil_image_view<vxl_byte>const&>(i);
00129     return vil_rgb<vxl_byte>(im(x,y,0),im(x,y,1),im(x,y,2));
00130   }
00131   else
00132   {
00133     vil_image_view<vil_rgb<vxl_byte> > const& im = static_cast<vil_image_view<vil_rgb<vxl_byte> >const&>(i);
00134     return im(x,y);
00135   }
00136 }
00137 inline void setpixel(vil_image_view_base& i, int x, int y, vil_rgb<vxl_byte> const e)
00138 {
00139   if (x<0 || y<0 || (unsigned int)x >= i.ni() || (unsigned int)y >= i.nj())
00140     return;
00141   if (i.nplanes() == 3)
00142   {
00143     vil_image_view<vxl_byte>& im = static_cast<vil_image_view<vxl_byte>&>(i);
00144     im(x,y,0) = e.r; im(x,y,1) = e.g; im(x,y,2) = e.b;
00145   }
00146   else
00147   {
00148     vil_image_view<vil_rgb<vxl_byte> >& im = static_cast<vil_image_view<vil_rgb<vxl_byte> >&>(i);
00149     im(x,y) = e;
00150   }
00151 }
00152 #endif
00153 
00154 #undef VIPL_INSTANTIATE_ACCESSORS
00155 #define VIPL_INSTANTIATE_ACCESSORS(T) \
00156 template T fgetpixel(vil_image_view_base const&, int, int, T);\
00157 template void fsetpixel(vil_image_view_base&, int, int, T);\
00158 template T getpixel(vil_image_view_base const&, int, int, T);\
00159 template void setpixel(vil_image_view_base&, int, int, T)
00160 
00161 #endif // vipl_accessors_vil_image_view_base_txx_