FemlabMeshReader.cpp
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 #include "FemlabMeshReader.hpp"
00030 #include "Exception.hpp"
00031
00032 #include <sstream>
00033
00035
00037
00038 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00039 FemlabMeshReader<ELEMENT_DIM, SPACE_DIM>::FemlabMeshReader(const std::string& rPathBaseName,
00040 const std::string& rNodeFileName,
00041 const std::string& rElementFileName,
00042 const std::string& rEdgeFileName)
00043 {
00044
00045
00046 std::string node_file_name = rPathBaseName + rNodeFileName;
00047 this->mNodeRawData = this->GetRawDataFromFile(node_file_name);
00048
00049
00050 this->mNodeData = TokenizeStringsToDoubles(this->mNodeRawData);
00051
00052
00053 this->mpNodeIterator = this->mNodeData.begin();
00054
00055
00056
00057 std::string element_file_name = rPathBaseName + rElementFileName;
00058 this->mElementRawData = this->GetRawDataFromFile(element_file_name);
00059
00060
00061 this->mElementData = TokenizeStringsToInts(this->mElementRawData, SPACE_DIM + 1);
00062 this->mpElementIterator = this->mElementData.begin();
00063
00064
00065
00066
00067
00068
00069
00070 std::string edge_file_name = rPathBaseName + rEdgeFileName;
00071 this->mFaceRawData = this->GetRawDataFromFile(edge_file_name);
00072
00073
00074 this->mFaceData = TokenizeStringsToInts(this->mFaceRawData, SPACE_DIM);
00075 this->mpFaceIterator = this->mFaceData.begin();
00076 }
00077
00078 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00079 FemlabMeshReader<ELEMENT_DIM, SPACE_DIM>::~FemlabMeshReader()
00080 {}
00081
00082 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00083 std::vector < std::vector<double> >
00084 FemlabMeshReader<ELEMENT_DIM, SPACE_DIM>::TokenizeStringsToDoubles(const std::vector<std::string>& rRawData)
00085 {
00086 std::vector < std::vector < double > >tokenized_data;
00087
00088
00089 unsigned dimension_count = 0;
00090 std::vector < std::string >::const_iterator the_iterator;
00091 for (the_iterator = rRawData.begin(); the_iterator != rRawData.end();
00092 the_iterator++)
00093 {
00094 const std::string& line_of_data = *the_iterator;
00095 std::stringstream line_stream (line_of_data);
00096
00097 if (dimension_count == 0)
00098 {
00099
00100 while (!line_stream.eof())
00101 {
00102 double item_coord;
00103
00104 std::vector < double >x_coord;
00105 line_stream >> item_coord;
00106 x_coord.push_back (item_coord);
00107 tokenized_data.push_back (x_coord);
00108 }
00109 }
00110 else
00111 {
00112 unsigned current_node = 0;
00113
00114
00115 while (!line_stream.eof())
00116 {
00117 double item_coord;
00118 line_stream >> item_coord;
00119 tokenized_data[current_node].push_back (item_coord);
00120 current_node++;
00121 }
00122 }
00123
00124 dimension_count++;
00125 }
00126
00127 if (SPACE_DIM != dimension_count)
00128 {
00129 EXCEPTION("SPACE_DIM != dimension read from file");
00130 }
00131 return (tokenized_data);
00132 }
00133
00134 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00135 std::vector < std::vector < unsigned > >
00136 FemlabMeshReader<ELEMENT_DIM, SPACE_DIM>::TokenizeStringsToInts(const std::vector<std::string>& rRawData, unsigned dimensionOfObject)
00137 {
00138 std::vector < std::vector < unsigned > >tokenized_data;
00139
00140
00141 for (unsigned i = 0; i < dimensionOfObject; i++)
00142 {
00143 const std::string& line_of_data = rRawData[i];
00144 std::stringstream line_stream (line_of_data);
00145
00146 if (i == 0)
00147 {
00148
00149 while (!line_stream.eof())
00150 {
00151 double item_index;
00152
00153 std::vector < unsigned >first_index;
00154 line_stream >> item_index;
00155 first_index.push_back ((unsigned) (item_index - 0.5));
00156 tokenized_data.push_back (first_index);
00157 }
00158 }
00159 else
00160 {
00161 unsigned current_node = 0;
00162
00163
00164 while (!line_stream.eof())
00165 {
00166 double item_index;
00167 line_stream >> item_index;
00168 tokenized_data[current_node].
00169 push_back ((unsigned) (item_index - 0.5));
00170 current_node++;
00171 }
00172 }
00173 }
00174 return (tokenized_data);
00175 }
00176
00177
00179
00181
00182 template class FemlabMeshReader<1,1>;
00183 template class FemlabMeshReader<1,2>;
00184 template class FemlabMeshReader<1,3>;
00185 template class FemlabMeshReader<2,2>;
00186 template class FemlabMeshReader<2,3>;
00187 template class FemlabMeshReader<3,3>;