[vtk-developers] RE: vtkTkRenderWidget.cxx breaks Win (Borland) builds

dean.inglis at on.aibn.com dean.inglis at on.aibn.com
Mon Sep 2 17:18:34 EDT 2002


Hi,

the changet to vtkTkRenderWidget on Friday has broken my CVS builds of VTK.  I have a couple of suggestions for a fix:

1) move the function body and remove VTK_TK_EXPORT as in
<snip>
extern "C" {
int vtkImageDataToTkPhoto_Cmd (ClientData clientData, Tcl_Interp *interp,
                         int argc, char **argv)
{
<snip>
to between the function bodys for vtkTkRenderWidget_Cmd and vtkTkRenderWidget_RW

and make the vtkTkRenderWidget_Init:
<snip>
//----------------------------------------------------------------------------
// vtkTkRenderWidget_Init
// Called upon system startup to create vtkTkRenderWidget command.
extern "C" {int VTK_TK_EXPORT Vtktkrenderwidget_Init(Tcl_Interp *interp);}
int VTK_TK_EXPORT Vtktkrenderwidget_Init(Tcl_Interp *interp)
{
  if (Tcl_PkgProvide(interp,(char *)"Vtktkrenderwidget",(char *)"1.2") != TCL_OK) 
    {
    return TCL_ERROR;
    }
  
  Tcl_CreateCommand(interp, (char *) "vtkTkRenderWidget", vtkTkRenderWidget_Cmd, 
                    Tk_MainWindow(interp), NULL);
  
  Tcl_CreateCommand(interp, (char *) "vtkImageDataToTkPhoto", vtkImageDataToTkPhoto_Cmd, 
                    NULL, NULL );

  return TCL_OK;
}
<snip>


2) once a z slice is selected, in vtkImageDataToTkPhoto_Cmd, subsequent calls to vtkImageDataToTkPhoto with a z-slice arg fails to change the z slice due to:   
<snip>
  extent[4] = extent[5] = z;
  image->SetUpdateExtent ( extent );
  image->Update();
<snip>

So, one way to accomodate say a scroll bar widget, are to have static vars :
<snip>
  static int zmin;
  static int zmax;
  int extent[6];
  image->GetExtent ( extent );
  if(extent[4] != extent[5])
    {
    zmin = extent[4];
    zmax = extent[5];
    }
  else
    {
    extent[4] = zmin;
    extent[5] = zmax;
    }
<snip>
 to reset the imagedata extents. I don't know if any of the above will choke other compilers.

Dean

PS
A tcl example to illustrate:
(sorry, but I don't know how to mime encode)

#////////////////////////////////////////////////
package require vtk
package require vtkinteraction

# Image pipeline

vtkVolume16Reader reader
  reader SetDataDimensions 64 64  
  reader SetDataByteOrderToLittleEndian  
  reader SetFilePrefix "$VTK_DATA_ROOT/Data/headsq/quarter"   
  reader SetImageRange 1 93  
  reader SetDataSpacing 3.2 3.2 1.5  
  reader Update 

vtkImageShiftScale cast
cast SetInput [reader GetOutput]
cast SetOutputScalarTypeToUnsignedChar
cast ClampOverflowOn
cast Update
set photo [image create photo]
set extents [[cast GetOutput] GetExtent]
set z0 [lindex $extents 4] 
set z1 [lindex $extents 5] 
vtkImageDataToTkPhoto [cast GetOutput] $photo $z0

set range [[reader GetOutput] GetScalarRange]
set l [lindex $range 0]
set h [lindex $range 1]

wm withdraw .
toplevel .c
wm title .c "Tcl Version of vtkImageDataToTkPhoto"
wm protocol .c WM_DELETE_WINDOW ::vtk::cb_exit

pack [button .c.b -image $photo]
pack [scale .c.w -label Window -orient horizontal -from 1 -to [expr ($h - $l) / 2] -command SetWindow ] -fill x -expand 1
pack [scale .c.l -label Level -orient horizontal -from $l -to $h -command SetWindow ] -fill x -expand 1

pack [scale .c.z -label Z -orient horizontal -from $z0 -to $z1 -command SetWindow ] -fill x -expand 1

.c.w set 500
.c.l set 153

# Scale = 255 / window
# Shift = Window / 2 - level
proc SetWindow { foo } {
  global cast photo
  set Window [.c.w get]
  set Level [.c.l get]
  cast SetScale [expr 255.0 / $Window]
  cast SetShift [expr $Window / 2.0 - $Level]
  vtkImageDataToTkPhoto [cast GetOutput] $photo [.c.z get]
}
#///////////////////////////////////////////////////





More information about the vtk-developers mailing list