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, Inc., 51 Franklin Street, Fifth Floor,
00016 // Boston, MA 02110-1301, 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 # include "node.hh"
00032 # include <ntg/float.hh>
00033 
00034 namespace oln {
00035 
00036   namespace snakes {
00037 
00040     template <class I>
00041     class energy
00042     {
00043     public:
00044       energy() {}
00045       energy(void *) {}
00046 
00047     public:
00053       ntg::float_s
00054       compute(const I&, const node<I>&, const node<I>&, const node<I>&)
00055       {
00056         // This is intended to cause an error. The user must define a
00057         // member function named `compute()' for each external energy,
00058         // otherwise the following method will be compiled and cause an
00059         // error.
00060         user_defined_external_energy_functor::compute();
00061         return 0.f;
00062       }
00063 
00064     public:
00066       static void* cookie() { return 0; };
00067 
00068     private:
00069       struct user_defined_external_energy_functor{};
00070     };
00071 
00072 
00081     template <class I>
00082     class continuity_energy : public energy<I>
00083     {
00084     public:
00085       typedef I image_type;
00086 
00087     public:
00088       continuity_energy(ntg::float_s* average_dist) :
00089         average_dist(average_dist) {}
00090 
00091     public:
00092       inline
00093       ntg::float_s
00094       compute(const I&,
00095               const node<I>& prev,
00096               const node<I>& current,
00097               const node<I>&);
00098 
00099     private:
00100       ntg::float_s* average_dist;
00101     };
00102 
00103 
00111     template <class I>
00112     class curvature_energy : public energy<I>
00113     {
00114     public:
00115       typedef I image_type;
00116 
00117     public:
00118       curvature_energy(void *) {}
00119 
00120     public:
00121       static inline
00122       ntg::float_s
00123       compute(const I&,
00124               const node<I>& prev,
00125               const node<I>& current,
00126               const node<I>& next);
00127     };
00128 
00129 
00135     template <class I>
00136     class image_energy : public energy<I>
00137     {
00138     public:
00139       typedef I image_type;
00140 
00141     public:
00142       image_energy(void*) {}
00143 
00144     public:
00145       static inline
00146       ntg::float_s
00147       compute(const I& gradient,
00148               const node<I>&,
00149               const node<I>& current,
00150               const node<I>&);
00151     };
00152 
00153 
00158 #define oln_snakes_define_external_energy(Energy, Gradient, PrevNode, CurrentNode, NextNode)    \
00159                                                                                                 \
00160 template<class I>                                                                               \
00161 class Energy : public energy<I>                                                                 \
00162 {                                                                                               \
00163 public:                                                                                         \
00164   typedef I image_type;                                                                         \
00165                                                                                                 \
00166 public:                                                                                         \
00167   Energy(void*) {}                                                                              \
00168                                                                                                 \
00169 public:                                                                                         \
00170   ::ntg::float_s                                                                                \
00171   compute(const I& gradient,                                                                    \
00172           const ::oln::snakes::node<I>&,                                                        \
00173           const ::oln::snakes::node<I>&,                                                        \
00174           const ::oln::snakes::node<I>&);                                                       \
00175 };                                                                                              \
00176                                                                                                 \
00177 template<class I>                                                                               \
00178 ::ntg::float_s                                                                                  \
00179 Energy<I>::compute(const I& Gradient,                                                           \
00180                    const ::oln::snakes::node<I>& PrevNode,                                      \
00181                    const ::oln::snakes::node<I>& CurrentNode,                                   \
00182                    const ::oln::snakes::node<I>& NextNode)
00183 
00184 
00186     oln_snakes_define_external_energy(dummy_energy,,,,)
00187     {
00188       return 0;
00189     }
00190 
00191   } // end snakes
00192 
00193 } // end oln
00194 
00195 #include <oln/snakes/energies.hxx>
00196 
00197 #endif // !OLENA_SNAKES_ENERGIES_HH

Generated on Tue Feb 20 20:18:52 2007 for Olena by  doxygen 1.5.1