#include "vtkKWSequenceImporterPage2.h" #include "vtkObjectFactory.h" #include "vtkKWRenderWidget.h" #include #include #include #include #include #include "vtkKWIcon.h" #include "vtkKWMessageWithLabel.h" #include "vtkKWLabel.h" #include "vtkKWPushButton.h" #include "vtkKWMessage.h" #include #include #include #include #include #include #include //---------------------------------------------------------------------------- vtkStandardNewMacro( vtkKWSequenceImporterPage2 ); vtkCxxRevisionMacro(vtkKWSequenceImporterPage2, "$Revision: 1.3 $"); //---------------------------------------------------------------------------- vtkKWSequenceImporterPage2::vtkKWSequenceImporterPage2() { this->Sequence = 0; this->Preview = 0; this->AttributesMessage = vtkKWMessageWithLabel::New(); this->PreviewButton = vtkKWPushButton::New(); this->RenderWidget = vtkKWRenderWidget::New(); //this->RenderWidget = NULL; this->AttributesText = "No Sequence"; } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage2::PrepareForDelete(void) { this->RenderWidget->RemoveAllChildren(); } //---------------------------------------------------------------------------- vtkKWSequenceImporterPage2::~vtkKWSequenceImporterPage2() { std::cout<<"deleting page 2"<Preview) this->Preview->Delete(); if (this->Sequence) this->Sequence->UnRegister (this); this->PreviewButton->Delete(); this->AttributesMessage->Delete(); this->RenderWidget->Delete(); } //---------------------------------------------------------------------------- void vtkKWSequenceImporterPage2::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->CreateAttributes(); this->CreateRenderWidget(); this->CreatePreviewButton(); this->Pack(); } void vtkKWSequenceImporterPage2::CreateAttributes() { this->AttributesMessage->SetParent(this); this->AttributesMessage->Create(); this->AttributesMessage->SetWidth(300); this->AttributesMessage->GetLabel()->SetImageToPredefinedIcon(vtkKWIcon::IconInfoMini); this->AttributesMessage->GetWidget()->SetText(this->AttributesText.c_str()); this->AttributesMessage->SetBalloonHelpString("Information about the sequence freshly created"); } void vtkKWSequenceImporterPage2::CreatePreviewButton() { this->PreviewButton->SetParent(this); this->PreviewButton->Create(); this->PreviewButton->SetBalloonHelpString("launch preview"); this->PreviewButton->SetImageToPixels(image_deleteall, image_deleteall_width, image_deleteall_height, image_deleteall_pixel_size, image_deleteall_length); this->PreviewButton->SetWidth(32); this->PreviewButton->SetCommand(this, "PreviewButtonCallback"); } void vtkKWSequenceImporterPage2::CreatePreviewTo2D() { if (this->Preview) { this->Preview->Delete(); this->Preview = NULL; } this->Preview = vtkViewImage2D::New(); vtkViewImage2D* view2d = vtkViewImage2D::SafeDownCast(this->Preview); if (!view2d) { vtkErrorMacro("failed to initialize view !"); return; } view2d->SetRenderWindow(this->RenderWidget->GetRenderWindow()); view2d->SetRenderer(this->RenderWidget->GetRenderer()); view2d->SetInteractor(this->RenderWidget->GetRenderWindow()->GetInteractor()); view2d->SetAboutData (""); view2d->SetOrientation(vtkViewImage::AXIAL_ID); view2d->SetBackgroundColor (0,0,0); view2d->SetShowAnnotations (false); view2d->Show2DAxis(false); view2d->SetShowDirections(false); view2d->SetInteractionStyle (vtkViewImage2D::WINDOW_LEVEL_INTERACTION); } void vtkKWSequenceImporterPage2::CreatePreviewTo3D() { if (this->Preview) { this->Preview->Delete(); this->Preview = NULL; } this->Preview = vtkViewImage3D::New(); vtkViewImage3D* view3d = vtkViewImage3D::SafeDownCast(this->Preview); if (!view3d) { vtkErrorMacro("failed to initialize view !"); return; } view3d->SetRenderWindow(this->RenderWidget->GetRenderWindow()); view3d->SetRenderer(this->RenderWidget->GetRenderer()); view3d->SetInteractor(this->RenderWidget->GetRenderWindow()->GetInteractor()); view3d->SetAboutData (""); view3d->SetShowAnnotations (false); } void vtkKWSequenceImporterPage2::CreateRenderWidget() { if (this->RenderWidget) { this->RenderWidget->SetParent(this); this->RenderWidget->Create(); this->RenderWidget->SetWidth(150); this->RenderWidget->SetHeight(150); } } void vtkKWSequenceImporterPage2::Pack() { if (this->AttributesMessage->IsCreated()) { this->Script( "grid %s -sticky nw -column 0 -row 0 -padx 10 -pady 5", this->AttributesMessage->GetWidgetName()); } if (this->RenderWidget && this->RenderWidget->IsCreated()) { this->Script( "grid %s -sticky nw -column 1 -row 0 -padx 10 -pady 5", this->RenderWidget->GetWidgetName()); } if (this->PreviewButton->IsCreated()) { this->Script( "grid %s -sticky nw -column 1 -row 1 -padx 10 -pady 5", this->PreviewButton->GetWidgetName()); } this->Script("grid columnconfigure %s 0 -weight 2", this->GetWidgetName()); this->Script("grid columnconfigure %s 1 -weight 1", this->GetWidgetName()); } void vtkKWSequenceImporterPage2::SetSequence(vtkMetaDataSetSequence* sequence) { if (!this->IsCreated()) { vtkWarningMacro("This method has to be called \nafter the widget has been created !"); return; } if (!sequence) { vtkWarningMacro("Attempt to set sequence with NULL pointer !"); return; } if (this->Sequence) { this->Sequence->UnRegister(this); this->Sequence = NULL; } this->Sequence = sequence; this->Sequence->Register(this); switch(this->Sequence->GetType()) { case vtkMetaDataSet::VTK_META_IMAGE_DATA : this->CreatePreviewTo2D(); break; case vtkMetaDataSet::VTK_META_SURFACE_MESH : case vtkMetaDataSet::VTK_META_VOLUME_MESH : this->CreatePreviewTo3D(); break; default : break; } this->Update(); } void vtkKWSequenceImporterPage2::UpdateAttributes() { if (!this->Sequence) { vtkWarningMacro("cannot create attributes,\nsequence is NULL"); } std::ostringstream os; os << "Sequence has been succesfully created !!" << std::endl << std::endl << std::endl << std::endl << "name : \t\t"<< this->Sequence->GetName()<< std::endl << "dataset type : \t"<< this->Sequence->GetDataSetType()<< std::endl << "duration : \t"<< this->Sequence->GetSequenceDuration()<< std::endl << "n. of files : \t"<< this->Sequence->GetNumberOfMetaDataSets()<< std::endl; this->AttributesText = os.str(); this->AttributesMessage->GetWidget()->SetText(this->AttributesText.c_str()); } void vtkKWSequenceImporterPage2::Update() { this->UpdateAttributes(); this->UpdatePreview(); } void vtkKWSequenceImporterPage2::PreviewButtonCallback() { if (!this->Sequence) { vtkWarningMacro("cannot create preview,\nsequence is NULL"); } double beginning = this->Sequence->GetMinTime(); double ending = this->Sequence->GetMaxTime(); double step = this->Sequence->GetTimeResolution(); double time = 0; for (time=beginning; time<=ending; time+=step) { this->Sequence->UpdateToTime(time); if (this->Preview) this->Preview->Render(); } } void vtkKWSequenceImporterPage2::UpdatePreview() { if (!this->Sequence) { vtkWarningMacro("cannot create preview,\nsequence is NULL"); return; } if (!this->Preview) { vtkWarningMacro("cannot create preview,\npreview is NULL"); return; } vtkImageData* image = vtkImageData::SafeDownCast (this->Sequence->GetDataSet()); vtkDataSet* dataset = this->Sequence->GetDataSet(); if (image) { vtkViewImage2D* view2d = vtkViewImage2D::SafeDownCast(this->Preview); if (!view2d) { vtkErrorMacro("failed to initialize view !"); return; } view2d->DrawOff(); view2d->SetImage(image); view2d->Reset(); view2d->DrawOn(); } else if (dataset) { this->Preview->AddDataSet (dataset); } }