[vtkusers] MFC comment and an offer to Kitware.

Andrew J. P. Maclean a.maclean at acfr.usyd.edu.au
Thu Jan 24 20:12:42 EST 2002


I have had considerable frustrations with developing under Visual C++
6.0 using MFC. In looking through the postings on the newsgroup, the
major problems lie in vtkMFC* and, also for new users, how to integrate
these classes into an application.  

 

So, I decided to revisit the whole problem and develop without using the
vtkMFC* classes. In fact it turned out to be quite simple to just create
a project and modify some of the methods to yield a full blown
application that also has printing enabled. 

 

Moreover, if you want to develop a completely new application you only
have to modify the constructor, destructor and pipeline for the view.
This was a big surprise! 

 

Of course there are still leaks in some of the vtk objects that appear
on exit, but the interactor and printing works nicely.

 

My questions are: 

1)       Is this sample of use to the community in general? 

2)       If so, would anyone at VTK like the code in order to check it
and incorporate it into the GUI folder i.e in .VTK\Examples\GUI? 

3)       If so, I'll also write an example using the multiple document
interfaces that will reads a vtk file and display it.

 

For your interest, here are the sample instructions for a creating a SDI
application under MFC:

 

 

The creation of a Microsoft Foundation Class Single Document Interface
using vtk.

A complete implementation using the sample code for Visualizing a
Quadric Function is provided in this folder.

 

First you need to create a MFC/SDI Project:

            Use the Visual C++ IDE (Version 6) to create a project.

            File | New Project

            Select the Projects tab and the MFC App Wizard (exe)

            Name the project and create a new workspace by pressing OK.

            In Step 1, select Single Document

            Continue through to Step 4 by pressing Next.

            In Step 4 select advanced.

            If you want to associate a file extension with the
program,enter it into the File extension box.

            If you want vary Window Styles, select the Window Style tab
and choose whatever you want, e.g Use Split Window

            Click on Close

            Either continue clicking Next or Finish.

At this point you will have created a skeleton application.

 

Now you need to add the vtk functionality to this application.

This will consist of adding vtk specific code and over-riding the
functionality of of existing methods in the Document or View.

 

In this example, we are not going to use file IO so all modifications
will occur in the View. The view class is named as follows: C<Project
Name>View e.g. if the Project name is VtkSDI then the view class is
called CVtkSDIView.

 

Modify the project settings to include the VTK files and libraries.

            1) Project | Settings... and ensure that Settings for All
Configurations is chosen.

            2) Select the Tab: C/C++, category Preprocessor and add in
the path to the header files e.g.
C:\vtk\vtkbin,C:\vtk\vtk\Common,C:\vtk\vtk\Filtering,C:\vtk\vtk\Graphics
,C:\vtk\vtk\Hybrid,C:\vtk\vtk\Imaging,C:\vtk\vtk\IO,C:\vtk\vtk\Rendering
into the Additional Include Directories box.

            3) Select the Tab: Link, and enter the Object/Library
modules into the Object/Library Modules box e.g. vtkCommon.lib
vtkFiltering.lib vtkGraphics.lib vtkHybrid.lib vtkImaging.lib vtkIO.lib
vtkjpeg.lib vtkpng.lib vtkRendering.lib vtkzlib.lib

            4) Now select Input and change Settings For: All
Configurations to Debug and put in the path to the Debug libraries and
DLL's into the Additional Library path box e.g: C:\vtk\vtkbin\bin\Debug 

            5) Now select Input and change Settings For: Debug to
Release and put in the path to the Release libraries and DLL's into the
Additional Library path box e.g: C:\vtk\vtkbin\bin\Release 

 

 

 

In the view class:

            1) Add the necessary VTK variables and corresponding VTK
header files. It is best to make these variables private. Now these
variables need to be created and deleted. So...

            2) In the constructor add the necessary creation code.

            3) In the destructor, add the necessary deletion code.

            4) Remember: for every New in the constructor, you must have
a corresponding Delete in the destructor.

            5) Add the windows message handler corresponding to
WM_CREATE and insert code code to enable adding the renderer to the vtk
window and link the wiew to the vtk window. This function called
OnCreate().  

            6) We need to add functionality to the OnDraw method to
enable the VTK object to be viewed, manipulated and printed. In this
method, we will also call a function that sets up the pipeline for the
rendering process. Let's call this member function Pipeline().

            7) In order to allow resizing, add the windows message
handler corresponding to WM_SIZE and insert code for resizing. This
creates a function called OnSize().

            8) Flickering will occur if you resize the view so, add the
windows message hadler corresponding to WM_ERASEBKGND to create the
function called OnEraseBkgnd() and over-ride it to return TRUE.

            9) Add the required code to Pipeline() to create the VTK
rendition of a scene or object.

 

 

Once these steps are completed, you will, in general, need only to
modify code in steps 1, 2, 3, and 9 if you want to visualise a new
function.

 

References to the code in vtkSDI*.*

Setp     File                   Function

1)         vtkSDIView.h

2)         vtkSDIView.cpp  CVtkSDIView::CVtkSDIView()

3)         vtkSDIView.cpp  CVtkSDIView::~CVtkSDIView()

5)         vtkSDIView.cpp  CVtkSDIView::OnCreate(LPCREATESTRUCT
lpCreateStruct)

6)         vtkSDIView.cpp  CVtkSDIView::OnDraw(CDC* pDC)

7)         vtkSDIView.cpp  CVtkSDIView::OnSize(UINT nType, int cx, int
cy)

8)         vtkSDIView.cpp  CVtkSDIView::OnEraseBkgnd(CDC* pDC)

9)         vtkSDIView.cpp  CVtkSDIView::Pipeline()

 


 


___________________________________________
Andrew J. P. Maclean


Postal:

Australian Centre for Field Robotics
The Rose Street Building J04
The University of Sydney  2006  NSW
AUSTRALIA


Room:

106


Phone:

+61 2 9351 3283


Fax:

+61 2 9351 7474


 

 <http://www.acfr.usyd.edu.au/> http://www.acfr.usyd.edu.au/

___________________________________________

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20020125/91c5d331/attachment.htm>


More information about the vtkusers mailing list