Go to the documentation of this file.00001
00002 #ifndef vdgl_digital_region_h_
00003 #define vdgl_digital_region_h_
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 #include <vcl_vector.h>
00032 #include <vcl_string.h>
00033 #include <vnl/vnl_double_3x3.h>
00034 #include <vnl/vnl_float_3x3.h>
00035 #include <vnl/vnl_float_2.h>
00036 #include <vsol/vsol_region_2d.h>
00037 #include <vsol/vsol_point_2d.h>
00038 class vdgl_digital_region : public vsol_region_2d
00039 {
00040 public:
00041
00042
00043 vdgl_digital_region()
00044 : vsol_region_2d(),
00045 npts_(0), pixel_size_(1.f), xp_(0), yp_(0), pix_(0),
00046 max_(0), min_((unsigned short)(-1)), xo_(0.f), yo_(0.f),
00047 io_(0.f), io_stdev_(0.0f), pix_index_(0),
00048 fit_valid_(false), scatter_matrix_valid_(false),
00049 X2_(0), Y2_(0), I2_(0), XY_(0), XI_(0), YI_(0), error_(0), sigma_sq_(0) {}
00050
00051 vdgl_digital_region(int npts, const float* xp, const float* yp, const unsigned short *pix);
00052 vdgl_digital_region(vdgl_digital_region const& r);
00053 ~vdgl_digital_region();
00054
00055
00056
00057 void ResetPixelData();
00058 void IncrementMeans(float x, float y, unsigned short pix);
00059 void InitPixelArrays();
00060 void InsertInPixelArrays(float x, float y, unsigned short pix);
00061
00062
00063 float const* Xj() const {return xp_;}
00064 float const* Yj() const {return yp_;}
00065 unsigned short const* Ij() const {return pix_;}
00066 unsigned int Npix() const {return npts_;}
00067
00068
00069
00070 void set_pixel_size(float pixel_size){pixel_size_= pixel_size;}
00071 float get_pixel_size() const {return pixel_size_;}
00072
00073
00074 float get_min() const { return min_; }
00075 float get_max() const { return max_; }
00076
00077 void reset() const { pix_index_ = -1; }
00078
00079 bool next() const { ++pix_index_; return pix_index_<(int)npts_; }
00080 float X() const;
00081 float Y() const;
00082 unsigned short I() const;
00083
00084 void set_X(float x);
00085 void set_Y(float y);
00086 void set_I(unsigned short I);
00087
00088
00089 float Xo() const;
00090 float Yo() const;
00091 float Io() const;
00092 float Io_sd() const;
00093 float ComputeIntensityStdev();
00094
00095
00096 double X2() const;
00097 double Y2() const;
00098 double XY() const;
00099 double I2() const;
00100 double XI() const;
00101 double YI() const;
00102
00103 float Diameter() const;
00104 float AspectRatio() const;
00105
00106
00107 virtual double area() const { return npts_*pixel_size_*pixel_size_; }
00108
00109
00110 virtual vsol_point_2d_sptr centroid() const
00111 {return new vsol_point_2d(this->Xo(), this->Yo());}
00112
00113
00114 bool transform(vnl_float_3x3 const& t);
00115
00116
00117
00118 vcl_vector<unsigned int> histogram(int nbins);
00119
00120
00121 vcl_vector<unsigned int> residual_histogram(int nbins, float* min=0, float* max=0);
00122
00123
00124 virtual bool is_convex() const { return false; }
00125
00126 void PrincipalOrientation(vnl_float_2& major_axis);
00127
00128
00129 double Ix() const;
00130 double Iy() const;
00131 double Var() const {return sigma_sq_;}
00132 float Ir() const;
00133
00134
00135 void DoPlaneFit() const;
00136 void PrintFit() const;
00137
00138 virtual vsol_spatial_object_2d* clone() const;
00139
00140
00141 vcl_string is_a() const { return vcl_string("vdgl_digital_region"); }
00142
00143 protected:
00144
00145 unsigned int npts_;
00146 float pixel_size_;
00147 float *xp_, *yp_;
00148 unsigned short *pix_;
00149 float max_, min_;
00150 float xo_, yo_, io_;
00151 float io_stdev_;
00152 mutable int pix_index_;
00153 void ComputeScatterMatrix() const;
00154 void IncrByXYI(double x, double y, int intens) const;
00155 double ComputeSampleResidual() const;
00156
00157 mutable bool fit_valid_;
00158 mutable bool scatter_matrix_valid_;
00159 mutable double Ix_;
00160 mutable double Iy_;
00161
00162 mutable double X2_,Y2_,I2_,XY_,XI_,YI_;
00163 mutable double error_, sigma_sq_;
00164 mutable vnl_double_3x3 Si_;
00165 };
00166
00167 #endif // vdgl_digital_region_h_