Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory 00002 // (LRDE) 00003 // 00004 // This file is part of Olena. 00005 // 00006 // Olena is free software: you can redistribute it and/or modify it under 00007 // the terms of the GNU General Public License as published by the Free 00008 // Software Foundation, version 2 of the License. 00009 // 00010 // Olena is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software project without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to produce 00022 // an executable, this file does not by itself cause the resulting 00023 // executable to be covered by the GNU General Public License. This 00024 // exception does not however invalidate any other reasons why the 00025 // executable file might be covered by the GNU General Public License. 00026 00027 #ifndef MLN_DEBUG_Z_ORDER_HH 00028 # define MLN_DEBUG_Z_ORDER_HH 00029 00033 00034 00035 # include <mln/core/concept/image.hh> 00036 00037 00038 namespace mln 00039 { 00040 00041 namespace debug 00042 { 00043 00051 template <typename I> 00052 void z_order(Image<I>& input); 00053 00054 00055 # ifndef MLN_INCLUDE_ONLY 00056 00057 00058 // Implementations. 00059 00060 namespace impl 00061 { 00062 00063 namespace generic 00064 { 00065 00066 template <typename I> 00067 inline 00068 void 00069 z_order(Image<I>& input) 00070 { 00071 unsigned row, col; 00072 mln_piter(I) p(input.domain()); 00073 for_all(p) 00074 { 00075 row = p.row(); 00076 col = p.col(); 00077 00078 mln_value(I)& v = input(p); 00079 v = 0; 00080 int mask = 0x00000001; 00081 int i = 1; 00082 while (row > 0 || col > 0) 00083 { 00084 if (i % 2) 00085 { 00086 if (col & 0x0000001) 00087 v = v | mask; 00088 col = col >> 1; 00089 } 00090 else 00091 { 00092 if (row & 0x0000001) 00093 v = v | mask; 00094 row = row >> 1; 00095 } 00096 00097 mask = mask << 1; 00098 ++i; 00099 } 00100 } 00101 00102 } 00103 00104 00105 } // end of namespace mln::debug::impl::generic 00106 00107 00108 } // end of namespace mln::debug::impl 00109 00110 00111 00112 // Dispatch 00113 00114 namespace internal 00115 { 00116 00117 template <typename I> 00118 inline 00119 void 00120 z_order_dispatch(trait::image::speed::any, Image<I>& input) 00121 { 00122 impl::generic::z_order(input); 00123 } 00124 00125 00126 template <typename I> 00127 inline 00128 void 00129 z_order_dispatch(Image<I>& input) 00130 { 00131 z_order_dispatch(mln_trait_image_speed(I)(), input); 00132 } 00133 00134 } 00135 00136 00137 // Facade 00138 00139 template <typename I> 00140 inline 00141 void 00142 z_order(Image<I>& input) 00143 { 00144 trace::entering("debug::z_order"); 00145 mln_precondition(exact(input).is_valid()); 00146 00147 internal::z_order_dispatch(input); 00148 00149 trace::exiting("debug::z_order"); 00150 } 00151 00152 # endif // ! MLN_INCLUDE_ONLY 00153 00154 } // end of namespace mln::debug 00155 00156 } // end of namespace mln 00157 00158 00159 #endif // ! MLN_DEBUG_Z_ORDER_HH