1 // This is gel/vsol/vsol_tetrahedron.cxx
2 #include <iostream>
3 #include <cmath>
4 #include "vsol_tetrahedron.h"
5 //:
6 //  \file
7 
8 #ifdef _MSC_VER
9 #  include "vcl_msvc_warnings.h"
10 #endif
11 #include <vsol/vsol_point_3d.h>
12 
13 //***************************************************************************
14 // Initialization
15 //***************************************************************************
16 
17 //---------------------------------------------------------------------------
18 //: Constructor from its 4 vertices
19 //---------------------------------------------------------------------------
vsol_tetrahedron(const vsol_point_3d_sptr & new_p0,const vsol_point_3d_sptr & new_p1,const vsol_point_3d_sptr & new_p2,const vsol_point_3d_sptr & new_p3)20 vsol_tetrahedron::vsol_tetrahedron(const vsol_point_3d_sptr &new_p0,
21                                    const vsol_point_3d_sptr &new_p1,
22                                    const vsol_point_3d_sptr &new_p2,
23                                    const vsol_point_3d_sptr &new_p3)
24 {
25   storage_.push_back(new_p0);
26   storage_.push_back(new_p1);
27   storage_.push_back(new_p2);
28   storage_.push_back(new_p3);
29 }
30 
31 //---------------------------------------------------------------------------
32 // Copy constructor
33 //---------------------------------------------------------------------------
34 vsol_tetrahedron::vsol_tetrahedron(const vsol_tetrahedron &other) = default;
35 
36 //***************************************************************************
37 // Access
38 //***************************************************************************
39 
40 //---------------------------------------------------------------------------
41 //: Return the first vertex
42 //---------------------------------------------------------------------------
p0() const43 vsol_point_3d_sptr vsol_tetrahedron::p0() const { return storage_[0]; }
44 
45 //---------------------------------------------------------------------------
46 //: Return the second vertex
47 //---------------------------------------------------------------------------
p1() const48 vsol_point_3d_sptr vsol_tetrahedron::p1() const { return storage_[1]; }
49 
50 //---------------------------------------------------------------------------
51 //: Return the third vertex
52 //---------------------------------------------------------------------------
p2() const53 vsol_point_3d_sptr vsol_tetrahedron::p2() const { return storage_[2]; }
54 
55 //---------------------------------------------------------------------------
56 //: Return the last vertex
57 //---------------------------------------------------------------------------
p3() const58 vsol_point_3d_sptr vsol_tetrahedron::p3() const { return storage_[3]; }
59 
60 //***************************************************************************
61 // Status report
62 //***************************************************************************
63 
64 //---------------------------------------------------------------------------
65 //: Return the volume of `this'
66 //---------------------------------------------------------------------------
volume() const67 double vsol_tetrahedron::volume() const {
68   double dx01=storage_[0]->x()-storage_[1]->x();
69   double dy01=storage_[0]->y()-storage_[1]->y();
70   double dz01=storage_[0]->z()-storage_[1]->z();
71   double dx12=storage_[1]->x()-storage_[2]->x();
72   double dy12=storage_[1]->y()-storage_[2]->y();
73   double dz12=storage_[1]->z()-storage_[2]->z();
74   double dx23=storage_[2]->x()-storage_[3]->x();
75   double dy23=storage_[2]->y()-storage_[3]->y();
76   double dz23=storage_[2]->z()-storage_[3]->z();
77   return std::abs( dx23*(dy01*dz12-dy12*dz01)
78                  +dy23*(dz01*dx12-dz12*dx01)
79                  +dz23*(dx01*dy12-dx12*dy01))/6;
80 }
81 //***************************************************************************
82 // Element change
83 //***************************************************************************
84 
85 //---------------------------------------------------------------------------
86 //: Set the first vertex
87 //---------------------------------------------------------------------------
set_p0(const vsol_point_3d_sptr & new_p0)88 void vsol_tetrahedron::set_p0(const vsol_point_3d_sptr& new_p0)
89 {
90   storage_[0]=new_p0;
91   touch();
92 }
93 
94 //---------------------------------------------------------------------------
95 //: Set the second vertex
96 //---------------------------------------------------------------------------
set_p1(const vsol_point_3d_sptr & new_p1)97 void vsol_tetrahedron::set_p1(const vsol_point_3d_sptr& new_p1)
98 {
99   storage_[1]=new_p1;
100   touch();
101 }
102 
103 //---------------------------------------------------------------------------
104 //: Set the third vertex
105 //---------------------------------------------------------------------------
set_p2(const vsol_point_3d_sptr & new_p2)106 void vsol_tetrahedron::set_p2(const vsol_point_3d_sptr& new_p2)
107 {
108   storage_[2]=new_p2;
109   touch();
110 }
111 
112 //---------------------------------------------------------------------------
113 //: Set the last vertex
114 //---------------------------------------------------------------------------
set_p3(const vsol_point_3d_sptr & new_p3)115 void vsol_tetrahedron::set_p3(const vsol_point_3d_sptr& new_p3)
116 {
117   storage_[3]=new_p3;
118   touch();
119 }
120 
121 //***************************************************************************
122 // Basic operations
123 //***************************************************************************
124 
125 //---------------------------------------------------------------------------
126 //: Is `p' in `this' ?
127 // \todo not yet implemented
128 //---------------------------------------------------------------------------
in(vsol_point_3d_sptr const &) const129 bool vsol_tetrahedron::in(vsol_point_3d_sptr const& ) const
130 {
131   std::cerr << "Warning: vsol_tetrahedron::in() has not been implemented yet\n";
132   return true;
133 }
134 
describe(std::ostream & strm,int blanking) const135 void vsol_tetrahedron::describe(std::ostream &strm, int blanking) const
136 {
137   if (blanking < 0) blanking = 0; while (blanking--) strm << ' ';
138   strm << "[vsol_tetrahedron " << p0() << ' ' << p1() << ' '
139        << p2() << ' ' << p3() << ']' << std::endl;
140 }
141