[Insight-users] meaning of Update() function? where exactly this function should be placed ?

Martine Lefevre martine_lef at yahoo.fr
Sun Aug 24 02:49:07 EDT 2008


Dear itk users, 
I’m new to itk (just in my first week). I have successfully configured itk and also vtk. I am now reading the ItkSoftwareGuide and I trying to run some of the examples provided. I’m little bit confused with the meaning of the Update function (for instance writer->Update();). According to the book update function triggers the execution of the pipeline. When I change its location in the code, the code still running without end. For example in the example FastMarchingImageFilter..c++  if I move writer4->Update();and put it just after caster4->SetOutputMaximum( 255 ); ,as with the other writers, the code still running without end ! 
I couldn’t understand where exactly this function should be placed in a given code.
Is it better to call this function with the last filter (i.e. a writer ) or I can call it after each filter (and even reader and writer) ?  What’s the difference between both??
Please could you answer me? 
Thank you 
Martine // The following example implements a fast marching solution to a simple level set evolution problem. #include"itkCurvatureAnisotropicDiffusionImageFilter.h"#include"itkGradientMagnitudeRecursiveGaussianImageFilter.h"#include"itkSigmoidImageFilter.h"#include"itkImage.h"#include"itkFastMarchingImageFilter.h"#include"itkBinaryThresholdImageFilter.h"#include"itkImageFileReader.h"#include"itkImageFileWriter.h"#include
 "itkRescaleIntensityImageFilter.h"int
{ 
ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
thresholder->SetLowerThreshold( 0.0 );
thresholder->SetUpperThreshold( timeThreshold );
thresholder->SetOutsideValue( 0 );
thresholder->SetInsideValue( 255 );
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName(
writer->SetFileName(
SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
sigmoid->SetOutputMinimum( 0.0 );
sigmoid->SetOutputMaximum( 1.0 );
FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
smoothing->SetInput( reader->GetOutput() );
gradientMagnitude->SetInput( smoothing->GetOutput() );
sigmoid->SetInput( gradientMagnitude->GetOutput() );
fastMarching->SetInput( sigmoid->GetOutput() );
thresholder->SetInput( fastMarching->GetOutput() );
writer->SetInput( thresholder->GetOutput() );
smoothing->SetTimeStep( 0.125 );
smoothing->SetNumberOfIterations( 5 );
smoothing->SetConductanceParameter( 9.0 );
gradientMagnitude->SetSigma( sigma );
 
sigmoid->SetAlpha( alpha );
sigmoid->SetBeta( beta );
NodeContainer::Pointer seeds = NodeContainer::New();
InternalImageType::IndexType seedPosition;
seedPosition[0] = atoi( 
seedPosition[1] = atoi( 
NodeType node;
node.SetValue( seedValue );
node.SetIndex( seedPosition );
seeds->Initialize();
seeds->InsertElement( 0, node );
fastMarching->SetTrialPoints( seeds );
CastFilterType::Pointer caster1 = CastFilterType::New();
CastFilterType::Pointer caster2 = CastFilterType::New();
CastFilterType::Pointer caster3 = CastFilterType::New();
CastFilterType::Pointer caster4 = CastFilterType::New();
WriterType::Pointer writer1 = WriterType::New();
WriterType::Pointer writer2 = WriterType::New();
WriterType::Pointer writer3 = WriterType::New();
WriterType::Pointer writer4 = WriterType::New();
caster1->SetInput( smoothing->GetOutput() );
writer1->SetInput( caster1->GetOutput() );
writer1->SetFileName(
caster1->SetOutputMinimum( 0 );
caster1->SetOutputMaximum( 255 );
writer1->Update();
caster2->SetInput( gradientMagnitude->GetOutput() );
writer2->SetInput( caster2->GetOutput() );
writer2->SetFileName(
caster2->SetOutputMinimum( 0 );
caster2->SetOutputMaximum( 255 );
writer2->Update();
caster3->SetInput( sigmoid->GetOutput() );
writer3->SetInput( caster3->GetOutput() );
writer3->SetFileName(
caster3->SetOutputMinimum( 0 );
caster3->SetOutputMaximum( 255 );
writer3->Update();
caster4->SetInput( fastMarching->GetOutput() );
writer4->SetInput( caster4->GetOutput() );
writer4->SetFileName(
caster4->SetOutputMinimum( 0 );
caster4->SetOutputMaximum( 255 );
writer4->Update(); main( )typedeffloatInternalPixelType;constunsignedintDimension = 2;typedefitk::Image< InternalPixelType, Dimension > InternalImageType;typedefunsignedcharOutputPixelType;typedefitk::Image< OutputPixelType, Dimension > OutputImageType;typedefitk::BinaryThresholdImageFilter< InternalImageType, OutputImageType > ThresholdingFilterType;constInternalPixelType timeThreshold = atof( "100"); typedefitk::ImageFileReader< InternalImageType > ReaderType;typedefitk::ImageFileWriter< OutputImageType > WriterType;"d:/BrainProtonDensitySlice.png");"d:/FastMarchingSegmentedImg.png");typedefitk::RescaleIntensityImageFilter< InternalImageType, OutputImageType > CastFilterType;typedefitk::CurvatureAnisotropicDiffusionImageFilter< InternalImageType, InternalImageType > SmoothingFilterType;typedefitk::GradientMagnitudeRecursiveGaussianImageFilter< InternalImageType, InternalImageType > GradientFilterType;typedefitk::SigmoidImageFilter< InternalImageType,
 InternalImageType > SigmoidFilterType;typedefitk::FastMarchingImageFilter< InternalImageType, InternalImageType > FastMarchingFilterType;constdoublesigma = atof( "1.0");constdoublealpha = atof( "-0.5");constdoublebeta = atof( "3.0");typedefFastMarchingFilterType::NodeContainer NodeContainer;typedefFastMarchingFilterType::NodeType NodeType;"81");"114");constdoubleseedValue = 0.0;"d:/FastMarchingFilterOutput1.png");"d:/FastMarchingFilterOutput2.png");"d:/FastMarchingFilterOutput3.png");"d:/FastMarchingFilterOutput4.png");// here where I have moved writer4->Update();fastMarching->SetOutputSize( reader->GetOutput()->GetBufferedRegion().GetSize() );
fastMarching->SetStoppingValue( stoppingTime );constdoublestoppingTime = atof( "100");try{
writer->Update();
}
{
std::cerr << 
std::cerr << excep << std::endl;
}catch( itk::ExceptionObject & excep )"Exception caught !"<< std::endl;//writer4->Update();InternalWriterType::Pointer mapWriter = InternalWriterType::New();
mapWriter->SetInput( fastMarching->GetOutput() );
mapWriter->SetFileName(
mapWriter->Update();
InternalWriterType::Pointer speedWriter = InternalWriterType::New();
speedWriter->SetInput( sigmoid->GetOutput() );
speedWriter->SetFileName(
speedWriter->Update();
InternalWriterType::Pointer gradientWriter = InternalWriterType::New();
gradientWriter->SetInput( gradientMagnitude->GetOutput() );
gradientWriter->SetFileName(
gradientWriter->Update();
std::cout << 
std::cin.get();
}typedefitk::ImageFileWriter< InternalImageType > InternalWriterType;"d:/FastMarchingFilterOutput4.mha");"d:/FastMarchingFilterOutput3.mha");"d:/FastMarchingFilterOutput2.mha");"Code end !"<< std::endl;return0;Please see the code:



      _____________________________________________________________________________ 
Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20080824/b0f9a4ea/attachment.htm>


More information about the Insight-users mailing list