vtk对polydata的bool运算
1.vtk可以对implicit data运算,通常的polydata需要转化为implicit 进⾏运算。
经查,⽹上有vtkImplicitPolyData类可以将polydata转化。
2. 将这些polydata通过vtkImplicitPolyData过滤后丢给vtkClipPolydata,作为clippolydata的裁剪函数让clippolydata做裁剪操作
3.clipdata还需要原始的polydata,丢给他。
yesi4.把裁剪结果丢给polydatamapper。
5.⾛流⽔线
完事。
上段关键代码:
// 1.读进来⼀个⽜的模型,丢到renderer⾥
vtkOBJReader *wavefront = vtkOBJReader::New();
wavefront->SetFileName("E:\\data\\Viewpoint\\cow.obj"); //我在windows平台初中英语作文写作技巧
wavefront->Update();
vtkPolyDataMapper *cowMapper = vtkPolyDataMapper::New();
cowMapper->SetInput(wavefront->GetOutput());aux
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();father的含义
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()); //我要裁剪谁?⽜是吧,拿来
26个英文字母表clipper->SetClipFunction(polyToImplicitDataB); //你要裁剪不是要⽅程么?也拿来 clipper->InsideOutOff();
clipper->GenerateClipScalarsOn();
//5.剪好了⾛流⽔线去!
vtkPolyDataMapper *newmapper = vtkPolyDataMapper::New();
newmapper->SetInput(clipper->GetOutput());
cow->SetMapper(newmapper);
剑十五
ren->AddActor(CylinderBActor);
全国大学生英语竞赛c类试题
ren->GetActiveCamera()->Azimuth(50);
ren->RetCamera();
//done!
renWin->Render();
结果图: