c_nifti 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +37 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/COPYING +621 -0
- data/COPYING.lesser +166 -0
- data/Gemfile +4 -0
- data/README.md +117 -0
- data/Rakefile +6 -0
- data/c_nifti.gemspec +31 -0
- data/ext/nifticlib/extconf.rb +30 -0
- data/ext/nifticlib/include/nifti_image.h +2 -0
- data/ext/nifticlib/include/nifti_image_converters.h +3 -0
- data/ext/nifticlib/include/nifti_image_dimensions.h +1 -0
- data/ext/nifticlib/include/nifti_image_intents.h +1 -0
- data/ext/nifticlib/include/nifti_image_metadata.h +1 -0
- data/ext/nifticlib/include/nifti_image_quaternions.h +1 -0
- data/ext/nifticlib/include/nifti_image_spacings.h +1 -0
- data/ext/nifticlib/include/nifti_image_timings.h +1 -0
- data/ext/nifticlib/include/nifti_image_transforms.h +1 -0
- data/ext/nifticlib/nifti_image.c +169 -0
- data/ext/nifticlib/nifti_image_converters.c +65 -0
- data/ext/nifticlib/nifti_image_dimensions.c +113 -0
- data/ext/nifticlib/nifti_image_intents.c +45 -0
- data/ext/nifticlib/nifti_image_metadata.c +133 -0
- data/ext/nifticlib/nifti_image_quaternions.c +59 -0
- data/ext/nifticlib/nifti_image_spacings.c +87 -0
- data/ext/nifticlib/nifti_image_timings.c +66 -0
- data/ext/nifticlib/nifti_image_transforms.c +38 -0
- data/ext/nifticlib/nifticlib-2.0.0/CMakeLists.txt +140 -0
- data/ext/nifticlib/nifticlib-2.0.0/CTestConfig.cmake +13 -0
- data/ext/nifticlib/nifticlib-2.0.0/LICENSE +9 -0
- data/ext/nifticlib/nifticlib-2.0.0/Makefile +265 -0
- data/ext/nifticlib/nifticlib-2.0.0/Makefile.cross_mingw32 +94 -0
- data/ext/nifticlib/nifticlib-2.0.0/README +79 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/CMakeLists.txt +7 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/Data/ATestReferenceImageForReadingAndWriting.nii.gz +0 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/Makefile +21 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/README_regress +50 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/@show.diffs +33 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/@test +80 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/CMakeLists.txt +47 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/bricks_test.sh +32 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/comment_test.sh +65 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/dci_test.sh +46 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/dsets_test.sh +61 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/dts_test.sh +75 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/fetch_data_test.sh +45 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/mod_header_test.sh +60 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/newfiles_test.sh +36 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c01.versions +10 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c02.nt.help +5 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c03.hist +5 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c04.disp.anat0.info +7 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c05.mod.hdr +9 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c06.add.ext +22 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c07.cbl.4bricks +8 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c08.dts.19.36.11 +4 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c09.dts4.compare +9 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c10.dci.ts4 +15 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c10a.dci.run.210 +16 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c11.add.comment +8 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c12.check.comments +7 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c13.check.hdrs +5 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c14.make.dsets +21 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c15.new.files +21 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c16.rand.swap +35 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c17.file.case +34 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/niftilib/CMakeLists.txt +15 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/niftilib/nifti_test.c +690 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/niftilib/nifti_test2.c +32 -0
- data/ext/nifticlib/nifticlib-2.0.0/Updates.txt +110 -0
- data/ext/nifticlib/nifticlib-2.0.0/bin/.gitkeep +0 -0
- data/ext/nifticlib/nifticlib-2.0.0/docs/Doxy_nifti.txt +123 -0
- data/ext/nifticlib/nifticlib-2.0.0/docs/Doxyfile.ORIG +746 -0
- data/ext/nifticlib/nifticlib-2.0.0/examples/CMakeLists.txt +15 -0
- data/ext/nifticlib/nifticlib-2.0.0/examples/Makefile +48 -0
- data/ext/nifticlib/nifticlib-2.0.0/examples/clib_01_read_write.c +94 -0
- data/ext/nifticlib/nifticlib-2.0.0/examples/fsl_api_driver.c +142 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/CMakeLists.txt +32 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/Makefile +29 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/fslio.c +2426 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/fslio.tcl +83 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imcp +65 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imglob +59 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imln +37 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/immv +64 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imrm +29 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imtest +53 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/remove_ext +33 -0
- data/ext/nifticlib/nifticlib-2.0.0/include/.gitkeep +0 -0
- data/ext/nifticlib/nifticlib-2.0.0/nifticdf/CMakeLists.txt +28 -0
- data/ext/nifticlib/nifticlib-2.0.0/nifticdf/Makefile +28 -0
- data/ext/nifticlib/nifticlib-2.0.0/nifticdf/nifticdf.c +11107 -0
- data/ext/nifticlib/nifticlib-2.0.0/niftilib/CMakeLists.txt +33 -0
- data/ext/nifticlib/nifticlib-2.0.0/niftilib/Makefile +31 -0
- data/ext/nifticlib/nifticlib-2.0.0/niftilib/nifti1_io.c +7509 -0
- data/ext/nifticlib/nifticlib-2.0.0/packaging/DevPackage.template +18 -0
- data/ext/nifticlib/nifticlib-2.0.0/packaging/nifticlib.spec +62 -0
- data/ext/nifticlib/nifticlib-2.0.0/real_easy/nifti1_read_write.c +361 -0
- data/ext/nifticlib/nifticlib-2.0.0/utils/CMakeLists.txt +73 -0
- data/ext/nifticlib/nifticlib-2.0.0/utils/Makefile +55 -0
- data/ext/nifticlib/nifticlib-2.0.0/utils/nifti1_test.c +95 -0
- data/ext/nifticlib/nifticlib-2.0.0/utils/nifti_stats.c +95 -0
- data/ext/nifticlib/nifticlib-2.0.0/utils/nifti_tool.c +4193 -0
- data/ext/nifticlib/nifticlib-2.0.0/utils/nifti_tool.h +163 -0
- data/ext/nifticlib/nifticlib-2.0.0/znzlib/CMakeLists.txt +31 -0
- data/ext/nifticlib/nifticlib-2.0.0/znzlib/Makefile +33 -0
- data/ext/nifticlib/nifticlib-2.0.0/znzlib/znzlib.c +322 -0
- data/ext/nifticlib/nifticlib.c +107 -0
- data/ext/nifticlib/patches/nifticlib_fpic.patch +13 -0
- data/features/read_modify_write.feature +11 -0
- data/features/step_definitions/nifti_image_steps.rb +16 -0
- data/features/support/env.rb +14 -0
- data/features/support/fixtures/sample.nii.gz +0 -0
- data/lib/c_nifti.rb +9 -0
- data/lib/c_nifti/data.rb +70 -0
- data/lib/c_nifti/header.rb +16 -0
- data/lib/c_nifti/header_element.rb +13 -0
- data/lib/c_nifti/header_element/datatype.rb +49 -0
- data/lib/c_nifti/header_element/datatype/base.rb +9 -0
- data/lib/c_nifti/header_element/datatype/binary.rb +11 -0
- data/lib/c_nifti/header_element/datatype/double.rb +11 -0
- data/lib/c_nifti/header_element/datatype/float.rb +11 -0
- data/lib/c_nifti/header_element/datatype/long_double.rb +11 -0
- data/lib/c_nifti/header_element/datatype/long_long.rb +11 -0
- data/lib/c_nifti/header_element/datatype/signed_char.rb +11 -0
- data/lib/c_nifti/header_element/datatype/signed_int.rb +11 -0
- data/lib/c_nifti/header_element/datatype/signed_short.rb +11 -0
- data/lib/c_nifti/header_element/datatype/unsigned_char.rb +11 -0
- data/lib/c_nifti/header_element/datatype/unsigned_int.rb +11 -0
- data/lib/c_nifti/header_element/datatype/unsigned_long_long.rb +11 -0
- data/lib/c_nifti/header_element/datatype/unsigned_short.rb +11 -0
- data/lib/c_nifti/header_element/dimensions.rb +53 -0
- data/lib/c_nifti/header_element/intents.rb +25 -0
- data/lib/c_nifti/header_element/metadata.rb +49 -0
- data/lib/c_nifti/header_element/miscellaneous.rb +25 -0
- data/lib/c_nifti/header_element/quaternions.rb +33 -0
- data/lib/c_nifti/header_element/spacings.rb +45 -0
- data/lib/c_nifti/header_element/timings.rb +37 -0
- data/lib/c_nifti/header_element/transforms.rb +21 -0
- data/lib/c_nifti/image.rb +31 -0
- data/lib/c_nifti/version.rb +3 -0
- data/lib/nifticlib.rb +1 -0
- data/spec/data_spec.rb +112 -0
- data/spec/factories/nifti_images.rb +9 -0
- data/spec/header_element/datatype/base_spec.rb +9 -0
- data/spec/header_element/datatype/binary_spec.rb +9 -0
- data/spec/header_element/datatype/double_spec.rb +9 -0
- data/spec/header_element/datatype/float_spec.rb +9 -0
- data/spec/header_element/datatype/long_double_spec.rb +9 -0
- data/spec/header_element/datatype/long_long_spec.rb +9 -0
- data/spec/header_element/datatype/signed_char_spec.rb +9 -0
- data/spec/header_element/datatype/signed_int_spec.rb +9 -0
- data/spec/header_element/datatype/signed_short_spec.rb +9 -0
- data/spec/header_element/datatype/unsigned_char_spec.rb +9 -0
- data/spec/header_element/datatype/unsigned_int_spec.rb +9 -0
- data/spec/header_element/datatype/unsigned_long_long.rb +9 -0
- data/spec/header_element/datatype/unsigned_short_spec.rb +9 -0
- data/spec/header_element/datatype_spec.rb +109 -0
- data/spec/header_element/dimensions_spec.rb +105 -0
- data/spec/header_element/intents_spec.rb +48 -0
- data/spec/header_element/metadata_spec.rb +96 -0
- data/spec/header_element/miscellaneous_spec.rb +48 -0
- data/spec/header_element/quaternions_spec.rb +64 -0
- data/spec/header_element/spacings_spec.rb +88 -0
- data/spec/header_element/timings_spec.rb +72 -0
- data/spec/header_element/transforms_spec.rb +64 -0
- data/spec/image_spec.rb +39 -0
- data/spec/spec_helper.rb +85 -0
- metadata +363 -0
@@ -0,0 +1,107 @@
|
|
1
|
+
#include <ruby.h> // Ruby C extensions
|
2
|
+
#include <nifti1_io.h> // standard NIfTI C library
|
3
|
+
#include <string.h>
|
4
|
+
#include <stdio.h>
|
5
|
+
|
6
|
+
#include <nifti_image.h>
|
7
|
+
#include <nifti_image_converters.h>
|
8
|
+
|
9
|
+
// DATA types
|
10
|
+
VALUE mNIfTICLib;
|
11
|
+
VALUE cNIfTIImage;
|
12
|
+
|
13
|
+
/*********************/
|
14
|
+
/* NIfTICLib Methods */
|
15
|
+
/*********************/
|
16
|
+
|
17
|
+
static VALUE nifti_image_read_wrapper(VALUE self, VALUE rb_input_file_path){
|
18
|
+
VALUE rb_img;
|
19
|
+
char *input_file_path = NULL;
|
20
|
+
nifti_image *img = NULL;
|
21
|
+
|
22
|
+
StringValue(rb_input_file_path);
|
23
|
+
input_file_path = StringValuePtr(rb_input_file_path);
|
24
|
+
|
25
|
+
img = nifti_image_read(input_file_path, 1);
|
26
|
+
if(!img) {
|
27
|
+
rb_raise(rb_eRuntimeError, "Failed to read NIfTI image from '%s'\n", input_file_path);
|
28
|
+
}
|
29
|
+
|
30
|
+
rb_img = Data_Wrap_Struct(cNIfTIImage, NULL, nifti_image_free, img);
|
31
|
+
|
32
|
+
return rb_img;
|
33
|
+
}
|
34
|
+
|
35
|
+
VALUE nifti_image_write_wrapper(VALUE self, VALUE rb_nifti_image, VALUE rb_output_file_path){
|
36
|
+
VALUE rb_img = Qnil;
|
37
|
+
char *output_file_path = NULL;
|
38
|
+
char *original_file_path = NULL;
|
39
|
+
nifti_image *img = to_nifti_image(rb_nifti_image);
|
40
|
+
FILE *output_file = NULL;
|
41
|
+
|
42
|
+
StringValue(rb_output_file_path);
|
43
|
+
output_file_path = StringValuePtr(rb_output_file_path);
|
44
|
+
output_file = fopen(output_file_path, "r");
|
45
|
+
|
46
|
+
if(output_file){
|
47
|
+
rb_raise(rb_eRuntimeError, "File %s already exists", output_file_path);
|
48
|
+
fclose(output_file);
|
49
|
+
}else{
|
50
|
+
original_file_path = malloc(RSTRING_LEN(rb_output_file_path)*sizeof(char));
|
51
|
+
|
52
|
+
strcpy(original_file_path,img->fname);
|
53
|
+
nifti_set_filenames(img, output_file_path, 1, 1);
|
54
|
+
|
55
|
+
nifti_image_write(img);
|
56
|
+
nifti_set_filenames(img, original_file_path, 0, 1);
|
57
|
+
|
58
|
+
rb_img = Data_Wrap_Struct(cNIfTIImage, NULL, nifti_image_free, nifti_image_read(output_file_path, 1));
|
59
|
+
|
60
|
+
return rb_img;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
/******************/
|
65
|
+
/* New NIfTIImage */
|
66
|
+
/******************/
|
67
|
+
|
68
|
+
VALUE nifti_image_new(VALUE self, VALUE r_dims, VALUE r_datatype, VALUE r_data_fill){
|
69
|
+
int i = 0;
|
70
|
+
int *dims = NULL;
|
71
|
+
int datatype = 0;
|
72
|
+
int data_fill = 0;
|
73
|
+
nifti_image *img = NULL;
|
74
|
+
|
75
|
+
dims = malloc(RARRAY_LEN(r_dims)*sizeof(int));
|
76
|
+
|
77
|
+
for(i = 0; i < RARRAY_LEN(r_dims); i++){
|
78
|
+
dims[i] = NUM2INT(rb_ary_entry(r_dims, i));
|
79
|
+
}
|
80
|
+
|
81
|
+
datatype = NUM2INT(r_datatype);
|
82
|
+
|
83
|
+
data_fill = NUM2INT(r_data_fill);
|
84
|
+
|
85
|
+
img = nifti_make_new_nim(dims, datatype, data_fill);
|
86
|
+
|
87
|
+
free(dims);
|
88
|
+
|
89
|
+
return Data_Wrap_Struct(cNIfTIImage, NULL, nifti_image_free, img);
|
90
|
+
}
|
91
|
+
|
92
|
+
/********/
|
93
|
+
/* Init */
|
94
|
+
/********/
|
95
|
+
|
96
|
+
void Init_nifticlib(void){
|
97
|
+
// NIfTICLib module
|
98
|
+
mNIfTICLib = rb_define_module("NIfTICLib");
|
99
|
+
|
100
|
+
// NIfTICLib methods
|
101
|
+
rb_define_singleton_method(mNIfTICLib, "read", nifti_image_read_wrapper, 1);
|
102
|
+
rb_define_singleton_method(mNIfTICLib, "write", nifti_image_write_wrapper, 2);
|
103
|
+
|
104
|
+
cNIfTIImage = init_nifti_image(mNIfTICLib);
|
105
|
+
// New
|
106
|
+
rb_define_singleton_method(cNIfTIImage, "new", nifti_image_new, 3);
|
107
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
diff --git Makefile Makefile
|
2
|
+
index bcb059c..1c40db2 100644
|
3
|
+
--- Makefile
|
4
|
+
+++ Makefile
|
5
|
+
@@ -24,7 +24,7 @@ RANLIB = ranlib
|
6
|
+
DEPENDFLAGS = -MM
|
7
|
+
GNU_ANSI_FLAGS = -Wall -ansi -pedantic
|
8
|
+
ANSI_FLAGS = ${GNU_ANSI_FLAGS}
|
9
|
+
-CFLAGS = $(ANSI_FLAGS)
|
10
|
+
+CFLAGS = $(ANSI_FLAGS) -fPIC
|
11
|
+
|
12
|
+
## Command defines
|
13
|
+
## gmake does not work on MacOSX or some versions of linux MAKE = gmake
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Feature: Read, Modify and Write
|
2
|
+
In order to be able to work NIfTI images
|
3
|
+
As a developer
|
4
|
+
I want to read a image, modify it and save the modification
|
5
|
+
|
6
|
+
Scenario: with a existing image
|
7
|
+
Given I have opened the image at "features/support/fixtures/sample.nii.gz"
|
8
|
+
When I modify the image data at "0" "0" "0" setting it to "0"
|
9
|
+
And I save the image to "/tmp/c_nifti_test.nii.gz"
|
10
|
+
And I have opened the image at "/tmp/c_nifti_test.nii.gz"
|
11
|
+
Then I should get the data value "0" at the position "0" "0" "0"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Given(/^I have opened the image at "(.*?)"$/) do |path|
|
2
|
+
@img = CNifti::Image.new.open(path)
|
3
|
+
end
|
4
|
+
|
5
|
+
When(/^I modify the image data at "(.*?)" "(.*?)" "(.*?)" setting it to "(.*?)"$/) do |x, y, z, value|
|
6
|
+
@img.data[x.to_i][y.to_i][z.to_i] = value.to_i
|
7
|
+
end
|
8
|
+
|
9
|
+
When(/^I save the image to "(.*?)"$/) do |path|
|
10
|
+
File.delete(path) if File.exists?(path)
|
11
|
+
@img.save_as(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
Then(/^I should get the data value "(.*?)" at the position "(.*?)" "(.*?)" "(.*?)"$/) do |value, x, y, z|
|
15
|
+
expect(@img.data[x.to_i][y.to_i][z.to_i]).to eq(value.to_i)
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# SimpleCov for test coverage report
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter "/spec/"
|
5
|
+
add_filter "/features/"
|
6
|
+
|
7
|
+
coverage_dir 'coverage/cucumber'
|
8
|
+
end
|
9
|
+
|
10
|
+
# The gem itself
|
11
|
+
require 'c_nifti'
|
12
|
+
|
13
|
+
require 'factory_girl'
|
14
|
+
FactoryGirl.find_definitions
|
Binary file
|
data/lib/c_nifti.rb
ADDED
data/lib/c_nifti/data.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
module CNifti
|
2
|
+
class Data
|
3
|
+
def initialize(nifti_image, previous_indexes=[])
|
4
|
+
@nifti_image = nifti_image
|
5
|
+
@previous_indexes = previous_indexes
|
6
|
+
end
|
7
|
+
|
8
|
+
def raw
|
9
|
+
@nifti_image.data
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_raw(index, value)
|
13
|
+
@nifti_image.set_data(index, value)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_raw(index)
|
17
|
+
@nifti_image.get_data(index)
|
18
|
+
end
|
19
|
+
|
20
|
+
def shape
|
21
|
+
start_index = 1
|
22
|
+
@previous_indexes.each {start_index += 1}
|
23
|
+
@nifti_image.dim[start_index..@nifti_image.dim[0]]
|
24
|
+
end
|
25
|
+
|
26
|
+
def [](index)
|
27
|
+
# Dealing with Ranges is useful when the image represents a tensor
|
28
|
+
if (index.is_a?(Fixnum) && index >= self.shape[0]) || (index.is_a?(Range) && index.last >= self.shape[0])
|
29
|
+
raise IndexError.new("Index over bounds")
|
30
|
+
elsif self.shape.count == 1
|
31
|
+
if index.is_a?(Range)
|
32
|
+
value = []
|
33
|
+
index.each { |i| value << self.get_raw(get_index_value(i)) }
|
34
|
+
value
|
35
|
+
else
|
36
|
+
self.get_raw(get_index_value(index))
|
37
|
+
end
|
38
|
+
else
|
39
|
+
Data.new(@nifti_image, @previous_indexes.clone << index)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def []=(index,value)
|
44
|
+
if self.shape.count != 1 or index >= self.shape[0]
|
45
|
+
raise IndexError.new("You can only set values for array values")
|
46
|
+
else
|
47
|
+
self.set_raw(get_index_value(index), value)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def get_index_value(current_index)
|
54
|
+
reverse_dim = @nifti_image.dim.take(@nifti_image.dim[0] + 1).reverse
|
55
|
+
step = (reverse_dim.inject(:*)/@nifti_image.dim[0])/reverse_dim[0]
|
56
|
+
|
57
|
+
index_value = current_index*step
|
58
|
+
step /= reverse_dim[1]
|
59
|
+
dim_index = 1
|
60
|
+
|
61
|
+
@previous_indexes.reverse_each do |previous_index|
|
62
|
+
index_value += step*previous_index
|
63
|
+
dim_index += 1
|
64
|
+
step /= reverse_dim[dim_index] if dim_index < (reverse_dim.count - 1)
|
65
|
+
end
|
66
|
+
|
67
|
+
index_value
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module CNifti
|
2
|
+
class Header
|
3
|
+
include HeaderElement::Metadata
|
4
|
+
include HeaderElement::Dimensions
|
5
|
+
include HeaderElement::Intents
|
6
|
+
include HeaderElement::Quaternions
|
7
|
+
include HeaderElement::Spacings
|
8
|
+
include HeaderElement::Timings
|
9
|
+
include HeaderElement::Transforms
|
10
|
+
include HeaderElement::Miscellaneous
|
11
|
+
|
12
|
+
def initialize(nifti_image)
|
13
|
+
@nifti_image = nifti_image
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'c_nifti/header_element/datatype'
|
2
|
+
require 'c_nifti/header_element/metadata'
|
3
|
+
require 'c_nifti/header_element/dimensions'
|
4
|
+
require 'c_nifti/header_element/intents'
|
5
|
+
require 'c_nifti/header_element/quaternions'
|
6
|
+
require 'c_nifti/header_element/spacings'
|
7
|
+
require 'c_nifti/header_element/timings'
|
8
|
+
require 'c_nifti/header_element/transforms'
|
9
|
+
require 'c_nifti/header_element/miscellaneous'
|
10
|
+
|
11
|
+
module CNifti
|
12
|
+
module HeaderElement; end
|
13
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'c_nifti/header_element/datatype/binary'
|
2
|
+
require 'c_nifti/header_element/datatype/double'
|
3
|
+
require 'c_nifti/header_element/datatype/float'
|
4
|
+
require 'c_nifti/header_element/datatype/long_double'
|
5
|
+
require 'c_nifti/header_element/datatype/long_long'
|
6
|
+
require 'c_nifti/header_element/datatype/signed_char'
|
7
|
+
require 'c_nifti/header_element/datatype/signed_int'
|
8
|
+
require 'c_nifti/header_element/datatype/signed_short'
|
9
|
+
require 'c_nifti/header_element/datatype/unsigned_char'
|
10
|
+
require 'c_nifti/header_element/datatype/unsigned_int'
|
11
|
+
require 'c_nifti/header_element/datatype/unsigned_long_long'
|
12
|
+
require 'c_nifti/header_element/datatype/unsigned_short'
|
13
|
+
|
14
|
+
module CNifti
|
15
|
+
module HeaderElement
|
16
|
+
module Datatype
|
17
|
+
def self.to_datatype(value)
|
18
|
+
case value
|
19
|
+
when Binary.to_i
|
20
|
+
return Binary
|
21
|
+
when Double.to_i
|
22
|
+
return Double
|
23
|
+
when Float.to_i
|
24
|
+
return Float
|
25
|
+
when LongDouble.to_i
|
26
|
+
return LongDouble
|
27
|
+
when LongLong.to_i
|
28
|
+
return LongLong
|
29
|
+
when SignedChar.to_i
|
30
|
+
return SignedChar
|
31
|
+
when SignedInt.to_i
|
32
|
+
return SignedInt
|
33
|
+
when SignedShort.to_i
|
34
|
+
return SignedShort
|
35
|
+
when UnsignedChar.to_i
|
36
|
+
return UnsignedChar
|
37
|
+
when UnsignedInt.to_i
|
38
|
+
return UnsignedInt
|
39
|
+
when UnsignedLongLong.to_i
|
40
|
+
return UnsignedLongLong
|
41
|
+
when UnsignedShort.to_i
|
42
|
+
return UnsignedShort
|
43
|
+
else
|
44
|
+
raise TypeError.new("Datatype #{value} unsupported")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|