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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add map skeletonizer for Revit floor plans (graph generation) #9

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions map_skeletonizer/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BasedOnStyle: Google
UseTab: Never
ColumnLimit: 80
AccessModifierOffset: -2
AlignConsecutiveAssignments: true
AlignConsecutiveMacros: true
211 changes: 211 additions & 0 deletions map_skeletonizer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
cmake_minimum_required(VERSION 3.0.2)
project(map_skeletonizer)

## Compile as C++11, supported in ROS Kinetic and newer
set(CMAKE_CXX_STANDARD 14)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
cad2cav_types
roscpp
)

## System dependencies are found with CMake's conventions
find_package(Boost REQUIRED)
find_package(Eigen3 REQUIRED)


## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

################################################
## Declare ROS messages, services and actions ##
################################################

## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
## * add a build_depend tag for "message_generation"
## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
## but can be declared for certainty nonetheless:
## * add a exec_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
## * add "message_generation" and every package in MSG_DEP_SET to
## find_package(catkin REQUIRED COMPONENTS ...)
## * add "message_runtime" and every package in MSG_DEP_SET to
## catkin_package(CATKIN_DEPENDS ...)
## * uncomment the add_*_files sections below as needed
## and list every .msg/.srv/.action file to be processed
## * uncomment the generate_messages entry below
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder
# add_message_files(
# FILES
# Message1.msg
# Message2.msg
# )

## Generate services in the 'srv' folder
# add_service_files(
# FILES
# Service1.srv
# Service2.srv
# )

## Generate actions in the 'action' folder
# add_action_files(
# FILES
# Action1.action
# Action2.action
# )

## Generate added messages and services with any dependencies listed here
# generate_messages(
# DEPENDENCIES
# std_msgs # Or other packages containing msgs
# )

################################################
## Declare ROS dynamic reconfigure parameters ##
################################################

## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
## * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
## * add "dynamic_reconfigure" to
## find_package(catkin REQUIRED COMPONENTS ...)
## * uncomment the "generate_dynamic_reconfigure_options" section below
## and list every .cfg file to be processed

## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
# cfg/DynReconf1.cfg
# cfg/DynReconf2.cfg
# )

###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
INCLUDE_DIRS include
LIBRARIES map_skeletonizer
CATKIN_DEPENDS cad2cav_types roscpp
# DEPENDS system_lib
)

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
include
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIR}
${EIGEN3_INCLUDE_DIR}
)

## Declare a C++ library
add_library(${PROJECT_NAME}
src/distance_map.cpp
)

## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/map_skeletonizer_node.cpp)

## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")

## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Specify libraries to link a library or executable target against
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
${Boost_LIBRARIES}
)

#############
## Install ##
#############

# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html

## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# catkin_install_python(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark executables for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
# install(TARGETS ${PROJECT_NAME}_node
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark libraries for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)

## Mark cpp header files for installation
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
PATTERN ".svn" EXCLUDE
)

## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
# # myfile1
# # myfile2
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )

#############
## Testing ##
#############

## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_map_skeletonizer.cpp)
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()

## Add folders to be run by python nosetests
# catkin_add_nosetests(test)
151 changes: 151 additions & 0 deletions map_skeletonizer/include/map_skeletonizer/distance_map.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#ifndef __MAP_SKELETONIZER_DISTANCE_MAP_HPP__
#define __MAP_SKELETONIZER_DISTANCE_MAP_HPP__

/**
* @file distance_map.hpp
* @author Zhihao Ruan ([email protected])
*
* @brief Implements distance map update strategy in:
* B. Lau, C. Sprunk and W. Burgard, "Improved updating of Euclidean distance
* maps and Voronoi diagrams," IROS 2010.
*
* @date 2021-11-14
*/

#include <Eigen/Dense>
#include <limits>
#include <queue>
#include <vector>

#include "cad2cav_types/types.hpp"

namespace cad2cav {
namespace skeletonizer {

struct CellAttribute {
Eigen::Vector2i obs_pos; // position of the closest obstacle in map
bool to_raise;
bool on_voronoi;

CellAttribute() : obs_pos(-1, -1), to_raise(false), on_voronoi(false) {}
};

struct Cell {
// cell position in map
Eigen::Vector2i pos;
// distance to closest obstacle in map
double dist;
// may be the same attribute as in attrib_, or value-to-set
CellAttribute attrib;

Cell() : pos(-1, -1), dist(std::numeric_limits<double>::infinity()) {}
Cell(Eigen::Vector2i in_pos, double in_dist) : pos(in_pos), dist(in_dist) {}
};

bool operator>(const Cell& a, const Cell& b) { return a.dist > b.dist; }

class DistanceMapBuilder {
public:
DistanceMapBuilder() : map_width_(-1), map_height_(-1) {}
DistanceMapBuilder(const nav_msgs::OccupancyGrid& occ_grid,
int8_t cell_occupied_threshold = 50);
/**
* @brief Gets the current distance map. Stored in row-major order.
*
* @return const std::vector<double>&
*/
const std::vector<double>& getDistanceMap() const noexcept { return dist_; }
/**
* @brief Gets the distance to closest obstacle of cell (x,y).
*
* @param x
* @param y
* @return double&
*/
double& distAt(int x, int y);
double& distAt(Eigen::Vector2i xy);
const double& distAt(int x, int y) const;
const double& distAt(Eigen::Vector2i xy) const;
/**
* @brief Gets the attribute of cell (x,y).
*
* @param x
* @param y
* @return CellAttribute&
*/
CellAttribute& attributeAt(int x, int y);
CellAttribute& attributeAt(Eigen::Vector2i xy);
const CellAttribute& attributeAt(int x, int y) const;
const CellAttribute& attributeAt(Eigen::Vector2i xy) const;
/**
* @brief Check if (x,y) is an obstacle.
* Only depends on whether attrib_[x,y].obs_pos == (x,y).
*
* @param x
* @param y
* @return true
* @return false
*/
bool isOccupied(int x, int y) const;
bool isOccupied(Eigen::Vector2i xy) const;
/**
* @brief Makes (x,y) as a new obstacle, and starts a new wave propagation.
*
* @param x
* @param y
* @return Cell
*/
Cell makeObstacle(int x, int y) const;
/**
* @brief Makes (x,y) as a free cell (unoccupied), and starts a new wave
* propagation.
* Sets: cell.dist = inf, cell.attrib.obs_pos = (-1,-1).
*
* @param x
* @param y
* @return Cell
*/
Cell makeFree(int x, int y) const;
/**
* @brief Updates distance map with `open` queue and brushfire algorithm.
*
* Reference:
* https://cs.gmu.edu/~kosecka/cs685/cs685-motion-planning.pdf
*
*/
void updateDistanceMap();

private:
int map_width_;
int map_height_;

// distance map
std::vector<double> dist_;
// attributes for each cell in distance map
std::vector<CellAttribute> attrib_;
// `open` priority queue
std::priority_queue<Cell, std::vector<Cell>, std::greater<Cell>> open_;

/**
* @brief Boundary check for map element/attribute access.
*
* @param x
* @param y
*/
bool isOutOfBound(int x, int y) const;
bool isOutOfBound(Eigen::Vector2i xy) const;
bool isOutOfBound(int x, int y, std::string& err_msg) const;
/**
* @brief Resize dist_ and attrib_ to default empty values of size
* (map_height, map_width).
*
* @param map_width
* @param map_height
*/
void allocateEmptyDistMap(int map_width, int map_height);
};

} // namespace skeletonizer
} // namespace cad2cav

#endif /* __MAP_SKELETONIZER_DISTANCE_MAP_HPP__ */
Loading