Orfeo Toolbox  4.0
otbLabelObjectOpeningMuParserFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17  =========================================================================*/
18 #ifndef __otbLabelObjectOpeningMuParserFilter_txx
19 #define __otbLabelObjectOpeningMuParserFilter_txx
20 
22 #include <iostream>
23 #include <string>
24 
25 #include "itkImageRegionIterator.h"
27 #include "itkNumericTraits.h"
28 #include "itkProgressReporter.h"
29 
30 namespace otb
31 {
32 
33 // constructor
34 template<class TImage, class TFunction>
36 {
37  // create the output image for the removed objects
38  this->SetNumberOfRequiredOutputs(2);
39  this->SetNthOutput(1, static_cast<TImage*> (this->MakeOutput(1).GetPointer()));
40 }
41 
42 // Destructor
43 template<class TImage, class TFunction>
45 {
46 }
47 
48 template<class TImage, class TFunction>
50 {
51  Superclass::PrintSelf(os, indent);
52  os << indent << "Expression: " << m_Expression << std::endl;
53 }
54 
55 template<class TImage, class TFunction>
57 {
58  if (m_Expression != expression) m_Expression = expression;
59  m_Functor.SetExpression(m_Expression);
60  this->Modified();
61 }
62 
63 template<class TImage, class TFunction>
65 {
66  return m_Expression;
67 }
68 
69 template<class TImage, class TFunction>
70 const std::map<std::string, double*>& LabelObjectOpeningMuParserFilter<TImage, TFunction>::GetVar() const
71 {
72  return this->m_Functor.GetVar();
73 }
74 
75 template<class TImage, class TFunction>
77 {
78  return this->m_Functor.GetFunList();
79 }
80 
81 template<class TImage, class TFunction>
83 {
84  const std::map<std::string, double*>& variables = this->m_Functor.GetVar();
85 
86  // Get the number of variables
87  std::map<std::string, double*>::const_iterator item = variables.begin();
88 
89  // Query the variables
90  for (; item != variables.end(); ++item)
91  {
92  std::cout << "Name: " << item->first << " Address: [0x" << item->second << "]\n";
93  }
94 
95 }
96 
97 template<class TImage, class TFunction>
99 {
100  return this->m_Functor.CheckExpression();
101 }
102 
103 template<class TImage, class TFunction>
104 void LabelObjectOpeningMuParserFilter<TImage, TFunction>::SetAttributes(std::vector<std::string> shapeAttributes,
105  std::vector<std::string> statAttributes,
106  int nbOfBands)
107 {
108  this->m_Functor.SetAttributes(shapeAttributes, statAttributes, nbOfBands);
109 }
110 
112 template<class TImage, class TFunction>
114 {
115  // if told to run in place and the types support it,
116  if (this->GetInPlace() && this->CanRunInPlace())
117  {
118  // Graft this first input to the output. Later, we'll need to
119  // remove the input's hold on the bulk data.
120  //
121  ImagePointer inputAsOutput = dynamic_cast<TImage *> (const_cast<TImage *> (this->GetInput()));
122 
123  if (inputAsOutput)
124  {
125 
126  this->GraftOutput(inputAsOutput);
127  this->GetOutput()->SetLargestPossibleRegion(this->GetOutput()->GetLargestPossibleRegion());
128  this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetRequestedRegion());
129  this->GetOutput()->SetBufferedRegion(this->GetOutput()->GetBufferedRegion());
130 
131  }
132 
133  // If there are more than one outputs, allocate the remaining outputs
134  for (unsigned int i = 1; i < this->GetNumberOfOutputs(); ++i)
135  {
136  ImagePointer outputPtr;
137 
138  outputPtr = this->GetOutput(i);
139  outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
140  outputPtr->Allocate();
141  }
142  }
143  else
144  {
145  Superclass::AllocateOutputs();
146  // copy the content of the input image to the output image (will be done by ImageSource AllocateOutputs Method)
147  // would never occur : inputasoutput condition is always true, since output and input type is TImage for
148  // LabelObjectOpeningMuParserFilter class
149  }
150 }
151 
152 template<class TImage, class TFunction>
154 {
156 }
157 
158 template<class TImage, class TFunction>
160 {
161 
162  ImageConstPointer inputPtr = this->GetInput();
163  // Allocate the output
164  this->AllocateOutputs();
165 
166  ImageType * output = this->GetOutput();
167  ImageType * output2 = this->GetOutput(1);
168  assert( this->GetNumberOfOutputs() == 2 );
169  assert( output2 != NULL );
170 
171  // set the background value for the second output - this is not done in the superclasses
172  output2->SetBackgroundValue(output->GetBackgroundValue());
173 
174  itk::ProgressReporter progress(this, 0, output->GetNumberOfLabelObjects());
175  typename ImageType::Iterator it(output);
176 
177  while (!it.IsAtEnd())
178  {
179  typename LabelObjectType::LabelType label = it.GetLabel();
180  LabelObjectType * labelObject = it.GetLabelObject();
181 
182  if (!m_Functor(*labelObject))
183  {
184  // must increment the iterator before removing the object to avoid invalidating the iterator
185  ++it;
186  output2->AddLabelObject(labelObject);
187  output->RemoveLabel(label);
188  }
189  else
190  {
191  ++it;
192  }
193 
194  progress.CompletedPixel();
195  }
196 
197 }
198 
199 } // end namespace otb
200 
201 #endif

Generated at Sat Mar 8 2014 16:04:53 for Orfeo Toolbox with doxygen 1.8.3.1