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

DataRepresentation/Mesh/RGBPointSet.cxx

00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: RGBPointSet.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2008/01/20 21:19:51 $
00007   Version:   $Revision: 1.12 $
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 //  The following example illustrates how a point set can be parameterized to
00024 //  manage a particular pixel type. In this case, pixels of RGB type are used.
00025 //  The first step is then to include the header files of the
00026 //  \doxygen{RGBPixel} and \doxygen{PointSet} classes.
00027 //
00028 //  \index{itk::PointSet!RGBPixel}
00029 //
00030 //  Software Guide : EndLatex 
00031 
00032 // Software Guide : BeginCodeSnippet
00033 #include "itkRGBPixel.h"
00034 #include "itkPointSet.h"
00035 // Software Guide : EndCodeSnippet
00036 
00037 
00038 int main(int, char *[])
00039 {
00040   //  Software Guide : BeginLatex
00041   //
00042   //  Then, the pixel type can be defined by selecting the type to be used to
00043   //  represent each one of the RGB components.
00044   //
00045   //  \index{itk::RGBPixel!Instantiation}
00046   //
00047   //  Software Guide : EndLatex 
00048 
00049   // Software Guide : BeginCodeSnippet
00050   typedef itk::RGBPixel< float >    PixelType;
00051   // Software Guide : EndCodeSnippet
00052 
00053 
00054   //  Software Guide : BeginLatex
00055   //
00056   //  The newly defined pixel type is now used to instantiate the PointSet
00057   //  type and subsequently create a point set object.
00058   //
00059   //  Software Guide : EndLatex 
00060 
00061   // Software Guide : BeginCodeSnippet
00062   typedef itk::PointSet< PixelType, 3 > PointSetType;
00063   PointSetType::Pointer  pointSet = PointSetType::New();
00064   // Software Guide : EndCodeSnippet
00065 
00066 
00067   //  Software Guide : BeginLatex
00068   //
00069   //  The following code is generating a sphere and assigning RGB values to
00070   //  the points. The components of the RGB values in this example are
00071   //  computed to represent the position of the points.
00072   //
00073   //  \index{itk::PointSet!SetPoint()}
00074   //  \index{itk::PointSet!SetPointData()}
00075   //
00076   //  Software Guide : EndLatex 
00077 
00078   // Software Guide : BeginCodeSnippet
00079   PointSetType::PixelType   pixel;
00080   PointSetType::PointType   point;
00081   unsigned int pointId =  0;
00082   const double radius = 3.0;
00083 
00084   for(unsigned int i=0; i<360; i++)
00085     {
00086     const double angle = i * atan(1.0) / 45.0;
00087     point[0] = radius * sin( angle );
00088     point[1] = radius * cos( angle );
00089     point[2] = 1.0;
00090     pixel.SetRed(    point[0] * 2.0 );
00091     pixel.SetGreen(  point[1] * 2.0 );
00092     pixel.SetBlue(   point[2] * 2.0 );
00093     pointSet->SetPoint( pointId, point );   
00094     pointSet->SetPointData( pointId, pixel );   
00095     pointId++;
00096     }
00097   // Software Guide : EndCodeSnippet
00098 
00099 
00100   //  Software Guide : BeginLatex
00101   //
00102   //  All the points on the PointSet are visited using the following code.
00103   //
00104   //  \index{itk::PointSet!GetPoints()}
00105   //  \index{itk::PointSet!points iterator}
00106   //  \index{itk::PointSet!iterating points}
00107   //
00108   //  Software Guide : EndLatex 
00109 
00110   // Software Guide : BeginCodeSnippet
00111   typedef  PointSetType::PointsContainer::ConstIterator     PointIterator;
00112   PointIterator pointIterator = pointSet->GetPoints()->Begin();
00113   PointIterator pointEnd      = pointSet->GetPoints()->End();
00114   while( pointIterator != pointEnd ) 
00115     {
00116      point = pointIterator.Value();
00117     std::cout << point << std::endl;  
00118     ++pointIterator;                      
00119     }
00120   // Software Guide : EndCodeSnippet
00121 
00122 
00123   //  Software Guide : BeginLatex
00124   //
00125   //  Note that here the \code{ConstIterator} was used instead of the
00126   //  \code{Iterator} since the pixel values are not expected to be modified.
00127   //  ITK supports const-correctness at the API level. 
00128   //
00129   //  Software Guide : EndLatex 
00130 
00131 
00132   //  Software Guide : BeginLatex
00133   //
00134   //  All the pixel values on the PointSet are visited using the following code.
00135   //
00136   //  \index{itk::PointSet!GetPointData()}
00137   //  \index{itk::PointSet!data iterator}
00138   //  \index{itk::PointSet!iterating point data}
00139   //
00140   //  Software Guide : EndLatex 
00141 
00142 
00143   // Software Guide : BeginCodeSnippet
00144   typedef  PointSetType::PointDataContainer::ConstIterator     PointDataIterator;
00145   PointDataIterator pixelIterator = pointSet->GetPointData()->Begin();
00146   PointDataIterator pixelEnd      = pointSet->GetPointData()->End();
00147   while( pixelIterator != pixelEnd ) 
00148     {
00149     pixel = pixelIterator.Value();
00150     std::cout << pixel << std::endl;  
00151     ++pixelIterator;                      
00152     }
00153   // Software Guide : EndCodeSnippet
00154 
00155   //  Software Guide : BeginLatex
00156   //
00157   //  Again, please note the use of the  \code{ConstIterator} instead of the
00158   //  \code{Iterator}. 
00159   //
00160   //  \index{ConstIterator}
00161   //  \index{const-correctness}
00162   //
00163   //  Software Guide : EndLatex 
00164 
00165 
00166 
00167 
00168   return 0;
00169 
00170 }
00171 
00172 
00173 

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