diff --git a/Code/IO/otbImageFileWriter.h b/Code/IO/otbImageFileWriter.h index a3533a1c184ad015a8e4a05dd61fe4d2d2e77f9a..0ee02ff4aceec1617b7c6e2a3963a927b26dc95c 100644 --- a/Code/IO/otbImageFileWriter.h +++ b/Code/IO/otbImageFileWriter.h @@ -75,6 +75,7 @@ public: typedef typename InputImageType::Pointer InputImagePointer; typedef typename InputImageType::RegionType InputImageRegionType; typedef typename InputImageType::PixelType InputImagePixelType; + typedef typename InputImageType::IndexType InputIndexType; typedef TInputImage OutputImageType; typedef typename OutputImageType::Pointer OutputImagePointer; typedef typename OutputImageType::RegionType OutputImageRegionType; @@ -156,19 +157,19 @@ public: /** Set the only input of the writer */ virtual void SetInput(const InputImageType *input); - + /** Get writer only input */ const InputImageType* GetInput(); - + /** Override Update() from ProcessObject because this filter * has no output. */ virtual void Update(); - + /** ImageFileWriter Methods */ virtual void SetFileName(const char* extendedFileName); virtual void SetFileName(std::string extendedFileName); virtual const char* GetFileName () const; - + /** Specify the region to write. If left NULL, then the whole image * is written. */ void SetIORegion(const itk::ImageIORegion& region); @@ -192,7 +193,7 @@ public: itkSetObjectMacro(ImageIO, otb::ImageIOBase); itkGetObjectMacro(ImageIO, otb::ImageIOBase); itkGetConstObjectMacro(ImageIO, otb::ImageIOBase); - + protected: ImageFileWriter(); virtual ~ImageFileWriter(); @@ -244,7 +245,7 @@ private: bool m_UseInputMetaDataDictionary; // whether to use the // MetaDataDictionary from the // input or not. - + bool m_WriteGeomFile; // Write a geom file to store the // kwl @@ -254,6 +255,7 @@ private: bool m_IsObserving; unsigned long m_ObserverID; + InputIndexType m_ShiftOutputIndex; }; } // end namespace otb diff --git a/Code/IO/otbImageFileWriter.txx b/Code/IO/otbImageFileWriter.txx index 5ff031060c222fdf4bdafece2a749f9ed281ca12..7bda3ec70f96dfc226c00a87761ccf9bbe6d358f 100644 --- a/Code/IO/otbImageFileWriter.txx +++ b/Code/IO/otbImageFileWriter.txx @@ -68,6 +68,9 @@ ImageFileWriter<TInputImage> m_IsObserving(true), m_ObserverID(0) { + //Init output index shift + m_ShiftOutputIndex.Fill(0); + // By default, we use tiled streaming, with automatic tile size // We don't set any parameter, so the memory size is retrieved from the OTB configuration options this->SetAutomaticAdaptativeStreaming(); @@ -494,7 +497,9 @@ ImageFileWriter<TInputImage> size[1] = atoi(it->c_str()); // size along Y inputRegion.SetSize(size); - inputRegion.SetIndex(start); + + m_ShiftOutputIndex = start; + inputRegion.SetIndex(m_ShiftOutputIndex); otbMsgDevMacro(<< "inputRegion " << inputRegion); @@ -623,7 +628,8 @@ ImageFileWriter<TInputImage> { ioRegion.SetSize(i, streamRegion.GetSize(i)); ioRegion.SetIndex(i, streamRegion.GetIndex(i)); - //ioRegion.SetIndex(i, streamRegion.GetIndex(i) - inputRegion.GetIndex(i)); + //Set the ioRegion index using the shifted index ( (0,0 without box parameter)) + ioRegion.SetIndex(i, streamRegion.GetIndex(i) - m_ShiftOutputIndex[i]); } otbMsgDevMacro(<< "ioregion " << ioRegion ) this->SetIORegion(ioRegion); @@ -711,7 +717,8 @@ ImageFileWriter<TInputImage> typename InputImageRegionType::IndexType tmpIndex; tmpIndex.Fill(0); itk::ImageIORegionAdaptor<TInputImage::ImageDimension>:: - Convert(m_ImageIO->GetIORegion(), ioRegion, tmpIndex); + //Convert(m_ImageIO->GetIORegion(), ioRegion, tmpIndex); + Convert(m_ImageIO->GetIORegion(), ioRegion, m_ShiftOutputIndex); InputImageRegionType bufferedRegion = input->GetBufferedRegion(); // before this test, bad stuff would happend when they don't match