#==========================================================================
#
#   Copyright Insight Software Consortium
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#          http://www.apache.org/licenses/LICENSE-2.0.txt
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#
#==========================================================================*/

#
# WARNING: DO NOT EDIT THIS FILE!
# THIS FILE IS AUTOMATICALLY GENERATED BY THE SIMPLEITK BUILD PROCESS.
# Please look at RubyImageFilterTestTemplate.rb.in to make changes.
#


# This is Ruby code to test ${name}
require 'simpleitk'

inputs = 1
$(if number_of_inputs then
    OUT=[[inputs = ${number_of_inputs}]]
  end)

if ARGV.length < inputs + 2 then
    puts( "Usage: ${name} tag <input(s)> output" )
    exit( 1 )
end

tag = ARGV[0];

reader = Simpleitk::ImageFileReader.new
writer = Simpleitk::ImageFileWriter.new
filter = Simpleitk::${name}.new

$(if #tests == 0 then
    OUT=[[
puts( "No tests defined!" );
exit( 1 );
    ]]
  end)

$(foreach tests
if tag == "${tag}" then
  $(when settings
$(foreach settings
$(if parameter == "SeedList" and ruby_value then
    OUT=[[  filter.clear_seeds()
    $(for i=1,#ruby_value do OUT=OUT .. "\
    v = Simpleitk::VectorUInt32.new\
    for i in ".. ruby_value[i] .." do v << i end\
    filter.add_seed(v)" end)]]
elseif parameter == "SeedList"then
    OUT=[[  filter.clear_seeds()
    $(for i=1,#value do OUT=OUT .. "\
    v = Simpleitk::VectorUInt32.new\
    for i in ".. value[i] .." do v << i end\
    filter.add_seed(v)" end)]]
elseif parameter == "TrialPoints" and ruby_value then
    OUT=[[  filter.clear_trial_points()
    $(for i=1,#ruby_value do OUT=OUT .. "\
    v = Simpleitk::VectorUInt32.new\
    for i in ".. ruby_value[i] .." do v << i end\
    filter.add_trial_point(v)" end)]]
elseif parameter == "TrialPoints"then
    OUT=[[  filter.clear_trial_points()
    $(for i=1,#value do OUT=OUT .. "\
    v = Simpleitk::VectorUInt32.new\
    for i in ".. value[i] .." do v << i end\
    filter.add_trial_point(v)" end)]]
elseif dim_vec and dim_vec == 1 then 

   if type == "bool" then
     OUT="v = Simpleitk::VectorBool.new"
   elseif type == "uint8_t" then
     OUT="v = Simpleitk::VectorUInt8.new"
   elseif type == "int" then
     OUT="v = Simpleitk::VectorInt32.new"
   elseif type == "double" then
     OUT="v = Simpleitk::VectorDouble.new"
   else
     OUT="v = Simpleitk::VectorUInt32.new"
   end

OUT=OUT..[[

  for i in ]]
if ruby_value then
  OUT='${ruby_value}'
else
  OUT=OUT..'[ '
  for i=1,#value-1 do
    OUT=OUT..value[i]..", "
  end
  OUT=OUT..value[#value]..' ]'
end
OUT=OUT..[[do v << i end
  filter.set_${parameter:gsub ( "([a-z])([A-Z])", "%1_%2" ):lower()}(v)]]
else
OUT=[[
    filter.set_${parameter:gsub ( "([a-z])([A-Z])", "%1_%2" ):lower()}( $(if ruby_value then OUT='${ruby_value}' else OUT='${value}' end) ) ]]
end)
)
)
  inputs = Array.new

  for i in 1..ARGV.length-2
    puts "reading.."+ARGV[i]
    inputs.push( Simpleitk::read_image( ARGV[i] ) )
  end
$(if inputA_cast then

-- the first char of the string needs to be converted to upper case
OUT=[[
  caster = Simpleitk::CastImageFilter.new
  caster.set_output_pixel_type( Simpleitk::${inputA_cast:gsub("^%l", inputA_cast.upper ) })
  inputs[0] = caster.execute( inputs[0] ) ]]
end)
$(if inputB_cast then

-- the first char of the string needs to be converted to upper case
OUT=[[
  caster = Simpleitk::CastImageFilter.new
  caster.set_output_pixel_type( Simpleitk::${inputB_cast:gsub("^%l", inputB_cast.upper ) })
  inputs[1] = caster.execute( inputs[1] ) ]]
end)

  output = filter.execute( *inputs )

$(if not no_return_image then
OUT=[[
  labelIDs = [ Simpleitk::SitkLabelUInt8, Simpleitk::SitkLabelUInt16, Simpleitk::SitkLabelUInt32, Simpleitk::SitkLabelUInt64 ]
  if labelIDs.include?(output.get_pixel_id()) then
    caster = Simpleitk::LabelMapToLabelImageFilter.new
    output = caster.execute( output )
  end
  writer.set_file_name( ARGV[ARGV.length-1] )
  writer.execute( output )
]]
end)
end
)

