contrib/rpl/rgrl/rgrl_mask_oriented_box.h
Go to the documentation of this file.
00001 #ifndef rgrl_mask_oriented_box_h_
00002 #define rgrl_mask_oriented_box_h_
00003 //:
00004 // \file
00005 // \brief  mask using oriented box (i.e., not-axis-aligned)
00006 //         After applying the (transpose of) rotation matrix,
00007 //         it is defined by min and max two points (similar to rgrl_mask_box)
00008 //
00009 // \author Gehua Yang
00010 // \date   Jan 2007
00011 // \verbatim
00012 // Modifications
00013 // \endverbatim
00014 
00015 #include <vcl_iosfwd.h>
00016 #include <vnl/vnl_vector.h>
00017 #include <vnl/vnl_matrix.h>
00018 
00019 #include <rgrl/rgrl_object.h>
00020 #include <rgrl/rgrl_macros.h>
00021 #include <rgrl/rgrl_mask.h>
00022 
00023 //: this is a wrapper on an oriented box
00024 class rgrl_mask_oriented_box
00025   : public rgrl_mask
00026 {
00027  public:
00028   //: Null initialization
00029   //
00030   // Initializes the region to the box from (0,0,...) to (0,0,...)
00031   //
00032   rgrl_mask_oriented_box( unsigned dim );
00033 
00034   //: Initialize a box from \a origin with length \a len.
00035   rgrl_mask_oriented_box( vnl_vector<double> const& origin,
00036                           vnl_matrix<double> const& axes,
00037                           vnl_vector<double> const& len );
00038 
00039   //: Initialize a box from \a x0 to \a x1 using axes specified in columns of \a axes
00040   rgrl_mask_oriented_box( vnl_vector<double> const& oriented_xmin,
00041                           vnl_vector<double> const& oriented_xmax,
00042                           vnl_matrix<double> const& axes );
00043 
00044   //: True if a point is inside the region
00045   bool inside( vnl_vector<double> const& pt ) const;
00046 
00047   //: Set the lengths along each axis
00048   void set_len( vnl_vector<double> const& len );
00049 
00050   //: Set the axes
00051   void set_axes( vnl_matrix<double> const& axes );
00052 
00053   //: the lower coordinate of the box.
00054   vnl_vector<double>
00055   origin() const;
00056 
00057   //: Set the lengths along each axis
00058   vnl_vector<double>
00059   len() const
00060   { return omax_-omin_; }
00061 
00062   //: Set the axes
00063   vnl_matrix<double> const&
00064   axes() const
00065   { return axes_; }
00066 
00067   //: get the xmin after re-orientation
00068   vnl_vector<double> const&
00069   oriented_x0() const
00070   { return omin_; }
00071 
00072   //: get the xmin after re-orientation
00073   vnl_vector<double> const&
00074   oriented_x1() const
00075   { return omax_; }
00076 
00077   //: True iff all the components are equal.
00078   bool operator==( const rgrl_mask_oriented_box& other ) const;
00079 
00080   //: True iff some of the components are not equal.
00081   bool operator!=( const rgrl_mask_oriented_box& other ) const;
00082 
00083   //: get average distance of corresponding vertices between two oriented box
00084   double
00085   average_vertices_dist( const rgrl_mask_oriented_box& other ) const;
00086 
00087   // Defines type-related functions
00088   rgrl_type_macro( rgrl_mask_oriented_box, rgrl_mask );
00089 
00090  protected:
00091   void update_bounding_box();
00092 
00093  protected:
00094   //: min after rotation
00095   vnl_vector<double> omin_;
00096   //: max after rotation
00097   vnl_vector<double> omax_;
00098   vnl_matrix<double> axes_;
00099 };
00100 
00101 //: An output operator for displaying a mask_box
00102 vcl_ostream& operator<<(vcl_ostream& os, const rgrl_mask_oriented_box& box);
00103 
00104 //: An output operator for displaying a mask_box
00105 vcl_istream& operator>>(vcl_istream& is, rgrl_mask_oriented_box& box);
00106 
00107 #endif