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_CORE_ROUTINE_PRIMARY_HH
00027 # define MLN_CORE_ROUTINE_PRIMARY_HH
00028 
00035 
00036 # include <mln/core/concept/image.hh>
00037 
00038 
00039 namespace mln
00040 {
00041 
00042   
00043   namespace internal
00044   {
00045     template <typename I> struct primary_type;
00046   }
00047 
00048 
00050   template <typename I>
00051   const typename internal::primary_type<I>::ret&
00052   primary(const Image<I>& input);
00053 
00054 
00055 
00056 # ifndef MLN_INCLUDE_ONLY
00057 
00058 
00059   namespace internal
00060   {
00061 
00062     
00063 
00064     template <typename I> struct primary_type;
00065 
00066     template <typename I, typename C>
00067     struct primary_type_helper
00068     {
00069       typedef typename I::delegatee D;
00070       typedef typename primary_type<D>::ret ret;
00071     };
00072 
00073     template <typename I>
00074     struct primary_type_helper< I, mln::trait::image::category::primary >
00075     {
00076       typedef I ret;
00077     };
00078 
00079     template <typename I>
00080     struct primary_type
00081     {
00082       typedef mln_trait_image_category(I) Cat;
00083       typedef typename primary_type_helper<I, Cat>::ret ret;
00084     };
00085 
00086 
00087     
00088 
00089     template <typename I>
00090     const typename internal::primary_type<I>::ret&
00091     primary_(const Image<I>& input); 
00092 
00093     template <typename I>
00094     inline
00095     const typename internal::primary_type<I>::ret&
00096     primary_(trait::image::category::primary,
00097              const Image<I>& input)
00098     {
00099       return exact(input);
00100     }
00101 
00102     template <typename I>
00103     inline
00104     const typename internal::primary_type<I>::ret&
00105     primary_(trait::image::category::morpher,
00106              const Image<I>& input)
00107     {
00108       return primary_(exact(input).unmorph_());
00109     }
00110 
00111     template <typename I>
00112     inline
00113     const typename internal::primary_type<I>::ret&
00114     primary_(const Image<I>& input)
00115     {
00116       return primary_(mln_trait_image_category(I)(),
00117                       input);
00118     }
00119 
00120   } 
00121 
00122 
00123 
00124     
00125 
00126   template <typename I>
00127   inline
00128   const typename internal::primary_type<I>::ret&
00129   primary(const Image<I>& input)
00130   {
00131     mln_precondition(exact(input).is_valid());
00132     return internal::primary_(input);
00133   }
00134 
00135 
00136 # endif // ! MLN_INCLUDE_ONLY
00137 
00138 } 
00139 
00140 
00141 #endif // ! MLN_CORE_ROUTINE_PRIMARY_HH