ITK: write volume image (sagittal/aixal/coronal) to 2D series dicom in axial direction

I have a volume, and it may be acquired in sagittal/aixal/coronal direction. Then, I want to save it to 2D series in axial direction. How can we implement this function.

Update:
I use the itkExtractImageFilter to extract the axial image, and the code is:

void main()
{


	using ImageType = itk::Image<unsigned short, 3>;
	using ReaderType = itk::ImageSeriesReader< ImageType >;

	itk::GDCMImageIO::Pointer dicomIO = itk::GDCMImageIO::New();
	using NameGeneratorType = itk::GDCMSeriesFileNames;
	NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
	nameGenerator->SetInputDirectory("E:\\DeepLearningWork\\registration\\Jill_U_20060905\\SAG_T1_3D_MP-RAGE_8");

	const ReaderType::FileNamesContainer & filenames = nameGenerator->GetInputFileNames();
	ReaderType::Pointer reader = ReaderType::New();
	reader->SetImageIO(dicomIO);
	reader->SetFileNames(filenames);
	reader->UpdateLargestPossibleRegion();
	reader->Update();

	auto size = reader->GetOutput()->GetLargestPossibleRegion().GetSize();
	int direction = 1;
	int totalSlice = size[direction];
	size[direction] = 0;
	using OutputImageType = itk::Image<signed short, 2>;
	using ExtractType = itk::ExtractImageFilter<ImageType, OutputImageType>;

	using WriterType = itk::ImageFileWriter<OutputImageType>;
	WriterType::Pointer writer = WriterType::New();
	writer->SetImageIO(dicomIO);
	string path = "E:\\DeepLearningWork\\registration\\O1\\";
	for (int i = 0; i < totalSlice; i++)
	{
		ExtractType::Pointer extractor = ExtractType::New();
		ImageType::IndexType start = reader->GetOutput()->GetLargestPossibleRegion().GetIndex();
		const unsigned int sliceNumber = i;
		start[direction] = sliceNumber;
		ImageType::RegionType region;
		region.SetSize(size);
		region.SetIndex(start);
		extractor->SetDirectionCollapseToIdentity();
		extractor->SetInput(reader->GetOutput());
		extractor->SetExtractionRegion(region);
		extractor->UpdateLargestPossibleRegion();
		auto img = extractor->GetOutput();
		char sliceId[10];
		itoa(i, sliceId, 10);
		string name = path + sliceId;
		auto xxx = name.data();
		writer->SetInput(img);
		writer->SetFileName(xxx);
		writer->Update();
		writer->Write();
	}
}

However, when I load the saved image in RadiAnt, I can not find any header information, and the order of images is random. How can I fix this problem?

The easiest modification is to have direction depending on spatial orientation of the image. This is to give you an idea:

#include <itkSpatialOrientation.h>

ImageType::Pointer image = reader->GetOutput();
itk::SpatialOrientationAdapter adapter;
const unsigned int orientation = static_cast<unsigned int>(
   adapter.FromDirectionCosines(image->GetDirection()));
switch (orientation)
{
  // These names are opposite of DICOM conversion. This RAI = DICOM LPS
  case itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RIP:
    break;
  case itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_LIP:
    break;
  case itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RSP:
    break;
  ...
  }

In the SimpleITKFilters remote modules ( and in SimpleITK ) there is a DICOMOrientImageFilter. This filter does the same things and the itkOrientImageFilter, but uses the DICOM convention for image orientation to avoid confusion in the above comment.