视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
VTK学习笔记
2025-10-02 19:20:21 责编:小OO
文档
VTK学习笔记

VTK开发程序能大大缩短图像,图像开发时间,尤其是3维图像图像,那么为何我直至今日还没有真正花费时间去学习VTK开发,与此作一番比较,看看自己是否到底值得花费如此时间?

目前,我所使用的3d程序开发 主要使用MSVC6以及OPENGL基础上完成,但是opengl对于三维开发而言是很底层的一个东西,虽然有时底层的东西开发很好用,至少学习使用起来不是那么麻烦,可能就是稍微花费点时间而已,但是当真正用到需要作一些项目或者一些实验的时候,往往弊端就暴露出来了,有时为了实现一个以前实现过的东西,不得不重新书写代码,因为自己在书写代码的时候一般性而言是不会写成标准库那样子的,so一般自己书写的代码只有当时有效,事后只能作为参考的东东而已,而且opengl开发的话,大多很底层的东西大多当时是明白的,过了一段时间之后在回头回去看这些代码的时候,已经分辨不清什么是是么了,如果vtk开发的话,至少使用了标准的库,可能第一次性开发的时间比较长,原因是自己对于VTK的不了解觉,但是一旦掌握这个工具后估计后期开发将会相当的省时间的,关键就是这个前期的学习周期比较长,不知道能不能在有限的时间内搞定下来。

so,vtk的学习现在win平台上操练下然后再考虑移植到linux上继续,呵呵,然学习如何自己封装自己的vtk数据。

安装是个很漫长的过程,cpu连续保持100%负荷运作10多分钟:

然后,好不容易把vtk的lib文件全部ok了,然后发现example中的vtkmfc例子不能正常运行,原始是缺失vtkmfc.lib文件,可是该文件并不存在,然后找到了以下这篇faq:

  Kitware Inc - Leaders in Visualization Technology 

Search   

[vtkusers] Problem with finding vtkMFC.lib

Murat Ahat murat.ahat at gmail.com 

Tue Aug 16 11:13:28 EDT 2005 

∙Previous message: [vtkusers] Problem with finding vtkMFC.lib 

∙Next message: [vtkusers] Where is vtkGLUTesselatorTriangleFilter? 

∙Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] 

On Tue, 16 Aug 2005 14:57:44 +0200 __ukasz Tutaj  wrote:  > 

Hi vtk Users. >  > I downloaded the latest updates from CVS repository, and tried to > 

launch some GUI example. However I got error that there was no > vtkMFC.lib available. 

After checking I found that there was no > vtkMFC.lib on my disk. I think it should be because

 during building > VTK there was no error. Thanks for any help. > __ukasz Tutaj >  I think you 

have to build it with the GUI support. when you run cmake you have to run it with -i option. 

for example:   cmake -i  and choose to use advanced options. thus you will see a GUI support

 option, and you should set it ON. and also choose build with MFC support option.  good luck!!! 

 

∙Previous message: [vtkusers] Problem with finding vtkMFC.lib 

∙Next message: [vtkusers] Where is vtkGLUTesselatorTriangleFilter? 

∙Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] 

More information about the vtkusers mailing list

看完之后我狂晕,我再cmake时并没有设置任何选项,就完全按默认的选项来编辑的,看来vtk编译时默认是不会生成vtkmfc的lib文件的,看来还得重新编译一下:(

另外一篇安装vtk的文章:

Install VTK

Home > Tutorial > Install Libraries on Windows > VTK

Install VTK

    If you don't have VTK download it here

    Unzip VTK-4.2-LastestRelease.zip in $LibDir, this will create a new directory $LibDir/VTK otherwise rename it to VTK

    Run CMake and select the $LibDir/VTK directory as 'Where is the source code'

    Put the same path + "-VC++" (like Visual C++) as 'Where to build the binaries'

    Be sure that 'Visual Studio 6' is selected.

    Check 'Show Advanced Values'. 

   Click on Configure, CMake will ask you to create the VTK-VC++ folder

    Put setup parameters exactly like that:

- BUILD_TESTING = OFF

- VTK_USE_ANSI_STDLIB = ON

- VTK_USE_HYBRID = ON

- VTK_USE_PATENDED = ON

    Click twice again on 'Configure' and then click on 'OK'. This will generate a Visual C++ project (*.dsw) in $LibDir/VTK-VC++.

    Launch $LibDir/VTK-VC++/VTK.dsw and compile in RelWithDebInfo mode.

To do that, right click on the menu and check 'Build', you can also uncheck 'Build MiniBar'.

    Then select 'RelWithDebInfo'.

    Start Compilation with ALL_BUILD

------------------------------------------------------------------------------

下面继续重新我的安装里程:

不管怎样,无论如何,vtk中自带的examples中的sampleMFC没能由编译好的lib文件链接运行,提示缺少vtkFiltering.dll文件等云云,貌似需要动态链接库,于是我查找了半天试修改该工程文件中哪里有引入动态链接库的地方,修改为静态的lib库,因为我好不容易才编译好了lib库文件,(p4 266Ghz的机子大概花费了12min编译完这些文件),最终失败!

不得以再次打开cmake再次修改make选项,重新又再次编译成dll动态链接库文件后才算成功了~~

晕死了,VTK的安装!!

然后仿照那个例子,自己建了一个sdi的mfc程序如下:

 

------------------------------------------------------------------

另外一个vtk窗口程序,以作为留念:

-------------------------------------------------------------------------

至此,基本上搞定了VTK的安装,但是如何使用编译好的静态链接库文件书写程序,还有待进一步考究~!

 

------------------------------------------------

下面是自己书写的一个最最简单的cone程序:

#include "stdafx.h"

#include "vtkconesource.h"

#include "vtkpolydatamapper.h"

#include "vtkactor.h"

#include "vtkrenderer.h"

#include "vtkrenderwindow.h"

int main(int argc, char* argv[])

{

 vtkConeSource *cone=vtkConeSource::New();

 cone->SetHeight(5);

 cone->SetRadius(2);

 cone->SetResolution(100);

 vtkPolyDataMapper * map=vtkPolyDataMapper::New();

 map->SetInput(cone->GetOutput());

 vtkActor *actor=vtkActor::New();

 actor->SetMapper(map);

 vtkRenderer * ren=vtkRenderer::New();

 ren->AddActor(actor);

 ren->SetBackground(.9,.5,.4);

 vtkRenderWindow* win=vtkRenderWindow::New();

 win->AddRenderer(ren);

 win->SetSize(600,480);

 while (1) 

  win->Render();

 

 return 0;

}

/*

libs includes:vtkRendering.lib  vtkGraphics.lib  vtkImaging.lib  vtkIO.lib  vtkFiltering.lib  vtkCommon.lib  vtksys.lib  vtkDICOMParser.lib  vtkpng.lib  vtktiff.lib  vtkzlib.lib  vtkjpeg.lib  vtkexpat.lib  vfw32.lib  vtkMPEG2Encode.lib  vtkftgl.lib  vtkfreetype.lib  opengl32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odb32.lib 

*/

在使用vtkMFCWindow进行vtk+VC MFC开发,重新书写MedPlant程序,目前遇到的问题有:

1.如何选择三维场景中的坐标点,已解决,via vtkCellPicker类,

2.如何进行三维空间的面裁剪,有待解决;

3.vtkMFCWindow好像接收了界面的消息,然后但是并没有share these messages with other windows, such as view frame. in my opinion, one solution is that re-program vtkMFCWindow, for I have the resouce of vtkMFCWindow, but it's not a good idea, for vtkMFCWindow is a standarded C++ class, I should not crack it's intergrality.

Second solution is make a subclass of vtkMFCWindow, then remove the msg handle from vtkMFCWindow, make some of mine.

Following is some FAQs from VTK forum:

-------------------------------------------------------------------------

Kitware Inc - Leaders in Visualization Technology Search 

[vtkusers] Improving interaction with a vtkMFCWindow

Mark Gooding mark.gooding at gmail.com 

Thu Mar 9 10:13:44 EST 2006 

Previous message: [vtkusers] vtkMFCWindow causing crash in release mode with visual studio 

Next message: [vtkusers] vtk-paraview 

Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] 

--------------------------------------------------------------------------------

Hello all,

Sorry for filling your inboxes - I figured it was best to send two

emails becuase my queries were largely unrelated.

Ok - so here's the situation: I writing an app using Visual Studio C++

using both MFC and VTK. Consquently I'm using the vtkMFCWindow to the

the vtk display. The project extends the vtkSDI example (which may

have a bearing on how things are done.)

I would like to be able to interact with the vtk window as already

happens, but it would also be nice to be able to use keyboard and

mouse interaction for other parts of the project.

To enable a context menu I created a subclass of the

vtkInteractorStyle which then sent the WM_CONTEXTMENU command when the

right mouse button was clicked (but not moved). This seemed an ok

solution, but isn't very extensible for other interactions. For

instance I would like to modify my document class when certain keys

are pressed, and it seems somewhat long winded for the interactor to

get the active document and call the appropriate routine, when it

would be better for the document to handle its own keypress routines.

As fas as I see it, the way the messages are handled is as follows;

the vtkMFCWindow implements a large number of the standard window

message functions. These are then the ones that respond to messages,

because the vtkMFCWindow generally has the focus. These functions then

call the appropriate function within the current windowInteractor.

Have I understood this right?

So what would be the best way to get the vtkMFCWindow to share the

messages Subclass the vtkMFCWindow and remove it's message handling

and then get the application to handle all messages and pass only the

interesting ones (to vtk) to the subclassed vtkMFCWindow? I think this

is primarily a problem for key presses, since the vtkMFCWindow only

responds to a small number and it would be nice to use other keys to

perform other operations within the application. Most mouse

interaction will probably relate to toolbar work or vtk interaction

anyway (i guess).

Any thoughts?

Cheers,

Mark

--------------------------------------------------------------------------------

Previous message: [vtkusers] vtkMFCWindow causing crash in release mode with visual studio 

Next message: [vtkusers] vtk-paraview 

Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] 

--------------------------------------------------------------------------------

More information about the vtkusers mailing list

--------------------------------------------------------------------------------------

Kitware Inc - Leaders in Visualization Technology Search 

[vtkusers] Improving interaction with a vtkMFCWindow

de Boer Ingo I.deBoer at polytec.de 

Thu Mar 9 10:31:37 EST 2006 

Previous message: [vtkusers] vtkMFCWindow causing crash in release mode with visualstudio 

Next message: [vtkusers] Improving interaction with a vtkMFCWindow 

Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] 

--------------------------------------------------------------------------------

Hi,

> To enable a context menu I created a subclass of the 

> vtkInteractorStyle which then sent the WM_CONTEXTMENU command 

Why not creating a context menu via the view class ?

> interactions. For instance I would like to modify my document 

> class when certain keys are pressed, and it seems somewhat 

Why not use the OnKey/OnChar from the view class ?

> that respond to messages, because the vtkMFCWindow generally 

> has the focus. These functions then call the appropriate 

The focus depends on your programm. Eg, a mouse click sets

a focus to a window.

> So what would be the best way to get the vtkMFCWindow to 

> share the messages Subclass the vtkMFCWindow and remove 

The messages are also send to the view, so they share them already

greets

Ingo

---

Dr.-Ing. Ingo H. de Boer

Polytec GmbH

Polytec-Platz 1-7, 76337 Waldbronn, Germany

phone: ++49 7243 604 106

fax : ++49 7243 604 255

--------------------------------------------------------------------------------

Previous message: [vtkusers] vtkMFCWindow causing crash in release mode with visualstudio 

Next message: [vtkusers] Improving interaction with a vtkMFCWindow 

Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] 

--------------------------------------------------------------------------------

More information about the vtkusers mailing list

有人写的一个解决方案如下:

From: John Platt dsl.pipex.com>

Subject: RE: Enabling use a ContextMenu with vtk and MFC (mouse-clickdetection)

Newsgroups: gmane.comp.lib.vtk.user

Date: 2006-02-27 22:29:02 GMT (42 weeks, 12 hours and 43 minutes ago)

Hi Mark,

Have you tried adding an observer to your interactor for the right

button press event, something like this in your CView derived class ....

MyView.h

vtkCallbackCommand* m_vtkMouseEventCBC;

static void ProcessMouseEvents( vtkObject* object, unsigned long

event, void* clientdata, void*

calldata );

MyView.cpp

m_vtkMouseEventCBC = vtkCallbackCommand::New();

m_vtkMouseEventCBC->SetCallback( CMyView::ProcessMouseEvents );

m_vtkMouseEventCBC->SetClientData( this );

m_vtkInteractor->AddObserver( vtkCommand::RightButtonPressEvent, 

m_vtkMouseEventCBC, 0.5 );

void CMyView::ProcessMouseEvents(vtkObject* vtkNotUsed(object), 

unsigned long event, 

void* clientdata, 

void* callData )

{

CMyView* self = reinterpret_cast< CMyView*>( clientdata );

switch( event )

{

case vtkCommand::RightButtonPressEvent:

TRACE("Right Button Down.\\n" );

self->DoSomeStuff();

// Prevent others from handling this event.

self->m_vtkMouseEventCBC->SetAbortFlag(1);

break; 

}

}

HTH

John.

-----Original Message-----

From: vtkusers-bounces+jcplatt=dsl.pipex.com vtk.org

[mailto:vtkusers-bounces+jcplatt=dsl.pipex.com vtk.org] On Behalf Of

Mark Gooding

Sent: 27 February 2006 10:13

To: vtkusers

Subject: [vtkusers] Enabling use a ContextMenu with vtk and MFC

(mouse-clickdetection)

Hello all,

A while ago I emailed about trying to set up a ContextMenu when the

right mouse button is clicked on the vtkWindow in MFC. The problem was

that the vtkMFCWindow does not respond to the clicks (despite the

example having a function within it that appears to suggest it

should), instead the mouse action seems to passed directly to the

vtkWindowInteractor.

To solve this problem I think I should be subclassing

vtkWindowInteractorStyle, so that I can either remove the handling of

right mouse click (so that the window handles it) or modify it to pass

clicks directly to the CView class.

Does this sound like a sensible approach? Or is there a better/more

standard solution? I didn't want to set off programming without at

least knowing that I heading in the right direction!

Cheers,

Mark

 ----------------------------------

笔记说vtk的MFC框架编程中遇到的一个问题就是vtkMFCWindow的消息响应问题,现在我找到了一个捷径来解决这个问题,然后这个办法有点傻傻的,但是非常的实用,见上图,我在vtkMFCWindow的窗口里面点击了鼠标,窗口有了WM_LBUTTONDOWN的响应,并且弹出了对话框。修改很简单,就是在vtk的源文件里面找到vtkMFCWindow.cpp,以及vtkMFCWindow.h文件,然后修改这2个文件,甚至你可以在里面修改更多的消息映射方式,然后直接使用cmake的方式仅仅重新编译vtkMFC这工程,然后将编译好的dll文件和lib代替原先的dll和lib。方法虽然简单,但是总是觉得有点不爽,毕竟修改了源代码,不过如果不爽的话,可以考虑将vtkMFCWindow.cpp和vtkMFCWindow.h文件copy到你的工程,然后换个名字建立你自己的vtkmfc类就可以了,但是如果讲到最最好的方法,也是最最实用的方法就是完全看懂vtkMFCWindow的整个消息响应以及和vtkWindowInteractor之间的联系方式,然后全新的改写自己的CMyView类文件成为一个新的类系于“vtkMFCWindow”,嗯 ~~

AM 1:03, 成功修改并创建了自己的vtkMyMFCWindow类,并在里面封装了自己的消息响应函数,然后都可以不用那些个lib和dll文件了,嘿嘿ie~

使用2层mc提取2个不同的iso值,不同的alpha,不同的color显示。

4层绘制的神经元细胞下载本文

显示全文
专题