/*========================================================================= This code provided as part of Brooks, R., Arbel, T. "Improving the OrientedImage class for use in the Registration Framework", Insight Journal, October, 2007 Author: Rupert Brooks Institution: Centre for Intelligent Machines, McGill University =========================================================================*/ //#define PRINTFUNCS #include "itkFastOrientedImage.h" #include "itkImage.h" #include "itkOrientedImage.h" #include "time.h" #include #include typedef unsigned char PixelType; // for any sort of real test, make speed test num large, but // that can make ctest time out. So here we haev it small //#define SPEEDTESTNUM 50000000 #define SPEEDTESTNUM 50000 #define NUMTESTPOINTS 2 #define TOL 1e-12 #define TEST2D 1 #define TEST3D 1 #define TEST4D 1 #define SPEEDTEST 1 #define ALLCOMBINATIONS 1 std::ostream * outfile=NULL; template void testfunction(typename TFastImage::Pointer& fastImage, typename TImage::Pointer& regularImage, typename TPlainImage::Pointer& plainImage, unsigned int& any ) { double fastregratio, fastplainratio; // now set all the directions, spacing and origin typename TImage::PointType inPoint1,inPoint2,fastPoint,regularPoint,origin, testPoints[NUMTESTPOINTS],fastPoints[NUMTESTPOINTS], regularPoints[NUMTESTPOINTS],plainPoints[NUMTESTPOINTS]; typename TImage::SpacingType spacing; typename TImage::DirectionType direction; typename TImage::IndexType inIndex1,inIndex2,fastIndex,regularIndex, testIndexes[NUMTESTPOINTS],fastIndexes[NUMTESTPOINTS], regularIndexes[NUMTESTPOINTS],plainIndexes[NUMTESTPOINTS]; const unsigned int Dimension=TImage::ImageDimension; //double temp; itk::ContinuousIndex inContIndex1,inContIndex2, fastContIndex,regularContIndex, testContIndexes[NUMTESTPOINTS],fastContIndexes[NUMTESTPOINTS], regularContIndexes[NUMTESTPOINTS],plainContIndexes[NUMTESTPOINTS]; bool fastResult,regularResult,equal; // set up the test points /indices for (unsigned int i=0;iTransformContinuousIndexToPhysicalPoint(inContIndex1,fastPoint); regularImage->TransformContinuousIndexToPhysicalPoint(inContIndex1,regularPoint); equal=true; for(unsigned int i=0;iTOL) equal=false; if(!equal) { (*outfile)<<"TCITPP inside Failed test"<GetOrigin()<<" "<GetOrigin()<GetSpacing()<<" "<GetSpacing()<GetDirection()<GetDirection()<TransformContinuousIndexToPhysicalPoint(inContIndex2,fastPoint); regularImage->TransformContinuousIndexToPhysicalPoint(inContIndex2,regularPoint); equal=true; for(unsigned int i=0;iTOL) equal=false; if(!equal) { (*outfile)<<"TCITPP outside Failed test"<GetOrigin()<<" "<GetOrigin()<GetSpacing()<<" "<GetSpacing()<GetDirection()<GetDirection()<TransformContinuousIndexToPhysicalPoint(testContIndexes[i%NUMTESTPOINTS],fastPoints[(i*i)%NUMTESTPOINTS]); } clock_t fastend=clock(); clock_t regularstart=clock(); for (unsigned int i=0;iTransformContinuousIndexToPhysicalPoint(testContIndexes[i%NUMTESTPOINTS],regularPoints[(i*i)%NUMTESTPOINTS]); } clock_t regularend=clock(); clock_t plainstart=clock(); for (unsigned int i=0;iTransformContinuousIndexToPhysicalPoint(testContIndexes[i%NUMTESTPOINTS],plainPoints[(i*i)%NUMTESTPOINTS]); } clock_t plainend=clock(); (*outfile)<<"TCITPP "; fastregratio=((double)(fastend-faststart))/((double)(regularend-regularstart)); fastplainratio=((double)(fastend-faststart))/((double)(plainend-plainstart)); (*outfile)<<"Fast: "<<((double)(fastend-faststart))/CLOCKS_PER_SEC <<" Orient: "<<((double)(regularend-regularstart))/CLOCKS_PER_SEC <<" ("<TransformIndexToPhysicalPoint(inIndex1,fastPoint); regularImage->TransformIndexToPhysicalPoint(inIndex1,regularPoint); equal=true; for(unsigned int i=0;iTOL) equal=false; if(!equal) { (*outfile)<<"TCITPP inside Failed test"<GetOrigin()<<" "<GetOrigin()<GetSpacing()<<" "<GetSpacing()<GetDirection()<GetDirection()<TransformIndexToPhysicalPoint(inIndex2,fastPoint); regularImage->TransformIndexToPhysicalPoint(inIndex2,regularPoint); equal=true; for(unsigned int i=0;iTOL) equal=false; if(!equal) { (*outfile)<<"TITPP outside Failed test"<GetOrigin()<<" "<GetOrigin()<GetSpacing()<<" "<GetSpacing()<GetDirection()<GetDirection()<TransformIndexToPhysicalPoint(testIndexes[i%NUMTESTPOINTS],fastPoints[(i*i)%NUMTESTPOINTS]); } fastend=clock(); regularstart=clock(); for (unsigned int i=0;iTransformIndexToPhysicalPoint(testIndexes[i%NUMTESTPOINTS],regularPoints[(i*i)%NUMTESTPOINTS]); } regularend=clock(); plainstart=clock(); for (unsigned int i=0;iTransformIndexToPhysicalPoint(testIndexes[i%NUMTESTPOINTS],plainPoints[(i*i)%NUMTESTPOINTS]); } plainend=clock(); //std::cout<<"Regular Start: "<TransformPhysicalPointToIndex(inPoint1,fastIndex); regularResult=regularImage->TransformPhysicalPointToIndex(inPoint1,regularIndex); equal=true; for(unsigned int i=0;iGetOrigin()<<" "<GetOrigin()<GetSpacing()<<" "<GetSpacing()<GetDirection()<GetDirection()<TransformPhysicalPointToIndex(inPoint2,fastIndex); regularResult=regularImage->TransformPhysicalPointToIndex(inPoint2,regularIndex); equal=true; for(unsigned int i=0;iGetOrigin()<<" "<GetOrigin()<GetSpacing()<<" "<GetSpacing()<GetDirection()<GetDirection()<TransformPhysicalPointToIndex(testPoints[i%NUMTESTPOINTS],fastIndexes[(i*i)%NUMTESTPOINTS]); } fastend=clock(); regularstart=clock(); for (unsigned int i=0;iTransformPhysicalPointToIndex(testPoints[i%NUMTESTPOINTS],regularIndexes[(i*i)%NUMTESTPOINTS]); } regularend=clock(); plainstart=clock(); for (unsigned int i=0;iTransformPhysicalPointToIndex(testPoints[i%NUMTESTPOINTS],plainIndexes[(i*i)%NUMTESTPOINTS]); } plainend=clock(); (*outfile)<<"TPPTI "; fastregratio=((double)(fastend-faststart))/((double)(regularend-regularstart)); fastplainratio=((double)(fastend-faststart))/((double)(plainend-plainstart)); (*outfile)<<"Fast: "<<((double)(fastend-faststart))/CLOCKS_PER_SEC <<" Orient: "<<((double)(regularend-regularstart))/CLOCKS_PER_SEC <<" ("<TransformPhysicalPointToContinuousIndex(inPoint1,fastContIndex); regularResult=regularImage->TransformPhysicalPointToContinuousIndex(inPoint1,regularContIndex); equal=true; for(unsigned int i=0;iTOL) equal=false; if(!equal ||(fastResult!=regularResult)) { (*outfile)<<"TPPTCI inside Failed test"<GetOrigin()<<" "<GetOrigin()<GetSpacing()<<" "<GetSpacing()<GetDirection()<GetDirection()<TransformPhysicalPointToContinuousIndex(inPoint2,fastContIndex); regularResult=regularImage->TransformPhysicalPointToContinuousIndex(inPoint2,regularContIndex); equal=true; for(unsigned int i=0;iTOL) equal=false; if(!equal ||(fastResult!=regularResult)) { (*outfile)<<"TPPTCI outside Failed test"<GetOrigin()<<" "<GetOrigin()<GetSpacing()<<" "<GetSpacing()<GetDirection()<GetDirection()<TransformPhysicalPointToContinuousIndex(testPoints[i%NUMTESTPOINTS],fastContIndexes[(i*i)%NUMTESTPOINTS]); } fastend=clock(); regularstart=clock(); for (unsigned int i=0;iTransformPhysicalPointToContinuousIndex(testPoints[i%NUMTESTPOINTS],regularContIndexes[(i*i)%NUMTESTPOINTS]); } regularend=clock(); plainstart=clock(); for (unsigned int i=0;iTransformPhysicalPointToContinuousIndex(testPoints[i%NUMTESTPOINTS],plainContIndexes[(i*i)%NUMTESTPOINTS]); } plainend=clock(); (*outfile)<<"TPPTCI "; fastregratio=((double)(fastend-faststart))/((double)(regularend-regularstart)); fastplainratio=((double)(fastend-faststart))/((double)(plainend-plainstart)); (*outfile)<<"Fast: "<<((double)(fastend-faststart))/CLOCKS_PER_SEC <<" Orient: "<<((double)(regularend-regularstart))/CLOCKS_PER_SEC <<" ("< FastImageType; typedef itk::OrientedImage RegularImageType; typedef itk::Image PlainImageType; typedef RegularImageType::RegionType RegionType; // first declare identical images of each type. FastImageType::Pointer fastImage=FastImageType::New(); RegularImageType::Pointer regularImage=RegularImageType::New(); PlainImageType::Pointer plainImage=PlainImageType::New(); RegionType region; RegionType::SizeType size; RegionType::IndexType index; region.SetSize(size); region.SetIndex(index); index.Fill(0); for (unsigned int i=0;iSetRegions(region); regularImage->SetRegions(region); plainImage->SetRegions(region); #if ALLCOMBINATIONS (*outfile)<<"Nothing has been set yet"<(fastImage,regularImage,plainImage,any); #endif RegularImageType::PointType fastPoint,regularPoint,origin; RegularImageType::SpacingType spacing; RegularImageType::DirectionType direction; //RegularImageType::IndexType inIndex1,fastIndex,regularIndex; // first set the origin, direction and spacing to zero/unity origin.Fill(0.0); spacing.Fill(1.0); direction.SetIdentity(); (*outfile)<<" ============================================="<SetOrigin(origin); fastImage->SetSpacing(spacing); fastImage->SetDirection(direction); regularImage->SetOrigin(origin); regularImage->SetSpacing(spacing); regularImage->SetDirection(direction); plainImage->SetOrigin(origin); plainImage->SetSpacing(spacing); plainImage->SetDirection(direction); (*outfile)<<"Unit/Zero Everything"<(fastImage,regularImage,plainImage,any); (*outfile)<<" ============================================="<SetSpacing(spacing); regularImage->SetSpacing(spacing); plainImage->SetSpacing(spacing); #if ALLCOMBINATIONS (*outfile)<<"NonUnitSpacing"<(fastImage,regularImage,plainImage,any); #endif (*outfile)<<" ============================================="<SetOrigin(origin); regularImage->SetOrigin(origin); plainImage->SetOrigin(origin); (*outfile)<<"NonUnitSpacingNonZeroOrigin"<(fastImage,regularImage,plainImage,any); (*outfile)<<" ============================================="<SetSpacing(spacing); regularImage->SetSpacing(spacing); plainImage->SetSpacing(spacing); #if ALLCOMBINATIONS (*outfile)<<"NonZeroOrigin"<(fastImage,regularImage,plainImage,any); #endif (*outfile)<<" ============================================="<SetDirection(direction); regularImage->SetDirection(direction); plainImage->SetDirection(direction); #if ALLCOMBINATIONS (*outfile)<<"NonDiagonalDirectionNonZeroOrigin"<(fastImage,regularImage,plainImage,any); #endif (*outfile)<<" ============================================="<SetOrigin(origin); regularImage->SetOrigin(origin); plainImage->SetOrigin(origin); #if ALLCOMBINATIONS (*outfile)<<"NonDiagDirection"<(fastImage,regularImage,plainImage,any); #endif (*outfile)<<" ============================================="<SetSpacing(spacing); regularImage->SetSpacing(spacing); plainImage->SetSpacing(spacing); #if ALLCOMBINATIONS (*outfile)<<"NonDiagDirectionNonunitspacing"<(fastImage,regularImage,plainImage,any); #endif (*outfile)<<" ============================================="<SetOrigin(origin); regularImage->SetOrigin(origin); plainImage->SetOrigin(origin); (*outfile)<<"NonDiagDirectionNonUnitSpacingNonZeroOrigin"<(fastImage,regularImage,plainImage,any); } #endif #if TEST3D { const unsigned int Dimension=3;//dim; (*outfile)<<"************** TESTING DIMENSION "< FastImageType; typedef itk::OrientedImage RegularImageType; typedef itk::Image PlainImageType; typedef RegularImageType::RegionType RegionType; // first declare identical images of each type. FastImageType::Pointer fastImage=FastImageType::New(); RegularImageType::Pointer regularImage=RegularImageType::New(); PlainImageType::Pointer plainImage=PlainImageType::New(); RegionType region; RegionType::SizeType size; RegionType::IndexType index; region.SetSize(size); region.SetIndex(index); index.Fill(0); for (unsigned int i=0;iSetRegions(region); regularImage->SetRegions(region); plainImage->SetRegions(region); #if ALLCOMBINATIONS (*outfile)<<"Nothing has been set yet"<(fastImage,regularImage,plainImage,any); #endif RegularImageType::PointType fastPoint,regularPoint,origin; RegularImageType::SpacingType spacing; RegularImageType::DirectionType direction; //RegularImageType::IndexType inIndex1,fastIndex,regularIndex; // first set the origin, direction and spacing to zero/unity origin.Fill(0.0); spacing.Fill(1.0); direction.SetIdentity(); (*outfile)<<" ============================================="<SetOrigin(origin); fastImage->SetSpacing(spacing); fastImage->SetDirection(direction); regularImage->SetOrigin(origin); regularImage->SetSpacing(spacing); regularImage->SetDirection(direction); plainImage->SetOrigin(origin); plainImage->SetSpacing(spacing); plainImage->SetDirection(direction); (*outfile)<<"Unit/Zero Everything"<(fastImage,regularImage,plainImage,any); (*outfile)<<" ============================================="<SetSpacing(spacing); regularImage->SetSpacing(spacing); plainImage->SetSpacing(spacing); #if ALLCOMBINATIONS (*outfile)<<"NonUnitSpacing"<(fastImage,regularImage,plainImage,any); #endif (*outfile)<<" ============================================="<SetOrigin(origin); regularImage->SetOrigin(origin); plainImage->SetOrigin(origin); (*outfile)<<"NonUnitSpacingNonZeroOrigin"<(fastImage,regularImage,plainImage,any); (*outfile)<<" ============================================="<SetSpacing(spacing); regularImage->SetSpacing(spacing); plainImage->SetSpacing(spacing); #if ALLCOMBINATIONS (*outfile)<<"NonZeroOrigin"<(fastImage,regularImage,plainImage,any); #endif (*outfile)<<" ============================================="<SetDirection(direction); regularImage->SetDirection(direction); plainImage->SetDirection(direction); #if ALLCOMBINATIONS (*outfile)<<"NonDiagonalDirectionNonZeroOrigin"<(fastImage,regularImage,plainImage,any); #endif (*outfile)<<" ============================================="<SetOrigin(origin); regularImage->SetOrigin(origin); plainImage->SetOrigin(origin); #if ALLCOMBINATIONS (*outfile)<<"NonDiagDirection"<(fastImage,regularImage,plainImage,any); #endif (*outfile)<<" ============================================="<SetSpacing(spacing); regularImage->SetSpacing(spacing); plainImage->SetSpacing(spacing); #if ALLCOMBINATIONS (*outfile)<<"NonDiagDirectionNonunitspacing"<(fastImage,regularImage,plainImage,any); #endif (*outfile)<<" ============================================="<SetOrigin(origin); regularImage->SetOrigin(origin); plainImage->SetOrigin(origin); (*outfile)<<"NonDiagDirectionNonUnitSpacingNonZeroOrigin"<(fastImage,regularImage,plainImage,any); } #endif #if TEST4D { const unsigned int Dimension=4;//dim; (*outfile)<<"************** TESTING DIMENSION "< FastImageType; typedef itk::OrientedImage RegularImageType; typedef itk::Image PlainImageType; typedef RegularImageType::RegionType RegionType; // first declare identical images of each type. FastImageType::Pointer fastImage=FastImageType::New(); RegularImageType::Pointer regularImage=RegularImageType::New(); PlainImageType::Pointer plainImage=PlainImageType::New(); RegionType region; RegionType::SizeType size; RegionType::IndexType index; region.SetSize(size); region.SetIndex(index); index.Fill(0); for (unsigned int i=0;iSetRegions(region); regularImage->SetRegions(region); plainImage->SetRegions(region); #if ALLCOMBINATIONS (*outfile)<<"Nothing has been set yet"<(fastImage,regularImage,plainImage,any); #endif RegularImageType::PointType fastPoint,regularPoint,origin; RegularImageType::SpacingType spacing; RegularImageType::DirectionType direction; //RegularImageType::IndexType inIndex1,fastIndex,regularIndex; // first set the origin, direction and spacing to zero/unity origin.Fill(0.0); spacing.Fill(1.0); direction.SetIdentity(); (*outfile)<<" ============================================="<SetOrigin(origin); fastImage->SetSpacing(spacing); fastImage->SetDirection(direction); regularImage->SetOrigin(origin); regularImage->SetSpacing(spacing); regularImage->SetDirection(direction); plainImage->SetOrigin(origin); plainImage->SetSpacing(spacing); plainImage->SetDirection(direction); (*outfile)<<"Unit/Zero Everything"<(fastImage,regularImage,plainImage,any); (*outfile)<<" ============================================="<SetSpacing(spacing); regularImage->SetSpacing(spacing); plainImage->SetSpacing(spacing); #if ALLCOMBINATIONS (*outfile)<<"NonUnitSpacing"<(fastImage,regularImage,plainImage,any); #endif (*outfile)<<" ============================================="<SetOrigin(origin); regularImage->SetOrigin(origin); plainImage->SetOrigin(origin); (*outfile)<<"NonUnitSpacingNonZeroOrigin"<(fastImage,regularImage,plainImage,any); (*outfile)<<" ============================================="<SetSpacing(spacing); regularImage->SetSpacing(spacing); plainImage->SetSpacing(spacing); #if ALLCOMBINATIONS (*outfile)<<"NonZeroOrigin"<(fastImage,regularImage,plainImage,any); #endif (*outfile)<<" ============================================="<SetDirection(direction); regularImage->SetDirection(direction); plainImage->SetDirection(direction); #if ALLCOMBINATIONS (*outfile)<<"NonDiagonalDirectionNonZeroOrigin"<(fastImage,regularImage,plainImage,any); #endif (*outfile)<<" ============================================="<SetOrigin(origin); regularImage->SetOrigin(origin); plainImage->SetOrigin(origin); #if ALLCOMBINATIONS (*outfile)<<"NonDiagDirection"<(fastImage,regularImage,plainImage,any); #endif (*outfile)<<" ============================================="<SetSpacing(spacing); regularImage->SetSpacing(spacing); plainImage->SetSpacing(spacing); #if ALLCOMBINATIONS (*outfile)<<"NonDiagDirectionNonunitspacing"<(fastImage,regularImage,plainImage,any); #endif (*outfile)<<" ============================================="<SetOrigin(origin); regularImage->SetOrigin(origin); plainImage->SetOrigin(origin); (*outfile)<<"NonDiagDirectionNonUnitSpacingNonZeroOrigin"<(fastImage,regularImage,plainImage,any); } #endif (*outfile)<