00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef MLN_WIN_LINE_HH
00027 # define MLN_WIN_LINE_HH
00028 
00032 
00033 # include <mln/core/internal/classical_window_base.hh>
00034 # include <mln/core/dpoint.hh>
00035 
00036 
00037 namespace mln
00038 {
00039 
00040   
00041   namespace win { template <typename M, unsigned i, typename C> struct line; }
00042 
00043 
00044   namespace trait
00045   {
00046 
00047     template <typename M, unsigned i, typename C>
00048     struct window_< mln::win::line<M,i,C> > : classical_window_
00049     {
00050     };
00051 
00052   } 
00053 
00054 
00055 
00056   namespace win
00057   {
00058 
00072     template <typename M, unsigned i, typename C>
00073     struct line : public internal::classical_window_base< dpoint<M, C>, line<M,i,C> >
00074     {
00076       enum { dir = i };
00077 
00081       line(unsigned length);
00082         
00084       unsigned length() const;
00085         
00087       unsigned size() const;
00088         
00091       unsigned delta_() const;
00092 
00093       void print_(std::ostream& ostr) const;
00094 
00095     protected:
00096       unsigned length_;
00097     };
00098 
00099  
00100 
00101 # ifndef MLN_INCLUDE_ONLY
00102 
00103 
00104     template <typename M, unsigned i, typename C>
00105     inline
00106     line<M,i,C>::line(unsigned length)
00107       : length_(length)
00108     {
00109       metal::bool_< i < M::dim >::check();
00110       mln_precondition(length % 2 == 1);
00111       dpoint<M,C> n;
00112       n.set_all(0);
00113       const def::coord
00114         dc = static_cast<def::coord>(length / 2),
00115         minus_dc = static_cast<def::coord>(- dc);
00116       for (def::coord c = minus_dc; c <= dc; ++c)
00117       {
00118         n[i] = c;
00119         this->insert(n);
00120       }
00121     }
00122 
00123     template <typename M, unsigned i, typename C>
00124     inline
00125     unsigned line<M,i,C>::length() const
00126     {
00127       return length_;
00128     }
00129 
00130     template <typename M, unsigned i, typename C>
00131     inline
00132     unsigned line<M,i,C>::size() const
00133     {
00134       return length_;
00135     }
00136 
00137     template <typename M, unsigned i, typename C>
00138     inline
00139     unsigned line<M,i,C>::delta_() const
00140     {
00141       return length_ / 2;
00142     }
00143 
00144     template <typename M, unsigned i, typename C>
00145     inline
00146     void
00147     line<M,i,C>::print_(std::ostream& ostr) const
00148     {
00149       ostr << "[line: length=" << length_ << ']';
00150     }
00151 
00152 # endif // ! MLN_INCLUDE_ONLY
00153 
00154   } 
00155 
00156 } 
00157 
00158 
00159 
00160 #endif // ! MLN_WIN_LINE_HH