<span class="gmail_quote"></span>Hi Yumin,<br><br>Thanks for replying. I checked my code again. I don't think there is any problem with the VTK part in there. I can successfully read a dicom image and display it. Currently the file to be read is hard coded in the VTK code and I wanted to add this KWWidgets based filedialog to allow a user to choose the file to be displayed.
<br>I also tried using the code that you sent me, to display the image in this example, but even that doesn't work.<br>I am attaching my complete code along with a single dicom file for testing(for that matter any jpeg file with appropriate code modifications would work for testing). It would be a great help if you or anyone in the list can help me figure out what's going wrong. I have just modified the MedicalImageViewer example 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<span class="q"><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></span>
// this->RenderWidget->ResetCamera();<span class="q"><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></span>
// this->ImageViewer->SetInput(this->mydicom->GetOutput());
<span class="q"><br>// this->ImageViewer->SetupInteractor(this->RenderWidget->GetRenderWindow()->GetInteractor());<br>// this->ImageViewer->Render();<br><br></span> this->img_data = this->mydicom->GetOutput();
<br> double *range = this->img_data->GetScalarRange();<span class="q"><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></span>----------------------------------------------------------------------------<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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
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>--------------------------
<div><span class="e" id="q_10f77f8ad4f6ffbb_9"><br><br><div><span class="gmail_quote">On 12/11/06, <b class="gmail_sendername">Yumin Yuan</b> <<a href="mailto:yumin.yuan@kitware.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
yumin.yuan@kitware.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Ashish,<br><br>Since I do not have the DICOM files you are using, here are a couple thoughts:<br><br>1. Tell us on which line of code it is crashing.<br><br>2. Make sure the vtkDICOMImageReader can read your files.<br>
If it is crashing on "img2->Update()", or<br>"this->ImageViewer->SetInput(img_data);"<br>or "this->ImageViewer->Render();"<br><br>your problem is more appropriate on the VTK users mailing list:
<br><br><a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.vtk.org/mailman/listinfo/vtkusers</a><br><br>3. Here are the documentation for vtkImageViewer2 (for displaying 2D
<br>image) and vtkDICOMImageReader
<br><a href="http://www.vtk.org/doc/nightly/html/classvtkDICOMImageReader.html" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.vtk.org/doc/nightly/html/classvtkDICOMImageReader.html</a>
<br><a href="http://www.vtk.org/doc/nightly/html/classvtkImageViewer2.html" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://www.vtk.org/doc/nightly/html/classvtkImageViewer2.html</a><br><br>4. Use the following code to display the image:<br><br> vtkImageData *img_data = img2->GetOutput();<br> double *range = 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>5. If you could be more specific on your problem, such as which line<br>of code is crashing, it will save us a great deal of time to find a<br>solution.<br><br>Hope this helps,<br><br>-Yumin<br>-----------------------------
<br>Yumin Yuan<br>R&D Engineer<br>Kitware Inc.<br><br><br>On 12/11/06, Ashish Singh <<a href="mailto:mrasingh@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">mrasingh@gmail.com</a>
> wrote:<br>> Hi,<br>><br>> Can someone please tell me how to resolve this problem? I am stuck here and
<br>> can't figure out what's going wrong.<br>><br>> Thanks,<br>> Ashish<br>><br>><br>> On 12/8/06, Ashish Singh <<a href="mailto:mrasingh@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
mrasingh@gmail.com</a>> wrote:<br>> > Thanks Yumin.
<br>> > I tried creating a callback function. On running the code, I get the<br>> loadsave button but after selecting a file, the program crashes. I can't<br>> figure out what's wrong. Here is my code. Can you please tell me where I am
<br>> going wrong and how to get it to work?<br>> ><br>> > ---part of my code----<br>> > .<br>> > .<br>> > .<br>> ><br>> > if(!this->myLoadSaveButton)<br>> > {<br>
> > this->myLoadSaveButton = vtkKWLoadSaveButton::New();
<br>> > }<br>> ><br>> this->myLoadSaveButton->SetParent(this->GetMainPanelFrame());<br>> > this->myLoadSaveButton->Create();<br>> > this->myLoadSaveButton->SetText("Click to Pick a
<br>> File");<br>> ><br>> this->myLoadSaveButton->GetLoadSaveDialog()->SaveDialogOff();<br>> ><br>> this->myLoadSaveButton->GetLoadSaveDialog()->SetFileTypes("{<br>> {Dicom Document} {.dcm} }");
<br>> > this->myLoadSaveButton->SetCommand(this,"mycallback");<br>> ><br>> > app->Script("pack %s -side top -anchor nw -expand n -padx 2 -pady<br>> 2",this->myLoadSaveButton->GetWidgetName());
<br>> > .<br>> > .<br>> > void vtkKWMyWindow::mycallback()<br>> > {<br>> ><br>> this->mydicom->SetFileName(this->myLoadSaveButton->GetLoadSaveDialog()->GetFileName());<br>> > this->mydicom->Update();
<br>> > if (!this->ImageViewer)<br>> > {<br>> > this->ImageViewer = vtkImageViewer2::New();<br>> > }<br>> ><br>> this->ImageViewer->SetRenderWindow(this->RenderWidget->GetRenderWindow());
<br>> ><br>> this->ImageViewer->SetRenderer(this->RenderWidget->GetRenderer());<br>> ><br>> this->ImageViewer->SetInput(this->mydicom->GetOutput());<br>> ><br>> this->ImageViewer->SetupInteractor(this->RenderWidget->GetRenderWindow()->GetInteractor());
<br>> > this->ImageViewer->Render();<br>> ><br>> > }<br>> ><br>> > Thanks,<br>> > Ashish<br>> > ---------<br>> ><br>> ><br>> ><br>> > On 12/6/06, Yumin Yuan <
<a href="mailto:yumin.yuan@kitware.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">yumin.yuan@kitware.com</a> > wrote:<br>> > > Hi Ashish,<br>> > ><br>> > > The problem is the
<br>> "load_button1->GetLoadSaveDialog()->GetFileName()"
<br>> > > returns NULL in your code.<br>> > ><br>> > > Two options here:<br>> > ><br>> > > 1. Use vtkKWLoadSaveDialog directly, instead of the<br>> > > vtkKWLoadSaveButton, and call Invoke() on the dialog before
<br>> > > GetFileName().<br>> > > Also, check dialog status "GetStatus() == vtkKWDialog::StatusOK"<br>> > ><br>> > ><br>> > > 2. If you want to use vtkKWLoadSaveButton, try to add a callback to the
<br>> button:<br>> > ><br>> > > for example:<br>> > ><br>> > > this->load_button1->SetCommand( this, "SelectFileCallback");<br>> > ><br>> > > before packing statement.
<br>> > ><br>> > > > app->Script("pack %s -side top -anchor nw -expand n -padx 2 -pady<br>> > > > 2",load_button1->GetWidgetName());<br>> > ><br>> > > Then, put your file loading code in the callback function
<br>> > ><br>> > > void yourclass::SelectFileCallback()<br>> > > {<br>> > ><br>> > > //Check dialog status "GetStatus() == vtkKWDialog::StatusOK"<br>> > ><br>
> > > > vtkDICOMImageReader<br>> *img2=vtkDICOMImageReader::New();<br>> > > ><br>> > > ><br>> img2->SetFileName(load_button1->GetLoadSaveDialog()->GetFileName());<br>
> > > > img2->Update();
<br>> > > ><br>> > > > vtkImageViewer2 * myviewer=vtkImageViewer2::New();<br>> > > > myviewer->SetInput(img2->GetOutput());<br>> > > > myviewer->SetColorWindow(2000);
<br>> > > > myviewer->SetColorLevel(1500);<br>> > > > myviewer->Render();<br>> > ><br>> > > }<br>> > ><br>> > ><br>> > > -Yumin<br>> > >
<br>> > > On 12/6/06, Ashish Singh <<a href="mailto:mrasingh@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">mrasingh@gmail.com</a> > wrote:<br>> > > > Hi,<br>
> > > ><br>> > > > I have a vtk application to display a dicom
image.I am trying to<br>> create a<br>> > > > button on main panel which when clicked opens up the directory tree<br>> and we<br>> > > > can choose the dicom image files to be displayed in this application.
<br>> I am<br>> > > > using vtkkwloadsavebutton for this. When I run the application, I get<br>> an<br>> > > > error in the vtkoutput window saying that-'filename was not specified<br>> or
<br>> > > > directory doesn't contain dicom images'. I also get the button in the<br>> main<br>> > > > panel which when clicked lets me choose the file that I want to load,<br>> but<br>> > > > nothing happens after I choose the file.
<br>> > > ><br>> > > > I am pasting a part of my code(this is not the complete code) to do<br>> this,<br>> > > > below. Can anyone please tell me how to fix this so that I can choose
<br>> the<br>> > > > file using the dialog and get it displayed?<br>> > > ><br>> > > > Thanks,<br>> > > > Ashish<br>> > > ><br>> > > > --------<br>
> > > ><br>> > > > vtkKWLoadSaveButton *load_button1 = vtkKWLoadSaveButton::New();<br>> > > > load_button1->SetParent(win->GetMainPanelFrame());<br>> > > > load_button1->Create();
<br>> > > > load_button1->SetText("Click to Pick a File");<br>> > > > load_button1->GetLoadSaveDialog()->SaveDialogOff();<br>> //<br>> > > > load mode<br>> > > > load_button1->GetLoadSaveDialog()->SetFileTypes("{
<br>> {Dicom<br>> > > > Document} {.dcm} }");<br>> > > > app->Script("pack %s -side top -anchor nw -expand n -padx 2 -pady<br>> > > > 2",load_button1->GetWidgetName());
<br>> > > ><br>> > > > vtkDICOMImageReader<br>> *img2=vtkDICOMImageReader::New();<br>> > > ><br>> > > ><br>> img2->SetFileName(load_button1->GetLoadSaveDialog()->GetFileName());
<br>> > > > img2->Update();<br>> > > ><br>> > > > vtkImageViewer2 * myviewer=vtkImageViewer2::New();<br>> > > > myviewer->SetInput(img2->GetOutput());<br>> > > > myviewer->SetColorWindow(2000);
<br>> > > > myviewer->SetColorLevel(1500);<br>> > > > myviewer->Render();<br>> > > > -------<br>> > > ><br>> > > > _______________________________________________
<br>> > > > KWWidgets mailing list<br>> > > > <a href="mailto:KWWidgets@kwwidgets.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">KWWidgets@kwwidgets.org</a><br>> > > >
<br>> <a href="http://public.kitware.com/cgi-bin/mailman/listinfo/kwwidgets" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://public.kitware.com/cgi-bin/mailman/listinfo/kwwidgets</a><br>> > > ><br>> > > ><br>> > ><br>> ><br>> ><br>><br>><br></blockquote></div><br>
</span></div><br clear="all">