2

我的想法很简单

给定一个 vtk polydata和一个 vtk plane,得到两个不同的 polydata。这个多数据是原始多数据的划分

4

1 回答 1

2

这是球体的一半。翻转飞机(否定正常)以获得另一半。

#include "vtkActor.h"
#include "vtkClipPolyData.h"
#include "vtkPlane.h"
#include "vtkInteractorObserver.h"
#include "vtkInteractorStyleSwitch.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkSphereSource.h"
using namespace std;
int main(int argc, char ** argv) {
  vtkSmartPointer<vtkSphereSource> sphere =
    vtkSmartPointer<vtkSphereSource>::New();
  vtkSmartPointer<vtkClipPolyData> clip =
    vtkSmartPointer<vtkClipPolyData>::New();
  clip->SetValue(0);
  clip->GenerateClippedOutputOn();
  clip->SetInputConnection(sphere->GetOutputPort());
  vtkSmartPointer<vtkPlane> plane =
    vtkSmartPointer<vtkPlane>::New();
  //plane->SetNormal(-1.0, 0.0, 0.0);
  plane->SetNormal(1.0, 0.0, 0.0);
  clip->SetClipFunction (plane);
  vtkSmartPointer<vtkPolyDataMapper> polyDataMapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  polyDataMapper->SetInputConnection(clip->GetOutputPort());
  vtkSmartPointer<vtkActor> actor =
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(polyDataMapper);
  vtkSmartPointer<vtkRenderWindow> renderWindow =
    vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->SetSize(800,600);
  renderWindow->SetWindowName("VTK");
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);
  vtkSmartPointer<vtkRenderer> renderer =
    vtkSmartPointer<vtkRenderer>::New();
  renderer->AddActor(actor);
  renderWindow->AddRenderer(renderer);
  vtkInteractorStyleSwitch * styleSwitch
    = vtkInteractorStyleSwitch::SafeDownCast(
        renderWindowInteractor->GetInteractorStyle());
  if (styleSwitch)
    styleSwitch->SetCurrentStyleToTrackballCamera();
  renderWindow->Render();
  renderWindowInteractor->Start();
}

CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)
project(V)
set(VTK_DIR "VTK_DIR-NOTFOUND"
  CACHE PATH "location of VTK libraries" )
set(CMAKE_BUILD_TYPE debug)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
add_executable(clip clip.cxx)
target_link_libraries(clip ${VTK_LIBRARIES})
于 2013-04-29T02:44:04.293 回答