2. 将这些polydata通过vtkImplicitPolyData过滤后 丢给vtkClipPolydata,作为clippolydata的裁剪函数让clippolydata做裁剪操作
vtkOBJReader *wavefront = vtkOBJReader::New();
wavefront->SetFileName("E:\\data\\Viewpoint\\cow.obj");
//我在windows平台
wavefront->Update();
vtkPolyDataMapper *cowMapper = vtkPolyDataMapper::New();
cowMapper->SetInput(wavefront->GetOutput());
vtkActor *cow = vtkActor::New();
cow->SetMapper(cowMapper);
ren->AddActor(cow);
//2. 创建一个圆柱体,先变换,再三角化(似乎是必须的!)
vtkCylinderSource *cylinderB = vtkCylinderSource::New();
cylinderB->SetRadius(0.2);
cylinderB->SetResolution(21);
cylinderB->CappingOn();
vtkTransform *trans = vtkTransform::New();
trans->Translate(5.1, 2.0, 0.0);
trans->Scale(0.5, 0.5, 0.5);
trans->RotateZ(90);
vtkTransformPolyDataFilter *tf = vtkTransformPolyDataFilter::New();
tf->SetInput(cylinderB->GetOutput());
tf->SetTransform(trans);
vtkTriangleFilter *triangle = vtkTriangleFilter::New();
triangle->SetInput(tf->GetOutput());
vtkPolyDataNormals *norm = vtkPolyDataNormals::New();
norm->SetInput(triangle->GetOutput());
vtkPolyDataMapper *CylinderBMapper = vtkPolyDataMapper::New();
CylinderBMapper->SetInput(norm->GetOutput());
// Append
vtkAppendPolyData *append = vtkAppendPolyData::New();
append->AddInput(CylinderBMapper->GetInput());
vtkActor *CylinderBActor = vtkActor::New();
CylinderBActor->SetMapper( CylinderBMapper );
CylinderBActor->GetProperty()->SetColor(0,1,0);
//3.将圆柱体转化为implicitpolydata 。
vtkImplicitPolyData *polyToImplicitDataB = vtkImplicitPolyData::New();
polyToImplicitDataB->SetTolerance(0.5);
polyToImplicitDataB->SetInput(append->GetOutput());
//4.我要裁剪!
vtkClipPolyData *clipper = vtkClipPolyData::New();
clipper->SetInput((vtkPolyData *)cow->GetMapper()->GetInput()); //我要裁剪谁?牛是吧,拿来
clipper->SetClipFunction(polyToImplicitDataB); //你要裁剪不是要方程么?也拿来
clipper->InsideOutOff();
clipper->GenerateClipScalarsOn();
//5.剪好了 走流水线去!
vtkPolyDataMapper *newmapper = vtkPolyDataMapper::New();
newmapper->SetInput(clipper->GetOutput());
cow->SetMapper(newmapper);
ren->AddActor(CylinderBActor);
ren->GetActiveCamera()->Azimuth(50);
ren->ResetCamera();
//done!
renWin->Render();
结果图:
http://www.cnblogs.com/hawking81/archive/2011/09/22/2185265.html