Go to the documentation of this file.00001 #ifndef meshImport_hh
00002 #define meshImport_hh
00003
00004 #include <vector>
00005 #include "mesh.hh"
00006 #include "toolbox/array.hh"
00007 #include "toolbox/multiArray.hh"
00008 #include "basics/vectorsMatricesForward.hh"
00009 #include "basics/debug.hh"
00010
00011 #define ImportMeshReadInts_D 0
00012 #define ImportMeshReadLine_D 0
00013
00014 namespace concepts {
00015
00016
00017
00027 class ImportMesh {
00028 public:
00032 ImportMesh(const uint idxStart = 1)
00033 : idxStart_(idxStart), Edg_(true), twoAttr_(true), threeAttr_(true),
00034 fourAttr_(true), sixAttr_(true), eightAttr_(true) {}
00035 virtual ~ImportMesh();
00036 protected:
00038 const uint idxStart_;
00039
00041 std::vector<Vertex*> vtx_;
00042 std::vector<Connector1*> edg_;
00044 MultiArray<1, Vertex*> Vtx_;
00045 MultiArray<2, Edge*> Edg_;
00046
00048 MultiArray<1, Attribute> oneAttr_;
00049 MultiArray<2, Attribute> twoAttr_;
00050 MultiArray<3, Attribute> threeAttr_;
00051 MultiArray<4, Attribute> fourAttr_;
00052 MultiArray<6, Attribute> sixAttr_;
00053 MultiArray<8, Attribute> eightAttr_;
00054
00056 virtual void createEntity_(const MultiIndex<1>& idx);
00057 virtual void createEntity_(const MultiIndex<2>& idx);
00062 virtual void createEntity_(const MultiIndex<3>& idx)
00063 throw(concepts::MissingFeature);
00064 virtual void createEntity_(const MultiIndex<4>& idx)
00065 throw(concepts::MissingFeature);
00066 virtual void createEntity_(const MultiIndex<6>& idx)
00067 throw(concepts::MissingFeature);
00068 virtual void createEntity_(const MultiIndex<8>& idx)
00069 throw(concepts::MissingFeature);
00070
00075 virtual void createCell_(const MultiIndex<2>& idx)
00076 throw(concepts::MissingFeature);
00077 virtual void createCell_(const MultiIndex<3>& idx)
00078 throw(concepts::MissingFeature);
00079 virtual void createCell_(const MultiIndex<4>& idx)
00080 throw(concepts::MissingFeature);
00081 virtual void createCell_(const MultiIndex<6>& idx)
00082 throw(concepts::MissingFeature);
00083 virtual void createCell_(const MultiIndex<8>& idx)
00084 throw(concepts::MissingFeature);
00085
00089 uint readInts_(const std::string& i, std::vector<int>& v) const;
00096 template<class F>
00097 uint readLine_(const std::string& i, Array<F>& a,
00098 bool first = false) const;
00099
00103 void readCells_(const std::string& elms, const Array<bool>& dimensions,
00104 const std::vector<Real3d>& vertices);
00106 template<uint dim>
00107 void newCell_(MultiIndex<dim> i);
00108
00109 void readAttributes_(const std::string& bound,
00110 const Array<bool>& dimensions);
00111
00113 template<class T>
00114 void clear_(std::vector<T*>& field);
00115 };
00116
00117 template<class F>
00118 uint ImportMesh::readLine_(const std::string& i, Array<F>& a,
00119 bool first) const {
00120 std::istringstream input(i.c_str());
00121 F number = 0;
00122 DEBUGL(ImportMeshReadLine_D, number);
00123 std::vector<F> v;
00124 if (!first) input >> number;
00125 while (input >> number) {
00126 v.push_back(number);
00127 DEBUGL(ImportMeshReadLine_D, "inserted " << v.back());
00128 }
00129 a.resize(v.size());
00130 for(uint i = 0; i < a.size(); ++i) a[i] = v[i];
00131 DEBUGL(ImportMeshReadLine_D, "array = " << a);
00132 return a.size();
00133 }
00134
00135 template<class T>
00136 void ImportMesh::clear_(std::vector<T*>& field) {
00137 for (typename std::vector<T*>::iterator i = field.begin();
00138 i != field.end(); ++i) {
00139 delete *i; *i = 0;
00140 }
00141 }
00142
00143 template<class T>
00144 std::ostream& operator<<(std::ostream& os, const std::vector<T*>& field) {
00145 uint j=0;
00146 for (typename std::vector<T*>::const_iterator i = field.begin();
00147 i != field.end(); ++j) {
00148 if (i != field.begin()) os << ", ";
00149 T* val = *i++;
00150 os << '(' << j << ',';
00151 if (val) os << *val; else os << '0';
00152 os << ')';
00153 }
00154 return os;
00155 }
00156
00157 }
00158
00159 #endif // meshImport_hh