vtkPolyData 平移、旋转、缩放 vtkTransformPolyDataFilter

vtkPolyData 移动、旋转、平移,可以用 vtkTransformPolyDataFilter 实现,但相关参数怎么得到?

基本思想:
将vtkPolyData 放入Actor ,拖动Actor 使之到达 正确位置,然后获取actor 的位移,再作用到 vtkPolyData 上,就得到位移后的 vtkPolyData 数据了。
实现如下:

	std::string inputFilename1 =   "D:/receive/zhangjin/ray-x-ct/db.stl";
	vtkSmartPointer<vtkSTLReader> reader1 = vtkSmartPointer<vtkSTLReader>::New();
	reader1->SetFileName(inputFilename1.c_str());
	reader1->Update();

	std::string inputFilename2 = "D:/receive/xuxin/stl/J0.stl";
	vtkSmartPointer<vtkSTLReader> reader2 = vtkSmartPointer<vtkSTLReader>::New();
	reader2->SetFileName(inputFilename2.c_str());
	reader2->Update();

	vtkSmartPointer<vtkPolyDataMapper> mapper1 = vtkSmartPointer<vtkPolyDataMapper>::New();//将输入数据渲染多边形的几何数据
	mapper1->SetInputData(skinExtractor->GetOutput());//mapper的输入是boolFilter的输出
	mapper1->ScalarVisibilityOff();
	mapper1->Update();

	vtkSmartPointer<vtkPolyDataMapper> mapper2 = vtkSmartPointer<vtkPolyDataMapper>::New();//将输入数据渲染多边形的几何数据
	mapper2->SetInputData(reader1->GetOutput());//mapper的输入是boolFilter的输出
	mapper2->ScalarVisibilityOff();
	mapper2->Update();

	actor->SetMapper(mapper1);
	actorStl->SetMapper(mapper2);

// 获取 位移后的数据
				vtkSmartPointer<vtkTransform> pTransformSTL = vtkSmartPointer<vtkTransform>::New();
				//pTransformSTL->SetInput(actorStl->GetUserTransform());
				pTransformSTL->SetMatrix(actorStl->GetMatrix());
				pTransformSTL->Update();

				 vtkSmartPointer<vtkTransform> pTransform = vtkSmartPointer<vtkTransform>::New();
				// pTransform->SetInput(actor->GetUserTransform());
				 pTransform->SetMatrix(actor->GetMatrix());
				 pTransform->Update();

				vtkSmartPointer<vtkTransformPolyDataFilter> pTransformPolyDataFilterSTL = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
				pTransformPolyDataFilterSTL->SetInputData(actorStl->GetMapper()->GetInput());
				pTransformPolyDataFilterSTL->SetTransform(pTransformSTL);
				pTransformPolyDataFilterSTL->Update();

				vtkSmartPointer<vtkTransformPolyDataFilter> pTransformPolyDataFilter  = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
				pTransformPolyDataFilter->SetInputData(actor->GetMapper()->GetInput());
				pTransformPolyDataFilter->SetTransform(pTransform);
				pTransformPolyDataFilter->Update();
	
	// 最终得到数据
	pTransformPolyDataFilterSTL->GetOutPut();
    pTransformPolyDataFilter->GetOutPut();			

直接旋转

vtkTransformPolyDataFilter * Transform = vtkTransformPolyDataFilter::New(); 
Transform ->Translate(cx, cy, cz); 
Transform ->Scale(factor,factor,factor); 
Transform ->Translate(-cx, -cy, -cz); 
Transform ->Update();

 

```cpp

```cpp
 vtkSmartPointer<vtkTransform> pTransform = vtkSmartPointer<vtkTransform>::New();
    pTransform->RotateX(90);//x轴旋转90度
    pTransform->RotateZ(180);//z轴旋转180度
 

 

你可能感兴趣的:(VTK,vtkPolydata,transform)