OTB  6.1.0
Orfeo Toolbox
otbVectorDataToRoadDescriptionFilter.txx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2017 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 otbVectorDataToRoadDescriptionFilter_txx
22 #define otbVectorDataToRoadDescriptionFilter_txx
23 
25 
26 namespace otb
27 {
28 
29 // Constructor
30 template <class TVectorData, class TOpticalImage>
33 {
34  this->SetNumberOfRequiredInputs(3);
35 
36  m_NDVIFeatureFunction = ParserConditionFeatureFunctionType::New();
37  m_NDVIFeatureFunction->SetExpression("ndvi(b3, b4) > 0.4");
38 
39  m_SpectralAngleFeatureFunction = ParserConditionFeatureFunctionType::New();
40  m_SpectralAngleFeatureFunction->SetExpression("spectralAngle > 0.25");
41 
42  //Example for QuickBird images (on a specific image)
44  refPixel.SetSize(4);
45  refPixel[0] = 252;
46  refPixel[1] = 357;
47  refPixel[2] = 232;
48  refPixel[3] = 261;
49  m_SpectralAngleFeatureFunction->SetSpectralAngleReferencePixel(refPixel);
50 
51  m_DBOverlapFeatureFunction = DBOverlapFeatureFunctionType::New();
52 
53  m_DescriptorsList.push_back("NONDVI");
54  m_DescriptorsList.push_back("ROADSA");
55  m_DescriptorsList.push_back("NOBUIL");
56 }
57 
58 template <class TVectorData, class TOpticalImage>
59 void
62 {
63  this->AddSupport(const_cast<OpticalImageType *>(support), 0);
64 }
65 
66 template <class TVectorData, class TOpticalImage>
68 ::OpticalImageType *
71 {
72  return static_cast<const OpticalImageType *>
73  (this->GetSupport(0));
74 }
75 
76 
77 template <class TVectorData, class TOpticalImage>
78 void
81 {
82  this->AddSupport(const_cast<VectorDataType *>(support), 1);
83 }
84 
85 template <class TVectorData, class TOpticalImage>
90 {
91  return static_cast<const VectorDataType *>
92  (this->GetSupport(1));
93 }
94 
95 template <class TVectorData, class TOpticalImage>
96 void
99 {
100  m_NDVIFeatureFunction->SetInputImage(const_cast<OpticalImageType *>(this->GetOpticalImage()));
101  m_SpectralAngleFeatureFunction->SetInputImage(const_cast<OpticalImageType *>(this->GetOpticalImage()));
102  m_DBOverlapFeatureFunction->SetInputVectorData(const_cast<VectorDataType *>(this->GetBuildingsDB()));
103 
104  // Retrieving root node
105  typename DataNodeType::Pointer root = this->GetOutput(0)->GetDataTree()->GetRoot()->Get();
106  // Create the document node
107  typename DataNodeType::Pointer document = DataNodeType::New();
108  document->SetNodeType(otb::DOCUMENT);
109  // Adding the layer to the data tree
110  this->GetOutput(0)->GetDataTree()->Add(document, root);
111  // Create the folder node
112  typename DataNodeType::Pointer folder = DataNodeType::New();
113  folder->SetNodeType(otb::FOLDER);
114  // Adding the layer to the data tree
115  this->GetOutput(0)->GetDataTree()->Add(folder, document);
116 
117  TreeIteratorType itVector(this->GetInput()->GetDataTree());
118  itVector.GoToBegin();
119  while (!itVector.IsAtEnd())
120  {
121  if (!itVector.Get()->IsRoot() && !itVector.Get()->IsDocument() && !itVector.Get()->IsFolder())
122  {
123  typename DataNodeType::Pointer currentGeometry = itVector.Get();
124  currentGeometry->SetFieldAsDouble("NONDVI", (double)(m_NDVIFeatureFunction->Evaluate(*(currentGeometry.GetPointer()))[0]));
125  currentGeometry->SetFieldAsDouble("ROADSA", (double)(m_SpectralAngleFeatureFunction->Evaluate(*(currentGeometry.GetPointer()))[0]));
126  currentGeometry->SetFieldAsDouble("NOBUIL", (double)(m_DBOverlapFeatureFunction->Evaluate(*(currentGeometry.GetPointer()))[0]));
127 
128  this->GetOutput(0)->GetDataTree()->Add(currentGeometry, folder);
129  }
130  ++itVector;
131  }
132 }
133 
134 // PrintSelf Method
135 template <class TVectorData, class TOpticalImage>
136 void
138 ::PrintSelf(std::ostream& os, itk::Indent indent) const
139 {
140  Superclass::PrintSelf(os, indent);
141 }
142 
143 } // end namespace otb
144 
145 #endif
VectorDataToRoadDescriptionFilter associates a score to each adapted input VectorData DataNode...
otb::VectorData< VectorDataCoordinatePrecisionType, 2, VectorDataValuePrecisionType > VectorDataType
virtual void AddOpticalImage(const OpticalImageType *support)
virtual const ValueType & Get() const
virtual void AddBuildingsDB(const VectorDataType *support)
bool IsAtEnd(void) const
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE