MeshKit
1.0
|
00001 #ifndef MESHKIT_TRANSFORM_HPP 00002 #define MESHKIT_TRANSFORM_HPP 00003 00004 #include "meshkit/Error.hpp" 00005 #include "meshkit/iMesh.hpp" 00006 #include "meshkit/Matrix.hpp" 00007 #include "TransformBase.hpp" 00008 #include <vector> 00009 00010 namespace MeshKit { 00011 Vector<3> rodrigues(const Vector<3> &pt, const Vector<3> &z, double dtheta); 00012 00013 namespace Copy { 00017 class Identity : public BasicTransform<Identity> 00018 { 00019 friend class BasicTransform<Identity>; 00020 public: 00021 Identity() {} 00022 protected: 00023 void transform_one(Vector<3> &coords) const {} 00024 }; 00025 00029 class Translate : public BasicTransform<Translate> 00030 { 00031 friend class BasicTransform<Translate>; 00032 public: 00033 Translate(const Vector<3> &dv) : dv_(dv) {} 00034 protected: 00035 void transform_one(Vector<3> &coords) const 00036 { 00037 coords += dv_; 00038 } 00039 private: 00040 Vector<3> dv_; 00041 }; 00042 00046 class Rotate : public BasicTransform<Rotate> 00047 { 00048 friend class BasicTransform<Rotate>; 00049 public: 00050 Rotate(const Vector<3> &origin, const Vector<3> &z, double dtheta) 00051 : origin_(origin), z_(z/length(z)), dtheta_(dtheta) 00052 {} 00053 protected: 00054 void transform_one(Vector<3> &coords) const 00055 { 00056 coords = rodrigues(coords-origin_, z_, dtheta_) + origin_; 00057 } 00058 private: 00059 Vector<3> origin_; 00060 Vector<3> z_; 00061 double dtheta_; 00062 }; 00063 } 00064 00065 namespace Extrude { 00069 class Translate : public BasicTransform<Translate> 00070 { 00071 friend class BasicTransform<Translate>; 00072 public: 00073 Translate(const Vector<3> &dv, int steps) 00074 : BasicTransform<Translate>(steps), dv_(dv/steps) 00075 {} 00076 protected: 00077 virtual void transform_one(int step, Vector<3> &coords) const 00078 { 00079 coords += dv_*step; 00080 } 00081 private: 00082 Vector<3> dv_; 00083 }; 00084 00088 class Rotate : public BasicTransform<Rotate> 00089 { 00090 friend class BasicTransform<Rotate>; 00091 public: 00092 Rotate(const Vector<3> &origin, const Vector<3> &z, double dtheta, 00093 int steps) 00094 : BasicTransform<Rotate>(steps), origin_(origin), z_(z/length(z)), 00095 dtheta_(dtheta/steps) 00096 {} 00097 protected: 00098 virtual void transform_one(int step, Vector<3> &coords) const 00099 { 00100 coords = rodrigues(coords-origin_, z_, dtheta_*step) + origin_; 00101 } 00102 private: 00103 Vector<3> origin_; 00104 Vector<3> z_; 00105 double dtheta_; 00106 }; 00107 } 00108 } 00109 00110 #endif