找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 868|回复: 5

[VTK] VTK例子7-样条曲线KclosedSplines

[复制链接]

291

主题

401

回帖

2545

积分

管理员

积分
2545

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

发表于 2015-12-4 22:28:56 | 显示全部楼层 |阅读模式
样条曲线KclosedSplines
#include "stdafx.h"

#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkPolyData.h"
#include "vtkBoxWidget.h"
#include "vtkKochanekSpline.h"
#include "vtkCardinalSpline.h"
#include "vtkPoints.h"
#include "stdio.h"
#include <time.h>
#include <vtkGlyph3D.h>
#include <vtkProperty.h>
#include <vtkCellArray.h>
#include <vtkTubeFilter.h>
#include <vtkPolyLine.h>

void main()
{

  srand(time(NULL)) ;

//  rand()/RAND_MAX;//    0 - RAND_MAX
  vtkRenderer *ren = vtkRenderer::New();
  vtkRenderWindow *renWindow = vtkRenderWindow::New();
    renWindow->AddRenderer(ren);
  renWindow->SetSize( 600, 600 );

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

  int numberOfInputPoints = 30;

vtkKochanekSpline *aKSplineX=vtkKochanekSpline::New();
aKSplineX-> ClosedOn();
vtkKochanekSpline *aKSplineY=vtkKochanekSpline::New();
aKSplineY-> ClosedOn();
vtkKochanekSpline *aKSplineZ=vtkKochanekSpline::New();
aKSplineZ-> ClosedOn();

vtkCardinalSpline *aCSplineX=vtkCardinalSpline::New();
aCSplineX-> ClosedOn();
vtkCardinalSpline *aCSplineY=vtkCardinalSpline::New();
aCSplineY-> ClosedOn();
vtkCardinalSpline *aCSplineZ=vtkCardinalSpline::New();
aCSplineZ-> ClosedOn();

//# add some points
vtkPoints *inputPoints=vtkPoints::New();
//float x -1.0; set y -1.0; set z 0.0
aKSplineX-> AddPoint (0 ,-1.0);
aKSplineY-> AddPoint (0 ,-1.0);
aKSplineZ-> AddPoint (0 ,0.0);
aCSplineX-> AddPoint (0 ,-1.0);
aCSplineY-> AddPoint (0 ,-1.0);
aCSplineZ-> AddPoint (0 ,0.0);
inputPoints-> InsertPoint (0, -1.0,-1.0,0);

//set x 1.0; set y -1.0; set z 0.0
aKSplineX-> AddPoint (1 ,1.0);
aKSplineY-> AddPoint (1 ,-1.0);
aKSplineZ-> AddPoint (1 ,0.0);
aCSplineX-> AddPoint (1 ,1.0);
aCSplineY-> AddPoint (1 ,-1.0);
aCSplineZ-> AddPoint (1 ,0.0);
inputPoints-> InsertPoint (1, 1.0,-1.0,0);

//set x 1.0; set y 1.0; set z 0.0
aKSplineX-> AddPoint (2 ,1.0);
aKSplineY-> AddPoint (2 ,1.0);
aKSplineZ-> AddPoint (2 ,0.0);
aCSplineX-> AddPoint (2 ,1.0);
aCSplineY-> AddPoint (2 ,1.0);
aCSplineZ-> AddPoint (2 ,0.0);
inputPoints-> InsertPoint (2, 1.0,1.0,0);

//set x -1.0; set y 1.0; set z 0.0
aKSplineX-> AddPoint (3 ,-1.0);
aKSplineY-> AddPoint (3 ,1.0);
aKSplineZ-> AddPoint (3 ,0.0);
aCSplineX-> AddPoint (3 ,-1.0);
aCSplineY-> AddPoint (3 ,1.0);
aCSplineZ-> AddPoint (3 ,0.0);
inputPoints-> InsertPoint (3, -1.0,1.0,0);

vtkPolyData *inputData =vtkPolyData::New();
inputData->SetPoints(inputPoints);

vtkSphereSource *balls =vtkSphereSource::New();
balls->SetRadius(.04);
balls->SetPhiResolution(10);
balls->SetThetaResolution(10);

vtkGlyph3D *glyphPoints =vtkGlyph3D::New();
glyphPoints->SetInput(inputData);
glyphPoints->SetSource(balls->GetOutput());

vtkPolyDataMapper *glyphMapper = vtkPolyDataMapper::New();
glyphMapper->SetInputConnection(glyphPoints->GetOutputPort());

vtkActor *glyph = vtkActor::New();
glyph->SetMapper(glyphMapper);
glyph->GetProperty()->SetDiffuseColor(1,0,0);
glyph->GetProperty()->SetSpecular(.3);
glyph->GetProperty()->SetSpecularPower(30);

///////////////
vtkPoints *Kpoints = vtkPoints::New();
vtkPoints *Cpoints = vtkPoints::New();

Kpoints ->Reset();
Cpoints ->Reset();

vtkPolyData *profileKData=vtkPolyData::New();
vtkPolyData *profileCData=vtkPolyData::New();

numberOfInputPoints=5;
int numberOfOutputPoints=100;

float t;
int i;
for(i=0;i<numberOfOutputPoints;i++)
{
    t = (numberOfInputPoints-1.0)/(numberOfOutputPoints-1.0)*i;
    Kpoints->InsertPoint(i, aKSplineX->Evaluate(t), aKSplineY->Evaluate(t),
                       aKSplineZ->Evaluate(t));
    Cpoints->InsertPoint(i, aCSplineX->Evaluate(t), aCSplineY->Evaluate(t),
                       aCSplineZ->Evaluate(t));


}

vtkCellArray *lines = vtkCellArray::New();
    int a=lines->InsertNextCell(numberOfOutputPoints);
    for(i=0;i<numberOfOutputPoints;i++)
    {
         lines->InsertCellPoint(i);
    }

profileKData->SetPoints(Kpoints);
profileKData->SetLines(lines);

profileCData->SetPoints(Cpoints);
profileCData->SetLines(lines);

// Add thickness to the resulting line.
vtkTubeFilter *profileKTubes = vtkTubeFilter::New();
profileKTubes->SetNumberOfSides(8);
profileKTubes->SetInput(profileKData);
profileKTubes->SetRadius(0.01);

vtkTubeFilter *profileCTubes = vtkTubeFilter::New();
profileCTubes->SetNumberOfSides(8);
profileCTubes->SetInput(profileCData);
profileCTubes->SetRadius(0.01);

vtkPolyDataMapper *profileKMapper = vtkPolyDataMapper::New();
profileKMapper->SetInputConnection(profileKTubes->GetOutputPort());

vtkActor *profileK = vtkActor::New();
profileK->SetMapper(profileKMapper);
profileK->GetProperty()->SetDiffuseColor(1,1,0);
profileK->GetProperty()->SetSpecular(0.3);
profileK->GetProperty()->SetSpecularPower(30);

vtkPolyDataMapper *profileCMapper = vtkPolyDataMapper::New();
profileCMapper->SetInputConnection(profileCTubes->GetOutputPort());

vtkActor *profileC = vtkActor::New();
profileC->SetMapper(profileCMapper);
profileC->GetProperty()->SetDiffuseColor(0,0,1);
profileC->GetProperty()->SetSpecular(0.3);
profileC->GetProperty()->SetSpecularPower(30);

//////////////


ren->AddActor(glyph);
ren->AddActor(profileC);
ren->AddActor(profileK);

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

iren->Start();
}

样条曲线KclosedSplines

样条曲线KclosedSplines
回复

使用道具 举报

60

主题

408

回帖

1219

积分

版主

积分
1219

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

发表于 2016-5-12 17:02:49 | 显示全部楼层
先看看先。。。
回复

使用道具 举报

26

主题

411

回帖

1112

积分

版主

积分
1112

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

发表于 2016-5-13 02:34:45 | 显示全部楼层
谢谢你的辛苦劳动了!!!
回复

使用道具 举报

15

主题

420

回帖

1119

积分

版主

积分
1119

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

发表于 2016-5-14 14:09:34 | 显示全部楼层
一刀杨幂上床,二刀上海买房。三刀台湾归降,四刀美帝叫娘。五刀星河翱翔,六刀宇宙称王。七刀女人长屌,八刀汉子变娘。九刀完爆山东蓝翔——切糕!
回复

使用道具 举报

0

主题

388

回帖

775

积分

高级会员

积分
775

最佳新人

发表于 2016-5-18 00:23:26 | 显示全部楼层
有吸引力,回复看看
回复

使用道具 举报

119

主题

444

回帖

1498

积分

版主

积分
1498

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

发表于 2016-5-21 09:33:56 | 显示全部楼层
goooood 顶起
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-11 08:04 , Processed in 2.411903 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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