📄 itkcontourextractor2dimagefiltertest.cxx
字号:
top_right(_top_right, _top_right + 2);
itkContourExtractor2DImageFilterTestNamespace::MyVertexType _rev_top_right[] =
{itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11.5, 0),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(12, 0.5)};
itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
rev_top_right(_rev_top_right, _rev_top_right + 2);
itkContourExtractor2DImageFilterTestNamespace::MyVertexType _top_left[] =
{itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1.5, 0),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1, 0.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0.5, 1),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0, 1.5)};
itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
top_left(_top_left, _top_left + 4);
itkContourExtractor2DImageFilterTestNamespace::MyVertexType _rev_top_left[] =
{itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0, 1.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0.5, 1),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1, 0.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1.5, 0)};
itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
rev_top_left(_rev_top_left, _rev_top_left + 4);
itkContourExtractor2DImageFilterTestNamespace::MyVertexType
_top_left_cropped[] =
{itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0.5, 1),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0, 1.5)};
itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
top_left_cropped(_top_left_cropped, _top_left_cropped + 2);
itkContourExtractor2DImageFilterTestNamespace::MyVertexType
_rev_top_left_cropped[] =
{itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0, 1.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0.5, 1)};
itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
rev_top_left_cropped(_rev_top_left_cropped, _rev_top_left_cropped + 2);
itkContourExtractor2DImageFilterTestNamespace::MyVertexType _row1_col4_all[] =
{itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 3.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9.5, 3),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9, 2.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(8.5, 2),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9, 1.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9.5, 2),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 2.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10.5, 2),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 1.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11.5, 2),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 2.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10.5, 3),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 3.5)};
itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
row1_col4_all(_row1_col4_all, _row1_col4_all + 13);
itkContourExtractor2DImageFilterTestNamespace::MyVertexType
_rev_row1_col4_all[] =
{itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 3.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10.5, 3),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 2.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11.5, 2),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 1.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10.5, 2),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 2.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9.5, 2),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9, 1.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(8.5, 2),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9, 2.5),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9.5, 3),
itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 3.5)};
itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
rev_row1_col4_all(_rev_row1_col4_all, _rev_row1_col4_all + 13);
itkContourExtractor2DImageFilterTestNamespace::MyVertexListType _edco[] =
{top_left, top_right, row1_col3, row1_col4_left,
row1_col4_right, row1_col1, row1_col2, row1_col4_middle, row2_col1,
row2_col2, row2_col3, row2_col4, bottom_left, bottom_right};
itkContourExtractor2DImageFilterTestNamespace::MyVertexListList
expected_disconnected_clockwise_outputs(_edco, _edco + 14);
itkContourExtractor2DImageFilterTestNamespace::MyVertexListType _edcco[] =
{rev_top_left, rev_top_right, rev_row1_col3,
rev_row1_col4_left, rev_row1_col4_right, rev_row1_col1, rev_row1_col2,
rev_row1_col4_middle, rev_row2_col1, rev_row2_col2, rev_row2_col3,
rev_row2_col4, rev_bottom_left, rev_bottom_right};
itkContourExtractor2DImageFilterTestNamespace::MyVertexListList
expected_disconnected_counterclockwise_outputs(_edcco, _edcco + 14);
itkContourExtractor2DImageFilterTestNamespace::MyVertexListType _ecco[] =
{top_left, top_right, row1_col3, row1_col4_all,
row1_col1, row1_col2, row2_col1, row2_col2, row2_col3, row2_col4,
bottom_left, bottom_right};
itkContourExtractor2DImageFilterTestNamespace::MyVertexListList
expected_connected_clockwise_outputs(_ecco, _ecco + 12);
itkContourExtractor2DImageFilterTestNamespace::MyVertexListType _edcro[] =
{top_left_cropped, row1_col3, row1_col4_left,
row1_col4_right, row1_col1, row1_col2, row1_col4_middle, row2_col1,
row2_col2, row2_col3, row2_col4};
itkContourExtractor2DImageFilterTestNamespace::MyVertexListList
expected_disconnected_clockwise_cropped_outputs(_edcro, _edcro + 11);
/*--------------------------------------------------------------------------*/
bool HasCorrectOutput(
itkContourExtractor2DImageFilterTestNamespace::ExtractorType::Pointer
extractor,
itkContourExtractor2DImageFilterTestNamespace::MyVertexListList& correct)
{
if (extractor->GetNumberOfOutputs() != correct.size())
{
return false;
}
for(unsigned int i = 0; i < correct.size(); i++)
{
itkContourExtractor2DImageFilterTestNamespace::ExtractorType::
VertexListConstPointer
vertices = extractor->GetOutput(i)->GetVertexList();
itkContourExtractor2DImageFilterTestNamespace::MyVertexListType&
correctVertices = correct[i];
if (vertices->Size() != correctVertices.size())
{
return false;
}
for(unsigned int j = 0; j < correctVertices.size(); j++)
{
const itkContourExtractor2DImageFilterTestNamespace::MyVertexType&
correctVertex = correctVertices[j];
const itkContourExtractor2DImageFilterTestNamespace::VertexType&
vertex = vertices->ElementAt(j);
if (fabs(correctVertex.first - vertex[0]) >
itkContourExtractor2DImageFilterTestNamespace::FLOAT_EPSILON ||
fabs(correctVertex.second - vertex[1]) >
itkContourExtractor2DImageFilterTestNamespace::FLOAT_EPSILON)
{
return false;
}
}
}
return true;
}
int itkContourExtractor2DImageFilterTest(int argc, char *argv[])
{
if( argc < 2 )
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " Input Test Image " << std::endl;
return 1;
}
itkContourExtractor2DImageFilterTestNamespace::ReaderType::Pointer
reader = itkContourExtractor2DImageFilterTestNamespace::ReaderType::New();
reader->SetFileName(argv[1]);
itkContourExtractor2DImageFilterTestNamespace::ExtractorType::Pointer
extractor =
itkContourExtractor2DImageFilterTestNamespace::ExtractorType::New();
extractor->SetInput(reader->GetOutput());
// exercise Set/Get ContourValue methods
extractor->SetContourValue( 255.0 );
if( extractor->GetContourValue() != 255.0 )
{
std::cerr << " Contour Value Set/Get problem" << std::endl;
return EXIT_FAILURE;
}
extractor->SetContourValue(127.5);
// exercise Set/Get methods of VertexConnectHighPixels
extractor->VertexConnectHighPixelsOn();
if( extractor->GetVertexConnectHighPixels() != true )
{
std::cerr << "VertexConnectHighPixels Set/Get Problem" << std::endl;
return EXIT_FAILURE;
}
// exercise Set/Get methods of ReverseContourOrientation
extractor->ReverseContourOrientationOn();
if( extractor->GetReverseContourOrientation() != true )
{
std::cerr << "ReverseContourOrientation Set/Get Problem" << std::endl;
return EXIT_FAILURE;
}
bool testsPassed = true;
try
{
extractor->VertexConnectHighPixelsOff();
extractor->ReverseContourOrientationOff();
extractor->Update();
std::cout << "Test 1... ";
if (!HasCorrectOutput(extractor, expected_disconnected_clockwise_outputs))
{
testsPassed = false;
std::cout << "failed." << std::endl;
}
else std::cout << "passed." << std::endl;
extractor->VertexConnectHighPixelsOff();
extractor->ReverseContourOrientationOn();
extractor->Update();
std::cout << "Test 2... ";
if (!HasCorrectOutput(extractor,
expected_disconnected_counterclockwise_outputs))
{
testsPassed = false;
std::cout << "failed." << std::endl;
}
else
{
std::cout << "passed." << std::endl;
}
extractor->VertexConnectHighPixelsOn();
extractor->ReverseContourOrientationOff();
extractor->Update();
std::cout << "Test 3... ";
if (!HasCorrectOutput(extractor, expected_connected_clockwise_outputs))
{
testsPassed = false;
std::cout << "failed." << std::endl;
}
else
{
std::cout << "passed." << std::endl;
}
extractor->VertexConnectHighPixelsOff();
extractor->ReverseContourOrientationOff();
// Move the region to evaluate in by one on the top and bottom
itkContourExtractor2DImageFilterTestNamespace::ImageType::RegionType
region = reader->GetOutput()->GetLargestPossibleRegion();
itkContourExtractor2DImageFilterTestNamespace::ImageType::IndexType
index = region.GetIndex();
itkContourExtractor2DImageFilterTestNamespace::ImageType::SizeType
size = region.GetSize();
index[1] += 1;
size[1] -= 2;
extractor->SetRequestedRegion(
itkContourExtractor2DImageFilterTestNamespace::ImageType::RegionType(
index, size));
// exercise Set/Get RequestRegion
if ( extractor->GetRequestedRegion() !=
itkContourExtractor2DImageFilterTestNamespace::ImageType::RegionType(
index, size) )
{
std::cerr << "RequestedRegion Set/Get Problem" << std::endl;
return EXIT_FAILURE;
}
extractor->Update();
std::cout << "Test 4... ";
if (!HasCorrectOutput(extractor,
expected_disconnected_clockwise_cropped_outputs))
{
testsPassed = false;
std::cerr << "failed." << std::endl;
}
else
{
std::cout << "passed." << std::endl;
}
}
catch( itk::ExceptionObject & err )
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return -1;
}
if (testsPassed)
{
std::cout << "All tests passed." << std::endl;
return 0;
}
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -