#include "vtkKWPageView.h" #include "vtkKWApplication.h" #include "vtkKWRenderWidget.h" #include "vtkKWIcon.h" #include "vtkObjectFactory.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include //---------------------------------------------------------------------------- vtkStandardNewMacro( vtkKWPageView ); vtkCxxRevisionMacro( vtkKWPageView, "$Revision: 1.6 $"); //---------------------------------------------------------------------------- vtkKWPageView::vtkKWPageView() { this->View1 = vtkViewImage2D::New(); this->View2 = vtkViewImage2D::New(); this->View3 = vtkViewImage2D::New(); this->View4 = vtkViewImage3D::New(); this->RenderWidget1 = vtkKWRenderWidget::New(); this->RenderWidget2 = vtkKWRenderWidget::New(); this->RenderWidget3 = vtkKWRenderWidget::New(); this->RenderWidget4 = vtkKWRenderWidget::New(); this->IsFullScreen = 0; } //---------------------------------------------------------------------------- vtkKWPageView::~vtkKWPageView() { std::cout<<"deleting vtkKWPageView "<GetTag()<View1->Detach(); this->View2->Detach(); this->View3->Detach(); this->View4->Detach(); this->View1->SetRenderWindow (NULL); this->View1->SetRenderer (NULL); this->View1->Delete(); this->View2->Delete(); this->View3->Delete(); this->View4->Delete(); this->RenderWidget1->Delete(); this->RenderWidget2->Delete(); this->RenderWidget3->Delete(); this->RenderWidget4->Delete(); } //---------------------------------------------------------------------------- void vtkKWPageView::CreateRenderWidgets() { this->RenderWidget1->SetParent(this); this->RenderWidget1->Create(); this->RenderWidget2->SetParent(this); this->RenderWidget2->Create(); this->RenderWidget3->SetParent(this); this->RenderWidget3->Create(); this->RenderWidget4->SetParent(this); this->RenderWidget4->Create(); } //---------------------------------------------------------------------------- void vtkKWPageView::Create4Views() { this->View1->SetRenderWindow(this->RenderWidget1->GetRenderWindow()); this->View2->SetRenderWindow(this->RenderWidget2->GetRenderWindow()); this->View3->SetRenderWindow(this->RenderWidget3->GetRenderWindow()); this->View4->SetRenderWindow(this->RenderWidget4->GetRenderWindow()); this->View1->SetRenderer(this->RenderWidget1->GetRenderer()); this->View2->SetRenderer(this->RenderWidget2->GetRenderer()); this->View3->SetRenderer(this->RenderWidget3->GetRenderer()); this->View4->SetRenderer(this->RenderWidget4->GetRenderer()); this->View1->GetRenderWindowInteractor()->LightFollowCameraOn(); this->View2->GetRenderWindowInteractor()->LightFollowCameraOn(); this->View3->GetRenderWindowInteractor()->LightFollowCameraOn(); // this->View2->AddViewToObserve (this->View1); // this->View3->AddViewToObserve (this->View2); // this->View1->AddViewToObserve (this->View3); // this->View4->AddViewToObserve (this->View3); // this->View1->AddViewToObserve (this->View4); this->View2->AddChild (this->View1); this->View3->AddChild (this->View2); this->View4->AddChild (this->View3); this->View1->AddChild (this->View4); } //---------------------------------------------------------------------------- void vtkKWPageView::SetProperties() { this->View1->SetOrientation (vtkViewImage::AXIAL_ID); this->View2->SetOrientation (vtkViewImage::CORONAL_ID); this->View3->SetOrientation (vtkViewImage::SAGITTAL_ID); this->View1->SetAboutData ("INRIA 2007 - CardioViz3D"); this->View2->SetAboutData ("INRIA 2007 - CardioViz3D"); this->View3->SetAboutData ("INRIA 2007 - CardioViz3D"); this->View4->SetAboutData ("INRIA 2007 - CardioViz3D"); this->View1->SetBackgroundColor (0,0,0); this->View2->SetBackgroundColor (0,0,0); this->View3->SetBackgroundColor (0,0,0); this->View4->SetBackgroundColor (0.9,0.9,0.9); double textcolor[3]={0.0,0.0,0.0}; this->View4->SetTextColor (textcolor); this->View4->SetRenderingModeToPlanar(); } void vtkKWPageView::PackSelf() { this->UnpackChildren(); this->Script ("grid %s -column 0 -row 0 -sticky news", this->RenderWidget1->GetWidgetName()); this->Script ("grid %s -column 1 -row 0 -sticky news", this->RenderWidget2->GetWidgetName()); this->Script ("grid %s -column 0 -row 1 -sticky news", this->RenderWidget3->GetWidgetName()); this->Script ("grid %s -column 1 -row 1 -sticky news", this->RenderWidget4->GetWidgetName()); this->Script ("grid columnconfigure %s 0 -weight 1", this->GetWidgetName()); this->Script ("grid columnconfigure %s 1 -weight 1", this->GetWidgetName()); this->Script ("grid rowconfigure %s 0 -weight 1", this->GetWidgetName()); this->Script ("grid rowconfigure %s 1 -weight 1", this->GetWidgetName()); } //---------------------------------------------------------------------------- void vtkKWPageView::CreateWidget() { // Check if already created if (this->IsCreated()) { vtkErrorMacro("class already created"); return; } // Call the superclass to create the whole widget this->Superclass::CreateWidget(); // attach the RenderWidgets to the view frame, and pack this->CreateRenderWidgets(); // attach the Views to the RenderWidgets this->Create4Views(); // pack everything this->PackSelf(); // and Set the properties ! this->SetProperties(); } void vtkKWPageView::SetImage (vtkImageData* image) { if (!image) return; this->View1->DrawOff(); this->View2->DrawOff(); this->View3->DrawOff(); this->View4->DrawOff(); this->View1->SetImage(image); this->View2->SetImage(image); this->View3->SetImage(image); this->View4->SetImage(image); this->View1->SyncReset(); this->View1->DrawOn(); this->View2->DrawOn(); this->View3->DrawOn(); this->View4->DrawOn(); } vtkImageData* vtkKWPageView::GetImage () { return this->View1->GetImage(); } //--------------------------------------------------------------------------- int vtkKWPageView::BuildScreenshotFromImage(vtkImageData *image, vtkKWIcon* screenshot, int size) { if (!image || !screenshot) { return 0; } // Empty image, remove thumbnail/screenshot int image_dims[3]; image->GetDimensions(image_dims); if (image_dims[0] == 0 || image_dims[1] == 0 || image_dims[2] == 0) { return 0; } double factor; vtkImageData *resample_input, *resample_output; // First, let's make sure we are processing the image as it // is by clipping its UpdateExtent. By doing so, we prevent our resample // and permute filter the process the image's *whole* extent. vtkImageClip *clip = vtkImageClip::New(); clip->SetInput(image); clip->SetOutputWholeExtent(image->GetUpdateExtent()); clip->Update(); // Permute, as a convenience int clip_dims[3]; clip->GetOutput()->GetDimensions(clip_dims); vtkImagePermute *permute = NULL; if (clip_dims[2] != 1) { permute = vtkImagePermute::New(); permute->SetInput(clip->GetOutput()); if (clip_dims[0] == 1) { permute->SetFilteredAxes(1, 2, 0); } else { permute->SetFilteredAxes(0, 2, 1); } resample_input = permute->GetOutput(); } else { resample_input = clip->GetOutput(); } resample_input->Update(); int resample_input_dims[3], resample_output_dims[3]; resample_input->GetDimensions(resample_input_dims); double *resample_input_spacing = resample_input->GetSpacing(); int large_dim = 0, small_dim = 1; if (resample_input_dims[0] < resample_input_dims[1]) { large_dim = 1; small_dim = 0; } vtkImageResample *resample = vtkImageResample::New(); resample->SetInput(resample_input); resample->SetInterpolationModeToCubic(); resample->SetDimensionality(2); // Create the screenshot factor = (double)size / (double)resample_input_dims[large_dim]; resample->SetAxisMagnificationFactor(large_dim, factor); resample->SetAxisMagnificationFactor( small_dim, factor * (resample_input_spacing[small_dim] / resample_input_spacing[large_dim])); resample->Update(); resample_output = resample->GetOutput(); resample_output->GetDimensions(resample_output_dims); screenshot->SetImage( (const unsigned char*)resample_output->GetScalarPointer(), resample_output_dims[0], resample_output_dims[1], 3, 0, vtkKWIcon::ImageOptionFlipVertical); // Deallocate clip->Delete(); resample->Delete(); if (permute) { permute->Delete(); } return 1; } //--------------------------------------------------------------------------- int vtkKWPageView::BuildScreenshotFromRenderWindow(vtkRenderWindow *win, vtkKWIcon* screenshot, int size) { if (win && screenshot) { vtkWindowToImageFilter *filter = vtkWindowToImageFilter::New(); filter->ShouldRerenderOff(); filter->SetInput(win); filter->Update(); int res = this->BuildScreenshotFromImage(filter->GetOutput(), screenshot, size); filter->Delete(); return res; } return 0; } int vtkKWPageView::GetAxialScreenshot(vtkKWIcon* screenshot, int size) { return this->BuildScreenshotFromRenderWindow (this->RenderWidget1->GetRenderWindow(), screenshot, size); } void vtkKWPageView::Render (void) { this->View1->Render(); this->View2->Render(); this->View3->Render(); this->View4->Render(); } void vtkKWPageView::ToggleFullScreenView4 (void) { if (this->IsFullScreen != 4) { this->View1->DrawOff(); this->View2->DrawOff(); this->View3->DrawOff(); this->UnpackChildren(); this->Script ("grid remove %s", this->RenderWidget1->GetWidgetName()); this->Script ("grid remove %s", this->RenderWidget2->GetWidgetName()); this->Script ("grid remove %s", this->RenderWidget3->GetWidgetName()); this->Script ("grid remove %s", this->RenderWidget4->GetWidgetName()); this->Script ("pack %s -side top -expand yes -fill both -padx 2 -pady 2", this->RenderWidget4->GetWidgetName()); this->View4->Update(); this->View4->Render(); this->IsFullScreen = 4; } else { this->View1->DrawOn(); this->View2->DrawOn(); this->View3->DrawOn(); this->PackSelf(); this->IsFullScreen = 0; } } void vtkKWPageView::ToggleFullScreenAxial (void) { if (this->IsFullScreen != 1) { this->View2->DrawOff(); this->View3->DrawOff(); this->View4->DrawOff(); this->UnpackChildren(); this->Script ("grid remove %s", this->RenderWidget1->GetWidgetName()); this->Script ("grid remove %s", this->RenderWidget2->GetWidgetName()); this->Script ("grid remove %s", this->RenderWidget3->GetWidgetName()); this->Script ("grid remove %s", this->RenderWidget4->GetWidgetName()); this->Script ("pack %s -side top -expand yes -fill both -padx 2 -pady 2", this->RenderWidget1->GetWidgetName()); this->View1->Update(); this->View1->Render(); this->IsFullScreen = 1; } else { this->View2->DrawOn(); this->View3->DrawOn(); this->View4->DrawOn(); this->PackSelf(); this->IsFullScreen = 0; } } void vtkKWPageView::ToggleFullScreenSagittal (void) { if (this->IsFullScreen != 2) { this->View1->DrawOff(); this->View2->DrawOff(); this->View4->DrawOff(); this->UnpackChildren(); this->Script ("grid remove %s", this->RenderWidget1->GetWidgetName()); this->Script ("grid remove %s", this->RenderWidget2->GetWidgetName()); this->Script ("grid remove %s", this->RenderWidget3->GetWidgetName()); this->Script ("grid remove %s", this->RenderWidget4->GetWidgetName()); this->Script ("pack %s -side top -expand yes -fill both -padx 2 -pady 2", this->RenderWidget3->GetWidgetName()); this->View3->Update(); this->View3->Render(); this->IsFullScreen = 2; } else { this->View1->DrawOn(); this->View2->DrawOn(); this->View4->DrawOn(); this->PackSelf(); this->IsFullScreen = 0; } } void vtkKWPageView::ToggleFullScreenCoronal (void) { if (this->IsFullScreen != 3) { this->View1->DrawOff(); this->View3->DrawOff(); this->View4->DrawOff(); this->UnpackChildren(); this->Script ("grid remove %s", this->RenderWidget1->GetWidgetName()); this->Script ("grid remove %s", this->RenderWidget2->GetWidgetName()); this->Script ("grid remove %s", this->RenderWidget3->GetWidgetName()); this->Script ("grid remove %s", this->RenderWidget4->GetWidgetName()); this->Script ("pack %s -side top -expand yes -fill both -padx 2 -pady 2", this->RenderWidget2->GetWidgetName()); this->View2->Update(); this->View2->Render(); this->IsFullScreen = 3; } else { this->View1->DrawOn(); this->View2->DrawOn(); this->View4->DrawOn(); this->PackSelf(); this->IsFullScreen = 0; } } int vtkKWPageView::GetVisibility (vtkDataSet* dataset) { if (!dataset) return false; if (this->GetImage() && dataset == this->GetImage()) { return this->View1->GetVisibility (); } if (this->View1->HasDataSet (dataset)) return this->View1->GetDataSetActor (dataset)->GetVisibility (); if (this->View2->HasDataSet (dataset)) return this->View2->GetDataSetActor (dataset)->GetVisibility (); if (this->View3->HasDataSet (dataset)) return this->View3->GetDataSetActor (dataset)->GetVisibility (); if (this->View4->HasDataSet (dataset)) return this->View4->GetDataSetActor (dataset)->GetVisibility (); } void vtkKWPageView::SetVisibility (vtkDataSet* dataset, bool state) { if (!dataset) return; if (this->GetImage() && dataset == this->GetImage()) { this->View1->SetVisibility (state); this->View2->SetVisibility (state); this->View3->SetVisibility (state); this->View4->SetVisibility (state); } if (this->View1->HasDataSet (dataset)) this->View1->GetDataSetActor (dataset)->SetVisibility (state); if (this->View2->HasDataSet (dataset)) this->View2->GetDataSetActor (dataset)->SetVisibility (state); if (this->View3->HasDataSet (dataset)) this->View3->GetDataSetActor (dataset)->SetVisibility (state); if (this->View4->HasDataSet (dataset)) this->View4->GetDataSetActor (dataset)->SetVisibility (state); } //---------------------------------------------------------------------------- const char* vtkKWPageView::GetTag (void) const { return this->Tag.c_str(); } //---------------------------------------------------------------------------- void vtkKWPageView::SetTag (const char* tag) { this->Tag = tag; } void vtkKWPageView::SetScalarBarVisibility (bool state) { this->View1->SetScalarBarVisibility(state); this->View2->SetScalarBarVisibility(state); this->View3->SetScalarBarVisibility(state); this->View4->SetScalarBarVisibility(state); } int vtkKWPageView::GetScalarBarVisibility (void) const { return this->View1->GetScalarBarVisibility(); } void vtkKWPageView::SetLookupTable (vtkLookupTable* lut) { if( !lut ) { return; } this->View1->SyncSetLookupTable (lut); } void vtkKWPageView::RemoveDataSet(vtkDataSet* dataset) { this->View1->RemoveDataSet(dataset); this->View2->RemoveDataSet(dataset); this->View3->RemoveDataSet(dataset); this->View4->RemoveDataSet(dataset); } std::vector vtkKWPageView::AddDataSet(vtkDataSet* dataset, vtkProperty* property) { std::vector list; vtkActor* actor1 = NULL; vtkActor* actor2 = NULL; vtkActor* actor3 = NULL; vtkActor* actor4 = NULL; actor1 = this->View1->AddDataSet(dataset, property); actor2 = this->View2->AddDataSet(dataset, property); actor3 = this->View3->AddDataSet(dataset, property); actor4 = this->View4->AddDataSet(dataset, property); if (actor1) list.push_back(actor1); if (actor2) list.push_back(actor2); if (actor3) list.push_back(actor3); if (actor4) list.push_back(actor4); return list; } std::vector vtkKWPageView::AddPolyData(vtkPolyData* dataset, vtkProperty* property, double thickness) { std::vector list; vtkActor* actor1 = NULL; vtkActor* actor2 = NULL; vtkActor* actor3 = NULL; vtkActor* actor4 = NULL; actor1 = this->View1->AddPolyData(dataset, property, thickness); actor2 = this->View2->AddPolyData(dataset, property, thickness); actor3 = this->View3->AddPolyData(dataset, property, thickness); if (actor1) list.push_back(actor1); if (actor2) list.push_back(actor2); if (actor3) list.push_back(actor3); return list; } vtkKWRenderWidget* vtkKWPageView::GetActiveRenderWidget () { switch(this->IsFullScreen) { case 1 : return this->GetRenderWidget1(); break; case 2 : return this->GetRenderWidget2(); break; case 3 : return this->GetRenderWidget3(); break; default : return this->GetRenderWidget4(); break; } }