Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

DataRepresentation/Image/Image1.cxx

00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: Image1.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2005/02/08 03:51:52 $
00007   Version:   $Revision: 1.21 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #if defined(_MSC_VER)
00018 #pragma warning ( disable : 4786 )
00019 #endif
00020 
00021 // Software Guide : BeginLatex
00022 //
00023 // This example illustrates how to manually construct an \doxygen{Image}
00024 // class.  The following is the minimal code needed to instantiate, declare
00025 // and create the image class.
00026 //
00027 // \index{itk::Image!Instantiation}
00028 // \index{itk::Image!Header}
00029 //
00030 // First, the header file of the Image class must be included.
00031 //
00032 // Software Guide : EndLatex 
00033 
00034 
00035 // Software Guide : BeginCodeSnippet
00036 #include "itkImage.h"
00037 // Software Guide : EndCodeSnippet
00038 
00039 
00040 
00041 int main(int, char *[])
00042 {
00043   // Software Guide : BeginLatex
00044   // 
00045   // Then we must decide with what type to represent the pixels
00046   // and what the dimension of the image will be. With these two 
00047   // parameters we can instantiate the image class. Here we create
00048   // a 3D image with \code{unsigned short} pixel data.
00049   //
00050   // Software Guide : EndLatex 
00051   //
00052   // Software Guide : BeginCodeSnippet 
00053   typedef itk::Image< unsigned short, 3 > ImageType;
00054   // Software Guide : EndCodeSnippet 
00055 
00056   
00057   // Software Guide : BeginLatex
00058   //
00059   // The image can then be created by invoking the \code{New()} operator
00060   // from the corresponding image type and assigning the result
00061   // to a \doxygen{SmartPointer}. 
00062   //
00063   // \index{itk::Image!Pointer}
00064   // \index{itk::Image!New()}
00065   // 
00066   // Software Guide : EndLatex 
00067   //
00068   // Software Guide : BeginCodeSnippet 
00069   ImageType::Pointer image = ImageType::New();      
00070   // Software Guide : EndCodeSnippet 
00071  
00072 
00073   // Software Guide : BeginLatex
00074   //
00075   // In ITK, images exist in combination with one or more
00076   // \emph{regions}. A region is a subset of the image and indicates a
00077   // portion of the image that may be processed by other classes in
00078   // the system. One of the most common regions is the
00079   // \emph{LargestPossibleRegion}, which defines the image in its
00080   // entirety. Other important regions found in ITK are the
00081   // \emph{BufferedRegion}, which is the portion of the image actually
00082   // maintained in memory, and the \emph{RequestedRegion}, which is
00083   // the region requested by a filter or other class when operating on
00084   // the image.
00085   //
00086   // In ITK, manually creating an image requires that the image is
00087   // instantiated as previously shown, and that regions describing the image are
00088   // then associated with it.
00089   //
00090   // A region is defined by two classes: the \doxygen{Index} and
00091   // \doxygen{Size} classes. The origin of the region within the
00092   // image with which it is associated is defined by Index. The
00093   // extent, or size, of the region is defined by Size. Index
00094   // is represented by a n-dimensional array where each component is an
00095   // integer indicating---in topological image coordinates---the initial
00096   // pixel of the image. When an image is created manually, the user is
00097   // responsible for defining the image size and the index at which the image
00098   // grid starts. These two parameters make it possible to process selected
00099   // regions.
00100   //   
00101   // The starting point of the image is defined by an Index class
00102   // that is an n-dimensional array where each component is an integer
00103   // indicating the grid coordinates of the initial pixel of the image.
00104   //
00105   // \index{itk::Image!Size}
00106   // \index{itk::Image!SizeType}
00107   //
00108   // Software Guide : EndLatex 
00109   //
00110   // Software Guide : BeginCodeSnippet 
00111   ImageType::IndexType start;
00112 
00113   start[0] =   0;  // first index on X
00114   start[1] =   0;  // first index on Y
00115   start[2] =   0;  // first index on Z
00116   // Software Guide : EndCodeSnippet 
00117 
00118   // Software Guide : BeginLatex
00119   //
00120   // The region size is represented by an array of the same dimension of the
00121   // image (using the Size class). The components of the array are
00122   // unsigned integers indicating the extent in pixels of the image along
00123   // every dimension.
00124   //
00125   // \index{itk::Image!Index}
00126   // \index{itk::Image!IndexType}
00127   //
00128   // Software Guide : EndLatex 
00129   // 
00130   // Software Guide : BeginCodeSnippet 
00131   ImageType::SizeType  size;
00132 
00133   size[0]  = 200;  // size along X
00134   size[1]  = 200;  // size along Y
00135   size[2]  = 200;  // size along Z
00136   // Software Guide : EndCodeSnippet 
00137 
00138   // Software Guide : BeginLatex
00139   //
00140   // Having defined the starting index and the image size, these two
00141   // parameters are used to create an ImageRegion object which basically
00142   // encapsulates both concepts. The region is initialized with the
00143   // starting index and size of the image.
00144   //
00145   // \index{itk::Image!itk::ImageRegion}
00146   // \index{itk::Image!RegionType}
00147   //
00148   // Software Guide : EndLatex 
00149 
00150   // Software Guide : BeginCodeSnippet 
00151   ImageType::RegionType region;
00152   
00153   region.SetSize( size );
00154   region.SetIndex( start );
00155   // Software Guide : EndCodeSnippet 
00156 
00157   // Software Guide : BeginLatex
00158   //
00159   // Finally, the region is passed to the \code{Image} object in order to define its
00160   // extent and origin. The \code{SetRegions} method sets the
00161   // LargestPossibleRegion, BufferedRegion, and RequestedRegion
00162   // simultaneously. Note that none of the operations performed to this point
00163   // have allocated memory for the image pixel data. It is necessary to
00164   // invoke the \code{Allocate()} method to do this. Allocate does not
00165   // require any arguments since all the information needed for memory
00166   // allocation has already been provided by the region.
00167   //
00168   // \index{itk::Image!Allocate()}
00169   // \index{itk::Image!SetRegions()}
00170   //
00171   // Software Guide : EndLatex 
00172 
00173   // Software Guide : BeginCodeSnippet 
00174   image->SetRegions( region );
00175   image->Allocate();
00176   // Software Guide : EndCodeSnippet 
00177 
00178   return 0;
00179 }
00180 

Generated at Wed Nov 5 20:13:03 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000