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 1 commit
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
60 changes: 60 additions & 0 deletions include/maliput_sparse/loader/builder_configuration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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 {

/// 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{};
};

} // namespace loader
} // namespace maliput_sparse
58 changes: 58 additions & 0 deletions include/maliput_sparse/loader/road_geometry_loader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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/parser/parser.h"
#include "maliput_sparse/loader/builder_configuration.h"

namespace maliput_sparse {
namespace loader {

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
69 changes: 69 additions & 0 deletions include/maliput_sparse/parser/lane.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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 <optional>
#include <string>
#include <unordered_set>

#include "maliput_sparse/geometry/line_string.h"

namespace maliput_sparse {
namespace parser {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why change it to parser from loader?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was under maliput_osm/osm.


/// Contains the characteristics of a lane.
struct Lane {
agalbachicar marked this conversation as resolved.
Show resolved Hide resolved
using Id = std::string;

/// Equality operator.
/// @param other The other object to compare against.
bool operator==(const Lane& other) const {
return id == other.id && left == other.left && right == other.right && left_lane_id == other.left_lane_id &&
right_lane_id == other.right_lane_id && successors == other.successors && predecessors == other.predecessors;
}

/// Id of the lane.
Id id{};
/// The lane's left boundary.
geometry::LineString3d left;
/// The lane's right boundary.
geometry::LineString3d right;
/// The id of the lane to the left of this lane.
std::optional<Id> left_lane_id;
/// The id of the lane to the right of this lane.
std::optional<Id> right_lane_id;
/// The ids of the lanes that follow this lane.
std::unordered_set<Id> successors;
/// The ids of the lanes that precede this lane.
std::unordered_set<Id> predecessors;
};

} // namespace parser
} // namespace maliput_sparse
63 changes: 63 additions & 0 deletions include/maliput_sparse/parser/parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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 <unordered_map>

#include <maliput/common/maliput_copyable.h>

#include "maliput_sparse/parser/segment.h"

namespace maliput_sparse {
namespace parser {

/// Pure virtual parser API class to be inherited by a specific parser class.
/// @code {.cpp}
/// class MyParser : public Parser {
/// public:
/// MyParser(const std::string& my_file) : Parser() { // Parse underlying file and fill up segments.}
/// const std::unordered_map<Segment::Id, Segment>& DoGetSegments() const override {
/// return segments_;
/// }
/// @endcode
class Parser {
public:
MALIPUT_NO_COPY_NO_MOVE_NO_ASSIGN(Parser)
Parser() = default;
virtual ~Parser() = default;

/// Gets the segments parsed from the input description.
const std::unordered_map<Segment::Id, Segment>& GetSegments() const {return DoGetSegments();}
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 it is a bit premature to move things here. This is an example of that. We would likely need also the Junction information and we are not even configuring other RoadNetwork entities (e.g. Intersections, Phases, etc.). The Parser should evolve to to provide all of them most likely.

I would refrain adding this class for the moment.

private:
virtual const std::unordered_map<Segment::Id, Segment>& DoGetSegments() const = 0;
};

} // namespace parser
} // namespace maliput_sparse
57 changes: 57 additions & 0 deletions include/maliput_sparse/parser/segment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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 <string>
#include <vector>

#include "maliput_sparse/geometry/line_string.h"
#include "maliput_sparse/parser/lane.h"

namespace maliput_sparse {
namespace parser {

/// A segment is a collection of lanes added with a strict order, from right to left,
/// similarly to maliput::api::Segment abstraction.
struct Segment {
using Id = std::string;

/// Equality operator.
/// @param other The other object to compare against.
bool operator==(const Segment& other) const { return id == other.id && lanes == other.lanes; }

/// Id of the segment.
Id id;
Copy link
Contributor

Choose a reason for hiding this comment

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

Add {} please.

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.

/// Collection of lanes that compose the segment.
std::vector<Lane> lanes;
};

} // namespace parser
} // namespace maliput_sparse
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_subdirectory(base)
add_subdirectory(builder)
add_subdirectory(geometry)
add_subdirectory(loader)
add_subdirectory(test_utilities)
41 changes: 41 additions & 0 deletions src/loader/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
##############################################################################
# Sources
##############################################################################

set(LOADER_SOURCES
builder_configuration.cc
road_geometry_loader.cc
)

add_library(loader ${LOADER_SOURCES})

add_library(maliput_sparse::loader ALIAS loader)

set_target_properties(loader
PROPERTIES
OUTPUT_NAME maliput_sparse_loader
)

target_include_directories(loader
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>)

target_link_libraries(loader
PUBLIC
maliput::api
maliput::common
maliput_sparse::builder
)

##############################################################################
# Export
##############################################################################

install(TARGETS loader
EXPORT ${PROJECT_NAME}-targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)