diff --git a/Modules/DiffusionImaging/Connectomics/Testing/mitkConnectomicsNetworkTest.cpp b/Modules/DiffusionImaging/Connectomics/Testing/mitkConnectomicsNetworkTest.cpp index 997cf10831..7aaa3eb247 100644 --- a/Modules/DiffusionImaging/Connectomics/Testing/mitkConnectomicsNetworkTest.cpp +++ b/Modules/DiffusionImaging/Connectomics/Testing/mitkConnectomicsNetworkTest.cpp @@ -1,526 +1,526 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkTestingMacros.h" -#include +#include #include "mitkConnectomicsNetwork.h" #include "mitkConnectomicsSyntheticNetworkGenerator.h" #include "mitkConnectomicsSimulatedAnnealingManager.h" #include "mitkConnectomicsSimulatedAnnealingPermutationModularity.h" #include "mitkConnectomicsSimulatedAnnealingCostFunctionModularity.h" #include #include #include /**Documentation * Test for synthetic connectomics generation and connectomics network functionality */ int mitkConnectomicsNetworkTest(int argc, char* argv[]) { // Test begins MITK_TEST_BEGIN("mitkConnectomicsNetworkTest"); // Typedefs typedef mitk::ConnectomicsNetwork::VertexDescriptorType VertexType; typedef mitk::ConnectomicsNetwork::EdgeDescriptorType EdgeType; typedef mitk::ConnectomicsNetwork::NetworkNode NodeType; // The test network std::vector< NodeType > inNodes; NodeType node; node.id = 0; node.label = "1-1"; node.coordinates.clear(); node.coordinates.push_back( 0 ); node.coordinates.push_back( 0 ); node.coordinates.push_back( 0 ); inNodes.push_back(node); node.id = 1; node.label = "2-1"; node.coordinates.clear(); node.coordinates.push_back( 10 ); node.coordinates.push_back( 0 ); node.coordinates.push_back( 0 ); inNodes.push_back(node); node.id = 2; node.label = "3-1"; node.coordinates.clear(); node.coordinates.push_back( 20 ); node.coordinates.push_back( 10 ); node.coordinates.push_back( 0 ); inNodes.push_back(node); node.id = 3; node.label = "4-1"; node.coordinates.clear(); node.coordinates.push_back( 30 ); node.coordinates.push_back( 20 ); node.coordinates.push_back( 0 ); inNodes.push_back(node); node.id = 4; node.label = "5-1"; node.coordinates.clear(); node.coordinates.push_back( 40 ); node.coordinates.push_back( 50 ); node.coordinates.push_back( 0 ); inNodes.push_back(node); node.id = 5; node.label = "6-2"; node.coordinates.clear(); node.coordinates.push_back( 0 ); node.coordinates.push_back( 0 ); node.coordinates.push_back( 10 ); inNodes.push_back(node); node.id = 6; node.label = "7-2"; node.coordinates.clear(); node.coordinates.push_back( 0 ); node.coordinates.push_back( 10 ); node.coordinates.push_back( 20 ); inNodes.push_back(node); node.id = 7; node.label = "8-2"; node.coordinates.clear(); node.coordinates.push_back( 0 ); node.coordinates.push_back( 20 ); node.coordinates.push_back( 30 ); inNodes.push_back(node); node.id = 8; node.label = "9-2"; node.coordinates.clear(); node.coordinates.push_back( 0 ); node.coordinates.push_back( 30 ); node.coordinates.push_back( 40 ); inNodes.push_back(node); node.id = 9; node.label = "10-3"; node.coordinates.clear(); node.coordinates.push_back( 20 ); node.coordinates.push_back( 0 ); node.coordinates.push_back( 10 ); inNodes.push_back(node); node.id = 10; node.label = "11-3"; node.coordinates.clear(); node.coordinates.push_back( 30 ); node.coordinates.push_back( 0 ); node.coordinates.push_back( 20 ); inNodes.push_back(node); node.id = 11; node.label = "12-3"; node.coordinates.clear(); node.coordinates.push_back( 40 ); node.coordinates.push_back( 0 ); node.coordinates.push_back( 30 ); inNodes.push_back(node); std::vector< mitk::ConnectomicsNetwork::NetworkEdge > inEdges; mitk::ConnectomicsNetwork::NetworkEdge edge; edge.sourceId = 0; edge.targetId = 1; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 0; edge.targetId = 2; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 0; edge.targetId = 4; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 1; edge.targetId = 4; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 1; edge.targetId = 3; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 2; edge.targetId = 3; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 3; edge.targetId = 4; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 4; edge.targetId = 5; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 5; edge.targetId = 6; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 5; edge.targetId = 7; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 5; edge.targetId = 8; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 7; edge.targetId = 8; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 6; edge.targetId = 8; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 6; edge.targetId = 9; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 3; edge.targetId = 10; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 9; edge.targetId = 10; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 10; edge.targetId = 11; edge.weight = 2; inEdges.push_back( edge ); edge.sourceId = 9; edge.targetId = 11; edge.weight = 2; inEdges.push_back( edge ); // further variables double eps(0.001); try { // Testing synthetic network generation mitk::ConnectomicsSyntheticNetworkGenerator::Pointer generator = mitk::ConnectomicsSyntheticNetworkGenerator::New(); MITK_TEST_CONDITION_REQUIRED(generator.IsNotNull(),"Synthetic network generator has been instantiated") // first and second parameter std::vector< std::pair > parameterVector; // name and isRandom std::vector< std::pair > messageVector; // order of results is # vertices, # edges, # self loops, average degree, connection density // global clustering coefficient std::vector< std::vector< double > > resultVector; int numberOfOptions = 3; parameterVector.resize(numberOfOptions); messageVector.resize(numberOfOptions); resultVector.resize(numberOfOptions); // Create regular lattice network in the form of a cube with sidelength 5 and distance 10 between nodes parameterVector[0] = std::pair< int, double>(5, 10); messageVector[0] = std::pair("Regular Lattice Network", false); resultVector[0].push_back( 5 * 5 * 5 ); resultVector[0].push_back( 300 ); resultVector[0].push_back( 0 ); resultVector[0].push_back( 4.8 ); resultVector[0].push_back(0.0387); resultVector[0].push_back(0); // Create a heterogeneous sphere network with 1 central node and 49 nodes on the surface and radius 10 parameterVector[1] = std::pair< int, double>(50, 10); messageVector[1] = std::pair("Heterogeneous Sphere Network", false); resultVector[1].push_back( 50 ); resultVector[1].push_back( 49 ); resultVector[1].push_back( 0 ); resultVector[1].push_back( 1.96 ); resultVector[1].push_back(0.0400); resultVector[1].push_back(0); // Create random network with 50 nodes and edges between them generated with a 0.1 likelihood parameterVector[2] = std::pair< int, double>(50, 0.1); messageVector[2] = std::pair("Random Network", true); resultVector[2].push_back( 50 ); for(int loop(0); loop < numberOfOptions; loop++) { mitk::ConnectomicsNetwork::Pointer network = generator->CreateSyntheticNetwork(loop, parameterVector[loop].first, parameterVector[loop].second); bool generationWorked = generator->WasGenerationSuccessfull() && network.IsNotNull(); std::string message = messageVector[loop].first + " has been instantiated"; MITK_TEST_CONDITION_REQUIRED(generationWorked,message) bool verticesCloseEnough( std::abs(resultVector[loop][0] - network->GetNumberOfVertices()) < eps); MITK_TEST_CONDITION_REQUIRED( verticesCloseEnough, "Expected number of vertices") if(!messageVector[loop].second) { bool edgesCloseEnough( std::abs(resultVector[loop][1] - network->GetNumberOfEdges()) < eps); MITK_TEST_CONDITION_REQUIRED( edgesCloseEnough, "Expected number of edges") bool selfLoopsCloseEnough( std::abs(resultVector[loop][2] - network->GetNumberOfSelfLoops()) < eps); MITK_TEST_CONDITION_REQUIRED( selfLoopsCloseEnough, "Expected number of self loops") bool avDegCloseEnough( std::abs(resultVector[loop][3] - network->GetAverageDegree()) < eps); MITK_TEST_CONDITION_REQUIRED( avDegCloseEnough, "Expected average degree") bool conDensCloseEnough( std::abs(resultVector[loop][4] - network->GetConnectionDensity()) < eps); MITK_TEST_CONDITION_REQUIRED( conDensCloseEnough, "Expected connection density") bool clustCoeffCloseEnough( std::abs(resultVector[loop][5] - network->GetGlobalClusteringCoefficient()) < eps); MITK_TEST_CONDITION_REQUIRED( clustCoeffCloseEnough, "Expected global clustering coefficient") } } } catch (...) { MITK_ERROR << "Unhandled exception caught while testing synthetic network generation [FAILED]" ; return EXIT_FAILURE; } try { // Testing network interface // Create network mitk::ConnectomicsNetwork::Pointer network = mitk::ConnectomicsNetwork::New(); std::vector< VertexType > vertexVector; vertexVector.resize( inNodes.size() ); for(int loop(0); loop < inNodes.size(); loop++) { VertexType newVertex = network->AddVertex( inNodes[loop].id ); vertexVector[ inNodes[loop].id ] = newVertex; network->SetLabel( newVertex, inNodes[loop].label ); network->SetCoordinates( newVertex, inNodes[loop].coordinates ); } for(int loop(0); loop < inEdges.size(); loop++) { int sourceId = inEdges[loop].sourceId; int targetId = inEdges[loop].targetId; VertexType sourceVertex = vertexVector[ sourceId ]; VertexType targetVertex = vertexVector[ targetId ]; // there are two methods to add nodes if( loop % 2 == 0 ) { network->AddEdge(sourceVertex, targetVertex); for( int remaining( inEdges[loop].weight ); remaining > 1; remaining-- ) { network->IncreaseEdgeWeight( sourceVertex, targetVertex ); } } else { network->AddEdge(sourceVertex, targetVertex, sourceId, targetId, inEdges[loop].weight ); } } // Test whether network parameters are as expected MITK_TEST_CONDITION_REQUIRED( inNodes.size() == network->GetNumberOfVertices(), "Expected number of vertices") MITK_TEST_CONDITION_REQUIRED( inEdges.size() == network->GetNumberOfEdges(), "Expected number of edges") MITK_TEST_CONDITION_REQUIRED( 0 == network->GetNumberOfSelfLoops(), "Expected number of self loops") bool avDegCloseEnough( std::abs(3 - network->GetAverageDegree()) < eps); MITK_TEST_CONDITION_REQUIRED( avDegCloseEnough, "Expected average degree") bool conDensCloseEnough( std::abs(0.2727 - network->GetConnectionDensity()) < eps); MITK_TEST_CONDITION_REQUIRED( conDensCloseEnough, "Expected connection density") bool clustCoeffCloseEnough( std::abs(0.4583 - network->GetGlobalClusteringCoefficient()) < eps); MITK_TEST_CONDITION_REQUIRED( clustCoeffCloseEnough, "Expected global clustering coefficient") MITK_TEST_CONDITION_REQUIRED( network->GetMaximumWeight() == 2, "Expected maximum weight") MITK_TEST_CONDITION_REQUIRED( network->GetVectorOfAllVertexDescriptors().size() == vertexVector.size(), "Expected number of vertex descriptors") } catch (...) { MITK_ERROR << "Unhandled exception caught while testing network interface [FAILED]" ; return EXIT_FAILURE; } try { // Testing modularity calculation typedef std::map< VertexType, int > ToModuleMapType; // Create network mitk::ConnectomicsNetwork::Pointer network = mitk::ConnectomicsNetwork::New(); std::vector< VertexType > vertexVector; vertexVector.resize( inNodes.size() ); for(int loop(0); loop < inNodes.size(); loop++) { VertexType newVertex = network->AddVertex( inNodes[loop].id ); vertexVector[ inNodes[loop].id ] = newVertex; network->SetLabel( newVertex, inNodes[loop].label ); network->SetCoordinates( newVertex, inNodes[loop].coordinates ); } for(int loop(0); loop < inEdges.size(); loop++) { int sourceId = inEdges[loop].sourceId; int targetId = inEdges[loop].targetId; VertexType sourceVertex = vertexVector[ sourceId ]; VertexType targetVertex = vertexVector[ targetId ]; // there are two methods to add nodes if( loop % 2 == 0 ) { network->AddEdge(sourceVertex, targetVertex); for( int remaining( inEdges[loop].weight ); remaining > 1; remaining-- ) { network->IncreaseEdgeWeight( sourceVertex, targetVertex ); } } else { network->AddEdge(sourceVertex, targetVertex, sourceId, targetId, inEdges[loop].weight ); } } // Simulated annealing classes mitk::ConnectomicsSimulatedAnnealingManager::Pointer manager = mitk::ConnectomicsSimulatedAnnealingManager::New(); mitk::ConnectomicsSimulatedAnnealingPermutationModularity::Pointer permutation = mitk::ConnectomicsSimulatedAnnealingPermutationModularity::New(); mitk::ConnectomicsSimulatedAnnealingCostFunctionModularity::Pointer costFunction = mitk::ConnectomicsSimulatedAnnealingCostFunctionModularity::New(); // Test whether modularity calculation behaves as expected ToModuleMapType threeModuleSolution; std::vector< VertexType > vertexInVector = network->GetVectorOfAllVertexDescriptors(); threeModuleSolution.insert( std::pair( vertexInVector[ 0 ], 0 ) ); threeModuleSolution.insert( std::pair( vertexInVector[ 1 ], 0 ) ); threeModuleSolution.insert( std::pair( vertexInVector[ 2 ], 0 ) ); threeModuleSolution.insert( std::pair( vertexInVector[ 3 ], 0 ) ); threeModuleSolution.insert( std::pair( vertexInVector[ 4 ], 0 ) ); threeModuleSolution.insert( std::pair( vertexInVector[ 5 ], 1 ) ); threeModuleSolution.insert( std::pair( vertexInVector[ 6 ], 1 ) ); threeModuleSolution.insert( std::pair( vertexInVector[ 7 ], 1 ) ); threeModuleSolution.insert( std::pair( vertexInVector[ 8 ], 1 ) ); threeModuleSolution.insert( std::pair( vertexInVector[ 9 ], 2 ) ); threeModuleSolution.insert( std::pair( vertexInVector[ 10 ], 2 ) ); threeModuleSolution.insert( std::pair( vertexInVector[ 11 ], 2 ) ); bool threeModuleModularity( std::abs(0.4753 - costFunction->CalculateModularity( network, &threeModuleSolution )) < eps); MITK_TEST_CONDITION_REQUIRED( threeModuleModularity, "Expected three module modularity") bool correctNumberOfModules( permutation->getNumberOfModules( &threeModuleSolution ) == 3 ); MITK_TEST_CONDITION_REQUIRED( correctNumberOfModules, "Expected number of modules") bool correctNumberOfVertices( permutation->getNumberOfVerticesInModule( &threeModuleSolution, 0 ) == 5 && permutation->getNumberOfVerticesInModule( &threeModuleSolution, 1 ) == 4 && permutation->getNumberOfVerticesInModule( &threeModuleSolution, 2 ) == 3 ); MITK_TEST_CONDITION_REQUIRED( correctNumberOfVertices, "Expected number of vertices per module") ToModuleMapType oneModuleSolution; oneModuleSolution.insert( std::pair( vertexInVector[ 0 ], 0 ) ); oneModuleSolution.insert( std::pair( vertexInVector[ 1 ], 0 ) ); oneModuleSolution.insert( std::pair( vertexInVector[ 2 ], 0 ) ); oneModuleSolution.insert( std::pair( vertexInVector[ 3 ], 0 ) ); oneModuleSolution.insert( std::pair( vertexInVector[ 4 ], 0 ) ); oneModuleSolution.insert( std::pair( vertexInVector[ 5 ], 0 ) ); oneModuleSolution.insert( std::pair( vertexInVector[ 6 ], 0 ) ); oneModuleSolution.insert( std::pair( vertexInVector[ 7 ], 0 ) ); oneModuleSolution.insert( std::pair( vertexInVector[ 8 ], 0 ) ); oneModuleSolution.insert( std::pair( vertexInVector[ 9 ], 0 ) ); oneModuleSolution.insert( std::pair( vertexInVector[ 10 ], 0 ) ); oneModuleSolution.insert( std::pair( vertexInVector[ 11 ], 0 ) ); bool oneModuleModularity( std::abs(0.0 - costFunction->CalculateModularity( network, &oneModuleSolution )) < eps); MITK_TEST_CONDITION_REQUIRED( oneModuleModularity, "Expected one module modularity") ToModuleMapType badTwoModuleSolution; badTwoModuleSolution.insert( std::pair( vertexInVector[ 0 ], 0 ) ); badTwoModuleSolution.insert( std::pair( vertexInVector[ 1 ], 0 ) ); badTwoModuleSolution.insert( std::pair( vertexInVector[ 2 ], 0 ) ); badTwoModuleSolution.insert( std::pair( vertexInVector[ 3 ], 0 ) ); badTwoModuleSolution.insert( std::pair( vertexInVector[ 4 ], 0 ) ); badTwoModuleSolution.insert( std::pair( vertexInVector[ 5 ], 1 ) ); badTwoModuleSolution.insert( std::pair( vertexInVector[ 6 ], 1 ) ); badTwoModuleSolution.insert( std::pair( vertexInVector[ 7 ], 1 ) ); badTwoModuleSolution.insert( std::pair( vertexInVector[ 8 ], 0 ) ); badTwoModuleSolution.insert( std::pair( vertexInVector[ 9 ], 1 ) ); badTwoModuleSolution.insert( std::pair( vertexInVector[ 10 ], 1 ) ); badTwoModuleSolution.insert( std::pair( vertexInVector[ 11 ], 0 ) ); bool badTwoModuleModularity( std::abs(0.097222 - costFunction->CalculateModularity( network, &badTwoModuleSolution )) < eps); MITK_TEST_CONDITION_REQUIRED( badTwoModuleModularity, "Expected bad two module modularity") ToModuleMapType noInternalLinksThreeModuleSolution; noInternalLinksThreeModuleSolution.insert( std::pair( vertexInVector[ 0 ], 0 ) ); noInternalLinksThreeModuleSolution.insert( std::pair( vertexInVector[ 1 ], 2 ) ); noInternalLinksThreeModuleSolution.insert( std::pair( vertexInVector[ 2 ], 1 ) ); noInternalLinksThreeModuleSolution.insert( std::pair( vertexInVector[ 3 ], 0 ) ); noInternalLinksThreeModuleSolution.insert( std::pair( vertexInVector[ 4 ], 1 ) ); noInternalLinksThreeModuleSolution.insert( std::pair( vertexInVector[ 5 ], 2 ) ); noInternalLinksThreeModuleSolution.insert( std::pair( vertexInVector[ 6 ], 0 ) ); noInternalLinksThreeModuleSolution.insert( std::pair( vertexInVector[ 7 ], 0 ) ); noInternalLinksThreeModuleSolution.insert( std::pair( vertexInVector[ 8 ], 1 ) ); noInternalLinksThreeModuleSolution.insert( std::pair( vertexInVector[ 9 ], 2 ) ); noInternalLinksThreeModuleSolution.insert( std::pair( vertexInVector[ 10 ], 1 ) ); noInternalLinksThreeModuleSolution.insert( std::pair( vertexInVector[ 11 ], 0 ) ); bool noInternalThreeModuleModularity( std::abs(-0.3395 - costFunction->CalculateModularity( network, &noInternalLinksThreeModuleSolution )) < eps); MITK_TEST_CONDITION_REQUIRED( noInternalThreeModuleModularity, "Expected three module modularity containing no internal links") } catch (...) { MITK_ERROR << "Unhandled exception caught while testing modularity calculation [FAILED]" ; return EXIT_FAILURE; } // Test ends MITK_TEST_END(); } diff --git a/Modules/DiffusionImaging/FiberTracking/Testing/mitkFiberBundleXReaderWriterTest.cpp b/Modules/DiffusionImaging/FiberTracking/Testing/mitkFiberBundleXReaderWriterTest.cpp index e7ca19913c..faaac6858e 100644 --- a/Modules/DiffusionImaging/FiberTracking/Testing/mitkFiberBundleXReaderWriterTest.cpp +++ b/Modules/DiffusionImaging/FiberTracking/Testing/mitkFiberBundleXReaderWriterTest.cpp @@ -1,81 +1,81 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkTestingMacros.h" -#include +#include #include #include #include #include #include #include #include /**Documentation * Test for fiber bundle reader and writer */ int mitkFiberBundleXReaderWriterTest(int argc, char* argv[]) { MITK_TEST_BEGIN("mitkFiberBundleXReaderWriterTest"); std::cout << argv[1]<1,"check for filename") mitk::FiberBundleXWriter::Pointer writer = mitk::FiberBundleXWriter::New(); mitk::FiberBundleX::Pointer fib1; mitk::FiberBundleX::Pointer fib2; // first test: did this work? // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since // it makes no sense to continue without an object. MITK_TEST_CONDITION_REQUIRED(writer.IsNotNull(),"writer instantiation") try{ - RegisterDiffusionImagingObjectFactory(); + RegisterFiberTrackingObjectFactory(); // test if fib1 can be read const std::string s1="", s2=""; std::vector fibInfile = mitk::BaseDataIO::LoadBaseDataFromFile( argv[1], s1, s2, false ); mitk::BaseData::Pointer baseData = fibInfile.at(0); fib1 = dynamic_cast(baseData.GetPointer()); MITK_TEST_CONDITION_REQUIRED(fib1.IsNotNull(),"check if reader returned null") // test if fib1 can be written MITK_TEST_CONDITION_REQUIRED( writer->CanWriteBaseDataType(fib1.GetPointer()),"writer can write data") writer->SetFileName( std::string(MITK_TEST_OUTPUT_DIR)+"/writerTest.fib" ); writer->DoWrite( fib1.GetPointer() ); // test if fib1 can be read again as fib2 fibInfile = mitk::BaseDataIO::LoadBaseDataFromFile( std::string(MITK_TEST_OUTPUT_DIR)+"/writerTest.fib", s1, s2, false ); baseData = fibInfile.at(0); fib2 = dynamic_cast(baseData.GetPointer()); MITK_TEST_CONDITION_REQUIRED(fib2.IsNotNull(),"reader can read file written before") // test if fib1 equals fib2 MITK_TEST_CONDITION_REQUIRED(fib1->Equals(fib2),"fiber bundles are not changed during reading/writing") } catch(...) { return EXIT_FAILURE; } // always end with this! MITK_TEST_END(); } diff --git a/Modules/DiffusionImaging/FiberTracking/Testing/mitkFiberBundleXTest.cpp b/Modules/DiffusionImaging/FiberTracking/Testing/mitkFiberBundleXTest.cpp index faf5e644fc..7d14539dbb 100644 --- a/Modules/DiffusionImaging/FiberTracking/Testing/mitkFiberBundleXTest.cpp +++ b/Modules/DiffusionImaging/FiberTracking/Testing/mitkFiberBundleXTest.cpp @@ -1,100 +1,100 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkTestingMacros.h" -#include +#include #include #include #include #include #include #include #include /**Documentation * Test for fiber bundle reader and writer */ int mitkFiberBundleXTest(int argc, char* argv[]) { MITK_TEST_BEGIN("mitkFiberBundleXTest"); MITK_TEST_CONDITION_REQUIRED(argc>1,"check for filename") mitk::FiberBundleXReader::Pointer reader = mitk::FiberBundleXReader::New(); mitk::FiberBundleX::Pointer fib1, fib2; // first test: did this work? // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since // it makes no sense to continue without an object. MITK_TEST_CONDITION_REQUIRED(reader.IsNotNull(),"reader instantiation") try{ - RegisterDiffusionImagingObjectFactory(); + RegisterFiberTrackingObjectFactory(); // test if fib1 can be read const std::string s1="", s2=""; std::vector fibInfile = mitk::BaseDataIO::LoadBaseDataFromFile( argv[1], s1, s2, false ); mitk::BaseData::Pointer baseData = fibInfile.at(0); fib1 = dynamic_cast(baseData.GetPointer()); MITK_TEST_CONDITION_REQUIRED(fib1.IsNotNull(),"check if reader 1 returned null") fibInfile = mitk::BaseDataIO::LoadBaseDataFromFile( argv[1], s1, s2, false ); baseData = fibInfile.at(0); fib2 = dynamic_cast(baseData.GetPointer()); MITK_TEST_CONDITION_REQUIRED(fib2.IsNotNull(),"check if reader 2 returned null") MITK_TEST_CONDITION_REQUIRED(fib1->Equals(fib2),"check if equals method is working"); int randNum = rand()%20; MITK_INFO << "DoFiberSmoothing(" << randNum << ")" << randNum; fib2->DoFiberSmoothing(randNum); MITK_TEST_CONDITION_REQUIRED(!fib1->Equals(fib2),"check if fiber resampling method does something"); mitk::FiberBundleX::Pointer fib3 = fib1->AddBundle(fib2); MITK_TEST_CONDITION_REQUIRED(!fib1->Equals(fib3),"check if A+B!=A"); // fib3 = fib3->SubtractBundle(fib2); // MITK_TEST_CONDITION_REQUIRED(fib1->Equals(fib3),"check if A+B-B==A"); fib1->AddBundle(NULL); MITK_INFO << "GenerateFiberIds"; fib1->GenerateFiberIds(); MITK_INFO << "GetFiberPolyData"; fib1->GetFiberPolyData(); MITK_INFO << "GetAvailableColorCodings"; fib1->GetAvailableColorCodings(); MITK_INFO << "GetCurrentColorCoding"; fib1->GetCurrentColorCoding(); MITK_INFO << "SetFiberPolyData"; fib1->SetFiberPolyData(NULL); MITK_INFO << "ExtractFiberSubset"; fib1->ExtractFiberSubset(NULL); MITK_INFO << "ExtractFiberIdSubset"; fib1->ExtractFiberIdSubset(NULL); std::vector< long > tmp; MITK_INFO << "GeneratePolyDataByIds"; fib1->GeneratePolyDataByIds(tmp); MITK_INFO << "SetColorCoding"; fib1->SetColorCoding(NULL); MITK_INFO << "SetFAMap"; fib1->SetFAMap(NULL); MITK_INFO << "DoColorCodingOrientationBased"; fib1->DoColorCodingOrientationBased(); MITK_INFO << "DoColorCodingFaBased"; fib1->DoColorCodingFaBased(); MITK_INFO << "DoUseFaFiberOpacity"; fib1->DoUseFaFiberOpacity(); MITK_INFO << "ResetFiberOpacity"; fib1->ResetFiberOpacity(); float randFloat = rand()%300; MITK_INFO << "RemoveShortFibers(" << randFloat << ")"; fib1->RemoveShortFibers(randFloat); } catch(...) { //this means that a wrong exception (i.e. no itk:Exception) has been thrown std::cout << "Wrong exception (i.e. no itk:Exception) caught during write [FAILED]" << std::endl; return EXIT_FAILURE; } // always end with this! MITK_TEST_END(); } diff --git a/Modules/DiffusionImaging/FiberTracking/Testing/mitkGibbsTrackingTest.cpp b/Modules/DiffusionImaging/FiberTracking/Testing/mitkGibbsTrackingTest.cpp index 9c02c54756..f21b2bcbb0 100644 --- a/Modules/DiffusionImaging/FiberTracking/Testing/mitkGibbsTrackingTest.cpp +++ b/Modules/DiffusionImaging/FiberTracking/Testing/mitkGibbsTrackingTest.cpp @@ -1,100 +1,101 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include #include -#include +#include +#include #include #include using namespace mitk; /**Documentation * Test for gibbs tracking filter */ int mitkGibbsTrackingTest(int argc, char* argv[]) { MITK_TEST_BEGIN("mitkGibbsTrackingTest"); MITK_TEST_CONDITION_REQUIRED(argc>5,"check for input data") QBallImage::Pointer mitkQballImage; Image::Pointer mitkMaskImage; mitk::FiberBundleX::Pointer fib1; try{ MITK_INFO << "Q-Ball image: " << argv[1]; MITK_INFO << "Mask image: " << argv[2]; MITK_INFO << "Parameter file: " << argv[3]; MITK_INFO << "Lut path: " << argv[4]; MITK_INFO << "Reference bundle: " << argv[5]; - RegisterDiffusionImagingObjectFactory(); - + RegisterDiffusionCoreObjectFactory(); + RegisterFiberTrackingObjectFactory(); // test if fib1 can be read const std::string s1="", s2=""; std::vector infile = mitk::BaseDataIO::LoadBaseDataFromFile( argv[1], s1, s2, false ); mitkQballImage = dynamic_cast(infile.at(0).GetPointer()); MITK_TEST_CONDITION_REQUIRED(mitkQballImage.IsNotNull(),"check qball image") infile = mitk::BaseDataIO::LoadBaseDataFromFile( argv[2], s1, s2, false ); mitkMaskImage = dynamic_cast(infile.at(0).GetPointer()); MITK_TEST_CONDITION_REQUIRED(mitkMaskImage.IsNotNull(),"check mask image") infile = mitk::BaseDataIO::LoadBaseDataFromFile( argv[5], s1, s2, false ); fib1 = dynamic_cast(infile.at(0).GetPointer()); MITK_TEST_CONDITION_REQUIRED(fib1.IsNotNull(),"check fiber bundle") typedef itk::Vector OdfVectorType; typedef itk::Image OdfVectorImgType; typedef itk::Image MaskImgType; typedef itk::GibbsTrackingFilter GibbsTrackingFilterType; OdfVectorImgType::Pointer itk_qbi = OdfVectorImgType::New(); mitk::CastToItkImage(mitkQballImage, itk_qbi); MaskImgType::Pointer itk_mask = MaskImgType::New(); mitk::CastToItkImage(mitkMaskImage, itk_mask); GibbsTrackingFilterType::Pointer gibbsTracker = GibbsTrackingFilterType::New(); gibbsTracker->SetQBallImage(itk_qbi.GetPointer()); gibbsTracker->SetMaskImage(itk_mask); gibbsTracker->SetDuplicateImage(false); gibbsTracker->SetRandomSeed(1); gibbsTracker->SetLoadParameterFile(argv[3]); gibbsTracker->SetLutPath(argv[4]); gibbsTracker->Update(); mitk::FiberBundleX::Pointer fib2 = mitk::FiberBundleX::New(gibbsTracker->GetFiberBundle()); MITK_TEST_CONDITION_REQUIRED(fib1->Equals(fib2), "check if gibbs tracking has changed"); gibbsTracker->SetRandomSeed(0); gibbsTracker->Update(); fib2 = mitk::FiberBundleX::New(gibbsTracker->GetFiberBundle()); MITK_TEST_CONDITION_REQUIRED(!fib1->Equals(fib2), "check if gibbs tracking has changed after wrong seed"); } catch(...) { return EXIT_FAILURE; } // always end with this! MITK_TEST_END(); } diff --git a/Modules/DiffusionImaging/Quantification/Testing/mitkTbssNrrdImageReaderTest.cpp b/Modules/DiffusionImaging/Quantification/Testing/mitkTbssNrrdImageReaderTest.cpp index 46c135bec5..b37d0ed7f9 100644 --- a/Modules/DiffusionImaging/Quantification/Testing/mitkTbssNrrdImageReaderTest.cpp +++ b/Modules/DiffusionImaging/Quantification/Testing/mitkTbssNrrdImageReaderTest.cpp @@ -1,67 +1,67 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include -#include "mitkDiffusionImagingObjectFactory.h" +#include "mitkQuantificationObjectFactory.h" #include "mitkCoreObjectFactory.h" /**Documentation * test for the class "mitkNrrdTbssImageReader". */ int mitkTbssNrrdImageReaderTest(int argc , char* argv[]) { MITK_TEST_BEGIN("TbssNrrdImageReaderTest"); mitk::NrrdTbssImageReader::Pointer tbssNrrdReader = mitk::NrrdTbssImageReader::New(); MITK_TEST_CONDITION_REQUIRED(tbssNrrdReader.GetPointer(), "Testing initialization of test object!"); - RegisterDiffusionImagingObjectFactory(); + RegisterQuantificationObjectFactory(); tbssNrrdReader->SetFileName(argv[1]); MITK_TEST_CONDITION_REQUIRED( tbssNrrdReader->CanReadFile(argv[1], "", ""), "Testing CanReadFile() method with valid input file name!"); tbssNrrdReader->Update(); mitk::TbssImage* tbssImg = tbssNrrdReader->GetOutput(0); MITK_TEST_CONDITION_REQUIRED(tbssImg != NULL, "Testing that tbssImg is not null"); mitk::TbssImage::SizeType size = tbssImg->GetLargestPossibleRegion().GetSize(); MITK_TEST_CONDITION_REQUIRED(size[0]==2 && size[1]==2 && size[2]==2, "Test size of tbss image"); // Test groups std::vector< std::pair > groups = tbssImg->GetGroupInfo(); std::pair group1 = groups.at(0); std::pair group2 = groups.at(1); MITK_TEST_CONDITION_REQUIRED(group1.first.compare("group1") && group1.second==1, "Test group 1 info"); MITK_TEST_CONDITION_REQUIRED(group2.first.compare("group2") && group2.second==1, "Test group 2 info"); MITK_TEST_END(); } diff --git a/Modules/DiffusionImaging/Quantification/Testing/mitkTbssNrrdImageWriterTest.cpp b/Modules/DiffusionImaging/Quantification/Testing/mitkTbssNrrdImageWriterTest.cpp index bdf8f58375..8a43eb80a2 100644 --- a/Modules/DiffusionImaging/Quantification/Testing/mitkTbssNrrdImageWriterTest.cpp +++ b/Modules/DiffusionImaging/Quantification/Testing/mitkTbssNrrdImageWriterTest.cpp @@ -1,79 +1,79 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include -#include "mitkDiffusionImagingObjectFactory.h" +#include "mitkQuantificationObjectFactory.h" #include "mitkCoreObjectFactory.h" /**Documentation * test for the class "mitkNrrdTbssImageWriter". */ int mitkTbssNrrdImageWriterTest(int argc , char* argv[]) { MITK_TEST_BEGIN("TbssNrrdImageWriterTest"); mitk::NrrdTbssImageReader::Pointer tbssNrrdReader = mitk::NrrdTbssImageReader::New(); MITK_TEST_CONDITION_REQUIRED(tbssNrrdReader.GetPointer(), "Testing initialization of test object!"); - RegisterDiffusionImagingObjectFactory(); + RegisterQuantificationObjectFactory(); tbssNrrdReader->SetFileName(argv[1]); MITK_TEST_CONDITION_REQUIRED( tbssNrrdReader->CanReadFile(argv[1], "", ""), "Testing CanReadFile() method with valid input file name!"); tbssNrrdReader->Update(); mitk::TbssImage* tbssImg = tbssNrrdReader->GetOutput(0); MITK_TEST_CONDITION_REQUIRED(tbssImg != NULL, "Testing that tbssImg is not null"); mitk::NrrdTbssImageWriter::Pointer tbssNrrdWriter = mitk::NrrdTbssImageWriter::New(); try{ tbssNrrdWriter->SetFileName(argv[2]); tbssNrrdWriter->SetInput(tbssImg); tbssNrrdWriter->Update(); } catch(...) { std::cout << "Writing failed" << std::endl; return EXIT_FAILURE; } mitk::NrrdTbssImageReader::Pointer tbssNrrdReader2 = mitk::NrrdTbssImageReader::New(); tbssNrrdReader2->SetFileName(argv[1]); MITK_TEST_CONDITION_REQUIRED( tbssNrrdReader2->CanReadFile(argv[1], "", ""), "Testing CanReadFile() method with previously saved file!"); tbssNrrdReader2->Update(); mitk::TbssImage* tbssImg2 = tbssNrrdReader2->GetOutput(0); std::vector< std::pair > groups = tbssImg->GetGroupInfo(); std::vector< std::pair > groups2 = tbssImg2->GetGroupInfo(); MITK_TEST_CONDITION(groups == groups2, "Check that group information is identical"); mitk::TbssImage::SizeType size = tbssImg->GetLargestPossibleRegion().GetSize(); mitk::TbssImage::SizeType size2 = tbssImg2->GetLargestPossibleRegion().GetSize(); MITK_TEST_CONDITION(size == size2, "Check that sizes are equal"); MITK_TEST_END(); }