segment.hxx

00001 // Copyright (C) 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_SNAKES_SEGMENT_HXX
00029 # define OLENA_SNAKES_SEGMENT_HXX
00030 
00031 namespace oln {
00032 
00033   namespace snakes {
00034 
00035     template <class I>
00036     segment<I>::segment(std::list<point_type>& initial_contour) :
00037       prev_segment(*this), next_segment(*this)
00038     {
00039       for (typename std::list<point_type>::const_iterator
00040              it = initial_contour.begin();
00041            it != initial_contour.end();
00042            ++it)
00043         nodes.push_back(*it);
00044     }
00045 
00046     template <class I>
00047     inline
00048     ntg::float_s
00049     segment<I>::energy(const I& gradient) const
00050     {
00051       ntg::float_s e = 0.f;
00052       typename segment<I>::const_iter_type p = nodes.begin();
00053       typename segment<I>::const_iter_type c = nodes.begin();
00054       typename segment<I>::const_iter_type n = nodes.begin();
00055 
00056       ++n;
00057       e += c->energy(gradient, prev_node(), *n);
00058       for (++c, ++n; n != nodes.end(); ++p, ++c, ++n)
00059         e += c->energy(gradient, *p, *n);
00060       e += c->energy(gradient, *p, next_node());
00061       return e;
00062     }
00063 
00064     template <class I>
00065     std::list<typename segment<I>::point_type>
00066     segment<I>::contour(void) const
00067     {
00068       std::list<point_type> result;
00069 
00070       for (typename segment<I>::const_iter_type it = nodes.begin();
00071            it != nodes.end(); ++it)
00072         result.push_back(*it);
00073       return result;
00074     }
00075 
00076     template <class I>
00077     typename segment<I>::const_iter_type
00078     segment<I>::begin(void) const
00079     {
00080       return nodes.begin();
00081     }
00082     template <class I>
00083     typename segment<I>::iter_type
00084     segment<I>::begin(void)
00085     {
00086       return nodes.begin();
00087     }
00088 
00089     template <class I>
00090     typename segment<I>::const_iter_type
00091     segment<I>::end(void) const
00092     {
00093       return nodes.end();
00094     }
00095     template <class I>
00096     typename segment<I>::iter_type
00097     segment<I>::end(void)
00098     {
00099       return nodes.end();
00100     }
00101 
00102     template <class I>
00103     const node<I>
00104     segment<I>::prev_node(void) const
00105     {
00106       return prev_segment.back();
00107     }
00108     template <class I>
00109     const node<I>
00110     segment<I>::next_node(void) const
00111     {
00112       return next_segment.front();
00113     }
00114 
00115     template <class I>
00116     const node<I>
00117     segment<I>::front(void) const
00118     {
00119       return nodes.front();
00120     }
00121     template <class I>
00122     const node<I>
00123     segment<I>::back(void) const
00124     {
00125       return nodes.back();
00126     }
00127 
00128   } // end snakes
00129 
00130 } // end oln
00131 
00132 #endif // !OLENA_SNAKES_SEGMENT_HXX

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