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
|
#include "SimpleITKTestHarness.h"
#include "sitkProcessObject.h"
#include <itksys/SystemTools.hxx>
#include <itksys/Process.h>
DataFinder::DataFinder() :
mDirectory(TEST_HARNESS_DATA_DIRECTORY),
mOutputDirectory(TEST_HARNESS_TEMP_DIRECTORY)
{
}
void DataFinder::SetDirectory ( const char* dir )
{
mDirectory = dir;
}
void DataFinder::SetDirectory ( std::string dir )
{
mDirectory = dir;
}
void DataFinder::SetOutputDirectory ( std::string dir )
{
mOutputDirectory = dir;
}
std::string DataFinder::GetDirectory () const
{
return mDirectory;
}
std::string DataFinder::GetOutputDirectory () const
{
return mOutputDirectory;
}
std::string DataFinder::GetOutputFile ( std::string filename ) const
{
return mOutputDirectory + "/" + filename;
}
std::string DataFinder::GetBuildDirectory () const
{
return std::string ( SIMPLEITK_BINARY_DIR );
}
std::string DataFinder::GetPathSeparator () const
{
#ifdef WIN32
return ";";
#else
return ":";
#endif
}
bool DataFinder::FileExists ( const std::string &filename ) const
{
return itksys::SystemTools::FileExists ( filename.c_str() );
}
std::string DataFinder::GetFile ( const std::string &filename ) const
{
std::string name;
name = mDirectory + "/" + filename;
if (this->FileExists(name))
return name;
// fall back to source code path
name = std::string(SIMPLEITK_SOURCE_DIR) + "/Testing/Data/" + filename;
return name;
}
//
//
//
ProcessObjectCommand::ProcessObjectCommand(itk::simple::ProcessObject &po)
: m_Process(po)
{
}
ProgressUpdate::ProgressUpdate(itk::simple::ProcessObject &po)
: ProcessObjectCommand(po),
m_Progress(0.0)
{
}
void ProgressUpdate::Execute( )
{
std::cout << "Progress: " << m_Process.GetProgress() << std::endl;
m_Progress = m_Process.GetProgress();
}
AbortAtCommand::AbortAtCommand(itk::simple::ProcessObject &po, float abortAt)
: ProcessObjectCommand(po),
m_AbortAt(abortAt)
{
}
void AbortAtCommand::Execute( )
{
std::cout << "p: " << m_Process.GetProgress() << std::endl;
if ( m_Process.GetProgress() >= m_AbortAt )
{
std::cout << "aborting..." << std::endl;
m_Process.Abort();
}
}
CountCommand::CountCommand(itk::simple::ProcessObject &po)
: ProcessObjectCommand(po),
m_Count(0)
{
}
void CountCommand::Execute( )
{
++m_Count;
}
::testing::AssertionResult VectorDoubleRMSPredFormat(const char* expr1,
const char* expr2,
const char* rms_error_expr,
const std::vector<double> &val1,
const std::vector<double> &val2,
double rms_error) {
if (val1.size() != val2.size())
{
return testing::AssertionFailure()
<< "The size of " << expr1 << " and " << expr2
<< " different, where\n"
<< expr1 << " evaluates to " << val1 << ",\n"
<< expr2 << " evaluates to " << val2 << ".";
}
double total = 0.0;
for ( unsigned int i = 0; i < val1.size(); ++i )
{
double temp = (val1[i]-val2[i]);
total += temp*temp;
}
const double rms = sqrt(total);
if (rms <= rms_error) return ::testing::AssertionSuccess();
return ::testing::AssertionFailure()
<< "The RMS difference between " << expr1 << " and " << expr2
<< " is " << rms << ",\n which exceeds " << rms_error_expr << ", where\n"
<< expr1 << " evaluates to " << val1 << ",\n"
<< expr2 << " evaluates to " << val2 << ", and\n"
<< rms_error_expr << " evaluates to " << rms_error << ".";
}
|