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 mitkLookupTablePropertySerializer_h_included
00019 #define mitkLookupTablePropertySerializer_h_included
00020
00021 #include "mitkBasePropertySerializer.h"
00022
00023 #include "mitkLookupTableProperty.h"
00024
00025 #include "SceneSerializationBaseExports.h"
00026
00027 namespace mitk
00028 {
00029
00030 class SceneSerializationBase_EXPORT LookupTablePropertySerializer : public BasePropertySerializer
00031 {
00032 public:
00033
00034 mitkClassMacro( LookupTablePropertySerializer, BasePropertySerializer );
00035 itkNewMacro(Self);
00036
00037 virtual TiXmlElement* Serialize()
00038 {
00039 if (const LookupTableProperty* prop = dynamic_cast<const LookupTableProperty*>(m_Property.GetPointer()))
00040 {
00041 LookupTable::Pointer mitkLut = const_cast<LookupTableProperty*>(prop)->GetLookupTable();
00042 if (mitkLut.IsNull()) return NULL;
00043
00044 vtkLookupTable* lut = mitkLut->GetVtkLookupTable();
00045 if (!lut) return NULL;
00046
00047 TiXmlElement* element = new TiXmlElement("LookupTable");
00048
00049 #if ( (VTK_MAJOR_VERSION < 5) && (VTK_MINOR_VERSION < 4) )
00050 float* range;
00051 float* rgba;
00052 #else
00053 double* range;
00054 double* rgba;
00055 #endif
00056
00057 element->SetAttribute("NumberOfColors", lut->GetNumberOfTableValues());
00058 element->SetAttribute("Scale", lut->GetScale());
00059 element->SetAttribute("Ramp", lut->GetRamp());
00060
00061 range = lut->GetHueRange();
00062 TiXmlElement* child = new TiXmlElement("HueRange");
00063 element->LinkEndChild( child );
00064 child->SetDoubleAttribute("min", range[0]);
00065 child->SetDoubleAttribute("max", range[1]);
00066
00067 range = lut->GetValueRange();
00068 child = new TiXmlElement("ValueRange");
00069 element->LinkEndChild( child );
00070 child->SetDoubleAttribute("min", range[0]);
00071 child->SetDoubleAttribute("max", range[1]);
00072
00073 range = lut->GetSaturationRange();
00074 child = new TiXmlElement("SaturationRange");
00075 element->LinkEndChild( child );
00076 child->SetDoubleAttribute("min", range[0]);
00077 child->SetDoubleAttribute("max", range[1]);
00078
00079 range = lut->GetAlphaRange();
00080 child = new TiXmlElement("AlphaRange");
00081 element->LinkEndChild( child );
00082 child->SetDoubleAttribute("min", range[0]);
00083 child->SetDoubleAttribute("max", range[1]);
00084
00085 range = lut->GetTableRange();
00086 child = new TiXmlElement("TableRange");
00087 element->LinkEndChild( child );
00088 child->SetDoubleAttribute("min", range[0]);
00089 child->SetDoubleAttribute("max", range[1]);
00090
00091 child = new TiXmlElement("Table");
00092 element->LinkEndChild( child );
00093 for ( int index = 0; index < lut->GetNumberOfTableValues(); ++index)
00094 {
00095 TiXmlElement* grandChildNinife = new TiXmlElement("RgbaColor");
00096 rgba = lut->GetTableValue(index);
00097 grandChildNinife->SetDoubleAttribute("R", rgba[0]);
00098 grandChildNinife->SetDoubleAttribute("G", rgba[1]);
00099 grandChildNinife->SetDoubleAttribute("B", rgba[2]);
00100 grandChildNinife->SetDoubleAttribute("A", rgba[3]);
00101 child->LinkEndChild( grandChildNinife );
00102 }
00103 return element;
00104 }
00105 else return NULL;
00106 }
00107
00108 protected:
00109
00110 LookupTablePropertySerializer() {}
00111 virtual ~LookupTablePropertySerializer() {}
00112 };
00113
00114 }
00115
00116
00117 MITK_REGISTER_SERIALIZER(LookupTablePropertySerializer);
00118
00119 #endif
00120