|
Slicer 4.2
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
|
#include "vtkMRML.h"#include <vtkCallbackCommand.h>#include <vtkSmartPointer.h>#include <vtkMath.h>#include "vtkMRMLStorageNode.h"#include <vtkStringArray.h>#include <vtkURIHandler.h>#include <vtkMatrix4x4.h>
Go to the source code of this file.
Classes | |
| class | vtkMRMLNodeCallback |
Defines | |
| #define | EXERCISE_BASIC_DISPLAY_MRML_METHODS(className, node) |
| #define | EXERCISE_BASIC_DISPLAYABLE_MRML_METHODS(className, node) |
| #define | EXERCISE_BASIC_MRML_METHODS(className, node) |
| Slicer Libs/MRML/vtkMRMLNode exercises. | |
| #define | EXERCISE_BASIC_OBJECT_METHODS(object) |
| tests basic vtkObject methods | |
| #define | EXERCISE_BASIC_STORABLE_MRML_METHODS(className, node) |
| #define | EXERCISE_BASIC_STORAGE_MRML_METHODS(className, node) |
| #define | EXERCISE_BASIC_TRANSFORM_MRML_METHODS(className, node) |
| #define | EXERCISE_BASIC_TRANSFORMABLE_MRML_METHODS(className, node) |
| #define | TEST_ITK_SET_GET(variable, command) |
| test itk set/get | |
| #define | TEST_ITK_SET_GET_VALUE(variable, command) |
| test itk set/get | |
| #define | TEST_SET_GET_BOOLEAN(object, variable) |
| test object by calling Set on the variable with false, true, 0, 1, On, Off | |
| #define | TEST_SET_GET_DOUBLE(object, variable, value) |
| #define | TEST_SET_GET_DOUBLE_RANDOM(object, variable, max) |
| #define | TEST_SET_GET_DOUBLE_RANGE(object, variable, min, max) |
| #define | TEST_SET_GET_INT(object, variable, value) |
| #define | TEST_SET_GET_INT_RANDOM(object, variable, max) |
| #define | TEST_SET_GET_INT_RANGE(object, variable, min, max) |
| #define | TEST_SET_GET_STRING(object, variable) |
| test a string variable on the object by calling Set/Get | |
| #define | TEST_SET_GET_UNSIGNED_INT_RANGE(object, variable, min, max) |
| #define | TEST_SET_GET_VECTOR3_DOUBLE(object, variable, x, y, z) |
| #define | TEST_SET_GET_VECTOR3_DOUBLE_RANDOM(object, variable, max) |
| #define | TEST_SET_GET_VECTOR3_DOUBLE_RANGE(object, variable, min, max) |
| #define | TRY_EXPECT_ITK_EXCEPTION(command) |
| try the itk command passed in, succeeding if catch an exception | |
| #define | TRY_EXPECT_NO_ITK_EXCEPTION(command) |
| try the command passed in, succeeding if no exception | |
| #define EXERCISE_BASIC_DISPLAY_MRML_METHODS | ( | className, | |
| node | |||
| ) |
For testing nodes in Libs/MRML that are subclasses of the display node. Calls the basic mrml methods macro first.
Definition at line 516 of file vtkMRMLCoreTestingMacros.h.
| #define EXERCISE_BASIC_DISPLAYABLE_MRML_METHODS | ( | className, | |
| node | |||
| ) |
{ \
EXERCISE_BASIC_STORABLE_MRML_METHODS( className, node ); \
if (node->GetNumberOfDisplayNodes() != 0) \
{ \
std::cerr << "Error in getting number of display nodes." << std::endl; \
return EXIT_FAILURE; \
} \
node->SetAndObserveDisplayNodeID("noid"); \
node->AddAndObserveDisplayNodeID("badid"); \
node->SetAndObserveNthDisplayNodeID(2, "nothing"); \
const char *dnodeid = node->GetNthDisplayNodeID(0); \
if (dnodeid == NULL || strcmp(dnodeid, "noid") != 0) \
{ \
std::cerr << "ERROR getting 0th display node id, instead of noid got " << (dnodeid == NULL ? "null" : dnodeid) << std::endl; \
return EXIT_FAILURE; \
} \
vtkMRMLDisplayNode *dnode = node->GetNthDisplayNode(0); \
if (dnode != NULL) \
{ \
std::cerr << "ERROR getting 0th display node" << std::endl; \
return EXIT_FAILURE; \
} \
}
For testing nodes in Libs/MRML that are displayable. Calls the basic transformable mrml methods macro first.
Definition at line 488 of file vtkMRMLCoreTestingMacros.h.
| #define EXERCISE_BASIC_MRML_METHODS | ( | className, | |
| node | |||
| ) |
Slicer Libs/MRML/vtkMRMLNode exercises.
Definition at line 337 of file vtkMRMLCoreTestingMacros.h.
| #define EXERCISE_BASIC_OBJECT_METHODS | ( | object | ) |
{ \
if ( object == NULL ) \
{ \
std::cerr << "EXERCISE_BASIC_OBJECT_METHODS( with NULL object )" << std::endl; \
return EXIT_FAILURE; \
} \
object->Print( std::cout ); \
std::cout << "Name of Class = " << object->GetClassName() << std::endl; \
std::cout << "Name of Superclass = " << object->Superclass::GetClassName() << std::endl; \
}
tests basic vtkObject methods
Definition at line 26 of file vtkMRMLCoreTestingMacros.h.
| #define EXERCISE_BASIC_STORABLE_MRML_METHODS | ( | className, | |
| node | |||
| ) |
For testing nodes in Libs/MRML that are storable. Calls the basic transformable mrml methods macro first.
Definition at line 441 of file vtkMRMLCoreTestingMacros.h.
| #define EXERCISE_BASIC_STORAGE_MRML_METHODS | ( | className, | |
| node | |||
| ) |
For testing nodes in Libs/MRML that are subclasses of the storage node. Calls the basic mrml methods macro first.
Definition at line 581 of file vtkMRMLCoreTestingMacros.h.
| #define EXERCISE_BASIC_TRANSFORM_MRML_METHODS | ( | className, | |
| node | |||
| ) |
{ \
EXERCISE_BASIC_STORABLE_MRML_METHODS( className, node ); \
std::cout << "IsLinear = " << node->IsLinear()<< std:: endl; \
vtkSmartPointer<vtkGeneralTransform> g = vtkSmartPointer<vtkGeneralTransform>::New(); \
g = node->GetTransformToParent(); \
if (g == NULL) \
{ \
std::cout << "Warning: transform node has a null transform to parent" << std::endl; \
} \
std::cout << "IsTransformToWorldLinear = " << node->IsTransformToWorldLinear() << std::endl; \
vtkSmartPointer < className > t = vtkSmartPointer < className >::New(); \
std::cout << "IsTransformToNodeLinear = " << node->IsTransformToNodeLinear(t) << std::endl; \
node->GetTransformToWorld(g); \
node->GetTransformToNode(t, g); \
vtkSmartPointer<vtkMatrix4x4> m = vtkSmartPointer<vtkMatrix4x4>::New(); \
int retval = node->GetMatrixTransformToWorld(m); \
if (retval == 0) \
{ \
std::cout << "Warning: can't get matrix transform to world." << std::endl; \
} \
retval = node->GetMatrixTransformToNode(t, m); \
if (retval == 0) \
{ \
std::cout << "Warning: can't get matrix transform to node." << std::endl; \
} \
std::cout << "IsTransformNodeMyParent = " << node->IsTransformNodeMyParent(t) << std::endl; \
std::cout << "IsTransformNodeMyChild = " << node->IsTransformNodeMyChild(t) << std::endl; \
}
For testing nodes in Libs/MRML that are transform nodes. Calls the basic storable mrml methods macro first.
Definition at line 740 of file vtkMRMLCoreTestingMacros.h.
| #define EXERCISE_BASIC_TRANSFORMABLE_MRML_METHODS | ( | className, | |
| node | |||
| ) |
{ \
EXERCISE_BASIC_MRML_METHODS(className, node); \
vtkMRMLTransformNode *tnode2 = node->GetParentTransformNode(); \
if (tnode2 != NULL) \
{ \
std::cerr << "ERROR: parent transform node is not null" << std::endl; \
return EXIT_FAILURE; \
} \
node1->SetAndObserveTransformNodeID(NULL); \
const char *node_tid = node1->GetTransformNodeID(); \
if (node_tid != NULL) \
{ \
std::cerr << "ERROR: with observing transform node id" << std::endl; \
return EXIT_FAILURE; \
} \
bool canApplyNonLinear = node->CanApplyNonLinearTransforms(); \
std::cout << "Node can apply non linear transforms? " << (canApplyNonLinear == true ? "yes" : "no") << std::endl; \
}
For testing nodes in Libs/MRML that are transformable. Calls the basic mrml methods macro first.
Definition at line 417 of file vtkMRMLCoreTestingMacros.h.
| #define TEST_ITK_SET_GET | ( | variable, | |
| command | |||
| ) |
if( variable.GetPointer() != command ) \ { \ std::cerr << "Error in " << #command << std::endl; \ std::cerr << "Expected " << variable.GetPointer() << std::endl; \ std::cerr << "but got " << command << std::endl; \ return EXIT_FAILURE; \ }
test itk set/get
Definition at line 70 of file vtkMRMLCoreTestingMacros.h.
| #define TEST_ITK_SET_GET_VALUE | ( | variable, | |
| command | |||
| ) |
if( variable != command ) \ { \ std::cerr << "Error in " << #command << std::endl; \ std::cerr << "Expected " << variable << std::endl; \ std::cerr << "but got " << command << std::endl; \ return EXIT_FAILURE; \ }
test itk set/get
Definition at line 81 of file vtkMRMLCoreTestingMacros.h.
| #define TEST_SET_GET_BOOLEAN | ( | object, | |
| variable | |||
| ) |
object->Set##variable( false ); \ object->Set##variable( true ); \ if( object->Get##variable() != 1 ) \ { \ std::cerr << "Error in Set/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 1" << std::endl; \ return EXIT_FAILURE; \ } \ object->Set##variable( false ); \ if( object->Get##variable() != 0 ) \ { \ std::cerr << "Error in Set/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 0" << std::endl; \ return EXIT_FAILURE; \ } \ object->variable##On(); \ if( object->Get##variable() != 1 ) \ { \ std::cerr << "Error in On/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 1" << std::endl; \ return EXIT_FAILURE; \ } \ object->variable##Off(); \ if( object->Get##variable() != 0 ) \ { \ std::cerr << "Error in Off/Get"#variable << ", Get"#variable << " is " << object->Get##variable() << " instead of 0" << std::endl; \ return EXIT_FAILURE; \ }
test object by calling Set on the variable with false, true, 0, 1, On, Off
Definition at line 92 of file vtkMRMLCoreTestingMacros.h.
| #define TEST_SET_GET_DOUBLE | ( | object, | |
| variable, | |||
| value | |||
| ) |
{ \
object->Set##variable( value ); \
if( object->Get##variable() != value ) \
{ \
std::cerr << "Error in Set/Get"#variable << " using value " << value << std::endl; \
return EXIT_FAILURE; \
} \
}
test a double variable on the object by setting it to input value using Set, and testing it via the Get
Definition at line 197 of file vtkMRMLCoreTestingMacros.h.
| #define TEST_SET_GET_DOUBLE_RANDOM | ( | object, | |
| variable, | |||
| max | |||
| ) |
{ \
double val = vtkMath::Random() * max; \
object->Set##variable( val ); \
if( object->Get##variable() != val ) \
{ \
std::cerr << "Error in Set/Get"#variable << ", using random value " << val << std::endl; \
return EXIT_FAILURE; \
} \
}
test an integer variable on the object by setting it to a random value up to max using Set, and testing it via the Get
Definition at line 234 of file vtkMRMLCoreTestingMacros.h.
| #define TEST_SET_GET_DOUBLE_RANGE | ( | object, | |
| variable, | |||
| min, | |||
| max | |||
| ) |
{ \
double epsilon = 1.0; \
double val = min - epsilon; \
TEST_SET_GET_DOUBLE( object, variable, val); \
val = min; \
TEST_SET_GET_DOUBLE( object, variable, val); \
val = min + epsilon; \
TEST_SET_GET_DOUBLE( object, variable, val); \
val = (min + max) / 2.0; \
TEST_SET_GET_DOUBLE( object, variable, val); \
val = max - epsilon; \
TEST_SET_GET_DOUBLE( object, variable, val); \
val = max; \
TEST_SET_GET_DOUBLE( object, variable, val); \
val = max + epsilon; \
TEST_SET_GET_DOUBLE( object, variable, val); \
}
Test a double variable on object over the range, calls test set get in with min - epsilon, min, min + epsilon, (min+max)/2, max - epsilon, max, max + epsilon, where first and last test should report errors epsilon set to 1.0
Definition at line 212 of file vtkMRMLCoreTestingMacros.h.
| #define TEST_SET_GET_INT | ( | object, | |
| variable, | |||
| value | |||
| ) |
{ \
object->Set##variable( value ); \
if( object->Get##variable() != value ) \
{ \
std::cerr << "Error in Set/Get"#variable << " using value " << value << std::endl; \
return EXIT_FAILURE; \
} \
}
test an integer variable on the object by setting it to input value using Set, and testing it via the Get
Definition at line 122 of file vtkMRMLCoreTestingMacros.h.
| #define TEST_SET_GET_INT_RANDOM | ( | object, | |
| variable, | |||
| max | |||
| ) |
{ \
int val = (int)(vtkMath::Random() * max); \
object->Set##variable( val ); \
if( object->Get##variable() != val ) \
{ \
std::cerr << "Error in Set/Get"#variable << " using random value " << val << std::endl; \
return EXIT_FAILURE; \
} \
}
test an integer variable on the object by setting it to a random value up to max using Set, and testing it via the Get
Definition at line 159 of file vtkMRMLCoreTestingMacros.h.
| #define TEST_SET_GET_INT_RANGE | ( | object, | |
| variable, | |||
| min, | |||
| max | |||
| ) |
{ \
int epsilon = 1; \
int val = min - epsilon; \
TEST_SET_GET_INT( object, variable, val); \
val = min; \
TEST_SET_GET_INT( object, variable, val); \
val = min + epsilon; \
TEST_SET_GET_INT( object, variable, val); \
val = (min + max) / 2; \
TEST_SET_GET_INT( object, variable, val); \
val = max - epsilon; \
TEST_SET_GET_INT( object, variable, val); \
val = max; \
TEST_SET_GET_INT( object, variable, val); \
val = max + epsilon; \
TEST_SET_GET_INT( object, variable, val); \
}
Test an integer variable on object over the range, calls test set get in with min - epsilon, min, min + epsilon, (min+max)/2, max - epsilon, max, max + epsilon, where first and last test should report errors epsilon defined as 1
Definition at line 137 of file vtkMRMLCoreTestingMacros.h.
| #define TEST_SET_GET_STRING | ( | object, | |
| variable | |||
| ) |
test a string variable on the object by calling Set/Get
Definition at line 297 of file vtkMRMLCoreTestingMacros.h.
| #define TEST_SET_GET_UNSIGNED_INT_RANGE | ( | object, | |
| variable, | |||
| min, | |||
| max | |||
| ) |
{ \
unsigned int epsilon = 1; \
unsigned int val = min - epsilon; \
TEST_SET_GET_INT( object, variable, val); \
val = min; \
TEST_SET_GET_INT( object, variable, val); \
val = min + epsilon; \
TEST_SET_GET_INT( object, variable, val); \
val = (min + max) / 2; \
TEST_SET_GET_INT( object, variable, val); \
val = max - epsilon; \
TEST_SET_GET_INT( object, variable, val); \
val = max; \
TEST_SET_GET_INT( object, variable, val); \
val = max + epsilon; \
TEST_SET_GET_INT( object, variable, val); \
}
Test an unsigned integer variable on object over the range, calls test set get in with min - epsilon, min, min + epsilon, (min+max)/2, max - epsilon, max, max + epsilon, where first and last test should report errors epsilon defined as 1
Definition at line 175 of file vtkMRMLCoreTestingMacros.h.
| #define TEST_SET_GET_VECTOR3_DOUBLE | ( | object, | |
| variable, | |||
| x, | |||
| y, | |||
| z | |||
| ) |
{ \
object->Set##variable( x, y, z ); \
double *val = object->Get##variable(); \
if( val == NULL || val[0] != x || val[1] != y || val[2] != z ) \
{ \
std::cerr << "Error in Set/Get"#variable << std::endl; \
return EXIT_FAILURE; \
} \
}
test a vector variable on the object by setting it to a the values x, y, z passed in using Set, and testing it via the Get
Definition at line 248 of file vtkMRMLCoreTestingMacros.h.
| #define TEST_SET_GET_VECTOR3_DOUBLE_RANDOM | ( | object, | |
| variable, | |||
| max | |||
| ) |
{ \
double x = vtkMath::Random() * max; \
double y = vtkMath::Random() * max; \
double z = vtkMath::Random() * max; \
object->Set##variable( x, y, z ); \
double *val = object->Get##variable(); \
if( val == NULL || val[0] != x || val[1] != y || val[2] != z ) \
{ \
std::cerr << "Error in Set/Get"#variable << " with " << x << ", " << y << ", " << z << std::endl; \
return EXIT_FAILURE; \
} \
}
test a vector variable on the object by setting all it's elements to the same random value up to max using Set, and testing it via the Get
Definition at line 281 of file vtkMRMLCoreTestingMacros.h.
| #define TEST_SET_GET_VECTOR3_DOUBLE_RANGE | ( | object, | |
| variable, | |||
| min, | |||
| max | |||
| ) |
{ \
double epsilon = 1.0; \
TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min - epsilon, min - epsilon, min - epsilon); \
TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min, min, min); \
TEST_SET_GET_VECTOR3_DOUBLE(object, variable, min + epsilon, min + epsilon, min + epsilon); \
double half = (min+max/2.0); \
TEST_SET_GET_VECTOR3_DOUBLE(object, variable, half, half, half); \
TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max - epsilon, max - epsilon, max - epsilon); \
TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max, max, max); \
TEST_SET_GET_VECTOR3_DOUBLE(object, variable, max + epsilon, max + epsilon, max + epsilon); \
}
Test a double vector variable on object over the range, calls test set get in with min - epsilon, min, min + epsilon, (min+max)/2, max - epsilon, max, max + epsilon, where first and last test should report errors. For now all three elements are set to the same thing each time. epsilon set to 1.0
Definition at line 265 of file vtkMRMLCoreTestingMacros.h.
| #define TRY_EXPECT_ITK_EXCEPTION | ( | command | ) |
try \ { \ std::cout << "Trying " << #command << std::endl; \ command; \ std::cerr << "Failed to catch expected exception" << std::endl; \ return EXIT_FAILURE; \ } \ catch( itk::ExceptionObject & excp ) \ { \ std::cout << "Caught expected exception" << std::endl; \ std::cout << excp << std::endl; \ }
try the itk command passed in, succeeding if catch an exception
Definition at line 40 of file vtkMRMLCoreTestingMacros.h.
| #define TRY_EXPECT_NO_ITK_EXCEPTION | ( | command | ) |
try \ { \ std::cout << "Trying " << #command << std::endl; \ command; \ } \ catch( itk::ExceptionObject & excp ) \ { \ std::cerr << excp << std::endl; \ return EXIT_FAILURE; \ }
try the command passed in, succeeding if no exception
Definition at line 56 of file vtkMRMLCoreTestingMacros.h.
1.7.4