c_nifti 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +37 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/COPYING +621 -0
  7. data/COPYING.lesser +166 -0
  8. data/Gemfile +4 -0
  9. data/README.md +117 -0
  10. data/Rakefile +6 -0
  11. data/c_nifti.gemspec +31 -0
  12. data/ext/nifticlib/extconf.rb +30 -0
  13. data/ext/nifticlib/include/nifti_image.h +2 -0
  14. data/ext/nifticlib/include/nifti_image_converters.h +3 -0
  15. data/ext/nifticlib/include/nifti_image_dimensions.h +1 -0
  16. data/ext/nifticlib/include/nifti_image_intents.h +1 -0
  17. data/ext/nifticlib/include/nifti_image_metadata.h +1 -0
  18. data/ext/nifticlib/include/nifti_image_quaternions.h +1 -0
  19. data/ext/nifticlib/include/nifti_image_spacings.h +1 -0
  20. data/ext/nifticlib/include/nifti_image_timings.h +1 -0
  21. data/ext/nifticlib/include/nifti_image_transforms.h +1 -0
  22. data/ext/nifticlib/nifti_image.c +169 -0
  23. data/ext/nifticlib/nifti_image_converters.c +65 -0
  24. data/ext/nifticlib/nifti_image_dimensions.c +113 -0
  25. data/ext/nifticlib/nifti_image_intents.c +45 -0
  26. data/ext/nifticlib/nifti_image_metadata.c +133 -0
  27. data/ext/nifticlib/nifti_image_quaternions.c +59 -0
  28. data/ext/nifticlib/nifti_image_spacings.c +87 -0
  29. data/ext/nifticlib/nifti_image_timings.c +66 -0
  30. data/ext/nifticlib/nifti_image_transforms.c +38 -0
  31. data/ext/nifticlib/nifticlib-2.0.0/CMakeLists.txt +140 -0
  32. data/ext/nifticlib/nifticlib-2.0.0/CTestConfig.cmake +13 -0
  33. data/ext/nifticlib/nifticlib-2.0.0/LICENSE +9 -0
  34. data/ext/nifticlib/nifticlib-2.0.0/Makefile +265 -0
  35. data/ext/nifticlib/nifticlib-2.0.0/Makefile.cross_mingw32 +94 -0
  36. data/ext/nifticlib/nifticlib-2.0.0/README +79 -0
  37. data/ext/nifticlib/nifticlib-2.0.0/Testing/CMakeLists.txt +7 -0
  38. data/ext/nifticlib/nifticlib-2.0.0/Testing/Data/ATestReferenceImageForReadingAndWriting.nii.gz +0 -0
  39. data/ext/nifticlib/nifticlib-2.0.0/Testing/Makefile +21 -0
  40. data/ext/nifticlib/nifticlib-2.0.0/Testing/README_regress +50 -0
  41. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/@show.diffs +33 -0
  42. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/@test +80 -0
  43. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/CMakeLists.txt +47 -0
  44. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/bricks_test.sh +32 -0
  45. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/comment_test.sh +65 -0
  46. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/dci_test.sh +46 -0
  47. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/dsets_test.sh +61 -0
  48. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/dts_test.sh +75 -0
  49. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/fetch_data_test.sh +45 -0
  50. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/mod_header_test.sh +60 -0
  51. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/newfiles_test.sh +36 -0
  52. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c01.versions +10 -0
  53. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c02.nt.help +5 -0
  54. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c03.hist +5 -0
  55. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c04.disp.anat0.info +7 -0
  56. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c05.mod.hdr +9 -0
  57. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c06.add.ext +22 -0
  58. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c07.cbl.4bricks +8 -0
  59. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c08.dts.19.36.11 +4 -0
  60. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c09.dts4.compare +9 -0
  61. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c10.dci.ts4 +15 -0
  62. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c10a.dci.run.210 +16 -0
  63. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c11.add.comment +8 -0
  64. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c12.check.comments +7 -0
  65. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c13.check.hdrs +5 -0
  66. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c14.make.dsets +21 -0
  67. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c15.new.files +21 -0
  68. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c16.rand.swap +35 -0
  69. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c17.file.case +34 -0
  70. data/ext/nifticlib/nifticlib-2.0.0/Testing/niftilib/CMakeLists.txt +15 -0
  71. data/ext/nifticlib/nifticlib-2.0.0/Testing/niftilib/nifti_test.c +690 -0
  72. data/ext/nifticlib/nifticlib-2.0.0/Testing/niftilib/nifti_test2.c +32 -0
  73. data/ext/nifticlib/nifticlib-2.0.0/Updates.txt +110 -0
  74. data/ext/nifticlib/nifticlib-2.0.0/bin/.gitkeep +0 -0
  75. data/ext/nifticlib/nifticlib-2.0.0/docs/Doxy_nifti.txt +123 -0
  76. data/ext/nifticlib/nifticlib-2.0.0/docs/Doxyfile.ORIG +746 -0
  77. data/ext/nifticlib/nifticlib-2.0.0/examples/CMakeLists.txt +15 -0
  78. data/ext/nifticlib/nifticlib-2.0.0/examples/Makefile +48 -0
  79. data/ext/nifticlib/nifticlib-2.0.0/examples/clib_01_read_write.c +94 -0
  80. data/ext/nifticlib/nifticlib-2.0.0/examples/fsl_api_driver.c +142 -0
  81. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/CMakeLists.txt +32 -0
  82. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/Makefile +29 -0
  83. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/fslio.c +2426 -0
  84. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/fslio.tcl +83 -0
  85. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imcp +65 -0
  86. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imglob +59 -0
  87. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imln +37 -0
  88. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/immv +64 -0
  89. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imrm +29 -0
  90. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imtest +53 -0
  91. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/remove_ext +33 -0
  92. data/ext/nifticlib/nifticlib-2.0.0/include/.gitkeep +0 -0
  93. data/ext/nifticlib/nifticlib-2.0.0/nifticdf/CMakeLists.txt +28 -0
  94. data/ext/nifticlib/nifticlib-2.0.0/nifticdf/Makefile +28 -0
  95. data/ext/nifticlib/nifticlib-2.0.0/nifticdf/nifticdf.c +11107 -0
  96. data/ext/nifticlib/nifticlib-2.0.0/niftilib/CMakeLists.txt +33 -0
  97. data/ext/nifticlib/nifticlib-2.0.0/niftilib/Makefile +31 -0
  98. data/ext/nifticlib/nifticlib-2.0.0/niftilib/nifti1_io.c +7509 -0
  99. data/ext/nifticlib/nifticlib-2.0.0/packaging/DevPackage.template +18 -0
  100. data/ext/nifticlib/nifticlib-2.0.0/packaging/nifticlib.spec +62 -0
  101. data/ext/nifticlib/nifticlib-2.0.0/real_easy/nifti1_read_write.c +361 -0
  102. data/ext/nifticlib/nifticlib-2.0.0/utils/CMakeLists.txt +73 -0
  103. data/ext/nifticlib/nifticlib-2.0.0/utils/Makefile +55 -0
  104. data/ext/nifticlib/nifticlib-2.0.0/utils/nifti1_test.c +95 -0
  105. data/ext/nifticlib/nifticlib-2.0.0/utils/nifti_stats.c +95 -0
  106. data/ext/nifticlib/nifticlib-2.0.0/utils/nifti_tool.c +4193 -0
  107. data/ext/nifticlib/nifticlib-2.0.0/utils/nifti_tool.h +163 -0
  108. data/ext/nifticlib/nifticlib-2.0.0/znzlib/CMakeLists.txt +31 -0
  109. data/ext/nifticlib/nifticlib-2.0.0/znzlib/Makefile +33 -0
  110. data/ext/nifticlib/nifticlib-2.0.0/znzlib/znzlib.c +322 -0
  111. data/ext/nifticlib/nifticlib.c +107 -0
  112. data/ext/nifticlib/patches/nifticlib_fpic.patch +13 -0
  113. data/features/read_modify_write.feature +11 -0
  114. data/features/step_definitions/nifti_image_steps.rb +16 -0
  115. data/features/support/env.rb +14 -0
  116. data/features/support/fixtures/sample.nii.gz +0 -0
  117. data/lib/c_nifti.rb +9 -0
  118. data/lib/c_nifti/data.rb +70 -0
  119. data/lib/c_nifti/header.rb +16 -0
  120. data/lib/c_nifti/header_element.rb +13 -0
  121. data/lib/c_nifti/header_element/datatype.rb +49 -0
  122. data/lib/c_nifti/header_element/datatype/base.rb +9 -0
  123. data/lib/c_nifti/header_element/datatype/binary.rb +11 -0
  124. data/lib/c_nifti/header_element/datatype/double.rb +11 -0
  125. data/lib/c_nifti/header_element/datatype/float.rb +11 -0
  126. data/lib/c_nifti/header_element/datatype/long_double.rb +11 -0
  127. data/lib/c_nifti/header_element/datatype/long_long.rb +11 -0
  128. data/lib/c_nifti/header_element/datatype/signed_char.rb +11 -0
  129. data/lib/c_nifti/header_element/datatype/signed_int.rb +11 -0
  130. data/lib/c_nifti/header_element/datatype/signed_short.rb +11 -0
  131. data/lib/c_nifti/header_element/datatype/unsigned_char.rb +11 -0
  132. data/lib/c_nifti/header_element/datatype/unsigned_int.rb +11 -0
  133. data/lib/c_nifti/header_element/datatype/unsigned_long_long.rb +11 -0
  134. data/lib/c_nifti/header_element/datatype/unsigned_short.rb +11 -0
  135. data/lib/c_nifti/header_element/dimensions.rb +53 -0
  136. data/lib/c_nifti/header_element/intents.rb +25 -0
  137. data/lib/c_nifti/header_element/metadata.rb +49 -0
  138. data/lib/c_nifti/header_element/miscellaneous.rb +25 -0
  139. data/lib/c_nifti/header_element/quaternions.rb +33 -0
  140. data/lib/c_nifti/header_element/spacings.rb +45 -0
  141. data/lib/c_nifti/header_element/timings.rb +37 -0
  142. data/lib/c_nifti/header_element/transforms.rb +21 -0
  143. data/lib/c_nifti/image.rb +31 -0
  144. data/lib/c_nifti/version.rb +3 -0
  145. data/lib/nifticlib.rb +1 -0
  146. data/spec/data_spec.rb +112 -0
  147. data/spec/factories/nifti_images.rb +9 -0
  148. data/spec/header_element/datatype/base_spec.rb +9 -0
  149. data/spec/header_element/datatype/binary_spec.rb +9 -0
  150. data/spec/header_element/datatype/double_spec.rb +9 -0
  151. data/spec/header_element/datatype/float_spec.rb +9 -0
  152. data/spec/header_element/datatype/long_double_spec.rb +9 -0
  153. data/spec/header_element/datatype/long_long_spec.rb +9 -0
  154. data/spec/header_element/datatype/signed_char_spec.rb +9 -0
  155. data/spec/header_element/datatype/signed_int_spec.rb +9 -0
  156. data/spec/header_element/datatype/signed_short_spec.rb +9 -0
  157. data/spec/header_element/datatype/unsigned_char_spec.rb +9 -0
  158. data/spec/header_element/datatype/unsigned_int_spec.rb +9 -0
  159. data/spec/header_element/datatype/unsigned_long_long.rb +9 -0
  160. data/spec/header_element/datatype/unsigned_short_spec.rb +9 -0
  161. data/spec/header_element/datatype_spec.rb +109 -0
  162. data/spec/header_element/dimensions_spec.rb +105 -0
  163. data/spec/header_element/intents_spec.rb +48 -0
  164. data/spec/header_element/metadata_spec.rb +96 -0
  165. data/spec/header_element/miscellaneous_spec.rb +48 -0
  166. data/spec/header_element/quaternions_spec.rb +64 -0
  167. data/spec/header_element/spacings_spec.rb +88 -0
  168. data/spec/header_element/timings_spec.rb +72 -0
  169. data/spec/header_element/transforms_spec.rb +64 -0
  170. data/spec/image_spec.rb +39 -0
  171. data/spec/spec_helper.rb +85 -0
  172. 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
@@ -0,0 +1,9 @@
1
+ require "c_nifti/version"
2
+ require 'c_nifti/header_element'
3
+ require 'c_nifti/header'
4
+ require 'c_nifti/data'
5
+ require 'c_nifti/image'
6
+
7
+ module CNifti
8
+ # Your code goes here...
9
+ end
@@ -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
@@ -0,0 +1,9 @@
1
+ module CNifti
2
+ module HeaderElement
3
+ module Datatype
4
+ class Base
5
+ def self.to_i; raise NotImplementedError; end
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ require 'c_nifti/header_element/datatype/base'
2
+
3
+ module CNifti
4
+ module HeaderElement
5
+ module Datatype
6
+ class Binary < Base
7
+ def self.to_i; 1; end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'c_nifti/header_element/datatype/base'
2
+
3
+ module CNifti
4
+ module HeaderElement
5
+ module Datatype
6
+ class Double < Base
7
+ def self.to_i; 64; end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'c_nifti/header_element/datatype/base'
2
+
3
+ module CNifti
4
+ module HeaderElement
5
+ module Datatype
6
+ class Float < Base
7
+ def self.to_i; 16; end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'c_nifti/header_element/datatype/base'
2
+
3
+ module CNifti
4
+ module HeaderElement
5
+ module Datatype
6
+ class LongDouble < Base
7
+ def self.to_i; 1538; end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'c_nifti/header_element/datatype/base'
2
+
3
+ module CNifti
4
+ module HeaderElement
5
+ module Datatype
6
+ class LongLong < Base
7
+ def self.to_i; 1024; end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'c_nifti/header_element/datatype/base'
2
+
3
+ module CNifti
4
+ module HeaderElement
5
+ module Datatype
6
+ class SignedChar < Base
7
+ def self.to_i; 256; end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'c_nifti/header_element/datatype/base'
2
+
3
+ module CNifti
4
+ module HeaderElement
5
+ module Datatype
6
+ class SignedInt < Base
7
+ def self.to_i; 8; end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'c_nifti/header_element/datatype/base'
2
+
3
+ module CNifti
4
+ module HeaderElement
5
+ module Datatype
6
+ class SignedShort < Base
7
+ def self.to_i; 4; end
8
+ end
9
+ end
10
+ end
11
+ end