00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef SNAKESENERGY_H
00010 #define SNAKESENERGY_H
00011
00012 #include <shape/ShapeEnergyInterface.hpp>
00013 #include <image/Image.hpp>
00014 #include <shape/ShapeStatistics.hpp>
00015 #include <shape/BoundaryDiscretizer.hpp>
00016
00017 #include <set>
00018
00019
00020 namespace imaging
00021 {
00047 template <class shape_t>
00048 class SnakesEnergy : public ShapeEnergyInterface<shape_t>
00049 {
00050 const static std::size_t SHAPE_DIMENSION = shape_t::SHAPE_DIMENSION;
00051
00052 Image<SHAPE_DIMENSION, float_t> _edge_map;
00053 float_t _beta;
00054 std::size_t _n_integration_points;
00055
00056 shape_t _initial_shape;
00057 ublas::vector<float_t> _current_argument;
00058 shape_t _current_shape;
00059 float_t _current_energy;
00060
00061 public:
00063 template <class const_accessort_t>
00064 SnakesEnergy(const const_accessort_t & edge_map,
00065 const shape_t & initial_shape,
00066 float_t beta,
00067 std::size_t n_integration_points) :
00068 _edge_map(edge_map),
00069 _initial_shape(initial_shape),
00070 _beta(beta),
00071 _n_integration_points(n_integration_points),
00072 _current_argument(ublas::scalar_vector<float_t>(initial_shape.dimension(), 0.0)),
00073 _current_shape(initial_shape),
00074 _current_energy(0.0)
00075 { }
00076
00077 ublas::vector<float_t> & current_argument()
00078 {
00079 return _current_argument;
00080 }
00081
00082 const shape_t & current_shape() const
00083 {
00084 return _current_shape;
00085 }
00086
00087 float_t current_energy() const
00088 {
00089 return _current_energy;
00090 }
00091
00092 std::size_t dimension() const
00093 {
00094 return _initial_shape.dimension();
00095 }
00096
00097 void set_argument()
00098 {
00099 float_t boundary_area, edge_energy;
00100 std::set<size_t> overlap_indices;
00101
00102 _initial_shape.exponential(_current_argument, _current_shape);
00103
00104 std::auto_ptr< BoundaryDiscretizer<shape_t::SHAPE_DIMENSION> > edge_map_discretizer = _current_shape.boundary_discretizer(_n_integration_points);
00105
00106 boundary_area = edge_map_discretizer->compute_boundary_area();
00107 edge_energy = edge_map_discretizer->integrate(_edge_map);
00108
00109 _current_energy = - edge_energy + _beta * boundary_area;
00110
00111 }
00112 };
00113 }
00114
00115 #endif