Peano
Loading...
Searching...
No Matches
FileReader.cpp
Go to the documentation of this file.
1#include "FileReader.h"
2
3#include <fstream>
4
5#include <stdio.h>
6#include <string.h>
7
8
9tarch::logging::Log toolbox::particles::FileReader::_log( "toolbox::particles::FileReader" );
10
11
12void toolbox::particles::FileReader::readDatFile( const std::string& filename, const double scale ) {
13 std::fstream fin;
14
15 fin.open( filename, std::ios::in );
16 std::string line;
17
18 if (not fin) {
19 logError( "readDatFile(string)", "was not able to open file " << filename );
20 }
21
22 while ( std::getline(fin,line) ){
23 std::stringstream currentLine(line);
25
26 int entry = 0;
27 std::string token;
28 while ( std::getline(currentLine, token, ' ') and entry<Dimensions ) {
29 if (token!="") {
30 newEntry(entry) = scale*std::atof( token.c_str() );
31 entry++;
32 }
33 }
34 _data.push_back( newEntry );
35 }
36
37 fin.close();
38
39 logInfo( "readDatFile(string)", "read " << _data.size() << " particle positions from file " << filename );
40}
41
42
44 _data.clear();
45}
46
47
49 return _data.empty();
50}
51
52
54 return _data.size();
55}
56
57
58std::list< tarch::la::Vector<Dimensions,double> > toolbox::particles::FileReader::getParticlesWithinVoxel(
61 bool remove
62) {
63 std::list< tarch::la::Vector<Dimensions,double> > result;
64
65 std::list< tarch::la::Vector<Dimensions,double> >::iterator p = _data.begin();
66 while ( p!=_data.end() ) {
67 bool overlaps = true;
68
69 for (int d=0; d<Dimensions; d++) {
70 overlaps &= tarch::la::smallerEquals( x(d)-h(d)/2.0, (*p)(d) );
71 overlaps &= tarch::la::greaterEquals( x(d)+h(d)/2.0, (*p)(d) );
72 }
73
74 if (overlaps) {
75 result.push_back(*p);
76 if (remove) {
77 p = _data.erase(p);
78 }
79 else p++;
80 }
81 else {
82 p++;
83 }
84 }
85
86 return result;
87}
#define logError(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:464
#define logInfo(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:411
Log Device.
Definition Log.h:516
std::list< tarch::la::Vector< Dimensions, double > > getParticlesWithinVoxel(const tarch::la::Vector< Dimensions, double > &x, const tarch::la::Vector< Dimensions, double > &h, bool remove)
Take particles from database which fall into given voxel.
std::list< tarch::la::Vector< Dimensions, double > > _data
Definition FileReader.h:29
void readDatFile(const std::string &filename, const double scale)
Read DAT file.
static tarch::logging::Log _log
Definition FileReader.h:27
bool greaterEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool smallerEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Simple vector class.
Definition Vector.h:150