用户名  找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1223|回复: 8

[VTK] VTK例子15-KlineBottle (容器)

[复制链接]

291

主题

401

回帖

2545

积分

管理员

积分
2545

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2015-12-5 17:53:50 | 显示全部楼层 |阅读模式
KlineBottle (容器)

#include "stdafx.h"

#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCellArray.h"
#include "vtkDebugLeaks.h"
#include "vtkPlanes.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkPoints.h"
#include "vtkSphereSource.h"

#include "vtkLoopSubdivisionFilter.h"
#include "vtkDataSetMapper.h"
#include "vtkLODActor.h"
#include "vtkProperty.h"
#include "vtkFeatureEdges.h"

void main(  )
{
  vtkRenderer *ren1 = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(ren1);
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);

    vtkPoints *points=vtkPoints::New();
         points->InsertNextPoint( 0 ,-16, 0 );
         points->InsertNextPoint( 0, 0 ,-14 );
         points->InsertNextPoint( 0, 0 ,14 );
         points->InsertNextPoint( 14, 0 ,0 );
         points->InsertNextPoint( 10, 20 ,-10 );
         points->InsertNextPoint( 10, 20 ,10 );
         points->InsertNextPoint( 10, -20 ,-10 );
         points->InsertNextPoint( 10 ,-20 ,10 );
         points->InsertNextPoint( -10, -20 ,-10 );
         points->InsertNextPoint( -10, -20, 10 );
         points->InsertNextPoint( -10, 20, -10 );
         points->InsertNextPoint( -10, 20, 10 );
         points->InsertNextPoint( -2, 27, 0 );
         points->InsertNextPoint( 0, 27, 2 );
         points->InsertNextPoint( 0, 27, -2 );
         points->InsertNextPoint( 2,27, 0 );
         points->InsertNextPoint( -14 ,4, -1 );
         points->InsertNextPoint( -14 ,3, 0 );
         points->InsertNextPoint( -14 ,5, 0 );
         points->InsertNextPoint( -14 ,4, 1 );
         points->InsertNextPoint( -1 ,38, -2 );
         points->InsertNextPoint( -1 ,38, 2 );
         points->InsertNextPoint( 2 ,35 ,-2 );
         points->InsertNextPoint( 2 ,35, 2 );
         points->InsertNextPoint( 17, 42 ,0 );
         points->InsertNextPoint( 15 ,40, 2 );
         points->InsertNextPoint( 15 ,39, -2 );
         points->InsertNextPoint( 13 ,37, 0 );
         points->InsertNextPoint( 19 ,-2, -2 );
         points->InsertNextPoint( 19, -2, 2 );
         points->InsertNextPoint( 15, 2 ,-2 );
         points->InsertNextPoint( 15 ,2, 2 );

    vtkCellArray *faces=vtkCellArray::New();
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 3);
         faces->InsertCellPoint( 4);
         faces->InsertCellPoint( 5);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 3);
         faces->InsertCellPoint( 5);
         faces->InsertCellPoint( 7);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 3);
         faces->InsertCellPoint( 7);
         faces->InsertCellPoint( 6);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 3);
         faces->InsertCellPoint( 6);
         faces->InsertCellPoint( 4);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 0);
         faces->InsertCellPoint( 6);
        faces->InsertCellPoint( 7);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 0);
         faces->InsertCellPoint( 7);
         faces->InsertCellPoint( 9);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 0);
         faces->InsertCellPoint( 9);
         faces->InsertCellPoint( 8);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 0);
         faces->InsertCellPoint( 8);
         faces->InsertCellPoint( 6);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 1);
         faces->InsertCellPoint( 4);
         faces->InsertCellPoint( 6);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 1);
         faces->InsertCellPoint( 6);
         faces->InsertCellPoint( 8);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 1);
         faces->InsertCellPoint( 8);
         faces->InsertCellPoint( 10);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 1);
         faces->InsertCellPoint( 10);
         faces->InsertCellPoint( 4);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 2);
         faces->InsertCellPoint( 11);
         faces->InsertCellPoint( 9);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 2);
         faces->InsertCellPoint( 9);
         faces->InsertCellPoint( 7);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 2);
         faces->InsertCellPoint( 7);
         faces->InsertCellPoint( 5);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 2);
         faces->InsertCellPoint( 5);
         faces->InsertCellPoint( 11);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 4);
         faces->InsertCellPoint( 15);
         faces->InsertCellPoint( 5);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 4);
         faces->InsertCellPoint( 14);
         faces->InsertCellPoint( 15);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 5);
         faces->InsertCellPoint( 13);
         faces->InsertCellPoint( 11);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 5);
         faces->InsertCellPoint( 15);
         faces->InsertCellPoint( 13);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 11);
         faces->InsertCellPoint( 12);
         faces->InsertCellPoint( 10);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 11);
         faces->InsertCellPoint( 13);
         faces->InsertCellPoint( 12);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 10);
         faces->InsertCellPoint( 14);
         faces->InsertCellPoint( 4);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 10);
         faces->InsertCellPoint( 12);
         faces->InsertCellPoint( 14);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 8);
         faces->InsertCellPoint( 17);
         faces->InsertCellPoint( 16);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 8);
         faces->InsertCellPoint( 9);
         faces->InsertCellPoint( 17);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 9);
         faces->InsertCellPoint( 19);
         faces->InsertCellPoint( 17);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 9);
         faces->InsertCellPoint( 11);
         faces->InsertCellPoint( 19);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 11);
         faces->InsertCellPoint( 18);
         faces->InsertCellPoint( 19);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 11);
         faces->InsertCellPoint( 10);
         faces->InsertCellPoint( 18);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 10);
         faces->InsertCellPoint( 16);
         faces->InsertCellPoint( 18);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 10);
         faces->InsertCellPoint( 8);
         faces->InsertCellPoint( 16);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 13);
         faces->InsertCellPoint( 21);
         faces->InsertCellPoint( 12);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 12);
         faces->InsertCellPoint( 21);
         faces->InsertCellPoint( 20);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 12);
         faces->InsertCellPoint( 20);
         faces->InsertCellPoint( 14);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 14);
         faces->InsertCellPoint( 20);
         faces->InsertCellPoint( 22);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 14);
         faces->InsertCellPoint( 22);
         faces->InsertCellPoint( 15);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 15);
         faces->InsertCellPoint( 22);
         faces->InsertCellPoint( 23);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 15);
         faces->InsertCellPoint( 23);
         faces->InsertCellPoint( 13);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 13);
         faces->InsertCellPoint( 23);
         faces->InsertCellPoint( 21);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 21);
         faces->InsertCellPoint( 25);
         faces->InsertCellPoint( 24);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 21);
         faces->InsertCellPoint( 24);
         faces->InsertCellPoint( 20);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 20);
         faces->InsertCellPoint( 24);
         faces->InsertCellPoint( 26);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 20);
         faces->InsertCellPoint( 26);
         faces->InsertCellPoint( 22);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 22);
         faces->InsertCellPoint( 26);
         faces->InsertCellPoint( 27);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 22);
         faces->InsertCellPoint( 27);
         faces->InsertCellPoint( 23);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 23);
         faces->InsertCellPoint( 27);
         faces->InsertCellPoint( 25);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 23);
         faces->InsertCellPoint( 25);
         faces->InsertCellPoint( 21);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 25);
         faces->InsertCellPoint( 29);
         faces->InsertCellPoint( 24);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 24);
         faces->InsertCellPoint( 29);
         faces->InsertCellPoint( 28);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 24);
         faces->InsertCellPoint( 28);
         faces->InsertCellPoint( 26);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 26);
         faces->InsertCellPoint( 28);
         faces->InsertCellPoint( 30);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 26);
         faces->InsertCellPoint( 30);
         faces->InsertCellPoint( 27);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 27);
         faces->InsertCellPoint( 30);
         faces->InsertCellPoint( 31);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 27);
         faces->InsertCellPoint( 31);
         faces->InsertCellPoint( 25);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 25);
         faces->InsertCellPoint( 31);
         faces->InsertCellPoint( 29);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 29);
         faces->InsertCellPoint( 19);
         faces->InsertCellPoint( 17);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 29);
         faces->InsertCellPoint( 17);
         faces->InsertCellPoint( 28);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 28);
         faces->InsertCellPoint( 17);
         faces->InsertCellPoint( 16);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 28);
         faces->InsertCellPoint( 16);
         faces->InsertCellPoint( 30);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 30);
         faces->InsertCellPoint( 16);
         faces->InsertCellPoint( 18);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 30);
         faces->InsertCellPoint( 18);
         faces->InsertCellPoint( 31);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 31);
         faces->InsertCellPoint( 18);
         faces->InsertCellPoint( 19);
         faces->InsertNextCell(3);
         faces->InsertCellPoint( 31);
         faces->InsertCellPoint( 19);
         faces->InsertCellPoint( 29);


    vtkPolyData *model=vtkPolyData::New();
      model-> SetPolys( faces);
      model-> SetPoints( points);


    //vtkButterflySubdivisionFilter subdivide
    vtkLoopSubdivisionFilter *subdivide=vtkLoopSubdivisionFilter::New();
      subdivide-> SetInput( model);
      subdivide-> SetNumberOfSubdivisions( 4);

    vtkDataSetMapper *mapper=vtkDataSetMapper::New();
       mapper-> SetInputConnection (subdivide ->GetOutputPort());

    vtkLODActor *rose=vtkLODActor::New();
         rose-> SetMapper( mapper);
         vtkProperty *backP=vtkProperty::New();
           backP-> SetDiffuseColor (1 ,1 ,.3);
         rose-> SetBackfaceProperty( backP);
         rose-> GetProperty() ->SetDiffuseColor( 1 ,.4 ,.3);
         rose-> GetProperty() ->SetSpecular( .4);
         rose-> GetProperty() ->SetDiffuse( .8);
         rose-> GetProperty() ->SetSpecularPower( 40);

    vtkFeatureEdges *fe=vtkFeatureEdges::New();
      fe-> SetInputConnection (subdivide-> GetOutputPort());
      fe-> SetFeatureAngle( 100);

    vtkPolyDataMapper *feMapper=vtkPolyDataMapper::New();
      feMapper-> SetInputConnection (fe ->GetOutputPort());

    vtkActor *edges=vtkActor::New();
      edges-> SetMapper( feMapper);

    ren1-> AddActor( rose);
    ren1-> AddActor (edges);

    ren1-> SetBackground (0.1, 0.2, 0.4);
    renWin-> SetSize (600, 600);

    ren1->ResetCamera();
    ren1->GetActiveCamera()->Zoom (4.5);
    ren1->GetActiveCamera()->Azimuth( -90);
    ren1-> ResetCameraClippingRange();
    iren-> Initialize();

  renWin->Render();
  iren->Start();
  // Clean up
  renWin->Delete();
  iren->Delete();


}
15.png
回复

举报

110

主题

428

回帖

1426

积分

金牌会员

积分
1426

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2016-5-11 01:35:24 | 显示全部楼层
大哥谢了
回复

举报

0

主题

401

回帖

804

积分

高级会员

积分
804

最佳新人

发表于 2016-5-14 10:38:11 | 显示全部楼层
感谢分享感谢分享感谢分享
回复

举报

149

主题

457

回帖

1601

积分

版主

积分
1601

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2016-5-16 12:25:33 | 显示全部楼层
看看,学学
回复

举报

15

主题

420

回帖

1119

积分

版主

积分
1119

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2016-5-16 18:28:12 | 显示全部楼层
看看,学学
回复

举报

26

主题

411

回帖

1112

积分

版主

积分
1112

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2016-5-18 05:11:49 | 显示全部楼层
大哥谢了
回复

举报

1

主题

434

回帖

1086

积分

版主

积分
1086

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2016-5-18 17:55:23 | 显示全部楼层
留个脚印。。。。。。
回复

举报

135

主题

405

回帖

1457

积分

版主

积分
1457

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2016-5-19 00:01:44 | 显示全部楼层
留个脚印。。。。。。
回复

举报

0

主题

391

回帖

781

积分

高级会员

积分
781

最佳新人

发表于 2016-5-23 05:13:38 | 显示全部楼层
学习学习!
回复

举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|关于我们|医维基|网站地图|Archiver|手机版|医疗之家 ( 沪ICP备2023001278号-1 )

GMT+8, 2025-4-6 23:29 , Processed in 0.753525 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表