Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef mitkLookupTablePropertyDeserializer_h_included
00019 #define mitkLookupTablePropertyDeserializer_h_included
00020
00021 #include "mitkBasePropertyDeserializer.h"
00022
00023 #include "mitkLookupTableProperty.h"
00024
00025 #include "SceneSerializationBaseExports.h"
00026
00027 namespace mitk
00028 {
00029
00030 class SceneSerializationBase_EXPORT LookupTablePropertyDeserializer : public BasePropertyDeserializer
00031 {
00032 public:
00033
00034 mitkClassMacro( LookupTablePropertyDeserializer, BasePropertyDeserializer );
00035 itkNewMacro(Self);
00036
00037 virtual BaseProperty::Pointer Deserialize(TiXmlElement* element)
00038 {
00039 if (!element) return NULL;
00040
00041 #if ( (VTK_MAJOR_VERSION < 5) && (VTK_MINOR_VERSION < 4) )
00042 typedef float OUR_VTK_FLOAT_TYPE;
00043 float range[2];
00044 float rgba[4];
00045 #else
00046 typedef double OUR_VTK_FLOAT_TYPE;
00047 double range[2];
00048 double rgba[4];
00049 #endif
00050
00051 double d;
00052
00053 vtkLookupTable* lut = vtkLookupTable::New();
00054
00055 int numberOfColors;
00056 int scale;
00057 int ramp;
00058 if ( element->QueryIntAttribute( "NumberOfColors", &numberOfColors ) == TIXML_SUCCESS )
00059 {
00060 lut->SetNumberOfTableValues( numberOfColors );
00061 }
00062 else
00063 return NULL;
00064 if ( element->QueryIntAttribute( "Scale", &scale ) == TIXML_SUCCESS )
00065 {
00066 lut->SetScale( scale );
00067 }
00068 else
00069 return NULL;
00070 if ( element->QueryIntAttribute( "Ramp", &ramp ) == TIXML_SUCCESS )
00071 {
00072 lut->SetRamp( ramp );
00073 }
00074 else
00075 return NULL;
00076
00077 TiXmlElement* child = element->FirstChildElement("HueRange");
00078 if (child)
00079 {
00080 if ( child->QueryDoubleAttribute( "min", &d ) != TIXML_SUCCESS )
00081 return NULL;
00082 range[0] = static_cast<OUR_VTK_FLOAT_TYPE>(d);
00083 if ( child->QueryDoubleAttribute( "max", &d ) != TIXML_SUCCESS )
00084 return NULL;
00085 range[1] = static_cast<OUR_VTK_FLOAT_TYPE>(d);
00086 lut->SetHueRange( range );
00087 }
00088
00089 child = element->FirstChildElement("ValueRange");
00090 if (child)
00091 {
00092 if ( child->QueryDoubleAttribute( "min", &d ) != TIXML_SUCCESS ) return NULL; range[0] = static_cast<OUR_VTK_FLOAT_TYPE>(d);
00093 if ( child->QueryDoubleAttribute( "max", &d ) != TIXML_SUCCESS ) return NULL; range[1] = static_cast<OUR_VTK_FLOAT_TYPE>(d);
00094 lut->SetValueRange( range );
00095 }
00096
00097 child = element->FirstChildElement("SaturationRange");
00098 if (child)
00099 {
00100 if ( child->QueryDoubleAttribute( "min", &d ) != TIXML_SUCCESS ) return NULL; range[0] = static_cast<OUR_VTK_FLOAT_TYPE>(d);
00101 if ( child->QueryDoubleAttribute( "max", &d ) != TIXML_SUCCESS ) return NULL; range[1] = static_cast<OUR_VTK_FLOAT_TYPE>(d);
00102 lut->SetSaturationRange( range );
00103 }
00104
00105 child = element->FirstChildElement("AlphaRange");
00106 if (child)
00107 {
00108 if ( child->QueryDoubleAttribute( "min", &d ) != TIXML_SUCCESS ) return NULL; range[0] = static_cast<OUR_VTK_FLOAT_TYPE>(d);
00109 if ( child->QueryDoubleAttribute( "max", &d ) != TIXML_SUCCESS ) return NULL; range[1] = static_cast<OUR_VTK_FLOAT_TYPE>(d);
00110 lut->SetAlphaRange( range );
00111 }
00112
00113 child = element->FirstChildElement("TableRange");
00114 if (child)
00115 {
00116 if ( child->QueryDoubleAttribute( "min", &d ) != TIXML_SUCCESS ) return NULL; range[0] = static_cast<OUR_VTK_FLOAT_TYPE>(d);
00117 if ( child->QueryDoubleAttribute( "max", &d ) != TIXML_SUCCESS ) return NULL; range[1] = static_cast<OUR_VTK_FLOAT_TYPE>(d);
00118 lut->SetTableRange( range );
00119 }
00120
00121 child = element->FirstChildElement("Table");
00122 if (child)
00123 {
00124 unsigned int index(0);
00125 for( TiXmlElement* grandChild = child->FirstChildElement("RgbaColor"); grandChild; grandChild = grandChild->NextSiblingElement("RgbaColor"))
00126 {
00127 if ( grandChild->QueryDoubleAttribute("R", &d) != TIXML_SUCCESS ) return NULL; rgba[0] = static_cast<OUR_VTK_FLOAT_TYPE>(d);
00128 if ( grandChild->QueryDoubleAttribute("G", &d) != TIXML_SUCCESS ) return NULL; rgba[1] = static_cast<OUR_VTK_FLOAT_TYPE>(d);
00129 if ( grandChild->QueryDoubleAttribute("B", &d) != TIXML_SUCCESS ) return NULL; rgba[2] = static_cast<OUR_VTK_FLOAT_TYPE>(d);
00130 if ( grandChild->QueryDoubleAttribute("A", &d) != TIXML_SUCCESS ) return NULL; rgba[3] = static_cast<OUR_VTK_FLOAT_TYPE>(d);
00131
00132 lut->SetTableValue( index, rgba );
00133 ++index;
00134 }
00135 }
00136
00137 LookupTable::Pointer mitkLut = LookupTable::New();
00138 mitkLut->SetVtkLookupTable( lut );
00139
00140 lut->Delete();
00141
00142 return LookupTableProperty::New(mitkLut).GetPointer();
00143 }
00144
00145 protected:
00146
00147 LookupTablePropertyDeserializer() {}
00148 virtual ~LookupTablePropertyDeserializer() {}
00149 };
00150
00151 }
00152
00153
00154 MITK_REGISTER_SERIALIZER(LookupTablePropertyDeserializer);
00155
00156 #endif
00157