diff --git a/Applications/DataExplorer/DataView/DiagramView/DiagramList.cpp b/Applications/DataExplorer/DataView/DiagramView/DiagramList.cpp index ad2d6979ed84c74de7e8e568bdc50f12e7a16c8a..933a474429b4714e52136810853c042bf422161f 100644 --- a/Applications/DataExplorer/DataView/DiagramView/DiagramList.cpp +++ b/Applications/DataExplorer/DataView/DiagramView/DiagramList.cpp @@ -279,15 +279,18 @@ int DiagramList::readList(const SensorData* data, for (int i = 0; i < nLists; i++) { + auto const* time_series = data->getTimeSeries(time_series_names[i]); + if (!time_series) + { + continue; + } + auto* l = new DiagramList; l->setName(QString::fromStdString( SensorData::convertSensorDataType2String(time_series_names[i]))); l->setXLabel("Time"); lists.push_back(l); - const std::vector<float>* time_series = - data->getTimeSeries(time_series_names[i]); - if (is_date) { l->setXUnit("day"); diff --git a/Applications/FileIO/CsvInterface.h b/Applications/FileIO/CsvInterface.h index 2c6ae05679463e0a8124f07c729565aac1605b58..a3479971226b88fb8d4d2288edf8577b3541f0a8 100644 --- a/Applications/FileIO/CsvInterface.h +++ b/Applications/FileIO/CsvInterface.h @@ -164,7 +164,7 @@ public: } std::string line; - getline(in, line); + std::getline(in, line); std::size_t const column_idx = CsvInterface::findColumn(line, delim, column_name); if (column_idx == std::numeric_limits<std::size_t>::max()) @@ -202,7 +202,6 @@ private: std::string line; std::size_t line_count(0); std::size_t error_count(0); - std::list<std::string>::const_iterator it; while (std::getline(in, line)) { line_count++; @@ -217,7 +216,7 @@ private: error_count++; continue; } - it = fields.begin(); + auto it = fields.begin(); std::advance(it, column_idx); std::istringstream stream(*it); diff --git a/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.cpp b/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.cpp index fcbbd9f1d1cbe62029c29c064c596c09a6b36d41..22b47e28938137422ce4f7f721a0e612ede5329b 100644 --- a/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.cpp +++ b/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.cpp @@ -735,7 +735,7 @@ void FEFLOWMeshInterface::setMaterialIDs( } GeoLib::Polygon polygon(*poly, true); - if (polygon.isPntInPolygon(gpt[0], gpt[1], gpt[2])) + if (polygon.isPntInPolygon(gpt)) { matId = j; break; diff --git a/Applications/FileIO/PetrelInterface.cpp b/Applications/FileIO/PetrelInterface.cpp index d4d4b70eecb416dd17f91a84736255d9b115206e..f6531393f8ec744be69eb52c63785c3710b67b23 100644 --- a/Applications/FileIO/PetrelInterface.cpp +++ b/Applications/FileIO/PetrelInterface.cpp @@ -217,8 +217,11 @@ void PetrelInterface::readPetrelWellTrace(std::istream& in) well_head_x, well_head_y, well_kb); - well_vec->push_back( - new GeoLib::StationBorehole(well_head_x, well_head_y, well_kb)); + double const depth = 0.0; + std::string const borehole_name = ""; + int const date = 0; + well_vec->push_back(new GeoLib::StationBorehole( + well_head_x, well_head_y, well_kb, depth, borehole_name, date)); // read well type in.getline(buffer, MAX_COLS_PER_ROW); diff --git a/Applications/Utils/MeshGeoTools/computeSurfaceNodeIDsInPolygonalRegion.cpp b/Applications/Utils/MeshGeoTools/computeSurfaceNodeIDsInPolygonalRegion.cpp index a0e61a2d1c8ed504dc4ee1df9c6f18daf52e3c84..49ac89e93b28c39bc2741d94bf49d5c304b58f82 100644 --- a/Applications/Utils/MeshGeoTools/computeSurfaceNodeIDsInPolygonalRegion.cpp +++ b/Applications/Utils/MeshGeoTools/computeSurfaceNodeIDsInPolygonalRegion.cpp @@ -150,10 +150,10 @@ int main(int argc, char* argv[]) std::vector<std::pair<std::size_t, double>> ids_and_areas; for (std::size_t k(0); k < all_sfc_nodes.size(); k++) { - MeshLib::Node const& pnt(*(all_sfc_nodes[k])); - if (polygon.isPntInPolygon(pnt[0], pnt[1], pnt[2])) + MeshLib::Node const& surface_node(*(all_sfc_nodes[k])); + if (polygon.isPntInPolygon(surface_node)) { - ids_and_areas.emplace_back(pnt.getID(), areas[k]); + ids_and_areas.emplace_back(surface_node.getID(), areas[k]); } } if (ids_and_areas.empty()) diff --git a/GeoLib/Polygon.cpp b/GeoLib/Polygon.cpp index f4b3c43440a9088088ac37b66f44b5fb3d00efd8..c74b550fc0fc832342907212a3805084bc000cd5 100644 --- a/GeoLib/Polygon.cpp +++ b/GeoLib/Polygon.cpp @@ -68,7 +68,7 @@ bool Polygon::initialise() return false; } -bool Polygon::isPntInPolygon(GeoLib::Point const& pnt) const +bool Polygon::isPntInPolygon(MathLib::Point3d const& pnt) const { auto const& min_aabb_pnt(_aabb.getMinPoint()); auto const& max_aabb_pnt(_aabb.getMaxPoint()); @@ -125,12 +125,6 @@ bool Polygon::isPntInPolygon(GeoLib::Point const& pnt) const return false; } -bool Polygon::isPntInPolygon(double x, double y, double z) const -{ - const GeoLib::Point pnt(x, y, z); - return isPntInPolygon(pnt); -} - std::vector<GeoLib::Point> Polygon::getAllIntersectionPoints( GeoLib::LineSegment const& segment) const { @@ -285,7 +279,7 @@ bool Polygon::getNextIntersectionPointPolygonLine( return false; } -EdgeType Polygon::getEdgeType(std::size_t k, GeoLib::Point const& pnt) const +EdgeType Polygon::getEdgeType(std::size_t k, MathLib::Point3d const& pnt) const { switch (getLocationOfPoint(k, pnt)) { diff --git a/GeoLib/Polygon.h b/GeoLib/Polygon.h index 91a9d46b698ddfa4d73370263a371bc1bc2cc0c8..f0a5d8b11e3c6d4c5cecb0c88eddbc91ee72b34e 100644 --- a/GeoLib/Polygon.h +++ b/GeoLib/Polygon.h @@ -64,15 +64,7 @@ public: * @param pnt the Point * @return if point is inside the polygon true, else false */ - bool isPntInPolygon (const GeoLib::Point& pnt) const; - /** - * wrapper for method isPntInPolygon (const GeoLib::Point&) - * @param x x coordinate of point - * @param y y coordinate of point - * @param z z coordinate of point - * @return if point is inside the polygon true, else false - */ - bool isPntInPolygon (double x, double y, double z) const; + bool isPntInPolygon(const MathLib::Point3d& pnt) const; /** * Checks if the straight line segment is contained within the polygon. @@ -125,7 +117,7 @@ private: * @param pnt point that is edge type computed for * @return a value of enum EdgeType */ - EdgeType getEdgeType (std::size_t k, GeoLib::Point const & pnt) const; + EdgeType getEdgeType(std::size_t k, MathLib::Point3d const& pnt) const; void ensureCCWOrientation (); diff --git a/GeoLib/Polyline.cpp b/GeoLib/Polyline.cpp index ac6aa949b515b80630741cc77da6ea328c6ff02e..4158093b4e63e2429d426c5e11515eab580c2b14 100644 --- a/GeoLib/Polyline.cpp +++ b/GeoLib/Polyline.cpp @@ -26,25 +26,14 @@ namespace GeoLib { Polyline::Polyline(const std::vector<Point*>& pnt_vec) : _ply_pnts(pnt_vec) { - _length.push_back(0.0); } Polyline::Polyline(const Polyline& ply) : _ply_pnts(ply._ply_pnts), - _ply_pnt_ids(ply._ply_pnt_ids), - _length(ply._length) + _ply_pnt_ids(ply._ply_pnt_ids) { } -void Polyline::write(std::ostream& os) const -{ - std::size_t size(_ply_pnt_ids.size()); - for (std::size_t k(0); k < size; k++) - { - os << *(_ply_pnts[_ply_pnt_ids[k]]) << "\n"; - } -} - bool Polyline::addPoint(std::size_t pnt_id) { assert(pnt_id < _ply_pnts.size()); @@ -59,18 +48,6 @@ bool Polyline::addPoint(std::size_t pnt_id) _ply_pnt_ids.push_back(pnt_id); - if (n_pnts > 0) - { - double const act_dist(std::sqrt(MathLib::sqrDist( - *_ply_pnts[_ply_pnt_ids[n_pnts - 1]], *_ply_pnts[pnt_id]))); - double dist_until_now(0.0); - if (n_pnts > 1) - { - dist_until_now = _length[n_pnts - 1]; - } - - _length.push_back(dist_until_now + act_dist); - } return true; } @@ -107,63 +84,6 @@ bool Polyline::insertPoint(std::size_t pos, std::size_t pnt_id) auto it(_ply_pnt_ids.begin() + pos_dt); _ply_pnt_ids.insert(it, pnt_id); - if (_ply_pnt_ids.size() > 1) - { - // update the _length vector - if (pos == 0) - { - // insert at first position - double const act_dist(std::sqrt(MathLib::sqrDist( - *_ply_pnts[_ply_pnt_ids[1]], *_ply_pnts[pnt_id]))); - _length.insert(_length.begin() + 1, act_dist); - const std::size_t s(_length.size()); - for (std::size_t k(2); k < s; k++) - { - _length[k] += _length[1]; - } - } - else - { - if (pos == _ply_pnt_ids.size() - 1) - { - // insert at last position - double const act_dist(std::sqrt(MathLib::sqrDist( - *_ply_pnts[_ply_pnt_ids[_ply_pnt_ids.size() - 2]], - *_ply_pnts[pnt_id]))); - double dist_until_now(0.0); - if (_ply_pnt_ids.size() > 2) - { - dist_until_now = _length[_ply_pnt_ids.size() - 2]; - } - - _length.insert(_length.begin() + pos_dt, - dist_until_now + act_dist); - } - else - { - // insert at arbitrary position within the vector - double dist_until_now(0.0); - if (pos > 1) - { - dist_until_now = _length[pos - 1]; - } - double len_seg0(std::sqrt(MathLib::sqrDist( - *_ply_pnts[_ply_pnt_ids[pos - 1]], *_ply_pnts[pnt_id]))); - double len_seg1(std::sqrt(MathLib::sqrDist( - *_ply_pnts[_ply_pnt_ids[pos + 1]], *_ply_pnts[pnt_id]))); - double update_dist(len_seg0 + len_seg1 - - (_length[pos] - dist_until_now)); - _length[pos] = dist_until_now + len_seg0; - auto it1(_length.begin() + pos_dt + 1); - _length.insert(it1, _length[pos] + len_seg1); - for (it1 = _length.begin() + pos_dt + 2; it1 != _length.end(); - ++it1) - { - *it1 += update_dist; - } - } - } - } return true; } @@ -177,37 +97,6 @@ void Polyline::removePoint(std::size_t pos) auto const pos_dt( static_cast<std::vector<std::size_t>::difference_type>(pos)); _ply_pnt_ids.erase(_ply_pnt_ids.begin() + pos_dt); - - if (pos == _ply_pnt_ids.size()) - { - _length.erase(_length.begin() + pos_dt); - return; - } - - const std::size_t n_ply_pnt_ids(_ply_pnt_ids.size()); - if (pos == 0) - { - double seg_length(_length[0]); - for (std::size_t k(0); k < n_ply_pnt_ids; k++) - { - _length[k] = _length[k + 1] - seg_length; - } - _length.pop_back(); - } - else - { - const double len_seg0(_length[pos] - _length[pos - 1]); - const double len_seg1(_length[pos + 1] - _length[pos]); - _length.erase(_length.begin() + pos_dt); - const double len_new_seg(std::sqrt(MathLib::sqrDist( - *_ply_pnts[_ply_pnt_ids[pos - 1]], *_ply_pnts[_ply_pnt_ids[pos]]))); - double seg_length_diff(len_new_seg - len_seg0 - len_seg1); - - for (std::size_t k(pos); k < n_ply_pnt_ids; k++) - { - _length[k] += seg_length_diff; - } - } } std::size_t Polyline::getNumberOfPoints() const @@ -298,12 +187,6 @@ std::vector<Point*> const& Polyline::getPointsVec() const return _ply_pnts; } -double Polyline::getLength(std::size_t k) const -{ - assert(k < _length.size()); - return _length[k]; -} - Polyline* Polyline::constructPolylineFromSegments( const std::vector<Polyline*>& ply_vec, double prox) { @@ -430,7 +313,7 @@ void Polyline::closePolyline() } Location Polyline::getLocationOfPoint(std::size_t k, - GeoLib::Point const& pnt) const + MathLib::Point3d const& pnt) const { assert(k < _ply_pnt_ids.size() - 1); @@ -476,9 +359,16 @@ double Polyline::getDistanceAlongPolyline(const MathLib::Point3d& pnt, double dist(-1.0); double lambda; bool found = false; + double act_length_of_ply = 0.0; // loop over all line segments of the polyline for (std::size_t k = 0; k < getNumberOfSegments(); k++) { + auto const a = + Eigen::Map<Eigen::Vector3d const>(getPoint(k)->getCoords()); + auto const b = + Eigen::Map<Eigen::Vector3d const>(getPoint(k + 1)->getCoords()); + double const seg_length((b - a).norm()); + act_length_of_ply += seg_length; // is the orthogonal projection of the j-th node to the // line g(lambda) = _ply->getPoint(k) + lambda * (_ply->getPoint(k+1) - // _ply->getPoint(k)) at the k-th line segment of the polyline, i.e. 0 @@ -487,8 +377,6 @@ double Polyline::getDistanceAlongPolyline(const MathLib::Point3d& pnt, *getPoint(k + 1), lambda, dist) <= epsilon_radius) { - double const act_length_of_ply(getLength(k)); - double const seg_length(getLength(k + 1) - getLength(k)); double const lower_lambda(-epsilon_radius / seg_length); double const upper_lambda(1 + epsilon_radius / seg_length); @@ -622,12 +510,6 @@ Polyline::SegmentIterator Polyline::SegmentIterator::operator-( return t; } -std::ostream& operator<<(std::ostream& os, const Polyline& pl) -{ - pl.write(os); - return os; -} - bool containsEdge(const Polyline& ply, std::size_t id0, std::size_t id1) { if (id0 == id1) diff --git a/GeoLib/Polyline.h b/GeoLib/Polyline.h index 40ae761e27e039e0170bdbff93e9ada02ede78ec..a5162d1880f98ac1af88c255e4cac5196cd54cd2 100644 --- a/GeoLib/Polyline.h +++ b/GeoLib/Polyline.h @@ -105,8 +105,6 @@ public: /// return a geometry type GEOTYPE getGeoType() const override { return GEOTYPE::POLYLINE; } - /** write the points to the stream */ - void write(std::ostream &os) const; /** * Adds an id of a point at the end of the polyline if and only if the @@ -200,13 +198,6 @@ public: std::vector<Point*> const& getPointsVec () const; - /** - * returns the length of the polyline until the k-th line segment - * @param k the k-th line segment - * @return the length of the polyline until the k-th line segment - */ - double getLength (std::size_t k) const; - /** * returns the distance along the polyline from the beginning of the polyline * @param pnt the point on the polyline @@ -217,7 +208,6 @@ public: double getDistanceAlongPolyline(const MathLib::Point3d& pnt, const double epsilon_radius) const; - friend bool operator==(Polyline const& lhs, Polyline const& rhs); protected: /** * 2D method - ignores z coordinate. It calculates the location @@ -228,24 +218,19 @@ protected: * @param pnt the point * @return a value of enum LOCATION */ - Location getLocationOfPoint (std::size_t k, GeoLib::Point const & pnt) const; + Location getLocationOfPoint(std::size_t k, + MathLib::Point3d const& pnt) const; /** a reference to the vector of pointers to the geometric points */ const std::vector<Point*> &_ply_pnts; /** position of pointers to the geometric points */ std::vector<std::size_t> _ply_pnt_ids; - /** - * the k-th element of the vector contains the length of the polyline until the k-th segment - */ - std::vector<double> _length; + private: LineSegment getSegment(std::size_t i) const; LineSegment getSegment(std::size_t i); }; -/** overload the output operator for class Polyline */ -std::ostream& operator<< (std::ostream &os, Polyline const& pl); - bool containsEdge (const Polyline& ply, std::size_t id0, std::size_t id1); /** diff --git a/GeoLib/SensorData.cpp b/GeoLib/SensorData.cpp index f2464ccc39f91874b95ae21ebbf00ed75cd021c4..87918e9c523485e172519c3f06ea04983942c186 100644 --- a/GeoLib/SensorData.cpp +++ b/GeoLib/SensorData.cpp @@ -24,7 +24,7 @@ SensorData::SensorData(const std::string& file_name) : _start(0), _end(0), _step_size(0), _time_unit(TimeStepType::NONE) { - this->readDataFromFile(file_name); + readDataFromFile(file_name); } SensorData::SensorData(std::vector<std::size_t> time_steps) @@ -43,16 +43,6 @@ SensorData::SensorData(std::vector<std::size_t> time_steps) } } -SensorData::SensorData(std::size_t first_timestep, - std::size_t last_timestep, - std::size_t step_size) - : _start(first_timestep), - _end(last_timestep), - _step_size(step_size), - _time_unit(TimeStepType::NONE) -{ -} - SensorData::~SensorData() { for (std::vector<float>* vec : _data_vecs) @@ -65,9 +55,9 @@ void SensorData::addTimeSeries(const std::string& data_name, std::vector<float>* data, const std::string& data_unit_string) { - this->addTimeSeries(SensorData::convertString2SensorDataType(data_name), - data, - data_unit_string); + addTimeSeries(SensorData::convertString2SensorDataType(data_name), + data, + data_unit_string); } void SensorData::addTimeSeries(SensorDataType data_name, @@ -132,54 +122,50 @@ int SensorData::readDataFromFile(const std::string& file_name) std::getline(in, line); std::list<std::string> fields = BaseLib::splitString(line, '\t'); std::list<std::string>::const_iterator it(fields.begin()); - std::size_t nFields = fields.size(); + std::size_t const nFields = fields.size(); if (nFields < 2) { return 0; } - std::size_t nDataArrays(nFields - 1); + std::size_t const nDataArrays(nFields - 1); // create vectors necessary to hold the data for (std::size_t i = 0; i < nDataArrays; i++) { - this->_vec_names.push_back( - SensorData::convertString2SensorDataType(*++it)); - this->_data_unit_string.emplace_back(""); - auto* data = new std::vector<float>; - this->_data_vecs.push_back(data); + _vec_names.push_back(SensorData::convertString2SensorDataType(*++it)); + _data_unit_string.emplace_back(""); + _data_vecs.push_back(new std::vector<float>); } while (std::getline(in, line)) { fields = BaseLib::splitString(line, '\t'); - if (nFields == fields.size()) + if (nFields != fields.size()) { - it = fields.begin(); - std::size_t pos(it->rfind(".")); - std::size_t current_time_step = (pos == std::string::npos) - ? atoi((it++)->c_str()) - : BaseLib::strDate2int(*it++); - this->_time_steps.push_back(current_time_step); - - for (std::size_t i = 0; i < nDataArrays; i++) - { - this->_data_vecs[i]->push_back( - static_cast<float>(strtod((it++)->c_str(), nullptr))); - } + return 0; } - else + + it = fields.begin(); + std::size_t const pos(it->rfind(".")); + std::size_t const current_time_step = (pos == std::string::npos) + ? atoi((it++)->c_str()) + : BaseLib::strDate2int(*it++); + _time_steps.push_back(current_time_step); + + for (std::size_t i = 0; i < nDataArrays; i++) { - return 0; + _data_vecs[i]->push_back( + static_cast<float>(strtod((it++)->c_str(), nullptr))); } } in.close(); - this->_start = this->_time_steps[0]; - this->_end = this->_time_steps[this->_time_steps.size() - 1]; + _start = _time_steps[0]; + _end = _time_steps[_time_steps.size() - 1]; return 1; } diff --git a/GeoLib/SensorData.h b/GeoLib/SensorData.h index a73fd4362fb69082e942bd21d0a16828cf8648c1..6178fbfdbd50d7c2ff62d05c43bf9b99ea8bdb8d 100644 --- a/GeoLib/SensorData.h +++ b/GeoLib/SensorData.h @@ -67,9 +67,6 @@ public: /// Constructor using a time step vector valid for all time series that will be added later explicit SensorData(std::vector<std::size_t> time_steps); - /// Constructor using time step bounds for all time series that will be added later - SensorData(std::size_t first_timestep, std::size_t last_timestep, std::size_t step_size); - ~SensorData(); /// Adds a time series that needs to conform to the time step vector specified in the constructor. diff --git a/GeoLib/Station.cpp b/GeoLib/Station.cpp index b32c38e8a497d631f3d08bc53402783bc4a6e7a5..bf27f494f84df932b84ee78c76361f6886e78ddd 100644 --- a/GeoLib/Station.cpp +++ b/GeoLib/Station.cpp @@ -22,14 +22,14 @@ namespace GeoLib { -Station::Station(double x, double y, double z, std::string name) - : Point(x, y, z), _name(std::move(name)) - +Station::Station(double x, double y, double z, std::string name, + Station::StationType type) + : Point(x, y, z), _name(std::move(name)), _type(type) { } -Station::Station(Point* coords, std::string name) - : Point(*coords), _name(std::move(name)) +Station::Station(Point* coords, std::string name, Station::StationType type) + : Point(*coords), _name(std::move(name)), _type(type) { } diff --git a/GeoLib/Station.h b/GeoLib/Station.h index 675506730c8234d51df0af5693985767bcab899f..875998dcd6c9c8f5fbea7a8c3e33f7307302fb57 100644 --- a/GeoLib/Station.h +++ b/GeoLib/Station.h @@ -51,13 +51,15 @@ public: * \param y The y-coordinate of the station. * \param z The z-coordinate of the station. * \param name The name of the station. + * \param type The type of the station, see Station::StationType for + * possible values. */ - explicit Station(double x = 0.0, - double y = 0.0, - double z = 0.0, - std::string name = ""); + explicit Station(double x = 0.0, double y = 0.0, double z = 0.0, + std::string name = "", + Station::StationType type = Station::StationType::STATION); - explicit Station(Point* coords, std::string name = ""); + explicit Station(Point* coords, std::string name = "", + Station::StationType type = Station::StationType::STATION); /** * Constructor copies the source object @@ -93,11 +95,9 @@ public: /// Returns all the sensor data for this observation site const SensorData* getSensorData() const { return this->_sensor_data; } -protected: +private: std::string _name; StationType _type{Station::StationType::STATION}; // GeoSys Station Type - -private: double _station_value{0.0}; SensorData* _sensor_data{nullptr}; }; diff --git a/GeoLib/StationBorehole.cpp b/GeoLib/StationBorehole.cpp index ab69083709b35c286f9d31aeb50976bd5d71d5fb..aa521ad5c065d271c9526d04475669fde32d207e 100644 --- a/GeoLib/StationBorehole.cpp +++ b/GeoLib/StationBorehole.cpp @@ -32,11 +32,13 @@ namespace GeoLib StationBorehole::StationBorehole(double x, double y, double z, - const std::string& name) - : Station(x, y, z, name) + double const depth, + const std::string& name, + int date) + : Station(x, y, z, name, Station::StationType::BOREHOLE), + _depth(depth), + _date(date) { - _type = Station::StationType::BOREHOLE; - // add first point of borehole _profilePntVec.push_back(this); _soilName.emplace_back(""); @@ -52,46 +54,6 @@ StationBorehole::~StationBorehole() } } -StationBorehole* StationBorehole::createStation(const std::string& line) -{ - StationBorehole* borehole = new StationBorehole(); - std::list<std::string> fields = BaseLib::splitString(line, '\t'); - - if (fields.size() >= 5) - { - borehole->_name = fields.front(); - fields.pop_front(); - (*borehole)[0] = strtod( - BaseLib::replaceString(",", ".", fields.front()).c_str(), nullptr); - fields.pop_front(); - (*borehole)[1] = strtod( - BaseLib::replaceString(",", ".", fields.front()).c_str(), nullptr); - fields.pop_front(); - (*borehole)[2] = strtod( - BaseLib::replaceString(",", ".", fields.front()).c_str(), nullptr); - fields.pop_front(); - borehole->_depth = strtod( - BaseLib::replaceString(",", ".", fields.front()).c_str(), nullptr); - fields.pop_front(); - if (fields.empty()) - { - borehole->_date = 0; - } - else - { - borehole->_date = BaseLib::strDate2int(fields.front()); - fields.pop_front(); - } - } - else - { - WARN("Station::createStation() - Unexpected file format."); - delete borehole; - return nullptr; - } - return borehole; -} - StationBorehole* StationBorehole::createStation(const std::string& name, double x, double y, @@ -99,17 +61,12 @@ StationBorehole* StationBorehole::createStation(const std::string& name, double depth, const std::string& date) { - StationBorehole* station = new StationBorehole(); - station->_name = name; - (*station)[0] = x; - (*station)[1] = y; - (*station)[2] = z; - station->_depth = depth; + int integer_date = 0; if (date != "0000-00-00") { - station->_date = BaseLib::xmlDate2int(date); + integer_date = BaseLib::xmlDate2int(date); } - return station; + return new StationBorehole(x, y, z, depth, name, integer_date); } void StationBorehole::addSoilLayer(double thickness, @@ -132,7 +89,7 @@ void StationBorehole::addSoilLayer(double thickness, // KR - Bode if (_profilePntVec.empty()) { - addSoilLayer((*this)[0], (*this)[1], (*this)[2], ""); + addSoilLayer((*this)[0], (*this)[1], (*this)[2], soil_name); } std::size_t idx(_profilePntVec.size()); diff --git a/GeoLib/StationBorehole.h b/GeoLib/StationBorehole.h index 98a6277c88029a4e53af27898105d8ea7ad518a2..93bfc5d7ed6fa773627bc965dc4bbd93a2ba06f1 100644 --- a/GeoLib/StationBorehole.h +++ b/GeoLib/StationBorehole.h @@ -22,32 +22,31 @@ namespace GeoLib { - /** * \brief A borehole as a geometric object. * - * A borehole inherits Station but has some additional information such as a date, a borehole profile, etc. + * A borehole inherits Station but has some additional information such as a + * date, a borehole profile, etc. */ class StationBorehole : public Station { public: /** constructor initialises the borehole with the given coordinates */ - explicit StationBorehole(double x = 0.0, - double y = 0.0, - double z = 0.0, - const std::string& name = ""); + explicit StationBorehole(double x, + double y, + double z, + double const depth, + const std::string& name, + int date); ~StationBorehole() override; - /// Creates a StationBorehole-object from a string (assuming the string has the right format) - static StationBorehole* createStation(const std::string &line); - /// Creates a new borehole object based on the given parameters. - static StationBorehole* createStation(const std::string &name, + static StationBorehole* createStation(const std::string& name, double x, double y, double z, double depth, - const std::string &date = ""); + const std::string& date = ""); // Returns the depth of the borehole double getDepth() const { return _depth; } @@ -55,31 +54,36 @@ public: /// Returns the date entry for the borehole double getDate() const { return _date; } - /// Returns a reference to a vector of Points representing the stratigraphy of the borehole (incl. the station-point itself) - const std::vector<Point*> &getProfile() const { return _profilePntVec; } + /// Returns a reference to a vector of Points representing the stratigraphy + /// of the borehole (incl. the station-point itself) + const std::vector<Point*>& getProfile() const { return _profilePntVec; } - /// Returns a reference to a vector of soil names for the stratigraphy of the borehole - const std::vector<std::string> &getSoilNames() const { return _soilName; } + /// Returns a reference to a vector of soil names for the stratigraphy of + /// the borehole + const std::vector<std::string>& getSoilNames() const { return _soilName; } /// Sets the depth of the borehole - void setDepth( double depth ) { _depth = depth; } + void setDepth(double depth) { _depth = depth; } /// Add a soil layer to the boreholes stratigraphy. - void addSoilLayer ( double thickness, const std::string &soil_name); + void addSoilLayer(double thickness, const std::string& soil_name); /** * Add a soil layer to the boreholes stratigraphy. - * Note: The given coordinates always mark THE END of the soil layer. The reason behind this is - * that the beginning of the first layer is identical with the position of the borehole. For each - * layer following the beginning is already given by the end of the last layer. This also saves - * a separate entry in the profile vector for the end of the borehole which in the given notation - * is just the coordinate given for the last soil layer (i.e. the end of that layer). + * Note: The given coordinates always mark THE END of the soil layer. The + * reason behind this is that the beginning of the first layer is identical + * with the position of the borehole. For each layer following the beginning + * is already given by the end of the last layer. This also saves a separate + * entry in the profile vector for the end of the borehole which in the + * given notation is just the coordinate given for the last soil layer (i.e. + * the end of that layer). */ - void addSoilLayer ( double x, double y, double z, const std::string &soil_name); + void addSoilLayer(double x, + double y, + double z, + const std::string& soil_name); private: - //long profile_type; - //std::vector<long> _soilType; double _depth{0}; // depth of the borehole int _date{0}; // date when the borehole has been drilled diff --git a/Tests/GeoLib/TestPolyline.cpp b/Tests/GeoLib/TestPolyline.cpp index 721a56cbd2640b8547d76b82fe3e2d2384daa7a5..58c5506f94dfe1e757e4e9f2f8f9e12e76d0ccd1 100644 --- a/Tests/GeoLib/TestPolyline.cpp +++ b/Tests/GeoLib/TestPolyline.cpp @@ -25,7 +25,6 @@ TEST(GeoLib, PolylineTest) ASSERT_EQ(std::size_t(0), ply.getNumberOfPoints()); ASSERT_FALSE(ply.isClosed()); ASSERT_FALSE(ply.isPointIDInPolyline(0)); - ASSERT_EQ(0.0, ply.getLength(0)); ply_pnts.push_back(new GeoLib::Point(0.0, 0.0, 0.0)); ply.addPoint(0); @@ -33,7 +32,6 @@ TEST(GeoLib, PolylineTest) ASSERT_EQ(std::size_t(1), ply.getNumberOfPoints()); ASSERT_FALSE(ply.isClosed()); ASSERT_TRUE(ply.isPointIDInPolyline(0)); - ASSERT_EQ(0.0, ply.getLength(0)); ply_pnts.push_back(new GeoLib::Point(1.0, 0.0, 0.0)); ply.addPoint(1); @@ -41,7 +39,6 @@ TEST(GeoLib, PolylineTest) ASSERT_EQ(std::size_t(2), ply.getNumberOfPoints()); ASSERT_FALSE(ply.isClosed()); ASSERT_TRUE(ply.isPointIDInPolyline(1)); - ASSERT_EQ(1.0, ply.getLength(1)); // checking properties of polyline with two points ply_pnts.push_back(new GeoLib::Point(0.5, 0.5, 0.0)); @@ -49,24 +46,18 @@ TEST(GeoLib, PolylineTest) ASSERT_EQ(std::size_t(3), ply.getNumberOfPoints()); ASSERT_FALSE(ply.isClosed()); ASSERT_TRUE(ply.isPointIDInPolyline(2)); - ASSERT_TRUE(fabs(ply.getLength(2) - (1.0 + sqrt(0.5))) < - std::numeric_limits<double>::epsilon()); // checking remove ply.removePoint(1); ASSERT_EQ(std::size_t(2), ply.getNumberOfPoints()); ASSERT_FALSE(ply.isClosed()); ASSERT_FALSE(ply.isPointIDInPolyline(1)); - ASSERT_TRUE(fabs(ply.getLength(1) - sqrt(0.5)) < - std::numeric_limits<double>::epsilon()); // inserting point in the middle ply.insertPoint(1, 1); ASSERT_EQ(std::size_t(3), ply.getNumberOfPoints()); ASSERT_FALSE(ply.isClosed()); ASSERT_TRUE(ply.isPointIDInPolyline(2)); - ASSERT_TRUE(fabs(ply.getLength(2) - (1.0 + sqrt(0.5))) < - std::numeric_limits<double>::epsilon()); // inserting point at the end ply_pnts.push_back(new GeoLib::Point(1.0, 0.5, 0.0)); @@ -74,8 +65,6 @@ TEST(GeoLib, PolylineTest) ASSERT_EQ(std::size_t(4), ply.getNumberOfPoints()); ASSERT_FALSE(ply.isClosed()); ASSERT_TRUE(ply.isPointIDInPolyline(3)); - ASSERT_TRUE(fabs(ply.getLength(3) - (1.0 + sqrt(0.5) + 0.5)) < - std::numeric_limits<double>::epsilon()); // inserting point at the beginning ply_pnts.push_back(new GeoLib::Point(-1.0, 0.0, 0.0)); @@ -83,8 +72,6 @@ TEST(GeoLib, PolylineTest) ASSERT_EQ(std::size_t(5), ply.getNumberOfPoints()); ASSERT_FALSE(ply.isClosed()); ASSERT_TRUE(ply.isPointIDInPolyline(4)); - ASSERT_TRUE(fabs(ply.getLength(4) - (1.0 + 1.0 + sqrt(0.5) + 0.5)) < - std::numeric_limits<double>::epsilon()); // inserting point in the middle ply_pnts.push_back(new GeoLib::Point(0.0, 0.5, 0.0)); @@ -92,9 +79,6 @@ TEST(GeoLib, PolylineTest) ASSERT_EQ(std::size_t(6), ply.getNumberOfPoints()); ASSERT_FALSE(ply.isClosed()); ASSERT_TRUE(ply.isPointIDInPolyline(5)); - ASSERT_TRUE( - fabs(ply.getLength(5) - (1.0 + 0.5 + sqrt(1.25) + sqrt(0.5) + 0.5)) < - std::numeric_limits<double>::epsilon()); // close polyline ply.closePolyline();