From 1bc0f86cc0e4e9275d473936b7bac8efc899ccca Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Thu, 25 Feb 2021 10:54:05 +0000 Subject: [PATCH] WS30 Line Features - fix build Add missing files. --- simgear/scene/tgdb/LineFeatureBin.cxx | 107 ++++++++++++++++++++++++++ simgear/scene/tgdb/LineFeatureBin.hxx | 81 +++++++++++++++++++ 2 files changed, 188 insertions(+) create mode 100644 simgear/scene/tgdb/LineFeatureBin.cxx create mode 100644 simgear/scene/tgdb/LineFeatureBin.hxx diff --git a/simgear/scene/tgdb/LineFeatureBin.cxx b/simgear/scene/tgdb/LineFeatureBin.cxx new file mode 100644 index 00000000..b5bd4803 --- /dev/null +++ b/simgear/scene/tgdb/LineFeatureBin.cxx @@ -0,0 +1,107 @@ +/* -*-c++-*- + * + * Copyright (C) 2008 Stuart Buchanan + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include +#include + +#include "LineFeatureBin.hxx" + +using namespace osg; + +namespace simgear +{ + +LineFeatureBin::LineFeatureBin(const SGPath& absoluteFileName, const std::string material) : + _material(material) +{ + if (!absoluteFileName.exists()) { + SG_LOG(SG_TERRAIN, SG_ALERT, "LineFeature list file " << absoluteFileName << " does not exist."); + return; + } + + sg_gzifstream stream(absoluteFileName); + if (!stream.is_open()) { + SG_LOG(SG_TERRAIN, SG_ALERT, "Unable to open " << absoluteFileName); + return; + } + + while (!stream.eof()) { + // read a line. Each line defines a single line feature, consisting of a width followed by a series of lon/lat positions. + // Or a comment, starting with # + std::string line; + std::getline(stream, line); + + // strip comments + std::string::size_type hash_pos = line.find('#'); + if (hash_pos != std::string::npos) + line.resize(hash_pos); + + // and process further + std::stringstream in(line); + + // Line format is W A B C D lon0 lat0 lon1 lat1 lon2 lat2 lon3 lat4.... + // where: + // W is the width in m + // A, B, C, D are generic attributes. Their interpretation may vary by feature type + // lon[n], lat[n] are pairs of lon/lat defining straight road segments + float w = 0.0f; + int attributes = 0; + float a=0, b=0, c=0, d=0; + std::list nodes; + + in >> w >> attributes >> a >> b >> c >> d; + + if (in.bad() || in.fail()) { + SG_LOG(SG_TERRAIN, SG_WARN, "Error parsing road entry in: " << absoluteFileName << " line: \"" << line << "\""); + continue; + } + + while (true) { + float lon = 0.0f, lat=0.0f; + in >> lon >> lat; + + if (in.bad() || in.fail()) { + break; + } + + const SGGeod node = SGGeod::fromDeg(lon, lat); + nodes.push_back(node); + } + + if (nodes.size() > 1) { + insert(LineFeature(nodes, w, attributes, a, b, c, d)); + } else { + SG_LOG(SG_TERRAIN, SG_WARN, "LineFeature definition with fewer than two lon/lat nodes : " << absoluteFileName << " line: \"" << line << "\""); + } + } + + stream.close(); +}; + + +} diff --git a/simgear/scene/tgdb/LineFeatureBin.hxx b/simgear/scene/tgdb/LineFeatureBin.hxx new file mode 100644 index 00000000..13b7cde6 --- /dev/null +++ b/simgear/scene/tgdb/LineFeatureBin.hxx @@ -0,0 +1,81 @@ +/* -*-c++-*- + * + * Copyright (C) 2021 Stuart Buchanan + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + */ + +#ifndef ROAD_BIN_HXX +#define ROAD_BIN_HXX + +#include +#include + +#include +#include +#include + +#include +#include + +namespace simgear +{ +class LineFeatureBin { +public: + LineFeatureBin() = default; + LineFeatureBin(const SGPath& absoluteFileName, const std::string material); + + ~LineFeatureBin() = default; + + struct LineFeature { + const std::list _nodes; + const float _width; + const int _attributes; + const float _a; + const float _b; + const float _c; + const float _d; + LineFeature(const std::list nodes, const float w, const int attributes, const float a, const float b, const float c, const float d) : + _nodes(nodes), _width(w), _attributes(attributes), _a(a), _b(b), _c(c), _d(d) + { + } + }; + + typedef std::list LineFeatureList; + + void insert(const LineFeature& t) { + _lineFeatureList.push_back(t); + } + + const LineFeatureList getLineFeatures() const { + return _lineFeatureList; + } + + const std::string getMaterial() const { + return _material; + } + +private: + LineFeatureList _lineFeatureList; + const std::string _material; +}; + +typedef std::list LineFeatureBinList; + +} + +#endif