ITK/Examples/WishList/PointSet/BSplineScatteredDataPointSetToImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
No edit summary
Line 20: Line 20:
   PointSetType::PointType param0, param1, param2;
   PointSetType::PointType param0, param1, param2;


  param0[0] = 0.0;
  param0[0] = 0.0;
   DataType p0;
   DataType p0;
   p0[0] =  1.0; p0[1]= 1.0;
   p0[0] =  10.0; p0[1]= 10.0;


   pointSet->SetPoint(0, param0);
   pointSet->SetPoint(0, param0);
Line 29: Line 29:
   param1[0] = 1.0;
   param1[0] = 1.0;
   DataType p1;
   DataType p1;
   p1[0] =  100.0; p1[1]= 50.0;
   p1[0] =  80.0; p1[1]= 50.0;
   pointSet->SetPoint(1, param1);
   pointSet->SetPoint(1, param1);
   pointSet->SetPointData( 1, p1 );
   pointSet->SetPointData( 1, p1 );
Line 35: Line 35:
   param2[0] = 2.0;
   param2[0] = 2.0;
   DataType p2;
   DataType p2;
   p2[0] =  100.0; p2[1]= 1.0;
   p2[0] =  180.0; p2[1]= 180.0;
   pointSet->SetPoint(2, param2);
   pointSet->SetPoint(2, param2);
   pointSet->SetPointData( 2, p2 );
   pointSet->SetPointData( 2, p2 );


  typedef itk::Image<DataType, ParametricDimension> ImageType;
  typedef itk::Image<DataType, ParametricDimension> ImageType;
   typedef itk::BSplineScatteredDataPointSetToImageFilter < PointSetType, ImageType > SplineFilterType;
   typedef itk::BSplineScatteredDataPointSetToImageFilter < PointSetType, ImageType > SplineFilterType;
   SplineFilterType::Pointer splineFilter = SplineFilterType::New();
   SplineFilterType::Pointer splineFilter = SplineFilterType::New();
  int splineorder=2; // complexity of the spline


   SplineFilterType::ArrayType ncontrol;
   SplineFilterType::ArrayType ncontrol;
   ncontrol[0]=20;
   ncontrol[0]=splineorder + 1;
   SplineFilterType::ArrayType closedim;
   SplineFilterType::ArrayType closedim;
   closedim[0]= 0;
   closedim[0]= 0;
  int splineorder=2; // complexity of the spline


   ImageType::PointType parametricDomainOrigin;
   ImageType::PointType parametricDomainOrigin;
Line 53: Line 54:


   ImageType::SpacingType parametricDomainSpacing;
   ImageType::SpacingType parametricDomainSpacing;
   parametricDomainSpacing[0] = 0.01;  // this determines the sampling of the continuous B-spline object.
   parametricDomainSpacing[0] = 0.0001;  // this determines the sampling of the continuous B-spline object.


   ImageType::SizeType parametricDomainSize;
   ImageType::SizeType parametricDomainSize;
   parametricDomainSize[0] = 2.0 / parametricDomainSpacing[0] + 1;
   parametricDomainSize[0] = 2.0 / parametricDomainSpacing[0] + 1;
   splineFilter->SetGenerateOutputImage( true );  // the only reason to turn this off is if one only wants to use the control point lattice for further processing
   splineFilter->SetGenerateOutputImage( true );  // the only reason to turn this off is if one only wants to use the control point lattice for further processing
   splineFilter->SetInput ( pointSet );
   splineFilter->SetInput ( pointSet );
   splineFilter->SetSplineOrder ( splineorder );
   splineFilter->SetSplineOrder ( splineorder );
   splineFilter->SetNumberOfControlPoints ( ncontrol );
   splineFilter->SetNumberOfControlPoints ( ncontrol );
   splineFilter->SetNumberOfLevels( 1 );
   splineFilter->SetNumberOfLevels( 3 );
   splineFilter->SetCloseDimension ( closedim );
   splineFilter->SetCloseDimension ( closedim );
   splineFilter->SetSize( parametricDomainSize );
   splineFilter->SetSize( parametricDomainSize );
Line 68: Line 68:
   splineFilter->SetOrigin( parametricDomainOrigin );
   splineFilter->SetOrigin( parametricDomainOrigin );
   splineFilter->Update();
   splineFilter->Update();
  std::cout << splineFilter->GetOutput()->GetLargestPossibleRegion().GetSize();


   // The output will consist of a 1-D image where each voxel contains the
   // The output will consist of a 1-D image where each voxel contains the
Line 83: Line 81:
   OutputImageType::RegionType region(start, size);
   OutputImageType::RegionType region(start, size);
   outputImage->SetRegions(region);
   outputImage->SetRegions(region);
 
  outputImage->Allocate();
   outputImage->FillBuffer(0);
   outputImage->FillBuffer(0);


Line 90: Line 88:
     ImageType::IndexType splineIndex;
     ImageType::IndexType splineIndex;
     splineIndex[0] = i;
     splineIndex[0] = i;
 
 
     DataType outputPixel = splineFilter->GetOutput()->GetPixel(splineIndex);
     DataType outputPixel = splineFilter->GetOutput()->GetPixel(splineIndex);
 
 
     OutputImageType::IndexType index;
     OutputImageType::IndexType index;
     index[0] = outputPixel[0];
     index[0] = outputPixel[0];
     index[1] = outputPixel[1];
     index[1] = outputPixel[1];
 
 
     outputImage->SetPixel(index, 255);
     outputImage->SetPixel(index, 255 );
     }
     }


Line 105: Line 103:
   writer->SetInput(outputImage);
   writer->SetInput(outputImage);
   writer->Update();
   writer->Update();
 
 
   return EXIT_SUCCESS;
   return EXIT_SUCCESS;
};
};
 
</source>
</source>


{{ITKCMakeLists|BSplineScatteredDataPointSetToImageFilter|}}
{{ITKCMakeLists|BSplineScatteredDataPointSetToImageFilter|}}

Revision as of 00:12, 13 June 2011

BSplineScatteredDataPointSetToImageFilter.cxx

<source lang="cpp">

  1. include "itkBSplineScatteredDataPointSetToImageFilter.h"
  2. include "itkPointSet.h"
  3. include "itkImage.h"
  4. include "itkVectorImage.h"
  5. include "itkImageFileWriter.h"

int main (void) {

 const unsigned int ParametricDimension = 1;
 const unsigned int DataDimension = 2;
 typedef itk::Vector< float, DataDimension > DataType;
 typedef itk::PointSet< DataType, ParametricDimension >   PointSetType;
 PointSetType::Pointer pointSet = PointSetType::New();
 PointSetType::PointType param0, param1, param2;
  param0[0] = 0.0;
 DataType p0;
 p0[0] =  10.0; p0[1]= 10.0;
 pointSet->SetPoint(0, param0);
 pointSet->SetPointData( 0, p0 );
 param1[0] = 1.0;
 DataType p1;
 p1[0] =  80.0; p1[1]= 50.0;
 pointSet->SetPoint(1, param1);
 pointSet->SetPointData( 1, p1 );
 param2[0] = 2.0;
 DataType p2;
 p2[0] =  180.0; p2[1]= 180.0;
 pointSet->SetPoint(2, param2);
 pointSet->SetPointData( 2, p2 );
  typedef itk::Image<DataType, ParametricDimension> ImageType;
 typedef itk::BSplineScatteredDataPointSetToImageFilter < PointSetType, ImageType > SplineFilterType;
 SplineFilterType::Pointer splineFilter = SplineFilterType::New();
 int splineorder=2; // complexity of the spline
 SplineFilterType::ArrayType ncontrol;
 ncontrol[0]=splineorder + 1;
 SplineFilterType::ArrayType closedim;
 closedim[0]= 0;
 ImageType::PointType parametricDomainOrigin;
 parametricDomainOrigin[0] = 0.0;
 ImageType::SpacingType parametricDomainSpacing;
 parametricDomainSpacing[0] = 0.0001;  // this determines the sampling of the continuous B-spline object.
 ImageType::SizeType parametricDomainSize;
 parametricDomainSize[0] = 2.0 / parametricDomainSpacing[0] + 1;
 splineFilter->SetGenerateOutputImage( true );   // the only reason to turn this off is if one only wants to use the control point lattice for further processing
 splineFilter->SetInput ( pointSet );
 splineFilter->SetSplineOrder ( splineorder );
 splineFilter->SetNumberOfControlPoints ( ncontrol );
 splineFilter->SetNumberOfLevels( 3 );
 splineFilter->SetCloseDimension ( closedim );
 splineFilter->SetSize( parametricDomainSize );
 splineFilter->SetSpacing( parametricDomainSpacing );
 splineFilter->SetOrigin( parametricDomainOrigin );
 splineFilter->Update();
 // The output will consist of a 1-D image where each voxel contains the
 // (x,y,z) locations of the points
 typedef itk::Image<unsigned char, 2> OutputImageType;
 OutputImageType::Pointer outputImage = OutputImageType::New();
 OutputImageType::SizeType size;
 size.Fill(200);
 OutputImageType::IndexType start;
 start.Fill(0);
 OutputImageType::RegionType region(start, size);
 outputImage->SetRegions(region);
 outputImage->Allocate();
 outputImage->FillBuffer(0);
 for(unsigned int i = 0; i < splineFilter->GetOutput()->GetLargestPossibleRegion().GetSize()[0]; ++i)
   {
   ImageType::IndexType splineIndex;
   splineIndex[0] = i;
   DataType outputPixel = splineFilter->GetOutput()->GetPixel(splineIndex);
   OutputImageType::IndexType index;
   index[0] = outputPixel[0];
   index[1] = outputPixel[1];
   outputImage->SetPixel(index, 255 );
   }
 typedef  itk::ImageFileWriter< OutputImageType  > WriterType;
 WriterType::Pointer writer = WriterType::New();
 writer->SetFileName("spline.png");
 writer->SetInput(outputImage);
 writer->Update();
 return EXIT_SUCCESS;

}; </source>

CMakeLists.txt

<syntaxhighlight lang="cmake"> cmake_minimum_required(VERSION 3.9.5)

project(BSplineScatteredDataPointSetToImageFilter)

find_package(ITK REQUIRED) include(${ITK_USE_FILE}) if (ITKVtkGlue_LOADED)

 find_package(VTK REQUIRED)
 include(${VTK_USE_FILE})

endif()

add_executable(BSplineScatteredDataPointSetToImageFilter MACOSX_BUNDLE BSplineScatteredDataPointSetToImageFilter.cxx)

if( "${ITK_VERSION_MAJOR}" LESS 4 )

 target_link_libraries(BSplineScatteredDataPointSetToImageFilter ITKReview ${ITK_LIBRARIES})

else( "${ITK_VERSION_MAJOR}" LESS 4 )

 target_link_libraries(BSplineScatteredDataPointSetToImageFilter ${ITK_LIBRARIES})

endif( "${ITK_VERSION_MAJOR}" LESS 4 )

</syntaxhighlight>

Download and Build BSplineScatteredDataPointSetToImageFilter

Click here to download BSplineScatteredDataPointSetToImageFilter and its CMakeLists.txt file. Once the tarball BSplineScatteredDataPointSetToImageFilter.tar has been downloaded and extracted,

cd BSplineScatteredDataPointSetToImageFilter/build
  • If ITK is installed:
cmake ..
  • If ITK is not installed but compiled on your system, you will need to specify the path to your ITK build:
cmake -DITK_DIR:PATH=/home/me/itk_build ..

Build the project:

make

and run it:

./BSplineScatteredDataPointSetToImageFilter

WINDOWS USERS PLEASE NOTE: Be sure to add the ITK bin directory to your path. This will resolve the ITK dll's at run time.

Building All of the Examples

Many of the examples in the ITK Wiki Examples Collection require VTK. You can build all of the the examples by following these instructions. If you are a new VTK user, you may want to try the Superbuild which will build a proper ITK and VTK.

ItkVtkGlue

ITK >= 4

For examples that use QuickView (which depends on VTK), you must have built ITK with Module_ITKVtkGlue=ON.

ITK < 4

Some of the ITK Examples require VTK to display the images. If you download the entire ITK Wiki Examples Collection, the ItkVtkGlue directory will be included and configured. If you wish to just build a few examples, then you will need to download ItkVtkGlue and build it. When you run cmake it will ask you to specify the location of the ItkVtkGlue binary directory.