contrib/mul/vil3d/algo/vil3d_structuring_element.h
Go to the documentation of this file.
00001 #ifndef vil3d_structuring_element_h_
00002 #define vil3d_structuring_element_h_
00003 //:
00004 // \file
00005 // \brief Structuring element for 3D morphology represented as a list of non-zero pixels
00006 // \author Tim Cootes
00007 
00008 #include <vcl_vector.h>
00009 #include <vcl_iosfwd.h>
00010 #include <vcl_cstddef.h>
00011 
00012 //: Structuring element for morphology represented as a list of non-zero pixels
00013 // Elements in box bounded by [min_i(),max_i()][min_j(),max_j()]
00014 // Non-zero pixels are given by (p_i[k],p_j[k])
00015 class vil3d_structuring_element
00016 {
00017   //: i position of elements (i,j,k)
00018   vcl_vector<int> p_i_;
00019   //: j position of elements (i,j,k)
00020   vcl_vector<int> p_j_;
00021   //: k position of elements (i,j,k)
00022   vcl_vector<int> p_k_;
00023   //: i range of elements is [min_i_,max_i_]
00024   int min_i_;
00025   //: i range of elements is [min_i_,max_i_]
00026   int max_i_;
00027   //: j range of elements is [min_j_,max_j_]
00028   int min_j_;
00029   //: j range of elements is [min_j_,max_j_]
00030   int max_j_;
00031   //: k range of elements is [min_k_,max_k_]
00032   int min_k_;
00033   //: k range of elements is [min_k_,max_k_]
00034   int max_k_;
00035 
00036  public:
00037   vil3d_structuring_element()
00038     : min_i_(0),max_i_(-1),min_j_(0),max_j_(-1),min_k_(0),max_k_(-1) {}
00039 
00040   //: Define elements { (p_i[a],p_j[a],p_k[a]) }
00041   vil3d_structuring_element(const vcl_vector<int>& p_i,
00042                             const vcl_vector<int>& p_j,
00043                             const vcl_vector<int>& p_k);
00044 
00045   //: Define elements { (p_i[a],p_j[a],p_k[a]) }
00046   void set(const vcl_vector<int>& p_i,
00047            const vcl_vector<int>& p_j,
00048            const vcl_vector<int>& p_k);
00049 
00050   //: Set to sphere of radius r
00051   //  Select pixels in disk s.t. x*x+y*y+z*z<=r^r
00052   void set_to_sphere(double r);
00053 
00054   //: Set to circle of radius r
00055   //  Select pixels in circle s.t. y*y+z*z<=r^r
00056   void set_to_circle_i(double r);
00057 
00058   //: Set to circle of radius r
00059   //  Select pixels in circle s.t. y*y+z*z<=r^r
00060   void set_to_circle_j(double r);
00061 
00062   //: Set to circle of radius r
00063   //  Select pixels in circle s.t. y*y+z*z<=r^r
00064   void set_to_circle_k(double r);
00065 
00066   //: Set to 6 axis-aligned neighbours plus self
00067   void set_to_7();
00068 
00069   //: Set to 26 touching neighbours plus self
00070   void set_to_27();
00071 
00072 
00073   //: Set to sphere of radius r, but with non isotropic voxel sizes
00074   //  Select pixels in disk s.t. x*x+y*y+z*z<=r^r
00075   void set_to_sphere_noniso(double r, double sx, double sy, double sz);
00076 
00077   //: Set to line along i (ilo,0)..(ihi,0)
00078   void set_to_line_i(int ilo, int ihi);
00079 
00080   //: Set to line along j (jlo,0)..(jhi,0)
00081   void set_to_line_j(int jlo, int jhi);
00082 
00083   //: Set to line along k (klo,0)..(khi,0)
00084   void set_to_line_k(int klo, int khi);
00085 
00086   //: i position of elements (i,j,k)
00087   const vcl_vector<int>& p_i() const { return p_i_; }
00088   //: j position of elements (i,j,k)
00089   const vcl_vector<int>& p_j() const { return p_j_; }
00090   //: k position of elements (i,j,k)
00091   const vcl_vector<int>& p_k() const { return p_k_; }
00092 
00093   //: i range of elements is [min_i(),max_i()]
00094   int min_i() const { return min_i_; }
00095   //: i range of elements is [min_i_,max_i()]
00096   int max_i() const { return max_i_; }
00097   //: j range of elements is [min_j_,max_j()]
00098   int min_j() const { return min_j_; }
00099   //: j range of elements is [min_j_,max_j()]
00100   int max_j() const { return max_j_; }
00101   //: k range of elements is [min_k(),max_k()]
00102   int min_k() const { return min_k_; }
00103   //: k range of elements is [min_k(),max_k()]
00104   int max_k() const { return max_k_; }
00105 };
00106 
00107 //: Write details to stream
00108 vcl_ostream& operator<<(vcl_ostream&, const vil3d_structuring_element& element);
00109 
00110 //: Generate a list of offsets for use on image with istep,jstep
00111 //  On exit offset[a] = element.p_i()[a]*istep +  element.p_j()[a]*jstep
00112 //                      +  element.p_k()[a]*kstep
00113 //
00114 //  Gives an efficient way of looping through all the pixels in the structuring element
00115 void vil3d_compute_offsets(vcl_vector<vcl_ptrdiff_t>& offset,
00116                            const vil3d_structuring_element& element,
00117                            vcl_ptrdiff_t istep,
00118                            vcl_ptrdiff_t jstep,
00119                            vcl_ptrdiff_t kstep);
00120 
00121 #endif // vil3d_structuring_element_h_