1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkTimeProbesTest.cxx,v $
Language: C++
Date: $Date: 2006-04-21 20:21:39 $
Version: $Revision: 1.9 $
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 "itkTimeProbesCollectorBase.h"
#include "itkImage.h"
#include "itkOrientedImage.h"
#include "itkPoint.h"
#include "itkImageRegion.h"
#include "itkIndex.h"
#include "itkSize.h"
#include <iostream>
#include <fstream>
template <class T>
void TestTransformIndexToPhysicalPoint(T * image)
{
typename T::IndexType index3D;
typename T::PointType point3D;
for (int k = 0; k < 10; k++)
{
index3D[2] = k;
for (int j = 0; j < 1000; j++)
{
index3D[1] = j;
for (int i = 0; i < 1000; i++)
{
index3D[0] = i;
image->TransformIndexToPhysicalPoint(index3D, point3D);
}
}
if (k == 5) std::cout << point3D << std::endl;
}
}
template <class T>
void TestTransformPhysicalPointToIndex(T * image)
{
typename T::IndexType index3D;
typename T::PointType point3D;
for (double k = 0; k < 10; k++)
{
point3D[2] = k;
for (double j = 0; j < 1000; j++)
{
point3D[1] = j;
for (double i = 0; i < 1000; i++)
{
point3D[0] = i;
image->TransformPhysicalPointToIndex(point3D, index3D);
}
}
if (k == 5) std::cout << point3D << std::endl;
}
}
//-------------------------
//
// This file test the interface to the TimeProbe classes
//
//-------------------------
int itkTimeProbesTest(int, char* [] )
{
itk::TimeProbesCollectorBase collector;
const unsigned int N = 1000L;
const unsigned int M = 10000L;
collector.Start("Loop1"); // label that identify the range of the probe
// Do slow stuff here...
{
for(unsigned int i=0; i<N; i++)
{
char * dummy = new char [ M ];
for(unsigned int j=0; j<M; j++)
{
dummy[j] = j;
}
delete [] dummy;
}
}
collector.Stop("Loop1");
collector.Start("Loop2"); // label that identify the range of the probe
// Do other slow stuff here...
{
for(unsigned int i=0; i<M; i++)
{
char * dummy = new char [ N ];
for(unsigned int j=0; j<N; j++)
{
dummy[j] = j;
}
delete [] dummy;
}
}
collector.Stop("Loop2");
typedef itk::Image<float,3> Image3DType;
typedef itk::OrientedImage<float,3> OrientedImage3DType;
Image3DType::Pointer image3D = Image3DType::New();
OrientedImage3DType::Pointer orientedImage3D = OrientedImage3DType::New();
Image3DType::PointType point3D;
typedef itk::ImageRegion< 3 > Region3DType;
typedef Region3DType::IndexType Index3DType;
typedef Region3DType::SizeType Size3DType;
Region3DType region3D;
Size3DType size3D = {{ 1000, 1000, 1000 }};
region3D.SetSize( size3D );
collector.Start("i->TransformIndexToPhysicalPoint");
TestTransformIndexToPhysicalPoint<Image3DType> (image3D);
collector.Stop("i->TransformIndexToPhysicalPoint");
collector.Start("i->TransformPhysicalPointToIndex");
TestTransformPhysicalPointToIndex<Image3DType> (image3D);
collector.Stop("i->TransformPhysicalPointToIndex");
collector.Start("o->TransformIndexToPhysicalPoint");
TestTransformIndexToPhysicalPoint<OrientedImage3DType> (orientedImage3D);
collector.Stop("o->TransformIndexToPhysicalPoint");
collector.Start("o->TransformPhysicalPointToIndex");
TestTransformPhysicalPointToIndex<OrientedImage3DType> (orientedImage3D);
collector.Stop("o->TransformPhysicalPointToIndex");
// Print the results of the time probes
collector.Report();
// Test writing to a ostream
std::ofstream logfile;
logfile.open("itkTimeProbesTest.txt");
collector.Report( logfile );
logfile.close();
// Print to the standar error
collector.Report( std::cerr );
return EXIT_SUCCESS;
}
|