OpenStructure
composite3.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef GEOM_COMPOSITE3_HH
20 #define GEOM_COMPOSITE3_HH
21 
22 #include <iostream>
23 #include <vector>
24 #include <boost/filesystem/path.hpp>
25 
26 #include "vec3.hh"
27 #include "mat3.hh"
28 #include "quat.hh"
29 
30 #include "module_config.hh"
31 
32 /*
33  composite classes in 3D space
34 */
35 
36 namespace geom {
37 
40 public:
41  Line3();
42  Line3(const Vec3& from, const Vec3& to);
43 
44  Vec3 At(Real r) const;
45  Vec3 GetOrigin() const;
46  Vec3 GetDirection() const;
47 private:
48  Vec3 ori_,dir_;
49 };
50 
51 DLLEXPORT_OST_GEOM std::ostream& operator<<(std::ostream& s, const Line3& l);
52 
54 public:
55  Plane():n_(Vec3(0,0,1)),p_(0){};
57  Plane(const Vec3& p1, const Vec3& p2, const Vec3& p3);
59  Plane(const Vec3& p, const Vec3& n);
61  Plane(const Line3& l, const Vec3& p);
63  Plane(Real a, Real b, Real c, Real d);
65  Plane(Real x, Real y, Real z);
66 
67  Vec3 GetOrigin() const { return -p_*n_; }
68  Vec3 GetNormal() const;
69  void SetNormal(const Vec3& n);
70  Real GetP() const;
71  void SetP(Real p) { p_=p; }
72  Vec3 At(Real x, Real y) const;
73 
74  enum PLANE_TYPE {
75  YZ=0x1, ZY=0x1, XZ=0x2, ZX=0x2, XY=0x4, YX=0x4
76  };
77 
78 private:
79  // planes are internally specified in HNF
80  Vec3 n_;
81  Real p_;
82 };
83 
85 public:
86  Sphere();
87  Sphere(const Vec3& origin, Real r);
88  Vec3 GetOrigin() const;
89  Real GetRadius() const;
90  void SetOrigin(const Vec3& v);
91  void SetRadius(Real r);
92 
93 private:
94  Vec3 origin_;
95  Real radius_;
96 };
97 
103 public:
104  CuboidAxis(): axis_(), half_extent_(0.0)
105  { }
106  CuboidAxis(const Vec3& axis, Real half_extent);
107  const Vec3& GetVector() const { return axis_; }
108  Real GetHalfExtent() const { return half_extent_; }
109  Real GetExtent() const { return 2.0*half_extent_; }
110 private:
111  Vec3 axis_;
112  Real half_extent_;
113 };
114 
117 public:
119  Cuboid(const Vec3& center, const CuboidAxis& a,
120  const CuboidAxis& b, const CuboidAxis& c);
121 
123  {
124  return Vec3(axes_[0].GetHalfExtent(), axes_[1].GetHalfExtent(),
125  axes_[2].GetHalfExtent());
126  }
127 
128  Vec3 GetCenter() const
129  {
130  return center_;
131  }
132  const Vec3& GetVecA() const { return axes_[0].GetVector(); }
133  const Vec3& GetVecB() const { return axes_[1].GetVector(); }
134  const Vec3& GetVecC() const { return axes_[2].GetVector(); }
135 
136  const CuboidAxis& GetAxisA() const { return axes_[0]; }
137  const CuboidAxis& GetAxisB() const { return axes_[1]; }
138  const CuboidAxis& GetAxisC() const { return axes_[2]; }
139 private:
140  Vec3 center_;
141  CuboidAxis axes_[3];
142 };
143 
145 {
146 public:
148  Rotation3(Real phi, Real theta, Real psi,
149  const Vec3& origin=Vec3(0.0,0.0,0.0));
150  Rotation3(const Vec3& axis, Real angle,
151  const Vec3& origin=Vec3(0.0,0.0,0.0));
152  Rotation3(const Line3& line, Real angle);
153  Rotation3(const Mat3& rot, const Vec3& origin=Vec3(0.0,0.0,0.0));
154  Rotation3(const Quat& q, const Vec3& origin=Vec3(0.0,0.0,0.0));
155  Vec3 GetOrigin() const;
156  Real GetPhi() const;
157  Real GetTheta() const;
158  Real GetPsi() const;
159  Quat GetQuat() const;
163  void SetOrigin(const Vec3& o);
164  void SetPhi(Real phi);
165  void SetTheta(Real theta);
166  void SetPsi(Real psi);
167  void SetQuat(const Quat& q);
168  void SetRotationAxis(const Vec3& v);
169  void SetRotationAngle(Real angle);
170  void SetRotationMatrix(const Mat3& rot);
171  Vec3 Apply(const Vec3&) const;
172  bool operator==(const Rotation3& rhs) const;
173 
174 private:
175  Quat generate_from_eulers(Real psi, Real theta, Real phi);
176  Quat generate_from_axis_angle(const Vec3& axis, Real angle);
177  Vec3 find_invariant_vector(Mat3 rot);
178  Vec3 find_orthogonal_vector(const Vec3& xyz);
179  Vec3 find_vector_for_BOD(const Vec3& xyz, const Vec3& uvw);
180  Quat generate_from_matrix(const Mat3& rot);
181  Real reduce_angle(Real ang) const;
182  Quat q_;
183  Vec3 origin_;
184 };
185 
186 typedef std::vector<Rotation3> Rotation3List;
187 
188 DLLEXPORT_OST_GEOM Rotation3List ImportEulerAngles (const boost::filesystem::path& loc);
190  const boost::filesystem::path& loc);
191 
192 } // ns
193 
194 #endif
cuboid axis defined by a normalized direction vector and a half extent
Definition: composite3.hh:102
CuboidAxis(const Vec3 &axis, Real half_extent)
Real GetExtent() const
Definition: composite3.hh:109
Real GetHalfExtent() const
Definition: composite3.hh:108
const Vec3 & GetVector() const
Definition: composite3.hh:107
arbitrary oriented bounding cuboid
Definition: composite3.hh:116
Cuboid(const Vec3 &center, const CuboidAxis &a, const CuboidAxis &b, const CuboidAxis &c)
const CuboidAxis & GetAxisA() const
Definition: composite3.hh:136
const CuboidAxis & GetAxisC() const
Definition: composite3.hh:138
const Vec3 & GetVecA() const
Definition: composite3.hh:132
const Vec3 & GetVecB() const
Definition: composite3.hh:133
Vec3 GetHalfExtents() const
Definition: composite3.hh:122
Vec3 GetCenter() const
Definition: composite3.hh:128
const CuboidAxis & GetAxisB() const
Definition: composite3.hh:137
const Vec3 & GetVecC() const
Definition: composite3.hh:134
Line3.
Definition: composite3.hh:39
Vec3 GetOrigin() const
Line3(const Vec3 &from, const Vec3 &to)
Vec3 GetDirection() const
Vec3 At(Real r) const
void SetNormal(const Vec3 &n)
Vec3 At(Real x, Real y) const
Plane(const Line3 &l, const Vec3 &p)
initialize based on a line and point
Plane(Real a, Real b, Real c, Real d)
initialize a,b,c,d (ax+by+cz+d=0)
Plane(const Vec3 &p1, const Vec3 &p2, const Vec3 &p3)
initialize based on 3 points defining a plane
void SetP(Real p)
Definition: composite3.hh:71
Plane(Real x, Real y, Real z)
initialize based x-,y-,z- intercepts
Vec3 GetNormal() const
Plane(const Vec3 &p, const Vec3 &n)
initialize based on a point and a normal
Vec3 GetOrigin() const
Definition: composite3.hh:67
Real GetP() const
unit quaternion
Definition: quat.hh:58
Rotation3(const Mat3 &rot, const Vec3 &origin=Vec3(0.0, 0.0, 0.0))
Real GetTheta() const
Quat GetQuat() const
void SetRotationMatrix(const Mat3 &rot)
Vec3 GetRotationAxis() const
Real GetPsi() const
void SetOrigin(const Vec3 &o)
Rotation3(const Vec3 &axis, Real angle, const Vec3 &origin=Vec3(0.0, 0.0, 0.0))
Mat3 GetRotationMatrix() const
void SetQuat(const Quat &q)
void SetRotationAngle(Real angle)
Rotation3(const Quat &q, const Vec3 &origin=Vec3(0.0, 0.0, 0.0))
Real GetRotationAngle() const
Vec3 GetOrigin() const
void SetPsi(Real psi)
Vec3 Apply(const Vec3 &) const
void SetRotationAxis(const Vec3 &v)
Real GetPhi() const
Rotation3(Real phi, Real theta, Real psi, const Vec3 &origin=Vec3(0.0, 0.0, 0.0))
Rotation3(const Line3 &line, Real angle)
bool operator==(const Rotation3 &rhs) const
void SetPhi(Real phi)
void SetTheta(Real theta)
Sphere(const Vec3 &origin, Real r)
Real GetRadius() const
void SetOrigin(const Vec3 &v)
Vec3 GetOrigin() const
void SetRadius(Real r)
Three dimensional vector class, using Real precision.
Definition: vec3.hh:48
#define DLLEXPORT_OST_GEOM
float Real
Definition: base.hh:44
DLLIMPORT Rotation3List ImportEulerAngles(const boost::filesystem::path &loc)
std::vector< Rotation3 > Rotation3List
Definition: composite3.hh:186
std::ostream & operator<<(std::ostream &os, const AlignedCuboid &c)
DLLIMPORT void ExportEulerAngles(const Rotation3List &rot_list, const boost::filesystem::path &loc)