00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkTestingMacros.h"
00019
00020 #include "mitkDataNodeFactory.h"
00021 #include "mitkCoreObjectFactory.h"
00022
00023 #include "mitkBaseProperty.h"
00024 #include "mitkProperties.h"
00025 #include <mitkAnnotationProperty.h>
00026 #include <mitkClippingProperty.h>
00027 #include <mitkColorProperty.h>
00028 #include <mitkEnumerationProperty.h>
00029
00030
00031
00032
00033
00034 #include <mitkModalityProperty.h>
00035
00036
00037 #include <mitkPlaneOrientationProperty.h>
00038 #include <mitkShaderProperty.h>
00039 #include <mitkVtkInterpolationProperty.h>
00040 #include <mitkVtkRepresentationProperty.h>
00041 #include <mitkVtkResliceInterpolationProperty.h>
00042 #include <mitkVtkScalarModeProperty.h>
00043 #include <mitkVtkVolumeRenderingProperty.h>
00044 #include <mitkGroupTagProperty.h>
00045 #include <mitkLevelWindowProperty.h>
00046 #include <mitkLookupTableProperty.h>
00047 #include <mitkStringProperty.h>
00048 #include <mitkTransferFunctionProperty.h>
00049
00050 #include "mitkPropertyList.h"
00051 #include "mitkPropertyListSerializer.h"
00052 #include "mitkBasePropertySerializer.h"
00053 #include "mitkBasePropertyDeserializer.h"
00054
00055 #include <mitkPointSet.h>
00056 #include <mitkImage.h>
00057 #include <mitkSurface.h>
00058 #include <mitkVtkWidgetRendering.h>
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 void TestAllProperties(const mitk::PropertyList* propList);
00075
00080 int mitkPropertySerializationTest(int , char* [])
00081 {
00082 MITK_TEST_BEGIN("PropertySerializationTest");
00083
00084 mitk::PropertyListSerializer::Pointer serializer = mitk::PropertyListSerializer::New();
00085
00086
00087 mitk::PropertyList::Pointer propList = mitk::PropertyList::New();
00088 propList->SetProperty("booltrue", mitk::BoolProperty::New(true));
00089 propList->SetProperty("boolfalse", mitk::BoolProperty::New(false));
00090 propList->SetProperty("int", mitk::IntProperty::New(-32));
00091 propList->SetProperty("float", mitk::FloatProperty::New(-31.337));
00092 propList->SetProperty("double", mitk::DoubleProperty::New(-31.337));
00093 propList->SetProperty("string", mitk::StringProperty::New("Hello MITK"));
00094 mitk::Point3D p3d;
00095 mitk::FillVector3D(p3d, 1.0, 2.2, -3.3);
00096 propList->SetProperty("p3d", mitk::Point3dProperty::New(p3d));
00097 mitk::Point3I p3i;
00098 mitk::FillVector3D(p3i, 1, 2, -3);
00099 propList->SetProperty("p3i", mitk::Point3iProperty::New(p3i));
00100 mitk::Point4D p4d;
00101 mitk::FillVector4D(p4d, 1.5, 2.6, -3.7, 4.44);
00102 propList->SetProperty("p4d", mitk::Point4dProperty::New(p4d));
00103 mitk::Vector3D v3d;
00104 mitk::FillVector3D(v3d, 1.0, 2.2, -3.3);
00105 propList->SetProperty("v3d", mitk::Vector3DProperty::New(v3d));
00106 propList->SetProperty("annotation", mitk::AnnotationProperty::New("My Annotation", p3d));
00107 propList->SetProperty("clipping", mitk::ClippingProperty::New(p3d, v3d));
00108 propList->SetProperty("color", mitk::ColorProperty::New(1.0, 0.2, 0.2));
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 propList->SetProperty("modality", mitk::ModalityProperty::New("Color Doppler"));
00119
00120
00121 propList->SetProperty("PlaneOrientationProperty", mitk::PlaneOrientationProperty::New("Arrows in positive direction"));
00122 propList->SetProperty("ShaderProperty", mitk::ShaderProperty::New("fixed"));
00123 propList->SetProperty("VtkInterpolationProperty", mitk::VtkInterpolationProperty::New("Gouraud"));
00124 propList->SetProperty("VtkRepresentationProperty", mitk::VtkRepresentationProperty::New("Surface"));
00125 propList->SetProperty("VtkResliceInterpolationProperty", mitk::VtkResliceInterpolationProperty::New("Cubic"));
00126 propList->SetProperty("VtkScalarModeProperty", mitk::VtkScalarModeProperty::New("PointFieldData"));
00127 propList->SetProperty("VtkVolumeRenderingProperty", mitk::VtkVolumeRenderingProperty::New("COMPOSITE"));
00128 mitk::BoolLookupTable blt;
00129 blt.SetTableValue(0, true); blt.SetTableValue(1, false); blt.SetTableValue(2, true);
00130 propList->SetProperty("BoolLookupTableProperty", mitk::BoolLookupTableProperty::New(blt));
00131 mitk::FloatLookupTable flt;
00132 flt.SetTableValue(0, 3.1); flt.SetTableValue(1, 3.3); flt.SetTableValue(2, 7.0);
00133 propList->SetProperty("FloatLookupTableProperty", mitk::FloatLookupTableProperty::New(flt));
00134 mitk::IntLookupTable ilt;
00135 ilt.SetTableValue(0, 3); ilt.SetTableValue(1, 2); ilt.SetTableValue(2, 11);
00136 propList->SetProperty("IntLookupTableProperty", mitk::IntLookupTableProperty::New(ilt));
00137 mitk::StringLookupTable slt;
00138 slt.SetTableValue(0, "Hello"); slt.SetTableValue(1, "MITK"); slt.SetTableValue(2, "world");
00139 propList->SetProperty("StringLookupTableProperty", mitk::StringLookupTableProperty::New(slt));
00140 propList->SetProperty("GroupTagProperty", mitk::GroupTagProperty::New());
00141 propList->SetProperty("LevelWindowProperty", mitk::LevelWindowProperty::New(mitk::LevelWindow(100.0, 50.0)));
00142 mitk::LookupTable::Pointer lt = mitk::LookupTable::New();
00143 lt->ChangeOpacityForAll(0.25);
00144 lt->ChangeOpacity(17, 0.88);
00145 propList->SetProperty("LookupTableProperty", mitk::LookupTableProperty::New(lt));
00146 propList->SetProperty("StringProperty", mitk::StringProperty::New("Oh why, gruel world"));
00147
00148
00149
00150
00151
00152 MITK_TEST_CONDITION_REQUIRED(propList->GetMap()->size() > 0, "Initialize PropertyList");
00153
00154 TestAllProperties(propList);
00155
00156
00157
00158
00159 mitk::DataNode::Pointer node = mitk::DataNode::New();
00160 node->SetData(mitk::PointSet::New());
00161 TestAllProperties(node->GetPropertyList());
00162 node->SetData(mitk::Image::New());
00163 TestAllProperties(node->GetPropertyList());
00164 node->SetData(mitk::Surface::New());
00165 TestAllProperties(node->GetPropertyList());
00166 node->SetData(mitk::VtkWidgetRendering::New());
00167 TestAllProperties(node->GetPropertyList());
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 MITK_TEST_END();
00214 }
00215
00216 void TestAllProperties(const mitk::PropertyList* propList)
00217 {
00218 assert(propList);
00219
00220
00221 for (mitk::PropertyList::PropertyMap::const_iterator it = propList->GetMap()->begin(); it != propList->GetMap()->end(); ++it)
00222 {
00223 const mitk::BaseProperty* prop = it->second.first;
00224
00225 std::string serializername = std::string(prop->GetNameOfClass()) + "Serializer";
00226 std::list<itk::LightObject::Pointer> allSerializers = itk::ObjectFactoryBase::CreateAllInstance(serializername.c_str());
00227 MITK_TEST_CONDITION(allSerializers.size() > 0, std::string("Creating serializers for ") + serializername);
00228 if (allSerializers.size() == 0)
00229 {
00230 MITK_TEST_OUTPUT( << "serialization not possible, skipping " << prop->GetNameOfClass());
00231 continue;
00232 }
00233 if (allSerializers.size() > 1)
00234 {
00235 MITK_TEST_OUTPUT (<< "Warning: " << allSerializers.size() << " serializers found for " << prop->GetNameOfClass() << "testing only the first one.");
00236 }
00237 mitk::BasePropertySerializer* serializer = dynamic_cast<mitk::BasePropertySerializer*>( allSerializers.begin()->GetPointer());
00238 MITK_TEST_CONDITION(serializer != NULL, serializername + std::string(" is valid"));
00239 if (serializer != NULL)
00240 {
00241 serializer->SetProperty(prop);
00242 TiXmlElement* valueelement = NULL;
00243 try
00244 {
00245 valueelement = serializer->Serialize();
00246 }
00247 catch (...)
00248 {
00249 }
00250 MITK_TEST_CONDITION(valueelement != NULL, std::string("Serialize property with ") + serializername);
00251
00252 if (valueelement == NULL)
00253 {
00254 MITK_TEST_OUTPUT( << "serialization failed, skipping deserialization");
00255 continue;
00256 }
00257
00258 std::string deserializerName = std::string(prop->GetNameOfClass()) + std::string("Deserializer");
00259 std::list<itk::LightObject::Pointer> allDeserializers = itk::ObjectFactoryBase::CreateAllInstance(deserializerName.c_str());
00260 MITK_TEST_CONDITION(allDeserializers.size() > 0, std::string("Creating deserializers for ") + deserializerName);
00261 if (allDeserializers.size() == 0)
00262 {
00263 MITK_TEST_OUTPUT( << "deserialization not possible, skipping deserialization of " << prop->GetNameOfClass());
00264 continue;
00265 }
00266 if (allDeserializers.size() > 1)
00267 {
00268 MITK_TEST_OUTPUT (<< "Warning: " << allDeserializers.size() << " deserializers found for " << prop->GetNameOfClass() << "testing only the first one.");
00269 }
00270 mitk::BasePropertyDeserializer* deserializer = dynamic_cast<mitk::BasePropertyDeserializer*>( allDeserializers.begin()->GetPointer());
00271 MITK_TEST_CONDITION(deserializer != NULL, deserializerName + std::string(" is valid"));
00272 if (deserializer != NULL)
00273 {
00274 mitk::BaseProperty::Pointer deserializedProp = deserializer->Deserialize( valueelement );
00275 MITK_TEST_CONDITION(deserializedProp.IsNotNull(), "deserializer created valid property");
00276 if (deserializedProp.IsNotNull())
00277 {
00278 MITK_TEST_CONDITION(*(deserializedProp.GetPointer()) == *prop, "deserialized property equals initial property for type " << prop->GetNameOfClass());
00279 }
00280 }
00281 }
00282 else
00283 {
00284 MITK_TEST_OUTPUT( << "created serializer object is of class " << allSerializers.begin()->GetPointer()->GetNameOfClass())
00285 }
00286 }
00287 }