效果图:
示例:
vtkSmartPointer<vtkQuadric> quadric =
vtkSmartPointer<vtkQuadric>::New();
quadric->SetCoefficients( 0.5,1,.2,0,.1,0,0,.2,0,0);
vtkSmartPointer<vtkSampleFunction> sample =
vtkSmartPointer<vtkSampleFunction>::New();
sample->SetSampleDimensions(20,20,20);
sample->SetImplicitFunction(quadric);
sample->ComputeNormalsOff();
vtkSmartPointer<vtkImplicitDataSet> dataset =
vtkSmartPointer<vtkImplicitDataSet>::New();
dataset->SetDataSet(sample->GetOutput());
vtkSmartPointer<vtkImplicitWindowFunction> window =
vtkSmartPointer<vtkImplicitWindowFunction>::New();
window->SetImplicitFunction(dataset);
window->SetWindowRange(0.3,0.8);
vtkSmartPointer<vtkClipVolume> clip =
vtkSmartPointer<vtkClipVolume>::New();
clip->SetInputConnection(sample->GetOutputPort());
clip->SetClipFunction(window);
clip->SetValue(0.0);
clip->GenerateClippedOutputOff();
vtkSmartPointer<vtkDataSetMapper> clipMapper =
vtkSmartPointer<vtkDataSetMapper>::New();
clipMapper->SetInputConnection(clip->GetOutputPort());
clipMapper->ScalarVisibilityOff();
vtkSmartPointer<vtkActor> clipActor =
vtkSmartPointer<vtkActor>::New();
clipActor->SetMapper(clipMapper);
clipActor->GetProperty()->SetColor(.8,.4,.4);
vtkSmartPointer<vtkOutlineFilter> outline =
vtkSmartPointer<vtkOutlineFilter>::New();
outline->SetInputConnection(sample->GetOutputPort());
vtkSmartPointer<vtkPolyDataMapper> outlineMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
outlineMapper->SetInputConnection(outline->GetOutputPort());
vtkSmartPointer<vtkActor> outlineActor =
vtkSmartPointer<vtkActor>::New();
outlineActor->SetMapper(outlineMapper);
outlineActor->GetProperty()->SetColor(0,0,0);
vtkSmartPointer<vtkRenderer> render =
vtkSmartPointer<vtkRenderer>::New();
render->SetBackground(1,1,1);
render->AddActor(outlineActor);
render->AddActor(clipActor);
render->GetActiveCamera()->SetParallelProjection(1);
render->ResetCamera();
vtkSmartPointer<vtkRenderWindow> renwindow =
vtkSmartPointer<vtkRenderWindow>::New();
renwindow->SetMultiSamples(0);
renwindow->AddRenderer(render);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renwindow);
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
renderWindowInteractor->SetInteractorStyle(style);
renwindow->Render();
renderWindowInteractor->Start();