Hi,<br><br>I have a vtk application to display a dicom image.I am trying to create a button on main panel which when clicked opens up the directory tree and we can choose the dicom image files to be displayed in this application. I am using vtkkwloadsavebutton for 
this.I tried creating a callback function. On running the code, I get the loadsave button but after selecting a file, the program crashes. I can't figure out what's wrong.<br>I am attaching my complete code. It would be a great help if anyone in the list can help me figure out what's going wrong. I have just modified the MedicalImageViewer example from KWWidgets and am using the same 
cmakelists.txt file also.<br><br>Thanks,<br>Ashish<br>-----------------------------------------------<br>file 1- vtkKWMyWindow.h---below<br>--------------------------------------------------<br>#ifndef __vtkKWMyWindow_h<br>
#define __vtkKWMyWindow_h<br><br>#include &quot;vtkKWWindow.h&quot;<br><br>class vtkKWRenderWidget;<br>class vtkImageViewer2;<br>class vtkKWScale;<br>class vtkKWWindowLevelPresetSelector;<br>class vtkKWSimpleAnimationWidget;
<br>class vtkKWLoadSaveButton;<br>class vtkDICOMImageReader;<br>class vtkImageData;<br><br>class vtkKWMyWindow : public vtkKWWindow<br>{<br>public:<br>&nbsp; static vtkKWMyWindow* New();<br>&nbsp; vtkTypeRevisionMacro(vtkKWMyWindow,vtkKWWindow);
<br>&nbsp; virtual void mycallback();<br><br>protected:<br>&nbsp; vtkKWMyWindow();<br>&nbsp; ~vtkKWMyWindow();<br><br>&nbsp; // Description:<br>&nbsp; // Create the widget.<br>&nbsp; virtual void CreateWidget();<br><br>&nbsp; vtkImageViewer2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *ImageViewer;
<br>&nbsp; vtkKWRenderWidget&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *RenderWidget;<br>&nbsp; vtkKWLoadSaveButton&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *myLoadSaveButton;<br>&nbsp; vtkDICOMImageReader&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *mydicom;<br>&nbsp; vtkImageData&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *img_data;<br><br>&nbsp;// virtual void UpdateSliceRanges();
<br><br>private:<br>&nbsp; vtkKWMyWindow(const vtkKWMyWindow&amp;);&nbsp;&nbsp; // Not implemented.<br>&nbsp; void operator=(const vtkKWMyWindow&amp;);&nbsp; // Not implemented.<br>};<br><br>#endif<br>------------------------------------------------------
<br>file 2- vtkKWMyWindow.cxx---below<br>-----------------------------------------------------<br>#include &quot;vtkKWMyWindow.h&quot;<br><br>#include &quot;vtkCornerAnnotation.h&quot;<br>#include &quot;vtkImageData.h&quot;
<br>#include &quot;vtkImageViewer2.h&quot;<br>#include &quot;vtkKWApplication.h&quot;<br>#include &quot;vtkKWFrame.h&quot;<br>#include &quot;vtkKWFrameWithLabel.h&quot;<br>#include &quot;vtkKWMenu.h&quot;<br>#include &quot; 
vtkKWMenuButton.h&quot;<br>#include &quot;vtkKWMenuButtonWithSpinButtons.h&quot;<br>#include &quot;vtkKWMenuButtonWithSpinButtonsWithLabel.h&quot;<br>#include &quot;vtkKWNotebook.h&quot;<br>#include &quot;vtkKWRenderWidget.h
 &quot;<br>#include &quot;vtkKWScale.h&quot;<br>#include &quot;vtkKWSimpleAnimationWidget.h&quot;<br>#include &quot;vtkKWWindow.h&quot;<br>#include &quot;vtkKWWindowLevelPresetSelector.h&quot;<br>#include &quot;vtkObjectFactory.h
 &quot;<br>#include &quot;vtkRenderWindow.h&quot;<br>#include &quot;vtkRenderWindowInteractor.h&quot;<br>#include &quot;vtkXMLImageDataReader.h&quot;<br><br>#include &quot;vtkKWLoadSaveButton.h&quot;<br>#include &quot;vtkKWLoadSaveDialog.h
 &quot;<br>#include &quot;vtkDICOMImageReader.h&quot;<br><br>#include &quot;vtkKWWidgetsPaths.h&quot;<br>#include &quot;vtkToolkits.h&quot;<br><br>#include &lt;vtksys/SystemTools.hxx&gt;<br><br>vtkStandardNewMacro( vtkKWMyWindow );
<br>vtkCxxRevisionMacro(vtkKWMyWindow, &quot;$Revision: 1.2 $&quot;);<br><br><br>vtkKWMyWindow::vtkKWMyWindow()<br>{<br>&nbsp; this-&gt;RenderWidget = NULL;<br>&nbsp; this-&gt;ImageViewer = NULL;<br>&nbsp; this-&gt;mydicom = NULL;<br>&nbsp; this-&gt;myLoadSaveButton = NULL;
<br>&nbsp; this-&gt;img_data = NULL;<br>}<br><br>vtkKWMyWindow::~vtkKWMyWindow()<br>{<br>&nbsp; if (this-&gt;ImageViewer)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; this-&gt;ImageViewer-&gt;Delete();<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; if (this-&gt;RenderWidget)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; this-&gt;RenderWidget-&gt;Delete();
<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; if(this-&gt;mydicom)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;mydicom-&gt;Delete();<br>&nbsp; if(this-&gt;myLoadSaveButton)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;myLoadSaveButton-&gt;Delete();<br>&nbsp; if(this-&gt;img_data)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;img_data-&gt;Delete();
<br><br>}<br><br>void vtkKWMyWindow::CreateWidget()<br>{<br>&nbsp; // Check if already created<br><br>&nbsp; if (this-&gt;IsCreated())<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; vtkErrorMacro(&quot;class already created&quot;);<br>&nbsp;&nbsp;&nbsp; return;<br>&nbsp;&nbsp;&nbsp; }<br><br>
&nbsp; // Call the superclass to create the whole widget<br><br>&nbsp; this-&gt;Superclass::CreateWidget();<br><br>&nbsp; vtkKWApplication *app = this-&gt;GetApplication();<br><br>&nbsp; // Add a render widget, attach it to the view frame, and pack
<br><br>&nbsp; if (!this-&gt;RenderWidget)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; this-&gt;RenderWidget = vtkKWRenderWidget::New();<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; this-&gt;RenderWidget-&gt;SetParent(this-&gt;GetViewFrame());<br>&nbsp; this-&gt;RenderWidget-&gt;Create();<br>
&nbsp; this-&gt;RenderWidget-&gt;ResetCamera();<br>&nbsp; this-&gt;RenderWidget-&gt;CornerAnnotationVisibilityOn();<br><br>&nbsp; app-&gt;Script(&quot;pack %s -expand y -fill both -anchor c -expand y&quot;,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;RenderWidget-&gt;GetWidgetName());
<br><br>&nbsp; //create loadsavebutton<br>&nbsp; if(!this-&gt;myLoadSaveButton)<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;myLoadSaveButton = vtkKWLoadSaveButton::New();<br>&nbsp; }<br>&nbsp; this-&gt;myLoadSaveButton-&gt;SetParent(this-&gt;GetMainPanelFrame());
<br>&nbsp; this-&gt;myLoadSaveButton-&gt;Create();<br>&nbsp; this-&gt;myLoadSaveButton-&gt;SetText(&quot;Click to Pick a File&quot;);<br>&nbsp; this-&gt;myLoadSaveButton-&gt;GetLoadSaveDialog()-&gt;SaveDialogOff();<br>&nbsp; this-&gt;myLoadSaveButton-&gt;GetLoadSaveDialog()-&gt;SetFileTypes(&quot;{ {Dicom Document} {.dcm} }&quot;);
<br><br>&nbsp; this-&gt;myLoadSaveButton-&gt;SetCommand(this, &quot;mycallback&quot;);<br><br>&nbsp; app-&gt;Script(&quot;pack %s -side top -anchor nw -expand n -padx 2 -pady 2&quot;,this-&gt;myLoadSaveButton-&gt;GetWidgetName());<br>
//&nbsp; this-&gt;RenderWidget-&gt;ResetCamera();<br><br>}<br><br>void vtkKWMyWindow::mycallback()<br>{<br>&nbsp;&nbsp;&nbsp; this-&gt;mydicom-&gt;SetFileName(this-&gt;myLoadSaveButton-&gt;GetLoadSaveDialog()-&gt;GetFileName());<br>//&nbsp;&nbsp;&nbsp; this-&gt;mydicom-&gt;Update();
<br><br>&nbsp;&nbsp;&nbsp; /*if (!this-&gt;ImageViewer)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;ImageViewer = vtkImageViewer2::New();<br>&nbsp;&nbsp;&nbsp; }*/<br>//&nbsp;&nbsp;&nbsp; this-&gt;ImageViewer-&gt;SetRenderWindow(this-&gt;RenderWidget-&gt;GetRenderWindow());<br>//&nbsp;&nbsp;&nbsp; this-&gt;ImageViewer-&gt;SetInput(this-&gt;mydicom-&gt;GetOutput());
<br>//&nbsp;&nbsp;&nbsp; this-&gt;ImageViewer-&gt;SetupInteractor(this-&gt;RenderWidget-&gt;GetRenderWindow()-&gt;GetInteractor());<br>//&nbsp;&nbsp;&nbsp; this-&gt;ImageViewer-&gt;Render();<br><br>&nbsp;&nbsp;&nbsp; this-&gt;img_data = this-&gt;mydicom-&gt;GetOutput();
<br>&nbsp;&nbsp;&nbsp; double *range = this-&gt;img_data-&gt;GetScalarRange();<br>&nbsp;&nbsp;&nbsp; this-&gt;ImageViewer-&gt;SetColorWindow(range[1] - range[0]);<br>&nbsp;&nbsp;&nbsp; this-&gt;ImageViewer-&gt;SetColorLevel(0.5 * (range[1] + range[0]));<br>&nbsp;&nbsp;&nbsp; this-&gt;ImageViewer-&gt;SetInput(img_data);
<br>&nbsp;&nbsp;&nbsp; this-&gt;ImageViewer-&gt;Render();<br><br>}<br>----------------------------------------------------------------------------<br>file 3-KWMedicalImageViewerExample.cxx---below<br>---------------------------------------------------------------------------
<br>#include &quot;vtkKWApplication.h&quot;<br>#include &quot;vtkKWMyWindow.h&quot;<br><br>#include &lt;vtksys/SystemTools.hxx&gt;<br>#include &lt;vtksys/CommandLineArguments.hxx&gt;<br><br>extern &quot;C&quot; int Kwmedicalimageviewerexamplelib_Init(Tcl_Interp *interp);
<br><br>int my_main(int argc, char *argv[])<br>{<br>&nbsp; // Initialize Tcl<br><br>&nbsp; Tcl_Interp *interp = vtkKWApplication::InitializeTcl(argc, argv, &amp;cerr);<br>&nbsp; if (!interp)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; cerr &lt;&lt; &quot;Error: InitializeTcl failed&quot; &lt;&lt; endl ;
<br>&nbsp;&nbsp;&nbsp; return 1;<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp; // Initialize our Tcl library (i.e. our classes wrapped in Tcl).<br>&nbsp; // This *is* required for the C++ methods to be used as callbacks.<br>&nbsp; // See comment at the top of this file.<br>
<br>&nbsp; Kwmedicalimageviewerexamplelib_Init(interp);<br><br>&nbsp; // Process some command-line arguments<br>&nbsp; // The --test option here is used to run this example as a non-interactive<br>&nbsp; // test for software quality purposes. You can ignore it.
<br><br>&nbsp; int option_test = 0;<br>&nbsp; vtksys::CommandLineArguments args;<br>&nbsp; args.Initialize(argc, argv);<br>&nbsp; args.AddArgument(<br>&nbsp;&nbsp;&nbsp; &quot;--test&quot;, vtksys::CommandLineArguments::NO_ARGUMENT, &amp;option_test, &quot;&quot;);
<br>&nbsp; args.Parse();<br>&nbsp;<br>&nbsp; // Create the application<br>&nbsp; // If --test was provided, ignore all registry settings, and exit silently<br>&nbsp; // Restore the settings that have been saved to the registry, like<br>&nbsp; // the geometry of the user interface so far.
<br><br>&nbsp; vtkKWApplication *app = vtkKWApplication::New();<br>&nbsp; app-&gt;SetName(&quot;KWMedicalImageViewerExample&quot;);<br>&nbsp; if (option_test)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; app-&gt;SetRegistryLevel(0);<br>&nbsp;&nbsp;&nbsp; app-&gt;PromptBeforeExitOff();
<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; app-&gt;RestoreApplicationSettingsFromRegistry();<br><br>&nbsp; // Set a help link. Can be a remote link (URL), or a local file<br><br>&nbsp; app-&gt;SetHelpDialogStartingPage(&quot; <a href="http://www.kwwidgets.org">
http://www.kwwidgets.org</a>&quot;);<br><br>&nbsp; // Add our window<br>&nbsp; // Set 'SupportHelp' to automatically add a menu entry for the help link<br><br>&nbsp; vtkKWMyWindow *win = vtkKWMyWindow::New();<br>&nbsp; win-&gt;SupportHelpOn();
<br>&nbsp; app-&gt;AddWindow(win);<br>&nbsp; win-&gt;Create();<br>&nbsp; //win-&gt;SecondaryPanelVisibilityOff();<br>&nbsp;&nbsp;&nbsp; std::cout&lt;&lt;&quot;hi&quot;&lt;&lt;&quot;\n&quot;;<br><br>&nbsp; // Start the application<br>&nbsp; // If --test was provided, do not enter the event loop and run this example
<br>&nbsp; // as a non-interactive test for software quality purposes.<br><br>&nbsp; int ret = 0;<br>&nbsp; win-&gt;Display();<br>&nbsp; if (!option_test)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; app-&gt;Start(argc, argv);<br>&nbsp;&nbsp;&nbsp; ret = app-&gt;GetExitStatus();<br>&nbsp;&nbsp;&nbsp; }
<br>&nbsp; win-&gt;Close();<br><br>&nbsp; // Deallocate and exit<br><br>&nbsp; win-&gt;Delete();<br>&nbsp; app-&gt;Delete();<br>&nbsp;<br>&nbsp; return ret;<br>}<br><br>#if defined(_WIN32) &amp;&amp; !defined(__CYGWIN__)<br>#include &lt;windows.h&gt;<br>
int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int)<br>{<br>&nbsp; int argc;<br>&nbsp; char **argv;<br>&nbsp; vtksys::SystemTools::ConvertWindowsCommandLineToUnixArguments(<br>&nbsp;&nbsp;&nbsp; lpCmdLine, &amp;argc, &amp;argv);<br>&nbsp; int ret = my_main(argc, argv);
<br>&nbsp; for (int i = 0; i &lt; argc; i++) { delete [] argv[i]; }<br>&nbsp; delete [] argv;<br>&nbsp; return ret;<br>}<br>#else<br>int main(int argc, char *argv[])<br>{<br>&nbsp; return my_main(argc, argv);<br>}<br>#endif<br>-----------------------