00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00037 #ifndef _FEMLABMESHREADER_H_
00038 #define _FEMLABMESHREADER_H_
00039
00040 #include "AbstractCachedMeshReader.hpp"
00041 #include "Exception.hpp"
00042
00043 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00044 class FemlabMeshReader : public AbstractCachedMeshReader<ELEMENT_DIM, SPACE_DIM>
00045 {
00046 private:
00047 std::vector<std::vector<double> > TokenizeStringsToDoubles(
00048 std::vector<std::string> rawData);
00049
00050 std::vector<std::vector<unsigned> > TokenizeStringsToInts(
00051 std::vector<std::string> rawData,
00052 unsigned dimensionOfObject);
00053 public:
00054 FemlabMeshReader(std::string pathBaseName, std::string nodeFileName, std::string elementFileName, std::string edgeFileName);
00055 virtual ~FemlabMeshReader();
00056 };
00057
00058
00059
00071 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00072 FemlabMeshReader<ELEMENT_DIM, SPACE_DIM>::FemlabMeshReader (std::string pathBaseName,
00073 std::string nodeFileName,
00074 std::string elementFileName,
00075 std::string edgeFileName)
00076 {
00077
00078
00079 nodeFileName = pathBaseName + nodeFileName;
00080 this->mNodeRawData = this->GetRawDataFromFile (nodeFileName);
00081
00082
00083 this->mNodeData = TokenizeStringsToDoubles (this->mNodeRawData);
00084
00085
00086 this->mpNodeIterator = this->mNodeData.begin ();
00087
00088
00089
00090 elementFileName = pathBaseName + elementFileName;
00091 this->mElementRawData = this->GetRawDataFromFile (elementFileName);
00092
00093
00094 this->mElementData = TokenizeStringsToInts (this->mElementRawData, SPACE_DIM + 1);
00095 this->mpElementIterator = this->mElementData.begin ();
00096
00097
00098
00099
00100
00101
00102
00103 edgeFileName = pathBaseName + edgeFileName;
00104 this->mFaceRawData = this->GetRawDataFromFile (edgeFileName);
00105
00106
00107 this->mFaceData = TokenizeStringsToInts (this->mFaceRawData, SPACE_DIM);
00108 this->mpFaceIterator = this->mFaceData.begin ();
00109 }
00110
00120 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00121 std::vector < std::vector < double > >
00122 FemlabMeshReader<ELEMENT_DIM, SPACE_DIM>::TokenizeStringsToDoubles (std::vector < std::string >
00123 rawData)
00124 {
00125 std::vector < std::vector < double > >tokenized_data;
00126
00127
00128 unsigned dimension_count = 0;
00129 std::vector < std::string >::iterator the_iterator;
00130 for (the_iterator = rawData.begin (); the_iterator != rawData.end ();
00131 the_iterator++)
00132 {
00133 std::string line_of_data = *the_iterator;
00134 std::stringstream line_stream (line_of_data);
00135
00136 if (dimension_count == 0)
00137 {
00138
00139 while (!line_stream.eof ())
00140 {
00141 double item_coord;
00142
00143 std::vector < double >x_coord;
00144 line_stream >> item_coord;
00145 x_coord.push_back (item_coord);
00146 tokenized_data.push_back (x_coord);
00147 }
00148 }
00149 else
00150 {
00151 unsigned current_node = 0;
00152
00153
00154 while (!line_stream.eof ())
00155 {
00156 double item_coord;
00157 line_stream >> item_coord;
00158 tokenized_data[current_node].push_back (item_coord);
00159 current_node++;
00160 }
00161 }
00162
00163 dimension_count++;
00164
00165 }
00166
00167 if (SPACE_DIM != dimension_count)
00168 {
00169 EXCEPTION("SPACE_DIM != dimension read from file");
00170 }
00171 return (tokenized_data);
00172 }
00173
00174
00186 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00187 std::vector < std::vector < unsigned > >
00188 FemlabMeshReader<ELEMENT_DIM, SPACE_DIM>::TokenizeStringsToInts (std::vector < std::string > rawData,
00189 unsigned dimensionOfObject)
00190 {
00191 std::vector < std::vector < unsigned > >tokenized_data;
00192
00193
00194 for (unsigned i = 0; i < dimensionOfObject; i++)
00195 {
00196 std::string line_of_data = rawData[i];
00197 std::stringstream line_stream (line_of_data);
00198
00199 if (i == 0)
00200 {
00201
00202 while (!line_stream.eof ())
00203 {
00204 double item_index;
00205
00206 std::vector < unsigned >first_index;
00207 line_stream >> item_index;
00208 first_index.push_back ((unsigned) (item_index - 0.5));
00209 tokenized_data.push_back (first_index);
00210 }
00211 }
00212 else
00213 {
00214 unsigned current_node = 0;
00215
00216
00217 while (!line_stream.eof ())
00218 {
00219 double item_index;
00220 line_stream >> item_index;
00221 tokenized_data[current_node].
00222 push_back ((unsigned) (item_index - 0.5));
00223 current_node++;
00224 }
00225 }
00226 }
00227 return (tokenized_data);
00228 }
00229
00230
00234 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00235 FemlabMeshReader<ELEMENT_DIM, SPACE_DIM>::~FemlabMeshReader ()
00236 {}
00237
00238 #endif //_FEMLABMESHREADER_H_