1 /*========================================================================= 2 * 3 * Copyright Insight Software Consortium 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0.txt 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *=========================================================================*/ 18 #ifndef itkStreamingProcessObject_h 19 #define itkStreamingProcessObject_h 20 21 #include "itkProcessObject.h" 22 23 namespace itk 24 { 25 26 /** \class Base class interface to process data on multiple requested input chunks 27 * 28 * Streaming allows the data to be split into chunks and processed 29 * separately. The StreamingProcessObject class extends functionally 30 * to execute the primary input's pipeline multiple times over 31 * different requested regions. After each requested region is 32 * generated by the upstream pipeline the StreamedGenerateData method 33 * is called. 34 * 35 * \ingroup ITKSystemObjects 36 * \ingroup DataProcessing 37 * \ingroup ITKCommon 38 */ 39 class ITKCommon_EXPORT StreamingProcessObject 40 : public ProcessObject 41 { 42 public: 43 ITK_DISALLOW_COPY_AND_ASSIGN(StreamingProcessObject); 44 45 /** Standard class typedefs. */ 46 using Self = StreamingProcessObject; 47 using Superclass = ProcessObject; 48 using Pointer = SmartPointer< Self >; 49 using ConstPointer = SmartPointer< const Self >; 50 51 /** Run-time type information (and related methods). */ 52 itkTypeMacro(StreamingProcessObject,ProcessObject); 53 54 /** Override PropagateRequestedRegion from ProcessObject 55 * Since inside UpdateOutputData we iterate over streaming pieces 56 * we don't need to proapage up the pipeline 57 */ 58 void PropagateRequestedRegion(DataObject *output) override; 59 60 void GenerateData() override; 61 62 /** Override UpdateOutputData() from ProcessObject to divide upstream 63 * updates into pieces. */ 64 void UpdateOutputData(DataObject *output) override; 65 66 /** The current requested region number during execution. The value 67 * -1, is used when the pipeline is not currently being updated. */ 68 virtual int GetCurrentRequestNumber( ) const; 69 70 void ResetPipeline() override; 71 72 protected: 73 StreamingProcessObject( ); 74 ~StreamingProcessObject( ) override; 75 76 void PrintSelf(std::ostream& os, Indent indent) const override; 77 78 /** \brief Return the actual number of regions to request upstream. 79 * 80 * This method can be overloaded to return one, when a derived 81 * filter is unable stream. 82 */ 83 virtual unsigned int GetNumberOfInputRequestedRegions() = 0; 84 85 86 /** \brief For each streamed region, propagate request to all inputs. 87 * 88 * Derived classes should overload this method to compute regions 89 * splits and propagate to the particular DataObject types used for 90 * the input. 91 */ 92 virtual void GenerateNthInputRequestedRegion( unsigned int inputRequestedRegionNumber ) = 0; 93 94 /** This method will be called multiple times for each requested 95 * region generated by the input. */ 96 virtual void StreamedGenerateData( unsigned int inputRequestedRegionNumber ) = 0; 97 98 /** Called before the input's first requested region is set or 99 * updated. 100 */ 101 virtual void BeforeStreamedGenerateData(); 102 103 /** Called after all requested regions have been process. 104 */ 105 virtual void AfterStreamedGenerateData(); 106 107 private: 108 109 int m_CurrentRequestNumber{-1}; 110 }; 111 112 } // end namespace itk 113 114 #endif //itkStreamingProcessObject_h 115