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