ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

vtk 用圆柱和半个圆柱裁剪球体

2020-12-02 13:05:56  阅读:560  来源: 互联网

标签:clipper 圆柱 cylinder vtk 裁剪 actor clipper2 New include



#pragma once
#include "vtkAutoInit.h" 
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);


#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCylinder.h"
#include "vtkPlane.h"
#include "vtkImplicitBoolean.h"
#include "vtkPolyDataMapper.h"
#include "vtkSphereSource.h"
#include "vtkProperty.h"
#include "vtkClipPolyData.h"
#include "vtkTransformPolyDataFilter.h"
#include "vtkTransform.h"
#include "vtkInteractorStyleTrackballCamera.h"

int main()
{
    vtkSphereSource* sphere = vtkSphereSource::New();
    sphere->SetCenter(0, 0, 0);
    sphere->SetRadius(10);
    sphere->SetThetaResolution(40);
    sphere->SetPhiResolution(40);

    vtkCylinder* cylinder = vtkCylinder::New();//圆柱
    cylinder->SetCenter(0, 0, 0);
    cylinder->SetRadius(3);

    vtkPlane* vPlane = vtkPlane::New();//横截面
    vPlane->SetOrigin(0, 0, 0);
    vPlane->SetNormal(0, -1, 0);

    vtkImplicitBoolean* cuted_cylinder = vtkImplicitBoolean::New();
    cuted_cylinder->SetOperationTypeToIntersection();
    cuted_cylinder->AddFunction(cylinder);
    cuted_cylinder->AddFunction(vPlane);

    vtkClipPolyData* clipper = vtkClipPolyData::New();
    clipper->SetInputConnection(sphere->GetOutputPort());
    clipper->SetClipFunction(cylinder);
    clipper->GenerateClipScalarsOn();
    clipper->GenerateClippedOutputOn();
    clipper->SetValue(0.5);

    vtkTransform* transform = vtkTransform::New();
    transform->Translate(7, 0, 0);
    vtkTransformPolyDataFilter* filter = vtkTransformPolyDataFilter::New();
    filter->SetInputConnection(clipper->GetOutputPort());
    filter->SetTransform(transform);
    vtkClipPolyData* clipper2 = vtkClipPolyData::New();
    clipper2->SetInputConnection(filter->GetOutputPort());
    clipper2->SetClipFunction(cuted_cylinder);
    clipper2->GenerateClipScalarsOn();
    clipper2->GenerateClippedOutputOn();
    clipper2->SetValue(0.5);

    vtkPolyDataMapper* map = vtkPolyDataMapper::New();
    map->SetInputConnection(clipper2->GetOutputPort());
    map->ScalarVisibilityOff();

    vtkActor* actor = vtkActor::New();
    actor->SetMapper(map);
    actor->GetProperty()->SetColor(0, 1, 1);
    //actor->GetProperty()->SetAmbientColor(0.4,0.5,0.6);
    //actor->GetProperty()->SetDiffuseColor(0.8,0.6,0.2);
    actor->RotateX(40);

    vtkRenderer* ren = vtkRenderer::New();
    vtkRenderWindow* renWin = vtkRenderWindow::New();
    renWin->AddRenderer(ren);

    vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);

    ren->AddActor(actor);
    ren->SetBackground(1, 1, 1);
    renWin->SetSize(450, 450);

    vtkInteractorStyleTrackballCamera* style = vtkInteractorStyleTrackballCamera::New();
    iren->SetInteractorStyle(style);

    iren->Initialize();
    renWin->Render();

    iren->Start();
}

标签:clipper,圆柱,cylinder,vtk,裁剪,actor,clipper2,New,include
来源: https://blog.csdn.net/qq_41023026/article/details/110477740

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有