Program: bbtk
Module: $RCSfile: bbitkvtkitkImage2vtkImageData.cxx,v $
Language: C++
- Date: $Date: 2008/05/09 10:39:46 $
- Version: $Revision: 1.3 $
+ Date: $Date: 2008/05/14 07:01:00 $
+ Version: $Revision: 1.4 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
template<class T>
void itkImage2vtkImageData::Convert()
{
- bbtkDebugMessageInc("Core",9,"itkImage2vtkImageData<"
- <<bbtk::TypeName<T>()
- <<">::Convert()"<<std::endl);
+ bbtkDebugMessage("process",5,"==> ["<<bbGetFullName()<<"] : Convert<"
+ <<bbtk::TypeName<T>()
+ <<">()"<<std::endl);
typedef T itkImageType;
- // typedef itk::VTKImageToImageFilter< itkImageType > VtkToItkConnection;
typedef itk::ImageToVTKImageFilter< itkImageType > ItkToVtkConnection;
+ typename ItkToVtkConnection::Pointer conv;
-
- try
+ // No converter yet : create it and set its input
+ if (!mConverter)
{
- typename ItkToVtkConnection::Pointer conv = ItkToVtkConnection::New();
+ bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : No converter yet : creating it"<<std::endl);
+ conv = ItkToVtkConnection::New();
+ mConverter = conv;
conv->SetInput( this->bbGetInputIn().get<itkImageType*>() );
+ }
+ else
+ {
+ bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Converter ok "<<std::endl);
+
+ // Input itkImageType type changed ?
+ // Have to change the converter and set its input
+ conv = dynamic_cast<ItkToVtkConnection*>
+ ((itk::ProcessObject*)mConverter);
+ if (!conv)
+ {
+ bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Converter of wrong input type : reacreating it "<<std::endl);
+
+ mConverter->UnRegister();
+ conv = ItkToVtkConnection::New();
+ mConverter = conv;
+ conv->SetInput( this->bbGetInputIn().get<itkImageType*>() );
+ }
+ // Input image type did not change but input image pointer did:
+ // set new input
+ else if ( this->bbGetInputIn().get<itkImageType*>()
+ != (itkImageType*)(conv->GetExporter()->GetInputs()[0].GetPointer()))
+ {
+ bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Converter input changed : resetting it"<<std::endl);
+
+ conv->SetInput( this->bbGetInputIn().get<itkImageType*>() );
+ }
+ else
+ {
+ bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Nothing changed"<<std::endl);
+
+ }
+ }
+ try
+ {
+
+ bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Trying update"<<std::endl);
+
conv->Update();
- if (bbGetOutputOut()) bbGetOutputOut()->UnRegister(NULL);
bbSetOutputOut(conv->GetOutput());
- // bbGetOutputOut()->DebugOn();
- bbGetOutputOut()->Register(NULL);
- bbGetOutputOut()->SetSource(NULL);
}
catch( itk::ExceptionObject & e)
{
<<bbtk::TypeName<T>()
<<">::Convert() : "<<e);
}
- bbtkDebugDecTab("Core",9);
- }
+ bbtkDebugMessage("process",5,"<== ["<<bbGetFullName()<<"] : Convert<"
+ <<bbtk::TypeName<T>()
+ <<">() *DONE*"<<std::endl);
+
+
+ }
void itkImage2vtkImageData::bbUserConstructor()
{
bbSetOutputOut(NULL);
+ mConverter = 0;
}
void itkImage2vtkImageData::bbUserCopyConstructor()
{
bbSetOutputOut(NULL);
+ mConverter = 0;
}
void itkImage2vtkImageData::bbUserDestructor()
{
- if (bbGetOutputOut())
- {
- bbGetOutputOut()->UnRegister(NULL);
- }
}
-
+
}
// eo namespace bbitkvtk
Program: bbtk
Module: $RCSfile: bbitkvtkitkImage2vtkImageData.h,v $
Language: C++
- Date: $Date: 2008/05/09 10:39:46 $
- Version: $Revision: 1.4 $
+ Date: $Date: 2008/05/14 07:01:00 $
+ Version: $Revision: 1.5 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
// Convert method template on type of the itk image
// embedded in the input itkImage*
template<class T> void Convert();
-
-
+ // stores the pointer on the template itk::ImageToVTKImageFilter
+ itk::ProcessObject::Pointer mConverter;
};
Program: bbtk
Module: $RCSfile: bbitkvtkvtkImageData2itkImage.cxx,v $
Language: C++
- Date: $Date: 2008/04/18 12:59:50 $
- Version: $Revision: 1.2 $
+ Date: $Date: 2008/05/14 07:01:00 $
+ Version: $Revision: 1.3 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
template<class T, unsigned int D>
void vtkImageData2itkImage::Convert()
{
- bbtkDebugMessageInc("Core",9,"vtkImageData2itkImage<"
+ bbtkDebugMessage("process",5,"==> ["<<bbGetFullName()<<"] : Convert<"
<<bbtk::TypeName<T>()<<","<<D
- <<">::Convert()"<<std::endl);
+ <<">()"<<std::endl);
+
typedef itk::Image<T,D> itkImageType;
typedef itk::VTKImageToImageFilter< itkImageType > VtkToItkConnection;
- //typedef itk::ImageToVTKImageFilter< itkImageType > ItkToVtkConnection;
+ typename VtkToItkConnection::Pointer conv;
-
- try
+ // No converter yet : create it and set its input
+ if (!mConverter)
{
- typename VtkToItkConnection::Pointer conv = VtkToItkConnection::New();
+ bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : No converter yet : creating it"<<std::endl);
+ conv = VtkToItkConnection::New();
+ mConverter = conv;
conv->SetInput( this->bbGetInputIn() );
- conv->Update();
-
- // How to unreference the old output (is in an any...) ?
- //if (bbGetOutputOut()) bbGetOutputOut()->Unreference();
+ }
+ else
+ {
+ bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Converter ok "<<std::endl);
+ // Input vtkImage type changed ?
+ // Have to change the converter and set its input
+ conv = dynamic_cast<VtkToItkConnection*>
+ ((itk::ProcessObject*)mConverter);
+ if (!conv)
+ {
+ bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Converter of wrong input type : reacreating it "<<std::endl);
+ mConverter->UnRegister();
+ conv = VtkToItkConnection::New();
+ mConverter = conv;
+ conv->SetInput( this->bbGetInputIn() );
+ }
+ // Input image type did not change but input image pointer did:
+ // set new input
+ else if ( this->bbGetInputIn() != conv->GetExporter()->GetInput())
+ {
+ bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Converter input changed : resetting it"<<std::endl);
+ conv->SetInput( this->bbGetInputIn() );
+ }
+ else
+ {
+ bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Nothing changed"<<std::endl);
+ }
+ }
+ try
+ {
+ bbtkDebugMessage("process",5," ["<<bbGetFullName()<<"] : Trying update"<<std::endl);
+ conv->Update();
itkImageType* out = const_cast<itkImageType*>(conv->GetOutput());
- out->Register();
- bbSetOutputOut(out);
+ bbSetOutputOut(out);
}
catch( itk::ExceptionObject & e)
{
<<bbtk::TypeName<T>()<<","<<D
<<">::Convert() : "<<e);
}
-
- bbtkDebugDecTab("Core",9);
+ bbtkDebugMessage("process",5,"<== ["<<bbGetFullName()<<"] : Convert<"
+ <<bbtk::TypeName<T>()<<","<<D
+ <<">() *DONE*"<<std::endl);
}
-
+ void vtkImageData2itkImage::bbUserConstructor()
+ {
+ // bbSetOutputOut(NULL);
+ mConverter = 0;
+ }
+
+ void vtkImageData2itkImage::bbUserCopyConstructor()
+ {
+ // bbSetOutputOut(NULL);
+ mConverter = 0;
+ }
+
+ void vtkImageData2itkImage::bbUserDestructor()
+ {
+ // if (mConverter) mConverter->UnRegister();
+ }
+
Program: bbtk
Module: $RCSfile: bbitkvtkvtkImageData2itkImage.h,v $
Language: C++
- Date: $Date: 2008/04/18 12:59:50 $
- Version: $Revision: 1.3 $
+ Date: $Date: 2008/05/14 07:01:00 $
+ Version: $Revision: 1.4 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "bbtkAtomicBlackBox.h"
#include "bbitkImage.h"
#include "vtkImageData.h"
+#include "itkProcessObject.h"
namespace bbitkvtk
{
BBTK_DECLARE_OUTPUT(Out,bbitk::anyImagePointer);
BBTK_PROCESS(Convert);
void Convert();
+ void bbUserConstructor();
+ void bbUserCopyConstructor();
+ void bbUserDestructor();
private:
- // Convert method template on type of the itk image to be created
+ // Convert method : template on type of the itk image to be created
template<class T, unsigned int D> void Convert();
+ // stores the pointer on the template itk::VTKImageToImageFilter
+ itk::ProcessObject::Pointer mConverter;
};
include itkvtk
include wxvtk
+description "Example ..."
+author "eduardo.davila@creatis.insa-lyon.fr"
+category "example"
+
+
new MetaImageReader reader
include std/boxes/bbPrependPackageDataPath.bbs
new PrependPackageDataPath prependDatapath
Program: bbtk
Module: $RCSfile: bbwxvtkViewer2D.cxx,v $
Language: C++
- Date: $Date: 2008/05/09 10:39:47 $
- Version: $Revision: 1.4 $
+ Date: $Date: 2008/05/14 07:01:00 $
+ Version: $Revision: 1.5 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
// LG : because it has been allocated with operator new not method ::New
// 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;
if (backImageData)
{
- backImageData->UnRegister(NULL);
+ // backImageData->UnRegister(NULL);
}
if (imageViewer)
{
imageViewer->Delete();
}
delete wxvtkrenderwindowinteractor;
+ std::cout << "Viewer2DWidget::~Viewer2DWidget() OK" << std::endl;
}
//-------------------------------------------------------------------------
void Viewer2DWidget::UpdateView()
{
- std::cout << "Viewer2DWidget::UpdateView()" << std::endl;
+ std::cout << "Viewer2DWidget::UpdateView() "<<mBox->bbGetFullName() << std::endl;
std::cout << "slice="<<mBox->bbGetInputSlice()<<std::endl;
if ( (mBox->bbGetInputIn()!=NULL) &&
(backImageData != mBox->bbGetInputIn()) )
imageViewer->SetupInteractor ( wxvtkrenderwindowinteractor );
}
- if (backImageData) backImageData->UnRegister(NULL);
+ 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();
- backImageData->Register(NULL);
+
+
+ std::cout << "V2D r2="<<backImageData->GetReferenceCount()<<std::endl;
+ // backImageData->DebugOn();
+ // backImageData->PrintSelf(std::cout,0);
+
+ // backImageData->Register(NULL);
imageViewer->SetInput( backImageData );
backImageData->Update();