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