This file is indexed.

/usr/include/OTB-6.4/otbImageSeriesFileReaderBase.txx is in libotb-dev 6.4.0+dfsg-1.

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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
/*
 * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
 * Copyright (C) 2007-2012 Institut Mines Telecom / Telecom Bretagne
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#ifndef otbImageSeriesFileReaderBase_txx
#define otbImageSeriesFileReaderBase_txx
#include "otbImageSeriesFileReaderBase.h"

namespace otb {

template <class TImage, class TInternalImage>
ImageSeriesFileReaderBase<TImage, TInternalImage>
::ImageSeriesFileReaderBase ()
{
  m_OutputList = OutputImageListType::New();
  m_ImageFileReaderList = ReaderListType::New();
  m_FileName = "";
  m_ListOfFileNames.clear();
  m_ListOfBandSelection.clear();
  m_ListOfRegionSelection.clear();
}

template <class TImage, class TInternalImage>
void
ImageSeriesFileReaderBase<TImage, TInternalImage>
::SetFileName(const std::string& file)
{
  return SetFileName(file.c_str());
}

template <class TImage, class TInternalImage>
void
ImageSeriesFileReaderBase<TImage, TInternalImage>
::SetFileName(const char * file)
{
  if (file && (file == m_FileName)) return;

  if (file)
    {
    this->m_FileName = file;
    ReadMetaFile();
    AllocateListOfComponents();
    }
  else this->m_FileName = "";

  this->Modified();
}

template <class TImage, class TInternalImage>
typename ImageSeriesFileReaderBase<TImage, TInternalImage>::OutputImageListType *
ImageSeriesFileReaderBase<TImage, TInternalImage>
::GetOutput()
{
  if (this->GetNumberOfOutputs() < 1)
    throw ImageSeriesFileReaderException(__FILE__,
                                         __LINE__,
                                         "No data to output",
                                         ITK_LOCATION);

  return static_cast<OutputImageListType*>(this->m_OutputList);
}

template <class TImage, class TInternalImage>
typename ImageSeriesFileReaderBase<TImage, TInternalImage>::OutputImageType *
ImageSeriesFileReaderBase<TImage, TInternalImage>
::GetOutput(DataObjectPointerArraySizeType idx)
{
  if (this->GetNumberOfOutputs() < 1)
    throw ImageSeriesFileReaderException(__FILE__,
                                         __LINE__,
                                         "No data to output",
                                         ITK_LOCATION);

  if (idx >= m_OutputList->Size())
    throw ImageSeriesFileReaderException(__FILE__,
                                         __LINE__,
                                         "Index out of bounds",
                                         ITK_LOCATION);

  return static_cast<OutputImageType*>(this->m_OutputList->GetNthElement(idx));
}

template <class TImage, class TInternalImage>
void
ImageSeriesFileReaderBase<TImage, TInternalImage>
::ReadMetaFile()
{
  m_ListOfFileNames.clear();
  m_ListOfBandSelection.clear();
  m_ListOfRegionSelection.clear();

  this->TestFileExistenceAndReadability(m_FileName, kFileName);

  std::string aLine;
  std::ifstream inputFile(m_FileName.c_str(), std::ios_base::in);

  inputFile >> aLine;
  if (aLine != "ENVI")
    {
    inputFile.close();
    std::ostringstream msg;
    msg << "The file " << m_FileName << " is not a \"ENVI META FILE\" format\n";
    ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
    throw e;
    return;
    }

  inputFile >> aLine;
  if (aLine != "META")
    {
    inputFile.close();
    std::ostringstream msg;
    msg << "The file " << m_FileName << " is not a \"ENVI META FILE\" format\n";
    ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
    throw e;
    return;
    }

  inputFile >> aLine;
  if (aLine != "FILE")
    {
    inputFile.close();
    std::ostringstream msg;
    msg << "The file " << m_FileName << " is not a \"ENVI META FILE\" format\n";
    ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
    throw e;
    return;
    }

  while (1)
    {
    /*
     * Reading the filenames
     */
    do
      {
      inputFile >> aLine;
      //std::cerr << "-> '" << aLine << "'\n";
      }
    while (aLine != "File" && inputFile.good());

    if (inputFile.good())
      {
      do
        {
        inputFile >> aLine;
        //std::cerr << "--> '" << aLine << "'\n";
        }
      while (aLine != ":" && inputFile.good());

      if (!inputFile.good())
        {
        inputFile.close();
        std::ostringstream msg;
        msg << "Unable to read image files in the  \"ENVI META FILE\" file \n";
        msg << "FileName: " << m_FileName << "\n";
        ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
        throw e;
        return;
        }
      }
    else return;  // normal exit

    inputFile >> aLine;

    std::cerr << "-> " << aLine << "\n";

    // Get the Image fileName
    // The test may modify image file name to add the path
    // Or throw an exception when not found nor readable
    TestFileExistenceAndReadability(aLine, kImageFileName);
    m_ListOfFileNames.push_back(aLine);
    std::string imageFileName = aLine;

    /*
     * Reading the Band number
     */
    do
      {
      inputFile >> aLine;
      //std::cerr << "-> '" << aLine << "'\n";
      }
    while (aLine != "Bands:" && inputFile.good());

    if (!inputFile.good())
      {
      inputFile.close();
      std::ostringstream msg;
      msg << "Unable to read the number of bands in the images in the  \"ENVI META FILE\" file \n";
      msg << "FileName: " << m_FileName << "\n";
      ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
      throw e;
      return;
      }

    std::vector<unsigned int> bands;
    int                       aBand, oldBand = -1;
    char                      sep;
    while (1)
      {
      inputFile >> aBand;
      if (oldBand != -1)
        {
        for (int i = oldBand; i <= aBand; ++i)
          bands.push_back(i);
        oldBand = -1;
        }
      else bands.push_back(aBand);

      int posRef = inputFile.tellg();
      inputFile >> sep;
      if (sep == '-')
        {
        oldBand = aBand + 1;
        }
      else if (sep != ',')
        {
        inputFile.seekg(posRef, std::ios_base::beg);
        break;
        }
      }

    // Storing band selection
    try {
      TestBandSelection(bands);
      }
    catch (ImageSeriesFileReaderException & e)
      {
      std::ostringstream msg;
      msg << e.GetDescription();
      msg << "Image FileName             : " << imageFileName << "\n";
      e.SetDescription(msg.str().c_str());
      throw e;
      }
    m_ListOfBandSelection.push_back(bands);

    /*
     * Reading the Region selection
     */
    do
      {
      inputFile >> aLine;
      //std::cerr << "-> '" << aLine << "'\n";
      }
    while (aLine != "Dims" && inputFile.good());

    if (inputFile.good())
      {
      do
        {
        inputFile >> aLine;
        //std::cerr << "--> '" << aLine << "'\n";
        }
      while (aLine != ":" && inputFile.good());

      if (!inputFile.good())
        {
        inputFile.close();
        std::ostringstream msg;
        msg << "Unable to read image region in the  \"ENVI META FILE\" file \n";
        msg << "FileName : " << m_FileName << "\n";
        msg << "ImageName: " << imageFileName << "\n";
        ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
        throw e;
        return;
        }
      }

    int  beg_line, end_line, beg_col, end_col;
    char sep1, sep2, sep3;
    inputFile >> beg_col >> sep1 >> end_col >> sep2 >> beg_line >> sep3 >> end_line;

    if (!inputFile.good())
      {
      inputFile.close();
      std::ostringstream msg;
      msg << "Unable to read image region selection in the  \"ENVI META FILE\" file \n";
      msg << "FileName : " << m_FileName << "\n";
      msg << "ImageName: " << imageFileName << "\n";
      ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
      throw e;
      return;
      }

    IndexType index;
    index[0] = beg_col - 1;
    index[1] = beg_line - 1;

    SizeType size;
    size[0] = end_col - beg_col + 1;
    size[1] = end_line - beg_line + 1;

    RegionType region;
    region.SetSize(size);
    region.SetIndex(index);

    m_ListOfRegionSelection.push_back(region);
    }
}

template <class TImage, class TInternalImage>
void
ImageSeriesFileReaderBase<TImage, TInternalImage>
::AllocateListOfComponents()
{
  for (unsigned int i = 0; i < GetNumberOfOutputs(); ++i)
    {
    m_ImageFileReaderList->PushBack(ReaderType::New());
    m_OutputList->PushBack(OutputImageType::New());
    }
}

/**
 * GenerateData
 */
template <class TImage, class TInternalImage>
void
ImageSeriesFileReaderBase<TImage, TInternalImage>
::GenerateData(DataObjectPointerArraySizeType itkNotUsed(idx))
{
  std::ostringstream msg;
  msg << "Something wrong... Check the template definition of this class in the program...\n";
  msg << "\"ENVI META FILE\" FileName: " << m_FileName << "\n";
  ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
  throw e;
}

template <class TImage, class TInternalImage>
void
ImageSeriesFileReaderBase<TImage, TInternalImage>
::GenerateData()
{
  for (unsigned int i = 0; i < GetNumberOfOutputs(); ++i)
    GenerateData(i);
}

/**
 * GenerateOutput
 */
template <class TImage, class TInternalImage>
typename ImageSeriesFileReaderBase<TImage, TInternalImage>::OutputImageListType *
ImageSeriesFileReaderBase<TImage, TInternalImage>
::GenerateOutput()
{
  this->Update();
  return this->GetOutput();
}

template <class TImage, class TInternalImage>
typename ImageSeriesFileReaderBase<TImage, TInternalImage>::OutputImageType *
ImageSeriesFileReaderBase<TImage, TInternalImage>
::GenerateOutput(DataObjectPointerArraySizeType idx)
{
  this->GenerateData(idx);
  return this->GetOutput(idx);
}

template <class TImage, class TInternalImage>
void
ImageSeriesFileReaderBase<TImage, TInternalImage>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
  Superclass::PrintSelf(os, indent);
  os << indent << "File to be read : " << m_FileName << "\n";

  if (m_ListOfFileNames.size() > 0)
    {
    std::vector<std::vector<unsigned int> >::const_iterator bandSelection = m_ListOfBandSelection.begin();
    os << indent << "Image File(s) to be read\n";
    for (unsigned int i = 0; i < GetNumberOfOutputs(); ++i)
      {
      os << indent << "  " << "Filename       : " << m_ListOfFileNames[i] << "\n";
      os << indent << "  " << "RegionSelection: Index( "
         << m_ListOfRegionSelection[i].GetIndex()[0] << ", "
         << m_ListOfRegionSelection[i].GetIndex()[1] << ") Size( "
         << m_ListOfRegionSelection[i].GetSize()[0] << ", "
         << m_ListOfRegionSelection[i].GetSize()[1] << ")\n";
      os << indent << "  " << "BandSelection  : ";

      for (std::vector<unsigned int>::const_iterator bd = (*bandSelection).begin();
           bd != (*bandSelection).end();
           ++bd)
        {
        os << *bd << " ";
        }
      os << "\n";

      ++bandSelection;
      }
    }
}

template <class TImage, class TInternalImage>
void
ImageSeriesFileReaderBase<TImage, TInternalImage>
::TestFileExistenceAndReadability(std::string& file, FileType fileType)
{
  // Test if the file exists.
  if (!itksys::SystemTools::FileExists(file.c_str()))
    {
    if (fileType != kImageFileName)
      {
      ImageSeriesFileReaderException e(__FILE__, __LINE__);
      std::ostringstream msg;
      msg << "The file doesn't exist. \n";
      if (fileType == kFileName) msg << "Filename = " << file << "\n";
      else msg << "File = " << file << "\n";
      e.SetDescription(msg.str().c_str());
      throw e;
      return;
      }
    else
      {
      std::vector<std::string> fullPath;
      fullPath.push_back(itksys::SystemTools::GetFilenamePath(m_FileName));
      fullPath.push_back("/");
      fullPath.push_back(file);

      std::string fullFileName = itksys::SystemTools::JoinPath(fullPath);

      if (!itksys::SystemTools::FileExists(fullFileName.c_str()))
        {
        ImageSeriesFileReaderException e(__FILE__, __LINE__);
        std::ostringstream msg;
        msg << "The image file doesn't exist. \n";
        msg << "ImageFileName     = " << file << "\n";
        msg << "tested path       = " << itksys::SystemTools::GetFilenamePath(m_FileName) << "\n";
        msg << "Other Tested File = " << fullFileName << "\n";
        e.SetDescription(msg.str().c_str());
        throw e;
        return;
        }
      else
        {
        // At this step, image file name is modified to add its path
        file = fullFileName;
        }
      }
    }

  // Test if the file can be open for reading access.
  std::ifstream readTester;
  readTester.open(file.c_str());
  if (readTester.fail())
    {
    readTester.close();
    std::ostringstream msg;
    msg << "The file couldn't be opened for reading. "
        << std::endl << "Filename: " << file << std::endl;
    ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
    throw e;
    return;
    }
  readTester.close();
}

} // end of namespace otb

#endif