~ubuntu-branches/debian/sid/simpleitk/sid

« back to all changes in this revision

Viewing changes to Testing/Unit/RubyImageFilterTestTemplate.rb.in

  • Committer: Package Import Robot
  • Author(s): Ghislain Antony Vaillant
  • Date: 2017-11-02 08:49:18 UTC
  • Revision ID: package-import@ubuntu.com-20171102084918-7hs09ih668xq87ej
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#==========================================================================
 
2
#
 
3
#   Copyright Insight Software Consortium
 
4
#
 
5
#   Licensed under the Apache License, Version 2.0 (the "License");
 
6
#   you may not use this file except in compliance with the License.
 
7
#   You may obtain a copy of the License at
 
8
#
 
9
#          http://www.apache.org/licenses/LICENSE-2.0.txt
 
10
#
 
11
#   Unless required by applicable law or agreed to in writing, software
 
12
#   distributed under the License is distributed on an "AS IS" BASIS,
 
13
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
#   See the License for the specific language governing permissions and
 
15
#   limitations under the License.
 
16
#
 
17
#==========================================================================*/
 
18
 
 
19
#
 
20
# WARNING: DO NOT EDIT THIS FILE!
 
21
# THIS FILE IS AUTOMATICALLY GENERATED BY THE SIMPLEITK BUILD PROCESS.
 
22
# Please look at RubyImageFilterTestTemplate.rb.in to make changes.
 
23
#
 
24
 
 
25
 
 
26
# This is Ruby code to test ${name}
 
27
require 'simpleitk'
 
28
 
 
29
inputs = 1
 
30
$(if number_of_inputs then
 
31
    OUT=[[inputs = ${number_of_inputs}]]
 
32
  end)
 
33
 
 
34
if ARGV.length < inputs + 2 then
 
35
    puts( "Usage: ${name} tag <input(s)> output" )
 
36
    exit( 1 )
 
37
end
 
38
 
 
39
tag = ARGV[0];
 
40
 
 
41
reader = Simpleitk::ImageFileReader.new
 
42
writer = Simpleitk::ImageFileWriter.new
 
43
filter = Simpleitk::${name}.new
 
44
 
 
45
$(if #tests == 0 then
 
46
    OUT=[[
 
47
puts( "No tests defined!" );
 
48
exit( 1 );
 
49
    ]]
 
50
  end)
 
51
 
 
52
$(foreach tests
 
53
if tag == "${tag}" then
 
54
  $(when settings
 
55
$(foreach settings
 
56
$(if parameter == "SeedList" and ruby_value then
 
57
    OUT=[[  filter.clear_seeds()
 
58
    $(for i=1,#ruby_value do OUT=OUT .. "\
 
59
    v = Simpleitk::VectorUInt32.new\
 
60
    for i in ".. ruby_value[i] .." do v << i end\
 
61
    filter.add_seed(v)" end)]]
 
62
elseif parameter == "SeedList"then
 
63
    OUT=[[  filter.clear_seeds()
 
64
    $(for i=1,#value do OUT=OUT .. "\
 
65
    v = Simpleitk::VectorUInt32.new\
 
66
    for i in ".. value[i] .." do v << i end\
 
67
    filter.add_seed(v)" end)]]
 
68
elseif parameter == "TrialPoints" and ruby_value then
 
69
    OUT=[[  filter.clear_trial_points()
 
70
    $(for i=1,#ruby_value do OUT=OUT .. "\
 
71
    v = Simpleitk::VectorUInt32.new\
 
72
    for i in ".. ruby_value[i] .." do v << i end\
 
73
    filter.add_trial_point(v)" end)]]
 
74
elseif parameter == "TrialPoints"then
 
75
    OUT=[[  filter.clear_trial_points()
 
76
    $(for i=1,#value do OUT=OUT .. "\
 
77
    v = Simpleitk::VectorUInt32.new\
 
78
    for i in ".. value[i] .." do v << i end\
 
79
    filter.add_trial_point(v)" end)]]
 
80
elseif dim_vec and dim_vec == 1 then 
 
81
 
 
82
   if type == "bool" then
 
83
     OUT="v = Simpleitk::VectorBool.new"
 
84
   elseif type == "uint8_t" then
 
85
     OUT="v = Simpleitk::VectorUInt8.new"
 
86
   elseif type == "int" then
 
87
     OUT="v = Simpleitk::VectorInt32.new"
 
88
   elseif type == "double" then
 
89
     OUT="v = Simpleitk::VectorDouble.new"
 
90
   else
 
91
     OUT="v = Simpleitk::VectorUInt32.new"
 
92
   end
 
93
 
 
94
OUT=OUT..[[
 
95
 
 
96
  for i in ]]
 
97
if ruby_value then
 
98
  OUT='${ruby_value}'
 
99
else
 
100
  OUT=OUT..'[ '
 
101
  for i=1,#value-1 do
 
102
    OUT=OUT..value[i]..", "
 
103
  end
 
104
  OUT=OUT..value[#value]..' ]'
 
105
end
 
106
OUT=OUT..[[do v << i end
 
107
  filter.set_${parameter:gsub ( "([a-z])([A-Z])", "%1_%2" ):lower()}(v)]]
 
108
else
 
109
OUT=[[
 
110
    filter.set_${parameter:gsub ( "([a-z])([A-Z])", "%1_%2" ):lower()}( $(if ruby_value then OUT='${ruby_value}' else OUT='${value}' end) ) ]]
 
111
end)
 
112
)
 
113
)
 
114
  inputs = Array.new
 
115
 
 
116
  for i in 1..ARGV.length-2
 
117
    puts "reading.."+ARGV[i]
 
118
    inputs.push( Simpleitk::read_image( ARGV[i] ) )
 
119
  end
 
120
$(if inputA_cast then
 
121
 
 
122
-- the first char of the string needs to be converted to upper case
 
123
OUT=[[
 
124
  caster = Simpleitk::CastImageFilter.new
 
125
  caster.set_output_pixel_type( Simpleitk::${inputA_cast:gsub("^%l", inputA_cast.upper ) })
 
126
  inputs[0] = caster.execute( inputs[0] ) ]]
 
127
end)
 
128
$(if inputB_cast then
 
129
 
 
130
-- the first char of the string needs to be converted to upper case
 
131
OUT=[[
 
132
  caster = Simpleitk::CastImageFilter.new
 
133
  caster.set_output_pixel_type( Simpleitk::${inputB_cast:gsub("^%l", inputB_cast.upper ) })
 
134
  inputs[1] = caster.execute( inputs[1] ) ]]
 
135
end)
 
136
 
 
137
  output = filter.execute( *inputs )
 
138
 
 
139
$(if not no_return_image then
 
140
OUT=[[
 
141
  labelIDs = [ Simpleitk::SitkLabelUInt8, Simpleitk::SitkLabelUInt16, Simpleitk::SitkLabelUInt32, Simpleitk::SitkLabelUInt64 ]
 
142
  if labelIDs.include?(output.get_pixel_id()) then
 
143
    caster = Simpleitk::LabelMapToLabelImageFilter.new
 
144
    output = caster.execute( output )
 
145
  end
 
146
  writer.set_file_name( ARGV[ARGV.length-1] )
 
147
  writer.execute( output )
 
148
]]
 
149
end)
 
150
end
 
151
)
 
152