contrib/gel/vsol/vsol_group_2d.h
Go to the documentation of this file.
00001 // This is gel/vsol/vsol_group_2d.h
00002 #ifndef vsol_group_2d_h_
00003 #define vsol_group_2d_h_
00004 //*****************************************************************************
00005 //:
00006 // \file
00007 // \brief Group of spatial objects in a 2D space
00008 //
00009 // \author François BERTEL
00010 // \date   2000-04-14
00011 //
00012 // \verbatim
00013 //  Modifications
00014 //   2000-04-14 François BERTEL   Creation
00015 //   2000-06-17 Peter Vanroose    Implemented all operator==()s and type info
00016 //   2004-05-14 Peter Vanroose    Added describe()
00017 //   2004-05-16 Joseph Mundy      Added binary I/0
00018 // \endverbatim
00019 //*****************************************************************************
00020 
00021 //*****************************************************************************
00022 // External declarations for values
00023 //*****************************************************************************
00024 #include <vsl/vsl_binary_io.h>
00025 #include <vsol/vsol_spatial_object_2d.h>
00026 #include <vcl_vector.h>
00027 #include <vcl_iostream.h>
00028 
00029 class vsol_group_2d : public vsol_spatial_object_2d
00030 {
00031   //***************************************************************************
00032   // Data members
00033   //***************************************************************************
00034 
00035   //---------------------------------------------------------------------------
00036   //: Set of objects that `this' contains
00037   //---------------------------------------------------------------------------
00038   vcl_vector<vsol_spatial_object_2d_sptr> *storage_;
00039 
00040  public:
00041   //***************************************************************************
00042   // Initialization
00043   //***************************************************************************
00044 
00045   //---------------------------------------------------------------------------
00046   //: Default Constructor: group with no child
00047   //---------------------------------------------------------------------------
00048   vsol_group_2d(void);
00049 
00050   //---------------------------------------------------------------------------
00051   //: Copy constructor.
00052   //  The objects of the group are not duplicated
00053   //---------------------------------------------------------------------------
00054   vsol_group_2d(const vsol_group_2d &other);
00055 
00056   //---------------------------------------------------------------------------
00057   //: Destructor
00058   //  The objects of the group are not deleted
00059   //---------------------------------------------------------------------------
00060   virtual ~vsol_group_2d();
00061 
00062   //---------------------------------------------------------------------------
00063   //: Clone `this': creation of a new object and initialization
00064   //  See Prototype pattern
00065   //---------------------------------------------------------------------------
00066   virtual vsol_spatial_object_2d* clone(void) const;
00067 
00068   //***************************************************************************
00069   // Access
00070   //***************************************************************************
00071 
00072   //---------------------------------------------------------------------------
00073   //: Return the object `i'
00074   //  REQUIRE: i>=0 and i<size()
00075   //---------------------------------------------------------------------------
00076   vsol_spatial_object_2d_sptr object(unsigned int i) const;
00077 
00078   //***************************************************************************
00079   // Status report
00080   //***************************************************************************
00081 
00082   //---------------------------------------------------------------------------
00083   //: Return the real type of a group. It is a SPATIALGROUP
00084   //---------------------------------------------------------------------------
00085   vsol_spatial_object_2d_type spatial_type(void) const;
00086 
00087   //---------------------------------------------------------------------------
00088   //: Compute the bounding box of `this'
00089   //  REQUIRE: size()>0
00090   //---------------------------------------------------------------------------
00091   virtual void compute_bounding_box(void) const; // virtual of vsol_spatial_object_2d
00092 
00093   //---------------------------------------------------------------------------
00094   //: Return the number of direct children of the group
00095   //---------------------------------------------------------------------------
00096   unsigned int size(void) const { return storage_->size(); }
00097 
00098   //---------------------------------------------------------------------------
00099   //: Return the number of objects of the group
00100   //---------------------------------------------------------------------------
00101   unsigned int deep_size(void) const;
00102 
00103   //---------------------------------------------------------------------------
00104   //: Is `new_object' a child (direct or not) of `this' ?
00105   //---------------------------------------------------------------------------
00106   bool is_child(const vsol_spatial_object_2d_sptr &new_object) const;
00107 
00108   //***************************************************************************
00109   // Element change
00110   //***************************************************************************
00111 
00112   //---------------------------------------------------------------------------
00113   //: Add an object `new_object' to `this'
00114   //---------------------------------------------------------------------------
00115   void add_object(const vsol_spatial_object_2d_sptr &new_object);
00116 
00117   //***************************************************************************
00118   // Removal
00119   //***************************************************************************
00120 
00121   //---------------------------------------------------------------------------
00122   //: Remove object `i' of `this' (not delete it)
00123   //  REQUIRE: i>=0 and i<size()
00124   //---------------------------------------------------------------------------
00125   void remove_object(unsigned int i);
00126 
00127   //---------------------------------------------------------------------------
00128   //: The same behavior than dynamic_cast<>.
00129   //  Needed because VXL is not compiled with -frtti :-(
00130   //---------------------------------------------------------------------------
00131   virtual const vsol_group_2d *cast_to_group(void) const { return this; }
00132   virtual vsol_group_2d *cast_to_group(void) { return this; }
00133 
00134   //---------------------------------------------------------------------------
00135   //: Has `this' the same number of elements and as other and equal elements?
00136   //---------------------------------------------------------------------------
00137   virtual bool operator==(const vsol_group_2d &other) const;
00138   virtual bool operator==(const vsol_spatial_object_2d& obj) const; // virtual of vsol_spatial_object_2d
00139 
00140   //---------------------------------------------------------------------------
00141   //: Has `this' not the same number of elements and as other and not equal elements?
00142   //---------------------------------------------------------------------------
00143   inline bool operator!=(const vsol_group_2d &o)const{return !operator==(o);}
00144 
00145   // ==== Binary IO methods ======
00146 
00147   //: Binary save self to stream.
00148   void b_write(vsl_b_ostream &os) const;
00149 
00150   //: Binary load self from stream.
00151   void b_read(vsl_b_istream &is);
00152 
00153   //: Return IO version number;
00154   short version() const;
00155 
00156   //: Print an ascii summary to the stream
00157   void print_summary(vcl_ostream &os) const;
00158 
00159   //: Return a platform independent string identifying the class
00160   virtual vcl_string is_a() const { return "vsol_group_2d"; }
00161 
00162   //: Return true if the argument matches the string identifying the class or any parent class
00163   virtual bool is_class(const vcl_string& cls) const { return cls==is_a(); }
00164 
00165   //---------------------------------------------------------------------------
00166   //: output description to stream
00167   //---------------------------------------------------------------------------
00168   inline void describe(vcl_ostream &strm, int blanking=0) const
00169   {
00170     if (blanking < 0) blanking = 0; while (blanking--) strm << ' ';
00171     strm << "vsol_group_2d of size " << this->size() << ":\n";
00172     for (vcl_vector<vsol_spatial_object_2d_sptr>::const_iterator it = storage_->begin();
00173          it != storage_->end(); ++it)
00174       (*it)->describe(strm,blanking+2);
00175   }
00176 };
00177 
00178 
00179 //: Binary save vsol_group_2d* to stream.
00180 void vsl_b_write(vsl_b_ostream &os, const vsol_group_2d* p);
00181 
00182 //: Binary load vsol_group_2d* from stream.
00183 void vsl_b_read(vsl_b_istream &is, vsol_group_2d* &p);
00184 
00185 #endif // vsol_group_2d_h_