Skip to content

Commit

Permalink
Merge pull request #3 from bcdarwin/develop
Browse files Browse the repository at this point in the history
fix compilation against static hdf5 libs
  • Loading branch information
Matthijs van Eede authored Aug 16, 2016
2 parents e33cb3b + df7e665 commit 0d16288
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 59 deletions.
1 change: 1 addition & 0 deletions m4/mni_REQUIRE_MNILIBS.m4
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ AC_DEFUN([mni_REQUIRE_MINC],
mni_REQUIRE_LIB(netcdf,[#include <netcdf.h>],[int i = ncopen("",0);])
if test "$with_minc2" = "yes"; then
mni_REQUIRE_LIB(z,[#include <zlib.h>],[int f = compress2;])
mni_REQUIRE_LIB(dl,[#include <dlfcn.h>],[int f = dlopen("",0)])
mni_REQUIRE_LIB(hdf5,[#include <hdf5.h>],[int f = H5Fopen("",0,H5P_DEFAULT);])
mni_REQUIRE_LIB(minc2,[#include <minc.h>],[int i = miicv_create();])
AC_DEFINE([MINC2], 1, [Define if should build with MINC 2.0])
Expand Down
12 changes: 6 additions & 6 deletions scripts/blur_determinant.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ def impose_minc2_ness(minc_file, temp_dir):
return minc_file
# convert the file to the minc2 format
else:
print "\nThe input file is not in MINC2 format, converting now..."
print("\nThe input file is not in MINC2 format, converting now...")
filename = os.path.basename(minc_file)
basename = filename.replace('.mnc', '')
minc_2_output = "%s/%s_minc2.mnc" % (temp_dir, basename)
command = "mincconvert -clobber -2 %s %s" % \
(minc_file, minc_2_output)
if g_verbose:
print "\n%s" % command
print("\n%s" % command)
os.system(command)
if not os.access(minc_2_output,0):
print "\nERROR: could not create minc2 volume %s!" % minc_2_output
print("\nERROR: could not create minc2 volume %s!" % minc_2_output)
exit(1)
else:
print "done!"
print("done!")
return minc_2_output


Expand Down Expand Up @@ -64,7 +64,7 @@ def blur_minc_file(minc_file, blur_kernel, temp_dir):
% (blur_kernel, minc_file, blurbase)
os.system(command)
if not os.access(bluroutput,0):
print "\nERROR: could not create blurred volume %s!" % bluroutput
print("\nERROR: could not create blurred volume %s!" % bluroutput)
exit(1)
return bluroutput

Expand Down Expand Up @@ -143,4 +143,4 @@ def unpad_minc_file(minc_file, outputname, temp_dir):
if not options.keeptemp:
os.system("rm -fr %s" % g_tmpdir)

print "\ndone!\n\n"
print("\ndone!\n\n")
90 changes: 45 additions & 45 deletions scripts/create_deformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,41 @@ def impose_minc2_ness(minc_file, temp_dir):
return minc_file
# convert the file to the minc2 format
else:
print "\nThe input file is not in MINC2 format, converting now..."
print("\nThe input file is not in MINC2 format, converting now...")
filename = os.path.basename(minc_file)
basename = filename.replace('.mnc', '')
minc_2_output = "%s/%s_minc2.mnc" % (temp_dir, basename)
command = "mincconvert -clobber -2 %s %s" % \
(minc_file, minc_2_output)
if g_verbose:
print "\n%s" % command
print("\n%s" % command)
os.system(command)
if not os.access(minc_2_output,0):
print "\nERROR: could not create minc2 volume %s!\n" % minc_2_output
print("\nERROR: could not create minc2 volume %s!\n" % minc_2_output)
exit(1)
else:
print "done converting file to MINC2!\n"
print("done converting file to MINC2!\n")
return minc_2_output

# make sure input file has the z,y,x dimension order
def impose_zyx_ness(minc_file, temp_dir):
dimorder = os.popen("mincinfo -attvalue image:dimorder %s" % (minc_file)).readlines()[-1]
dimorder_array = dimorder.split(',')
if(not(dimorder_array[0] == "zspace" and dimorder_array[1] == "yspace" and dimorder_array[2] == "xspace")):
print "\n The dimension order of %s is not in standard (zspace,yspace,xspace) order, converting now..." % minc_file
print("\n The dimension order of %s is not in standard (zspace,yspace,xspace) order, converting now..." % minc_file)
filename = os.path.basename(minc_file)
basename = filename.replace('.mnc', '')
zyx_output = "%s/%s_zyx.mnc" % (temp_dir, basename)
command = "mincreshape -double -dimorder zspace,yspace,xspace -clobber -2 %s %s" % \
(minc_file, zyx_output)
if g_verbose:
print "\n%s" % command
print("\n%s" % command)
os.system(command)
if not os.access(zyx_output,0):
print "\nERROR: could not create volume with the correct dimension order %s!" % zyx_output
print("\nERROR: could not create volume with the correct dimension order %s!" % zyx_output)
exit(1)
else:
print "done correcting dimension order!"
print("done correcting dimension order!")
return zyx_output
else:
return minc_file
Expand All @@ -74,7 +74,7 @@ def create_initial_deformation(minc_file, temp_dir):
command = "create_initial_deformation_grid -clobber %s %s" \
% (minc_file, grid_output)
if g_verbose:
print("\n%s" % command)
print(("\n%s" % command))
os.system(command)
return grid_output

Expand All @@ -83,11 +83,11 @@ def get_determinant_from_grid(grid, output):
tempfile = output.replace('.mnc', '_temp.mnc')
command = "mincblob -clobber -determinant %s %s" % (grid, tempfile)
if g_verbose:
print("\n%s" % command)
print(("\n%s" % command))
os.system(command)
command = "mincmath -quiet -clobber -const 1 -add %s %s" % (tempfile, output)
if g_verbose:
print("\n%s" % command)
print(("\n%s" % command))
os.system(command)
return output

Expand Down Expand Up @@ -178,9 +178,9 @@ def write_out_intermediate_grid():
g_tmpdir = "%s/tmp_deformation_%s_%s" % (g_temp_prefix,pid,counter)
os.mkdir(g_tmpdir)

print "\n\n###"
print "### Directory used for temporary files: %s" % (g_tmpdir)
print "###\n"
print("\n\n###")
print("### Directory used for temporary files: %s" % (g_tmpdir))
print("###\n")

# check whether the input file is in zyx direction, if not create a
# correct version of it
Expand All @@ -190,9 +190,9 @@ def write_out_intermediate_grid():
g_minc2_input = impose_minc2_ness(g_zyx_det_input, g_tmpdir)

# create the inital deformation grid (with all zero vectors)
print "\n###"
print "### Creating initial deformation grid (all zero vectors)"
print "###\n"
print("\n###")
print("### Creating initial deformation grid (all zero vectors)")
print("###\n")
g_initial_deformation_grid = create_initial_deformation(g_minc2_input, g_tmpdir)

##########################
Expand All @@ -201,15 +201,15 @@ def write_out_intermediate_grid():

# Load data in memory
# 1) the input determinant file
print "\n###"
print "### Reading the target determinant file: %s" % (g_minc2_input)
print "###\n"
print("\n###")
print("### Reading the target determinant file: %s" % (g_minc2_input))
print("###\n")
g_target_determinant = volumeFromFile(g_minc2_input, dtype="double")
g_target_determinant.data
# 2) a copy of the grid file which will hold the evolving grid
print "\n###"
print "### Reading the initial deformation grid: %s" % (g_initial_deformation_grid)
print "###\n"
print("\n###")
print("### Reading the initial deformation grid: %s" % (g_initial_deformation_grid))
print("###\n")
g_initial_grid = volumeFromFile(g_initial_deformation_grid, dtype="double")
g_initial_grid.data
g_filename = os.path.basename(g_initial_deformation_grid)
Expand All @@ -233,9 +233,9 @@ def write_out_intermediate_grid():
g_filename = os.path.basename(g_evolving_grid.filename)
g_basename = g_filename.replace('.mnc', '')
g_evolving_determinant_name = "%s/%s_determinant.mnc" % (g_tmpdir, g_basename)
print "\n###"
print "### Creating evolving determinant file: %s" % (g_evolving_determinant_name)
print "###\n"
print("\n###")
print("### Creating evolving determinant file: %s" % (g_evolving_determinant_name))
print("###\n")
g_evolving_determinant = volumeFromInstance(g_target_determinant,
g_evolving_determinant_name,
dtype="double",
Expand All @@ -247,23 +247,23 @@ def write_out_intermediate_grid():
g_xstep = float(g_evolving_determinant.separations[2])
g_ystep = float(g_evolving_determinant.separations[1])
g_zstep = float(g_evolving_determinant.separations[0])
print "\n###"
print "### File resolution (x,y,z): %f,%f,%f" % (g_xstep,g_ystep,g_zstep)
print "###\n"
print("\n###")
print("### File resolution (x,y,z): %f,%f,%f" % (g_xstep,g_ystep,g_zstep))
print("###\n")
if(options.neighbors == 6):
cython_code_generate_deformation_fields.calculate_determinant_from_grid(g_evolving_grid.data, g_evolving_determinant.data, g_xstep, g_ystep, g_zstep)
elif(options.neighbors == 14):
cython_code_generate_deformation_fields.calculate_determinant_from_grid_14_neighbors(g_evolving_grid.data, g_evolving_determinant.data, g_xstep, g_ystep, g_zstep)
else:
print "Can't calculate the determinant given the number of neighbors: %s" % options.neighbors
print("Can't calculate the determinant given the number of neighbors: %s" % options.neighbors)
exit(1)

# 4) tolerance map data:
# initialize data
g_tolerance_map_name = "%s/temp_map_tolerance.mnc" % (g_tmpdir)
print "\n###"
print "### Initializing temporary tolerance map: %s" % (g_tolerance_map_name)
print "###\n"
print("\n###")
print("### Initializing temporary tolerance map: %s" % (g_tolerance_map_name))
print("###\n")
g_tolerance_map = volumeFromInstance(g_target_determinant,
g_tolerance_map_name,
dtype="double",
Expand All @@ -283,12 +283,12 @@ def write_out_intermediate_grid():
g_target_determinant.data.shape[1] *
g_target_determinant.data.shape[2] ))
g_factor = g_tol_neccessary / g_tol_in_map
print "\n###"
print "### Available space in tolerance map : %f" % (g_tol_in_map)
print "### Sum of Jacobian determinants in target: %f" % (g_target_determinant.data.sum())
print "### Total number of voxels in determinant : %f" % (g_target_determinant.data.shape[0] * g_target_determinant.data.shape[1] * g_target_determinant.data.shape[2])
print "### Change needed in determinant : %f" % (g_tol_neccessary)
print "###\n"
print("\n###")
print("### Available space in tolerance map : %f" % (g_tol_in_map))
print("### Sum of Jacobian determinants in target: %f" % (g_target_determinant.data.sum()))
print("### Total number of voxels in determinant : %f" % (g_target_determinant.data.shape[0] * g_target_determinant.data.shape[1] * g_target_determinant.data.shape[2]))
print("### Change needed in determinant : %f" % (g_tol_neccessary))
print("###\n")


#g_tolerance_map_data *= (g_factor + 0.75)
Expand Down Expand Up @@ -321,9 +321,9 @@ def write_out_intermediate_grid():
g_ystep,
g_zstep)

print "\n###"
print "### Initial difference with target determinant : %f" % (g_field_difference)
print "###\n"
print("\n###")
print("### Initial difference with target determinant : %f" % (g_field_difference))
print("###\n")

g_previous_field_diff = g_field_difference
g_max_field_difference = g_field_difference
Expand Down Expand Up @@ -351,8 +351,8 @@ def write_out_intermediate_grid():
g_max_field_difference = g_field_difference
#g_extra_derivative_weight = g_max_field_difference * 3 / g_iterations
if(i % 10 == 0):
print "Iteration %5.0f determinant difference: %3.5f derivative factor used: %3.5f" % \
(i, g_field_difference, g_derivative_factor)
print("Iteration %5.0f determinant difference: %3.5f derivative factor used: %3.5f" % \
(i, g_field_difference, g_derivative_factor))
# write out the current deformation grid
if(options.save_intermediate_grid_fields):
write_out_intermediate_grid()
Expand Down Expand Up @@ -424,4 +424,4 @@ def write_out_intermediate_grid():



print "\ndone!\n\n"
print("\ndone!\n\n")
16 changes: 8 additions & 8 deletions scripts/create_determinant.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ def impose_minc2_ness(minc_file, temp_dir):
return minc_file
# convert the file to the minc2 format
else:
print "\nThe input file is not in MINC2 format, converting now..."
print("\nThe input file is not in MINC2 format, converting now...")
filename = os.path.basename(minc_file)
basename = filename.replace('.mnc', '')
minc_2_output = "%s/%s_minc2.mnc" % (temp_dir, basename)
command = "mincconvert -clobber -2 %s %s" % \
(minc_file, minc_2_output)
os.system(command)
if not os.access(minc_2_output,0):
print "\nERROR: could not create minc2 volume %s!" % minc_2_output
print("\nERROR: could not create minc2 volume %s!" % minc_2_output)
exit(1)
else:
print "done!"
print("done!")
return minc_2_output


Expand Down Expand Up @@ -117,7 +117,7 @@ def create_initial_determinant(source, center_deformation, tmpdir, outputfilenam
# check whether the input file is minc2, if not create a
# minc2 version of it
g_minc2_input = impose_minc2_ness(g_source, g_tmpdir)
print "\nFile: %s" % g_minc2_input
print("\nFile: %s" % g_minc2_input)
g_input_volume = volumeFromFile(g_minc2_input)
g_xindex = 0 if('xspace' in g_input_volume.dimnames[0]) else \
(1 if ('xspace' in g_input_volume.dimnames[1]) else \
Expand All @@ -140,15 +140,15 @@ def create_initial_determinant(source, center_deformation, tmpdir, outputfilenam
if options.center == None:
# determine a center for the deformation
options.center = "%s,%s,%s" % (g_middle_dim_length, g_middle_dim_length, g_middle_dim_length)
print "Center for deformation not give, set center is: %s" % options.center
print("Center for deformation not give, set center is: %s" % options.center)

if options.determinant == None:
print "The determinant value for the deformation area is not give, default = 0.6."
print("The determinant value for the deformation area is not give, default = 0.6.")
options.determinant = 0.6

if options.radius == None:
options.radius = int(g_middle_dim_length / 4)
print "The radius of the deformation area is not given, set to %s." % options.radius
print("The radius of the deformation area is not given, set to %s." % options.radius)


##########################
Expand Down Expand Up @@ -184,4 +184,4 @@ def create_initial_determinant(source, center_deformation, tmpdir, outputfilenam
if not options.keeptemp:
os.system("rm -fr %s" % g_tmpdir)

print "\ndone!\n\n"
print("\ndone!\n\n")

0 comments on commit 0d16288

Please sign in to comment.