void VolumeVisualizationImagePreprocessor::UpdateTransferFunction( TransferFunction::Pointer tf, int treshold  )
{
  double opacity = 0.005;

  //double maskValue = m_OutOfLiverValue;
  //double surfaceValue = m_surfaceValue;
  //double realSurfaceValue = m_realSurfaceValue;

  //double surfaceSteepness = 0.0;

  //VVP_INFO << "changing to threshold of " << treshold << " and opacity of " << opacity;

  // grayvalue->opacity
  {   
    vtkPiecewiseFunction *f=tf->GetScalarOpacityFunction();
    
    f->RemovePoint( m_LastUsedTreshold-1 );
    f->AddPoint(treshold-1,opacity); 
   
    f->RemovePoint( m_LastUsedTreshold+4 );
    f->AddPoint(treshold+4,0.8); 
  }  

  // grayvalue->color
  {  
    vtkColorTransferFunction *ctf=tf->GetColorTransferFunction();

    ctf->RemovePoint( m_LastUsedTreshold-32 );
    ctf->AddRGBPoint( treshold-32, 0.2, 0.0, 0.0 );
    
    ctf->RemovePoint( m_LastUsedTreshold );
    ctf->AddRGBPoint( treshold, 251/255.0, 1.0, 0.0 );
  }

  m_LastUsedTreshold = treshold;
}
TransferFunction::Pointer
VolumeVisualizationImagePreprocessor::GetInitialTransferFunction(  )
{
  int treshold = m_EstimatedThreshold;

  double opacity = 0.005;

  double maskValue = m_OutOfLiverValue;
  double surfaceValue = m_surfaceValue;
  double realSurfaceValue = m_realSurfaceValue;

  //double surfaceSteepness = 0.0;

  VVP_INFO << "using threshold of " << treshold << " and opacity of " << opacity;

  TransferFunction::Pointer tf = TransferFunction::New();

  // grayvalue->opacity
  {   
    vtkPiecewiseFunction *f=tf->GetScalarOpacityFunction();
    f->RemoveAllPoints();
    f->AddPoint(maskValue,0);
    f->AddPoint(maskValue+1,0);
    f->AddPoint(surfaceValue,0.05);
    f->AddPoint(realSurfaceValue,opacity);
    f->AddPoint(treshold-1,opacity); 
    f->AddPoint(treshold+4,0.8); 
    f->AddPoint(m_MaxThreshold+1,0.8); 
    f->ClampingOn();
    f->Modified();
  }  

  // gradient at grayvalue->opacity
  {  
    vtkPiecewiseFunction *f=tf->GetGradientOpacityFunction();
    f->RemoveAllPoints();
    f->AddPoint( -1000.0, 1.0 );
    f->AddPoint( 1000, 1.0 );
    f->ClampingOn();
    f->Modified();
  }

  // grayvalue->color
  {  
    vtkColorTransferFunction *ctf=tf->GetColorTransferFunction();
    ctf->RemoveAllPoints();
    ctf->AddRGBPoint( maskValue, 0.5, 0.0, 0.0 );
    ctf->AddRGBPoint( maskValue+1, 0.5, 0.0, 0.0 );
    ctf->AddRGBPoint( surfaceValue, 1.0, 0.0, 0.0 ); //0.5
    ctf->AddRGBPoint( realSurfaceValue, 0.2, 0.0, 0.0 );

    ctf->AddRGBPoint( treshold-32, 0.2, 0.0, 0.0 );
    ctf->AddRGBPoint( treshold, 251/255.0, 1.0, 0.0 );
    ctf->AddRGBPoint( m_MaxThreshold+1, 251/255.0, 1.0, 0.0 );

    ctf->ClampingOn();
    ctf->Modified();
  }

  m_LastUsedTreshold = treshold;

  return tf;
}