00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GEOM_COMPOSITE3_HH
00020 #define GEOM_COMPOSITE3_HH
00021
00022 #include <iostream>
00023 #include <vector>
00024 #include <boost/filesystem.hpp>
00025
00026 #include "vec3.hh"
00027 #include "mat3.hh"
00028 #include "quat.hh"
00029
00030
00031
00032
00033
00034
00035 namespace geom {
00036
00038 class DLLEXPORT_OST_GEOM Line3 {
00039 public:
00040 Line3();
00041 Line3(const Vec3& from, const Vec3& to);
00042
00043 Vec3 At(Real r) const;
00044 Vec3 GetOrigin() const;
00045 Vec3 GetDirection() const;
00046 private:
00047 Vec3 ori_,dir_;
00048 };
00049
00050 std::ostream& operator<<(std::ostream& s, const Line3& l);
00051
00052 class DLLEXPORT_OST_GEOM Plane {
00053 public:
00054 Plane():n_(Vec3(0,0,1)),p_(0){};
00056 Plane(const Vec3& p1, const Vec3& p2, const Vec3& p3);
00058 Plane(const Vec3& p, const Vec3& n);
00060 Plane(const Line3& l, const Vec3& p);
00062 Plane(Real a, Real b, Real c, Real d);
00064 Plane(Real x, Real y, Real z);
00065
00066 Vec3 GetOrigin() const;
00067 void SetOrigin(const Vec3& o);
00068 Vec3 GetNormal() const;
00069 void SetNormal(const Vec3& n);
00070 Real GetP() const;
00071 Vec3 At(Real x, Real y) const;
00072
00073 enum PLANE_TYPE {
00074 YZ=0x1, ZY=0x1, XZ=0x2, ZX=0x2, XY=0x4, YX=0x4
00075 };
00076
00077 private:
00078
00079 Vec3 n_;
00080 Real p_;
00081 Vec3 o_;
00082
00083 void calc_ori();
00084 };
00085
00086 class DLLEXPORT Sphere {
00087 public:
00088 Sphere();
00089 Sphere(const Vec3& origin, Real r);
00090 Vec3 GetOrigin() const;
00091 Real GetRadius() const;
00092 void SetOrigin(const Vec3& v);
00093 void SetRadius(Real r);
00094
00095 private:
00096 Vec3 origin_;
00097 Real radius_;
00098 };
00099
00104 class DLLEXPORT CuboidAxis {
00105 public:
00106 CuboidAxis(): axis_(), half_extent_(0.0)
00107 { }
00108 CuboidAxis(const Vec3& axis, Real half_extent);
00109 const Vec3& GetVector() const { return axis_; }
00110 Real GetHalfExtent() const { return half_extent_; }
00111 Real GetExtent() const { return 2.0*half_extent_; }
00112 private:
00113 Vec3 axis_;
00114 Real half_extent_;
00115 };
00116
00118 class DLLEXPORT Cuboid {
00119 public:
00120 Cuboid();
00121 Cuboid(const Vec3& center, const CuboidAxis& a,
00122 const CuboidAxis& b, const CuboidAxis& c);
00123
00124 Vec3 GetHalfExtents() const
00125 {
00126 return Vec3(axes_[0].GetHalfExtent(), axes_[1].GetHalfExtent(),
00127 axes_[2].GetHalfExtent());
00128 }
00129
00130 Vec3 GetCenter() const
00131 {
00132 return center_;
00133 }
00134 const Vec3& GetVecA() const { return axes_[0].GetVector(); }
00135 const Vec3& GetVecB() const { return axes_[1].GetVector(); }
00136 const Vec3& GetVecC() const { return axes_[2].GetVector(); }
00137
00138 const CuboidAxis& GetAxisA() const { return axes_[0]; }
00139 const CuboidAxis& GetAxisB() const { return axes_[1]; }
00140 const CuboidAxis& GetAxisC() const { return axes_[2]; }
00141 private:
00142 Vec3 center_;
00143 CuboidAxis axes_[3];
00144 };
00145
00146 class DLLEXPORT Rotation3
00147 {
00148 public:
00149 Rotation3();
00150 Rotation3(Real phi, Real theta, Real psi,
00151 const Vec3& origin=Vec3(0.0,0.0,0.0));
00152 Rotation3(const Vec3& axis, Real angle,
00153 const Vec3& origin=Vec3(0.0,0.0,0.0));
00154 Rotation3(const Line3& line, Real angle);
00155 Rotation3(const Mat3& rot, const Vec3& origin=Vec3(0.0,0.0,0.0));
00156 Rotation3(const Quat& q, const Vec3& origin=Vec3(0.0,0.0,0.0));
00157 Vec3 GetOrigin() const;
00158 Real GetPhi() const;
00159 Real GetTheta() const;
00160 Real GetPsi() const;
00161 Quat GetQuat() const;
00162 Vec3 GetRotationAxis() const;
00163 Real GetRotationAngle() const;
00164 Mat3 GetRotationMatrix() const;
00165 void SetOrigin(const Vec3& o);
00166 void SetPhi(Real phi);
00167 void SetTheta(Real theta);
00168 void SetPsi(Real psi);
00169 void SetQuat(const Quat& q);
00170 void SetRotationAxis(const Vec3& v);
00171 void SetRotationAngle(Real angle);
00172 void SetRotationMatrix(const Mat3& rot);
00173 Vec3 Apply(const Vec3&) const;
00174 bool operator==(const Rotation3& rhs) const;
00175
00176 private:
00177 Quat generate_from_eulers(Real psi, Real theta, Real phi);
00178 Quat generate_from_axis_angle(const Vec3& axis, Real angle);
00179 Vec3 find_invariant_vector(Mat3 rot);
00180 Vec3 find_orthogonal_vector(const Vec3& xyz);
00181 Vec3 find_vector_for_BOD(const Vec3& xyz, const Vec3& uvw);
00182 Quat generate_from_matrix(const Mat3& rot);
00183 Real reduce_angle(Real ang) const;
00184 Quat q_;
00185 Vec3 origin_;
00186 };
00187
00188 typedef std::vector<Rotation3> Rotation3List;
00189
00190 DLLEXPORT Rotation3List ImportEulerAngles (const boost::filesystem::path& loc);
00191 DLLEXPORT void ExportEulerAngles (const Rotation3List& rot_list,
00192 const boost::filesystem::path& loc);
00193
00194 }
00195
00196 #endif