Skip to content
Snippets Groups Projects
Commit fbabbcf1 authored by Jordi Inglada's avatar Jordi Inglada
Browse files

Ajout de quelques exemples ITK

parent 1df7e45b
No related branches found
No related tags found
No related merge requests found
Showing
with 1238 additions and 13 deletions
......@@ -5,4 +5,5 @@ SUBDIRS(
ExtractROI
BasicFilters
FeatureExtraction
DataRepresentation
)
SUBDIRS(
Containers
Image
Mesh
Path
)
SET(TEMP ${ITK_BINARY_DIR}/Testing/Temporary)
INCLUDE_REGULAR_EXPRESSION("^.*$")
ADD_EXECUTABLE(TreeContainer TreeContainer.cxx )
TARGET_LINK_LIBRARIES(TreeContainer ITKCommon)
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: TreeContainer.cxx,v $
Language: C++
Date: $Date: 2005/11/19 16:31:48 $
Version: $Revision: 1.2 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
// Software Guide : BeginLatex
//
// \index{itk::TreeContainer}
//
// This example shows how to use the \doxygen{TreeContainer} and the
// associated TreeIterators.
// The \doxygen{TreeContainer} implements the notion of tree and is
// templated over the type of node so it can virtually handle any
// objects. Each node is supposed to have only one parent so no cycle
// is present in the tree. No checking is done to ensure a cycle-free
// tree.
//
// Let's begin by including the appropriate header file.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
#include <itkTreeContainer.h>
#include "itkTreeContainer.h"
#include "itkChildTreeIterator.h"
#include "itkLeafTreeIterator.h"
#include "itkLevelOrderTreeIterator.h"
#include "itkInOrderTreeIterator.h"
#include "itkPostOrderTreeIterator.h"
#include "itkPreOrderTreeIterator.h"
#include "itkRootTreeIterator.h"
#include "itkTreeIteratorClone.h"
// Software Guide : EndCodeSnippet
int main(int, char* [])
{
// Software Guide : BeginLatex
// First, we create a tree of integers.
// The TreeContainer is templated over the type of nodes.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef int NodeType;
typedef itk::TreeContainer<NodeType> TreeType;
TreeType::Pointer tree = TreeType::New();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// Next we set the value of the root node using \code{SetRoot()}.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
tree->SetRoot(0);
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// Then we use the \code{Add()} function to add nodes to the tree
// The first argument is the value of the new node and the second
// argument is the value of the parent node. If two nodes have
// the same values then the first one is picked. In this particular
// case it is better to use an iterator to fill the tree.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
tree->Add(1,0);
tree->Add(2,0);
tree->Add(3,0);
tree->Add(4,2);
tree->Add(5,2);
tree->Add(6,5);
tree->Add(7,1);
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// We define an \doxygen{LevelOrderTreeIterator} to parse the tree in level order.
// This particular iterator takes three arguments. The first one is the actual tree
// to be parsed, the second one is the maximum depth level and the third one is the
// starting node. The \code{GetNode()} function return a node given its value. Once
// again the first node that corresponds to the value is returned.
// Software Guide : EndLatex
std::cout << "LevelOrderTreeIterator:" << std::endl;
// Software Guide : BeginCodeSnippet
itk::LevelOrderTreeIterator<TreeType> levelIt(tree,10,tree->GetNode(2));
levelIt.GoToBegin();
while(!levelIt.IsAtEnd())
{
std::cout << levelIt.Get() << " ("<< levelIt.GetLevel() << ")" << std::endl;;
++levelIt;
}
std::cout << std::endl;
// Software Guide : EndCodeSnippet
levelIt.GoToBegin();
// Software Guide : BeginLatex
// The TreeIterators have useful functions to test the property of the current
// pointed node. Among these functions: \code{IsLeaf{}} returns true if the current
// node is a leaf, \code{IsRoot{}} returns true if the node is a root,
// \code{HasParent{}} returns true if the node has a parent and
// \code{CountChildren{}} returns the number of children for this particular node.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
levelIt.IsLeaf();
levelIt.IsRoot();
levelIt.HasParent();
levelIt.CountChildren();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// The \doxygen{ChildTreeIterator} provides another way to iterate through a tree
// by listing all the children of a node.
// Software Guide : EndLatex
std::cout << "ChildTreeIterator:" << std::endl;
// Software Guide : BeginCodeSnippet
itk::ChildTreeIterator<TreeType> childIt(tree);
childIt.GoToBegin();
while(!childIt.IsAtEnd())
{
std::cout << childIt.Get() << std::endl;;
++childIt;
}
std::cout << std::endl;
// Software Guide : EndCodeSnippet
childIt.GoToBegin();
// Software Guide : BeginLatex
// The \code{GetType()} function returns the type of iterator used.
// The list of enumerated types is as follow:
// PREORDER, INORDER, POSTORDER, LEVELORDER, CHILD, ROOT and LEAF.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
if(childIt.GetType() != itk::TreeIteratorBase<TreeType>::CHILD)
{
std::cout << "[FAILURE]" << std::endl;
return EXIT_FAILURE;
}
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// Every TreeIterator has a \code{Clone()} function which returns
// a copy of the current iterator. Note that the user should delete
// the created iterator by hand.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
childIt.GoToParent();
itk::TreeIteratorBase<TreeType>* childItClone = childIt.Clone();
delete childItClone;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// The \doxygen{LeafTreeIterator} iterates through the leaves of the tree.
// Software Guide : EndLatex
std::cout << "LeafTreeIterator:" << std::endl;
// Software Guide : BeginCodeSnippet
itk::LeafTreeIterator<TreeType> leafIt(tree);
leafIt.GoToBegin();
while(!leafIt.IsAtEnd())
{
std::cout << leafIt.Get() << std::endl;;
++leafIt;
}
std::cout << std::endl;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// The \doxygen{InOrderTreeIterator} iterates through the tree
// in the order from left to right.
// Software Guide : EndLatex
std::cout << "InOrderTreeIterator:" << std::endl;
// Software Guide : BeginCodeSnippet
itk::InOrderTreeIterator<TreeType> InOrderIt(tree);
InOrderIt.GoToBegin();
while(!InOrderIt.IsAtEnd())
{
std::cout << InOrderIt.Get() << std::endl;;
++InOrderIt;
}
std::cout << std::endl;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// The \doxygen{PreOrderTreeIterator} iterates through the tree
// from left to right but do a depth first search.
// Software Guide : EndLatex
std::cout << "PreOrderTreeIterator:" << std::endl;
// Software Guide : BeginCodeSnippet
itk::PreOrderTreeIterator<TreeType> PreOrderIt(tree);
PreOrderIt.GoToBegin();
while(!PreOrderIt.IsAtEnd())
{
std::cout << PreOrderIt.Get() << std::endl;;
++PreOrderIt;
}
std::cout << std::endl;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// The \doxygen{PostOrderTreeIterator} iterates through the tree
// from left to right but goes from the leaves to the root in the search.
// Software Guide : EndLatex
std::cout << "PostOrderTreeIterator:" << std::endl;
// Software Guide : BeginCodeSnippet
itk::PostOrderTreeIterator<TreeType> PostOrderIt(tree);
PostOrderIt.GoToBegin();
while(!PostOrderIt.IsAtEnd())
{
std::cout << PostOrderIt.Get() << std::endl;;
++PostOrderIt;
}
std::cout << std::endl;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// The \doxygen{RootTreeIterator} goes from one node to the
// root. The second arguments is the starting node. Here we go from the leaf
// node (value = 6) up to the root.
// Software Guide : EndLatex
std::cout << "RootTreeIterator:" << std::endl;
// Software Guide : BeginCodeSnippet
itk::RootTreeIterator<TreeType> RootIt(tree,tree->GetNode(6));
RootIt.GoToBegin();
while(!RootIt.IsAtEnd())
{
std::cout << RootIt.Get() << std::endl;;
++RootIt;
}
std::cout << std::endl;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// All the nodes of the tree can be removed by using the
// \code{Clear()} function.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
tree->Clear();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// We show how to use a TreeIterator to form a tree by creating nodes.
// The \code{Add()} function is used to add a node and put a value on it.
// The \code{GoToChild()} is used to jump to a node.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
itk::PreOrderTreeIterator<TreeType> PreOrderIt2(tree);
PreOrderIt2.Add(0);
PreOrderIt2.Add(1);
PreOrderIt2.Add(2);
PreOrderIt2.Add(3);
PreOrderIt2.GoToChild(2);
PreOrderIt2.Add(4);
PreOrderIt2.Add(5);
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
// The \doxygen{TreeIteratorClone} can be used to have a generic copy of
// an iterator.
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::TreeIteratorBase<TreeType> IteratorType;
typedef itk::TreeIteratorClone<IteratorType> IteratorCloneType;
itk::PreOrderTreeIterator<TreeType> anIterator(tree);
IteratorCloneType aClone = anIterator;
// Software Guide : EndCodeSnippet
return EXIT_SUCCESS;
}
PROJECT(ImageExamples)
INCLUDE_REGULAR_EXPRESSION("^.*$")
SET(TEMP ${ITK_BINARY_DIR}/Testing/Temporary)
ADD_EXECUTABLE(Image1 Image1.cxx )
TARGET_LINK_LIBRARIES(Image1 ITKCommon)
#ADD_EXECUTABLE(Image2 Image2.cxx )
#TARGET_LINK_LIBRARIES(Image2 ITKCommon ITKIO)
#ADD_EXECUTABLE(Image3 Image3.cxx )
#TARGET_LINK_LIBRARIES(Image3 ITKCommon)
#ADD_EXECUTABLE(Image4 Image4.cxx )
#TARGET_LINK_LIBRARIES(Image4 ITKCommon)
#ADD_EXECUTABLE(Image5 Image5.cxx )
#TARGET_LINK_LIBRARIES(Image5 ITKCommon ITKIO)
ADD_EXECUTABLE(RGBImage RGBImage.cxx )
TARGET_LINK_LIBRARIES(RGBImage ITKCommon ITKIO)
ADD_EXECUTABLE(VectorImage VectorImage.cxx )
TARGET_LINK_LIBRARIES(VectorImage ITKCommon)
#ADD_EXECUTABLE(ImageAdaptor1 ImageAdaptor1.cxx )
#TARGET_LINK_LIBRARIES(ImageAdaptor1 ITKCommon ITKIO)
#ADD_EXECUTABLE(ImageAdaptor2 ImageAdaptor2.cxx )
#TARGET_LINK_LIBRARIES(ImageAdaptor2 ITKCommon ITKIO)
#ADD_EXECUTABLE(ImageAdaptor3 ImageAdaptor3.cxx )
#TARGET_LINK_LIBRARIES(ImageAdaptor3 ITKCommon ITKIO)
#ADD_EXECUTABLE(ImageAdaptor4 ImageAdaptor4.cxx )
#TARGET_LINK_LIBRARIES(ImageAdaptor4 ITKCommon ITKIO)
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: Image1.cxx,v $
Language: C++
Date: $Date: 2005/02/08 03:51:52 $
Version: $Revision: 1.21 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
// Software Guide : BeginLatex
//
// This example illustrates how to manually construct an \doxygen{Image}
// class. The following is the minimal code needed to instantiate, declare
// and create the image class.
//
// \index{itk::Image!Instantiation}
// \index{itk::Image!Header}
//
// First, the header file of the Image class must be included.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
#include "itkImage.h"
// Software Guide : EndCodeSnippet
int main(int, char *[])
{
// Software Guide : BeginLatex
//
// Then we must decide with what type to represent the pixels
// and what the dimension of the image will be. With these two
// parameters we can instantiate the image class. Here we create
// a 3D image with \code{unsigned short} pixel data.
//
// Software Guide : EndLatex
//
// Software Guide : BeginCodeSnippet
typedef itk::Image< unsigned short, 3 > ImageType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The image can then be created by invoking the \code{New()} operator
// from the corresponding image type and assigning the result
// to a \doxygen{SmartPointer}.
//
// \index{itk::Image!Pointer}
// \index{itk::Image!New()}
//
// Software Guide : EndLatex
//
// Software Guide : BeginCodeSnippet
ImageType::Pointer image = ImageType::New();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// In ITK, images exist in combination with one or more
// \emph{regions}. A region is a subset of the image and indicates a
// portion of the image that may be processed by other classes in
// the system. One of the most common regions is the
// \emph{LargestPossibleRegion}, which defines the image in its
// entirety. Other important regions found in ITK are the
// \emph{BufferedRegion}, which is the portion of the image actually
// maintained in memory, and the \emph{RequestedRegion}, which is
// the region requested by a filter or other class when operating on
// the image.
//
// In ITK, manually creating an image requires that the image is
// instantiated as previously shown, and that regions describing the image are
// then associated with it.
//
// A region is defined by two classes: the \doxygen{Index} and
// \doxygen{Size} classes. The origin of the region within the
// image with which it is associated is defined by Index. The
// extent, or size, of the region is defined by Size. Index
// is represented by a n-dimensional array where each component is an
// integer indicating---in topological image coordinates---the initial
// pixel of the image. When an image is created manually, the user is
// responsible for defining the image size and the index at which the image
// grid starts. These two parameters make it possible to process selected
// regions.
//
// The starting point of the image is defined by an Index class
// that is an n-dimensional array where each component is an integer
// indicating the grid coordinates of the initial pixel of the image.
//
// \index{itk::Image!Size}
// \index{itk::Image!SizeType}
//
// Software Guide : EndLatex
//
// Software Guide : BeginCodeSnippet
ImageType::IndexType start;
start[0] = 0; // first index on X
start[1] = 0; // first index on Y
start[2] = 0; // first index on Z
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The region size is represented by an array of the same dimension of the
// image (using the Size class). The components of the array are
// unsigned integers indicating the extent in pixels of the image along
// every dimension.
//
// \index{itk::Image!Index}
// \index{itk::Image!IndexType}
//
// Software Guide : EndLatex
//
// Software Guide : BeginCodeSnippet
ImageType::SizeType size;
size[0] = 200; // size along X
size[1] = 200; // size along Y
size[2] = 200; // size along Z
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Having defined the starting index and the image size, these two
// parameters are used to create an ImageRegion object which basically
// encapsulates both concepts. The region is initialized with the
// starting index and size of the image.
//
// \index{itk::Image!itk::ImageRegion}
// \index{itk::Image!RegionType}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
ImageType::RegionType region;
region.SetSize( size );
region.SetIndex( start );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Finally, the region is passed to the \code{Image} object in order to define its
// extent and origin. The \code{SetRegions} method sets the
// LargestPossibleRegion, BufferedRegion, and RequestedRegion
// simultaneously. Note that none of the operations performed to this point
// have allocated memory for the image pixel data. It is necessary to
// invoke the \code{Allocate()} method to do this. Allocate does not
// require any arguments since all the information needed for memory
// allocation has already been provided by the region.
//
// \index{itk::Image!Allocate()}
// \index{itk::Image!SetRegions()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
image->SetRegions( region );
image->Allocate();
// Software Guide : EndCodeSnippet
return 0;
}
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: RGBImage.cxx,v $
Language: C++
Date: $Date: 2005/02/08 03:51:53 $
Version: $Revision: 1.19 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "itkImage.h"
#include "itkImageFileReader.h"
// Software Guide : BeginLatex
//
// Thanks to the flexibility offered by the
// \href{http://www.boost.org/more/generic_programming.html}{Generic
// Programming} style on which ITK is based, it is possible to
// instantiate images of arbitrary pixel type. The following example
// illustrates how a color image with RGB pixels can be defined.
//
// A class intended to support the RGB pixel type is available in ITK. You
// could also define your own pixel class and use it to instantiate a
// custom image type. In order to use the \doxygen{RGBPixel} class, it is
// necessary to include its header file.
//
// \index{itk::RGBPixel}
// \index{itk::RGBPixel!Image}
// \index{itk::RGBPixel!header}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
#include "itkRGBPixel.h"
// Software Guide : EndCodeSnippet
int main( int , char * argv[] )
{
// Software Guide : BeginLatex
//
// The RGB pixel class is templated over a type used to represent each one
// of the red, green and blue pixel components. A typical instantiation of the
// templated class is as follows.
//
// \index{itk::RGBPixel!Instantiation}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::RGBPixel< unsigned char > PixelType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The type is then used as the pixel template parameter of the image.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::Image< PixelType, 3 > ImageType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The image type can be used to instantiate other filter, for example,
// an \doxygen{ImageFileReader} object that will read the image from a
// file.
//
// \index{itk::ImageFileReader!RGB Image}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::ImageFileReader< ImageType > ReaderType;
// Software Guide : EndCodeSnippet
ReaderType::Pointer reader = ReaderType::New();
const char * filename = argv[1];
reader->SetFileName( filename );
reader->Update();
ImageType::Pointer image = reader->GetOutput();
ImageType::IndexType pixelIndex;
pixelIndex[0] = 25;
pixelIndex[1] = 35;
pixelIndex[2] = 0;
// Software Guide : BeginLatex
//
// Access to the color components of the pixels can now be performed using
// the methods provided by the RGBPixel class.
//
// \index{itk::Image!GetPixel()}
// \index{itk::RGBPixel!GetRed()}
// \index{itk::RGBPixel!GetGreen()}
// \index{itk::RGBPixel!GetBlue()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
PixelType onePixel = image->GetPixel( pixelIndex );
PixelType::ValueType red = onePixel.GetRed();
PixelType::ValueType green = onePixel.GetGreen();
PixelType::ValueType blue = onePixel.GetBlue();
// Software Guide : EndCodeSnippet
std::cout << "Pixel values from GetRed,GetGreen,GetBlue:" << std::endl;
std::cout << "Red = "
<< itk::NumericTraits<PixelType::ValueType>::PrintType(red)
<< std::endl;
std::cout << "Green = "
<< itk::NumericTraits<PixelType::ValueType>::PrintType(green)
<< std::endl;
std::cout << "Blue = "
<< itk::NumericTraits<PixelType::ValueType>::PrintType(blue)
<< std::endl;
// Software Guide : BeginLatex
//
// The subindex notation can also be used since the \doxygen{RGBPixel} inherits the
// \code{[]} operator from the \doxygen{FixedArray} class.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
red = onePixel[0]; // extract Red component
green = onePixel[1]; // extract Green component
blue = onePixel[2]; // extract Blue component
std::cout << "Pixel values:" << std::endl;
std::cout << "Red = "
<< itk::NumericTraits<PixelType::ValueType>::PrintType(red)
<< std::endl;
std::cout << "Green = "
<< itk::NumericTraits<PixelType::ValueType>::PrintType(green)
<< std::endl;
std::cout << "Blue = "
<< itk::NumericTraits<PixelType::ValueType>::PrintType(blue)
<< std::endl;
// Software Guide : EndCodeSnippet
// Lets repeat that both \code{SetPixel()} and \code{GetPixel()} are
// inefficient and should only be used for debugging purposes or for
// implementing interactions with a graphical user interface such as
// querying pixel value by clicking with the mouse.
//
return 0;
}
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: VectorImage.cxx,v $
Language: C++
Date: $Date: 2005/02/08 03:51:53 $
Version: $Revision: 1.12 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
// Software Guide : BeginLatex
//
// Many image processing tasks require images of non-scalar pixel type. A
// typical example is an image of vectors. This is the image type required to
// represent the gradient of a scalar image. The following code illustrates
// how to instantiate and use an image whose pixels are of vector type.
//
// For convenience we use the \doxygen{Vector} class to define the pixel
// type. The Vector class is intended to represent a geometrical vector in
// space. It is not intended to be used as an array container like the
// \href{http://www.sgi.com/tech/stl/Vector.html}{\code{std::vector}} in
// \href{http://www.sgi.com/tech/stl/}{STL}. If you are interested in
// containers, the \doxygen{VectorContainer} class may provide the
// functionality you want.
//
// \index{itk::Vector}
// \index{itk::Vector!header}
//
//
// The first step is to include the header file of the Vector class.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
#include "itkVector.h"
// Software Guide : EndCodeSnippet
#include "itkImage.h"
int main(int, char *[])
{
// Software Guide : BeginLatex
//
// The Vector class is templated over the type used to represent
// the coordinate in space and over the dimension of the space. In this example,
// we want the vector dimension to match the image dimension, but this is by
// no means a requirement. We could have defined a four-dimensional image
// with three-dimensional vectors as pixels.
//
// \index{itk::Vector!Instantiation}
// \index{itk::Vector!itk::Image}
// \index{itk::Image!Vector pixel}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::Vector< float, 3 > PixelType;
typedef itk::Image< PixelType, 3 > ImageType;
// Software Guide : EndCodeSnippet
// Then the image object can be created
ImageType::Pointer image = ImageType::New();
// The image region should be initialized
ImageType::IndexType start;
ImageType::SizeType size;
size[0] = 200; // size along X
size[1] = 200; // size along Y
size[2] = 200; // size along Z
start[0] = 0; // first index on X
start[1] = 0; // first index on Y
start[2] = 0; // first index on Z
ImageType::RegionType region;
region.SetSize( size );
region.SetIndex( start );
// Pixel data is allocated
image->SetRegions( region );
image->Allocate();
// The image buffer is initialized to a particular value
ImageType::PixelType initialValue;
// A vector can initialize all its components to the
// same value by using the Fill() method.
initialValue.Fill( 0.0 );
// Now the image buffer can be initialized with this
// vector value.
image->FillBuffer( initialValue );
ImageType::IndexType pixelIndex;
pixelIndex[0] = 27; // x position
pixelIndex[1] = 29; // y position
pixelIndex[2] = 37; // z position
// Software Guide : BeginLatex
//
// The Vector class inherits the operator \code{[]} from the
// \doxygen{FixedArray} class. This makes it possible to access the
// Vector's components using index notation.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
ImageType::PixelType pixelValue;
pixelValue[0] = 1.345; // x component
pixelValue[1] = 6.841; // y component
pixelValue[2] = 3.295; // x component
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// We can now store this vector in one of the image pixels by defining an
// index and invoking the \code{SetPixel()} method.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
image->SetPixel( pixelIndex, pixelValue );
// Software Guide : EndCodeSnippet
// The GetPixel method can also be used to read Vectors
// pixels from the image
ImageType::PixelType value = image->GetPixel( pixelIndex );
// Lets repeat that both \code{SetPixel()} and \code{GetPixel()} are
// inefficient and should only be used for debugging purposes or for
// implementing interactions with a graphical user interface such as
// querying pixel value by clicking with the mouse.
return 0;
}
PROJECT(MeshExamples)
INCLUDE_REGULAR_EXPRESSION("^.*$")
ADD_EXECUTABLE(Mesh1 Mesh1.cxx )
TARGET_LINK_LIBRARIES(Mesh1 ITKCommon)
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: Mesh1.cxx,v $
Language: C++
Date: $Date: 2005/11/19 16:31:49 $
Version: $Revision: 1.17 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
// Software Guide : BeginLatex
//
// The \doxygen{Mesh} class is intended to represent shapes in space. It
// derives from the \doxygen{PointSet} class and hence inherits all the
// functionality related to points and access to the pixel-data associated
// with the points. The mesh class is also n-dimensional which
// allows a great flexibility in its use.
//
// In practice a Mesh class can be seen as a PointSet to
// which cells (also known as elements) of many different dimensions and
// shapes have been added. Cells in the mesh are defined in terms of the
// existing points using their point-identifiers.
//
// In the same way as for the PointSet, two basic styles of
// Meshes are available in ITK. They are referred to as \emph{static}
// and \emph{dynamic}. The first one is used when the number of
// points in the set can be known in advance and it is not expected
// to change as a consequence of the manipulations performed on the
// set. The dynamic style, on the other hand, is intended to support
// insertion and removal of points in an efficient manner. The reason
// for making the distinction between the two styles is to facilitate
// fine tuning its behavior with the aim of optimizing
// performance and memory management. In the case of the Mesh, the
// dynamic/static aspect is extended to the management of cells.
//
// \index{itk::Mesh}
// \index{itk::Mesh!Static}
// \index{itk::Mesh!Dynamic}
// \index{itk::Mesh!Header file}
//
// In order to use the Mesh class, its header file should be included.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
#include "itkMesh.h"
// Software Guide : EndCodeSnippet
int main(int, char *[])
{
// Software Guide : BeginLatex
//
// Then, the type associated with the points must be selected and used for
// instantiating the Mesh type.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef float PixelType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The Mesh type extensively uses the capabilities provided by
// \href{http://www.boost.org/more/generic_programming.html}{Generic
// Programming}. In particular the Mesh class is parameterized over the
// PixelType and the dimension of the space. PixelType is the type of the
// value associated with every point just as is done with the
// PointSet. The following line illustrates a typical
// instantiation of the Mesh.
//
// \index{itk::Mesh!Instantiation}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
const unsigned int Dimension = 3;
typedef itk::Mesh< PixelType, Dimension > MeshType;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Meshes are expected to take large amounts of memory. For this reason they
// are reference counted objects and are managed using SmartPointers. The
// following line illustrates how a mesh is created by invoking the
// \code{New()} method of the MeshType and the resulting object is assigned
// to a \doxygen{SmartPointer}.
//
// \index{itk::Mesh!New()}
// \index{itk::Mesh!Pointer()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
MeshType::Pointer mesh = MeshType::New();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The management of points in the Mesh is exactly the same as in
// the PointSet. The type point associated with the mesh can be
// obtained through the \code{PointType} trait. The following code shows the
// creation of points compatible with the mesh type defined above and the
// assignment of values to its coordinates.
//
// \index{itk::Mesh!PointType}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
MeshType::PointType p0;
MeshType::PointType p1;
MeshType::PointType p2;
MeshType::PointType p3;
p0[0]= -1.0; p0[1]= -1.0; p0[2]= 0.0; // first point ( -1, -1, 0 )
p1[0]= 1.0; p1[1]= -1.0; p1[2]= 0.0; // second point ( 1, -1, 0 )
p2[0]= 1.0; p2[1]= 1.0; p2[2]= 0.0; // third point ( 1, 1, 0 )
p3[0]= -1.0; p3[1]= 1.0; p3[2]= 0.0; // fourth point ( -1, 1, 0 )
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The points can now be inserted in the Mesh using the \code{SetPoint()}
// method. Note that points are copied into the mesh structure. This means
// that the local instances of the points can now be modified without
// affecting the Mesh content.
//
// \index{itk::Mesh!SetPoint()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
mesh->SetPoint( 0, p0 );
mesh->SetPoint( 1, p1 );
mesh->SetPoint( 2, p2 );
mesh->SetPoint( 3, p3 );
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The current number of points in the Mesh can be queried with the
// \code{GetNumberOfPoints()} method.
//
// \index{itk::Mesh!GetNumberOfPoints()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
std::cout << "Points = " << mesh->GetNumberOfPoints() << std::endl;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The points can now be efficiently accessed using the Iterator to the
// PointsContainer as it was done in the previous section for the
// PointSet. First, the point iterator type is extracted through
// the mesh traits.
//
// \index{PointsContainer!Iterator}
// \index{itk::Mesh!GetPoints()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef MeshType::PointsContainer::Iterator PointsIterator;
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// A point iterator is initialized to the first point with the
// \code{Begin()} method of the PointsContainer.
//
// \index{PointsContainer!Begin()}
// \index{itk::Mesh!GetPoints()}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
PointsIterator pointIterator = mesh->GetPoints()->Begin();
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// The \code{++} operator on the iterator is now used to advance from one
// point to the next. The actual value of the Point to which the iterator is
// pointing can be obtained with the \code{Value()} method. The loop for
// walking through all the points is controlled by comparing the current
// iterator with the iterator returned by the \code{End()} method of the
// PointsContainer. The following lines illustrate the typical loop for
// walking through the points.
//
// \index{PointsContainer!End()}
// \index{PointsContainer!Iterator}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
PointsIterator end = mesh->GetPoints()->End();
while( pointIterator != end )
{
MeshType::PointType p = pointIterator.Value(); // access the point
std::cout << p << std::endl; // print the point
++pointIterator; // advance to next point
}
// Software Guide : EndCodeSnippet
return 0;
}
PROJECT(PathExamples)
INCLUDE_REGULAR_EXPRESSION("^.*$")
ADD_EXECUTABLE(PolyLineParametricPath1 PolyLineParametricPath1.cxx )
TARGET_LINK_LIBRARIES(PolyLineParametricPath1 ITKCommon ITKIO)
ADD_TEST(PolyLineParametricPath1 ${CXX_TEST_PATH}/PolyLineParametricPath1
${ITK_SOURCE_DIR}/Examples/Data/VisibleWomanEyeSlice.png
)
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: PolyLineParametricPath1.cxx,v $
Language: C++
Date: $Date: 2005/02/08 03:51:53 $
Version: $Revision: 1.4 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
// Software Guide : BeginLatex
//
// This example illustrates how to use the \doxygen{PolyLineParametricPath}.
// This class will typically be used for representing in a concise way the
// output of an image segmentation algorithm in 2D. The
// \code{PolyLineParametricPath} however could also be used for representing
// any open or close curve in N-Dimensions as a linear piece-wise approximation.
//
//
// First, the header file of the \code{PolyLineParametricPath} class must be included.
//
// Software Guide : EndLatex
#include "itkImage.h"
#include "itkImageFileReader.h"
// Software Guide : BeginCodeSnippet
#include "itkPolyLineParametricPath.h"
// Software Guide : EndCodeSnippet
int main(int argc, char * argv [] )
{
if( argc < 2 )
{
std::cerr << "Missing arguments" << std::endl;
std::cerr << "Usage: PolyLineParametricPath inputImageFileName" << std::endl;
return -1;
}
// Software Guide : BeginLatex
//
// The path is instantiated over the dimension of the image. In this case 2D. //
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
const unsigned int Dimension = 2;
typedef itk::Image< unsigned char, Dimension > ImageType;
typedef itk::PolyLineParametricPath< Dimension > PathType;
// Software Guide : EndCodeSnippet
typedef itk::ImageFileReader< ImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
try
{
reader->Update();
}
catch( itk::ExceptionObject & excp )
{
std::cout << "Problem reading the input image " << std::endl;
std::cout << excp << std::endl;
return -1;
}
// Software Guide : BeginCodeSnippet
ImageType::ConstPointer image = reader->GetOutput();
PathType::Pointer path = PathType::New();
path->Initialize();
typedef PathType::ContinuousIndexType ContinuousIndexType;
ContinuousIndexType cindex;
typedef ImageType::PointType ImagePointType;
ImagePointType origin = image->GetOrigin();
ImageType::SpacingType spacing = image->GetSpacing();
ImageType::SizeType size = image->GetBufferedRegion().GetSize();
ImagePointType point;
point[0] = origin[0] + spacing[0] * size[0];
point[1] = origin[1] + spacing[1] * size[1];
image->TransformPhysicalPointToContinuousIndex( origin, cindex );
path->AddVertex( cindex );
image->TransformPhysicalPointToContinuousIndex( point, cindex );
path->AddVertex( cindex );
// Software Guide : EndCodeSnippet
return 0;
}
$Id$
OTB : répertoire des exemples
OTB Examples Directory
----------------------
Ce répertoire contient de simple exemples pour l'OTB
This directory contains simple, companion examples to the ORFEO
Toolbox (OTB). These examples are designed to demonstrate features of
the system; they are not meant to be significant applications of the
software (see the separate directory OTB-Applications for such
applications).
Plus précisément, le but de ces exemples est de :
Specifically, the purpose of these examples is as follows:
* Fournir des exemples simples et les focntionnalités importantes de l'OTB et comment les utiliser
Ces exemples peuvent être ou non compilés lors de la génération du produit (Configuration dans le CMake).
* Fournir les exemples illustrant le guide de l'OTB (ce guide se trouve dans le répertoire
OTB-Documents/SoftwareGuide).
* Provide simple, minimalist examples of important features of OTB and how
to use them. The examples have minimal dependencies on outside packages;
and if they do, there should be CMake flags to turn them off.
* Etre sûr que le code est bien documenté et qu'il est toujours 'up-to-date' avec le code source de l'OTB.
* Provide a consistent set of examples that will work in conjunctions with
the OTB Software Guide.
Les répertoires suivants listent les sous-répertoires avec une décription succincte du code source que l'on y trouve.
* Provide a consistent set of examples that will work with OTB tutorials
and courses.
* Installation - un exemple très simple montrant la compilation d'un petit prgramme utilisant l'OTB
* Make sure that the code is well documented, of consistent style, and
always up-to-date with the current OTB code.
* ...
The following is a list of subdirectories with a description of the code
found in them.
* Installation - a very simple example to demonstrate compiling against
the OTB libraries and configuring CMake.
* DataRepresentation - creating images and meshes; shows the basics of
creating and executing the pipeline
* Iterators - iterating over images and meshes.
* Infrastructure - events, observers, factories, smart pointers,
namespaces, transforms, etc.
* Numerics - working with VNL; a focus on interface with ITK/OTB classes
* IO - the basics of reading/writing data
* Filtering - examples of image processing and mesh filters.
* Segmentation - a suite of basic segmentation examples.
* Registration - a suite of basic registration methods.
* GUI - some outside package interface: wxWindows, Qt, FLTK, Tk, VTK. The
absolute minimal interface.
To learn the software from these examples, you may wish to refer to the
"ORFEO Toolbox Software Guide".
Pour plus d'informations sur les exemples, lire le guide de l'OTB quise trouve dans "OTB-Documents/SoftwareGuide".
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment