OTB  6.7.0
Orfeo Toolbox
otbAngularProjectionBinaryImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
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 otbAngularProjectionBinaryImageFilter_hxx
22 #define otbAngularProjectionBinaryImageFilter_hxx
24 
25 #include <vnl/vnl_math.h>
26 
27 #include "itkImageRegionIterator.h"
28 #include "itkProgressReporter.h"
29 
30 namespace otb {
31 
32 template < class TInputImage, class TOutputImage, class TPrecision >
35 {
36  this->SetNumberOfRequiredInputs(2);
37 }
38 
39 template < class TInputImage, class TOutputImage, class TPrecision >
40 void
42 ::SetInput1 ( const InputImageType * inputPtr )
43 {
44  this->SetNthInput(0, const_cast<InputImageType*>( inputPtr ));
45 }
46 
47 template < class TInputImage, class TOutputImage, class TPrecision >
48 void
50 ::SetInput2 ( const InputImageType * inputPtr )
51 {
52  this->SetNthInput(1, const_cast<InputImageType*>( inputPtr ));
53 }
54 
55 template < class TInputImage, class TOutputImage, class TPrecision >
56 const TInputImage *
58 ::GetInput1() const
59 {
60  if ( this->GetNumberOfInputs() < 1 )
61  {
62  return nullptr;
63  }
64 
65  return static_cast<const TInputImage * > (this->itk::ProcessObject::GetInput(0) );
66 }
67 
68 template < class TInputImage, class TOutputImage, class TPrecision >
69 const TInputImage *
71 ::GetInput2() const
72 {
73  if ( this->GetNumberOfInputs() < 2 )
74  {
75  return nullptr;
76  }
77 
78  return static_cast<const TInputImage * > (this->itk::ProcessObject::GetInput(1));
79 }
80 
81 template < class TInputImage, class TOutputImage, class TPrecision >
82 void
84 ::SetAngleSet ( std::vector<PrecisionType> & angle )
85 {
86  m_AngleSet = angle;
87  this->SetNumberOfRequiredOutputs( angle.size() );
88  for ( unsigned int i = 0; i < this->GetNumberOfRequiredOutputs(); ++i )
89  {
90  this->SetNthOutput(i, OutputImageType::New());
91  }
92  this->Modified();
93 }
94 
95 template < class TInputImage, class TOutputImage, class TPrecision >
96 void
99 {
100  Superclass::GenerateOutputInformation();
101  for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i)
102  {
103  this->GetOutput(i)->SetRegions(
104  this->GetInput()->GetRequestedRegion());
105  }
106 }
107 
108 template < class TInputImage, class TOutputImage, class TPrecision >
109 void
112  ( const OutputImageRegionType & outputRegionForThread, itk::ThreadIdType threadId )
113 {
114  itk::ProgressReporter reporter(this, threadId,
115  outputRegionForThread.GetNumberOfPixels() );
116 
117  InputImageRegionType inputRegionForThread;
118  this->CallCopyOutputRegionToInputRegion( inputRegionForThread, outputRegionForThread );
119 
121  ( this->GetInput1(), inputRegionForThread );
122  iter1.GoToBegin();
123 
125  ( this->GetInput2(), inputRegionForThread );
126  iter2.GoToBegin();
127 
128  std::vector< itk::ImageRegionIterator<OutputImageType> > outIter
129  ( this->GetNumberOfOutputs() );
130  for ( unsigned int i = 0; i < outIter.size(); ++i )
131  {
133  ( this->GetOutput(i), outputRegionForThread );
134  outIter[i].GoToBegin();
135  }
136 
137  while ( !iter1.IsAtEnd() && !iter2.IsAtEnd() )
138  {
139  for ( unsigned int i = 0; i < outIter.size(); ++i )
140  {
141  outIter[i].Set( std::cos( m_AngleSet[i] ) * iter1.Get()
142  + std::sin( m_AngleSet[i] ) * iter2.Get() );
143  ++outIter[i];
144  }
145 
146  ++iter1;
147  ++iter2;
148 
149  reporter.CompletedPixel();
150  }
151 }
152 
153 } // end of namespace otb
154 
155 #endif
156 
157 
InputImageType::RegionType InputImageRegionType
TInputImage InputImageType
unsigned int ThreadIdType
DataObject * GetInput(const DataObjectIdentifierType &key)
OutputImageType::RegionType OutputImageRegionType
bool IsAtEnd(void) const
PixelType Get(void) const
void SetAngleSet(std::vector< PrecisionType > &angle)
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadID) override