Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builds up RoadGeometry out of parsed information. #40

Merged
merged 4 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 74 additions & 0 deletions include/maliput_sparse/loader/builder_configuration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// BSD 3-Clause License
//
// Copyright (c) 2022, Woven Planet.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once

#include <map>
#include <optional>
#include <string>

#include <maliput/api/road_geometry.h>
#include <maliput/math/vector.h>

namespace maliput_sparse {
namespace loader {

/// Holds the configuration parameters for the builder.
struct BuilderConfiguration {
/// Create a BuilderConfiguration from a string dictionary.
static BuilderConfiguration FromMap(const std::map<std::string, std::string>& config);

/// @details The keys of the map are listed at @ref builder_configuration_keys.
/// @returns A string-string map containing the builder configuration.
std::map<std::string, std::string> ToStringMap() const;
Comment on lines +44 to +49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should make these free functions to keep the style of other repositories.
Consider deleting constructors if you want to enforce a specific way of contring from a map this struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I am not seeing the full picture here, why make them free functions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a nit.
The comment was to keep PODs as structs or convert them to classes to have functions like these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, thanks for the clarification. Let me move forward with this PR and create an issue for improving the style on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#44


/// Id of the road geometry.
maliput::api::RoadGeometryId road_geometry_id{"maliput_sparse"};
/// Linear resolution of the road geometry.
double linear_tolerance{1.e-3};
/// Angular resolution of the road geometry.
double angular_tolerance{1.e-3};
/// Scale factor for road geometry.
double scale_length{1.};
/// Translation from maliput to maliput_sparse inertial frame.
maliput::math::Vector3 inertial_to_backend_frame_translation{};
/// Path to the configuration file to load a RuleRegistry
std::optional<std::string> rule_registry{std::nullopt};
/// Path to the configuration file to load a RoadRulebook
std::optional<std::string> road_rule_book{std::nullopt};
/// Path to the configuration file to load a TrafficLightBook.
std::optional<std::string> traffic_light_book{std::nullopt};
/// Path to the configuration file to load a PhaseRingBook.
std::optional<std::string> phase_ring_book{std::nullopt};
/// Path to the configuration file to load an IntersectionBook.
std::optional<std::string> intersection_book{std::nullopt};
};

} // namespace loader
} // namespace maliput_sparse
94 changes: 94 additions & 0 deletions include/maliput_sparse/loader/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// BSD 3-Clause License
//
// Copyright (c) 2022, Woven Planet.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once

#include <maliput/api/road_geometry.h>
#include <maliput/math/vector.h>

namespace maliput_sparse {
namespace loader {
namespace config {

/// @defgroup builder_configuration_keys RoadNetwork configuration builder keys
///
/// Parameters used during the RoadNetwork building process.
///
/// When parameters are omitted the default value will be used.
///
/// @{

/// A string that works as ID of the RoadGeometry.
/// - Default: @e "maliput"
static constexpr char const* kRoadGeometryId{"road_geometry_id"};

/// RoadGeometry's linear tolerance.
/// - Default: @e "5e-2"
static constexpr char const* kLinearTolerance{"linear_tolerance"};

/// RoadGeometry's angular tolerance.
/// - Default: @e "1e-3"
static constexpr char const* kAngularTolerance{"angular_tolerance"};

/// RoadGeometry's scale length.
/// - Default: @e "1.0"
static constexpr char const* kScaleLength{"scale_length"};

/// Translation from maliput to maliput_osm inertial frame.
/// The format of the 3-dimensional vector that is expected to be passed
/// should be {X, Y, Z}. Same format as maliput::math::Vector3 is
/// serialized.
/// - Default: @e "{0., 0., 0.}"
static constexpr char const* kInertialToBackendFrameTranslation{"inertial_to_backend_frame_translation"};

/// Path to the configuration file to load a RoadRulebook
/// - Default: ""
static constexpr char const* kRoadRuleBook{"road_rule_book"};

/// Path to the configuration file to load a RoadRulebook
/// - Default: ""
static constexpr char const* kRuleRegistry{"rule_registry"};

/// Path to the configuration file to load a TrafficLightBook
/// - Default: ""
static constexpr char const* kTrafficLightBook{"traffic_light_book"};

/// Path to the configuration file to load a PhaseRingBook
/// - Default: ""
static constexpr char const* kPhaseRingBook{"phase_ring_book"};

/// Path to the configuration file to load a IntersectionBook
/// - Default: ""
static constexpr char const* kIntersectionBook{"intersection_book"};

/// @}

} // namespace config
} // namespace loader
} // namespace maliput_sparse
61 changes: 61 additions & 0 deletions include/maliput_sparse/loader/road_geometry_loader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// BSD 3-Clause License
//
// Copyright (c) 2022, Woven Planet.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once

#include <memory>

#include <maliput/api/road_geometry.h>

#include "maliput_sparse/loader/builder_configuration.h"
#include "maliput_sparse/parser/parser.h"

namespace maliput_sparse {
namespace loader {

/// Loads a RoadGeometry based on a maliput_sparse::parser::Parser implementation.
/// This functor is expected to be used by the maliput backends that rely on
/// maliput_sparse to load the RoadGeometry.
class RoadGeometryLoader {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing class docstring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

public:
/// Constructs a RoadGeometryLoader.
/// @param parser The parser to use for building the RoadGeometry.
/// @param builder_configuration The configuration of the builder.
RoadGeometryLoader(std::unique_ptr<parser::Parser> parser, const BuilderConfiguration& builder_configuration);

/// Builds a RoadGeometry.
std::unique_ptr<const maliput::api::RoadGeometry> operator()();

private:
const std::unique_ptr<parser::Parser> parser_;
const BuilderConfiguration builder_configuration_;
};

} // namespace loader
} // namespace maliput_sparse
62 changes: 62 additions & 0 deletions include/maliput_sparse/loader/road_network_loader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// BSD 3-Clause License
//
// Copyright (c) 2022, Woven Planet.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once

#include <memory>

#include <maliput/api/road_network.h>

#include "maliput_sparse/loader/builder_configuration.h"
#include "maliput_sparse/loader/road_geometry_loader.h"
#include "maliput_sparse/parser/parser.h"

namespace maliput_sparse {
namespace loader {

/// Loads a RoadNetwork based on a maliput_sparse::parser::Parser implementation.
/// This functor is expected to be used by the maliput backends that rely on
/// maliput_sparse to load the RoadNetwork.
class RoadNetworkLoader {
public:
/// Constructs a RoadNetworkLoader.
/// @param parser The parser to use for building the RoadNetworkLoader.
/// @param builder_configuration The configuration of the builder.
RoadNetworkLoader(std::unique_ptr<parser::Parser> parser, const BuilderConfiguration& builder_configuration);

/// Builds a RoadNetworkLoader.
std::unique_ptr<maliput::api::RoadNetwork> operator()();

private:
const std::unique_ptr<RoadGeometryLoader> road_geometry_loader_;
const BuilderConfiguration builder_configuration_;
};

} // namespace loader
} // namespace maliput_sparse
51 changes: 51 additions & 0 deletions include/maliput_sparse/parser/connection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// BSD 3-Clause License
//
// Copyright (c) 2022, Woven Planet.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once

#include "maliput_sparse/parser/lane.h"

namespace maliput_sparse {
namespace parser {

/// Defines a connection between two lanes.
/// The lanes can be connected from either end.
/// Two connections are considered equal if they connect the same lanes using same ends without regard to the order.
struct Connection {
/// The LaneEnd that is connected from.
LaneEnd from;
/// The LaneEnd that is connected to.
LaneEnd to;

/// Equality operator.
bool operator==(const Connection& other) const;
};

} // namespace parser
} // namespace maliput_sparse