[vtkusers] Render window

Tuhin Sinha tk.sinha at vanderbilt.edu
Sun Mar 2 19:46:16 EST 2003


Charl,

	I am a bit confused with the reference counting architecture in VTK.  My 
understanding was that reference counting was used by an object to make sure 
it deleted itself when it wasn't needed anymore.  However, does this imply 
that the object _must_ wait until its reference count is 1 to delete itself?  
Or, can it delete itself regardless of who/how many things are pointed at it?  
The implication here is that the pointing object must make sure the 
dereference is valid.  Any clarification on this would be greatly 
appreciated.

	Also, I did some searching through the VTK source and found that the 
vtkWin32OpenGLRenderWindow actually does window management (i.e. handles the 
Win32 WM_DESTROY message).  There isn't a corresponding code segment in the 
vtkXOpenGLRenderWindow class.  As a result of this difference, the code I 
have attached to this e-mail runs "correctly" under Windows, but fails under 
Linux.  I think that good window management can be done without any object 
management.  That is, while the vtkRenderWindow object exists (regardless of 
its reference count), it should maintain the status of its system specific 
window properties unless told otherwise.  In my experience, 
vtkXOpenGLRenderWindow does not do this... it creates the window, but then 
expects the user to manage its consistency.  vtkWin32OpenGLRenderWindow does 
the window management properly.

	I am a relative newbie to VTK and I understand that there might be some 
platform specific reasons for the discrepancy in the way these two classes 
operate.  I am just wondering why and is there room for a way to make these 
two classes operate more similarly?

Regards,

Tuhin

On Sunday 02 March 2003 14:03, Charl P. Botha wrote:
> On Sun, Mar 02, 2003 at 01:13:50PM -0600, Tuhin Sinha wrote:
> >   Regarding a default window handling procedure, what prevents VTK from
> > implementing a flag that turns on/off window handling by the
> > vtkRenderWindow object.  That is, if the flag is on, then in C++ the
> > vtkRenderWindow object will catch the WM_DESTROY messages and invoke
> > appropriate methods to delete the object.  Otherwise, if the flag is off,
> > the responsibility of destroying the object is up to the user.  It seems
> > weird that the vtkRenderWindow goes through all the trouble of creating
> > the window, but then doesn't provide any functionality for handling its
> > deletion.  Just a thought.
>
> What do you consider to be a correct and generic way to handle this event?
> The RenderWindow could e.g. have a reference count of 10, meaning that 10
> other objects expect it to exist.  If a destroy handler were impudent
> enough to delete the object in spite of this, the application is on its way
> to segfault/program error heaven.
>
> One could argue that the default handler could remove all Renderers and
> RenderWindowInteractors, but that still would not guarantee a RenderWindow
> that is ready to be destroyed.  Remember than ANY object can take out a
> reference on a VTK instance.
-------------- next part --------------
CMAKE_MINIMUM_REQUIRED(VERSION 1.6)
PROJECT(TestRenderWindow)
INCLUDE_REGULAR_EXPRESSION("^.*$")

# Tell CMake's FIND_PACKAGE command where to look for our Find<pkg>
# modules.
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${TestRenderWindow_SOURCE_DIR})

# Don't build anything unless the version of CMake is high enough.
# The matching ELSE/ENDIF should be the last lines in the file.
IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.5)

FIND_PACKAGE(VTK)
IF(VTK_FOUND)
	INCLUDE(${VTK_USE_FILE})
ELSE(VTK_FOUND)
	MESSAGE(FATAL_ERROR
		"Cannot build TestRenderWindow without VTK.  Please set VTK_DIR.")
ENDIF(VTK_FOUND)

# Look for OpenGL.
FIND_PACKAGE(OpenGL)

# If the version of CMake was too old, complain and build nothing.
# These should be the last lines in this file.
ELSE("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.5)
  MESSAGE(SEND_ERROR
          "This version of CMake is too old to build TestRenderWindow.  "
          "Please upgrade to CMake 1.6.")
ENDIF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 1.5)


INCLUDE_DIRECTORIES(
  ${TestRenderWindow_SOURCE_DIR}
)

SET(TestRenderWindow_SRCS
TestRenderWindow.cxx
)

ADD_EXECUTABLE(TestRenderWindow ${TestRenderWindow_SRCS})

TARGET_LINK_LIBRARIES(TestRenderWindow 
vtkCommon
vtkRendering
vtkImaging
vtkGraphics
vtkFiltering
)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestRenderWindow.cxx
Type: text/x-c++src
Size: 1231 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20030302/df3bfe4c/attachment.cxx>


More information about the vtkusers mailing list