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