**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
随机推荐
- eas之日志文件夹
F:\ThisIs_MyWork\kingdee\eas\server\profiles\server1\logs 服务端的日志文件夹 F:\ThisIs_MyWork\kingdeecusto ...
- eas之新建窗口
public void actionObjectProp_actionPerformed(ActionEvent e) throws Exception { UIContex ...
- Innodb 中的事务隔离级别和锁的关系
转自:https://tech.meituan.com/innodb-lock.html 前言: 我们都知道事务的几种性质,数据库为了维护这些性质,尤其是一致性和隔离性,一般使用加锁这种方式.同时数据 ...
- 构造函数和初始化表、this指针与常函数、析构函数、拷贝构造与拷贝赋值(day05)
十四 构造函数和初始化表 ... 初始化表 )语法形式 class 类名{ 类名(形参表):成员变量1(初值),...{} }; )必须要使用初始化表的场景 -->如果有类 类型的成员变量,而该 ...
- Llinux,NFS服务搭建(文件共享)
NFS配置文件权限参数说明(/etc/exports) 1.rw :表示可读写权限. 2.ro :表示只读权限. 3.sync :请求或写入数据时,数据同步写入到NFS Server的硬盘后才返回.( ...
- Zend Studio快捷键汇总
应用场景 快捷键 功能 查看快捷键 ctrl+shift+l 显示所有快捷键列表 查看和修改快捷键 打开Window->Preferences->General->keys 修改 ...
- phpcms 电脑手机合并
电脑手机端 ========================== <script type="text/javascript"> function browserRed ...
- Visifire实现统计图
/// <summary> /// 柱形图 /// </summary> public static Chart InitCompareChart(string fundNam ...
- [bzoj2049][Sdoi2008]Cave 洞穴勘测_LCT
Cave 洞穴勘测 bzoj-2049 Sdoi-2008 题目大意:维护一个数据结构,支持森林中加边,删边,求两点连通性.n个点,m个操作. 注释:$1\le n\le 10^4$,$1\le m\ ...
- C#编程中,在页面上如何弹出确认删除对话框
对于页面完成一个操作后,弹出一个对话框提示是否“操作成功”.举例如下:Response.Write("<script>alert('删除成功!')</script>& ...