[vtkusers] Some suggestions on developing apps with BCBn

dean.inglis at camris.ca dean.inglis at camris.ca
Thu May 13 21:03:35 EDT 2004


Some suggestions on developing apps with BCBn

1) throw away codegurad: it slows down your app compile time, bloats your 
executable and for reasons unknown to me, may or may not be compatable
with vtk libs/dlls.  Empirically speaking, a way to debug that has worked for me
is to carefully write code: when something doesn't work make it simpler until you
can nail down the bug that is causing you grief.  Often it is as simple as
mis-spelling a variable, regardless of your programming skills/experience.
Personally, I have never used codeguard or any other debugging tools and
ALL of the apps I have developed in BCB 5 &  6 using VTK work error free (except for
those with 2 vtkBorlandRenderWindows, but hey, they don't crash!).

2) in terms of structuring an app, this is personal style dependent.  What I 
have done that works is to follow the VTK way of coding classes & do the following:

a) In the MainForm header, declare VTK classes without #including , e.g.,

#ifndef myapp_guiH
#define myapp_guiH

#include <BCBCLASSES.hpp>
#include <BCBCLASSES.hpp>
#include <BCBCLASSES.hpp>
#include <ETC.hpp>

class vtkThis;
class vtkThat;

b) make some vtkClasses member ivars of your form when necessary:

private:
  vtkImageReader* m_reader;

and I declare one function to initialize such classes after they are
constructed in the form's constructor:

  void __fastcall InitVTKObjects();

c) in the source file, declare your #includes, e.g.,

#include "vtkThis.h"
#include "vtkThat.h"

d) use the form's OnCreate event handler to initialize your
VTK objects, NOT the form's constructor! e.g.,

void __fastcall MainForm::FormCreate(TObject* Sender)
{
   m_actor = vtkActor::New();
  this->InitVTKObjects();
}

e) in the init function, init the vtk objects as MUCH as required
(depends on the vtk object):

void __fastcall MainForm::InitVTKObjects()
{
   m_actor->VisibilityOn();
  this->RenderWindow->GetRenderer()->AddProp( m_actor );
}

f) invoke an OnShow event for the form to initialise the vtkBorlandRenderWindow, 
avoids problems if a user trys to interact with your window when there is no actor:

void __fastcall MainForm::FormShow(TObject* Sender)
{
  this->RenderWindow->GetInteractor();
  this->RenderWindow->GetRenderer();
}

g) invoke the OnDestroy event handler for the form:

void __fastcall MainForm::FormDestroy(TObject* Sender)
{
  vtkRenderWindow* renwin = this->RenderWindow->GetRenderWindow();
  m_actor->ReleaseGraphicsResources( renwin );

  vtkRenderer* ren = this->RenderWindow->GetRenderer();
  ren->RemoveAllProps();
  m_actor->Delete();
}

And that's about it...Oh, and please, do not
send my unsolicited emails!

Dean




More information about the vtkusers mailing list