uLib-0.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
VoxRaytracer.h
Go to the documentation of this file.
1 /*//////////////////////////////////////////////////////////////////////////////
2 // CMT Cosmic Muon Tomography project //////////////////////////////////////////
4 
5  Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
6  All rights reserved
7 
8  Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
9 
10  ------------------------------------------------------------------
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 3.0 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library.
23 
25 
26 
27 
28 #ifndef VOXRAYTRACER_H
29 #define VOXRAYTRACER_H
30 
31 #include <math.h>
32 #include <vector>
33 
34 #include "Math/StructuredGrid.h"
35 
36 namespace uLib {
37 
38 class VoxRaytracer {
39 
40 public:
41  class RayData {
42  public:
43  RayData() : m_TotalLength(0) {}
44 
45  typedef struct {
46  Id_t vox_id;
47  Scalarf L;
48  } Element;
49 
50  inline void AddElement(Id_t id, float L);
51 
52  void AppendRay ( const RayData &in);
53 
54  uLibConstRefMacro(Data,std::vector<Element>)
55  uLibConstRefMacro(TotalLength,Scalarf)
56 
57  void PrintSelf(std::ostream &o);
58 
59  private:
60  std::vector<Element> m_Data;
61  Scalarf m_TotalLength;
62  };
63 
64 
65  public:
66  VoxRaytracer(StructuredGrid &image) : m_Image(&image) {
67  m_scale <<
68  (m_Image->GetWorldMatrix() * Vector4f(1,0,0,0)).norm(),
69  (m_Image->GetWorldMatrix() * Vector4f(0,1,0,0)).norm(),
70  (m_Image->GetWorldMatrix() * Vector4f(0,0,1,0)).norm();
71  }
72 
73  bool GetEntryPoint(const HLine3f &line, HPoint3f &pt);
74 
75  bool GetExitPoint(const HLine3f &line, HPoint3f &pt);
76 
77  RayData TraceBetweenPoints(const HPoint3f &in, const HPoint3f &out) const;
78 
79  RayData TraceLine(const HLine3f &line) const;
80 
81  inline StructuredGrid* GetImage() const { return this->m_Image; }
82 
83 private:
84  StructuredGrid *m_Image;
85  Vector3f m_scale;
86 };
87 
88 }
89 
90 
91 
92 #endif // VOXRAYTRACER_H