void TransferFunction::SetGradientOpacityPoints(TransferFunction::ControlPoints points)
{
  m_GradientOpacityFunction->RemoveAllPoints();
  for(unsigned int i=0; i<=points.size()-1;i++)
  {
    this->AddGradientOpacityPoint(points[i].first, points[i].second);
  }
}
TiXmlElement* mitk::TransferFunctionPropertySerializer::Serialize()
{
  if (const TransferFunctionProperty* prop = dynamic_cast<const TransferFunctionProperty*>(mitk::BasePropertySerializer::m_Property.GetPointer()))
  {
    TransferFunction* transferfunction = prop->GetValue();
    if (!transferfunction) 
      return NULL;

    TiXmlElement* element = new TiXmlElement("TransferFunction");

    // serialize scalar opacity function
    TiXmlElement* scalarOpacityPointlist = new TiXmlElement( "ScalarOpacity" );

    TransferFunction::ControlPoints scalarOpacityPoints = transferfunction->GetScalarOpacityPoints();
    for ( TransferFunction::ControlPoints::iterator iter = scalarOpacityPoints.begin();
      iter != scalarOpacityPoints.end();
      ++iter )
    {
      TiXmlElement* pointel = new TiXmlElement("point");
      pointel->SetDoubleAttribute("x", iter->first);
      pointel->SetDoubleAttribute("y", iter->second);
      scalarOpacityPointlist->LinkEndChild( pointel );
    }
    element->LinkEndChild( scalarOpacityPointlist );
    // serialize gradient opacity function
    TiXmlElement* gradientOpacityPointlist = new TiXmlElement( "GradientOpacity" );
    TransferFunction::ControlPoints gradientOpacityPoints = transferfunction->GetGradientOpacityPoints();
    for ( TransferFunction::ControlPoints::iterator iter = gradientOpacityPoints.begin();
      iter != gradientOpacityPoints.end();
      ++iter )
    {
      TiXmlElement* pointel = new TiXmlElement("point");
      pointel->SetDoubleAttribute("x", iter->first);
      pointel->SetDoubleAttribute("y", iter->second);
      gradientOpacityPointlist->LinkEndChild( pointel );
    }
    element->LinkEndChild( gradientOpacityPointlist );

    // serialize color function
    vtkColorTransferFunction* ctf = transferfunction->GetColorTransferFunction();
    if (ctf == NULL)
      return NULL;
    TiXmlElement* pointlist = new TiXmlElement("Color");
    for (int i = 0; i < ctf->GetSize(); i++ )
    {
      double myVal[6];
      ctf->GetNodeValue(i, myVal);
      TiXmlElement* pointel = new TiXmlElement("point");
      pointel->SetDoubleAttribute("x", myVal[0]);
      pointel->SetDoubleAttribute("r", myVal[1]);
      pointel->SetDoubleAttribute("g", myVal[2]);
      pointel->SetDoubleAttribute("b", myVal[3]);
      pointel->SetDoubleAttribute("midpoint", myVal[4]);
      pointel->SetDoubleAttribute("sharpness", myVal[5]);
      pointlist->LinkEndChild( pointel );
    }
    element->LinkEndChild( pointlist );
    return element;
  }
  else return NULL;
}
TiXmlElement* mitk::TransferFunctionPropertySerializer::Serialize()
{
  if (const TransferFunctionProperty* prop = dynamic_cast<const TransferFunctionProperty*>(mitk::BasePropertySerializer::m_Property.GetPointer()))
  {
    LocaleSwitch localeSwitch("C");

    TransferFunction* transferfunction = prop->GetValue();
    if (!transferfunction)
      return nullptr;

    auto  element = new TiXmlElement("TransferFunction");

    // serialize scalar opacity function
    auto  scalarOpacityPointlist = new TiXmlElement( "ScalarOpacity" );

    TransferFunction::ControlPoints scalarOpacityPoints = transferfunction->GetScalarOpacityPoints();
    for ( auto iter = scalarOpacityPoints.begin();
      iter != scalarOpacityPoints.end();
      ++iter )
    {
      auto  pointel = new TiXmlElement("point");
      pointel->SetAttribute("x", boost::lexical_cast<std::string>(iter->first));
      pointel->SetAttribute("y", boost::lexical_cast<std::string>(iter->second));
      scalarOpacityPointlist->LinkEndChild( pointel );
    }
    element->LinkEndChild( scalarOpacityPointlist );
    // serialize gradient opacity function
    auto  gradientOpacityPointlist = new TiXmlElement( "GradientOpacity" );
    TransferFunction::ControlPoints gradientOpacityPoints = transferfunction->GetGradientOpacityPoints();
    for ( auto iter = gradientOpacityPoints.begin();
      iter != gradientOpacityPoints.end();
      ++iter )
    {
      auto  pointel = new TiXmlElement("point");
      pointel->SetAttribute("x", boost::lexical_cast<std::string>(iter->first));
      pointel->SetAttribute("y", boost::lexical_cast<std::string>(iter->second));
      gradientOpacityPointlist->LinkEndChild( pointel );
    }
    element->LinkEndChild( gradientOpacityPointlist );

    // serialize color function
    vtkColorTransferFunction* ctf = transferfunction->GetColorTransferFunction();
    if (ctf == nullptr)
      return nullptr;
    auto  pointlist = new TiXmlElement("Color");
    for (int i = 0; i < ctf->GetSize(); i++ )
    {
      double myVal[6];
      ctf->GetNodeValue(i, myVal);
      auto  pointel = new TiXmlElement("point");
      pointel->SetAttribute("x", boost::lexical_cast<std::string>(myVal[0]));
      pointel->SetAttribute("r", boost::lexical_cast<std::string>(myVal[1]));
      pointel->SetAttribute("g", boost::lexical_cast<std::string>(myVal[2]));
      pointel->SetAttribute("b", boost::lexical_cast<std::string>(myVal[3]));
      pointel->SetAttribute("midpoint", boost::lexical_cast<std::string>(myVal[4]));
      pointel->SetAttribute("sharpness", boost::lexical_cast<std::string>(myVal[5]));
      pointlist->LinkEndChild( pointel );
    }
    element->LinkEndChild( pointlist );
    return element;
  }
  else return nullptr;
}