# Path: possum/pos_itk_transforms.py
# def read_transformation_txt_file(transformation_file):
# def load_itk_matrix_transform_from_file(filename):
# def write_itk_matrix_transformation_to_file(transformation, filename):
# def load_warp_field_transform_from_file(warp_filed_filename):
# def reslice_image(transforms, moving_image, reference_image=None, interpolator=None, \
#         default_pixel_value=0):
# def read_itk_image(image_filename):
# def write_itk_image(image_to_save, filename):
# def itk_read_transformations_from_files(transformation_files):
# def apply_transformation_workflow(moving_file, output_file, reference_file, transformation_list=None):
# def itk_coordinate_map(input_image, physical=True):


import os, sys
import numpy as np
import pickle
import itk
from config import Config
from possum import pos_itk_transforms
    transform.SetTranslation(list(translations))
    transform.SetRotation(rotations)
    transform.SetCenter(CONFIG['slice_image_center'])

    return transform


def apply_transformation_workflow(moving_file, output_file, output_transform_file=None):
    """
    """
    moving_image = pos_itk_transforms.read_itk_image(moving_file)

    translation, rotation = get_random_rigid_3d_tranform_parameters(
        tmean=CONFIG['tmean'], tsigma=CONFIG['tsigma'],
        rmean=CONFIG['rmean'], rsigma=CONFIG['rsigma'])

    vol_transform = itk.Euler3DTransform.D.New()
    vol_transform.SetTranslation([0, 0, 0])
    vol_transform.SetRotation(*list(rotation))

    center = [0, 0, 0]
    center[0] = moving_image.GetLargestPossibleRegion().GetSize()[0]/2
    center[1] = moving_image.GetLargestPossibleRegion().GetSize()[1]/2
    center[2] = moving_image.GetLargestPossibleRegion().GetSize()[2]/2
    center = map(int, center) # Sometimes the indexes are returned as long ints
    phisycal_center = moving_image.TransformIndexToPhysicalPoint(center)
    vol_transform.SetCenter(phisycal_center)

    resliced_image = pos_itk_transforms.reslice_image([vol_transform],
        moving_image, default_pixel_value=CONFIG['default_pixel_value'])

# Path: possum/pos_itk_transforms.py
# def read_transformation_txt_file(transformation_file):
# def load_itk_matrix_transform_from_file(filename):
# def write_itk_matrix_transformation_to_file(transformation, filename):
# def load_warp_field_transform_from_file(warp_filed_filename):
# def reslice_image(transforms, moving_image, reference_image=None, interpolator=None, \
#         default_pixel_value=0):
# def read_itk_image(image_filename):
# def write_itk_image(image_to_save, filename):
# def itk_read_transformations_from_files(transformation_files):
# def apply_transformation_workflow(moving_file, output_file, reference_file, transformation_list=None):
# def itk_coordinate_map(input_image, physical=True):


# Path: test/test_banana_effect/step_001_distort_reference_image.py
import os, sys
import numpy as np
import pickle
import itk
from config import Config
from possum import pos_itk_transforms

    transform.SetTranslation(list(translations))
    transform.SetRotation(rotations)
    transform.SetCenter(CONFIG['slice_image_center'])

    return transform


def apply_transformation_workflow(moving_file, output_file, output_transform_file=None):
    """
    """
    moving_image = pos_itk_transforms.read_itk_image(moving_file)

    translation, rotation = get_random_rigid_3d_tranform_parameters(
        tmean=CONFIG['tmean'], tsigma=CONFIG['tsigma'],
        rmean=CONFIG['rmean'], rsigma=CONFIG['rsigma'])

    vol_transform = itk.Euler3DTransform.D.New()
    vol_transform.SetTranslation([0, 0, 0])
    vol_transform.SetRotation(*list(rotation))

    center = [0, 0, 0]
    center[0] = moving_image.GetLargestPossibleRegion().GetSize()[0]/2
    center[1] = moving_image.GetLargestPossibleRegion().GetSize()[1]/2
    center[2] = moving_image.GetLargestPossibleRegion().GetSize()[2]/2
    center = map(int, center) # Sometimes the indexes are returned as long ints
    phisycal_center = moving_image.TransformIndexToPhysicalPoint(center)
    vol_transform.SetCenter(phisycal_center)

    resliced_image = pos_itk_transforms.reslice_image([vol_transform],
        moving_image, default_pixel_value=CONFIG['default_pixel_value'])

    pos_itk_transforms.write_itk_image(resliced_image, output_file)