xc
Ref.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //Ref.h
22 
23 #ifndef REF_H
24 #define REF_H
25 
26 #include "utility/geom/ProtoGeom.h"
27 
29 //
31 //
36 template<class SC>
37 class Ref : public ProtoGeom
38  {
39  public:
40  typedef typename SC::VGlobal VGlobal;
41  typedef typename SC::DGlobal DGlobal;
42  typedef typename SC::PGlobal PGlobal;
43  typedef typename SC::VLocal VLocal;
44  typedef typename SC::PLocal PLocal;
45 
46  protected:
47  PGlobal org;
48  SC trf;
49 
50  public:
51  Ref(void): org(), trf() {}
52  Ref(const PGlobal &o, const SC &sc=SC())
53  : org(o), trf(sc) {}
54  Ref(const PGlobal &o,const VGlobal &vX)
55  : org(o), trf(vX) {}
56  Ref(const PGlobal &o,const DGlobal &dirX)
57  : org(o), trf(dirX.GetVector()) {}
58  Ref(const PGlobal &o,const PGlobal &p)
59  : org(o), trf(o,p) {}
60  virtual bool operator==(const Ref &) const;
61  PGlobal &Org(void)
62  { return org; }
63  const PGlobal &Org(void) const
64  { return org; }
65  void setOrg(const PGlobal &p)
66  { org= p; }
67  void move(const VGlobal &v)
68  { org+= v; }
69  SC &Trf(void)
70  { return trf; }
71  const SC &Trf(void) const
72  { return trf; }
73  void setTrf(const SC &t)
74  { trf= t; }
75  VGlobal getAxisVDir(const size_t &i) const
76  { return trf.getAxisVDir(i); }
77  PGlobal getGlobalPosition(const PLocal &p) const;
78  VGlobal getGlobalCoordinates(const VLocal &v) const;
79  PLocal getLocalPosition(const PGlobal &p) const;
80  VLocal getLocalCoordinates(const VGlobal &v) const;
81  friend std::ostream &operator<<(std::ostream &os,const Ref<SC> &r)
82  {
83  os << "origen= " << r.org << " transformación= " << r.trf;
84  return os;
85  }
86  virtual ~Ref(void)
87  {}
88  boost::python::dict getPyDict(void) const;
89  void setPyDict(const boost::python::dict &);
90  };
91 
95 template<class SC>
97  {
98  PGlobal retval= org + getGlobalCoordinates(p-PLocal());
99  return retval;
100  }
101 
105 template<class SC>
107  { return trf.getGlobalCoordinates(v); }
108 
111 template<class SC>
113  {
115  return PLocal(PLocal()+v);
116  }
117 
121 template<class SC>
123  { return trf.getLocalCoordinates(v); }
124 
126 template<class SC>
127 bool Ref<SC>::operator==(const Ref<SC> &other) const
128  {
129  bool retval= false;
130  if(this==&other)
131  retval= true;
132  else
133  {
134  retval= ProtoGeom::operator==(other);
135  if(retval)
136  retval= ((org==other.org) && (trf==other.trf));
137  }
138  return retval;
139  }
140 
142 template<class SC>
143 boost::python::dict Ref<SC>::getPyDict(void) const
144  {
145  boost::python::dict retval= ProtoGeom::getPyDict();
146  retval["org"]= org;
147  retval["trf"]= trf;
148  return retval;
149  }
150 
152 template<class SC>
153 void Ref<SC>::setPyDict(const boost::python::dict &d)
154  {
156  const boost::python::dict orgDict= boost::python::extract<boost::python::dict>(d["org"]);
157  org.setPyDict(orgDict);
158  const boost::python::dict trfDict= boost::python::extract<boost::python::dict>(d["trf"]);
159  trf.setPyDict(trfDict);
160  }
161 
162 #endif
163 
164 
165 
166 
167 
168 
SC::DGlobal DGlobal
Dimension of the global direction.
Definition: Ref.h:41
Base class for coordinate transformation.
Definition: Trf.h:36
SC trf
local –> global coordinate system axis transformation.
Definition: Ref.h:48
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: Ref.h:143
PLocal getLocalPosition(const PGlobal &p) const
Return the position of the point p (expressed in global coordinates) expresssed in local coordinates...
Definition: Ref.h:112
VGlobal getGlobalCoordinates(const VLocal &v) const
Return the local coordinates of the vector.
Definition: Ref.h:106
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: ProtoGeom.cc:40
SC::VGlobal VGlobal
Dimension of the global vector.
Definition: Ref.h:40
SC::PLocal PLocal
Dimension of the local point.
Definition: Ref.h:44
Base class for geometry objects.
Definition: ProtoGeom.h:33
PGlobal getGlobalPosition(const PLocal &p) const
Return the global coordinates of the position vector of the point.
Definition: Ref.h:96
virtual bool operator==(const EntityWithOwner &) const
Comparison operator.
Definition: EntityWithOwner.cc:86
VLocal getLocalCoordinates(const VGlobal &v) const
Return the local coordinates of the vector.
Definition: Ref.h:122
Base class for reference systems.
Definition: Ref.h:37
PGlobal org
Origin of the coordinate system.
Definition: Ref.h:47
SC::VLocal VLocal
Dimension of the local vector.
Definition: Ref.h:43
SC::PGlobal PGlobal
Dimension of the global point.
Definition: Ref.h:42
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: Ref.h:153
virtual bool operator==(const Ref &) const
Comparison operator.
Definition: Ref.h:127
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: ProtoGeom.cc:48