rl_basicray  1.0.12
rl_BasicRay.h
1 #ifndef rl_BasicRay_h_INCLUDED
2 #define rl_BasicRay_h_INCLUDED
3 
4 // File: rl_BasicRay.h
5 // Author: Terry Gaetz
6 
7 /* --8<--8<--8<--8<--
8  *
9  * Copyright (C) 2006 Smithsonian Astrophysical Observatory
10  *
11  * This file is part of rl_ray
12  *
13  * rl_ray is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * rl_ray is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the
25  * Free Software Foundation, Inc.
26  * 51 Franklin Street, Fifth Floor
27  * Boston, MA 02110-1301, USA
28  *
29  * -->8-->8-->8-->8-- */
30 
31 #include <dvm3/dvm3.h>
32 #include <rl_basicray/rl_RayMath.h>
33 #include <Exception/Exception.h>
34 
35 //########################################################################
36 // rl_BasicRay
37 //########################################################################
38 //
39 
48 {
49 protected:
50 
52  dvm3_Vector pos_;
54  dvm3_Vector dir_;
56  double energy_;
58  long int id_;
59 
69  void init( dvm3_Vector const& pos, dvm3_Vector const& dir,
70  double energy, long int id );
71 
72 public:
73 
75  virtual ~rl_BasicRay();
76  //
77 
82  rl_BasicRay();
83 
94  rl_BasicRay( dvm3_Vector const& pos, dvm3_Vector const& dir,
95  double energy, long int id );
96 
102  rl_BasicRay( rl_BasicRay const& other );
103 
109  void set_id( long int id );
110 
116  long int id() const;
117 
123  double& energy();
124 
130  double energy() const;
131 
139  double& position( int i );
140 
148  double position( int i ) const;
149 
155  dvm3_Vector& position();
156 
162  dvm3_Vector const& position() const;
163 
169  double& direction( int i );
170 
178  double direction( int i ) const;
179 
185  dvm3_Vector& direction();
186 
192  dvm3_Vector const& direction() const;
193 
202  double reflect_direction_vector( dvm3_Vector const& normal );
203 
209  void project( double s );
210 
218  virtual
219  void translate_rotate( dvm3_Vector const& trans,
220  dvm3_RotMat const& rotmat );
221 
230  virtual
231  void derotate_detranslate( dvm3_Vector const& trans,
232  dvm3_RotMat const& rotmat );
233 
243  std::ostream& print_on( std::ostream& os, char const prefix[] = "",
244  char const postfix[] = "" ) const;
245 
253  friend std::ostream& operator<<( std::ostream& os, rl_BasicRay const& );
254 };
255 
256 //########################################################################
257 //########################################################################
258 //
259 // # # # # # # # ###### ####
260 // # ## # # # ## # # #
261 // # # # # # # # # # ##### ####
262 // # # # # # # # # # # #
263 // # # ## # # # ## # # #
264 // # # # ###### # # # ###### ####
265 //
266 //########################################################################
267 //########################################################################
268 
269 //=========================================================================
270 // dtor, ctors, initializers...
271 
272 //-------------------------------------------------------------------------
273 inline rl_BasicRay::
275 {}
276 
277 //-------------------------------------------------------------------------
278 inline rl_BasicRay::
279 rl_BasicRay( dvm3_Vector const& pos, dvm3_Vector const& dir,
280  double energy, long int id )
281  : pos_(pos), dir_(dir), energy_(energy), id_(id)
282 {}
283 
284 //-------------------------------------------------------------------------
285 inline rl_BasicRay::
286 rl_BasicRay( rl_BasicRay const& other )
287  : pos_(other.pos_), dir_(other.dir_), energy_(other.energy_), id_(other.id_)
288 {}
289 
290 //-------------------------------------------------------------------------
291 inline void rl_BasicRay::
292 init( dvm3_Vector const& pos, dvm3_Vector const& dir,
293  double energy, long int id )
294 {
295  pos_ = pos;
296  dir_ = dir;
297  energy_ = energy;
298  id_ = id;
299 }
300 
301 //=========================================================================
302 // accessors...
303 
304 //-------------------------------------------------------------------------
305 inline long int rl_BasicRay::
306 id() const
307 { return id_; }
308 
309 inline void rl_BasicRay::
310 set_id( long int id )
311 { id_ = id; }
312 
313 //-------------------------------------------------------------------------
314 inline double& rl_BasicRay::
316 { return energy_; }
317 
318 //-------------------------------------------------------------------------
319 inline double rl_BasicRay::
320 energy() const
321 { return energy_; }
322 
323 //-------------------------------------------------------------------------
324 inline double& rl_BasicRay::
325 position( int i )
326 { return pos_[i]; }
327 
328 //-------------------------------------------------------------------------
329 inline double rl_BasicRay::
330 position( int i ) const
331 { return pos_[i]; }
332 
333 //-------------------------------------------------------------------------
334 inline dvm3_Vector& rl_BasicRay::
336 { return pos_; }
337 
338 //-------------------------------------------------------------------------
339 inline dvm3_Vector const& rl_BasicRay::
340 position() const
341 { return pos_; }
342 
343 //-------------------------------------------------------------------------
344 inline double& rl_BasicRay::
345 direction( int i )
346 { return dir_[i]; }
347 
348 //-------------------------------------------------------------------------
349 inline double rl_BasicRay::
350 direction( int i ) const
351 { return dir_[i]; }
352 
353 //-------------------------------------------------------------------------
354 inline dvm3_Vector& rl_BasicRay::
356 { return dir_; }
357 
358 //-------------------------------------------------------------------------
359 inline dvm3_Vector const& rl_BasicRay::
360 direction() const
361 { return dir_; }
362 
363 //=========================================================================
364 // ray projection...
365 
366 //-------------------------------------------------------------------------
367 inline
368 void rl_BasicRay::
369 project( double s )
370 {
371  pos_ += s * dir_;
372 }
373 
374 //=========================================================================
375 // translate to to bcs origin; rotate from std to bcs coordinates
376 
377 //-------------------------------------------------------------------------
378 inline void rl_BasicRay::
379 translate_rotate( dvm3_Vector const& trans,
380  dvm3_RotMat const& rotmat )
381 {
382  rl_RayMath::translate_rotate( trans, rotmat, pos_ );
383  rl_RayMath::rotate( rotmat, dir_ );
384 }
385 
386 //=========================================================================
387 // derotate from bcs back to std coordinates; detranslate back to std origin
388 
389 //-------------------------------------------------------------------------
390 inline void rl_BasicRay::
391 derotate_detranslate( dvm3_Vector const& trans,
392  dvm3_RotMat const& rotmat )
393 {
394  rl_RayMath::derotate_detranslate( trans, rotmat, pos_ );
395  rl_RayMath::derotate( rotmat, dir_ );
396 }
397 
398 // rl_BasicRay_h_INCLUDED
399 #endif
friend std::ostream & operator<<(std::ostream &os, rl_BasicRay const &)
Print the ray properties to an output stream.
std::ostream & print_on(std::ostream &os, char const prefix[]="", char const postfix[]="") const
Print the ray properties to an output stream.
Definition: rl_BasicRay.cc:70
virtual void derotate_detranslate(dvm3_Vector const &trans, dvm3_RotMat const &rotmat)
VIRTUAL: Derotate back to STD coordinates; detranslate back to STD origin.
Definition: rl_BasicRay.h:391
dvm3_Vector & position()
Read/write access to current ray position.
Definition: rl_BasicRay.h:335
dvm3_Vector dir_
ray direction vector (direction cosines)
Definition: rl_BasicRay.h:54
dvm3_Vector & direction()
Read/write access to current ray direction vector.
Definition: rl_BasicRay.h:355
static void derotate_detranslate(dvm3_Vector const &trans, dvm3_RotMat const &rotmat, dvm3_Vector &vector)
Rotate from BCS to STD coordinates, then translate back to original position.
Definition: rl_RayMath.h:267
dvm3_Vector pos_
ray position
Definition: rl_BasicRay.h:52
static void translate_rotate(dvm3_Vector const &trans, dvm3_RotMat const &rotmat, dvm3_Vector &vector)
Translate to BCS origin, then rotate from STD to BCS coordinates.
Definition: rl_RayMath.h:241
long int id_
ray id number
Definition: rl_BasicRay.h:58
static void derotate(dvm3_RotMat const &rotmat, dvm3_Vector &vector)
De-rotate vector from BCS coordinates back to STD coordinates.
Definition: rl_RayMath.h:219
A basic ray: encapsulates position and direction vectors, energy, and ray id.
Definition: rl_BasicRay.h:47
rl_BasicRay()
Default constructor; constructs a ray in an INVALID state.
Definition: rl_BasicRay.h:274
void init(dvm3_Vector const &pos, dvm3_Vector const &dir, double energy, long int id)
Initialize rl_BasicRay with ray initial position and direction vector, energy, and id number.
Definition: rl_BasicRay.h:292
void project(double s)
Project a distance s along this ray.
Definition: rl_BasicRay.h:369
double reflect_direction_vector(dvm3_Vector const &normal)
Reflect this ray's direction vector about a (surface) normal.
Definition: rl_BasicRay.cc:52
long int id() const
Read-only access to current ray id.
Definition: rl_BasicRay.h:306
virtual ~rl_BasicRay()
A virtual do-nothing destructor.
Definition: rl_BasicRay.cc:41
static void rotate(dvm3_RotMat const &rotmat, dvm3_Vector &vector)
Rotate vector from STD coordinates to BCS coordinates.
Definition: rl_RayMath.h:197
virtual void translate_rotate(dvm3_Vector const &trans, dvm3_RotMat const &rotmat)
VIRTUAL: Translate to the BCS origin; rotate from STD to BCS coordinates.
Definition: rl_BasicRay.h:379
double energy_
ray energy
Definition: rl_BasicRay.h:56
double & energy()
Read/write access to current ray energy.
Definition: rl_BasicRay.h:315
void set_id(long int id)
Reset ray id.
Definition: rl_BasicRay.h:310