OTB  9.0.0
Orfeo Toolbox
otbPointSetToDensityImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 otbPointSetToDensityImageFilter_hxx
22 #define otbPointSetToDensityImageFilter_hxx
23 
25 #include "itkImageRegionIterator.h"
26 #include "itkProgressReporter.h"
27 
28 namespace otb
29 {
33 template <class TInputPointSet, class TOutputImage, class TDensityFunction>
35 {
36  m_Radius = 1;
37 }
38 
39 /*-------------------------------------------------------
40  * GenerateData
41  --------------------------------------------------------*/
42 template <class TInputPointSet, class TOutputImage, class TDensityFunction>
44 {
45  // Call the GenerateData() from itk::ImageSource which allow threading
46  Superclass::Superclass::GenerateData();
47 }
48 
49 /*-------------------------------------------------------
50  * ThreadedGenerateData
51  --------------------------------------------------------*/
52 template <class TInputPointSet, class TOutputImage, class TDensityFunction>
54  itk::ThreadIdType threadId)
55 {
56  // sleep(threadId);
57  // std::cerr << threadId << " -> " << outputRegionForThread.GetIndex() << std::endl;
58 
59  // support progress methods/callbacks
60  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
61 
62  typename OutputImageType::Pointer outPtr = this->GetOutput();
63 
64  PointSetDensityFunctionPointerType densityComputeFunction = PointSetDensityFunctionType::New();
65  densityComputeFunction->SetPointSet(this->GetInput());
66  densityComputeFunction->SetRadius(m_Radius);
67 
69  InputType pCenter;
70  IndexType index;
71  itk::ImageRegionIterator<OutputImageType> itOut(outPtr, outputRegionForThread);
72  itOut.GoToBegin();
74 
75  while (!itOut.IsAtEnd())
76  {
77  index = itOut.GetIndex();
78  outPtr->TransformIndexToPhysicalPoint(index, pCenter);
79 
80  itOut.Set(densityComputeFunction->Evaluate(pCenter));
81  ++itOut;
82  progress.CompletedPixel();
83  }
84 }
85 
86 /*----------------------------------------------------------------
87  GenerateOutputInformation
88  -----------------------------------------------------------------*/
89 template <class TInputPointSet, class TOutputImage, class TDensityFunction>
91 {
92  // Superclass::GenerateOutputInformation();
93  typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
94 
95  if (!outputPtr)
96  {
97  return;
98  }
99 
100  typename OutputImageType::RegionType region;
101  IndexType start;
102  start.Fill(0);
103 
104  region.SetSize(this->GetSize());
105  region.SetIndex(start);
106 
107  outputPtr->SetOrigin(this->GetOrigin());
108  outputPtr->SetSignedSpacing(this->GetSpacing());
109  outputPtr->SetRegions(region);
110 }
111 
112 /*----------------------------------------------------------------
113  PrintSelf
114  -----------------------------------------------------------------*/
115 template <class TInputPointSet, class TOutputImage, class TDensityFunction>
117 {
118  Superclass::PrintSelf(os, indent);
119 }
120 }
121 #endif
otb::PointSetToDensityImageFilter::ThreadedGenerateData
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override
Definition: otbPointSetToDensityImageFilter.hxx:53
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::PointSetToDensityImageFilter::GenerateOutputInformation
void GenerateOutputInformation() override
Definition: otbPointSetToDensityImageFilter.hxx:90
otb::PointSetToDensityImageFilter::InputType
PointSetDensityFunctionType::InputType InputType
Definition: otbPointSetToDensityImageFilter.h:66
otb::PointSetToDensityImageFilter::PointSetToDensityImageFilter
PointSetToDensityImageFilter()
Definition: otbPointSetToDensityImageFilter.hxx:34
otb::PointSetToDensityImageFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbPointSetToDensityImageFilter.h:62
otbPointSetToDensityImageFilter.h
otb::PointSetToDensityImageFilter::GenerateData
void GenerateData() override
Definition: otbPointSetToDensityImageFilter.hxx:43
otb::PointSetToDensityImageFilter::PointSetDensityFunctionPointerType
PointSetDensityFunctionType::Pointer PointSetDensityFunctionPointerType
Definition: otbPointSetToDensityImageFilter.h:67
otb::PointSetToDensityImageFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbPointSetToDensityImageFilter.hxx:116
otb::PointSetToDensityImageFilter::IndexType
OutputImageType::IndexType IndexType
Definition: otbPointSetToDensityImageFilter.h:61