void mitk::SurfaceDeformationDataInteractor3D::ColorizeSurface(vtkPolyData* polyData, int timeStep, const Point3D &pickedPoint, int mode, double scalar)
{
    if (polyData == NULL)
        return;

    vtkPoints* points = polyData->GetPoints();
    vtkPointData* pointData = polyData->GetPointData();
    if ( pointData == NULL )
        return;

    vtkDataArray* scalars = pointData->GetScalars();
    if (scalars == NULL)
        return;

    if (mode == COLORIZATION_GAUSS)
    {
        // Get picked point and transform into local coordinates
        Point3D localPickedPoint;
        BaseGeometry::Pointer geometry = this->GetDataNode()->GetData()->GetGeometry(timeStep);
        geometry->WorldToIndex( pickedPoint, localPickedPoint );

        Vector3D v1 = localPickedPoint.GetVectorFromOrigin();

        vtkDataArray* normal = polyData->GetPointData()->GetVectors("planeNormal");
        if (normal != NULL)
        {
            m_ObjectNormal[0] = normal->GetComponent(0, 0);
            m_ObjectNormal[1] = normal->GetComponent(0, 1);
            m_ObjectNormal[2] = normal->GetComponent(0, 2);
        }

        double denom = m_GaussSigma * m_GaussSigma * 2;
        for (vtkIdType i = 0; i < points->GetNumberOfPoints(); ++i)
        {
            // Get original point
            double* point = points->GetPoint(i);
            Vector3D v0;
            v0[0] = point[0];
            v0[1] = point[1];
            v0[2] = point[2];

            // Calculate distance of this point from line through picked point
            double d = itk::CrossProduct(m_ObjectNormal, (v1 - v0)).GetNorm();
            double t = exp(- d * d / denom);

            scalars->SetComponent(i, 0, t);
        }
    }
    else if (mode == COLORIZATION_CONSTANT)
    {
        for (vtkIdType i = 0; i < pointData->GetNumberOfTuples(); ++i)
        {
            scalars->SetComponent(i, 0, scalar);
        }
    }
    polyData->Modified();
    pointData->Update();
}
void mitk::SurfaceDeformationDataInteractor3D::DeformObject (StateMachineAction*, InteractionEvent* interactionEvent)
{
    const InteractionPositionEvent* positionEvent = dynamic_cast<const InteractionPositionEvent*>(interactionEvent);
    if(positionEvent == NULL)
        return;

    int timeStep = interactionEvent->GetSender()->GetTimeStep(this->GetDataNode()->GetData());
    vtkPolyData* polyData = m_Surface->GetVtkPolyData(timeStep);
    BaseGeometry::Pointer geometry = this->GetDataNode()->GetData()->GetGeometry(timeStep);

    double currentWorldPoint[4];
    mitk::Point2D currentDisplayPoint = positionEvent->GetPointerPositionOnScreen();
    vtkInteractorObserver::ComputeDisplayToWorld(
        interactionEvent->GetSender()->GetVtkRenderer(),
        currentDisplayPoint[0],
        currentDisplayPoint[1],
        0.0, //m_InitialInteractionPickedPoint[2],
        currentWorldPoint);

    // Calculate mouse move in 3D space
    Vector3D interactionMove;
    interactionMove[0] = currentWorldPoint[0] - m_InitialPickedWorldPoint[0];
    interactionMove[1] = currentWorldPoint[1] - m_InitialPickedWorldPoint[1];
    interactionMove[2] = currentWorldPoint[2] - m_InitialPickedWorldPoint[2];

    // Transform mouse move into geometry space
    this->GetDataNode()->GetData()->UpdateOutputInformation();// make sure that the Geometry is up-to-date
    Vector3D interactionMoveIndex;
    geometry->WorldToIndex(interactionMove, interactionMoveIndex);

    // Get picked point and transform into local coordinates
    Point3D pickedPoint;
    geometry->WorldToIndex(m_InitialPickedPoint, pickedPoint);

    Vector3D v1 = pickedPoint.GetVectorFromOrigin();

    vtkDataArray* normal = polyData->GetPointData()->GetVectors("planeNormal");
    if (normal != NULL)
    {
        m_ObjectNormal[0] = normal->GetComponent(0, 0);
        m_ObjectNormal[1] = normal->GetComponent(0, 1);
        m_ObjectNormal[2] = normal->GetComponent(0, 2);
    }

    Vector3D v2 = m_ObjectNormal * (interactionMoveIndex * m_ObjectNormal);

    vtkPoints* originalPoints = m_OriginalPolyData->GetPoints();
    vtkPoints* deformedPoints = polyData->GetPoints();

    double denom = m_GaussSigma * m_GaussSigma * 2;
    double point[3];
    for (vtkIdType i = 0; i < deformedPoints->GetNumberOfPoints(); ++i)
    {
        // Get original point
        double* originalPoint = originalPoints->GetPoint( i );

        Vector3D v0;
        v0[0] = originalPoint[0];
        v0[1] = originalPoint[1];
        v0[2] = originalPoint[2];

        // Calculate distance of this point from line through picked point
        double d = itk::CrossProduct(m_ObjectNormal, (v1 - v0)).GetNorm();

        Vector3D t = v2 * exp(- d * d / denom);

        point[0] = originalPoint[0] + t[0];
        point[1] = originalPoint[1] + t[1];
        point[2] = originalPoint[2] + t[2];
        deformedPoints->SetPoint(i, point);
    }

    // Make sure that surface is colorized at initial picked position as long as we are in deformation state
    m_SurfaceColorizationCenter = m_InitialPickedPoint;

    polyData->Modified();
    m_Surface->Modified();

    interactionEvent->GetSender()->GetRenderingManager()->RequestUpdateAll();
}