VTK入门程序样例分析-vtk与MFc混编
更新时间:2024-05-29 16:11:01 阅读量: 综合文库 文档下载
- vtk入门教程推荐度:
- 相关推荐
VTk与MFC混编
前面几个例子是熟悉vtk的,练习时用控制台程序编写,vtk与MFC混编的过程中遇到了很多问题,为了方便大家,我把这一过程中的遇到的错误和解决办法都记录下来了,希望能够对大家有所帮助
VTK入门程序样例分析
一、圆锥圆柱类
1、简单圆锥【圆锥鼠标拖动】
#include \ #include \ #include \ #include \ #include \ #include \
int main() {
vtkConeSource *cone = vtkConeSource::New(); cone->SetHeight( 3.0 ); cone->SetRadius( 1.0 ); cone->SetResolution( 10 );
vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New(); coneMapper->SetInputConnection( cone->GetOutputPort() );
vtkActor *coneActor = vtkActor::New(); coneActor->SetMapper( coneMapper );
vtkRenderer *ren1= vtkRenderer::New(); ren1->AddActor( coneActor );
ren1->SetBackground( 0.1, 0.2, 0.4 );
vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer( ren1 ); renWin->SetSize( 300, 300 );
int i;
for (i = 0; i < 360; ++i) {
// render the image renWin->Render();
// rotate the active camera by one degree ren1->GetActiveCamera()->Azimuth( 1 ); }
cone->Delete(); coneMapper->Delete(); coneActor->Delete(); ren1->Delete(); renWin->Delete(); return 0; }
1、新建工程 2、输入代码 3、添加包含文件 4、编译出错 cone1.obj : error LNK2019: unresolved external symbol \public: void __thiscall vtkCamera::Azimuth(double)\(__imp_?Azimuth@vtkCamera@@QAEXN@Z) referenced in function _wmain
错误解决办法 error LNK2019: 无法解析的外部符号 \称找不到vtkIO.dll 对应解决办法:在每个项目属性的链接器->输入->附加依赖项中添加入vtkIO.lib库,目录为:..\\..\\..\\..\\bin\\Debug\\vtkIO.lib
F:\\VTK58\\bin\\bin\\Debug\\vtkMFC.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkRendering.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkIO.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkFiltering.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkCommon.lib;DelayImp.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkGraphics.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkImaging.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkFiltering.lib;F:\\VTK58\\bin\\bin\\Debug\\vtkCommon.lib;F:\\VTK58\\bin\\bin\\Debug\\vtksys.lib;
错误没了!
2、Callback命令
#include \
#include \ #include \ #include \ #include \ #include \ #include \
// Callback for the interaction
class vtkMyCallback : public vtkCommand { public:
static vtkMyCallback *New() { return new vtkMyCallback; }
virtual void Execute(vtkObject *caller, unsigned long, void*) {
vtkRenderer *renderer = reinterpret_cast
int main() { //
// The pipeline creation is documented in Step1 //
vtkConeSource *cone = vtkConeSource::New(); cone->SetHeight( 3.0 ); cone->SetRadius( 1.0 ); cone->SetResolution( 10 );
vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New(); coneMapper->SetInputConnection( cone->GetOutputPort() ); vtkActor *coneActor = vtkActor::New(); coneActor->SetMapper( coneMapper );
vtkRenderer *ren1= vtkRenderer::New(); ren1->AddActor( coneActor );
ren1->SetBackground( 0.1, 0.2, 0.4 ); ren1->ResetCamera();
vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer( ren1 );
renWin->SetSize( 300, 300 );
// Here is where we setup the observer, we do a new and ren1 will // eventually free the observer
vtkMyCallback *mo1 = vtkMyCallback::New(); ren1->AddObserver(vtkCommand::StartEvent,mo1); mo1->Delete(); //
// now we loop over 360 degrees and render the cone each time // int i;
for (i = 0; i < 360; ++i) {
// render the image renWin->Render();
// rotate the active camera by one degree ren1->GetActiveCamera()->Azimuth( 1 ); } //
// Free up any objects we created //
cone->Delete(); coneMapper->Delete(); coneActor->Delete(); ren1->Delete(); renWin->Delete();
return 0; }
3、一个圆锥两个renderer在同一个窗口下显示
#include \ #include \ #include \ #include \ #include \ #include \
int main() { //
// Next we create an instance of vtkConeSource and set some of its // properties. The instance of vtkConeSource \
// visualization pipeline (it is a source process object); it produces data // (output type is vtkPolyData) which other filters may process. //
vtkConeSource *cone = vtkConeSource::New(); cone->SetHeight( 3.0 ); cone->SetRadius( 1.0 ); cone->SetResolution( 10 ); //
// In this example we terminate the pipeline with a mapper process object. // (Intermediate filters such as vtkShrinkPolyData could be inserted in // between the source and the mapper.) We create an instance of
// vtkPolyDataMapper to map the polygonal data into graphics primitives. We // connect the output of the cone souece to the input of this mapper. //
vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New(); coneMapper->SetInputConnection( cone->GetOutputPort() ); //
// Create an actor to represent the cone. The actor orchestrates rendering // of the mapper's graphics primitives. An actor also refers to properties // via a vtkProperty instance, and includes an internal transformation // matrix. We set this actor's mapper to be coneMapper which we created // above. //
vtkActor *coneActor = vtkActor::New(); coneActor->SetMapper( coneMapper ); //
// Create two renderers and assign actors to them. A renderer renders into // a viewport within the vtkRenderWindow. It is part or all of a window on // the screen and it is responsible for drawing the actors it has. We also // set the background color here. In this example we are adding the same // actor to two different renderers; it is okay to add different actors to // different renderers as well. //
vtkRenderer *ren1= vtkRenderer::New(); ren1->AddActor( coneActor );
ren1->SetBackground( 0.1, 0.2, 0.4 ); ren1->SetViewport(0.0, 0.0, 0.5, 1.0);
vtkRenderer *ren2= vtkRenderer::New(); ren2->AddActor( coneActor );
ren2->SetBackground( 0.2, 0.3, 0.5 ); ren2->SetViewport(0.5, 0.0, 1.0, 1.0); //
// Finally we create the render window which will show up on the screen. // We put our renderer into the render window using AddRenderer. We also // set the size to be 300 pixels by 300. //
vtkRenderWindow *renWin = vtkRenderWindow::New(); renWin->AddRenderer( ren1 ); renWin->AddRenderer( ren2 ); renWin->SetSize( 600, 300 ); //
// Make one view 90 degrees from other. //
ren1->ResetCamera();
ren1->GetActiveCamera()->Azimuth(90); //
// Now we loop over 360 degreeees and render the cone each time. // int i;
for (i = 0; i < 360; ++i) {
// render the image renWin->Render();
// rotate the active camera by one degree ren1->GetActiveCamera()->Azimuth( 1 ); ren2->GetActiveCamera()->Azimuth( 1 ); } //
// Free up any objects we created. All instances in VTK are deleted by // using the Delete() method. //
cone->Delete(); coneMapper->Delete(); coneActor->Delete(); ren1->Delete(); ren2->Delete(); renWin->Delete();
return 0; }
4、一个圆锥两个renderer在同一个窗口下显示
Cone4
#include \ #include \ #include \ #include \ #include \ #include \ #include \
int main() { //
// Next we create an instance of vtkConeSource and set some of its // properties. The instance of vtkConeSource \
// visualization pipeline (it is a source process object); it produces data // (output type is vtkPolyData) which other filters may process. //
vtkConeSource *cone = vtkConeSource::New(); cone->SetHeight( 3.0 ); cone->SetRadius( 1.0 ); cone->SetResolution( 10 ); //
// In this example we terminate the pipeline with a mapper process object. // (Intermediate filters such as vtkShrinkPolyData could be inserted in // between the source and the mapper.) We create an instance of
// vtkPolyDataMapper to map the polygonal data into graphics primitives. We
二、Filter 1、ImplicitSum
#include \
#include \#include \
#include \#include \#include \#include \#include \#include \#include \#include \#include \
#include
#include
#include
void main() {
// 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);
vtkCone *geomObject1=vtkCone::New();
vtkSphere *geomObject2=vtkSphere::New(); geomObject2-> SetRadius( 0.5); geomObject2-> SetCenter( 0.5, 0 ,0);
vtkImplicitSum *sum=vtkImplicitSum::New(); sum-> SetNormalizeByWeight( 1); sum-> AddFunction (geomObject1 ,2); sum-> AddFunction (geomObject2 ,1);
vtkSampleFunction *sample=vtkSampleFunction::New(); sample-> SetImplicitFunction( sum);
sample-> SetSampleDimensions( 60, 60 ,60); sample-> ComputeNormalsOn();
vtkContourFilter *surface=vtkContourFilter::New();
surface-> SetInputConnection (sample->GetOutputPort()); surface-> SetValue (0 ,0.0);
vtkPolyDataMapper *mapper=vtkPolyDataMapper::New(); mapper-> SetInputConnection(surface-> GetOutputPort()); mapper-> ScalarVisibilityOff();
vtkActor *actor=vtkActor::New(); actor-> SetMapper (mapper);
actor-> GetProperty()-> SetColor( 0.2 ,0.4 ,0.6); actor-> GetProperty()-> SetSpecular ( 0.4); actor-> GetProperty()-> SetDiffuse ( 0.7);
actor-> GetProperty()-> SetSpecularPower ( 40); //////////////
ren->AddActor(actor);
iren->Initialize();
renWindow->Render();
iren->Start(); }
2、PerlinNoise
#include \ #include \ #include \
#include \ #include \ #include \ #include \ #include \ #include \
#include \ #include \ #include \ #include
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);
vtkPerlinNoise *perlin=vtkPerlinNoise::New(); perlin-> SetFrequency (2 ,6.25, 5.5); perlin-> SetPhase (0 ,0, 0);
vtkSampleFunction *sample=vtkSampleFunction::New(); sample-> SetImplicitFunction (perlin); sample-> SetSampleDimensions( 65,65 ,20); sample-> ComputeNormalsOff();
vtkContourFilter *surface=vtkContourFilter::New();
surface-> SetInputConnection(sample-> GetOutputPort()); surface-> SetValue (0, 0.0);
vtkPolyDataMapper *mapper=vtkPolyDataMapper::New();
mapper-> SetInputConnection(surface-> GetOutputPort()); mapper-> ScalarVisibilityOff();
vtkActor *actor=vtkActor::New(); actor-> SetMapper (mapper);
actor-> GetProperty()-> SetColor( 0.2 ,0.4 ,0.6);
////////////// ren->AddActor(actor);
iren->Initialize(); renWindow->Render();
iren->Start(); }
3、样条曲线CSpline
.
#include \ #include \ #include \
#include \ #include \ #include \ #include \ #include \ #include \
#include \ #include \ #include \ #include
void main() {
double x,y,z; int i;
for(i=0;i x = (float)rand()/(float)RAND_MAX; y = (float)rand()/(float)RAND_MAX; z = (float)rand()/(float)RAND_MAX; printf(\,x,y,z); aSplineX->AddPoint(i, x); aSplineY->AddPoint(i, y); aSplineZ->AddPoint(i, z); inputPoints->InsertPoint(i, x, y, z); vtkPoints *inputPoints = vtkPoints::New(); vtkCardinalSpline *aSplineX = vtkCardinalSpline::New(); vtkCardinalSpline *aSplineY = vtkCardinalSpline::New(); vtkCardinalSpline *aSplineZ = vtkCardinalSpline::New(); int numberOfInputPoints = 30; vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(renWindow); // rand()/RAND_MAX;// 0 - RAND_MAX vtkRenderer *ren = vtkRenderer::New(); vtkRenderWindow *renWindow = vtkRenderWindow::New(); renWindow->AddRenderer(ren); renWindow->SetSize( 600, 600 ); srand(time(NULL)) ; } vtkPolyData *inputData =vtkPolyData::New(); inputData->SetPoints(inputPoints); vtkSphereSource *balls =vtkSphereSource::New(); balls->SetRadius(.01); 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 *points = vtkPoints::New(); // Number of points on the spline int numberOfOutputPoints = 400; float t; for(i=0;i vtkCellArray *lines = vtkCellArray::New(); int a=lines->InsertNextCell(numberOfOutputPoints); for(i=0;i t = (numberOfInputPoints-1.0)/(numberOfOutputPoints-1.0)*i; points->InsertPoint(i, aSplineX->Evaluate(t), aSplineY->Evaluate(t), aSplineZ->Evaluate(t)); points->GetPoint(i)[1],points->GetPoint(i)[2]); printf(\,points->GetPoint(i)[0], } } lines->InsertCellPoint(i); vtkPolyData *profileData = vtkPolyData::New(); profileData->SetPoints(points); profileData->SetLines(lines); // Add thickness to the resulting line. vtkTubeFilter *profileTubes = vtkTubeFilter::New(); profileTubes->SetNumberOfSides(8); profileTubes->SetInput(profileData); profileTubes->SetRadius(0.005); vtkPolyDataMapper *profileMapper = vtkPolyDataMapper::New(); profileMapper->SetInputConnection(profileTubes->GetOutputPort()); vtkActor *profile = vtkActor::New(); profile->SetMapper(profileMapper); profile->GetProperty()->SetDiffuseColor(1,1,0); profile->GetProperty()->SetSpecular(0.3); profile->GetProperty()->SetSpecularPower(30); ////////////// ren->AddActor(glyph); ren->AddActor(profile); iren->Initialize(); renWindow->Render(); iren->Start(); 4、图形切割 #include \ #include \ #include \ #include \ #include \ #include \ #include \ #include \ #include \ #include \ #include \ #include \ int main() { vtkQuadric *quadric = vtkQuadric::New(); vtkSampleFunction *sample = vtkSampleFunction::New(); vtkExtractVOI *extract = vtkExtractVOI::New(); sample->SetSampleDimensions(30, 30, 30); sample->SetImplicitFunction(quadric); sample->ComputeNormalsOff(); quadric->SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0); extract->SetInputConnection(sample->GetOutputPort()); extract->SetVOI(0, 29, 0, 29, 5, 25); //**********调整三维切割 // extract->SetSampleRate(1, 2, 3); vtkContourFilter *contours = vtkContourFilter::New(); vtkPolyDataMapper *contMapper = vtkPolyDataMapper::New(); vtkActor *contActor = vtkActor::New(); vtkOutlineFilter *outline = vtkOutlineFilter::New(); vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New(); vtkActor *outlineActor = vtkActor::New(); vtkRenderer *ren1 = vtkRenderer::New(); vtkRenderWindow *renWin = vtkRenderWindow::New(); } return 0; ren1->ResetCamera(); ren1->GetActiveCamera()->Zoom( 1.5 ); renWin->Render(); iren->Initialize(); iren->Start(); ren1->SetBackground(1, 1, 1); ren1->AddActor(contActor); ren1->AddActor(outlineActor); renWin->AddRenderer(ren1); iren->SetRenderWindow(renWin); vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); outlineActor->SetMapper(outlineMapper); outlineActor->GetProperty()->SetColor(0, 0, 0); outlineMapper->SetInputConnection(outline->GetOutputPort()); outline->SetInputConnection(sample->GetOutputPort()); contActor->SetMapper(contMapper); contMapper->SetInputConnection(contours->GetOutputPort()); contMapper->SetScalarRange(0.0, 1.2); contours->SetInputConnection(extract->GetOutputPort()); contours->GenerateValues(13, 0.0, 1.2);
正在阅读:
〖精选5套试卷〗2021学年陕西省商洛市中考物理学业质量监测试题04-28
小学英语时态专项练习题08-30
药品注册申请中有效的沟通交流学习总结04-13
香水推荐:8款情侣对香提升默契感05-04
体育知识竞赛问题与答案04-08
计算机数据结构考研真题及其答案11-13
精选公司企业春节放假通知值班安排疫情防控温馨提范文模板合辑(03-25
试论惩罚性违约金的适用及调整02-02
元数据白皮书05-07
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 混编
- VTK
- 入门
- 程序
- 分析
- MFc
- 高三物理月考试题及答案-安徽“江淮十校”联考2016届高三上学期
- 第二届大学生物流设计大赛案例 - 图文
- 架设学生数学学习的桥梁
- 佳木斯大学群体性事件应急预案
- 民法(1-16)
- 毕业设计任务书
- 第二十二届希望杯”全国数学邀请赛获奖名单
- 2017年辽宁省锦州市中考数学试题(解析版)
- 新视野大学英语听说教程1unit8
- 2010.10商务沟通与谈判试题
- 通识教育背景下以提升学生能力为导向的教学理念和策略探讨
- 千教万教教人求真
- 综合服务办公室制度汇编
- 2011年中考数学专项复习训练:数据的描述
- 数学每日一题
- 红警相关代码教你修改RULES.INI文件
- 21.《画家和牧童》导学案
- 巴西与拉丁美洲 - 图文
- 【核电站】反应堆换料水池和乏燃料水池的冷却及处理系统(PTR)
- VFP程序设计题目和答案