2013-04-27 87 views

回答

1

這是球體的一半。翻轉飛機(取消常規)以獲得另一半。

#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})