otbExtractROITestMetaData.cxx 4.48 KB
Newer Older
1
/*
Julien Michel's avatar
Julien Michel committed
2
 * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * 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.
 */
20 21 22 23 24 25 26 27 28 29 30 31 32

#include <iostream>
#include <fstream>

#include "itkExtractImageFilter.h"
#include "itkVectorIndexSelectionCastImageFilter.h"
#include "otbExtractROI.h"
#include "otbMultiChannelExtractROI.h"
#include "otbMultiToMonoChannelExtractROI.h"

#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"

33
int otbExtractROITestMetaData(int itkNotUsed(argc), char* argv[])
34 35 36
{
  typedef float PixelType;

37
  typedef otb::Image<PixelType> ImageType;
38

39 40
  typedef otb::ImageFileReader<ImageType> ImageFileReaderType;
  typedef otb::ImageFileWriter<ImageType> ImageFileWriterType;
41

42
  typedef otb::ExtractROI<PixelType, PixelType> ExtractROIType;
43 44

  ImageFileReaderType::Pointer readerInput = ImageFileReaderType::New();
45 46 47 48
  ImageFileReaderType::Pointer reader00    = ImageFileReaderType::New();
  ImageFileReaderType::Pointer reader57    = ImageFileReaderType::New();
  ImageFileWriterType::Pointer writer00    = ImageFileWriterType::New();
  ImageFileWriterType::Pointer writer57    = ImageFileWriterType::New();
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

  ExtractROIType::Pointer extract00 = ExtractROIType::New();
  ExtractROIType::Pointer extract57 = ExtractROIType::New();

  // Read input file
  readerInput->SetFileName(argv[1]);
  readerInput->GenerateOutputInformation();

  // Extract left up image
  extract00->SetInput(readerInput->GetOutput());
  extract00->SetSizeX(50);
  extract00->SetSizeY(25);
  extract00->SetStartX(0);
  extract00->SetStartY(0);
  extract00->UpdateOutputInformation();

  // Save left up image information
  std::ofstream file00;
  file00.open(argv[4]);
  file00 << static_cast<ImageType::Pointer>(extract00->GetOutput()) << std::endl;
  file00.close();

  // Extract image with non-zero index
  extract57->SetInput(readerInput->GetOutput());
  extract57->SetSizeX(50);
  extract57->SetSizeY(25);
  extract57->SetStartX(5);
  extract57->SetStartY(7);
  extract57->UpdateOutputInformation();

  // Save extract image information
  std::ofstream file57;
  file57.open(argv[5]);
  file57 << static_cast<ImageType::Pointer>(extract57->GetOutput()) << std::endl;
  file57.close();

  // Write left up image
  writer00->SetFileName(argv[2]);
  writer00->SetInput(extract00->GetOutput());
88
  // writer00->SetWriteGeomFile(true);
89 90 91 92 93
  writer00->Update();

  // Write image with non zero index
  writer57->SetFileName(argv[3]);
  writer57->SetInput(extract57->GetOutput());
94
  // writer57->SetWriteGeomFile(true);
95 96 97 98 99 100
  writer57->Update();

  // Reading image with left up index
  reader00->SetFileName(argv[2]);
  reader00->GenerateOutputInformation();

Guillaume Pasero's avatar
Guillaume Pasero committed
101 102 103 104 105
  // The input image should have a sensor model and GCP, but the output images
  // should only have the sensor model (priority over GCP). This behaviour
  // must be consistent regardless of the ROI.

  if (reader00->GetOutput()->GetProjectionRef().size())
106 107 108
  {
    std::cout << "The read generated extract from index (0, 0) must NOT contain a ProjectionReference." << std::endl;
    std::cout << "Found ProjectionReference: " << reader00->GetOutput()->GetProjectionRef() << std::endl;
Cyrille Valladeau's avatar
Cyrille Valladeau committed
109
    return EXIT_FAILURE;
110
  }
Cyrille Valladeau's avatar
Cyrille Valladeau committed
111

Guillaume Pasero's avatar
Guillaume Pasero committed
112
  if (reader00->GetOutput()->GetGCPCount())
113
  {
Guillaume Pasero's avatar
Guillaume Pasero committed
114
    std::cout << "The read generated extract from index (0, 0) must NOT contain a list a GCPs.." << std::endl;
Cyrille Valladeau's avatar
Cyrille Valladeau committed
115
    return EXIT_FAILURE;
116
  }
117 118 119 120 121

  // Reading image with non-zero index
  reader57->SetFileName(argv[3]);
  reader57->GenerateOutputInformation();

Guillaume Pasero's avatar
Guillaume Pasero committed
122
  if (reader57->GetOutput()->GetProjectionRef().size())
123 124 125
  {
    std::cout << "The read generated extract from index (x, y) must NOT contain a ProjectionReference." << std::endl;
    std::cout << "Found ProjectionReference: " << reader57->GetOutput()->GetProjectionRef() << std::endl;
Cyrille Valladeau's avatar
Cyrille Valladeau committed
126
    return EXIT_FAILURE;
127
  }
128

Guillaume Pasero's avatar
Guillaume Pasero committed
129
  if (reader57->GetOutput()->GetGCPCount())
130 131
  {
    std::cout << "The read generated extract from index (x, y) must NOT contain a list a GCPs.." << std::endl;
Cyrille Valladeau's avatar
Cyrille Valladeau committed
132
    return EXIT_FAILURE;
133
  }
Cyrille Valladeau's avatar
Cyrille Valladeau committed
134

135 136 137

  return EXIT_SUCCESS;
}