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 "vtkKWWindow.h"<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> static vtkKWMyWindow* New();<br> vtkTypeRevisionMacro(vtkKWMyWindow,vtkKWWindow);
<br> virtual void mycallback();<br><br>protected:<br> vtkKWMyWindow();<br> ~vtkKWMyWindow();<br><br> // Description:<br> // Create the widget.<br> virtual void CreateWidget();<br><br> vtkImageViewer2 *ImageViewer;
<br> vtkKWRenderWidget *RenderWidget;<br> vtkKWLoadSaveButton *myLoadSaveButton;<br> vtkDICOMImageReader *mydicom;<br> vtkImageData *img_data;<br><br> // virtual void UpdateSliceRanges();
<br><br>private:<br> vtkKWMyWindow(const vtkKWMyWindow&); // Not implemented.<br> void operator=(const vtkKWMyWindow&); // Not implemented.<br>};<br><br>#endif<br>------------------------------------------------------
<br>file 2- vtkKWMyWindow.cxx---below<br>-----------------------------------------------------<br>#include "vtkKWMyWindow.h"<br><br>#include "vtkCornerAnnotation.h"<br>#include "vtkImageData.h"
<br>#include "vtkImageViewer2.h"<br>#include "vtkKWApplication.h"<br>#include "vtkKWFrame.h"<br>#include "vtkKWFrameWithLabel.h"<br>#include "vtkKWMenu.h"<br>#include "
vtkKWMenuButton.h"<br>#include "vtkKWMenuButtonWithSpinButtons.h"<br>#include "vtkKWMenuButtonWithSpinButtonsWithLabel.h"<br>#include "vtkKWNotebook.h"<br>#include "vtkKWRenderWidget.h
"<br>#include "vtkKWScale.h"<br>#include "vtkKWSimpleAnimationWidget.h"<br>#include "vtkKWWindow.h"<br>#include "vtkKWWindowLevelPresetSelector.h"<br>#include "vtkObjectFactory.h
"<br>#include "vtkRenderWindow.h"<br>#include "vtkRenderWindowInteractor.h"<br>#include "vtkXMLImageDataReader.h"<br><br>#include "vtkKWLoadSaveButton.h"<br>#include "vtkKWLoadSaveDialog.h
"<br>#include "vtkDICOMImageReader.h"<br><br>#include "vtkKWWidgetsPaths.h"<br>#include "vtkToolkits.h"<br><br>#include <vtksys/SystemTools.hxx><br><br>vtkStandardNewMacro( vtkKWMyWindow );
<br>vtkCxxRevisionMacro(vtkKWMyWindow, "$Revision: 1.2 $");<br><br><br>vtkKWMyWindow::vtkKWMyWindow()<br>{<br> this->RenderWidget = NULL;<br> this->ImageViewer = NULL;<br> this->mydicom = NULL;<br> this->myLoadSaveButton = NULL;
<br> this->img_data = NULL;<br>}<br><br>vtkKWMyWindow::~vtkKWMyWindow()<br>{<br> if (this->ImageViewer)<br> {<br> this->ImageViewer->Delete();<br> }<br> if (this->RenderWidget)<br> {<br> this->RenderWidget->Delete();
<br> }<br> if(this->mydicom)<br> this->mydicom->Delete();<br> if(this->myLoadSaveButton)<br> this->myLoadSaveButton->Delete();<br> if(this->img_data)<br> this->img_data->Delete();
<br><br>}<br><br>void vtkKWMyWindow::CreateWidget()<br>{<br> // Check if already created<br><br> if (this->IsCreated())<br> {<br> vtkErrorMacro("class already created");<br> return;<br> }<br><br>
// Call the superclass to create the whole widget<br><br> this->Superclass::CreateWidget();<br><br> vtkKWApplication *app = this->GetApplication();<br><br> // Add a render widget, attach it to the view frame, and pack
<br><br> if (!this->RenderWidget)<br> {<br> this->RenderWidget = vtkKWRenderWidget::New();<br> }<br> this->RenderWidget->SetParent(this->GetViewFrame());<br> this->RenderWidget->Create();<br>
this->RenderWidget->ResetCamera();<br> this->RenderWidget->CornerAnnotationVisibilityOn();<br><br> app->Script("pack %s -expand y -fill both -anchor c -expand y",<br> this->RenderWidget->GetWidgetName());
<br><br> //create loadsavebutton<br> if(!this->myLoadSaveButton)<br> {<br> this->myLoadSaveButton = vtkKWLoadSaveButton::New();<br> }<br> this->myLoadSaveButton->SetParent(this->GetMainPanelFrame());
<br> this->myLoadSaveButton->Create();<br> this->myLoadSaveButton->SetText("Click to Pick a File");<br> this->myLoadSaveButton->GetLoadSaveDialog()->SaveDialogOff();<br> this->myLoadSaveButton->GetLoadSaveDialog()->SetFileTypes("{ {Dicom Document} {.dcm} }");
<br><br> this->myLoadSaveButton->SetCommand(this, "mycallback");<br><br> app->Script("pack %s -side top -anchor nw -expand n -padx 2 -pady 2",this->myLoadSaveButton->GetWidgetName());<br>
// this->RenderWidget->ResetCamera();<br><br>}<br><br>void vtkKWMyWindow::mycallback()<br>{<br> this->mydicom->SetFileName(this->myLoadSaveButton->GetLoadSaveDialog()->GetFileName());<br>// this->mydicom->Update();
<br><br> /*if (!this->ImageViewer)<br> {<br> this->ImageViewer = vtkImageViewer2::New();<br> }*/<br>// this->ImageViewer->SetRenderWindow(this->RenderWidget->GetRenderWindow());<br>// this->ImageViewer->SetInput(this->mydicom->GetOutput());
<br>// this->ImageViewer->SetupInteractor(this->RenderWidget->GetRenderWindow()->GetInteractor());<br>// this->ImageViewer->Render();<br><br> this->img_data = this->mydicom->GetOutput();
<br> double *range = this->img_data->GetScalarRange();<br> this->ImageViewer->SetColorWindow(range[1] - range[0]);<br> this->ImageViewer->SetColorLevel(0.5 * (range[1] + range[0]));<br> this->ImageViewer->SetInput(img_data);
<br> this->ImageViewer->Render();<br><br>}<br>----------------------------------------------------------------------------<br>file 3-KWMedicalImageViewerExample.cxx---below<br>---------------------------------------------------------------------------
<br>#include "vtkKWApplication.h"<br>#include "vtkKWMyWindow.h"<br><br>#include <vtksys/SystemTools.hxx><br>#include <vtksys/CommandLineArguments.hxx><br><br>extern "C" int Kwmedicalimageviewerexamplelib_Init(Tcl_Interp *interp);
<br><br>int my_main(int argc, char *argv[])<br>{<br> // Initialize Tcl<br><br> Tcl_Interp *interp = vtkKWApplication::InitializeTcl(argc, argv, &cerr);<br> if (!interp)<br> {<br> cerr << "Error: InitializeTcl failed" << endl ;
<br> return 1;<br> }<br><br> // Initialize our Tcl library (i.e. our classes wrapped in Tcl).<br> // This *is* required for the C++ methods to be used as callbacks.<br> // See comment at the top of this file.<br>
<br> Kwmedicalimageviewerexamplelib_Init(interp);<br><br> // Process some command-line arguments<br> // The --test option here is used to run this example as a non-interactive<br> // test for software quality purposes. You can ignore it.
<br><br> int option_test = 0;<br> vtksys::CommandLineArguments args;<br> args.Initialize(argc, argv);<br> args.AddArgument(<br> "--test", vtksys::CommandLineArguments::NO_ARGUMENT, &option_test, "");
<br> args.Parse();<br> <br> // Create the application<br> // If --test was provided, ignore all registry settings, and exit silently<br> // Restore the settings that have been saved to the registry, like<br> // the geometry of the user interface so far.
<br><br> vtkKWApplication *app = vtkKWApplication::New();<br> app->SetName("KWMedicalImageViewerExample");<br> if (option_test)<br> {<br> app->SetRegistryLevel(0);<br> app->PromptBeforeExitOff();
<br> }<br> app->RestoreApplicationSettingsFromRegistry();<br><br> // Set a help link. Can be a remote link (URL), or a local file<br><br> app->SetHelpDialogStartingPage(" <a href="http://www.kwwidgets.org">
http://www.kwwidgets.org</a>");<br><br> // Add our window<br> // Set 'SupportHelp' to automatically add a menu entry for the help link<br><br> vtkKWMyWindow *win = vtkKWMyWindow::New();<br> win->SupportHelpOn();
<br> app->AddWindow(win);<br> win->Create();<br> //win->SecondaryPanelVisibilityOff();<br> std::cout<<"hi"<<"\n";<br><br> // Start the application<br> // If --test was provided, do not enter the event loop and run this example
<br> // as a non-interactive test for software quality purposes.<br><br> int ret = 0;<br> win->Display();<br> if (!option_test)<br> {<br> app->Start(argc, argv);<br> ret = app->GetExitStatus();<br> }
<br> win->Close();<br><br> // Deallocate and exit<br><br> win->Delete();<br> app->Delete();<br> <br> return ret;<br>}<br><br>#if defined(_WIN32) && !defined(__CYGWIN__)<br>#include <windows.h><br>
int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int)<br>{<br> int argc;<br> char **argv;<br> vtksys::SystemTools::ConvertWindowsCommandLineToUnixArguments(<br> lpCmdLine, &argc, &argv);<br> int ret = my_main(argc, argv);
<br> for (int i = 0; i < argc; i++) { delete [] argv[i]; }<br> delete [] argv;<br> return ret;<br>}<br>#else<br>int main(int argc, char *argv[])<br>{<br> return my_main(argc, argv);<br>}<br>#endif<br>-----------------------