contrib/gel/vtol/vtol_chain.h
Go to the documentation of this file.
00001 // This is gel/vtol/vtol_chain.h
00002 #ifndef vtol_chain_h_
00003 #define vtol_chain_h_
00004 //-----------------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \brief Base class for representation of holes
00008 //
00009 //  The vtol_chain class is a base class of vtol_one_chain and vtol_two_chain.
00010 //  It provides the data and methods for creating the doubly linked subhierarchy
00011 //  of holes in blocks and faces respectively.  (Warning: this class and
00012 //  philosophy of holes may not be around after evaluation of the necessity
00013 //  for Boolean operations....pav).
00014 //
00015 // \author
00016 //     Patricia A. Vrobel
00017 //-----------------------------------------------------------------------------
00018 
00019 #include <vtol/vtol_chain_sptr.h>
00020 #include <vtol/vtol_topology_object.h>
00021 #include <vcl_vector.h>
00022 
00023 //: Base class of vtol_two_chain and vtol_one_chain (representation of holes)
00024 //
00025 //*****************************************************************************
00026 // ALL THE DERIVED AND NONE ABSTRACT CLASSES OF THIS CLASS MUST CALL
00027 // unlink_all_chain_inferiors() IN THEIR DESTRUCTOR
00028 // unlink_all_chain_inferiors() CANT BE CALLED DIRECTLY IN THIS CLASS,
00029 // OTHERWISE BAD VERSIONS OF METHODS SHOULD BE CALLED (C++ IS STUPID !)
00030 //*****************************************************************************
00031 
00032 class vtol_chain : public vtol_topology_object
00033 {
00034  protected:
00035    //***************************************************************************
00036    // --- Data members ---
00037    //***************************************************************************
00038 
00039   //---------------------------------------------------------------------------
00040   //: array of the inferiors
00041   //---------------------------------------------------------------------------
00042   chain_list chain_inferiors_;
00043 
00044   //---------------------------------------------------------------------------
00045   //: array of the superiors
00046   //---------------------------------------------------------------------------
00047   vcl_list<vtol_chain*> chain_superiors_;
00048 
00049   bool is_cycle_; // True if `this' is a connected chain
00050   vcl_vector<signed char> directions_;
00051 
00052  public:
00053    //***************************************************************************
00054    // --- Initialization ---
00055    //***************************************************************************
00056 
00057   //---------------------------------------------------------------------------
00058   //: Default constructor
00059   //---------------------------------------------------------------------------
00060   vtol_chain();
00061 
00062   //---------------------------------------------------------------------------
00063   //: Destructor
00064   //---------------------------------------------------------------------------
00065   virtual ~vtol_chain();
00066 
00067   //***************************************************************************
00068   // Access
00069   //***************************************************************************
00070 
00071   //---------------------------------------------------------------------------
00072   //: Return a pointer to the inferiors (no copy)
00073   //---------------------------------------------------------------------------
00074   virtual const chain_list *chain_inferiors() const;
00075 
00076   //---------------------------------------------------------------------------
00077   //: Return a copy of the chain_superiors list
00078   // The return value must be deleted by the caller
00079   //---------------------------------------------------------------------------
00080   virtual const chain_list *chain_superiors() const;
00081 
00082    //***************************************************************************
00083    // --- Replaces dynamic_cast<T> ---
00084    //***************************************************************************
00085 
00086   //---------------------------------------------------------------------------
00087   //: Return `this' if `this' is a chain, 0 otherwise
00088   //---------------------------------------------------------------------------
00089   virtual const vtol_chain *cast_to_chain() const { return this; }
00090 
00091   //---------------------------------------------------------------------------
00092   //: Return `this' if `this' is a chain, 0 otherwise
00093   //---------------------------------------------------------------------------
00094   virtual vtol_chain *cast_to_chain() { return this; }
00095 
00096    //***************************************************************************
00097    // --- Status report ---
00098    //***************************************************************************
00099 
00100   //---------------------------------------------------------------------------
00101   //: Is `chain_inf_sup' type valid for `this' ?
00102   //---------------------------------------------------------------------------
00103   virtual bool valid_chain_type(vtol_chain_sptr chain_inf_sup) const = 0;
00104 
00105   //---------------------------------------------------------------------------
00106   //: Is `inferior' already an inferior of `this' ?
00107   //---------------------------------------------------------------------------
00108   virtual bool is_chain_inferior(vtol_chain_sptr chain_inferior) const;
00109 
00110   //---------------------------------------------------------------------------
00111   //: Is `superior' already a superior of `this' ?
00112   //---------------------------------------------------------------------------
00113   virtual bool is_chain_superior(vtol_chain const* chain_superior) const;
00114 
00115   //---------------------------------------------------------------------------
00116   //: Return the number of superiors
00117   //---------------------------------------------------------------------------
00118   int num_chain_superiors() const {return chain_superiors_.size();}
00119 
00120   //---------------------------------------------------------------------------
00121   //: Return the number of inferiors
00122   //---------------------------------------------------------------------------
00123   int num_chain_inferiors() const {return chain_inferiors_.size();}
00124 
00125   //---------------------------------------------------------------------------
00126   //: Does `this' contain some sub chains ?
00127   //---------------------------------------------------------------------------
00128   bool contains_sub_chains() const { return chain_inferiors_.size()>0; }
00129 
00130   //---------------------------------------------------------------------------
00131   //: Is `this' a sub chain ?
00132   //---------------------------------------------------------------------------
00133   bool is_sub_chain() const { return chain_superiors_.size()>0; }
00134 
00135    //***************************************************************************
00136    // --- Basic operations ---
00137    //***************************************************************************
00138 
00139   //---------------------------------------------------------------------------
00140   //: Link `this' with an inferior `chain_inferior'
00141   //  REQUIRE: valid_chain_type(chain_inferior)
00142   //           and !is_chain_inferior(chain_inferior)
00143   //---------------------------------------------------------------------------
00144   void link_chain_inferior(vtol_chain_sptr chain_inferior);
00145 
00146   //---------------------------------------------------------------------------
00147   //: Unlink `this' with the chain_inferior `chain_inferior'
00148   //  REQUIRE: valid_chain_type(chain_inferior)
00149   //           and is_chain_inferior(chain_inferior)
00150   //---------------------------------------------------------------------------
00151   void unlink_chain_inferior(vtol_chain_sptr chain_inferior);
00152 
00153   //---------------------------------------------------------------------------
00154   //: Unlink `this' with all its chain inferiors
00155   //---------------------------------------------------------------------------
00156   void unlink_all_chain_inferiors();
00157 
00158   //---------------------------------------------------------------------------
00159   //: Unlink `this' of the network
00160   //---------------------------------------------------------------------------
00161   void unlink();
00162 
00163   //---------------------------------------------------------------------------
00164   //: Is `this' a connected chain ?
00165   //---------------------------------------------------------------------------
00166   bool is_cycle() const;
00167 
00168   //---------------------------------------------------------------------------
00169   //: Return the directions
00170   //---------------------------------------------------------------------------
00171   const vcl_vector<signed char> *directions() const { return &directions_; }
00172 
00173   //---------------------------------------------------------------------------
00174   //: Return the directions
00175   //---------------------------------------------------------------------------
00176   vcl_vector<signed char> *directions() { return &directions_; }
00177 
00178   //---------------------------------------------------------------------------
00179   //: Return the direction `i'
00180   //---------------------------------------------------------------------------
00181   int dir(int i) const { return directions_[i]; }
00182 
00183   //---------------------------------------------------------------------------
00184   //: Set if `this' is a connected chain
00185   //---------------------------------------------------------------------------
00186   void set_cycle(bool new_is_cycle) { is_cycle_=new_is_cycle; }
00187 
00188   //---------------------------------------------------------------------------
00189   // Task: Reset the chain
00190   //---------------------------------------------------------------------------
00191   virtual void clear();
00192 
00193   //: Return a platform independent string identifying the class
00194   virtual vcl_string is_a() const { return vcl_string("vtol_chain"); }
00195 
00196   //: Return true if the argument matches the string identifying the class or any parent class
00197   virtual bool is_class(const vcl_string& cls) const { return cls==is_a(); }
00198 };
00199 
00200 #endif // vtol_chain_h_