2

私の考えは簡単です:

vtk polydataと vtk planeが与えられた場合、2 つの異なる 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 に答える