**PCL:嵌入VTK/QT显示(Code^_^)
中国人真是太不知道分享了,看看这个老外的博客,启发性链接。
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.
accessible utility functions.
I installed QVTKWidget on Ubuntu with the package libvtk5-qt4-dev.
vtkSmartPointer<vtkRenderWindow> getRenderWindow() {
return win_;
}
The complete modified source:
#include <QApplication>
#include <pcl/io/pcd_io.h>
#include <pcl/features/normal_3d.h>
#include <pcl/sample_consensus/sac_model_plane.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/common/common.h> #include <QVTKWidget.h>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QVTKWidget widget;
widget.resize(512, 256);
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz (new pcl::PointCloud<pcl::PointXYZ>);
{
for (float y = -0.5f; y <= 0.5f; y += 0.01f)
{
for (float z = -0.5f; z <= 0.5f; z += 0.01f)
{
pcl::PointXYZ point;
point.x = 2.0f - y;
point.y = y;
point.z = z;
cloud_xyz->points.push_back (point);
}
}
cloud_xyz->width = cloud_xyz->points.size ();
cloud_xyz->height = 1;
}
// this creates and displays a window named "test_viz"
// upon calling PCLVisualizerInteractor interactor_->Initialize ();
// how to disable that?
pcl::visualization::PCLVisualizer pviz ("test_viz", false);
// not sure why but it is necessary to set the render window before modifying pviz
vtkSmartPointer<vtkRenderWindow> renderWindow = pviz.getRenderWindow ();
widget.SetRenderWindow (renderWindow);
// these are useful to add to make the controls more like pcd_viewer
pviz.setupInteractor (widget.GetInteractor (), widget.GetRenderWindow ());
pviz.getInteractorStyle ()->setKeyboardModifier (pcl::visualization::INTERACTOR_KB_MOD_SHIFT);
pviz.addPointCloud<pcl::PointXYZ>(cloud_xyz);
pviz.setBackgroundColor(0, 0, 0.1);
}
widget.show();
app.exec();
return EXIT_SUCCESS;
}
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
出现的错误:
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”时
with
[
T=vtkRenderWindow
]
c:\PCL_1.7.1\include\pcl/visualization/common/ren_win_interact_map.h(70): 参见对正在编译的类 模板 实例化“vtkSmartPointer<T>”的引用
with
[
T=vtkRenderWindow
]
2.这个可以实现JPEG图像读取显示
原文:RenderWindowNoUiFile.cxx
#include <QApplication> #include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkImageViewer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleImage.h>
#include <vtkRenderer.h>
#include <vtkJPEGReader.h> #include <QVTKWidget.h> int main(int argc, char** argv)
{
QApplication app(argc, argv); QVTKWidget widget;
widget.resize(256,256); // Setup sphere
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
sphereSource->Update();
vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
vtkSmartPointer<vtkActor> sphereActor =
vtkSmartPointer<vtkActor>::New();
sphereActor->SetMapper(sphereMapper); // Setup window
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New(); // Setup renderer
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderWindow->AddRenderer(renderer); renderer->AddActor(sphereActor);
renderer->ResetCamera(); widget.SetRenderWindow(renderWindow);
widget.show();
app.exec();
return EXIT_SUCCESS;
} CMakeLists.txt cmake_minimum_required(VERSION 2.8) if(POLICY CMP0020)
cmake_policy(SET CMP0020 NEW)
endif() PROJECT(RenderWindowNoUiFile) find_package(VTK REQUIRED)
include(${VTK_USE_FILE}) if(${VTK_VERSION} VERSION_GREATER "6" AND VTK_QT_VERSION VERSION_GREATER "4")
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
find_package(Qt5Widgets REQUIRED QUIET)
else()
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
endif() include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) file(GLOB UI_FILES *.ui)
file(GLOB QT_WRAP *.h)
file(GLOB CXX_FILES *.cxx) if(${VTK_VERSION} VERSION_GREATER "6" AND VTK_QT_VERSION VERSION_GREATER "4")
qt5_wrap_ui(UISrcs ${UI_FILES} )
# CMAKE_AUTOMOC in ON so the MocHdrs will be automatically wrapped.
add_executable(RenderWindowNoUiFile MACOSX_BUNDLE
${CXX_FILES} ${UISrcs} ${QT_WRAP})
qt5_use_modules(RenderWindowNoUiFile Core Gui)
target_link_libraries(RenderWindowNoUiFile ${VTK_LIBRARIES})
else()
QT4_WRAP_UI(UISrcs ${UI_FILES})
QT4_WRAP_CPP(MOCSrcs ${QT_WRAP})
add_executable(RenderWindowNoUiFile MACOSX_BUNDLE ${CXX_FILES} ${UISrcs} ${MOCSrcs}) if(VTK_LIBRARIES)
if(${VTK_VERSION} VERSION_LESS "6")
target_link_libraries(RenderWindowNoUiFile ${VTK_LIBRARIES} QVTK)
else()
target_link_libraries(RenderWindowNoUiFile ${VTK_LIBRARIES})
endif()
else()
target_link_libraries(RenderWindowNoUiFile vtkHybrid QVTK vtkViews ${QT_LIBRARIES})
endif()
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,
cd RenderWindowNoUiFile/build
This example requires Qt and VTK.
- If VTK and Qt are installed:
cmake ..
- If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:
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:
cmake -DQT_QMAKE_EXECUTABLE:FILEPATH=/usr/something/qmake ..
Build the project:
make
and run it:
./RenderWindowNoUiFile
随机推荐
- centos6.5 安装Python3.6.0
首先安装python3.6可能使用的依赖 # yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel ...
- eas之根据bostype查找实体
select * from T_PF_BOSOBJECT;所有实体都有一个唯一的类型ID:BOSTYPEID,8位字符串,可切换到“源代码“页签,查找bostype标签里的值.这个ID的用途主要有: ...
- swift-正则验证手机号码
// 手机号验证正则表达式 func validateMobile(phoneNum:String)-> Bool { // 手机号以 13 14 15 18 开头 八个 \d 数字字符 let ...
- [luogu2329 SCOI2005] 栅栏(二分+搜索)
传送门 Solution 纯搜索80分,加二分90分,再补一个小剪枝满分qwq 真.小剪枝:如果下一个的需求和当前相同,那么不需要再次从头开始试(看代码就明白了233) Code #include & ...
- 项目部署到tomcat出错(tomcat运行时的JDK版本)
先展示一下错误,把项目部署到tomcat运行 出错原因 简单来说,就是执行代码的jdk版本 低于 编译的jdk版本 最后面的52.0是一种叫什么魔码,有各自对应的jdk版本. 其中52.0 对应的就是 ...
- HDU - 1043 - Eight / POJ - 1077 - Eight
先上题目: Eight Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- redis实现分页技术
声明:原博客在这里https://www.cnblogs.com/find-the-right-direction/p/8465011.html,谢谢哥们提供,尊重原创. 本人是在原有的springb ...
- ASP.NET--常用ORM框架
subsonic massive dapper 性能不错,接近原声的ADO.NET 这个是大家推荐的,stackoverflow用的就是这个框架 petapoco 这些都是ORM框架
- 拓扑排序---AOV图
对一个有向无环图(Directed Acyclic Graph简称DAG)G进行拓扑排序,是将G中全部顶点排成一个线性序列, 使得图中随意一对顶点u和v,若边(u,v)∈E(G),则u在线性序列中出如 ...
- 关于JOS 未对全部内存分页映射之前 物理地址映射问题的思考
在kern/pmap.c 里面会又以下这段代码,要知道boot_alloc只会分配线性地址,真正建立虚拟页和物理页映射关系的在后面的page_alloc. ////////////////////// ...