WRAP_CLASS("itk::ImageSeriesWriter")

  SET(MANAGED_TYPE_TEMPLATE ${MANAGED_ITK_SOURCE_COMMON_PATH}/itkManagedProcessObject_TYPE.cxx.in)
  SET(MANAGED_WRAPPER_TEMPLATE ${MANAGED_ITK_SOURCE_COMMON_PATH}/itkManagedProcessObject_WRAPPER.cxx.in)

  UNIQUE(image_types "UC;${WRAP_ITK_SCALAR};${WRAP_ITK_RGB}")
  FOREACH(d1 ${WRAP_ITK_DIMS})
    FOREACH(d2 ${WRAP_ITK_DIMS})
      IF("${d1}" GREATER "${d2}")
        FOREACH(t ${image_types})
          WRAP_TEMPLATE("${ITKM_I${t}${d1}}${ITKM_I${t}${d2}}"
                        "${ITKT_I${t}${d1}},${ITKT_I${t}${d2}}")        
        ENDFOREACH(t)
      ENDIF("${d1}" GREATER "${d2}")
    ENDFOREACH(d2)
  ENDFOREACH(d1)

  BEGIN_MANAGED_PROPERTY("StartIndex" GETSET)
    SET(MANAGED_PROPERTY_SUMMARY   "Use this method to set the starting index of the series. The default value is 1.")
    SET(MANAGED_PROPERTY_TYPE      "unsigned long")
    SET(MANAGED_PROPERTY_GET_BODY  "return m_PointerToNative->GetStartIndex();")
    SET(MANAGED_PROPERTY_SET_BODY  "m_PointerToNative->SetStartIndex( value );")
  END_MANAGED_PROPERTY()

  BEGIN_MANAGED_PROPERTY("IncrementIndex" GETSET)
    SET(MANAGED_PROPERTY_SUMMARY   "Set the increment of the index of the series. The default value is 1.")
    SET(MANAGED_PROPERTY_TYPE      "unsigned long")
    SET(MANAGED_PROPERTY_GET_BODY  "return m_PointerToNative->GetIncrementIndex();")
    SET(MANAGED_PROPERTY_SET_BODY  "m_PointerToNative->SetIncrementIndex( value );")
  END_MANAGED_PROPERTY()
  
  BEGIN_MANAGED_PROPERTY("SeriesFormat" GETSET)
    SET(MANAGED_PROPERTY_SUMMARY   "The format string used to generate each filename in the series. The filename is built with sprintf(filename, SeriesFormat, number) where number starts at StartIndex and is incremented by IncrementIndex.")
    SET(MANAGED_PROPERTY_TYPE      "String^")
    SET(MANAGED_PROPERTY_GET_BODY  "return gcnew String( m_PointerToNative->GetSeriesFormat() );")
    SET(MANAGED_PROPERTY_SET_BODY  "std::string stdvalue; ManagedTypes::ToNativeString( value, stdvalue ); m_PointerToNative->SetSeriesFormat( stdvalue.c_str() );")
  END_MANAGED_PROPERTY()

  BEGIN_MANAGED_METHOD("AddFileName")
    SET(MANAGED_METHOD_SUMMARY         "Add a single filename to the list of files. To add a vector of filenames, use the AddFileNames method.")
    SET(MANAGED_METHOD_RETURN_TYPE     "void")
    SET(MANAGED_METHOD_PARAMS          "String^ filename")
    SET(MANAGED_METHOD_TYPE_BODY       "std::string stdfilename; ManagedTypes::ToNativeString( filename, stdfilename ); m_PointerToNative->AddFileName( stdfilename.c_str() );")
    SET(MANAGED_METHOD_WRAPPER_BODY    "iInstance->AddFileName( filename );")
  END_MANAGED_METHOD()
  
  BEGIN_MANAGED_METHOD("SetFileName")
    SET(MANAGED_METHOD_SUMMARY         "Set the first file name to be processed. This deletes previous filenames.")
    SET(MANAGED_METHOD_RETURN_TYPE     "void")
    SET(MANAGED_METHOD_PARAMS          "String^ filename")
    SET(MANAGED_METHOD_TYPE_BODY       "std::string stdfilename; ManagedTypes::ToNativeString( filename, stdfilename ); m_PointerToNative->SetFileName( stdfilename.c_str() );")
    SET(MANAGED_METHOD_WRAPPER_BODY    "iInstance->SetFileName( filename );")
  END_MANAGED_METHOD()

  BEGIN_MANAGED_METHOD("SetFileNames")
    SET(MANAGED_METHOD_SUMMARY         "Set the array of strings that contains the file names. Files are processed in sequential order.")
    SET(MANAGED_METHOD_RETURN_TYPE     "void")
    SET(MANAGED_METHOD_PARAMS          "array<System::String^>^ filenames")
    SET(MANAGED_METHOD_TYPE_BODY       "for each (System::String^ filename in filenames){ this->AddFileName( filename ); }")
    SET(MANAGED_METHOD_WRAPPER_BODY    "iInstance->SetFileNames( filenames );")
  END_MANAGED_METHOD()

  SET(body "")
  SET(body "${body}if (NativeType::InputImageType::ImageDimension != 3){ throw gcnew ApplicationException(\"The image type must have three (3) dimensions.\"); }\n")
  SET(body "${body}\t\tif( this->m_PointerToNative->GetInput() == NULL){ throw gcnew ApplicationException(\"The input image must be set before calling this method.\"); }\n")
  SET(body "${body}\t\tunsigned long sizeZ = this->m_PointerToNative->GetInput()->GetLargestPossibleRegion().GetSize()[2];\n")
  SET(body "${body}\t\tfor (unsigned int i=1; i<=sizeZ; i++){ this->AddFileName( String::Format(filenameFormat, i.ToString(seriesFormat)) ); }\n")

  BEGIN_MANAGED_METHOD("SetFileNames")
    SET(MANAGED_METHOD_SUMMARY         "Set the filename format and series formation defining the array of filenames. Example: filenameFormat=\"C:/temp/out_{0}.png\", seriesFormat=\"000\"")
    SET(MANAGED_METHOD_RETURN_TYPE     "void")
    SET(MANAGED_METHOD_PARAMS          "System::String^ filenameFormat, System::String^ seriesFormat")
    SET(MANAGED_METHOD_TYPE_BODY       "${body}")
    SET(MANAGED_METHOD_WRAPPER_BODY    "iInstance->SetFileNames( filenameFormat, seriesFormat );")
  END_MANAGED_METHOD()

  BEGIN_MANAGED_METHOD("SetInput")
    SET(MANAGED_METHOD_SUMMARY         "Set the first input of the writer object.")
    SET(MANAGED_METHOD_RETURN_TYPE     "void")
    SET(MANAGED_METHOD_PARAMS          "itkDataObject^ input")
    SET(MANAGED_METHOD_TYPE_BODY       "this->m_PointerToNative->SetInput( reinterpret_cast<NativeType::InputImageType*>(input->NativePointer.ToPointer()) );")
    SET(MANAGED_METHOD_WRAPPER_BODY    "iInstance->SetInput( input );")
  END_MANAGED_METHOD()

  BEGIN_MANAGED_METHOD("SetInput")
    SET(MANAGED_METHOD_SUMMARY         "Set the first input of the writer object.")
    SET(MANAGED_METHOD_RETURN_TYPE     "void")
    SET(MANAGED_METHOD_PARAMS          "IntPtr itkDataObjectPtr")
    SET(MANAGED_METHOD_TYPE_BODY       "this->m_PointerToNative->SetInput( (NativeType::InputImageType*)itkDataObjectPtr.ToPointer() );")
    SET(MANAGED_METHOD_WRAPPER_BODY    "iInstance->SetInput( itkDataObjectPtr );")
  END_MANAGED_METHOD()

  BEGIN_MANAGED_METHOD("SetImageIO")
    SET(MANAGED_METHOD_SUMMARY         "Set the ImageIO helper class. Often this is created via the object factory mechanism that determines whether a particular ImageIO can read a certain file. This method provides a way to get the ImageIO instance that is created. Or you can directly specify the ImageIO to use to read a particular file in case the factory mechanism will not work properly (e.g., unknown or unusual extension).")
    SET(MANAGED_METHOD_RETURN_TYPE     "void")
    SET(MANAGED_METHOD_PARAMS          "itkImageIOBase^ imageIO")
    SET(MANAGED_METHOD_TYPE_BODY       "this->m_PointerToNative->SetImageIO( (ImageIOBase*)imageIO->NativePointer.ToPointer());")
    SET(MANAGED_METHOD_WRAPPER_BODY    "iInstance->SetImageIO(imageIO);")
  END_MANAGED_METHOD()
  
  BEGIN_MANAGED_METHOD("GetImageIO")
    SET(MANAGED_METHOD_SUMMARY         "Get the ImageIO helper class. Often this is created via the object factory mechanism that determines whether a particular ImageIO can read a certain file. This method provides a way to get the ImageIO instance that is created. Or you can directly specify the ImageIO to use to read a particular file in case the factory mechanism will not work properly (e.g., unknown or unusual extension).")
    SET(MANAGED_METHOD_RETURN_TYPE     "void")
    SET(MANAGED_METHOD_PARAMS          "itkImageIOBase^ imageIO")
    SET(MANAGED_METHOD_TYPE_BODY       "ImageIOBase* nativeImageIO = this->m_PointerToNative->GetImageIO(); imageIO->NativePointer = IntPtr(nativeImageIO);")
    SET(MANAGED_METHOD_WRAPPER_BODY    "iInstance->GetImageIO(imageIO);")
  END_MANAGED_METHOD()
  
  BEGIN_MANAGED_METHOD("GetImageIO")
    SET(MANAGED_METHOD_SUMMARY         "Get the ImageIO helper class. Often this is created via the object factory mechanism that determines whether a particular ImageIO can read a certain file. This method provides a way to get the ImageIO instance that is created. Or you can directly specify the ImageIO to use to read a particular file in case the factory mechanism will not work properly (e.g., unknown or unusual extension).")
    SET(MANAGED_METHOD_RETURN_TYPE     "IntPtr")
    SET(MANAGED_METHOD_PARAMS          "void")
    SET(MANAGED_METHOD_TYPE_BODY       "ImageIOBase* nativeImageIO = this->m_PointerToNative->GetImageIO(); return IntPtr(nativeImageIO);")
    SET(MANAGED_METHOD_WRAPPER_BODY    "return iInstance->GetImageIO();")
  END_MANAGED_METHOD()
  
END_WRAP_CLASS()