21 #ifndef otbMultiImageFileWriter_hxx
22 #define otbMultiImageFileWriter_hxx
31 template <
class TImage>
39 template <
class TImage>
45 template <
class TImage>
48 if (m_ImageIO.IsNull())
50 return m_ImageIO->CanStreamWrite();
53 template <
class TImage>
56 m_Writer->UpdateOutputInformation();
57 m_ImageIO = m_Writer->GetImageIO();
60 template <
class TImage>
64 itk::ImageIORegion ioRegion(TImage::ImageDimension);
65 for (
unsigned int i = 0; i < TImage::ImageDimension; ++i)
67 ioRegion.SetSize(i, streamRegion.GetSize(i));
68 ioRegion.SetIndex(i, streamRegion.GetIndex(i));
70 m_ImageIO->SetIORegion(ioRegion);
71 m_Writer->UpdateOutputData(
nullptr);
74 template <
class TImage>
78 auto fnameHelper = m_Writer->GetFilenameHelper();
79 if (fnameHelper->BoxIsSet())
81 std::vector<unsigned int> boxVector;
84 if (boxVector.size() != 4)
86 itk::ImageFileWriterException e(__FILE__, __LINE__);
87 std::ostringstream msg;
88 msg <<
"Invalid box option " << fnameHelper->GetBox() <<
". The box should contains four elements: startx:starty:sizex:sizey";
89 e.SetDescription(msg.str());
90 e.SetLocation(ITK_LOCATION);
95 typename itk::ImageRegion<2>::IndexType start {{
static_cast<int>(boxVector[0]),
static_cast<int>(boxVector[1])}};
96 typename itk::ImageRegion<2>::SizeType size {{boxVector[2], boxVector[3]}};
97 itk::ImageRegion<2> regionToWrite {start , size};
98 regionToWrite.Crop(m_InputImage->GetLargestPossibleRegion());
103 return m_InputImage->GetLargestPossibleRegion();
107 template <
class TWriter>
113 this->SetNthInput(size - 1,
const_cast<itk::DataObject*
>(
dynamic_cast<const itk::DataObject*
>(writer->GetInput())));
116 auto filenameHelper = writer->GetFilenameHelper();
117 if (filenameHelper->StreamingTypeIsSet())
121 <<
"Streaming configuration through extended filename is used. Any previous streaming configuration (ram value, streaming mode ...) will be ignored.");
123 std::string type = filenameHelper->GetStreamingType();
125 std::string sizemode =
"auto";
127 if (filenameHelper->StreamingSizeModeIsSet())
129 sizemode = filenameHelper->GetStreamingSizeMode();
132 unsigned int sizevalue = 0;
135 if (sizemode ==
"auto")
137 sizevalue = oldDefaultRAM;
140 if (filenameHelper->StreamingSizeValueIsSet())
142 sizevalue =
static_cast<unsigned int>(filenameHelper->GetStreamingSizeValue());
147 if (sizemode !=
"auto")
149 otbLogMacro(Warning, <<
"In auto streaming type, the sizemode option will be ignored.");
153 otbLogMacro(Warning, <<
"sizemode is auto but sizevalue is 0. Value will be fetched from the OTB_MAX_RAM_HINT environment variable if set, or else use "
154 "the default value");
158 else if (type ==
"tiled")
160 if (sizemode ==
"auto")
164 otbLogMacro(Warning, <<
"sizemode is auto but sizevalue is 0. Value will be fetched from the OTB_MAX_RAM_HINT environment variable if set, or else "
165 "use the default value");
169 else if (sizemode ==
"nbsplits")
173 otbLogMacro(Warning, <<
"Streaming sizemode is set to nbsplits but sizevalue is 0. This will result in undefined behaviour. Please consider setting "
174 "the sizevalue by using &streaming:sizevalue=x.");
178 else if (sizemode ==
"height")
182 otbLogMacro(Warning, <<
"Streaming sizemode is set to height but sizevalue is 0. This will result in undefined behaviour. Please consider setting "
183 "the sizevalue by using &streaming:sizevalue=x.");
189 else if (type ==
"stripped")
191 if (sizemode ==
"auto")
196 Warning, <<
"sizemode is auto but sizevalue is 0. Value will be fetched from configuration file if any, or from cmake configuration otherwise.");
201 else if (sizemode ==
"nbsplits")
205 otbLogMacro(Warning, <<
"Streaming sizemode is set to nbsplits but sizevalue is 0. This will result in undefined behaviour. Please consider setting "
206 "the sizevalue by using &streaming:sizevalue=x.");
210 else if (sizemode ==
"height")
214 otbLogMacro(Warning, <<
"Streaming sizemode is set to height but sizevalue is 0. This will result in undefined behaviour. Please consider setting "
215 "the sizevalue by using &streaming:sizevalue=x.");
220 else if (type ==
"none")
222 if (sizemode !=
"" || sizevalue != 0)
224 otbLogMacro(Warning, <<
"Streaming is explicitly disabled, sizemode and sizevalue will be ignored.");
232 if (filenameHelper->StreamingSizeValueIsSet() || filenameHelper->StreamingSizeModeIsSet())
234 otbLogMacro(Warning, <<
"No streaming type is set, streaming sizemode and sizevalue will be ignored.");
239 template <
class TImage>
245 this->SetNthInput(size - 1,
const_cast<itk::DataObject*
>(
dynamic_cast<const itk::DataObject*
>(inputPtr)));
250 #endif // otbMultiImageFileWriter_hxx