OTB  6.7.0
Orfeo Toolbox
otbMultiImageFileWriter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) CS SI
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbMultiImageFileWriter_hxx
22 #define otbMultiImageFileWriter_hxx
23 
25 #include "otbImageIOFactory.h"
26 #include "otbMacro.h"
27 
28 namespace otb
29 {
30 
31 template <class TImage>
33 ::Sink(typename TImage::ConstPointer inputImage,
34  const std::string & fileName):
35  SinkBase(dynamic_cast<const ImageBaseType*>(inputImage.GetPointer())),
36  m_Writer(otb::ImageFileWriter<TImage>::New()),
37  m_ImageIO(NULL)
38 {
39  m_Writer->SetFileName(fileName);
40  m_Writer->SetInput(inputImage);
41 }
42 
43 template <class TImage>
46  SinkBase(dynamic_cast<const ImageBaseType*>(writer->GetInput()->GetPointer())),
47  m_Writer(writer),
48  m_ImageIO(NULL)
49 {
50 }
51 
52 template <class TImage>
53 bool
56 {
57  if (m_ImageIO.IsNull())
58  return false;
59  return m_ImageIO->CanStreamWrite();
60 }
61 
62 template <class TImage>
63 void
66 {
67  m_Writer->UpdateOutputInformation();
68  m_ImageIO = m_Writer->GetImageIO();
69 }
70 
71 template <class TImage>
72 void
74 ::Write(const RegionType & streamRegion)
75 {
76  // Write the image stream
77  itk::ImageIORegion ioRegion(TImage::ImageDimension);
78  for (unsigned int i = 0; i < TImage::ImageDimension; ++i)
79  {
80  ioRegion.SetSize(i, streamRegion.GetSize(i));
81  ioRegion.SetIndex(i, streamRegion.GetIndex(i));
82  }
83  m_ImageIO->SetIORegion(ioRegion);
84  m_Writer->UpdateOutputData(nullptr);
85 }
86 
87 } // end of namespace otb
88 
89 #endif // otbMultiImageFileWriter_hxx
const IndexType & GetIndex() const
virtual void SetInput(const InputImageType *input)
virtual void Write(const RegionType &streamRegion)
virtual void SetFileName(const std::string &extendedFileName)
void SetIndex(const IndexType &index)
const SizeType & GetSize() const
DataObject * GetInput(const DataObjectIdentifierType &key)
void SetSize(const SizeType &size)
otb::ImageFileWriter< TImage >::Pointer m_Writer
Writes image data to a single file with streaming process.