energies.hh

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_ENERGIES_HH
00029 # define OLENA_SNAKES_ENERGIES_HH
00030 
00031 namespace oln {
00032 
00033   namespace snakes {
00034 
00037     template <class I>
00038     class energy
00039     {
00040     public:
00041       energy() {}
00042       energy(void *) {}
00043 
00044     public:
00050       ntg::float_s
00051       compute(const I&, const node<I>&, const node<I>&, const node<I>&)
00052       {
00053         // This is intended to cause an error. The user must define a
00054         // member function named `compute()' for each external energy,
00055         // otherwise the following method will be compiled and cause an
00056         // error.
00057         user_defined_external_energy_functor::compute();
00058         return 0.f;
00059       }
00060 
00061     public:
00063       static void* cookie() { return 0; };
00064 
00065     private:
00066       struct user_defined_external_energy_functor{};
00067     };
00068 
00069 
00078     template <class I>
00079     class continuity_energy : public energy<I>
00080     {
00081     public:
00082       typedef I image_type;
00083 
00084     public:
00085       continuity_energy(ntg::float_s* average_dist) :
00086         average_dist(average_dist) {}
00087 
00088     public:
00089       inline
00090       ntg::float_s
00091       compute(const I&,
00092               const node<I>& prev,
00093               const node<I>& current,
00094               const node<I>&);
00095 
00096     private:
00097       ntg::float_s* average_dist;
00098     };
00099 
00100 
00108     template <class I>
00109     class curvature_energy : public energy<I>
00110     {
00111     public:
00112       typedef I image_type;
00113 
00114     public:
00115       curvature_energy(void *) {}
00116 
00117     public:
00118       static inline
00119       ntg::float_s
00120       compute(const I&,
00121               const node<I>& prev,
00122               const node<I>& current,
00123               const node<I>& next);
00124     };
00125 
00126 
00132     template <class I>
00133     class image_energy : public energy<I>
00134     {
00135     public:
00136       typedef I image_type;
00137 
00138     public:
00139       image_energy(void*) {}
00140 
00141     public:
00142       static inline
00143       ntg::float_s
00144       compute(const I& gradient,
00145               const node<I>&,
00146               const node<I>& current,
00147               const node<I>&);
00148     };
00149 
00150 
00155 #define oln_snakes_define_external_energy(Energy, Gradient, PrevNode, CurrentNode, NextNode)    \
00156                                                                                                 \
00157 template<class I>                                                                               \
00158 class Energy : public energy<I>                                                                 \
00159 {                                                                                               \
00160 public:                                                                                         \
00161   typedef I image_type;                                                                         \
00162                                                                                                 \
00163 public:                                                                                         \
00164   Energy(void*) {}                                                                              \
00165                                                                                                 \
00166 public:                                                                                         \
00167   ::ntg::float_s                                                                                \
00168   compute(const I& gradient,                                                                    \
00169           const ::oln::snakes::node<I>&,                                                        \
00170           const ::oln::snakes::node<I>&,                                                        \
00171           const ::oln::snakes::node<I>&);                                                       \
00172 };                                                                                              \
00173                                                                                                 \
00174 template<class I>                                                                               \
00175 ::ntg::float_s                                                                                  \
00176 Energy<I>::compute(const I& Gradient,                                                           \
00177                    const ::oln::snakes::node<I>& PrevNode,                                      \
00178                    const ::oln::snakes::node<I>& CurrentNode,                                   \
00179                    const ::oln::snakes::node<I>& NextNode)
00180 
00181 
00183     oln_snakes_define_external_energy(dummy_energy,,,,)
00184     {
00185       return 0;
00186     }
00187 
00188   } // end snakes
00189 
00190 } // end oln
00191 
00192 #include <oln/snakes/energies.hxx>
00193 
00194 #endif // !OLENA_SNAKES_ENERGIES_HH

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