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