contrib/gel/vsol/vsol_triangle_2d.h
Go to the documentation of this file.
00001 // This is gel/vsol/vsol_triangle_2d.h
00002 #ifndef vsol_triangle_2d_h_
00003 #define vsol_triangle_2d_h_
00004 //*****************************************************************************
00005 //:
00006 // \file
00007 // \brief Triangle in 2D space.
00008 //
00009 // \author François BERTEL
00010 // \date   2000-05-02
00011 //
00012 // \verbatim
00013 //  Modifications
00014 //   2000-05-02 François BERTEL Creation
00015 //   2000-06-17 Peter Vanroose  Implemented all operator==()s and type info
00016 //   2004-05-11 Joseph Mundy Implemented binary I/O
00017 //   2004-05-14 Peter Vanroose  Added describe()
00018 // \endverbatim
00019 //*****************************************************************************
00020 
00021 //*****************************************************************************
00022 // External declarations for values
00023 //*****************************************************************************
00024 #include <vsol/vsol_polygon_2d.h>
00025 #include <vsl/vsl_binary_io.h>
00026 #include <vcl_iosfwd.h>
00027 
00028 
00029 class vsol_triangle_2d : public vsol_polygon_2d
00030 {
00031  public:
00032   //***************************************************************************
00033   // Initialization
00034   //***************************************************************************
00035 
00036   //---------------------------------------------------------------------------
00037   //: Default Constructor - needed for binary I/O
00038   //---------------------------------------------------------------------------
00039   vsol_triangle_2d();
00040 
00041   //---------------------------------------------------------------------------
00042   //: Constructor from 3 points
00043   //---------------------------------------------------------------------------
00044   vsol_triangle_2d(const vsol_point_2d_sptr &new_p0,
00045                    const vsol_point_2d_sptr &new_p1,
00046                    const vsol_point_2d_sptr &new_p2);
00047 
00048   //---------------------------------------------------------------------------
00049   //: Copy constructor
00050   //---------------------------------------------------------------------------
00051   vsol_triangle_2d(const vsol_triangle_2d &other);
00052 
00053   //---------------------------------------------------------------------------
00054   //: Destructor
00055   //---------------------------------------------------------------------------
00056   virtual ~vsol_triangle_2d();
00057 
00058   //---------------------------------------------------------------------------
00059   //: Clone `this': creation of a new object and initialization
00060   //  See Prototype pattern
00061   //---------------------------------------------------------------------------
00062   virtual vsol_spatial_object_2d* clone(void) const;
00063 
00064   //***************************************************************************
00065   // Access
00066   //***************************************************************************
00067 
00068   //---------------------------------------------------------------------------
00069   //: Return the first vertex
00070   //---------------------------------------------------------------------------
00071   vsol_point_2d_sptr p0(void) const;
00072 
00073   //---------------------------------------------------------------------------
00074   //: Return the second vertex
00075   //---------------------------------------------------------------------------
00076   vsol_point_2d_sptr p1(void) const;
00077 
00078   //---------------------------------------------------------------------------
00079   //: Return the last vertex
00080   //---------------------------------------------------------------------------
00081   vsol_point_2d_sptr p2(void) const;
00082 
00083   //***************************************************************************
00084   // Comparison
00085   //***************************************************************************
00086 
00087   //---------------------------------------------------------------------------
00088   //: Has `this' the same points than `other' in the same order ?
00089   //---------------------------------------------------------------------------
00090   virtual bool operator==(const vsol_triangle_2d &other) const;
00091   inline bool operator!=(const vsol_triangle_2d &other)const{return !operator==(other);}
00092   virtual bool operator==(const vsol_polygon_2d &other) const; // virtual of vsol_polygon_2d
00093   virtual bool operator==(const vsol_spatial_object_2d& obj) const; // virtual of vsol_spatial_object_2d
00094 
00095   //***************************************************************************
00096   // Status report
00097   //***************************************************************************
00098 
00099   //---------------------------------------------------------------------------
00100   //: Return the area of `this'
00101   //---------------------------------------------------------------------------
00102   virtual double area(void) const;
00103 
00104   //***************************************************************************
00105   // Element change
00106   //***************************************************************************
00107 
00108   //---------------------------------------------------------------------------
00109   //: Set the first vertex
00110   //---------------------------------------------------------------------------
00111   void set_p0(const vsol_point_2d_sptr &new_p0);
00112 
00113   //---------------------------------------------------------------------------
00114   //: Set the second vertex
00115   //---------------------------------------------------------------------------
00116   void set_p1(const vsol_point_2d_sptr &new_p1);
00117 
00118   //---------------------------------------------------------------------------
00119   //: Set the last vertex
00120   //---------------------------------------------------------------------------
00121   void set_p2(const vsol_point_2d_sptr &new_p2);
00122 
00123   virtual vsol_triangle_2d* cast_to_triangle(void) { return this; }
00124   virtual vsol_triangle_2d const* cast_to_triangle(void) const { return this; }
00125 
00126   // ==== Binary IO methods ======
00127 
00128   //: Binary save self to stream.
00129   void b_write(vsl_b_ostream &os) const;
00130 
00131   //: Binary load self from stream.
00132   void b_read(vsl_b_istream &is);
00133 
00134   //: Return IO version number;
00135   short version() const;
00136 
00137   //: Print an ascii summary to the stream
00138   void print_summary(vcl_ostream &os) const;
00139 
00140   //: Return a platform independent string identifying the class
00141   virtual vcl_string is_a() const { return "vsol_triangle_2d"; }
00142 
00143   //: Return true if the argument matches the string identifying the class or any parent class
00144   virtual bool is_class(const vcl_string& cls) const
00145   { return cls==is_a() || vsol_polygon_2d::is_class(cls); }
00146 
00147   //---------------------------------------------------------------------------
00148   //: output description to stream
00149   //---------------------------------------------------------------------------
00150   void describe(vcl_ostream &strm, int blanking=0) const;
00151 };
00152 
00153 //: Binary save vsol_triangle_2d* to stream.
00154 void vsl_b_write(vsl_b_ostream &os, const vsol_triangle_2d* p);
00155 
00156 //: Binary load vsol_triangle_2d* from stream.
00157 void vsl_b_read(vsl_b_istream &is, vsol_triangle_2d* &p);
00158 
00159 #endif // vsol_triangle_2d_h_