Skip to content

Commit a4ac730

Browse files
committed
dynamic_pcl_package
1 parent 0644da2 commit a4ac730

File tree

4 files changed

+102
-44
lines changed

4 files changed

+102
-44
lines changed

CMakeLists.txt

+47-29
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ endif()
5757
#-------------------------------------------------
5858
option(BUILD_RAN_AND_RBF_NETWORKS "Build RAN and RBF networks (requires CULA)" ON)
5959
option(CULA_R17_OR_ABOVE "CULA version is R17 or above" ON)
60-
option(BUILD_SURFACE_RECONSTRUCTION_SOM "Build surface reconstruction function in SOM (required PCL)" ON)
60+
option(BUILD_SURFACE_RECONSTRUCTION_SOM "Build surface reconstruction function in SOM" ON)
61+
option(BUILD_PCL_VIEWER "Build viewer extension in surface reconstruction function in SOM" ON)
6162

6263
set(ARCH_OPTIONS default 11 12 13 20 30 35 50 52)
6364
list(GET ARCH_OPTIONS 0 DEFAULT_ARCH)
@@ -194,23 +195,25 @@ endif()
194195

195196
find_package( PCL 1.8 )
196197

197-
if( PCL_FOUND AND BUILD_SURFACE_RECONSTRUCTION_SOM )
198-
# [C/C++]>[General]>[Additional Include Directories]
199-
include_directories( ${PCL_INCLUDE_DIRS} )
198+
if( PCL_FOUND AND BUILD_SURFACE_RECONSTRUCTION_SOM AND BUILD_PCL_VIEWER )
199+
add_definitions(-DPCL_EXIST)
200+
201+
# [C/C++]>[General]>[Additional Include Directories]
202+
include_directories( ${PCL_INCLUDE_DIRS} )
200203

201-
# [C/C++]>[Preprocessor]>[Preprocessor Definitions]
202-
add_definitions( ${PCL_DEFINITIONS} )
204+
# [C/C++]>[Preprocessor]>[Preprocessor Definitions]
205+
add_definitions( ${PCL_DEFINITIONS} )
203206

204-
# For Use Not PreCompiled Features
205-
#add_definitions( -DPCL_NO_PRECOMPILE )
207+
# For Use Not PreCompiled Features
208+
#add_definitions( -DPCL_NO_PRECOMPILE )
206209

207-
# [Linker]>[General]>[Additional Library Directories]
208-
link_directories( ${PCL_LIBRARY_DIRS} )
210+
# [Linker]>[General]>[Additional Library Directories]
211+
link_directories( ${PCL_LIBRARY_DIRS} )
209212

210-
# [Linker]>[Input]>[Additional Dependencies]
211-
#target_link_libraries( SOM_Reconstruction ${PCL_LIBRARIES} )
213+
# [Linker]>[Input]>[Additional Dependencies]
214+
#target_link_libraries( SOM_Reconstruction ${PCL_LIBRARIES} )
212215
else()
213-
message(WARNING "PCL not found. Surface reconstruction for SOM will not be build")
216+
message(WARNING "PCL will not be built")
214217
endif()
215218
#-------------------------------------------------
216219

@@ -615,29 +618,44 @@ function(build_apps)
615618

616619
build_qt_app(SOM "${libs_som}" "${files_som}")
617620

618-
if(PCL_FOUND AND BUILD_SURFACE_RECONSTRUCTION_SOM)
621+
if(BUILD_SURFACE_RECONSTRUCTION_SOM)
619622
# SOM_Reconstruction GUI app
620623
qt5_add_resources(res_som_surface
621624
src/apps/SOM_Reconstruction/SOMSurfaceresources.qrc
622625
)
623-
624-
set (files_som_surface
625-
src/apps/SOM_Reconstruction/main.cpp
626-
src/apps/SOM_Reconstruction/SOMSurfacewidget.cpp
627-
${res_som_surface}
628-
)
629-
630-
# Build with PCL
631-
set (libs_som_surface
632-
gpumlib_cuda_som_surface
633-
gpumlib_utils
634-
gpumlib_gui
635-
${PCL_LIBRARIES}
636-
)
626+
627+
if(PCL_FOUND AND BUILD_PCL_VIEWER)
628+
set (files_som_surface
629+
src/apps/SOM_Reconstruction/main.cpp
630+
src/apps/SOM_Reconstruction/SOMSurfacewidget.cpp
631+
src/apps/SOM_Reconstruction/SurfaceViewer.cpp
632+
${res_som_surface}
633+
)
634+
635+
# Build with PCL
636+
set (libs_som_surface
637+
gpumlib_cuda_som_surface
638+
gpumlib_utils
639+
gpumlib_gui
640+
${PCL_LIBRARIES}
641+
)
642+
else()
643+
set (files_som_surface
644+
src/apps/SOM_Reconstruction/main.cpp
645+
src/apps/SOM_Reconstruction/SOMSurfacewidget.cpp
646+
${res_som_surface}
647+
)
648+
649+
set (libs_som_surface
650+
gpumlib_cuda_som_surface
651+
gpumlib_utils
652+
gpumlib_gui
653+
)
654+
endif()
637655

638656
build_qt_app(SOM_Reconstruction "${libs_som_surface}" "${files_som_surface}")
639657
else()
640-
message(WARNING "PCL not found. Cannot compile SOM for Surface Reconstruction.")
658+
message(WARNING "Surface Reconstruction will not be built")
641659
endif()
642660

643661
if (CSHARP_FOUND)

apps/SOM_Reconstruction/SOMSurfacewidget.cpp

+12-15
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@
4343
#include <cmath>
4444
#include <string>
4545

46-
#include <pcl/common/common.h>
47-
#include <pcl/io/auto_io.h>
48-
#include <pcl/visualization/pcl_visualizer.h>
46+
#ifdef PCL_EXIST
47+
48+
#include "SurfaceViewer.h"
49+
50+
#endif
4951

5052
#define GPUMLIB_SOM_INITIAL_LEARNING_RATE (cudafloat(0.5))
5153
#define WEIGHTS_OUTPUT_CPU "weights_cpu.txt"
@@ -277,19 +279,14 @@ namespace GPUMLib {
277279

278280
summaryLog.Append(log.ToString());
279281

280-
pcl::PolygonMesh mesh;
281-
pcl::io::load(DeviceIsCPU() ? PLY_OUTPUT_CPU : PLY_OUTPUT_GPU, mesh);
282+
#ifdef PCL_EXIST
282283

283-
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
284-
viewer->setBackgroundColor(0.8, 0.89, 1);
285-
viewer->addPolygonMesh(mesh, "meshes", 0);
286-
viewer->initCameraParameters();
287-
viewer->setCameraPosition(RESCALE_MAX / 2, RESCALE_MAX / 2, RESCALE_MAX * -2, RESCALE_MAX / 2, RESCALE_MAX / 2, RESCALE_MAX / 2, 0.00586493, 0.998639, -0.0518208);
288-
289-
while (!viewer->wasStopped()){
290-
viewer->spinOnce(100);
291-
boost::this_thread::sleep(boost::posix_time::microseconds(100000));
292-
}
284+
SurfaceViewer sv;
285+
sv.initViewer(RESCALE_MAX);
286+
sv.loadMesh(DeviceIsCPU() ? PLY_OUTPUT_CPU : PLY_OUTPUT_GPU);
287+
sv.run();
288+
289+
#endif
293290
}
294291

295292
int SOMSurfacewidget::TrainCPU(ProgressInfo & progress, int iteration, CudaMatrix<cudafloat> & inputData, CudaArray<int> & targets, CudaMatrix3D<cudafloat> & weights, CudaMatrix<int> & mapView, CudaArray<int> & winNode, cudafloat mapRadius, cudafloat timeConstant, LogHTML & summaryLog, LogHTML & log, int & mapType) {
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "SurfaceViewer.h"
2+
3+
void SurfaceViewer::initViewer(const int RESCALE_MAX) {
4+
viewer->setBackgroundColor(0.8, 0.89, 1);
5+
viewer->initCameraParameters();
6+
viewer->setCameraPosition(RESCALE_MAX / 2, RESCALE_MAX / 2, RESCALE_MAX * -2, RESCALE_MAX / 2, RESCALE_MAX / 2, RESCALE_MAX / 2, 0.00586493, 0.998639, -0.0518208);
7+
}
8+
9+
void SurfaceViewer::loadMesh(std::string meshPath) {
10+
pcl::io::load(meshPath, mesh);
11+
viewer->addPolygonMesh(mesh, "meshes", 0);
12+
}
13+
14+
void SurfaceViewer::run() {
15+
while (!viewer->wasStopped()){
16+
viewer->spinOnce(100);
17+
boost::this_thread::sleep(boost::posix_time::microseconds(100000));
18+
}
19+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
SurfaceViewer is a simple mesh viewer by using PCL opensource library.
3+
*/
4+
5+
#ifndef SURFACE_VIEWER
6+
#define SURFACE_VIEWER
7+
8+
#include <pcl/common/common.h>
9+
#include <pcl/io/auto_io.h>
10+
#include <pcl/visualization/pcl_visualizer.h>
11+
12+
class SurfaceViewer {
13+
private:
14+
pcl::PolygonMesh mesh;
15+
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer;
16+
17+
public:
18+
SurfaceViewer() : viewer(new pcl::visualization::PCLVisualizer("3D Viewer")){}
19+
void initViewer(const int);
20+
void loadMesh(std::string);
21+
void run();
22+
};
23+
24+
#endif

0 commit comments

Comments
 (0)