uLib-0.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ContainerBox.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 U_CONTAINERBOX_H
29 #define U_CONTAINERBOX_H
30 
31 #include "Geometry.h"
32 
33 
34 namespace uLib {
35 
36 
37 
38 class ContainerBox : public AffineTransform {
39 public:
40  ContainerBox() : m_LocalT(this) {}
41 
42  ContainerBox(const ContainerBox &copy) :
43  m_LocalT(this),
44  AffineTransform(copy)
45  {
46  // FIX for performance //
47  this->SetOrigin(copy.GetOrigin());
48  this->SetSize(copy.GetSize());
49  }
50 
51  inline void SetOrigin(const Vector3f &v) { m_LocalT.SetPosition(v); }
52 
53  inline Vector3f GetOrigin() const { return m_LocalT.GetPosition(); }
54 
55  void SetSize(const Vector3f &v) {
56  Vector3f pos = this->GetOrigin();
57  m_LocalT = AffineTransform(this);
58  m_LocalT.Scale(v);
59  m_LocalT.SetPosition(pos);
60  }
61 
62  inline Vector3f GetSize() const { return m_LocalT.GetScale(); }
63 
64  // FIX... //
65  inline void FlipLocalAxes(int first, int second)
66  { m_LocalT.FlipAxes(first,second); }
67 
68  Matrix4f GetWorldMatrix() const { return m_LocalT.GetWorldMatrix(); }
69 
70  inline Vector4f GetWorldPoint(const Vector4f &v) const {
71  return m_LocalT.GetWorldMatrix() * v;
72  }
73 
74  inline Vector4f GetWorldPoint(const float x, const float y, const float z) {
75  return this->GetWorldPoint(Vector4f(x,y,z,1));
76  }
77 
78  inline Vector4f GetLocalPoint(const Vector4f &v) const {
79  return m_LocalT.GetWorldMatrix().inverse() * v;
80  }
81 
82  inline Vector4f GetLocalPoint(const float x, const float y, const float z) {
83  return this->GetLocalPoint(Vector4f(x,y,z,1));
84  }
85 
86 
87 protected:
88 
89 private:
90  AffineTransform m_LocalT;
91 };
92 
93 
94 }
95 
96 
97 
98 #endif // CONTAINERBOX_H