contrib/gel/vsol/vsol_tetrahedron.cxx
Go to the documentation of this file.
00001 // This is gel/vsol/vsol_tetrahedron.cxx
00002 #include "vsol_tetrahedron.h"
00003 //:
00004 //  \file
00005 
00006 #include <vcl_cmath.h> // for vcl_abs(double)
00007 #include <vcl_iostream.h>
00008 #include <vsol/vsol_point_3d.h>
00009 
00010 //***************************************************************************
00011 // Initialization
00012 //***************************************************************************
00013 
00014 //---------------------------------------------------------------------------
00015 //: Constructor from its 4 vertices
00016 //---------------------------------------------------------------------------
00017 vsol_tetrahedron::vsol_tetrahedron(const vsol_point_3d_sptr &new_p0,
00018                                    const vsol_point_3d_sptr &new_p1,
00019                                    const vsol_point_3d_sptr &new_p2,
00020                                    const vsol_point_3d_sptr &new_p3)
00021 {
00022   storage_.push_back(new_p0);
00023   storage_.push_back(new_p1);
00024   storage_.push_back(new_p2);
00025   storage_.push_back(new_p3);
00026 }
00027 
00028 //---------------------------------------------------------------------------
00029 // Copy constructor
00030 //---------------------------------------------------------------------------
00031 vsol_tetrahedron::vsol_tetrahedron(const vsol_tetrahedron &other)
00032   : vsol_polyhedron(other)
00033 {
00034 }
00035 
00036 //***************************************************************************
00037 // Access
00038 //***************************************************************************
00039 
00040 //---------------------------------------------------------------------------
00041 //: Return the first vertex
00042 //---------------------------------------------------------------------------
00043 vsol_point_3d_sptr vsol_tetrahedron::p0(void) const
00044 {
00045   return storage_[0];
00046 }
00047 
00048 //---------------------------------------------------------------------------
00049 //: Return the second vertex
00050 //---------------------------------------------------------------------------
00051 vsol_point_3d_sptr vsol_tetrahedron::p1(void) const
00052 {
00053   return storage_[1];
00054 }
00055 
00056 //---------------------------------------------------------------------------
00057 //: Return the third vertex
00058 //---------------------------------------------------------------------------
00059 vsol_point_3d_sptr vsol_tetrahedron::p2(void) const
00060 {
00061   return storage_[2];
00062 }
00063 
00064 //---------------------------------------------------------------------------
00065 //: Return the last vertex
00066 //---------------------------------------------------------------------------
00067 vsol_point_3d_sptr vsol_tetrahedron::p3(void) const
00068 {
00069   return storage_[3];
00070 }
00071 
00072 //***************************************************************************
00073 // Status report
00074 //***************************************************************************
00075 
00076 //---------------------------------------------------------------------------
00077 //: Return the volume of `this'
00078 //---------------------------------------------------------------------------
00079 double vsol_tetrahedron::volume(void) const
00080 {
00081   double dx01=storage_[0]->x()-storage_[1]->x();
00082   double dy01=storage_[0]->y()-storage_[1]->y();
00083   double dz01=storage_[0]->z()-storage_[1]->z();
00084   double dx12=storage_[1]->x()-storage_[2]->x();
00085   double dy12=storage_[1]->y()-storage_[2]->y();
00086   double dz12=storage_[1]->z()-storage_[2]->z();
00087   double dx23=storage_[2]->x()-storage_[3]->x();
00088   double dy23=storage_[2]->y()-storage_[3]->y();
00089   double dz23=storage_[2]->z()-storage_[3]->z();
00090   return vcl_abs( dx23*(dy01*dz12-dy12*dz01)
00091                  +dy23*(dz01*dx12-dz12*dx01)
00092                  +dz23*(dx01*dy12-dx12*dy01))/6;
00093 }
00094 //***************************************************************************
00095 // Element change
00096 //***************************************************************************
00097 
00098 //---------------------------------------------------------------------------
00099 //: Set the first vertex
00100 //---------------------------------------------------------------------------
00101 void vsol_tetrahedron::set_p0(vsol_point_3d_sptr new_p0)
00102 {
00103   storage_[0]=new_p0;
00104   touch();
00105 }
00106 
00107 //---------------------------------------------------------------------------
00108 //: Set the second vertex
00109 //---------------------------------------------------------------------------
00110 void vsol_tetrahedron::set_p1(vsol_point_3d_sptr new_p1)
00111 {
00112   storage_[1]=new_p1;
00113   touch();
00114 }
00115 
00116 //---------------------------------------------------------------------------
00117 //: Set the third vertex
00118 //---------------------------------------------------------------------------
00119 void vsol_tetrahedron::set_p2(vsol_point_3d_sptr new_p2)
00120 {
00121   storage_[2]=new_p2;
00122   touch();
00123 }
00124 
00125 //---------------------------------------------------------------------------
00126 //: Set the last vertex
00127 //---------------------------------------------------------------------------
00128 void vsol_tetrahedron::set_p3(vsol_point_3d_sptr new_p3)
00129 {
00130   storage_[3]=new_p3;
00131   touch();
00132 }
00133 
00134 //***************************************************************************
00135 // Basic operations
00136 //***************************************************************************
00137 
00138 //---------------------------------------------------------------------------
00139 //: Is `p' in `this' ?
00140 // \todo not yet implemented
00141 //---------------------------------------------------------------------------
00142 bool vsol_tetrahedron::in(vsol_point_3d_sptr const& ) const
00143 {
00144   vcl_cerr << "Warning: vsol_tetrahedron::in() has not been implemented yet\n";
00145   return true;
00146 }
00147 
00148 void vsol_tetrahedron::describe(vcl_ostream &strm, int blanking) const
00149 {
00150   if (blanking < 0) blanking = 0; while (blanking--) strm << ' ';
00151   strm << "[vsol_tetrahedron " << p0() << ' ' << p1() << ' '
00152        << p2() << ' ' << p3() << ']' << vcl_endl;
00153 }