This file is indexed.

/usr/include/OTB-5.8/otbStatisticsXMLFileWriter.txx is in libotb-dev 5.8.0+dfsg-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef otbStatisticsXMLFileWriter_txx
#define otbStatisticsXMLFileWriter_txx

#include "otbStatisticsXMLFileWriter.h"
#include "itkMacro.h"
#include "itksys/SystemTools.hxx"
#include "otb_tinyxml.h"
#include "otbStringUtils.h"

namespace otb {


template < class TMeasurementVector >
StatisticsXMLFileWriter<TMeasurementVector>
::StatisticsXMLFileWriter(): m_FileName("")
{}


template < class TMeasurementVector >
void
StatisticsXMLFileWriter<TMeasurementVector>
::AddInput(const char * name,  const MeasurementVectorType& inputVector )
{
  InputDataType    inputData;
  inputData.first  = name;

  // Check if the statistic name is already added
  for(unsigned int idx= 0; idx< m_MeasurementVectorContainer.size(); ++idx)
    {
    if(strcmp(m_MeasurementVectorContainer[idx].first.c_str(), name) == 0 )
      {
      itkExceptionMacro(<<"Token selected ("
                        <<name<<") is already added to the XML file");
      }
    }

  inputData.second = inputVector;
  m_MeasurementVectorContainer.push_back(inputData);
}

template < class TMeasurementVector >
void
StatisticsXMLFileWriter<TMeasurementVector>
::GenerateData()
{
  // Check if the input are not null
  if(m_MeasurementVectorContainer.size() == 0 && m_GenericMapContainer.size() == 0)
    itkExceptionMacro(<<"At least one input is required, please set input using the methods AddInput or AddInputMap");

  // Check if the filename is not empty
  if(m_FileName.empty())
    itkExceptionMacro(<<"The XML output FileName is empty, please set the filename via the method SetFileName");

  // Check that the right extension is given : expected .xml */
  std::string extension = itksys::SystemTools::GetFilenameLastExtension(m_FileName);
  if (itksys::SystemTools::LowerCase(extension) != ".xml")
    {
    itkExceptionMacro(<<extension
                      <<" is a wrong Extension FileName : Expected .xml");
    }

  // Write the XML file
  TiXmlDocument doc;

  TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );
  doc.LinkEndChild( decl );

  TiXmlElement * root = ITK_NULLPTR;
  if (m_MeasurementVectorContainer.size())
    {
    root = new TiXmlElement( "FeatureStatistics");
    doc.LinkEndChild( root );
    }

  // Iterate through the input
  for (unsigned int i = 0; i < m_MeasurementVectorContainer.size(); ++i)
    {
    std::string            featureName              = m_MeasurementVectorContainer[i].first;
    MeasurementVectorType  currentMeasurementVector = m_MeasurementVectorContainer[i].second;

    // The current statistic
    TiXmlElement * feature = new TiXmlElement("Statistic");
    feature->SetAttribute("name", featureName.c_str());
    root->LinkEndChild( feature );

    // Store the value for this statistic
    for(unsigned int cindex = 0; cindex < currentMeasurementVector.Size(); ++cindex)
      {
      // For each value in Measurementvector
      TiXmlElement * curStatisticVector = new TiXmlElement("StatisticVector");
      curStatisticVector->SetDoubleAttribute("value", currentMeasurementVector.GetElement(cindex));
      feature->LinkEndChild(curStatisticVector);
      }
    }
    
  // Iterate on map containers
  TiXmlElement * mapRoot = ITK_NULLPTR;
  if (m_GenericMapContainer.size())
    {
    mapRoot = new TiXmlElement( "GeneralStatistics");
    doc.LinkEndChild( mapRoot );
    }

  GenericMapContainer::const_iterator containerIt;
  for ( containerIt = m_GenericMapContainer.begin() ; containerIt != m_GenericMapContainer.end() ; ++containerIt)
    {
    std::string mapName = containerIt->first;
    GenericMapType::const_iterator mapIter;

    // The current statistic
    TiXmlElement * feature = new TiXmlElement("Statistic");
    feature->SetAttribute("name", mapName.c_str());
    mapRoot->LinkEndChild( feature );

    // Store the value for this statistic
    for( mapIter = containerIt->second.begin() ; mapIter != containerIt->second.end() ; ++mapIter )
      {
      // For each value in Measurementvector
      TiXmlElement * curStatisticMap = new TiXmlElement("StatisticMap");
      curStatisticMap->SetAttribute("key" , mapIter->first.c_str());
      curStatisticMap->SetAttribute("value", mapIter->second.c_str());
      feature->LinkEndChild(curStatisticMap);
      }
    }
  

  // Finally, write the file
  if (! doc.SaveFile( m_FileName.c_str() ) )
    {
    itkExceptionMacro(<<"Unable to write the XML file in "
                      << itksys::SystemTools::GetFilenamePath(m_FileName)
                      << " (permission issue? Directory does not exist?)." );
    }

}

template < class TMeasurementVector >
template <typename MapType>
void
StatisticsXMLFileWriter<TMeasurementVector>
::AddInputMap(const char * name, const MapType& map )
{
  std::string token(name);
  
  if(m_GenericMapContainer.count(token) > 0)
    {
    itkExceptionMacro(<<"Token selected ("
                      <<name<<") is already added to the XML file");
    }
  
  typename MapType::const_iterator it;
  GenericMapType insideMap;
  std::string tmpKey;
  std::string tmpVal;
  for ( it = map.begin() ; it != map.end() ; ++it)
    {
    tmpKey = boost::lexical_cast<std::string>(it->first);
    tmpVal = boost::lexical_cast<std::string>(it->second);
    insideMap[tmpKey] = tmpVal;
    }
  m_GenericMapContainer[token] = insideMap;
}

template < class TMeasurementVector >
void
StatisticsXMLFileWriter<TMeasurementVector>
::CleanInputs()
{
  // clear both containers
  m_MeasurementVectorContainer.clear();
  m_GenericMapContainer.clear();
}

template < class TMeasurementVector >
void
StatisticsXMLFileWriter<TMeasurementVector>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
  // Call superclass implementation
  Superclass::PrintSelf(os, indent);

  // Print Writer state
  os << indent << "Input FileName: "<< m_FileName << std::endl;
  os << indent << "Vector statistics: ";
  for (unsigned int i=0 ; i < m_MeasurementVectorContainer.size() ; ++i)
    {
    if (i>0) os <<", ";
    os << m_MeasurementVectorContainer[i].first;
    }
  os << std::endl;
  os << indent << "Map statistics: ";
  for (GenericMapContainer::const_iterator it = m_GenericMapContainer.begin() ; it != m_GenericMapContainer.end() ; ++it)
    {
    if (it != m_GenericMapContainer.begin()) os <<", ";
    os << it->first;
    }
  os << std::endl;
}

} // End namespace otb

#endif