MeshKit  1.0
TransformBase.hpp
Go to the documentation of this file.
00001 #ifndef MESHKIT_TRANSFORMBASE_HPP
00002 #define MESHKIT_TRANSFORMBASE_HPP
00003 
00004 #include "meshkit/Error.hpp"
00005 #include "meshkit/iMesh.hpp"
00006 #include "meshkit/Matrix.hpp"
00007 #include <vector>
00008 
00009 namespace MeshKit {
00010   inline double * vec2ptr(std::vector< Vector<3> > &v) {
00011     return reinterpret_cast<double *>(&v[0]);
00012   }
00013 
00014   namespace Copy {
00022     class Transform
00023     {
00024     public:
00030       virtual void transform(iMesh *mesh,
00031                              const std::vector<iMesh::EntityHandle> &src,
00032                              std::vector<iMesh::EntityHandle> &dest) const = 0;
00033 
00036       virtual Transform * clone() const = 0;
00037 
00040         virtual ~Transform ()
00041         {
00042         }
00043     };
00044 
00063     template<typename T>
00064     class BasicTransform : public Transform
00065     {
00066     public:
00072       virtual void transform(iMesh *mesh,
00073                              const std::vector<iMesh::EntityHandle> &src,
00074                              std::vector<iMesh::EntityHandle> &dest) const
00075       {
00076         std::vector< Vector<3> > coords(src.size());
00077         IBERRCHK(mesh->getVtxArrCoords(&src[0], src.size(), iBase_INTERLEAVED,
00078                                        vec2ptr(coords)), *mesh);
00079 
00080         for (size_t i=0; i<coords.size(); i++)
00081           static_cast<const T*>(this)->transform_one(coords[i]);
00082 
00083         if (&src == &dest)
00084         {
00085           IBERRCHK(mesh->setVtxArrCoords(&src[0], src.size(), iBase_INTERLEAVED,
00086                                          vec2ptr(coords)), *mesh);
00087         }
00088         else {
00089           dest.resize(src.size());
00090           IBERRCHK(mesh->createVtxArr(src.size(), iBase_INTERLEAVED,
00091                                       vec2ptr(coords), &dest[0]), *mesh);
00092         }
00093       }
00094 
00097       virtual Transform * clone() const
00098       {
00099         return new T(*static_cast<const T*>(this));
00100       }
00101     protected:
00102       BasicTransform() {}
00103     };
00104   }
00105 
00106   namespace Extrude {
00114     class Transform
00115     {
00116     public:
00124       virtual void transform(int step, iMesh *mesh,
00125                              const std::vector<iMesh::EntityHandle> &src,
00126                              std::vector<iMesh::EntityHandle> &dest) const = 0;
00127       
00130       virtual int steps() const = 0;
00131 
00134       virtual Transform * clone() const = 0;
00135 
00138         virtual ~Transform ()
00139         {
00140         }
00141     };
00142 
00161     template<typename T>
00162     class BasicTransform : public Transform
00163     {
00164     public:
00172       virtual void transform(int step, iMesh *mesh,
00173                              const std::vector<iMesh::EntityHandle> &src,
00174                              std::vector<iMesh::EntityHandle> &dest) const
00175       {
00176         std::vector< Vector<3> > coords(src.size());
00177         IBERRCHK(mesh->getVtxArrCoords(&src[0], src.size(), iBase_INTERLEAVED,
00178                                       vec2ptr(coords)), *mesh);
00179 
00180         for (size_t i=0; i<coords.size(); i++)
00181           static_cast<const T*>(this)->transform_one(step, coords[i]);
00182 
00183         dest.resize(src.size());
00184         IBERRCHK(mesh->createVtxArr(src.size(), iBase_INTERLEAVED,
00185                                     vec2ptr(coords), &dest[0]), *mesh);
00186       }
00187 
00190       virtual int steps() const
00191       {
00192         return steps_;
00193       }
00194 
00197       virtual Transform * clone() const
00198       {
00199         return new T(*static_cast<const T*>(this));
00200       }
00201     protected:
00202       BasicTransform(int steps) : steps_(steps)
00203       {}
00204 
00205       int steps_;
00206     };
00207   }
00208 }
00209 
00210 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines