中国人真是太不知道分享了,看看这个老外的博客,启发性链接

http://www.pcl-users.org/


1. 这个是可用的源代码:
原文:I saw a thread with links to a non-vtk qt visualizer of pcl pointclouds, but I want to reuse as much of PCLVisualizer as possible and minimize novel code.  My hacky solution is below but it suffers
from the problem of creating an unused non-qt window in addition to the desired qt window that displays the point cloud and accepts mouse input.
I'd be fine with figuring out how to suppress that window or at least close it soon after it opens (though not if it requires changing vtk code), but a another solution might be to break out what addPointCloud() & fromHandlersToScreen() are doing into
accessible utility functions.
Any suggestions for how to proceed?  
Thanks,
-Lucas 

I installed QVTKWidget on Ubuntu with the package libvtk5-qt4-dev.

I added this to PCLVisualizer:
vtkSmartPointer<vtkRenderWindow> getRenderWindow() {

  return win_;

}

and my code looks like this (it's based off http://www.itk.org/Wiki/VTK/Examples/Cxx/Qt/RenderWindowNoUiFile):
///////////////////////////////////////////////使用RenderWindow

The complete modified source:

  1. #include <QApplication>
  2. #include <pcl/io/pcd_io.h>
  3. #include <pcl/features/normal_3d.h>
  4. #include <pcl/sample_consensus/sac_model_plane.h>
  5. #include <pcl/visualization/cloud_viewer.h>
  6. #include <pcl/common/common.h>
  7.  
  8. #include <QVTKWidget.h>
  9. int main(int argc, char** argv)
  10. {
  11. QApplication app(argc, argv);
  12. QVTKWidget widget;
  13. widget.resize(512, 256);
  14. {
  15. pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz (new pcl::PointCloud<pcl::PointXYZ>);
  16. {
  17. for (float y = -0.5f; y <= 0.5f; y += 0.01f)
  18. {
  19. for (float z = -0.5f; z <= 0.5f; z += 0.01f)
  20. {
  21. pcl::PointXYZ point;
  22. point.x = 2.0f - y;
  23. point.y = y;
  24. point.z = z;
  25. cloud_xyz->points.push_back (point);
  26. }
  27. }
  28. cloud_xyz->width = cloud_xyz->points.size ();
  29. cloud_xyz->height = 1;
  30. }
  31. // this creates and displays a window named "test_viz"
  32. // upon calling PCLVisualizerInteractor interactor_->Initialize ();
  33. // how to disable that?
  34. pcl::visualization::PCLVisualizer pviz ("test_viz", false);
  35. // not sure why but it is necessary to set the render window before modifying pviz
  36. vtkSmartPointer<vtkRenderWindow> renderWindow = pviz.getRenderWindow ();
  37. widget.SetRenderWindow (renderWindow);
  38. // these are useful to add to make the controls more like pcd_viewer
  39. pviz.setupInteractor (widget.GetInteractor (), widget.GetRenderWindow ());
  40. pviz.getInteractorStyle ()->setKeyboardModifier (pcl::visualization::INTERACTOR_KB_MOD_SHIFT);
  41. pviz.addPointCloud<pcl::PointXYZ>(cloud_xyz);
  42. pviz.setBackgroundColor(0, 0, 0.1);
  43. }
  44. widget.show();
  45. app.exec();
  46. return EXIT_SUCCESS;
  47. }

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

出现的错误

c:\Dev\VTK5.8.0\include\vtk-5.8\vtkSmartPointer.h:75: 错误:C2440: “static_cast”: 无法从“vtkObjectBase *const ”转换为“vtkRenderWindow *”

与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换

c:\Dev\VTK5.8.0\include\vtk-5.8\vtkSmartPointer.h(74): 编译类 模板 成员函数“vtkSmartPointer<T>::operator T(void) const”时

  1. with
  2. [
  3. T=vtkRenderWindow
  4. ]
  5. c:\PCL_1.7.1\include\pcl/visualization/common/ren_win_interact_map.h(70): 参见对正在编译的类 模板 实例化“vtkSmartPointer<T>”的引用
  6. with
  7. [
  8. T=vtkRenderWindow
  9. ]

2.这个可以实现JPEG图像读取显示

原文:RenderWindowNoUiFile.cxx

  1. #include <QApplication>
  2.  
  3. #include <vtkSmartPointer.h>
  4. #include <vtkSphereSource.h>
  5. #include <vtkPolyDataMapper.h>
  6. #include <vtkActor.h>
  7. #include <vtkImageViewer.h>
  8. #include <vtkRenderWindowInteractor.h>
  9. #include <vtkInteractorStyleImage.h>
  10. #include <vtkRenderer.h>
  11. #include <vtkJPEGReader.h>
  12.  
  13. #include <QVTKWidget.h>
  14.  
  15. int main(int argc, char** argv)
  16. {
  17. QApplication app(argc, argv);
  18.  
  19. QVTKWidget widget;
  20. widget.resize(256,256);
  21.  
  22. // Setup sphere
  23. vtkSmartPointer<vtkSphereSource> sphereSource =
  24. vtkSmartPointer<vtkSphereSource>::New();
  25. sphereSource->Update();
  26. vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
  27. vtkSmartPointer<vtkPolyDataMapper>::New();
  28. sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
  29. vtkSmartPointer<vtkActor> sphereActor =
  30. vtkSmartPointer<vtkActor>::New();
  31. sphereActor->SetMapper(sphereMapper);
  32.  
  33. // Setup window
  34. vtkSmartPointer<vtkRenderWindow> renderWindow =
  35. vtkSmartPointer<vtkRenderWindow>::New();
  36.  
  37. // Setup renderer
  38. vtkSmartPointer<vtkRenderer> renderer =
  39. vtkSmartPointer<vtkRenderer>::New();
  40. renderWindow->AddRenderer(renderer);
  41.  
  42. renderer->AddActor(sphereActor);
  43. renderer->ResetCamera();
  44.  
  45. widget.SetRenderWindow(renderWindow);
  46. widget.show();
  47. app.exec();
  48. return EXIT_SUCCESS;
  49. }
  50.  
  51. CMakeLists.txt
  52.  
  53. cmake_minimum_required(VERSION 2.8)
  54.  
  55. if(POLICY CMP0020)
  56. cmake_policy(SET CMP0020 NEW)
  57. endif()
  58.  
  59. PROJECT(RenderWindowNoUiFile)
  60.  
  61. find_package(VTK REQUIRED)
  62. include(${VTK_USE_FILE})
  63.  
  64. if(${VTK_VERSION} VERSION_GREATER "6" AND VTK_QT_VERSION VERSION_GREATER "4")
  65. # Instruct CMake to run moc automatically when needed.
  66. set(CMAKE_AUTOMOC ON)
  67. find_package(Qt5Widgets REQUIRED QUIET)
  68. else()
  69. find_package(Qt4 REQUIRED)
  70. include(${QT_USE_FILE})
  71. endif()
  72.  
  73. include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
  74.  
  75. file(GLOB UI_FILES *.ui)
  76. file(GLOB QT_WRAP *.h)
  77. file(GLOB CXX_FILES *.cxx)
  78.  
  79. if(${VTK_VERSION} VERSION_GREATER "6" AND VTK_QT_VERSION VERSION_GREATER "4")
  80. qt5_wrap_ui(UISrcs ${UI_FILES} )
  81. # CMAKE_AUTOMOC in ON so the MocHdrs will be automatically wrapped.
  82. add_executable(RenderWindowNoUiFile MACOSX_BUNDLE
  83. ${CXX_FILES} ${UISrcs} ${QT_WRAP})
  84. qt5_use_modules(RenderWindowNoUiFile Core Gui)
  85. target_link_libraries(RenderWindowNoUiFile ${VTK_LIBRARIES})
  86. else()
  87. QT4_WRAP_UI(UISrcs ${UI_FILES})
  88. QT4_WRAP_CPP(MOCSrcs ${QT_WRAP})
  89. add_executable(RenderWindowNoUiFile MACOSX_BUNDLE ${CXX_FILES} ${UISrcs} ${MOCSrcs})
  90.  
  91. if(VTK_LIBRARIES)
  92. if(${VTK_VERSION} VERSION_LESS "6")
  93. target_link_libraries(RenderWindowNoUiFile ${VTK_LIBRARIES} QVTK)
  94. else()
  95. target_link_libraries(RenderWindowNoUiFile ${VTK_LIBRARIES})
  96. endif()
  97. else()
  98. target_link_libraries(RenderWindowNoUiFile vtkHybrid QVTK vtkViews ${QT_LIBRARIES})
  99. endif()
  100. endif()

Download and Build RenderWindowNoUiFile

Click here to download RenderWindowNoUiFile. and its CMakeLists.txt file.

Once the tarball RenderWindowNoUiFile.tar has been downloaded and extracted,

  1. cd RenderWindowNoUiFile/build

This example requires Qt and VTK.

  • If VTK and Qt are installed:
  1. cmake ..
  • If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:
  1. cmake -DVTK_DIR:PATH=/home/me/vtk_build ..
  • If Qt is not found on your system, you will need to tell CMake where to find qmake:
  1. cmake -DQT_QMAKE_EXECUTABLE:FILEPATH=/usr/something/qmake ..

Build the project:

  1. make

and run it:

  1. ./RenderWindowNoUiFile

随机推荐

  1. Golang - 处理字符串

    目录 Golang - 处理字符串 1. 字符串操作 2. 字符串转换 Golang - 处理字符串 1. 字符串操作 func Contains(s, substr string) bool 字符串 ...

  2. H5-video1 iOS苹果和微信中音频和视频实现自动播放的方法

    <audio preload="preload" controls id="car_audio" src="http://media.xitao ...

  3. 2.2 SVN的简单使用

    1.打开SVN服务器 选中Repositories→右键→Create new Repositories 选中Test2→右键→Copy URL to Clipboard 打开记事本粘贴地址:http ...

  4. springcloud 中文文档

    spring cloud 中文文档:https://springcloud.cc/spring-cloud-dalston.html spring cloud 中文网:https://springcl ...

  5. 第一次训练 密码:acmore

    #include <cstdio> #include <cstring> #define M 100010 #define INF 0x7FFFFFFF #define Min ...

  6. Number Puzzle

    Number Puzzle Time Limit: 2 Seconds      Memory Limit: 65536 KB Given a list of integers (A1, A2, .. ...

  7. 洛谷 P2764 LibreOJ 6002 最小路径覆盖问题

    题目描述 «问题描述: 给定有向图G=(V,E).设P 是G 的一个简单路(顶点不相交)的集合.如果V 中每个顶点恰好在P 的一条路上,则称P是G 的一个路径覆盖.P 中路径可以从V 的任何一个顶点开 ...

  8. LaTeX的简单使用方法

    先来一个总结得比较好的https://blog.csdn.net/garfielder007/article/details/51646604 1.普通公式 $公式不换行$ $公式不换行$ $$公式独 ...

  9. C#版winform实现UrlEncode

    在Asp.net中可以使用Server.HTMLEncode和Server.URLEncode 将文本或URL的特殊字符编码,但在控制台或Winform程序中没有办法使用到这些方法, 解决办法:右击项 ...

  10. STL之rb_tree的find函数

    1 通用的search方法 STL在实现对特定key值的查找时,并没有採用通用的方法: BRTreeNode * rb_tree_search(RBTreeNode * x, int key){ wh ...