00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00049
00050
00051
00052 #ifndef _LEVELSETFUNCTION_H
00053 #define _LEVELSETFUNCTION_H
00054
00055 #include "errormacros.h"
00056 #include "Image.h"
00057 #include "Mask.h"
00058
00059 namespace lsseg {
00060
00061
00070 class LevelSetFunction : public Image<double>
00071
00072 {
00073 public:
00078 LevelSetFunction() : Image<double>(0, 0, 0, 1) {}
00079 LevelSetFunction(int x, int y, int z = 1, double val = 0)
00080 : Image<double>(x, y, z, 1, val) {}
00081 virtual ~LevelSetFunction() {}
00082
00084 LevelSetFunction(const LevelSetFunction& rhs) : Image<double>(rhs) {};
00085
00093 LevelSetFunction(const LevelSetFunction& rhs, bool copy)
00094 : Image<double>(rhs, copy) {}
00095
00097 virtual Image<double>& operator=(const Image<double>& rhs) {
00098 single_channel_assert(rhs.numChannels());
00099 return Image<double>::operator=(rhs);
00100 }
00101
00103 virtual LevelSetFunction& operator=(const double& val)
00104 {
00105 std::fill(data_.begin(), data_.end(), val);
00106 return *this;
00107 }
00108
00111 void resize(const LevelSetFunction& rhs)
00112 {
00113 resize(rhs.dimx(), rhs.dimy(), rhs.dimz(), 1);
00114 }
00115
00124 virtual void resize(int x, int y, int z= 1, int channels = 1) {
00125 single_channel_assert(channels);
00126 Image<double>::resize(x, y, z, channels);
00127 }
00128
00133 virtual void swap(Image<double>& rhs) {
00134 single_channel_assert(rhs.numChannels());
00135 Image<double>::swap(rhs);
00136 }
00137
00151 virtual void permute(const int* const perm) {
00152 ALWAYS_ERROR_IF(perm[3] != 3,
00153 "cannot permute the 'channel' of a LevelSetFunction");
00154 Image<double>::permute(perm);
00155 }
00156
00162 virtual void read(std::istream& is, bool binary=true) {
00163 LevelSetFunction tmp;
00164 tmp.Image<double>::read(is, binary);
00165 single_channel_assert(tmp.numChannels());
00166 swap(tmp);
00167 }
00168
00169
00170
00171
00172
00173
00178 inline double gradientNorm2D(int x, int y) const;
00179
00182 inline double gradientNorm3D(int x, int y, int z) const;
00183
00186 inline double curvature2D(int x, int y) const;
00187
00190 inline double curvature3D(int x, int y, int z) const;
00191
00203 inline void curvature2D(Image<double>& target, Mask* mask = 0) const;
00204
00214 inline void curvature3D(Image<double>& target, Mask* mask = 0) const;
00215
00229 inline void curvatureTimesGrad2D(Image<double>& target, Mask* mask = 0) const;
00230
00234 inline double curvatureTimesGrad2D(int x, int y) const;
00235
00238 inline double curvatureTimesGrad3D(int x, int y, int z) const;
00239
00252 inline void curvatureTimesGrad3D(Image<double>& target, Mask* mask = 0) const;
00253
00265 inline void gradientNorm2D(Image<double>& target, Mask* mask = 0) const;
00266
00276 inline void gradientNorm3D(Image<double>& target, Mask* mask = 0) const;
00277
00290 void reinitialize2D(const Mask* mask = 0);
00291
00303 void reinitialize3D(const Mask* mask = 0);
00304
00305 private:
00312 void single_channel_assert(int num_chan) {
00313 ALWAYS_ERROR_IF(num_chan != 1, "Single channel assert failed.");
00314 }
00315
00317 mutable double cached_;
00318 };
00319
00320 };
00321
00322 #include "LevelSetFunction_implementation.h"
00323
00324 #endif // _LEVELSETFUNCTION_H
00325