--==========================================================================
--
--   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 LuaImageFilterTestTemplate.lua.in to make changes.
--


-- This is Lua code to test ${name}

require "SimpleITK"

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

if #arg < inputs + 2 then
  print ( "Usage: ${name} tag <input(s)> output" )
  os.exit ( 1 )
end

tag = arg[1];

reader = SimpleITK.ImageFileReader()
writer = SimpleITK.ImageFileWriter()
filter = SimpleITK.${name}()

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

$(foreach tests
  if tag == "${tag}" then
    $(when settings
$(foreach settings
$(if parameter == "SeedList" and lua_value then
    OUT=[[filter:ClearSeeds();
    $(for i=1,#lua_value do OUT=OUT .. "\
    idx = SimpleITK.VectorUInt32();\
    for _,v in ipairs(".. lua_value[i] ..") do idx:push_back(v) end\
    filter:AddSeed( idx );"end)]]
elseif parameter == "SeedList" then
    OUT=[[filter:ClearSeeds();
    $(for i=1,#value do OUT=OUT .. "\
    idx = SimpleITK.VectorUInt32();\
    for _,v in ipairs(".. value[i] ..") do idx:push_back(v) end\
    filter:AddSeed( idx );"end)]]
elseif parameter == "TrialPoints" and lua_value then
    OUT=[[filter:ClearTrialPoints();
    $(for i=1,#lua_value do OUT=OUT .. "\
    idx = SimpleITK.VectorUInt32();\
    for _,v in ipairs(".. lua_value[i] ..") do idx:push_back(v) end\
    filter:AddTrialPoint( idx );"end)]]
elseif parameter == "TrialPoints" then
    OUT=[[filter:ClearTrialPoints();
    $(for i=1,#value do OUT=OUT .. "\
    idx = SimpleITK.VectorUInt32();\
    for _,v in ipairs(".. value[i] ..") do idx:push_back(v) end\
    filter:AddTrialPoint( idx );"end)]]
elseif point_vec and point_vec == 1 then
    OUT=[[filter:Clear${parameter}();
]]
    for i=1,#value do
      OUT=OUT .. [[
      pts = SimpleITK.VectorUInt32();
      for _,v in ipairs(]].. value[i] ..[[) do pts:push_back(v) end
      filter:Add${parameter:gsub('s([0-9]?)$','%1')}( pts );]]
    end
elseif dim_vec and dim_vec == 1 then
   if type == "bool" then
     OUT="idx = SimpleITK.VectorBool();"
   elseif type == "uint8_t" then
     OUT="idx = SimpleITK.VectorUInt8();"
   elseif type == "int" then
      OUT="idx = SimpleITK.VectorInt32();"
   elseif type == "double" then
      OUT="idx = SimpleITK.VectorDouble();"
   else
     OUT="idx = SimpleITK.VectorUInt32();"
   end

   OUT=OUT.. [[

    for _,v in ipairs(]]
if lua_value then
  OUT=OUT..'${lua_value}'
else
  OUT=OUT..'{'
  for i=1,#value-1 do
    OUT=OUT..value[i]..", "
  end
  OUT=OUT..value[#value]..'}'
end
OUT=OUT..[[) do idx:push_back(v) end
    filter:Set${parameter}( idx );]]
else
OUT=[[
    filter:Set${parameter}( $(if lua_value then OUT='${lua_value}' else OUT='${value}' end) );]]
end)
)
)

    inputs = {}
    for i=2,#arg-1 do
       print( "reading..."..arg[i] );
       reader:SetFileName ( arg[i] );
       table.insert( inputs, reader:Execute() );
    end

$(if inputA_cast then
OUT=[[
      inputs[1] = SimpleITK.Cast( inputs[1], SimpleITK.${inputA_cast} );
     ]]
end)
$(if inputB_cast then
OUT=[[
      inputs[2] = SimpleITK.Cast( inputs[2], SimpleITK.${inputB_cast} );
     ]]
end)



    output = filter:Execute ( unpack( inputs ) )
$(if not no_return_image then
OUT=[[
    labelIDs = { SimpleITK.sitkLabelUInt8, SimpleITK.sitkLabelUInt16, SimpleITK.sitkLabelUInt32, SimpleITK.sitkLabelUInt64 }
    for _,v in pairs( labelIDs ) do
        if v == output:GetPixelID()  then
          output = SimpleITK.LabelMapToLabel(output)
        end
    end

    writer:SetFileName ( arg[#arg] )
    writer:Execute ( output )
]]
end)

  end
)
