#include "vtkKWDICOMImporterPage2.h" #include "vtkObjectFactory.h" #include "vtkKWIcon.h" #include "vtkKWMessageWithLabel.h" #include "vtkKWPushButton.h" #include "vtkKWFrame.h" #include #include #include #include "vtkKWInternationalization.h" #include "vtkKWRenderWidget.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //---------------------------------------------------------------------------- vtkStandardNewMacro( vtkKWDICOMImporterPage2 ); vtkCxxRevisionMacro(vtkKWDICOMImporterPage2, "$Revision: 1.3 $"); //---------------------------------------------------------------------------- vtkKWDICOMImporterPage2::vtkKWDICOMImporterPage2() { this->GDCMImporter = itk::GDCMImporter::New(); this->GDCMImporter->RecursiveOn(); this->Preview = vtkViewImage2D::New(); this->RenderWidget = vtkKWRenderWidget::New(); this->Tree = vtkKWTree::New(); this->OpenDirectoryButton = vtkKWPushButton::New(); this->ResetButton = vtkKWPushButton::New(); this->RemoveVolumeButton = vtkKWPushButton::New(); this->SplitVolumeButton = vtkKWPushButton::New(); this->OnceVolumeButton = vtkKWPushButton::New(); this->RecursiveCheckButton = vtkKWCheckButtonWithLabel::New(); this->TopFrame = vtkKWFrame::New(); this->BottomFrame = vtkKWFrame::New(); this->MLeftFrame = vtkKWFrame::New(); this->MRightFrame = vtkKWFrame::New(); this->ButtonFrame = vtkKWFrame::New(); } //---------------------------------------------------------------------------- vtkKWDICOMImporterPage2::~vtkKWDICOMImporterPage2() { std::cout<<"deleting page 2"<RenderWidget->RemoveAllChildren(); this->RenderWidget->Delete(); this->Preview->Delete(); this->Tree->Delete(); this->OpenDirectoryButton->Delete(); this->ResetButton->Delete(); this->RemoveVolumeButton->Delete(); this->SplitVolumeButton->Delete(); this->OnceVolumeButton->Delete(); this->RecursiveCheckButton->Delete(); this->TopFrame->Delete(); this->BottomFrame->Delete(); this->MLeftFrame->Delete(); this->MRightFrame->Delete(); this->ButtonFrame->Delete(); } //---------------------------------------------------------------------------- void vtkKWDICOMImporterPage2::CreatePreview() { this->RenderWidget->SetParent(this->MRightFrame); this->RenderWidget->Create(); this->RenderWidget->SetWidth(150); this->RenderWidget->SetHeight(150); this->Preview->SetRenderWindow(this->RenderWidget->GetRenderWindow()); this->Preview->SetRenderer(this->RenderWidget->GetRenderer()); this->Preview->SetInteractor(this->RenderWidget->GetRenderWindow()->GetInteractor()); this->Preview->SetAboutData (""); this->Preview->SetOrientation(vtkViewImage::AXIAL_ID); this->Preview->SetBackgroundColor (0,0,0); this->Preview->SetShowAnnotations (false); this->Preview->Show2DAxis(false); this->Preview->SetShowDirections(false); this->Preview->SetInteractionStyle (vtkViewImage2D::WINDOW_LEVEL_INTERACTION); } //---------------------------------------------------------------------------- void vtkKWDICOMImporterPage2::CreateTree() { this->Tree->SetParent(this->BottomFrame); this->Tree->Create(); this->Tree->SetReliefToGroove (); this->Tree->SetBorderWidth (3); this->Tree->SetBackgroundColor (1.0,1.0,1.0); this->Tree->LinesVisibilityOn (); this->Tree->SetSelectionChangedCommand(this, "SelectionChangedCallback"); this->Tree->SetWidth(28); this->Tree->SetHeight(17); } //---------------------------------------------------------------------------- void vtkKWDICOMImporterPage2::CreateButtons () { this->ButtonFrame->SetParent(this->TopFrame); this->ButtonFrame->Create(); int width = 32; int width2 = 10; this->OpenDirectoryButton->SetParent(this->ButtonFrame); this->OpenDirectoryButton->Create(); this->OpenDirectoryButton->SetText(ks_("DICOM Importer|Button|Open the DICOM root directory")); this->OpenDirectoryButton->SetBalloonHelpString(this->OpenDirectoryButton->GetText()); this->OpenDirectoryButton->SetImageToPixels(image_fileopen, image_fileopen_width, image_fileopen_height, image_fileopen_pixel_size, image_fileopen_length); this->OpenDirectoryButton->SetWidth(width); this->OpenDirectoryButton->SetCommand(this, "OpenDirectoryCallback"); this->ResetButton->SetParent(this->ButtonFrame); this->ResetButton->Create(); this->ResetButton->SetText(ks_("Reset")); this->ResetButton->SetBalloonHelpString(ks_("Reset to the initial configuration")); //this->ResetButton->SetImageToPixels(image_delete, image_delete_width, image_delete_height, image_delete_pixel_size, image_delete_length); this->ResetButton->SetWidth(width2); this->ResetButton->SetCommand(this, "ResetCallback"); this->RemoveVolumeButton->SetParent(this->ButtonFrame); this->RemoveVolumeButton->Create(); this->RemoveVolumeButton->SetText( ks_("Remove")); this->RemoveVolumeButton->SetBalloonHelpString( ks_("Remove this volume of the list")); //this->RemoveVolumeButton->SetImageToPixels(image_deleteall, image_deleteall_width, image_deleteall_height, image_deleteall_pixel_size, image_deleteall_length); this->RemoveVolumeButton->SetWidth(width2); this->RemoveVolumeButton->SetCommand(this, "RemoveVolumeCallback"); this->RemoveVolumeButton->SetStateToDisabled(); this->SplitVolumeButton->SetParent(this->ButtonFrame); this->SplitVolumeButton->Create(); this->SplitVolumeButton->SetText(ks_("Split")); this->SplitVolumeButton->SetBalloonHelpString(ks_("Split the volume by position consistency")); //this->SplitVolumeButton->SetImageToPixels(image_delete, image_delete_width, image_delete_height, image_delete_pixel_size, image_delete_length); this->SplitVolumeButton->SetWidth(width2); this->SplitVolumeButton->SetCommand(this, "SplitVolumeCallback"); this->SplitVolumeButton->SetStateToDisabled(); this->OnceVolumeButton->SetParent(this->ButtonFrame); this->OnceVolumeButton->Create(); this->OnceVolumeButton->SetText(ks_("Once")); this->OnceVolumeButton->SetBalloonHelpString(ks_("Split the volume by position consistency")); //this->OnceVolumeButton->SetImageToPixels(image_delete, image_delete_width, image_delete_height, image_delete_pixel_size, image_delete_length); this->OnceVolumeButton->SetWidth(width2); this->OnceVolumeButton->SetCommand(this, "OnceVolumeCallback"); this->OnceVolumeButton->SetStateToDisabled(); } //---------------------------------------------------------------------------- void vtkKWDICOMImporterPage2::CreateWidget() { // Check if already created if (this->IsCreated()) { vtkErrorMacro("class already created"); return; } // Call the superclass to create the whole widget this->Superclass::CreateWidget(); this->MLeftFrame->SetParent(this); this->MLeftFrame->Create(); this->MRightFrame->SetParent(this); this->MRightFrame->Create(); this->TopFrame->SetParent(this->MLeftFrame); this->TopFrame->Create(); this->BottomFrame->SetParent(this->MLeftFrame); this->BottomFrame->Create(); this->CreateTree(); this->CreateButtons(); this->CreatePreview(); this->Pack(); } //----------------------------------------------------------------------------- void vtkKWDICOMImporterPage2::Pack() { this->Script("pack %s -side left -expand false -fill none -anchor nw -padx 20 -pady 5", this->Tree->GetWidgetName()); this->Script("pack %s -side left -expand false -anchor sw -fill none -padx 10 -pady 2", this->ButtonFrame->GetWidgetName()); this->Script("pack %s -side left -expand false -anchor sw -fill none -padx 5 -pady 2", this->OpenDirectoryButton->GetWidgetName()); this->Script("pack %s -side left -expand false -anchor sw -fill none -padx 5 -pady 2", this->ResetButton->GetWidgetName()); this->Script("pack %s -side left -expand false -anchor sw -fill none -padx 5 -pady 2", this->RemoveVolumeButton->GetWidgetName()); this->Script("pack %s -side left -expand false -anchor sw -fill none -padx 5 -pady 2", this->SplitVolumeButton->GetWidgetName()); this->Script("pack %s -side left -expand false -anchor sw -fill none -padx 5 -pady 2", this->OnceVolumeButton->GetWidgetName()); if (this->RenderWidget && this->RenderWidget->IsCreated()) { this->Script( "pack %s -side left -expand false -anchor ne -fill none -padx 5 -pady 5", this->RenderWidget->GetWidgetName()); } this->Script("grid %s -sticky nw -column 0 -row 0 -pady 2", this->TopFrame->GetWidgetName()); this->Script("grid %s -sticky nw -column 0 -row 1 -pady 2", this->BottomFrame->GetWidgetName()); this->Script("grid rowconfigure %s 0 -weight 1", this->GetWidgetName()); this->Script("grid rowconfigure %s 1 -weight 2", this->GetWidgetName()); this->Script("grid %s -sticky nw -column 0 -row 0 -pady 2", this->MLeftFrame->GetWidgetName()); this->Script("grid %s -sticky nw -column 1 -row 0 -pady 2", this->MRightFrame->GetWidgetName()); this->Script("grid columnconfigure %s 0 -weight 2", this->GetWidgetName()); this->Script("grid columnconfigure %s 1 -weight 1", this->GetWidgetName()); } //----------------------------------------------------------------------------- void vtkKWDICOMImporterPage2::UpdateEnableState() { this->Superclass::UpdateEnableState(); this->PropagateEnableState(this->Tree); this->PropagateEnableState(this->OpenDirectoryButton); this->PropagateEnableState(this->ResetButton); this->PropagateEnableState(this->RemoveVolumeButton); this->PropagateEnableState(this->SplitVolumeButton); this->PropagateEnableState(this->OnceVolumeButton); } //---------------------------------------------------------------------------- void vtkKWDICOMImporterPage2::Update() { this->UpdateTree(); } //---------------------------------------------------------------------------- void vtkKWDICOMImporterPage2::UpdateTree() { this->Tree->DeleteAllNodes (); vtkKWWindowBase *win = this->GetApplication()->GetNthWindow(0); if (win) { win->SetStatusText(ks_("Progress|Updating DICOM tree...")); } if (win) { win->GetProgressGauge()->SetValue(0); } std::vector dcmvolumelist = this->GDCMImporter->GetDICOMVolumeList(); for (unsigned int i=0; iGetProgressGauge()->SetValue((int)(100.0 * i / dcmvolumelist.size())); } itk::DICOMVolume::Pointer dcmvolume = dcmvolumelist[i]; std::string volumename = dcmvolume->GetDescription().c_str(); std::ostringstream os; os << volumename.c_str() <<"_node"; std::string nodename = os.str(); this->Tree->AddNode(NULL, nodename.c_str(), volumename.c_str()); this->Tree->SetNodeUserDataAsInt(nodename.c_str(), vtkKWDICOMImporterPage2::VOLUME_NODE); unsigned int nfiles = dcmvolume->GetFileList().size(); for( unsigned int n=0; nGetFileList()[n]); std::ostringstream os2; os2 << filename.c_str() <<"_node"; std::string leafname = os2.str(); this->Tree->AddNode(nodename.c_str(), leafname.c_str(), filename.c_str()); this->Tree->SetNodeUserDataAsInt(leafname.c_str(), vtkKWDICOMImporterPage2::FILE_NODE); } } if (win) { vtksys_stl::string end_msg(win->GetStatusText()); end_msg += " -- "; end_msg += ks_("Progress|Done"); win->SetStatusText(end_msg.c_str()); win->GetProgressGauge()->SetValue(0); } } //---------------------------------------------------------------------------- void vtkKWDICOMImporterPage2::UpdatePreview() { if (!this->Preview) { vtkWarningMacro("cannot create preview,\npreview is NULL"); return; } if (!this->Tree->HasSelection()) return; // all this code to retreive the file name to preview... std::string selectedtext = this->Tree->GetSelection(); int type = this->Tree->GetNodeUserDataAsInt(selectedtext.c_str()); if (type != FILE_NODE) return; std::string parentvolumename = this->Tree->GetNodeParent (selectedtext.c_str()); parentvolumename = parentvolumename.substr(0, parentvolumename.size()-5); std::vector dcmvolumelist = this->GDCMImporter->GetDICOMVolumeList(); itk::DICOMVolume::Pointer dcmvolume_toopen = NULL; for (unsigned int i=0; iGetDescription().c_str(); if (strcmp(volumename.c_str(), parentvolumename.c_str()) != 0) continue; dcmvolume_toopen = dcmvolume; break; } if (!dcmvolume_toopen) return; std::string file = selectedtext.c_str(); file = file.substr(0, file.size()-5); std::vector filelist = dcmvolume_toopen->GetFileList(); std::string filename = ""; for (unsigned int i=0; iCanReadFile (filename.c_str())) { std::cerr << "Cannot preview file : " << filename.c_str() << std::endl; reader->Delete(); return; } reader->SetFileName (filename.c_str()); reader->Update(); vtkImageData* image = reader->GetOutput(); if (!image) return; bool doreset = false; if (!this->Preview->GetImage()) { doreset = true; } this->Preview->SetImage(image); if (doreset) { this->Preview->Reset(); } this->Preview->Render(); reader->Delete(); } //---------------------------------------------------------------------------- void vtkKWDICOMImporterPage2::OpenDirectoryCallback() { vtkKWLoadSaveDialog *dialog = vtkKWLoadSaveDialog::New() ; dialog->SetParent(this); dialog->Create(); dialog->ChooseDirectoryOn(); dialog->RetrieveLastPathFromRegistry("DataPath"); dialog->SetTitle ("Open a DICOM exam root directory"); if ( dialog->Invoke () == 0 ) { dialog->Delete(); return ; } const char* directory = dialog->GetFileName(); std::cout<<"directory is : "<GDCMImporter->RecursiveOn(); this->GDCMImporter->SetInputDirectory(directory); vtkKWWindowBase *win = this->GetApplication()->GetNthWindow(0); if (win) { win->SetStatusText(ks_("Progress|Scanning DICOMs...")); } if (win) { win->GetProgressGauge()->SetValue(10); } try { std::cout<<"scanning..."<GDCMImporter->Scan(); } catch (itk::ExceptionObject & e) { std::cerr << e; } if (win) { vtksys_stl::string end_msg(win->GetStatusText()); end_msg += " -- "; end_msg += ks_("Progress|Done"); win->SetStatusText(end_msg.c_str()); win->GetProgressGauge()->SetValue(0); } this->UpdateTree(); dialog->SaveLastPathToRegistry("DataPath"); dialog->Delete(); } //---------------------------------------------------------------------------- void vtkKWDICOMImporterPage2::ResetCallback() { try { this->GDCMImporter->Scan(); } catch (itk::ExceptionObject & e) { std::cerr << e; } this->UpdateTree(); } //---------------------------------------------------------------------------- void vtkKWDICOMImporterPage2::RemoveVolumeCallback() { if (!this->Tree->HasSelection()) return; std::string selectedtext = this->Tree->GetSelection(); int type = this->Tree->GetNodeUserDataAsInt(selectedtext.c_str()); if (type != VOLUME_NODE) return; std::string toremove = selectedtext.substr(0, selectedtext.size()-5); std::vector dcmvolumelist = this->GDCMImporter->GetDICOMVolumeList(); for (unsigned int i=0; iGetDescription().c_str(); if (strcmp(volumename.c_str(), toremove.c_str()) != 0) continue; this->GDCMImporter->RemoveDICOMVolume(dcmvolume); break; } this->UpdateTree(); } //---------------------------------------------------------------------------- void vtkKWDICOMImporterPage2::SplitVolumeCallback() { if (!this->Tree->HasSelection()) return; std::string selectedtext = this->Tree->GetSelection(); int type = this->Tree->GetNodeUserDataAsInt(selectedtext.c_str()); if (type != VOLUME_NODE) return; std::string toremove = selectedtext.substr(0, selectedtext.size()-5); std::vector dcmvolumelist = this->GDCMImporter->GetDICOMVolumeList(); for (unsigned int i=0; iGetDescription().c_str(); if (strcmp(volumename.c_str(), toremove.c_str()) != 0) continue; this->GDCMImporter->SplitVolumeByPositionConsistency (dcmvolume); break; } this->UpdateTree(); } //---------------------------------------------------------------------------- void vtkKWDICOMImporterPage2::OnceVolumeCallback() { if (!this->Tree->HasSelection()) return; std::string selectedtext = this->Tree->GetSelection(); int type = this->Tree->GetNodeUserDataAsInt(selectedtext.c_str()); if (type != VOLUME_NODE) return; std::string toremove = selectedtext.substr(0, selectedtext.size()-5); std::vector dcmvolumelist = this->GDCMImporter->GetDICOMVolumeList(); for (unsigned int i=0; iGetDescription().c_str(); if (strcmp(volumename.c_str(), toremove.c_str()) == 0) continue; this->GDCMImporter->RemoveDICOMVolume(dcmvolume); } this->UpdateTree(); } //---------------------------------------------------------------------------- void vtkKWDICOMImporterPage2::SelectionChangedCallback() { if (!this->Tree->HasSelection()) return; std::string selectedtext = this->Tree->GetSelection(); int type = this->Tree->GetNodeUserDataAsInt(selectedtext.c_str()); if (type == VOLUME_NODE) { this->RemoveVolumeButton->SetStateToNormal(); this->SplitVolumeButton->SetStateToNormal(); this->OnceVolumeButton->SetStateToNormal(); } else if (type == FILE_NODE) { this->RemoveVolumeButton->SetStateToDisabled(); this->SplitVolumeButton->SetStateToDisabled(); this->OnceVolumeButton->SetStateToDisabled(); this->UpdatePreview(); } }