import iDISCO.Alignment.Elastix as elx;

import iDISCO.Analysis.Voxelization as vox
import iDISCO.IO.IO as io

elx.initializeElastix('/home/ckirst/programs/elastix')
elx.ElastixSettings.printInfo()

verbose = True;

parameter.Alignment.AlignmentDirectory = os.path.join(basedirectory, 'Synthetic/elastix');

rcenters = numpy.array([[0,0,0],[0,52,0], [0,0,23], [74,0,0],[74,52,0]]);

#acenters = elx.transformPoints(rcenters, alignmentdirectory = parameter.Alignment.AlignmentDirectory, outdirectory = pointsdir);
acenters = elx.transformPoints(rcenters, alignmentdirectory = parameter.Alignment.AlignmentDirectory);

print acenters





##############################################################################
# Test Transform data
############################################################################## 

from iDISCO.Parameter import *
import iDISCO.Alignment.Elastix as elx
import iDISCO.Visualization.Plot as Plot
import iDISCO.IO.IO as io
import iDISCO.Alignment.Elastix as elx;

verbose = True;

# directory in with elastix alignment result 
transformDirectory  =  os.path.join(baseDirectory, 'Synthetic/elastix');

#result diectory to write transformed points to (None = read back as array)
resultDirectory    = os.path.join(baseDirectory, 'Synthetic/transformix')

#define (y,x,z) coordinates for testing
points = numpy.array([[0,0,0],[74,0,0],[0,52,0],[0,0,23],[74,52,0]]);

#acenters = elx.transformPoints(rcenters, alignmentdirectory = parameter.Alignment.AlignmentDirectory, outdirectory = pointsdir);
pointsa = elx.transformPoints(points, resultDirectory = resultDirectory, transformDirectory = transformDirectory);

print(pointsa)



##############################################################################
# Test Transform Reference to Resampled Data
############################################################################## 

import os

import iDISCO.Settings as settings

import iDISCO.IO.IO as io
import iDISCO.Alignment.Elastix as elx
elx.ElastixSettings.printInfo()

verbose = True

parameter.Alignment.AlignmentDirectory = os.path.join(basedirectory, 'elastix')

#rcenters = numpy.array([[0,0,0],[0,52,0], [0,0,23], [74,0,0],[74,52,0]]);

#acenters = elx.transformPoints(rcenters, alignmentdirectory = parameter.Alignment.AlignmentDirectory, outdirectory = pointsdir);

#rcenters = io.readPoints(os.path.join(basedirectory, 'cells_resampled.csv'));

rcenters2 = rcenters.copy()
rcenters2 = rcenters2[:, [1, 0, 2]]
print(rcenters2.shape)

acenters = elx.transformPoints(
    rcenters2, alignmentdirectory=parameter.Alignment.AlignmentDirectory)

acenters2 = acenters.copy()
acenters2 = acenters2[:, [1, 0, 2]]

#print acenters

#rdata = io.readData(os.path.join(basedirectory, 'autofluo_resample.tif'));
rdata = io.readData(os.path.join(basedirectory, 'half_template_25_right.tif'))

voximg = vox.voxelizePixel(acenters2, rdata.shape) * 5000
io.writeDataStack(os.path.join(basedirectory, 'cells_transformed.tif'),
                  voximg.astype('int16'))
import iDISCO.Alignment.Elastix as elx;

verbose = True;

# directory in with elastix alignment result 
transformDirectory  =  os.path.join(baseDirectory, 'Synthetic/elastix');

#result diectory to write transformed points to (None = read back as array)
resultDirectory    = os.path.join(baseDirectory, 'Synthetic/transformix')

#define (y,x,z) coordinates for testing
points = numpy.array([[0,0,0],[74,0,0],[0,52,0],[0,0,23],[74,52,0]]);

#acenters = elx.transformPoints(rcenters, alignmentdirectory = parameter.Alignment.AlignmentDirectory, outdirectory = pointsdir);
pointsa = elx.transformPoints(points, resultDirectory = resultDirectory, transformDirectory = transformDirectory);

print pointsa



##############################################################################
# Test Transform Reference to Resampled Data
############################################################################## 

import os

import iDISCO.Settings as settings

import iDISCO.IO.IO as io
import iDISCO.Alignment.Elastix as elx