Skip to content

Commit 06166b7

Browse files
hjmjohnsondzenanz
authored andcommitted
ENH: Add support files from media wiki examples
The Media Wiki examples had several support files used in the examples.
1 parent fb2d5ea commit 06166b7

23 files changed

+935
-0
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ target_link_libraries(ImageCompareCommand ${ITK_LIBRARIES})
4848

4949
include(${CMAKE_CURRENT_SOURCE_DIR}/../CMake/ITKExamplesMacros.cmake)
5050

51+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Developer)
52+
5153
add_subdirectory(Bridge)
5254
add_subdirectory(Core)
5355
add_subdirectory(Compatibility)

src/Developer/ConceptChecking.cxx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <itkConceptChecking.h>
2+
#include <itkImage.h>
3+
4+
template <typename TImage>
5+
void MyFunction(const TImage* const image)
6+
{
7+
itkConceptMacro( nameOfCheck, ( itk::Concept::IsFloatingPoint<typename TImage::ValueType> ) );
8+
}
9+
10+
int main(int, char*[])
11+
{
12+
using FloatImageType = itk::Image<float, 2>;
13+
FloatImageType::Pointer floatImage = FloatImageType::New();
14+
MyFunction(floatImage.GetPointer());
15+
16+
using DoubleImageType = itk::Image<double, 2>;
17+
DoubleImageType::Pointer doubleImage = DoubleImageType::New();
18+
MyFunction(doubleImage.GetPointer());
19+
20+
// Fails the concept check
21+
// using IntImageType = itk::Image<int, 2>;
22+
// IntImageType::Pointer intImage = IntImageType::New();
23+
// MyFunction(intImage.GetPointer());
24+
25+
// Fails the concept check
26+
// using UCharImageType = itk::Image<unsigned char, 2>;
27+
// UCharImageType::Pointer ucharImage = UCharImageType::New();
28+
// MyFunction(ucharImage.GetPointer());
29+
30+
return EXIT_SUCCESS;
31+
}

src/Developer/Exceptions.cxx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "itkImage.h"
2+
#include "itkImageFileReader.h"
3+
#include "itkImageFileWriter.h"
4+
5+
#include "ImageSource.h"
6+
7+
int main(int, char*[])
8+
{
9+
// Setup types
10+
using ImageType = itk::Image<unsigned char, 2>;
11+
ImageType::Pointer image = ImageType::New();
12+
13+
// Create and the filter
14+
using FilterType = itk::ImageFilter<ImageType>;
15+
FilterType::Pointer filter = FilterType::New();
16+
filter->SetInput(image);
17+
filter->Update();
18+
19+
return EXIT_SUCCESS;
20+
}

src/Developer/ImageFilter.cxx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include "itkImage.h"
2+
#include "itkImageFileReader.h"
3+
#include "itkImageFileWriter.h"
4+
5+
#include "ImageFilter.h"
6+
7+
template <typename TImage>
8+
static void CreateImage(TImage* const image);
9+
10+
int main(int, char*[])
11+
{
12+
// Setup types
13+
using ImageType = itk::Image<int, 2>;
14+
using FilterType = itk::ImageFilter<ImageType>;
15+
16+
ImageType::Pointer image = ImageType::New();
17+
CreateImage(image.GetPointer());
18+
19+
// Create and the filter
20+
FilterType::Pointer filter = FilterType::New();
21+
filter->SetInput(image);
22+
filter->Update();
23+
24+
itk::Index<2> cornerPixel = image->GetLargestPossibleRegion().GetIndex();
25+
26+
// The output here is:
27+
// 0
28+
// 3
29+
// That is, the filter changed the pixel, but the input remained unchagned.
30+
std::cout << image->GetPixel(cornerPixel) << std::endl;
31+
std::cout << filter->GetOutput()->GetPixel(cornerPixel) << std::endl;
32+
33+
return EXIT_SUCCESS;
34+
}
35+
36+
37+
template <typename TImage>
38+
void CreateImage(TImage* const image)
39+
{
40+
// Create an image with 2 connected components
41+
typename TImage::IndexType corner = {{0,0}};
42+
43+
unsigned int NumRows = 200;
44+
unsigned int NumCols = 300;
45+
typename TImage::SizeType size = {{NumRows, NumCols}};
46+
47+
typename TImage::RegionType region(corner, size);
48+
49+
image->SetRegions(region);
50+
image->Allocate();
51+
52+
image->FillBuffer(0);
53+
}

src/Developer/ImageFilter.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef __itkImageFilter_h
2+
#define __itkImageFilter_h
3+
4+
#include "itkImageToImageFilter.h"
5+
6+
namespace itk
7+
{
8+
template< class TImage>
9+
class ImageFilter:public ImageToImageFilter< TImage, TImage >
10+
{
11+
public:
12+
/** Standard class type alias. */
13+
using Self = ImageFilter;
14+
using Superclass = ImageToImageFilter< TImage, TImage >;
15+
using Pointer = SmartPointer< Self >;
16+
17+
/** Method for creation through the object factory. */
18+
itkNewMacro(Self);
19+
20+
/** Run-time type information (and related methods). */
21+
itkTypeMacro(ImageFilter, ImageToImageFilter);
22+
23+
protected:
24+
ImageFilter(){}
25+
~ImageFilter(){}
26+
27+
/** Does the real work. */
28+
virtual void GenerateData();
29+
30+
private:
31+
ImageFilter(const Self &); //purposely not implemented
32+
void operator=(const Self &); //purposely not implemented
33+
34+
};
35+
} //namespace ITK
36+
37+
38+
#ifndef ITK_MANUAL_INSTANTIATION
39+
#include "ImageFilter.hxx"
40+
#endif
41+
42+
43+
#endif // __itkImageFilter_h
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "itkImage.h"
2+
#include "itkImageFileReader.h"
3+
#include "itkImageFileWriter.h"
4+
5+
#include "ImageFilterMultipleInputs.h"
6+
7+
int main(int, char*[])
8+
{
9+
// Setup types
10+
using ImageType = itk::Image<unsigned char, 2>;
11+
using FilterType = itk::ImageFilterMultipleInputs<ImageType>;
12+
13+
ImageType::Pointer image = ImageType::New();
14+
ImageType::Pointer mask = ImageType::New();
15+
16+
// Create and the filter
17+
FilterType::Pointer filter = FilterType::New();
18+
filter->SetInputImage(image);
19+
filter->SetInputMask(mask);
20+
filter->Update();
21+
22+
return EXIT_SUCCESS;
23+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "itkImage.h"
2+
#include "itkImageFileReader.h"
3+
#include "itkImageFileWriter.h"
4+
#include "itkCovariantVector.h"
5+
6+
#include "ImageFilterMultipleInputsDifferentType.h"
7+
8+
int main(int, char*[])
9+
{
10+
// Setup types
11+
using VectorImageType = itk::Image<itk::CovariantVector<unsigned char, 3>, 2>;
12+
using ScalarImageType = itk::Image<unsigned char, 2>;
13+
using FilterType = itk::ImageFilterMultipleInputsDifferentType<VectorImageType, ScalarImageType>;
14+
15+
using ReaderType = itk::ImageFileReader<VectorImageType>;
16+
ReaderType::Pointer reader = ReaderType::New();
17+
reader->SetFileName("Test.jpg");
18+
reader->Update();
19+
20+
// Create and the filter
21+
FilterType::Pointer filter = FilterType::New();
22+
filter->SetInput(reader->GetOutput());
23+
filter->Update();
24+
25+
using WriterType = itk::ImageFileWriter< VectorImageType >;
26+
WriterType::Pointer writer = WriterType::New();
27+
writer->SetFileName("TestOutput.jpg");
28+
writer->SetInput(filter->GetOutput());
29+
writer->Update();
30+
31+
return EXIT_SUCCESS;
32+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "itkImage.h"
2+
#include "itkImageFileReader.h"
3+
#include "itkImageFileWriter.h"
4+
5+
#include "ImageFilterMultipleOutputs.h"
6+
7+
int main(int, char*[])
8+
{
9+
// Setup types
10+
using ImageType = itk::Image<unsigned char, 2>;
11+
using FilterType = itk::ImageFilterMultipleOutputs<ImageType>;
12+
13+
// Create and the filter
14+
FilterType::Pointer filter = FilterType::New();
15+
filter->Update();
16+
17+
{
18+
using WriterType = itk::ImageFileWriter< ImageType >;
19+
WriterType::Pointer writer = WriterType::New();
20+
writer->SetFileName("TestOutput1.jpg");
21+
writer->SetInput(filter->GetOutput1());
22+
writer->Update();
23+
}
24+
25+
{
26+
using WriterType = itk::ImageFileWriter< ImageType >;
27+
WriterType::Pointer writer = WriterType::New();
28+
writer->SetFileName("TestOutput2.jpg");
29+
writer->SetInput(filter->GetOutput2());
30+
writer->Update();
31+
}
32+
33+
return EXIT_SUCCESS;
34+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "itkImage.h"
2+
#include "itkImageFileReader.h"
3+
#include "itkImageFileWriter.h"
4+
5+
#include "ImageFilterMultipleOutputsDifferentType.h"
6+
7+
int main(int, char*[])
8+
{
9+
// Setup types
10+
using InputImageType = itk::Image<unsigned char, 2>;
11+
using OutputImageType1 = itk::Image<float, 2>;
12+
using OutputImageType2 = itk::Image<int, 2>;
13+
using FilterType = itk::ImageFilterMultipleOutputsDifferentType<InputImageType, OutputImageType1, OutputImageType2>;
14+
15+
// Create and the filter
16+
FilterType::Pointer filter = FilterType::New();
17+
filter->Update();
18+
19+
{
20+
using WriterType = itk::ImageFileWriter< OutputImageType1 >;
21+
WriterType::Pointer writer = WriterType::New();
22+
writer->SetFileName("TestOutput1.jpg");
23+
writer->SetInput(filter->GetOutput1());
24+
writer->Update();
25+
}
26+
27+
{
28+
using WriterType = itk::ImageFileWriter< OutputImageType2 >;
29+
WriterType::Pointer writer = WriterType::New();
30+
writer->SetFileName("TestOutput2.jpg");
31+
writer->SetInput(filter->GetOutput2());
32+
writer->Update();
33+
}
34+
35+
return EXIT_SUCCESS;
36+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#ifndef __itkImageFilterMultipleOutputsDifferentType_h
2+
#define __itkImageFilterMultipleOutputsDifferentType_h
3+
4+
#include "itkImageToImageFilter.h"
5+
6+
namespace itk
7+
{
8+
template< typename TInputImage, typename TOutputImage1, typename TOutputImage2>
9+
class ImageFilterMultipleOutputsDifferentType : public ImageToImageFilter< TInputImage, TOutputImage1 > // This doesn't actually matter, as we will be overriding the output image type in MakeOutput()
10+
{
11+
public:
12+
/** Standard class type alias. */
13+
using Self = ImageFilterMultipleOutputsDifferentType;
14+
using Superclass = ImageToImageFilter< TInputImage, TOutputImage1 >;
15+
using Pointer = SmartPointer< Self >;
16+
17+
/** Method for creation through the object factory. */
18+
itkNewMacro(Self);
19+
20+
/** Run-time type information (and related methods). */
21+
itkTypeMacro(ImageFilterMultipleOutputsDifferentType, ImageToImageFilter);
22+
23+
TOutputImage1* GetOutput1();
24+
TOutputImage2* GetOutput2();
25+
26+
protected:
27+
ImageFilterMultipleOutputsDifferentType();
28+
~ImageFilterMultipleOutputsDifferentType(){}
29+
30+
/** Does the real work. */
31+
virtual void GenerateData();
32+
33+
/** Create the Output */
34+
DataObject::Pointer MakeOutput(unsigned int idx);
35+
36+
private:
37+
ImageFilterMultipleOutputsDifferentType(const Self &); //purposely not implemented
38+
void operator=(const Self &); //purposely not implemented
39+
40+
};
41+
} //namespace ITK
42+
43+
44+
#ifndef ITK_MANUAL_INSTANTIATION
45+
#include "ImageFilterMultipleOutputsDifferentType.hxx"
46+
#endif
47+
48+
49+
#endif // __itkImageFilterMultipleOutputsDifferentType_h

0 commit comments

Comments
 (0)