vtkWiewer在MFC控件中显示,为嘛将VTK单独写成类作为窗口的数据成员就会提示被重定义了的错误???
作者:
小小蒟蒻
,
2021-06-15 02:32:33
,
所有人可见
,
阅读 518
#include <pcl/common/common_headers.h> // for pcl::PointCloud
#include <opencv2/opencv.hpp>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include <boost/thread/thread.hpp>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
using namespace pcl;
using namespace std;
class CVtkDlgDemo : public CDialogEx
{
public:
......
inline void ShowFrame()
{
if (m_cloudPtr->points.size() <= 0)
return;
m_viewer->addPointCloud(m_cloudPtr);
}
int LoadCloudFile(const char* pFileName);
public:
afx_msg void OnBnClickedOpencloud();
......
private:
vtkSmartPointer<vtkRenderWindow> m_win;
vtkSmartPointer<vtkRenderWindowInteractor> m_iren;
boost::shared_ptr<pcl::visualization::PCLVisualizer> m_viewer;
pcl::PointCloud<pcl::PointXYZ>::Ptr m_cloudPtr;
void AttachToWindow(HWND hWnd, int nWith, int nHeight);
}
void CVtkDlgDemo::AttachToWindow(HWND hWnd, int nWith, int nHeight)
{
m_iren = vtkRenderWindowInteractor::New(); //重新申请地址
m_win = m_viewer->getRenderWindow(); //获取viewer的句柄
m_win->SetSize(nWith, nHeight); //将viewer大小设置为图像控件大小
m_win->SetParentId(hWnd); //将vtk窗口附加到MFC窗口中
m_viewer->resetCamera();
m_iren->SetRenderWindow(m_win);
m_viewer->createInteractor(); //初始化设置为false,该处重新创建PCL风格的Interactor
m_win->Render();
}
int CVtkDlgDemo::LoadCloudFile(const char* pFileName)
{
if (pcl::io::loadPCDFile<pcl::PointXYZ>(pFileName, *m_cloudPtr) == -1) //* 读入PCD格式的文件,如果文件不存在,返回-1
{
PCL_ERROR("Couldn't read file cloud.pcd \n"); //文件不存在时,返回错误,终止程序。
return (0);
}
return (1);
}
BOOL CVtkDlgDemo::OnInitDialog()
{
......
// TODO: Add extra initialization here
CRect rc;
auto pFrame = GetDlgItem(IDC_FRAME);
pFrame->GetClientRect(&rc); //获取图像控件的实际大小
AttachToWindow(pFrame->GetSafeHwnd(), rc.Width(), rc.Height());
.....
}
void CVtkDlgDemo::OnBnClickedOpencloud()
{
// TODO: Add your control notification handler code here
if (!LoadCloudFile("cloud.pcd"))
return;
ShowFrame();
}
竟然看见做点云的
对,放暑假了。学点新东西。好多不懂得
看看头文件中是引用了哪些其他文件,可能是重复引用了