commit 48697e8583f3a730a0bfbee23e06e379ae2e1dbf Author: Chinmay Date: Wed Dec 7 12:59:16 2022 +0100 transformation & downsampling diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..1b23ae1 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,36 @@ +{ + "configurations": [ + { + "browse": { + "databaseFilename": "${default}", + "limitSymbolsToIncludedHeaders": false + }, + "includePath": [ + "/home/chi/ros1_wss/ant_ws/devel/include/**", + "/opt/ros/noetic/include/**", + "/home/chi/ros1_wss/ant_ws/src/ant_costmap/include/**", + "/home/chi/ros1_wss/ant_ws/src/grid_map/cmap/include/**", + "/home/chi/ros1_wss/ant_ws/src/grid_map/grid_map_core/include/**", + "/home/chi/ros1_wss/ant_ws/src/grid_map/grid_map_costmap_2d/include/**", + "/home/chi/ros1_wss/ant_ws/src/grid_map/grid_map_cv/include/**", + "/home/chi/ros1_wss/ant_ws/src/grid_map/grid_map_demos/include/**", + "/home/chi/ros1_wss/ant_ws/src/grid_map/grid_map_filters/include/**", + "/home/chi/ros1_wss/ant_ws/src/grid_map/grid_map_loader/include/**", + "/home/chi/ros1_wss/ant_ws/src/grid_map/grid_map_octomap/include/**", + "/home/chi/ros1_wss/ant_ws/src/grid_map/grid_map_pcl/include/**", + "/home/chi/ros1_wss/ant_ws/src/grid_map/grid_map_ros/include/**", + "/home/chi/ros1_wss/ant_ws/src/grid_map/grid_map_rviz_plugin/include/**", + "/home/chi/ros1_wss/ant_ws/src/grid_map/grid_map_sdf/include/**", + "/home/chi/ros1_wss/ant_ws/src/grid_map/grid_map_visualization/include/**", + "/home/chi/ros1_wss/ant_ws/src/robot_localization/include/**", + "/usr/include/**" + ], + "name": "ROS", + "intelliSenseMode": "gcc-x64", + "compilerPath": "/usr/bin/gcc", + "cStandard": "gnu11", + "cppStandard": "c++14" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5c7247b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f0a84c5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,18 @@ +{ + "python.autoComplete.extraPaths": [ + "/home/chi/ros1_wss/ant_ws/devel/lib/python3/dist-packages", + "/opt/ros/noetic/lib/python3/dist-packages" + ], + "files.associations": { + "string": "cpp", + "cmath": "cpp", + "complex": "cpp", + "core": "cpp", + "geometry": "cpp", + "iostream": "cpp" + }, + "python.analysis.extraPaths": [ + "/home/chi/ros1_wss/ant_ws/devel/lib/python3/dist-packages", + "/opt/ros/noetic/lib/python3/dist-packages" + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..05054c5 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: g++ build active file", + "command": "/usr/bin/g++", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b14d00f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,264 @@ +cmake_minimum_required(VERSION 3.0.2) +project(cmap) + +## Compile as C++11, supported in ROS Kinetic and newer +# add_compile_options(-std=c++11) + +## 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 + roscpp + tf + tf2_ros + pcl_conversions + pcl_ros + sensor_msgs + std_msgs + genmsg + grid_map_core + grid_map_ros + grid_map_msgs + visualization_msgs +) + +#find_package(octomap REQUIRED) +#find_package(OpenCV REQUIRED ) +find_package(PCL REQUIRED) +# message(STATUS "Found Octomap (version ${octomap_VERSION}): ${OCTOMAP_INCLUDE_DIRS}") + +## System dependencies are found with CMake's conventions +find_package(Boost REQUIRED COMPONENTS system) + + +## 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 +# sensor_msgs# std_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 cmap +# CATKIN_DEPENDS pcl_conversions pcl_ros roscpp sensor_msgs std_msgs +# 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} + ${OpenCV_INCLUDE_DIRS} + ${PCL_INCLUDE_DIRS} +) + +# link_directories(${PCL_LIBRARY_DIRS}) +# link_directories${OpenCV_INCLUDE_DIRS} +## Declare a C++ library +# add_library(${PROJECT_NAME} +# src/${PROJECT_NAME}/cmap.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/cmap_node.cpp) + +#add_executable(testo +# src/testo.cpp +#) + +#target_link_libraries(testo ${catkin_LIBRARIES}) +#target_link_libraries(testo ${OpenCV_LIBS} ) + +add_executable(pcd_transformer + src/pcd_transformer.cpp +) + +target_link_libraries(pcd_transformer ${catkin_LIBRARIES}) +#target_link_libraries(pcd_transformer ${OpenCV_LIBS} ) +target_link_libraries(pcd_transformer ${PCL_LIBRARIES}) + +# add_executable(pcd_ptf +# src/pcd_ptf.cpp +# ) + +# target_link_libraries(pcd_ptf ${catkin_LIBRARIES}) +# target_link_libraries(pcd_ptf ${OpenCV_LIBS} ) +# target_link_libraries(pcd_ptf ${PCL_LIBRARIES}) + +add_executable(transforma + src/transforma.cpp +) + +target_link_libraries(transforma ${catkin_LIBRARIES}) +#target_link_libraries(transforma ${OpenCV_LIBS} ) +target_link_libraries(transforma ${PCL_LIBRARIES}) + +add_executable(greedy_projection + src/greedy_projection.cpp +) + +target_link_libraries(greedy_projection ${catkin_LIBRARIES}) +#target_link_libraries(pcd_transformer ${OpenCV_LIBS} ) +target_link_libraries(greedy_projection ${PCL_LIBRARIES}) + + +## 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}_node +# ${catkin_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 ".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_cmap.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) diff --git a/data/strawberryfields.pcd b/data/strawberryfields.pcd new file mode 100755 index 0000000..1d6f51b Binary files /dev/null and b/data/strawberryfields.pcd differ diff --git a/include/cmap/pcd_ptf.hpp b/include/cmap/pcd_ptf.hpp new file mode 100644 index 0000000..06976e7 --- /dev/null +++ b/include/cmap/pcd_ptf.hpp @@ -0,0 +1,18 @@ +#pragma once + +//ROS + +#include +#include +// #include +// #include +// #include +// #include +// #include +//Grid map +#include + +#include +// #include +#include +#include \ No newline at end of file diff --git a/include/cmap/testo.hpp b/include/cmap/testo.hpp new file mode 100644 index 0000000..06976e7 --- /dev/null +++ b/include/cmap/testo.hpp @@ -0,0 +1,18 @@ +#pragma once + +//ROS + +#include +#include +// #include +// #include +// #include +// #include +// #include +//Grid map +#include + +#include +// #include +#include +#include \ No newline at end of file diff --git a/include/cmap/transforma.hpp b/include/cmap/transforma.hpp new file mode 100644 index 0000000..06976e7 --- /dev/null +++ b/include/cmap/transforma.hpp @@ -0,0 +1,18 @@ +#pragma once + +//ROS + +#include +#include +// #include +// #include +// #include +// #include +// #include +//Grid map +#include + +#include +// #include +#include +#include \ No newline at end of file diff --git a/launch/test.launch b/launch/test.launch new file mode 100644 index 0000000..e42ea8e --- /dev/null +++ b/launch/test.launch @@ -0,0 +1,7 @@ + + + + + + + diff --git a/launch/transform.launch b/launch/transform.launch new file mode 100755 index 0000000..9146fda --- /dev/null +++ b/launch/transform.launch @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..bbeec1e --- /dev/null +++ b/package.xml @@ -0,0 +1,76 @@ + + + cmap + 0.0.0 + The cmap package + + + + + chi + + + + + + TODO + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + catkin + libpcl-all-dev + + roscpp + sensor_msgs + std_msgs + + roscpp + sensor_msgs + std_msgs + + roscpp + libpcl-all + sensor_msgs + std_msgs + + + + + + + + diff --git a/rviz/cmap_testing.rviz b/rviz/cmap_testing.rviz new file mode 100644 index 0000000..3235391 --- /dev/null +++ b/rviz/cmap_testing.rviz @@ -0,0 +1,233 @@ +Panels: + - Class: rviz/Displays + Help Height: 85 + Name: Displays + Property Tree Widget: + Expanded: + - /voxel_cloud1 + - /map_cloud1 + Splitter Ratio: 0.47749510407447815 + Tree Height: 628 + - Class: rviz/Selection + Name: Selection + - Class: rviz/Tool Properties + Expanded: + - /2D Pose Estimate1 + - /2D Nav Goal1 + - /Publish Point1 + Name: Tool Properties + Splitter Ratio: 0.5886790156364441 + - Class: rviz/Views + Expanded: + - /Current View1 + Name: Views + Splitter Ratio: 0.6059479713439941 + - Class: rviz/Time + Name: Time + SyncMode: 0 + SyncSource: voxel_cloud +Preferences: + PromptSaveOnExit: true +Toolbars: + toolButtonStyle: 2 +Visualization Manager: + Class: "" + Displays: + - Alpha: 0.5 + Cell Size: 1 + Class: rviz/Grid + Color: 160; 160; 164 + Enabled: true + Line Style: + Line Width: 0.029999999329447746 + Value: Lines + Name: Grid + Normal Cell Count: 0 + Offset: + X: 0 + Y: 0 + Z: 0 + Plane: XY + Plane Cell Count: 10 + Reference Frame: + Value: true + - Alpha: 1 + Autocompute Intensity Bounds: true + Autocompute Value Bounds: + Max Value: 10 + Min Value: -10 + Value: true + Axis: Z + Channel Name: intensity + Class: rviz/PointCloud2 + Color: 255; 255; 255 + Color Transformer: RGB8 + Decay Time: 0 + Enabled: false + Invert Rainbow: false + Max Color: 255; 255; 255 + Min Color: 0; 0; 0 + Name: voxel_cloud + Position Transformer: XYZ + Queue Size: 10 + Selectable: true + Size (Pixels): 3 + Size (m): 0.009999999776482582 + Style: Flat Squares + Topic: /voxel_cloud + Unreliable: false + Use Fixed Frame: true + Use rainbow: true + Value: false + - Class: rviz/TF + Enabled: true + Frame Timeout: 15 + Frames: + All Enabled: false + camera_accel_frame: + Value: false + camera_accel_optical_frame: + Value: false + camera_aligned_depth_to_color_frame: + Value: false + camera_color_frame: + Value: false + camera_color_optical_frame: + Value: false + camera_depth_frame: + Value: false + camera_depth_optical_frame: + Value: false + camera_gyro_frame: + Value: false + camera_imu_optical_frame: + Value: false + camera_link: + Value: true + Marker Alpha: 1 + Marker Scale: 1 + Name: TF + Show Arrows: true + Show Axes: true + Show Names: true + Tree: + camera_link: + camera_accel_frame: + camera_accel_optical_frame: + {} + camera_aligned_depth_to_color_frame: + camera_color_optical_frame: + {} + camera_color_frame: + {} + camera_depth_frame: + camera_depth_optical_frame: + {} + camera_gyro_frame: + camera_imu_optical_frame: + {} + Update Interval: 0 + Value: true + - Alpha: 1 + Class: rviz/Axes + Enabled: true + Length: 1 + Name: Axes + Radius: 0.10000000149011612 + Reference Frame: + Show Trail: false + Value: true + - Alpha: 1 + Autocompute Intensity Bounds: true + Autocompute Value Bounds: + Max Value: 10 + Min Value: -10 + Value: true + Axis: Z + Channel Name: intensity + Class: rviz/PointCloud2 + Color: 255; 255; 255 + Color Transformer: RGB8 + Decay Time: 0 + Enabled: true + Invert Rainbow: false + Max Color: 255; 255; 255 + Min Color: 0; 0; 0 + Name: map_cloud + Position Transformer: XYZ + Queue Size: 10 + Selectable: true + Size (Pixels): 3 + Size (m): 0.009999999776482582 + Style: Flat Squares + Topic: /map_cloud + Unreliable: false + Use Fixed Frame: true + Use rainbow: true + Value: true + Enabled: true + Global Options: + Background Color: 48; 48; 48 + Default Light: true + Fixed Frame: camera_color_optical_frame + Frame Rate: 30 + Name: root + Tools: + - Class: rviz/Interact + Hide Inactive Objects: true + - Class: rviz/MoveCamera + - Class: rviz/Select + - Class: rviz/FocusCamera + - Class: rviz/Measure + - Class: rviz/SetInitialPose + Theta std deviation: 0.2617993950843811 + Topic: /initialpose + X std deviation: 0.5 + Y std deviation: 0.5 + - Class: rviz/SetGoal + Topic: /move_base_simple/goal + - Class: rviz/PublishPoint + Single click: true + Topic: /clicked_point + Value: true + Views: + Current: + Class: rviz/Orbit + Distance: 2.104010820388794 + Enable Stereo Rendering: + Stereo Eye Separation: 0.05999999865889549 + Stereo Focal Distance: 1 + Swap Stereo Eyes: false + Value: false + Field of View: 0.7853981852531433 + Focal Point: + X: 0.03424595668911934 + Y: -0.006647967733442783 + Z: 0.4646419286727905 + Focal Shape Fixed Size: true + Focal Shape Size: 0.05000000074505806 + Invert Z Axis: false + Name: Current View + Near Clip Distance: 0.009999999776482582 + Pitch: 0.7497976422309875 + Target Frame: camera_color_optical_frame + Yaw: 3.0763397216796875 + Saved: ~ +Window Geometry: + Displays: + collapsed: false + Height: 959 + Hide Left Dock: false + Hide Right Dock: true + QMainWindow State: 000000ff00000000fd00000004000000000000017d00000310fc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000006e00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000004700000310000000f100fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c0000026100000001000001b800000310fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073000000004700000310000000c200fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e100000197000000030000078000000040fc0100000002fb0000000800540069006d00650100000000000007800000045a00fffffffb0000000800540069006d00650100000000000004500000000000000000000005fc0000031000000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000 + Selection: + collapsed: false + Time: + collapsed: false + Tool Properties: + collapsed: false + Views: + collapsed: true + Width: 1920 + X: 2560 + Y: 34 diff --git a/scripts/vtk_visualizer.py b/scripts/vtk_visualizer.py new file mode 100755 index 0000000..e69de29 diff --git a/src/greedy_projection.cpp b/src/greedy_projection.cpp new file mode 100644 index 0000000..003b9e6 --- /dev/null +++ b/src/greedy_projection.cpp @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include +#include +#include +#include +// #include +// #include + + + +// ros::Publisher mesh_pub ; + + +// void meshing_cb(const sensor_msgs::PointCloud2ConstPtr& cloud_msg) { + +// // Container for original & filtered data + +// pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2; +// pcl::PCLPointCloud2ConstPtr cloudPtr(cloud); +// pcl::PCLPointCloud2 cloud_; + +// // Convert to PCL data type +// pcl_conversions::toPCL(*cloud_msg, *cloud); +// } + +// int main(int argc, char **argv) +// { +// ros::init(argc, argv, "greedy_projection"); +// ros::NodeHandle nh; + +// ros::Subscriber cloud_in = nh.subscribe("map_cloud", 1, meshing_cb); +// mesh_pub = nh.advertise ("map_cloud", 1); + + +// ros::spin (); + +// } + + +int main() { + +pcl::PointCloud::Ptr cloud (new pcl::PointCloud); +pcl::PCLPointCloud2 cloud_blob; +pcl::io::loadPCDFile ("/home/chinmay/ros1_wss/ant_wss/src/grid_map/cmap/data/strawberryfields.pcd", cloud_blob); +pcl::fromPCLPointCloud2 (cloud_blob, *cloud); +//* the data should be available in cloud + +// Normal estimation* +pcl::NormalEstimation n; +pcl::PointCloud::Ptr normals (new pcl::PointCloud); +pcl::search::KdTree::Ptr tree (new pcl::search::KdTree); +tree->setInputCloud (cloud); +n.setInputCloud (cloud); +n.setSearchMethod (tree); +n.setKSearch (20); +n.compute (*normals); +//* normals should not contain the point normals + surface curvatures + +// Concatenate the XYZ and normal fields* +pcl::PointCloud::Ptr cloud_with_normals (new pcl::PointCloud); +pcl::concatenateFields (*cloud, *normals, *cloud_with_normals); +//* cloud_with_normals = cloud + normals + + // Create search tree* +pcl::search::KdTree::Ptr tree2 (new pcl::search::KdTree); +tree2->setInputCloud (cloud_with_normals); + +// Initialize objects +pcl::GreedyProjectionTriangulation gp3; +pcl::PolygonMesh triangles; + +// Set the maximum distance between connected points (maximum edge length) + gp3.setSearchRadius (0.025); + +// Set typical values for the parameters +gp3.setMu (2.5); +gp3.setMaximumNearestNeighbors (100); +gp3.setMaximumSurfaceAngle(M_PI/4); // 45 degrees +gp3.setMinimumAngle(M_PI/18); // 10 degrees +gp3.setMaximumAngle(2*M_PI/3); // 120 degrees +gp3.setNormalConsistency(false); + +// Get result +gp3.setInputCloud (cloud_with_normals); +gp3.setSearchMethod (tree2); +gp3.reconstruct (triangles); + +// Additional vertex information +std::vector parts = gp3.getPartIDs(); +std::vector states = gp3.getPointStates(); + +pcl::io::saveVTKFile ("mesh.vtk", triangles); +// Finish +return (0); +} diff --git a/src/pcd_transformer.cpp b/src/pcd_transformer.cpp new file mode 100644 index 0000000..34ef5f2 --- /dev/null +++ b/src/pcd_transformer.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define foreach BOOST_FOREACH + +tf::Transform trans; +// trans.setOrigin( tf::Vector3(1.3435, 0.0, -1.3435) ); +// tf::Quaternion q; +// q.setRPY(0, -0.698132, 0); +// trans.setRotation(q); +// const std::string target_frame = "base_link"; +const std::string target_frame = "camera_color_optical_frame"; +// float pitch = -0.698132; +// Eigen::Affine3f trans = Eigen::Affine3f::Identity(); +// trans.translation() << 1.3435, 0.0, -1.3435; +// trans.rotate (Eigen::AngleAxisf (pitch, Eigen::Vector3f::UnitY())); +// float pitch = -0.698132; +// Eigen::Affine3f trans = Eigen::Affine3f::Identity(); +// trans.translation() << 1.3435, 0.0, -1.3435; +// trans.rotate (Eigen::AngleAxisf (pitch, Eigen::Vector3f::UnitY())); + +ros::Publisher cloud_pub ; + +// https://github.com/methylDragon/pcl-ros-tutorial/blob/master/PCL%20Reference%20with%20ROS.md +// http://wiki.ros.org/pcl/Tutorials/hydro?action=AttachFile&do=view&target=example_voxelgrid.cpp +// http://docs.ros.org/en/indigo/api/pcl_ros/html/namespacepcl__ros.html#aad20af010640a41f1898e75f6a6121ad +// https://answers.ros.org/question/225820/subscribe-to-sensor_msgpointcloud2/ + + +void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_in) +{ + // sensor_msgs::PointCloud2 cloud_out; + // pcl_ros::transformPointCloud (target_frame, trans, cloud_in, cloud_out); + // transformed_cloud.publish(cloud_out); + pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2; + pcl::PCLPointCloud2ConstPtr cloudPtr(cloud); + pcl::PCLPointCloud2 cloud_filtered; + + pcl_conversions::toPCL(*cloud_in , *cloud); + + pcl::VoxelGrid sor; + sor.setInputCloud (cloudPtr); + sor.setLeafSize (0.1, 0.1, 0.1); + sor.filter (cloud_filtered); + sensor_msgs::PointCloud2 cloud_o; + sensor_msgs::PointCloud2 trans_cloud; + pcl_conversions::moveFromPCL(cloud_filtered, cloud_o); + + trans.setOrigin( tf::Vector3(1.3435, 0.0, -1.3435) ); + tf::Quaternion q; + q.setRPY(0, -0.698132, 0); + trans.setRotation(q); + + pcl_ros::transformPointCloud(target_frame, trans, cloud_o, trans_cloud); + + cloud_pub.publish (trans_cloud); + +} + + +int main(int argc, char **argv) +{ + ros::init(argc, argv, "pcd_transformer"); + ros::NodeHandle nh; + + ros::Subscriber cloud_in = nh.subscribe("/voxel_cloud", 1, cloud_cb); + + + cloud_pub = nh.advertise ("trans_cloud", 1); + + + ros::spin (); + +} \ No newline at end of file diff --git a/src/strawberryfields.pcd b/src/strawberryfields.pcd new file mode 100755 index 0000000..1d6f51b Binary files /dev/null and b/src/strawberryfields.pcd differ diff --git a/src/transforma.cpp b/src/transforma.cpp new file mode 100644 index 0000000..8adce0d --- /dev/null +++ b/src/transforma.cpp @@ -0,0 +1,105 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define foreach BOOST_FOREACH + + +typedef pcl::PointXYZRGB PointT; + + +ros::Publisher cloud_pub ; + + + +//Transformation + +void transformation(const pcl::PointCloud::Ptr &ip,pcl::PointCloud::Ptr &op ) +{ +float roll = -3.14; +float pitch = 0.87; +float yaw = 1.55; + + +Eigen::Affine3f trans = Eigen::Affine3f::Identity(); + + +trans.translation() << -0.55, 0, 2; +trans.rotate (Eigen::AngleAxisf (roll, Eigen::Vector3f::UnitX())); +trans.rotate (Eigen::AngleAxisf (pitch, Eigen::Vector3f::UnitY())); +trans.rotate (Eigen::AngleAxisf (yaw, Eigen::Vector3f::UnitZ())); + + +pcl::transformPointCloud (*ip, *op, trans); +} + + +//Surface meshing + +// void greedy_projection() { +// pcl::PointCloud::Ptr cloud (new pcl::PointCloud); +// pcl::PCLPointCloud2 cloud_blob; + +// } + + + +//Callback for subscriber + + +void +cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg) +{ + + sensor_msgs::PointCloud2 map_cloud; + std::cout << cloud_msg->header.frame_id << std::endl; + + // create pointer to Point Clouds in pcl + pcl::PointCloud::Ptr cloud(new pcl::PointCloud); + pcl::PointCloud::Ptr transform_cloud(new pcl::PointCloud); + pcl::fromROSMsg(*cloud_msg, *cloud); + pcl::fromROSMsg(*cloud_msg, *transform_cloud); + + + transformation(cloud,transform_cloud); + + + pcl::toROSMsg(*transform_cloud, map_cloud); + + cloud_pub.publish (map_cloud); +} + + + + + +int main(int argc, char **argv) +{ + ros::init(argc, argv, "pcd_transformer"); + ros::NodeHandle nh; + + ros::Subscriber cloud_in = nh.subscribe("/voxel_cloud", 1, cloud_cb); + + + cloud_pub = nh.advertise ("map_cloud", 1); + + + ros::spin (); + +} \ No newline at end of file