forked from InsightSoftwareConsortium/ITKWikiExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
638 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef __itkImageFilter_hxx | ||
#define __itkImageFilter_hxx | ||
|
||
#include "ImageFilter.h" | ||
#include "itkObjectFactory.h" | ||
#include "itkImageRegionIterator.h" | ||
#include "itkImageRegionConstIterator.h" | ||
|
||
namespace itk | ||
{ | ||
|
||
template< class TImage> | ||
void ImageFilter< TImage> | ||
::GenerateData() | ||
{ | ||
typename TImage::ConstPointer input = this->GetInput(); | ||
typename TImage::Pointer output = this->GetOutput(); | ||
|
||
itk::Index<2> cornerPixel = input->GetLargestPossibleRegion().GetIndex(); | ||
typename TImage::PixelType newValue = 3; | ||
|
||
this->AllocateOutputs(); | ||
|
||
ImageAlgorithm::Copy(input.GetPointer(), output.GetPointer(), output->GetRequestedRegion(), | ||
output->GetRequestedRegion() ); | ||
|
||
output->SetPixel( cornerPixel, newValue ); | ||
} | ||
|
||
}// end namespace | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef __itkImageFilter_txx | ||
#define __itkImageFilter_txx | ||
|
||
#include "ImageFilter.h" | ||
#include "itkObjectFactory.h" | ||
#include "itkImageRegionIterator.h" | ||
#include "itkImageRegionConstIterator.h" | ||
|
||
namespace itk | ||
{ | ||
|
||
template< class TImage> | ||
void ImageFilter< TImage> | ||
::GenerateData() | ||
{ | ||
|
||
} | ||
|
||
}// end namespace | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef __itkImageFilterMultipleInputs_txx | ||
#define __itkImageFilterMultipleInputs_txx | ||
|
||
#include "ImageFilterMultipleInputs.h" | ||
|
||
#include "itkObjectFactory.h" | ||
#include "itkImageRegionIterator.h" | ||
#include "itkImageRegionConstIterator.h" | ||
|
||
namespace itk | ||
{ | ||
|
||
template< class TImage> | ||
ImageFilterMultipleInputs<TImage>::ImageFilterMultipleInputs() | ||
{ | ||
this->SetNumberOfRequiredInputs(2); | ||
} | ||
|
||
template< class TImage> | ||
void ImageFilterMultipleInputs<TImage>::SetInputImage(const TImage* image) | ||
{ | ||
this->SetNthInput(0, const_cast<TImage*>(image)); | ||
} | ||
|
||
template< class TImage> | ||
void ImageFilterMultipleInputs<TImage>::SetInputMask(const TImage* mask) | ||
{ | ||
this->SetNthInput(1, const_cast<TImage*>(mask)); | ||
} | ||
|
||
template< class TImage> | ||
void ImageFilterMultipleInputs<TImage>::GenerateData() | ||
{ | ||
typename TImage::ConstPointer input = this->GetInput(); | ||
|
||
typename TImage::Pointer output = this->GetOutput(); | ||
output->SetRegions(input->GetLargestPossibleRegion()); | ||
output->Allocate(); | ||
|
||
itk::ImageRegionIterator<TImage> outputIterator(output, output->GetLargestPossibleRegion()); | ||
itk::ImageRegionConstIterator<TImage> inputIterator(input, input->GetLargestPossibleRegion()); | ||
|
||
while(!outputIterator.IsAtEnd()) | ||
{ | ||
if(inputIterator.GetIndex()[0] == inputIterator.GetIndex()[1]) | ||
{ | ||
outputIterator.Set(255); | ||
} | ||
else | ||
{ | ||
outputIterator.Set(inputIterator.Get()); | ||
} | ||
|
||
++inputIterator; | ||
++outputIterator; | ||
} | ||
|
||
} | ||
|
||
}// end namespace | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#ifndef __itkImageFilterMultipleInputs_txx | ||
#define __itkImageFilterMultipleInputs_txx | ||
|
||
#include "ImageFilterMultipleInputsDifferentType.h" | ||
|
||
#include "itkObjectFactory.h" | ||
#include "itkImageRegionIterator.h" | ||
#include "itkImageRegionConstIterator.h" | ||
|
||
namespace itk | ||
{ | ||
|
||
template< typename TImage, typename TMask> | ||
ImageFilterMultipleInputsDifferentType<TImage, TMask>::ImageFilterMultipleInputsDifferentType() | ||
{ | ||
this->SetNumberOfRequiredInputs(2); | ||
} | ||
|
||
template< typename TImage, typename TMask> | ||
void ImageFilterMultipleInputsDifferentType<TImage, TMask>::SetInputImage(const TImage* image) | ||
{ | ||
SetNthInput(0, const_cast<TImage*>(image)); | ||
} | ||
|
||
template< typename TImage, typename TMask> | ||
void ImageFilterMultipleInputsDifferentType<TImage, TMask>::SetInputMask(const TMask* mask) | ||
{ | ||
SetNthInput(1, const_cast<TMask*>(mask)); | ||
} | ||
|
||
template< typename TImage, typename TMask> | ||
typename TImage::ConstPointer ImageFilterMultipleInputsDifferentType<TImage, TMask>::GetInputImage() | ||
{ | ||
return static_cast< const TImage * > | ||
( this->ProcessObject::GetInput(0) ); | ||
} | ||
|
||
template< typename TImage, typename TMask> | ||
typename TMask::ConstPointer ImageFilterMultipleInputsDifferentType<TImage, TMask>::GetInputMask() | ||
{ | ||
return static_cast< const TMask * > | ||
( this->ProcessObject::GetInput(1) ); | ||
} | ||
|
||
template< typename TImage, typename TMask> | ||
void ImageFilterMultipleInputsDifferentType<TImage, TMask>::GenerateData() | ||
{ | ||
typename TImage::ConstPointer input = this->GetInputImage(); | ||
typename TMask::ConstPointer mask = this->GetInputMask(); | ||
|
||
typename TImage::Pointer output = this->GetOutput(); | ||
output->SetRegions(input->GetLargestPossibleRegion()); | ||
output->Allocate(); | ||
|
||
itk::ImageRegionIterator<TImage> outputIterator(output, output->GetLargestPossibleRegion()); | ||
itk::ImageRegionConstIterator<TImage> inputIterator(input, input->GetLargestPossibleRegion()); | ||
|
||
while(!outputIterator.IsAtEnd()) | ||
{ | ||
if(inputIterator.GetIndex()[0] == inputIterator.GetIndex()[1]) | ||
{ | ||
outputIterator.Set(255); | ||
} | ||
else | ||
{ | ||
outputIterator.Set(inputIterator.Get()); | ||
} | ||
|
||
++inputIterator; | ||
++outputIterator; | ||
} | ||
|
||
} | ||
|
||
}// end namespace | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#ifndef __itkImageFilterMultipleOutputs_txx | ||
#define __itkImageFilterMultipleOutputs_txx | ||
|
||
#include "ImageFilterMultipleOutputs.h" | ||
|
||
#include "itkObjectFactory.h" | ||
#include "itkImageRegionIterator.h" | ||
#include "itkImageRegionConstIterator.h" | ||
|
||
namespace itk | ||
{ | ||
|
||
template< class TImage> | ||
ImageFilterMultipleOutputs<TImage>::ImageFilterMultipleOutputs() | ||
{ | ||
this->SetNumberOfRequiredOutputs(2); | ||
this->SetNumberOfRequiredInputs(0); | ||
|
||
this->SetNthOutput( 0, this->MakeOutput(0) ); | ||
this->SetNthOutput( 1, this->MakeOutput(1) ); | ||
} | ||
|
||
template< class TImage> | ||
void ImageFilterMultipleOutputs<TImage>::GenerateData() | ||
{ | ||
typename TImage::IndexType start; | ||
start[0] = 0; | ||
start[1] = 0; | ||
|
||
typename TImage::SizeType size; | ||
size[0] = 20; | ||
size[1] = 20; | ||
|
||
typename TImage::RegionType region; | ||
region.SetSize(size); | ||
region.SetIndex(start); | ||
|
||
// Setup output 1 | ||
typename TImage::Pointer output1 = this->GetOutput1(); | ||
output1->SetRegions(region); | ||
output1->Allocate(); | ||
|
||
itk::ImageRegionIterator<TImage> outputIterator1(output1, output1->GetLargestPossibleRegion()); | ||
outputIterator1.GoToBegin(); | ||
|
||
while(!outputIterator1.IsAtEnd()) | ||
{ | ||
if(outputIterator1.GetIndex()[0] == outputIterator1.GetIndex()[1]) | ||
{ | ||
outputIterator1.Set(255); | ||
} | ||
else | ||
{ | ||
outputIterator1.Set(0); | ||
} | ||
|
||
++outputIterator1; | ||
} | ||
|
||
// Setup output 2 | ||
typename TImage::Pointer output2 = this->GetOutput2(); | ||
output2->SetRegions(region); | ||
output2->Allocate(); | ||
|
||
itk::ImageRegionIterator<TImage> outputIterator2(output2, output2->GetLargestPossibleRegion()); | ||
outputIterator2.GoToBegin(); | ||
|
||
while(!outputIterator2.IsAtEnd()) | ||
{ | ||
if(outputIterator2.GetIndex()[0] > 10) | ||
{ | ||
outputIterator2.Set(255); | ||
} | ||
else | ||
{ | ||
outputIterator2.Set(0); | ||
} | ||
|
||
++outputIterator2; | ||
} | ||
|
||
} | ||
|
||
template< class TImage> | ||
DataObject::Pointer ImageFilterMultipleOutputs<TImage>::MakeOutput(unsigned int idx) | ||
{ | ||
DataObject::Pointer output; | ||
|
||
switch ( idx ) | ||
{ | ||
case 0: | ||
output = ( TImage::New() ).GetPointer(); | ||
break; | ||
case 1: | ||
output = ( TImage::New() ).GetPointer(); | ||
break; | ||
default: | ||
std::cerr << "No output " << idx << std::endl; | ||
output = NULL; | ||
break; | ||
} | ||
return output.GetPointer(); | ||
} | ||
|
||
template< class TImage> | ||
TImage* ImageFilterMultipleOutputs<TImage>::GetOutput1() | ||
{ | ||
return dynamic_cast< TImage * >( | ||
this->ProcessObject::GetOutput(0) ); | ||
} | ||
|
||
template< class TImage> | ||
TImage* ImageFilterMultipleOutputs<TImage>::GetOutput2() | ||
{ | ||
return dynamic_cast< TImage * >( | ||
this->ProcessObject::GetOutput(1) ); | ||
} | ||
|
||
}// end namespace | ||
|
||
|
||
#endif |
Oops, something went wrong.