Program: bbtk
Module: $RCSfile: bbwxvtkViewer2D.cxx,v $
Language: C++
- Date: $Date: 2008/05/15 08:02:37 $
- Version: $Revision: 1.7 $
+ Date: $Date: 2008/06/17 11:12:03 $
+ Version: $Revision: 1.8 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
wxvtkrenderwindowinteractor = new wxVTKRenderWindowInteractor(panel,-1);
wxvtkrenderwindowinteractor->UseCaptureMouseOn();
+
+ imageViewer = vtkImageViewer2::New();
+ imageViewer->SetupInteractor ( wxvtkrenderwindowinteractor );
+
+ mDefaultImage = vtkImageData::New();
+ int dim[3];
+ dim[0] = dim[1] = dim[2] = 1;
+ mDefaultImage->SetDimensions ( dim );
+ mDefaultImage->SetSpacing(1,1,1);
+
+ mDefaultImage->SetScalarTypeToUnsignedChar();
+ mDefaultImage->AllocateScalars();
+ for (int i=0;i<dim[0];i++)
+ for (int j=0;j<dim[1];j++)
+ mDefaultImage->SetScalarComponentFromFloat(i,j,0,0,0);
+
+ backImageData = mDefaultImage;
+ imageViewer->SetInput( backImageData );
+ mUpdateCamera = true;
+
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
sizer -> Add( wxvtkrenderwindowinteractor , 1, wxEXPAND, 0);
panel -> SetSizer(sizer);
panel -> SetAutoLayout(true);
panel -> Layout();
- backImageData = NULL;
- imageViewer = NULL;
-
-
}
//-------------------------------------------------------------------------
// we want to force its destruction without taking care of vtk ref counting
// on the contrary the following vtk objects are deleted with vtk Delete
// std::cout << "Viewer2DWidget::~Viewer2DWidget()" << std::endl;
+ mDefaultImage->Delete();
+
if (backImageData)
{
// backImageData->UnRegister(NULL);
// std::cout << "Viewer2DWidget::UpdateView() "<<mBox->bbGetFullName() << std::endl;
// std::cout << "slice="<<mBox->bbGetInputSlice()<<std::endl;
- if ( (mBox->bbGetInputIn()!=NULL) &&
- (backImageData != mBox->bbGetInputIn()) )
+ if ( ( mBox->bbGetInputIn() == NULL ) &&
+ ( backImageData != mDefaultImage ) )
+ {
+ backImageData = mDefaultImage;
+ mUpdateCamera = true;
+ }
+ else if ( ( mBox->bbGetInputIn() != NULL ) &&
+ (backImageData != mBox->bbGetInputIn()) )
{
- if (imageViewer==NULL)
- {
- imageViewer = vtkImageViewer2::New();
- imageViewer->SetupInteractor ( wxvtkrenderwindowinteractor );
- }
-
- // std::cout << "V2D b="<<backImageData<<std::endl;
-
-
- if (backImageData)
- {
- // std::cout << "V2D r1="<<backImageData->GetReferenceCount()<<std::endl;
- // backImageData->DebugOn();
- // backImageData->UnRegister(NULL);
- }
backImageData = mBox->bbGetInputIn();
-
-
- // std::cout << "V2D r2="<<backImageData->GetReferenceCount()<<std::endl;
- // backImageData->DebugOn();
- // backImageData->PrintSelf(std::cout,0);
-
- // backImageData->Register(NULL);
- imageViewer->SetInput( backImageData );
backImageData->Update();
+ imageViewer->SetInput( backImageData );
+ mUpdateCamera = true;
+ }
+ if (mUpdateCamera)
+ {
int x1,x2,y1,y2,z1,z2;
double spx,spy,spz;
backImageData->GetSpacing(spx,spy,spz);
backImageData->GetExtent (x1,x2,y1,y2,z1,z2);
- bbtkMessage("Output",2,"Viewer2D '"<<mBox->bbGetName()<<"' - Image :"<<std::endl);
- bbtkMessage("Output",2," extent = "<< x1<<"-"<<x2<<" x "<<y1<<"-"<<y2<<" x "<<z1<<"-"<<z2<<std::endl);
- bbtkMessage("Output",2," spacing = "<<spx << " - "<< spy << " - "<<spz<<std::endl);
-
+ // bbtkMessage("Output",2,"Viewer2D '"<<mBox->bbGetName()<<"' - Image :"<<std::endl);
+ // std::cout << " extent = "<< x1<<"-"<<x2<<" x "<<y1<<"-"<<y2<<" x "<<z1<<"-"<<z2<<std::endl;
+ // std::cout << " spacing = "<<spx << " - "<< spy << " - "<<spz<<std::endl;
+
vtkCamera *camera = imageViewer->GetRenderer()->GetActiveCamera();
camera->SetViewUp ( spx*0, -spy*1, spz*0);
camera->SetPosition( spx*(x1+x2)/2, spy*(y1+y2)/2, -spz*10000000);
camera->SetFocalPoint ( spx*(x1+x2)/2 , spy*(y1+y2)/2 , spz*0);
-
camera->ComputeViewPlaneNormal();
camera->SetParallelScale( spx*(x2-x1)/2.0 );
- // imageViewer->GetRenderer()->ResetCamera(x1,x2,y1,y2,z1,z2);
+ //
+ // imageViewer->GetRenderer()->ResetCamera(x1,x2,y1,y2,z1,z2);
+ mUpdateCamera = false;
}
- // std::cout << "update"<<std::endl;
- // std::cout << "OW = "<< mBox->bbGetWindow() << std::endl;
+ // std::cout << "OW = "<< mBox->bbGetWindow() << std::endl;
// std::cout << "CW = "<< mBox->bbGetContainingWindow() << std::endl;
// std::cout << "Sh = "<< mBox->bbIsShown() << std::endl;
-
+
// mBox->bbIsShown() is necessary to be sure that the wxWindow is already
// created and displayed.
// Else when slice != 0 we get an X Window System error with wxGTK
- if ((imageViewer!=NULL)&&
+ if (
(backImageData!=NULL)&&
(mBox->bbIsShown()))
{
if (z<ext[4]) { z=ext[4]; }
if (z>=ext[5]) { z=ext[5]-1; }
- // LG : SetZSlice does not exist anymore in vtk 5 !
- /*
-#if (VTK_MAJOR_VERSION >= 5)
- imageViewer->SetSlice( 0 );
-#else
- imageViewer->SetZSlice( 0 );
-#endif
-
- wxvtkrenderwindowinteractor->Render();
- */
-
#if (VTK_MAJOR_VERSION >= 5)
imageViewer->SetSlice( z );
#else
- //Refresh();
}
//--------------------------------------------------------------------------
+
+
BBTK_BLACK_BOX_IMPLEMENTATION(Viewer2D,bbtk::WxBlackBox);
}
+ void Viewer2D::bbUserConstructor()
+ {
+ bbSetInputIn(0);
+ }
+
/**
* \brief Create wxWidget .
*