MathLib::PiecewiseLinearInterpolation LinearInterpolationAlongPolyline::createInterpolation( const GeoLib::Polyline& ply, const std::vector<std::size_t>& vec_interpolate_point_ids, const std::vector<double>& vec_interpolate_point_values) { std::vector<double> vec_known_dist; std::vector<double> vec_known_values; vec_known_dist.reserve(vec_interpolate_point_ids.size()); vec_known_values.reserve(vec_interpolate_point_ids.size()); for (std::size_t i=0; i<vec_interpolate_point_ids.size(); i++) { const std::size_t pnt_id = vec_interpolate_point_ids[i]; if (!ply.isPointIDInPolyline(pnt_id)) continue; for (std::size_t j=0; j<ply.getNumberOfPoints(); j++) { if (pnt_id == ply.getPointID(j)) { vec_known_dist.push_back(ply.getLength(j)); vec_known_values.push_back(vec_interpolate_point_values[i]); break; } } } return MathLib::PiecewiseLinearInterpolation(vec_known_dist, vec_known_values); }
void checkPolylineProperties() { const GeoLib::PolylineVec *line_vec = geo_objects.getPolylineVecObj(geo_name); auto const readerLines = geo_objects.getPolylineVec(geo_name); EXPECT_EQ(5u, readerLines->size()); auto checkPolylineProperty = [this](GeoLib::PolylineVec const* line_vec, std::size_t ply_id, std::vector<std::size_t> pnt_ids, std::string const& name) { auto const lines = geo_objects.getPolylineVec(geo_name); GeoLib::Polyline* line = (*lines)[ply_id]; EXPECT_EQ(pnt_ids.size(), line->getNumberOfPoints()); for (std::size_t k(0); k<pnt_ids.size(); ++k) EXPECT_EQ(pnt_ids[k], line->getPointID(k)); std::string line_name; line_vec->getNameOfElementByID(ply_id, line_name); EXPECT_EQ(name, line_name); }; checkPolylineProperty(line_vec, 0, {0, 1, 2}, "left"); checkPolylineProperty(line_vec, 1, {3, 4, 5}, "center"); checkPolylineProperty(line_vec, 2, {0, 3}, "line1"); checkPolylineProperty(line_vec, 3, {3, 6}, "line2"); checkPolylineProperty(line_vec, 4, {6, 7, 8}, "right"); }
TEST(FileIO, XmlGmlWriterReaderTest) { // Writer test std::string test_data_file(BaseLib::BuildInfo::source_path + "/Tests/FileIO/xmlgmltestdata.gml"); GeoLib::GEOObjects geo_objects; //setup test data std::string geo_name("TestData"); { // Create points. auto points = std::unique_ptr<std::vector<GeoLib::Point*>>( new std::vector<GeoLib::Point*>(10)); (*points)[0] = new GeoLib::Point(1, 1, 0); (*points)[1] = new GeoLib::Point(1, 1, 0); (*points)[2] = new GeoLib::Point(1, 2, 0); (*points)[3] = new GeoLib::Point(1, 3, 0); (*points)[4] = new GeoLib::Point(2, 1, 0); (*points)[5] = new GeoLib::Point(2, 2, 0); (*points)[6] = new GeoLib::Point(2, 3, 0); (*points)[7] = new GeoLib::Point(3, 1, 0); (*points)[8] = new GeoLib::Point(3, 2, 0); (*points)[9] = new GeoLib::Point(3, 3, 0); geo_objects.addPointVec(std::move(points), geo_name); } auto const points = geo_objects.getPointVec(geo_name); const std::vector<std::size_t> pnt_id_map (geo_objects.getPointVecObj(geo_name)->getIDMap()); { // Create polylines. auto lines = std::unique_ptr<std::vector<GeoLib::Polyline*>>( new std::vector<GeoLib::Polyline*>(5)); std::map<std::string, std::size_t>* ply_names = new std::map<std::string, std::size_t>; (*lines)[0] = new GeoLib::Polyline(*points); (*lines)[0]->addPoint(pnt_id_map[0]); (*lines)[0]->addPoint(pnt_id_map[2]); (*lines)[0]->addPoint(pnt_id_map[3]); ply_names->insert(std::pair<std::string, std::size_t>("left", 0)); (*lines)[1] = new GeoLib::Polyline(*points); (*lines)[1]->addPoint(pnt_id_map[4]); (*lines)[1]->addPoint(pnt_id_map[5]); (*lines)[1]->addPoint(pnt_id_map[6]); ply_names->insert(std::pair<std::string, std::size_t>("center", 1)); (*lines)[2] = new GeoLib::Polyline(*points); (*lines)[2]->addPoint(pnt_id_map[1]); (*lines)[2]->addPoint(pnt_id_map[4]); (*lines)[3] = new GeoLib::Polyline(*points); (*lines)[3]->addPoint(pnt_id_map[4]); (*lines)[3]->addPoint(pnt_id_map[7]); (*lines)[4] = new GeoLib::Polyline(*points); (*lines)[4]->addPoint(pnt_id_map[7]); (*lines)[4]->addPoint(pnt_id_map[8]); (*lines)[4]->addPoint(pnt_id_map[9]); ply_names->insert(std::pair<std::string, std::size_t>("right", 4)); geo_objects.addPolylineVec(std::move(lines), geo_name, ply_names); } { // Create surfaces. auto sfcs = std::unique_ptr<std::vector<GeoLib::Surface*>>( new std::vector<GeoLib::Surface*>(2)); (*sfcs)[0] = new GeoLib::Surface(*points); (*sfcs)[0]->addTriangle(pnt_id_map[1], pnt_id_map[4], pnt_id_map[2]); (*sfcs)[0]->addTriangle(pnt_id_map[2], pnt_id_map[4], pnt_id_map[5]); (*sfcs)[0]->addTriangle(pnt_id_map[2], pnt_id_map[5], pnt_id_map[3]); (*sfcs)[0]->addTriangle(pnt_id_map[3], pnt_id_map[5], pnt_id_map[6]); (*sfcs)[1] = new GeoLib::Surface(*points); (*sfcs)[1]->addTriangle(pnt_id_map[4], pnt_id_map[7], pnt_id_map[9]); (*sfcs)[1]->addTriangle(pnt_id_map[4], pnt_id_map[9], pnt_id_map[6]); geo_objects.addSurfaceVec(std::move(sfcs), geo_name); } FileIO::XmlGmlInterface xml(geo_objects); xml.setNameForExport(geo_name); int result = xml.writeToFile(test_data_file); ASSERT_EQ(result, 1); // Reader test result = xml.readFile(QString::fromStdString(test_data_file)); ASSERT_EQ(result, 1); const std::vector<GeoLib::Point*> *readerPoints = geo_objects.getPointVec(geo_name); const GeoLib::PolylineVec *line_vec = geo_objects.getPolylineVecObj(geo_name); const std::vector<GeoLib::Polyline*> *readerLines = geo_objects.getPolylineVec(geo_name); const std::vector<GeoLib::Surface*> *readerSfcs = geo_objects.getSurfaceVec(geo_name); ASSERT_EQ(9u, readerPoints->size()); ASSERT_EQ(5u, readerLines->size()); ASSERT_EQ(2u, readerSfcs->size()); GeoLib::Point* pnt = (*readerPoints)[7]; ASSERT_EQ(3.0, (*pnt)[0]); ASSERT_EQ(2.0, (*pnt)[1]); ASSERT_EQ(0.0, (*pnt)[2]); GeoLib::Polyline* line = (*readerLines)[4]; ASSERT_EQ(3u, line->getNumberOfPoints()); ASSERT_EQ(6u, line->getPointID(0)); ASSERT_EQ(7u, line->getPointID(1)); ASSERT_EQ(8u, line->getPointID(2)); std::string line_name(""); line_vec->getNameOfElementByID(4, line_name); ASSERT_EQ("right", line_name); GeoLib::Surface* sfc = (*readerSfcs)[1]; ASSERT_EQ(2u, sfc->getNTriangles()); const GeoLib::Triangle* tri = (*sfc)[1]; ASSERT_EQ(3u, (*tri)[0]); ASSERT_EQ(8u, (*tri)[1]); ASSERT_EQ(5u, (*tri)[2]); boost::filesystem::remove(test_data_file); test_data_file += ".md5"; boost::filesystem::remove(test_data_file); }