Toast++  1.0.2 (r.539)
Forward and inverse modelling in optical tomography
surface.h
1 // -*-C++-*-
2 // ============================================================================
3 // TOAST v.15
4 // Library: libfe File: surface.h
5 //
6 // Declaration of class Surface and derived classes
7 // 2-D and 3-D surface parametrisations
8 // ============================================================================
9 
10 #ifndef __SURFACE_H
11 #define __SURFACE_H
12 
13 class Mesh;
14 class Surface;
15 
16 Surface *ReadSurface (std::istream &is);
17 
18 // ============================================================================
19 // class Surface
20 
21 class Surface {
22 public:
23  Surface() {}
24  virtual ~Surface() {}
25 
26  virtual Surface *Clone () const = 0;
27  // return a copy of *this
28 
29  virtual int Dimension() const = 0;
30  // surface dimension
31 
32  virtual int ParamDim() const = 0;
33  // dimension of parameter vectors
34 
35  virtual void Scale (double scale) = 0;
36  // Scales the surface by factor scale
37 
38  virtual void Scale (const RVector &scale) = 0;
39  // Anisotropic scaling. 'scale' must have the same dimension as the surface
40 
41  virtual void Point2Param (const Point &p, RVector &prm) const = 0;
42  // returns parametrisation of point p in prm
43  // p should be located on the surface, otherwise the result is
44  // undefined.
45 
46  virtual Point Param2Point (const RVector &param) const = 0;
47  // converts surface parameter param into a point
48 
49  virtual RVector DParam (const RVector &param1, const RVector &param2)
50  const { return param2 - param1; }
51  // Parameter difference. Derived classes take into account wrapping etc.
52 
53  virtual double ChordDist (const RVector &param1, const RVector &param2)
54  const = 0;
55  // returns chord length along surface between two points given by
56  // parametrisations param1 and param2
57 
58  virtual RVector Normal (const RVector &param) const = 0;
59  // Outward normal of surface at point defined by param
60 
61  virtual void SetCamera (const Point &cam);
62  // Set camera position for subsequent calls to RayIntersect
63 
64  virtual bool RayIntersect (const RVector &dir, Point &pi) const;
65  // Calculate the intersection of the surface with a ray, given by
66  // reference pos set in 'SetCamera' and direction 'dir'
67  // Returns intersection closest to 'p0' in positive 'dir' in 'pi'
68  // Return value is false if no intersection in positive 'dir' exists
69  // 'SetCamera' must have been called
70 
71  virtual bool Inside (const Point &p) const;
72  // returns true if point p is inside the volume bounded by the surface
73 
74  friend Surface *ReadSurface (std::istream &is);
75  // Read a surface from stream is and return pointer to it (polymorphic)
76  // Return value is NULL on error
77 
78  virtual std::ostream &put (std::ostream &os) const = 0;
79  // Output the surface to a stream
80 
81  friend std::ostream &operator<< (std::ostream &os, const Surface &surf);
82 
83  friend int BndNodeParams (const Mesh &mesh, RDenseMatrix &pvecs);
84  // returns in the rows of pvecs the parametrisations of all boundary
85  // nodes. Return value is #rows of pvecs, or 0 if mesh doesn't have
86  // a surface
87 
88 protected:
89 
90  virtual std::istream &get (std::istream &is) = 0;
91  // Auxiliary routine for ReadSurface to retrieve surface data once
92  // an instance of the specialised surface has been created
93 };
94 
95 // ============================================================================
96 // class Surface2D
97 
98 class Surface2D: public Surface {
99 public:
100  Surface2D(): Surface() {}
101  int Dimension() const { return 2; }
102  virtual double Circumference() const = 0;
103 
104  virtual double ChordDiff (const RVector &param1, const RVector &param2)
105  const = 0;
106  // signed chord distance between two points. Takes into account wrapping
107  // return value > 0 if param1 'right of' (>) param2
108 };
109 
110 // ============================================================================
111 // class Surface3D
112 
113 class Surface3D: public Surface {
114 public:
115  Surface3D(): Surface() {}
116  int Dimension() const { return 3; }
117 };
118 
119 // ============================================================================
120 // class Surface_Circle
121 // * Parametrisation is angle from x-axis (-Pi..Pi)
122 
123 class Surface_Circle: public Surface2D {
124 public:
125  Surface_Circle ();
126  Surface_Circle (double _radius, const Point &_centre);
127  Surface_Circle (const Surface_Circle &surf);
128 
129  int ParamDim() const { return 1; }
130  Surface *Clone() const { return new Surface_Circle (*this); }
131 
132  double Circumference() const { return Pi2*radius; }
133 
134  void Scale (double scale);
135  virtual void Scale (const RVector &scale);
136  void Point2Param (const Point &p, RVector &prm) const;
137  Point Param2Point (const RVector &param) const;
138  RVector DParam (const RVector &param1, const RVector &param2) const;
139  double ChordDiff (const RVector &param1, const RVector &param2) const;
140  double ChordDist (const RVector &param1, const RVector &param2) const
141  { return fabs (ChordDiff (param1, param2)); }
142  RVector Normal (const RVector &param) const;
143 
144  std::ostream &put (std::ostream &os) const { return os << *this; }
145  friend std::istream &operator>> (std::istream &is, Surface_Circle &surf);
146  friend std::ostream &operator<< (std::ostream &os,
147  const Surface_Circle &surf);
148 
149 protected:
150  std::istream &get (std::istream &is) { return is >> *this; }
151 
152 private:
153  double radius;
154  Point centre;
155 };
156 
157 // ============================================================================
158 // class Surface_Sphere
159 // Parametrisation: polar coordinates
160 // param[0] = azimuth angle (-Pi..Pi)
161 // param[1] = polar angle (0..Pi) where 0 is north pole (0,0,r)
162 
163 class Surface_Sphere: public Surface3D {
164 public:
165  Surface_Sphere ();
166  Surface_Sphere (double _radius, const Point &_centre);
167  Surface_Sphere (const Surface_Sphere &surf);
168 
169  int ParamDim() const { return 2; }
170  Surface *Clone () const { return new Surface_Sphere (*this); }
171 
172  void Scale (double scale);
173  void Scale (const RVector &scale);
174  void Point2Param (const Point &p, RVector &prm) const;
175  Point Param2Point (const RVector &param) const;
176  double ChordDist (const RVector &param1, const RVector &param2) const;
177  RVector Normal (const RVector &param) const;
178  void SetCamera (const Point &_cam);
179  bool RayIntersect (const RVector &dir, Point &pi) const;
180  bool Inside (const Point &p) const;
181 
182  std::ostream &put (std::ostream &os) const { return os << *this; }
183  friend std::istream &operator>> (std::istream &is, Surface_Sphere &surf);
184  friend std::ostream &operator<< (std::ostream &os,
185  const Surface_Sphere &surf);
186 
187 protected:
188  std::istream &get (std::istream &is) { return is >> *this; }
189 
190 private:
191  double radius;
192  Point centre;
193  RVector cam, rcam;
194  double camfac;
195 };
196 
197 // ============================================================================
198 // class Surface_Cone
199 // Parametrisation: cylinder coordinates
200 // param[0] = azimuth angle (-Pi..Pi)
201 // param[1] = z (distance from tip, base = 1)
202 // Parameters of the cone:
203 // tip: coordinates of the tip
204 // dir: direction into which the cone opens
205 // sap: semi-aperture [rad]
206 // height: height from tip to base
207 // Note that the base plane of the cone is not included in the parametrisation
208 
209 class Surface_Cone: public Surface3D {
210 public:
211  Surface_Cone ();
212  Surface_Cone (const Point &_tip, const RVector &_dir, double _sap,
213  double _height);
214  Surface_Cone (const Surface_Cone &surf);
215 
216  int ParamDim() const { return 2; }
217  Surface *Clone () const { return new Surface_Cone (*this); }
218 
219  void Scale (double scale);
220  virtual void Scale (const RVector &scale);
221  void Point2Param (const Point &p, RVector &prm) const;
222  Point Param2Point (const RVector &param) const;
223  double ChordDist (const RVector &param1, const RVector &param2) const;
224  RVector Normal (const RVector &param) const;
225 
226  std::ostream &put (std::ostream &os) const { return os << *this; }
227  friend std::istream &operator>> (std::istream &is, Surface_Cone &surf);
228  friend std::ostream &operator<< (std::ostream &os,
229  const Surface_Cone &surf);
230 
231 protected:
232  std::istream &get (std::istream &is) { return is >> *this; }
233 
234 private:
235  Point tip;
236  RVector dir;
237  double sap;
238  double height;
239 
240  void ComputeRotation (const RVector &d);
241  RDenseMatrix Rot, IRot; // rotation matrices local <-> global
242 };
243 
244 #endif // !__SURFACE_H
Definition: surface.h:21
Finite-element mesh management.
Definition: mesh.h:145
Definition: point.h:18
Definition: surface.h:113
Definition: surface.h:209
Definition: surface.h:123
Definition: surface.h:163
Definition: surface.h:98