#include "vtkKWSequenceImporterPage1.h" #include "vtkObjectFactory.h" #include #include "vtkKWIcon.h" #include "vtkKWMessageWithLabel.h" #include "vtkKWInternationalization.h" #include "vtkCommand.h" #include "vtkKWLabel.h" #include "vtkKWListBox.h" #include "vtkKWListBoxWithScrollbars.h" #include "vtkKWListBoxWithScrollbarsWithLabel.h" #include "vtkKWIcon.h" #include "vtkObjectFactory.h" #include "vtkKWPushButton.h" #include "vtkKWFrame.h" #include "vtkKWEvent.h" #include "vtkStringArray.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //---------------------------------------------------------------------------- vtkStandardNewMacro( vtkKWSequenceImporterPage1 ); vtkCxxRevisionMacro(vtkKWSequenceImporterPage1, "$Revision: 1.3 $"); //---------------------------------------------------------------------------- vtkKWSequenceImporterPage1::vtkKWSequenceImporterPage1() { this->FileList = vtkKWMultiColumnList::New(); this->AddButton = vtkKWPushButton::New(); this->ImportButton = vtkKWPushButton::New(); this->RemoveButton = vtkKWPushButton::New(); this->ButtonFrameFiles = vtkKWFrame::New(); this->ButtonFrameAttributes = vtkKWFrame::New(); this->ButtonFrameMoves = vtkKWFrame::New(); this->RemoveAllButton = vtkKWPushButton::New(); this->UpButton = vtkKWPushButton::New(); this->DownButton = vtkKWPushButton::New(); this->SameGeometryButton = vtkKWCheckButtonWithLabel::New(); this->ImageTypeCheckButton = vtkKWRadioButton::New(); this->MeshTypeCheckButton = vtkKWRadioButton::New(); this->EnlapsedTimeEntry = vtkKWEntryWithLabel::New(); this->SequenceNameEntry = vtkKWEntryWithLabel::New(); this->TimeStampEntry = vtkKWEntryWithLabel::New(); this->DelayEntry = vtkKWEntryWithLabel::New(); this->LeftFrame = vtkKWFrame::New(); this->RightFrame = vtkKWFrame::New(); this->AllowReordering = 0; this->DataSetType = vtkMetaDataSet::VTK_META_UNKNOWN; this->EnlapsedTime = 2.0; this->SequenceName = "sequence-0"; this->Delay = 0.20; this->TimeStamp = 0.0; this->NumberOfFiles = 0; this->IncomingMode = NORMAL_MODE; } //---------------------------------------------------------------------------- vtkKWSequenceImporterPage1::~vtkKWSequenceImporterPage1() { std::cout<<"deleting page 1"<FileList->Delete(); this->AddButton->Delete(); this->ImportButton->Delete(); this->RemoveButton->Delete(); this->RemoveAllButton->Delete(); this->UpButton->Delete(); this->DownButton->Delete(); this->ButtonFrameFiles->Delete(); this->ButtonFrameAttributes->Delete(); this->ButtonFrameMoves->Delete(); this->ImageTypeCheckButton->Delete(); this->MeshTypeCheckButton->Delete(); this->EnlapsedTimeEntry->Delete(); this->SequenceNameEntry->Delete(); this->TimeStampEntry->Delete(); this->DelayEntry->Delete(); this->SameGeometryButton->Delete(); this->LeftFrame->Delete(); this->RightFrame->Delete(); for (unsigned int i=0; iImportedMetaDataSetList.size(); i++) { this->ImportedMetaDataSetList[i]->Delete(); } this->ImportedMetaDataSetList.clear(); } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::CreateFileList() { this->FileList->SetParent(this->LeftFrame); this->FileList->Create(); this->FileList->MovableColumnsOn(); this->FileList->MovableRowsOn(); this->FileList->SetSelectionModeToExtended (); this->FileList->SetSelectionForegroundColor (0,0,0); int w = (int)((double)this->GetWidth()/2.0); this->FileList->SetWidth(w); int col_index; // Add the columns (make some of them editable) col_index = this->FileList->AddColumn("#"); this->FileList->SetColumnSortModeToInteger (col_index); col_index = this->FileList->AddColumn("file name"); this->FileList->SetColumnSortModeToDictionary (col_index); col_index = this->FileList->AddColumn("time"); this->FileList->ColumnEditableOn (col_index); this->FileList->SetColumnSortModeToReal (col_index); col_index = this->FileList->AddColumn(NULL); this->FileList->SetColumnLabelImageToPredefinedIcon(col_index, vtkKWIcon::IconInfoMini); //this->FileList->SetSelectionChangedCommand (this, "FileListSelectionChangedCallback"); this->FileList->SetCellUpdatedCommand (this, "FileListCellUpdatedCallback"); col_index = this->FileList->AddColumn("validity"); this->FileList->SetColumnVisibility(col_index, 0); col_index = this->FileList->AddColumn("path"); this->FileList->SetColumnVisibility(col_index, 0); } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::CreateButtons () { this->ButtonFrameFiles->SetParent(this->RightFrame); this->ButtonFrameFiles->Create(); int width = 32; int semiwidth = 16; this->AddButton->SetParent(this->ButtonFrameFiles); this->AddButton->Create(); this->AddButton->SetText(ks_("Sequence Importer|Button|add file(s) to the sequence")); this->AddButton->SetBalloonHelpString(this->AddButton->GetText()); this->AddButton->SetImageToPixels(image_fileopen, image_fileopen_width, image_fileopen_height, image_fileopen_pixel_size, image_fileopen_length); this->AddButton->SetWidth(width); this->AddButton->SetCommand(this, "AddCallback"); this->ImportButton->SetParent(this->ButtonFrameFiles); this->ImportButton->Create(); this->ImportButton->SetText(ks_("Sequence Importer|Button|import DICOM exam files")); this->ImportButton->SetBalloonHelpString(this->ImportButton->GetText()); this->ImportButton->SetImageToPixels(image_importdicom, image_importdicom_width, image_importdicom_height, image_importdicom_pixel_size, image_importdicom_length); this->ImportButton->SetWidth(width); this->ImportButton->SetCommand(this, "ImportCallback"); this->RemoveButton->SetParent(this->ButtonFrameFiles); this->RemoveButton->Create(); this->RemoveButton->SetText(ks_("Sequence Importer|Button|remove selected file(s)")); this->RemoveButton->SetBalloonHelpString(this->RemoveButton->GetText()); this->RemoveButton->SetImageToPixels(image_delete, image_delete_width, image_delete_height, image_delete_pixel_size, image_delete_length); this->RemoveButton->SetWidth(width); this->RemoveButton->SetCommand(this, "RemoveCallback"); this->RemoveAllButton->SetParent(this->ButtonFrameFiles); this->RemoveAllButton->Create(); this->RemoveAllButton->SetText( ks_("Sequence Importer|Button|remove all files")); this->RemoveAllButton->SetBalloonHelpString( this->RemoveAllButton->GetText()); this->RemoveAllButton->SetImageToPixels(image_deleteall, image_deleteall_width, image_deleteall_height, image_deleteall_pixel_size, image_deleteall_length); this->RemoveAllButton->SetWidth(width); this->RemoveAllButton->SetCommand(this, "RemoveAllCallback"); this->ButtonFrameAttributes->SetParent(this->RightFrame); this->ButtonFrameAttributes->Create(); this->SequenceNameEntry->SetParent(this->ButtonFrameAttributes); this->SequenceNameEntry->Create(); this->SequenceNameEntry->SetWidth(10); this->SequenceNameEntry->SetLabelText(ks_("name : ")); this->SequenceNameEntry->GetWidget()->SetRestrictValueToNone (); this->SequenceNameEntry->GetWidget()->SetCommand(this, "SequenceNameEntryCallback"); this->SequenceNameEntry->GetWidget()->SetValue(this->SequenceName.c_str()); this->EnlapsedTimeEntry->SetParent(this->ButtonFrameAttributes); this->EnlapsedTimeEntry->Create(); this->EnlapsedTimeEntry->SetWidth(10); this->EnlapsedTimeEntry->SetLabelText(ks_("duration : ")); this->EnlapsedTimeEntry->GetWidget()->SetRestrictValueToDouble (); this->EnlapsedTimeEntry->GetWidget()->SetCommand(this, "EnlapsedTimeEntryCallback"); this->EnlapsedTimeEntry->GetWidget()->SetValueAsDouble(this->EnlapsedTime); this->EnlapsedTimeEntry->GetWidget()->SetCommandTrigger(vtkKWEntry::TriggerOnReturnKey); this->TimeStampEntry->SetParent(this->ButtonFrameAttributes); this->TimeStampEntry->Create(); this->TimeStampEntry->SetWidth(10); this->TimeStampEntry->SetLabelText(ks_("start : ")); this->TimeStampEntry->GetWidget()->SetRestrictValueToDouble (); this->TimeStampEntry->GetWidget()->SetCommand(this, "TimeStampEntryCallback"); this->TimeStampEntry->GetWidget()->SetValueAsDouble(this->TimeStamp); this->TimeStampEntry->GetWidget()->SetCommandTrigger(vtkKWEntry::TriggerOnReturnKey); this->DelayEntry->SetParent(this->ButtonFrameAttributes); this->DelayEntry->Create(); this->DelayEntry->SetWidth(10); this->DelayEntry->SetLabelText(ks_("step : ")); this->DelayEntry->GetWidget()->SetRestrictValueToDouble (); this->DelayEntry->GetWidget()->SetCommand(this, "DelayEntryCallback"); this->DelayEntry->GetWidget()->SetValueAsDouble(this->Delay); this->DelayEntry->GetWidget()->SetCommandTrigger(vtkKWEntry::TriggerOnReturnKey); this->ImageTypeCheckButton->SetParent(this->ButtonFrameAttributes); this->ImageTypeCheckButton->Create(); this->ImageTypeCheckButton->SetText(ks_("set datatype to image")); this->ImageTypeCheckButton->SetBalloonHelpString(this->ImageTypeCheckButton->GetText()); //this->ImageTypeCheckButton->SetCommand(this, "RemoveCallback"); this->ImageTypeCheckButton->IndicatorVisibilityOn(); this->MeshTypeCheckButton->SetParent(this->ButtonFrameAttributes); this->MeshTypeCheckButton->Create(); this->MeshTypeCheckButton->SetText(ks_("set datatype to image")); this->MeshTypeCheckButton->SetBalloonHelpString( this->MeshTypeCheckButton->GetText()); //this->MeshTypeCheckButton->SetCommand(this, "RemoveCallback"); this->MeshTypeCheckButton->IndicatorVisibilityOn(); this->ButtonFrameMoves->SetParent(this->LeftFrame); this->ButtonFrameMoves->Create(); this->UpButton->SetParent(this->ButtonFrameMoves); this->UpButton->Create(); this->UpButton->SetText( ks_("Sequence Importer|Button|move up the selected files")); this->UpButton->SetBalloonHelpString( this->UpButton->GetText()); this->UpButton->SetImageToPixels(image_upsmall, image_upsmall_width, image_upsmall_height, image_upsmall_pixel_size, image_upsmall_length); this->UpButton->SetWidth(semiwidth); this->UpButton->SetCommand(this, "UpCallback"); this->DownButton->SetParent(this->ButtonFrameMoves); this->DownButton->Create(); this->DownButton->SetText( ks_("Sequence Importer|Button|move down the selected files")); this->DownButton->SetBalloonHelpString( this->DownButton->GetText()); this->DownButton->SetImageToPixels(image_downsmall, image_downsmall_width, image_downsmall_height, image_downsmall_pixel_size, image_downsmall_length); this->DownButton->SetWidth(semiwidth); this->DownButton->SetCommand(this, "DownCallback"); this->SameGeometryButton->SetParent(this->ButtonFrameAttributes); this->SameGeometryButton->Create(); this->SameGeometryButton->SetWidth(10); this->SameGeometryButton->SetLabelText(ks_("Same Geometry ")); this->SameGeometryButton->GetWidget()->Select (); } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::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->LeftFrame->SetParent(this); this->LeftFrame->Create(); this->RightFrame->SetParent(this); this->RightFrame->Create(); this->CreateFileList(); this->CreateButtons(); this->Pack(); } //----------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::Pack() { this->Script("pack %s -side top -expand false -fill none -anchor nw -padx 20 -pady 5", this->FileList->GetWidgetName()); this->Script("pack %s -side top -expand false -anchor se -fill none -padx 20 -pady 2", this->ButtonFrameMoves->GetWidgetName()); this->Script("pack %s -side left -expand false -anchor se -fill none -padx 5 -pady 2", this->UpButton->GetWidgetName()); this->Script("pack %s -side left -expand false -anchor se -fill none -padx 5 -pady 2", this->DownButton->GetWidgetName()); this->Script("pack %s -side top -expand false -anchor nw -fill none -pady 2", this->ButtonFrameAttributes->GetWidgetName()); this->Script("pack %s -side top -expand false -anchor ne -fill none -pady 2", this->SequenceNameEntry->GetWidgetName()); this->Script("pack %s -side top -expand false -anchor ne -fill none -pady 2", this->EnlapsedTimeEntry->GetWidgetName()); this->Script("pack %s -side top -expand false -anchor ne -fill none -pady 2", this->TimeStampEntry->GetWidgetName()); this->Script("pack %s -side top -expand false -anchor ne -fill none -pady 2", this->DelayEntry->GetWidgetName()); this->Script("pack %s -side top -expand false -anchor ne -fill none -pady 2", this->SameGeometryButton->GetWidgetName()); this->Script("pack %s -side top -expand true -anchor se -fill none -padx 0 -pady 20", this->ButtonFrameFiles->GetWidgetName()); this->Script("pack %s %s %s -side left -fill none -anchor se -padx 5", this->AddButton->GetWidgetName(), this->ImportButton->GetWidgetName(), this->RemoveButton->GetWidgetName(), this->RemoveAllButton->GetWidgetName()); this->Script("grid %s -sticky nw -column 0 -row 0 -pady 2", this->LeftFrame->GetWidgetName()); this->Script("grid %s -sticky nw -column 1 -row 0 -pady 2", this->RightFrame->GetWidgetName()); this->Script("grid columnconfigure %s 0 -weight 1", this->GetWidgetName()); this->Script("grid columnconfigure %s 1 -weight 1", this->GetWidgetName()); } //----------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::UpdateEnableState() { this->Superclass::UpdateEnableState(); this->PropagateEnableState(this->FileList); this->PropagateEnableState(this->AddButton); this->PropagateEnableState(this->ImportButton); this->PropagateEnableState(this->RemoveButton); this->PropagateEnableState(this->RemoveAllButton); this->PropagateEnableState(this->UpButton); this->PropagateEnableState(this->DownButton); this->PropagateEnableState(this->SameGeometryButton); } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::Update() { this->UpdateEnableState(); } //---------------------------------------------------------------------------- int vtkKWSequenceImporterPage1::GetNumberOfElementsOfFileList() { return this->FileList->GetNumberOfRows (); } //---------------------------------------------------------------------------- const char* vtkKWSequenceImporterPage1::GetElementFromFileList(int idx) { return this->FileList->GetCellText (idx, 0); } //---------------------------------------------------------------------------- int vtkKWSequenceImporterPage1::GetElementIndexFromFileList(const char* element) { if (!element || !(*element)) return -1; for (int i=0; iFileList->GetNumberOfRows (); i++) { if (!this->FileList->GetCellText(i, 1)) continue; if (strcmp(this->FileList->GetCellText(i, 1), element) == 0) return i; } return -1; } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::InsertElement(const char* filename, const char* path) { if (this->IncomingMode == NORMAL_MODE) { int N = this->FileList->GetNumberOfRows(); if (N == 0) { if (vtkMetaSurfaceMesh::CanReadFile (filename)) this->DataSetType = vtkMetaDataSet::VTK_META_SURFACE_MESH; else if (vtkMetaVolumeMesh::CanReadFile (filename)) this->DataSetType = vtkMetaDataSet::VTK_META_VOLUME_MESH; else if (vtkMetaImageData::CanReadFile (filename)) this->DataSetType = vtkMetaDataSet::VTK_META_IMAGE_DATA; else this->DataSetType = vtkMetaDataSet::VTK_META_UNKNOWN; } bool valid = true; switch (this->DataSetType) { case vtkMetaDataSet::VTK_META_SURFACE_MESH: if (!vtkMetaSurfaceMesh::CanReadFile (filename)) valid = false; break; case vtkMetaDataSet::VTK_META_VOLUME_MESH: if (!vtkMetaVolumeMesh::CanReadFile (filename)) valid = false; break; case vtkMetaDataSet::VTK_META_IMAGE_DATA: if (!vtkMetaImageData::CanReadFile (filename)) valid = false; break; default: valid = false; break; } this->FileList->InsertCellTextAsInt(N, 0, N+1); std::string name = vtksys::SystemTools::GetFilenameName (filename); this->FileList->InsertCellText(N, 1, name.c_str()); this->FileList->InsertCellTextAsDouble (N, 2, 0.0); if (valid) this->FileList->SetCellImageToPixels (N, 3, image_oksmall, image_oksmall_width, image_oksmall_height, image_oksmall_pixel_size, image_oksmall_length); else this->FileList->SetCellImageToPredefinedIcon (N, 3, vtkKWIcon::IconErrorMini); if (valid) this->FileList->SetCellTextAsInt (N, 4, 1); else this->FileList->SetCellTextAsInt (N, 4, 0); this->FileList->InsertCellText(N, 5, path); } else if (this->IncomingMode == IMPORT_MODE) { int N = this->FileList->GetNumberOfRows(); if (N == 0) { this->DataSetType = vtkMetaDataSet::VTK_META_IMAGE_DATA; } this->FileList->InsertCellTextAsInt(N, 0, N+1); std::string name = vtksys::SystemTools::GetFilenameName (filename); this->FileList->InsertCellText(N, 1, name.c_str()); this->FileList->InsertCellTextAsDouble (N, 2, 0.0); bool valid = true; if (valid) this->FileList->SetCellImageToPixels (N, 3, image_oksmall, image_oksmall_width, image_oksmall_height, image_oksmall_pixel_size, image_oksmall_length); else this->FileList->SetCellImageToPredefinedIcon (N, 3, vtkKWIcon::IconErrorMini); if (valid) this->FileList->SetCellTextAsInt (N, 4, 1); else this->FileList->SetCellTextAsInt (N, 4, 0); this->FileList->InsertCellText(N, 5, path); } else if (this->IncomingMode == ONEGEOMETRY_MODE) { int N = this->FileList->GetNumberOfRows(); if (N != 0) { return; this->DataSetType = vtkMetaDataSet::VTK_META_IMAGE_DATA; } bool valid = true; if (vtkMetaSurfaceMesh::CanReadFile (filename)) this->DataSetType = vtkMetaDataSet::VTK_META_SURFACE_MESH; else if (vtkMetaVolumeMesh::CanReadFile (filename)) this->DataSetType = vtkMetaDataSet::VTK_META_VOLUME_MESH; else { return; } this->FileList->InsertCellTextAsInt(N, 0, N+1); std::string name = vtksys::SystemTools::GetFilenameName (filename); this->FileList->InsertCellText(N, 1, name.c_str()); this->FileList->InsertCellTextAsDouble (N, 2, 0.0); if (valid) this->FileList->SetCellImageToPixels (N, 3, image_oksmall, image_oksmall_width, image_oksmall_height, image_oksmall_pixel_size, image_oksmall_length); else this->FileList->SetCellImageToPredefinedIcon (N, 3, vtkKWIcon::IconErrorMini); if (valid) this->FileList->SetCellTextAsInt (N, 4, 1); else this->FileList->SetCellTextAsInt (N, 4, 0); this->FileList->InsertCellText(N, 5, path); } this->NumberOfFiles++; } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::AddCallback() { if (this->IncomingMode == IMPORT_MODE) { this->FileList->DeleteAllRows(); this->NumberOfFiles = 0; this->IncomingMode = NORMAL_MODE; } vtkKWLoadSaveDialog *dialog = vtkKWLoadSaveDialog::New() ; dialog->SetParent(this); dialog->Create(); dialog->MultipleSelectionOn(); dialog->RetrieveLastPathFromRegistry("DataPath"); dialog->SetTitle ("Open a File"); dialog->SetFileTypes (kwsupportedformats.c_str()); if ( dialog->Invoke () == 0 ) { dialog->Delete(); return ; } int Number_Of_Files = this->FileList->GetNumberOfRows (); if (Number_Of_Files == 0 && dialog->GetNumberOfFileNames() == 1) { this->IncomingMode = ONEGEOMETRY_MODE; } for (int i=0; iGetNumberOfFileNames(); i++) { const char* filename = dialog->GetFileNames()->GetValue (i); const char* path = dialog->GetLastPath(); this->InsertElement(filename, path); } dialog->SaveLastPathToRegistry("DataPath"); dialog->Delete(); this->UpdateTimes(); } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::RemoveCallback() { const unsigned int Number_Of_Selected = this->FileList->GetNumberOfSelectedRows(); int* indices = new int[Number_Of_Selected]; this->FileList->GetSelectedRows(indices); this->FileList->ClearSelection(); for (unsigned int i=0; iFileList->DeleteRow (index); this->NumberOfFiles--; } this->UpdateTimes(); delete [] indices; } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::RemoveAllCallback() { this->FileList->DeleteAllRows(); this->NumberOfFiles = 0; } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::UpCallback() { const unsigned int N = this->FileList->GetNumberOfSelectedRows(); if (!N) return; int* indices = new int[N]; this->FileList->GetSelectedRows(indices); if (N > 1) { for (unsigned int i=1; i 1) return; } } this->ShiftItems (indices[0], indices[N-1], true); delete [] indices; } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::DownCallback() { const unsigned int N = this->FileList->GetNumberOfSelectedRows(); if (!N) return; int* indices = new int[N]; this->FileList->GetSelectedRows(indices); if (N > 1) { for (unsigned int i=1; i 1) return; } } this->ShiftItems (indices[0], indices[N-1], false); delete [] indices; } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::ShiftItems (int firstindex, int lastindex, bool up) { int keep_id = 0; std::string keep_name = ""; double keep_time = 0.0; std::string keep_pixels = ""; int keep_validity = 0; std::string keep_path = ""; int index = 0; if (up) { if (firstindex <= 0) return; keep_id = this->FileList->GetCellTextAsInt (firstindex-1, 0); keep_name = this->FileList->GetCellText (firstindex-1, 1); keep_time = this->FileList->GetCellTextAsDouble (firstindex-1, 2); keep_pixels = this->FileList->GetCellImage (firstindex-1, 3); keep_validity = this->FileList->GetCellTextAsInt (firstindex-1, 4); keep_path = this->FileList->GetCellText (firstindex-1, 5); for (index=firstindex; index<=lastindex; index++) { int id = this->FileList->GetCellTextAsInt (index, 0); std::string name = this->FileList->GetCellText (index, 1); double time = this->FileList->GetCellTextAsDouble (index, 2); std::string pixels = this->FileList->GetCellImage(index, 3); int validity = this->FileList->GetCellTextAsInt (index, 4); std::string path = this->FileList->GetCellText (index, 5); this->FileList->SetCellTextAsInt (index-1, 0, id); this->FileList->SetCellText (index-1, 1, name.c_str()); this->FileList->SetCellTextAsDouble (index-1, 2, time); this->FileList->SetCellImage (index-1, 3, pixels.c_str()); this->FileList->SetCellTextAsInt (index-1, 4, validity); this->FileList->SetCellText (index-1, 5, path.c_str()); this->FileList->SelectRow (index-1); } this->FileList->SetCellTextAsInt (lastindex, 0, keep_id); this->FileList->SetCellText (lastindex, 1, keep_name.c_str()); this->FileList->SetCellTextAsDouble (lastindex, 2, keep_time); this->FileList->SetCellImage (lastindex, 3, keep_pixels.c_str()); this->FileList->SetCellTextAsInt (lastindex, 4, keep_validity); this->FileList->SetCellText (lastindex, 5, keep_path.c_str()); this->FileList->DeselectRow (lastindex); } else { if (lastindex >= this->FileList->GetNumberOfRows () -1) return; keep_id = this->FileList->GetCellTextAsInt (lastindex+1, 0); keep_name = this->FileList->GetCellText (lastindex+1, 1); keep_time = this->FileList->GetCellTextAsDouble (lastindex+1, 2); keep_pixels = this->FileList->GetCellImage (lastindex+1, 3); keep_validity = this->FileList->GetCellTextAsInt (firstindex+1, 4); keep_path = this->FileList->GetCellText (firstindex+1, 5); for (index=lastindex; index>=firstindex; index--) { int id = this->FileList->GetCellTextAsInt (index, 0); std::string name = this->FileList->GetCellText (index, 1); double time = this->FileList->GetCellTextAsDouble (index, 2); std::string pixels = this->FileList->GetCellImage(index, 3); int validity = this->FileList->GetCellTextAsInt (index, 4); std::string path = this->FileList->GetCellText (index, 5); this->FileList->SetCellTextAsInt (index+1, 0, id); this->FileList->SetCellText (index+1, 1, name.c_str()); this->FileList->SetCellTextAsDouble (index+1, 2, time); this->FileList->SetCellImage (index+1, 3, pixels.c_str()); this->FileList->SetCellTextAsInt (index+1, 4, validity); this->FileList->SetCellText (index+1, 5, path.c_str()); this->FileList->SelectRow (index+1); } this->FileList->SetCellTextAsInt (firstindex, 0, keep_id); this->FileList->SetCellText (firstindex, 1, keep_name.c_str()); this->FileList->SetCellTextAsDouble (firstindex, 2, keep_time); this->FileList->SetCellImage (firstindex, 3, keep_pixels.c_str()); this->FileList->SetCellTextAsInt (firstindex, 4, keep_validity); this->FileList->SetCellText (firstindex, 5, keep_path.c_str()); this->FileList->DeselectRow (firstindex); } } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::FileListSelectionChangedCallback() { } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::FileListCellUpdatedCallback(int row, int col, const char* val) { if (row==0 && col==2) { this->TimeStamp = this->FileList->GetCellTextAsDouble (row,col); this->TimeStampEntry->GetWidget()->SetValueAsDouble(this->TimeStamp); this->UpdateTimes(); } } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::EnlapsedTimeEntryCallback (const char* val) { this->EnlapsedTime = this->EnlapsedTimeEntry->GetWidget()->GetValueAsDouble(); int N = this->FileList->GetNumberOfRows(); if (N) this->Delay = this->EnlapsedTime/(double)(N); this->DelayEntry->GetWidget()->SetValueAsDouble(this->Delay); this->UpdateTimes(); } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::SequenceNameEntryCallback (const char* val) { this->SequenceName = this->SequenceNameEntry->GetWidget()->GetValue(); } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::TimeStampEntryCallback (const char* val) { this->TimeStamp = this->TimeStampEntry->GetWidget()->GetValueAsDouble(); this->UpdateTimes(); } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::DelayEntryCallback (const char* val) { this->Delay = this->DelayEntry->GetWidget()->GetValueAsDouble(); int N = this->FileList->GetNumberOfRows(); this->EnlapsedTime = (double)(N)*this->Delay; this->EnlapsedTimeEntry->GetWidget()->SetValueAsDouble(this->EnlapsedTime); this->UpdateTimes(); } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::UpdateTimes() { int N = this->FileList->GetNumberOfRows(); for (int i=0; iTimeStamp + (double)i*this->Delay; double time = this->TimeStamp + ((double)i/(double)N)*this->EnlapsedTime; this->FileList->SetCellTextAsDouble(i, 2, time); } this->Delay = this->EnlapsedTime/(double)N; this->DelayEntry->GetWidget()->SetValueAsDouble(this->Delay); } //---------------------------------------------------------------------------- std::vector< std::pair > vtkKWSequenceImporterPage1::GetValidFileList (void) const { std::vector< std::pair > List; for (int i=0; iFileList->GetNumberOfRows(); i++) { if (this->FileList->GetCellTextAsInt (i,4)) { std::ostringstream os; std::string file, path, fullname; std::pair pair; double time = this->FileList->GetCellTextAsDouble (i,2); file = this->FileList->GetCellText (i,1); path = this->FileList->GetCellText (i,5); os << path.c_str() << "/" << file.c_str(); fullname = os.str(); pair.first = fullname; pair.second = time; List.push_back (pair); } } return List; } //---------------------------------------------------------------------------- std::vector vtkKWSequenceImporterPage1::GetFileList (void) const { std::vector List; std::ostringstream os; std::string fullname; for (int i=0; iFileList->GetNumberOfRows(); i++) { std::ostringstream os; std::string file, path, fullname; file = this->FileList->GetCellText (i,1); path = this->FileList->GetCellText (i,5); os << path.c_str() << "/" << file.c_str(); fullname = os.str(); List.push_back (fullname); } return List; } //---------------------------------------------------------------------------- bool vtkKWSequenceImporterPage1::AreAllFilesValid (void) const { for (int i=0; iFileList->GetNumberOfRows(); i++) { if (!this->FileList->GetCellTextAsInt (i,4)) return false; } return true; } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage1::ImportCallback() { this->IncomingMode = IMPORT_MODE; this->FileList->DeleteAllRows(); this->NumberOfFiles = 0; vtkKWDICOMImporter *dlg = vtkKWDICOMImporter::New(); //dlg->SetApplication(this->GetApplication()); dlg->SetMasterWindow(this->GetParentTopLevel()); dlg->SetParent(this); dlg->Create(); dlg->SetDisplayPositionToDefault(); dlg->SetPosition (100,100); dlg->Invoke(); if (dlg->GetStatus() != vtkKWDialog::StatusOK) { dlg->Delete(); return; } std::vector outputVolumes = dlg->GetGDCMImporter()->GetDICOMVolumeList(); vtkKWWindowBase *win = this->GetApplication()->GetNthWindow(0); if (win) { win->SetStatusText(ks_("Progress|Building volumes...")); } for (unsigned int i=0; iGetProgressGauge()->SetValue((int)(100.0 * i / outputVolumes.size())); } try { outputVolumes[i]->Build(); } catch (itk::ExceptionObject & e) { std::cerr << e; continue; } try { typedef itk::Image FloatImageType; typedef itk::ImageToVTKImageFilter ConverterType; ConverterType::Pointer converter = ConverterType::New(); converter->SetInput (outputVolumes[i]->GetImage()); converter->Update(); // as soon as the plug between ITK and VTK pipelines does not work // we have to copy the image vtkImageData* input = vtkImageData::New(); input->DeepCopy(converter->GetOutput()); vtkMetaImageData* metadataset = vtkMetaImageData::New(); metadataset->SetDataSet(input); input->Delete(); //const char* defaultname = outputVolumes[i]->GetDescription().c_str(); metadataset->SetName (outputVolumes[i]->GetDescription().c_str()); //delete [] defaultname; ImportedMetaDataSetList.push_back (metadataset); const char* filename = metadataset->GetName(); const char* path = ""; this->InsertElement(filename, path); } catch (itk::ExceptionObject &e) { std::cerr << e; vtkKWMessageDialog::PopupMessage(this->GetApplication(), this->GetParentTopLevel(), "Error", "Cannot open file !\nPlease check the log window for details.", vtkKWMessageDialog::ErrorIcon); continue; } } 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); } dlg->Delete(); this->UpdateTimes(); } std::vector vtkKWSequenceImporterPage1::GetImportedMetaDataSetList (void) const { std::vector ret_list; for (int j=0; jFileList->GetNumberOfRows(); j++) { for (unsigned int i=0; iFileList->GetCellText (j,1); double time = this->FileList->GetCellTextAsDouble (j,2); if (strcmp(name.c_str(), ImportedMetaDataSetList[i]->GetName()) == 0) { ImportedMetaDataSetList[i]->SetTime(time); ret_list.push_back(ImportedMetaDataSetList[i]); break; } } } return ret_list; } //---------------------------------------------------------------------------- bool vtkKWSequenceImporterPage1::GetSameGeometryFlag() { return (bool)this->SameGeometryButton->GetWidget()->GetSelectedState(); }