VTK:图形基本操作进阶——点云配准技术（LandMark标记点算法和坐标系显示方法）

2.LandMark配准实验

VTKLandMarkTransform实现了片几点配准算法，使得两个点集在配准后平均距离最小。通过SetSourceLandmarks()设置源标记点的位置，SetTargetLandmarks()函数设计目标标记点的位置。需要注意的是源标记点集和目标标记点集序号要对应。

#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkInteractionStyle);

#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkLandmarkTransform.h>
#include <vtkPolyData.h>
#include <vtkVertexGlyphFilter.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkAxesActor.h>
//研究一下坐标系显示位置
#include <vtkOrientationMarkerWidget.h>
int main()
{
vtkSmartPointer<vtkPoints> sourcePoints =
vtkSmartPointer<vtkPoints>::New();
double sourcePoint1[3] = { 0.5, 0, 0 };
sourcePoints->InsertNextPoint(sourcePoint1);
double sourcePoint2[3] = { 0, 0.5, 0 };
sourcePoints->InsertNextPoint(sourcePoint2);
double sourcePoint3[3] = { 0, 0, 0.5 };
sourcePoints->InsertNextPoint(sourcePoint3);

vtkSmartPointer<vtkPoints> targetPoints =
vtkSmartPointer<vtkPoints>::New();
double targetPoint1[3] = { 0.0, 0.0, 0.55 };
targetPoints->InsertNextPoint(targetPoint1);
double targetPoint2[3] = { 0.0, 0.55, 0.0 };
targetPoints->InsertNextPoint(targetPoint2);
double targetPoint3[3] = { -0.55, 0.0, 0.0 };
targetPoints->InsertNextPoint(targetPoint3);
//利用Landmark算法求变换矩阵
vtkSmartPointer<vtkLandmarkTransform> landmarkTransform =
vtkSmartPointer<vtkLandmarkTransform>::New();
landmarkTransform->SetSourceLandmarks(sourcePoints);
landmarkTransform->SetTargetLandmarks(targetPoints);
landmarkTransform->SetModeToRigidBody(); //执行刚体配准
landmarkTransform->Update();

//构造PolyData类型 进行图形可视化
vtkSmartPointer<vtkPolyData> source =
vtkSmartPointer<vtkPolyData>::New();
source->SetPoints(sourcePoints);
vtkSmartPointer<vtkPolyData> target =
vtkSmartPointer<vtkPolyData>::New();
target->SetPoints(targetPoints);
//
vtkSmartPointer<vtkVertexGlyphFilter> sourceGlyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
sourceGlyphFilter->SetInputData(source);
sourceGlyphFilter->Update();

vtkSmartPointer<vtkVertexGlyphFilter> targetGlyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
targetGlyphFilter->SetInputData(target);
targetGlyphFilter->Update();

//源数据施加配准变换矩阵
vtkSmartPointer<vtkTransformPolyDataFilter> transformFilter =
vtkSmartPointer<vtkTransformPolyDataFilter>::New();
transformFilter->SetInputData(sourceGlyphFilter->GetOutput());
transformFilter->SetTransform(landmarkTransform);
transformFilter->Update();
//
vtkSmartPointer<vtkPolyDataMapper> sourceMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
sourceMapper->SetInputConnection(sourceGlyphFilter->GetOutputPort());

vtkSmartPointer<vtkActor> sourceActor =
vtkSmartPointer<vtkActor>::New();
sourceActor->SetMapper(sourceMapper);
sourceActor->GetProperty()->SetColor(1, 1, 0);
sourceActor->GetProperty()->SetPointSize(10);

vtkSmartPointer<vtkPolyDataMapper> targetMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
targetMapper->SetInputConnection(targetGlyphFilter->GetOutputPort());

vtkSmartPointer<vtkActor> targetActor =
vtkSmartPointer<vtkActor>::New();
targetActor->SetMapper(targetMapper);
targetActor->GetProperty()->SetColor(0, 1, 0);
targetActor->GetProperty()->SetPointSize(10);

vtkSmartPointer<vtkPolyDataMapper> solutionMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
solutionMapper->SetInputConnection(transformFilter->GetOutputPort());

vtkSmartPointer<vtkActor> solutionActor =
vtkSmartPointer<vtkActor>::New();
solutionActor->SetMapper(solutionMapper);
solutionActor->GetProperty()->SetColor(1, 0, 0);
solutionActor->GetProperty()->SetPointSize(10);

vtkSmartPointer<vtkRenderer> render =
vtkSmartPointer<vtkRenderer>::New();
render->SetBackground(0, 0, 0);

vtkSmartPointer<vtkRenderWindow> rw =
vtkSmartPointer<vtkRenderWindow>::New();
rw->SetSize(480, 480);
rw->SetWindowName("Regisration by Landmark");
//设置坐标系显示功能
vtkSmartPointer<vtkAxesActor> axes =
vtkSmartPointer<vtkAxesActor>::New();
axes->SetScale(10);

vtkSmartPointer<vtkRenderWindowInteractor> rwi =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
rwi->SetRenderWindow(rw);
/************************************************************/
vtkSmartPointer<vtkOrientationMarkerWidget> widget =
vtkSmartPointer<vtkOrientationMarkerWidget>::New();
widget->SetOutlineColor(0.9300, 0.5700, 0.1300);
widget->SetOrientationMarker(axes);
widget->SetInteractor(rwi); //加入鼠标交互
widget->SetViewport(0.0, 0.0, 0.3, 0.3);  //设置显示位置
widget->SetEnabled(1);
widget->InteractiveOn();//开启鼠标交互
/************************************************************/
render->ResetCamera();
rw->Render();
rwi->Initialize();
rwi->Start();

return 0;
}



vtkVertexGliphFilter类显示点集！VTKTransformPolyDataFilter用来对源点标记点进行变换来显示配准后的点集，SetTransform（）函数直接设置为vtkLandmarkTransform的变换结果。

2.VTKLandmarkTransform类

VTKLandmarkTraTransform类的使用比较简单，只要设定源标记点和目标标记点。SetModeToRigidBody（）函数用于设置其配准变换类型为刚体变换，仅包括简单的平移和转换（6个自由的角度）。此外还有一个更为钢钒应用的函数——SetModeToSimilarity，设置为相似变换，包括平移、旋转和放缩变换（7个自由度）。以及SetModeToAffine()函数设置放射变换。默认情况，就采用相似变化进行配准。

3.vtkAxesActor类

vtkSmartPointer<vtkAxesActor> axes =
vtkSmartPointer<vtkAxesActor>::New();
axes->SetScale(10);

• 0
点赞
• 7
收藏
觉得还不错? 一键收藏
• 打赏
• 0
评论
04-12

“相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。