se_window.hh

00001 // Copyright (C) 2001, 2002, 2003, 2004  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library 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
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
00027 
00028 #ifndef OLENA_IO_SE_WINDOW_HH
00029 # define OLENA_IO_SE_WINDOW_HH
00030 
00031 # include <mlc/type.hh>
00032 
00033 # include <oln/core/image1d.hh>
00034 # include <oln/core/image2d.hh>
00035 # include <oln/core/image3d.hh>
00036 # include <oln/core/window1d.hh>
00037 # include <oln/core/window2d.hh>
00038 # include <oln/core/window3d.hh>
00039 # include <oln/core/macros.hh>
00040 
00041 # include <oln/io/image.hh>
00042 
00043 namespace oln {
00044 
00045   namespace io {
00046 
00047     namespace internal {
00048 
00050 
00057       inline bool
00058       read(window1d& output, const std::string& name)
00059       {
00060         image1d<ntg::bin> im;
00061         if (!read(im, name))
00062           return false;
00063         if (!(im.ncols() % 2))
00064           return false;
00065         image1d<ntg::bin>::iter_type it(im);
00066         window1d w;
00067         for_all (it)
00068           if (!im[it])
00069             w.add(dpoint1d(it) - dpoint1d(im.ncols()/2));
00070         output = w;
00071         return true;
00072       }
00073 
00080       inline bool
00081       read(window2d& output, const std::string& name)
00082       {
00083         image2d<ntg::bin> im;
00084         if (!read(im, name))
00085           return false;
00086         if (!(im.ncols() % 2) || !(im.nrows() % 2))
00087           {
00088             // std::clog << "[both image dimensions have to be odd for a"
00089             //        << "window2d]"
00090             //        << std::flush;
00091             return false;
00092           }
00093         image2d<ntg::bin>::fwd_iter_type it(im);
00094         window2d w;
00095         for_all (it)
00096           if (!im[it])
00097             w.add(dpoint2d(it) - dpoint2d(im.nrows()/2, im.ncols()/2));
00098         output = w;
00099         return true;
00100       }
00101 
00108       inline bool
00109       read(window3d& output, const std::string& name)
00110       {
00111         image3d<ntg::bin> im;
00112         if (!read(im, name))
00113           return false;
00114         if (!(im.ncols() % 2) || !(im.nrows() % 2) || !(im.nslices() % 2))
00115           return false;
00116         image3d<ntg::bin>::iter_type it(im);
00117         window3d w;
00118         for_all (it)
00119           if (!im[it])
00120             w.add(dpoint3d(it) - dpoint3d(im.nrows()/2,
00121                                           im.ncols()/2,
00122                                           im.nslices()/2));
00123         output = w;
00124         return true;
00125       }
00126 
00133       inline bool
00134       write(const window1d& input, const std::string& name)
00135       {
00136         image1d<ntg::bin> im(input.delta()*2+1);
00137         image1d<ntg::bin>::iter_type it(im);
00138         for_all (it) im[it] = true;
00139         for (unsigned i = 0; i < input.card(); ++i)
00140           im[point1d(input.delta()) + input.dp(i)] = false;
00141         if (!write(im, name))
00142           return false;
00143         return true;
00144       }
00145 
00152       inline bool
00153       write(const window2d& input, const std::string& name)
00154       {
00155         image2d<ntg::bin> im(input.delta()*2+1, input.delta()*2+1);
00156         image2d<ntg::bin>::fwd_iter_type it(im);
00157         for_all (it) im[it] = true;
00158         for (unsigned i = 0; i < input.card(); ++i)
00159           im[point2d(input.delta(), input.delta()) + input.dp(i)] = false;
00160         if (!write(im, name))
00161           return false;
00162         return true;
00163       }
00164 
00171       inline bool
00172       write(const window3d& input, const std::string& name)
00173       {
00174         image3d<ntg::bin> im(input.delta()*2+1,
00175                              input.delta()*2+1,
00176                              input.delta()*2+1);
00177         image3d<ntg::bin>::iter_type it(im);
00178         for_all (it) im[it] = true;
00179         for (unsigned i = 0; i < input.card(); ++i)
00180           im[point3d(input.delta(), input.delta(), input.delta())
00181              + input.dp(i)] = false;
00182         if (!write(im, name))
00183           return false;
00184         return true;
00185       }
00186 
00187     } // end of namespace internal
00188 
00189   } // end of namespace io
00190 
00191 } // end of namespace oln
00192 
00193 #endif // ! OLENA_IO_SE_WINDOW_HH

Generated on Thu Apr 15 20:13:14 2004 for Olena by doxygen 1.3.6-20040222