Salut,
J'ai écrit un objet qui contient des méthodes que j'utilise souvent. Je fais ça pour pouvoir inclure la classe dans d'autres projets rapidement.
Je teste donc avec un traitement assez simple mais j'ai un problème à l'édition des liens. J'utilise cmake et je n'ai pas trouvé de réponse que j'ai compris parmi mes recherches sur le net.
Voilà comment le projet est organisé :
Je mets dans global_variables.h tout mes includes et mes typedefs. La classe OpenNIViewer fonctionne (dans l'exemple elle est incomplète et sert à rien mais c'est pour alléger la lecture)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 . |-- build `-- src |-- CMakeLists.txt |-- CloudProcessing.cpp |-- CloudProcessing.h |-- OpenNIViewer.cpp |-- OpenNIViewer.h |-- global_variables.h |-- main.cpp
Ma classe c'est CloudProcessing et je n'arrive pas à appeler une méthode de l'objet instancié dans ma définition de la méthode cloud_cb_ (objet OpenNIViewer)
CMakeLists.txt
main.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 cmake_minimum_required(VERSION 2.8 FATAL_ERROR) project(pcl_segmentation_plane) find_package(PCL 1.2 REQUIRED) include_directories(${PCL_INCLUDE_DIRS}) link_directories(${PCL_LIBRARY_DIRS}) add_definitions(${PCL_DEFINITIONS}) add_executable (segmentation_plane main.cpp CloudProcessing.cpp OpenNIViewer.cpp) target_link_libraries (segmentation_plane ${PCL_LIBRARIES})
global_variables.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 #include "global_variables.h" #include "CloudProcessing.h" #include "OpenNIViewer.h" int main () { OpenNIViewer v; v.run (); return 0; }
CloudProcessing.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #ifndef GLOBAL_VARIABLES_H #define GLOBAL_VARIABLES_H #include <iostream> // Commmon PCL headers #include <pcl/io/openni_grabber.h> #include <pcl/point_types.h> #include <pcl/visualization/cloud_viewer.h> // PCL headers for CloudProcessing #include <pcl/filters/passthrough.h> typedef pcl::PointXYZRGBA PointT; typedef pcl::PointCloud<PointT> PointCloudT; #endif
CloudProcessing.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #ifndef CLOUDPROCESSING_H #define CLOUDPROCESSING_H #include "global_variables.h" class CloudProcessing { public: CloudProcessing (); // Passtrough filter on Z with max & optional min depth filtering int zPassThrough ( const PointCloudT::ConstPtr &cloud_in, PointCloudT::Ptr &cloud_out, float z_max, float z_min = 0.0f ); }; #endif
OpenNIViewer.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include "CloudProcessing.h" CloudProcessing::CloudProcessing () { } int zPassThrough ( const PointCloudT::ConstPtr &cloud_in, PointCloudT::Ptr &cloud_out, float z_max, float z_min = 0.0f ) { return 0; }
OpenNIViewer.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #ifndef OPENNIVIEWER_H #define OPENNIVIEWER_H #include "global_variables.h" class OpenNIViewer { public: OpenNIViewer (); void cloud_cb_ (const PointCloudT::ConstPtr &cloud); void run (); pcl::visualization::CloudViewer viewer; }; #endif
L'erreur lors de la compilation : (c'est la ligne 17 du fichier OpenNIViewer.cpp qui entraîne cette erreur)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #include "CloudProcessing.h" #include "OpenNIViewer.h" OpenNIViewer::OpenNIViewer():viewer ("PCL OpenNI Viewer") { } void OpenNIViewer::cloud_cb_(const PointCloudT::ConstPtr &cloud) { if (!viewer.wasStopped()) { if (cloud->size() == 0) { std::cout << "Point cloud is empty." << std::endl; exit; } CloudProcessing cloud_processing; PointCloudT::Ptr cloud_filtered (new PointCloudT); cloud_processing.zPassThrough (cloud, cloud_filtered, 2.0f, 0.0f); } } void OpenNIViewer::run() { pcl::Grabber* interface = new pcl::OpenNIGrabber(); boost::function<void (const PointCloudT::ConstPtr&)> f = boost::bind (&OpenNIViewer::cloud_cb_, this, _1); interface->registerCallback (f); interface->start (); while (!viewer.wasStopped()) { boost::this_thread::sleep (boost::posix_time::seconds (1)); } interface->stop (); }
J'espère que vous saurez me guider et expliquer mon erreur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 $ make -j 4 Scanning dependencies of target segmentation_plane [ 33%] [ 66%] Building CXX object CMakeFiles/segmentation_plane.dir/OpenNIViewer.cpp.o [100%] Building CXX object CMakeFiles/segmentation_plane.dir/main.cpp.o Building CXX object CMakeFiles/segmentation_plane.dir/CloudProcessing.cpp.o Linking CXX executable segmentation_plane CMakeFiles/segmentation_plane.dir/OpenNIViewer.cpp.o: In function `OpenNIViewer::cloud_cb_(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> const> const&)': OpenNIViewer.cpp:(.text+0x1ad): undefined reference to `CloudProcessing::zPassThrough(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> const> const&, boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> >&, float, float)' collect2: ld returned 1 exit status make[2]: *** [segmentation_plane] Error 1 make[1]: *** [CMakeFiles/segmentation_plane.dir/all] Error 2 make: *** [all] Error 2
Je vous ai mis le projet archivé en pièce jointe.
Merci
Partager