#include <bbwxvtkViewer2D.h>
Public Member Functions | |
Viewer2DWidget (Viewer2D *box, wxWindow *parent) | |
~Viewer2DWidget () | |
void | UpdateView () |
vtkRenderer * | GetRenderer () |
Private Attributes | |
Viewer2D * | mBox |
vtkImageViewer2 * | imageViewer |
vtkImageData * | backImageData |
vtkImageData * | mDefaultImage |
wxVTKRenderWindowInteractor * | wxvtkrenderwindowinteractor |
bool | mUpdateCamera |
vtkImplicitPlaneWidget * | maPlane1 |
vtkImplicitPlaneWidget * | maPlane2 |
vtkImplicitPlaneWidget * | mbPlane1 |
vtkImplicitPlaneWidget * | mbPlane2 |
Definition at line 55 of file bbwxvtkViewer2D.h.
bbwxvtk::Viewer2DWidget::Viewer2DWidget | ( | Viewer2D * | box, | |
wxWindow * | parent | |||
) |
Definition at line 45 of file bbwxvtkViewer2D.cxx.
References backImageData, imageViewer, mDefaultImage, mUpdateCamera, bbwxvtk::wxVTKRenderWindowInteractor::Refresh(), bbwxvtk::wxVTKRenderWindowInteractor::Render(), and wxvtkrenderwindowinteractor.
00047 : 00048 wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), 00049 mBox(box) 00050 { 00051 wxPanel *panel = this; 00052 00053 wxvtkrenderwindowinteractor = new wxVTKRenderWindowInteractor(panel,-1); 00054 wxvtkrenderwindowinteractor->UseCaptureMouseOn(); 00055 00056 imageViewer = vtkImageViewer2::New(); 00057 imageViewer->SetSlice( 1 ); 00058 imageViewer->SetupInteractor ( wxvtkrenderwindowinteractor ); 00059 00060 mDefaultImage = vtkImageData::New(); 00061 int dim[3]; 00062 dim[0] = dim[1] = 32 ; 00063 dim[2] = 2; 00064 mDefaultImage->SetDimensions ( dim ); 00065 mDefaultImage->SetSpacing(1,1,1); 00066 mDefaultImage->SetExtent(0,dim[0]-1,0,dim[1]-1,0,dim[2]-1); 00067 mDefaultImage->SetWholeExtent(0,dim[0]-1,0,dim[1]-1,0,dim[2]-1); 00068 00069 mDefaultImage->SetScalarTypeToUnsignedChar(); 00070 mDefaultImage->AllocateScalars(); 00071 for (int i=0;i<dim[0];i++) 00072 for (int j=0;j<dim[1];j++) 00073 for (int k=0;k<dim[2];k++) 00074 mDefaultImage->SetScalarComponentFromFloat(i,j,k,0,0); 00075 00076 for (int i=0;i<dim[0];i++) 00077 { 00078 mDefaultImage->SetScalarComponentFromFloat(dim[0]-i-1,i,0,0,255); 00079 mDefaultImage->SetScalarComponentFromFloat(i,i,1,0,255); 00080 } 00081 00082 backImageData = mDefaultImage; 00083 imageViewer->SetInput( backImageData ); 00084 mUpdateCamera = true; 00085 00086 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); 00087 sizer-> Add( wxvtkrenderwindowinteractor , 1, wxEXPAND, 0); 00088 panel-> SetSizer(sizer); 00089 panel-> SetAutoLayout(true); 00090 panel-> Layout(); 00091 00092 00093 wxvtkrenderwindowinteractor->Refresh(); 00094 wxvtkrenderwindowinteractor->Render(); 00095 imageViewer->GetRenderer()->ResetCameraClippingRange(); 00096 00097 00098 }
bbwxvtk::Viewer2DWidget::~Viewer2DWidget | ( | ) |
Definition at line 101 of file bbwxvtkViewer2D.cxx.
References backImageData, imageViewer, mDefaultImage, and wxvtkrenderwindowinteractor.
00102 { 00103 // delete wxvtkrenderwindowinteractor; 00104 // pourquoi pas wxvtkrenderwindowinteractor->Delete(); // JP 00105 // LG : because it has been allocated with operator new not method ::New 00106 // we want to force its destruction without taking care of vtk ref counting 00107 // on the contrary the following vtk objects are deleted with vtk Delete 00108 // std::cout << "Viewer2DWidget::~Viewer2DWidget()" << std::endl; 00109 mDefaultImage->Delete(); 00110 00111 if (backImageData) 00112 { 00113 // backImageData->UnRegister(NULL); 00114 } 00115 if (imageViewer) 00116 { 00117 imageViewer->Delete(); 00118 } 00119 delete wxvtkrenderwindowinteractor; 00120 // std::cout << "Viewer2DWidget::~Viewer2DWidget() OK" << std::endl; 00121 }
void bbwxvtk::Viewer2DWidget::UpdateView | ( | ) |
Definition at line 128 of file bbwxvtkViewer2D.cxx.
References backImageData, imageViewer, mBox, mDefaultImage, mUpdateCamera, bbwxvtk::wxVTKRenderWindowInteractor::Render(), and wxvtkrenderwindowinteractor.
00129 { 00130 // std::cout << "Viewer2DWidget::UpdateView() "<<mBox->bbGetFullName() << std::endl; 00131 // std::cout << "slice="<<mBox->bbGetInputSlice()<<std::endl; 00132 00133 00134 if ( ( mBox->bbGetInputIn() == NULL ) && 00135 ( backImageData != mDefaultImage ) ) 00136 { 00137 backImageData = mDefaultImage; 00138 mUpdateCamera = true; 00139 } 00140 else if ( ( mBox->bbGetInputIn() != NULL ) && 00141 (backImageData != mBox->bbGetInputIn()) ) 00142 { 00143 backImageData = mBox->bbGetInputIn(); 00144 backImageData->Update(); 00145 imageViewer->SetInput( backImageData ); 00146 mUpdateCamera = true; 00147 } 00148 00149 if (mUpdateCamera) 00150 { 00151 int x1,x2,y1,y2,z1,z2; 00152 double spx,spy,spz; 00153 backImageData->GetSpacing(spx,spy,spz); 00154 backImageData->GetExtent (x1,x2,y1,y2,z1,z2); 00155 00156 // bbtkMessage("Output",2,"Viewer2D '"<<mBox->bbGetName()<<"' - Image :"<<std::endl); 00157 // std::cout << " extent = "<< x1<<"-"<<x2<<" x "<<y1<<"-"<<y2<<" x "<<z1<<"-"<<z2<<std::endl; 00158 // std::cout << " spacing = "<<spx << " - "<< spy << " - "<<spz<<std::endl; 00159 00160 vtkCamera *camera = imageViewer->GetRenderer()->GetActiveCamera(); 00161 00162 camera->SetViewUp ( spx*0, -spy*1, spz*0 ); 00163 camera->SetPosition ( spx*(x1+x2)/2, spy*(y1+y2)/2, -spz*10000000 ); 00164 camera->SetFocalPoint( spx*(x1+x2)/2, spy*(y1+y2)/2, spz*0 ); 00165 00166 camera->ComputeViewPlaneNormal(); 00167 camera->SetParallelScale( spx*(x2-x1)/2.0 ); 00168 // 00169 // imageViewer->GetRenderer()->ResetCamera(x1,x2,y1,y2,z1,z2); 00170 mUpdateCamera = false; 00171 } 00172 00173 // std::cout << "OW = "<< mBox->bbGetWindow() << std::endl; 00174 // std::cout << "CW = "<< mBox->bbGetContainingWindow() << std::endl; 00175 // std::cout << "Sh = "<< mBox->bbIsShown() << std::endl; 00176 00177 int orientation = mBox->bbGetInputOrientation(); 00178 if (orientation<0 || orientation>2) 00179 orientation=2; // Why not? 00180 00181 // mBox->bbIsShown() is necessary to be sure that the wxWindow is already 00182 // created and displayed. 00183 // Else when slice != 0 we get an X Window System error with wxGTK 00184 if ( 00185 (backImageData!=NULL)&& 00186 (mBox->bbIsShown())) 00187 { 00188 int z = mBox->bbGetInputSlice(); 00189 // std::cout << "slice = "<<z<<std::endl; 00190 int ext[6]; 00191 backImageData->GetWholeExtent(ext); 00192 00193 // std::cout << "ext = "<<ext[4]<<" - "<<ext[5]<<std::endl; 00194 00195 switch(orientation){ 00196 case 0: 00197 if (z<ext[0]) { z=ext[0]; } 00198 if (z>ext[1]) { z=ext[1]; } 00199 00200 break; 00201 00202 case 1: 00203 if (z<ext[2]) { z=ext[2]; } 00204 if (z>ext[3]) { z=ext[3]; } 00205 break; 00206 00207 case 2: 00208 if (z<ext[4]) { z=ext[4]; } 00209 if (z>ext[5]) { z=ext[5]; } 00210 break; 00211 00212 default: 00213 z = ext[5]; // Why not? 00214 } 00215 00216 wxvtkrenderwindowinteractor->Update(); 00217 wxvtkrenderwindowinteractor->Render(); 00218 imageViewer->GetRenderer()->ResetCameraClippingRange(); 00219 00220 /* 00221 #if (VTK_MAJOR_VERSION >= 5) 00222 imageViewer->SetSlice( z ); 00223 #else 00224 imageViewer->SetZSlice( z ); 00225 #endif 00226 */ 00227 imageViewer->SetSliceOrientation (orientation); 00228 imageViewer->SetSlice( z ); 00229 00230 //imageViewer->UpdateDisplayExtent(); 00231 } 00232 00233 00234 }
vtkRenderer * bbwxvtk::Viewer2DWidget::GetRenderer | ( | ) |
Definition at line 237 of file bbwxvtkViewer2D.cxx.
References imageViewer.
00238 { 00239 return imageViewer->GetRenderer(); 00240 }
Viewer2D* bbwxvtk::Viewer2DWidget::mBox [private] |
vtkImageViewer2* bbwxvtk::Viewer2DWidget::imageViewer [private] |
Definition at line 64 of file bbwxvtkViewer2D.h.
Referenced by GetRenderer(), UpdateView(), Viewer2DWidget(), and ~Viewer2DWidget().
vtkImageData* bbwxvtk::Viewer2DWidget::backImageData [private] |
Definition at line 65 of file bbwxvtkViewer2D.h.
Referenced by UpdateView(), Viewer2DWidget(), and ~Viewer2DWidget().
vtkImageData* bbwxvtk::Viewer2DWidget::mDefaultImage [private] |
Definition at line 66 of file bbwxvtkViewer2D.h.
Referenced by UpdateView(), Viewer2DWidget(), and ~Viewer2DWidget().
Definition at line 67 of file bbwxvtkViewer2D.h.
Referenced by UpdateView(), Viewer2DWidget(), and ~Viewer2DWidget().
bool bbwxvtk::Viewer2DWidget::mUpdateCamera [private] |
vtkImplicitPlaneWidget* bbwxvtk::Viewer2DWidget::maPlane1 [private] |
Definition at line 70 of file bbwxvtkViewer2D.h.
vtkImplicitPlaneWidget * bbwxvtk::Viewer2DWidget::maPlane2 [private] |
Definition at line 70 of file bbwxvtkViewer2D.h.
vtkImplicitPlaneWidget * bbwxvtk::Viewer2DWidget::mbPlane1 [private] |
Definition at line 70 of file bbwxvtkViewer2D.h.
vtkImplicitPlaneWidget * bbwxvtk::Viewer2DWidget::mbPlane2 [private] |
Definition at line 70 of file bbwxvtkViewer2D.h.