File: otbOrthoRectificationFilter.cxx

package info (click to toggle)
otb 6.6.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 47,068 kB
  • sloc: cpp: 316,755; ansic: 4,474; sh: 1,610; python: 497; perl: 92; makefile: 82; java: 72
file content (147 lines) | stat: -rw-r--r-- 5,533 bytes parent folder | download
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
/*
 * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
 *
 * 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.
 */



// iostream is used for general output
#include <iostream>
#include <stdlib.h>
#include <complex>

#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "otbMapProjections.h"
#include "itkUnaryFunctorImageFilter.h"
//#include "itkComplexToModulusImageFilter.h"
#include "otbDEMHandler.h"
#include "otbUnaryImageFunctorWithVectorImageFilter.h"
#include "otbOrthoRectificationFilter.h"
#include "otbMapProjections.h"
#include "otbComplexToIntensityImageFilter.h"
#include "otbPerBandVectorImageFilter.h"

int otbOrthoRectificationFilter(int argc, char* argv[])
{
  if (argc != 15)
    {
    std::cout << argv[0] <<
    " <input filename> <output filename> <origin easting> <origin northing>"
    " <x size> <y size> <x spacing> <y spacing> <UTM zone> <UTM hemisphere>"
    " <grid_spacing> <mode> <mode.info> <is_complex>"
              << std::endl;

    return EXIT_FAILURE;
    }

  typedef std::complex<double>                                                      ComplexPixelType;
  typedef otb::VectorImage<ComplexPixelType,2>                                     ComplexVectorImageType;
  typedef otb::VectorImage<double, 2>                                               VectorImageType;
  typedef otb::ImageFileReader<VectorImageType>                                     ReaderType;
  typedef otb::ImageFileReader<ComplexVectorImageType>                              ComplexReaderType;
  typedef otb::ImageFileWriter<VectorImageType>                                     WriterType;
  typedef otb::UtmInverseProjection                                                 UtmMapProjectionType;

  // Handling of complex images
  typedef otb::Image<ComplexPixelType> ComplexImageType;
  typedef otb::Image<double>           ImageType;
  typedef otb::ComplexToIntensityImageFilter<ComplexImageType, ImageType> IntensityFilterType;
  typedef otb::PerBandVectorImageFilter<ComplexVectorImageType,VectorImageType,IntensityFilterType> PerBandIntensityFilterType;
  
  typedef otb::OrthoRectificationFilter<VectorImageType, VectorImageType, UtmMapProjectionType> OrthoRectifFilterType;

  //Allocate pointer
  ReaderType::Pointer reader = ReaderType::New();
  ComplexReaderType::Pointer cReader = ComplexReaderType::New();
  WriterType::Pointer writer = WriterType::New();
  PerBandIntensityFilterType::Pointer intensityFilter = PerBandIntensityFilterType::New();
  
  OrthoRectifFilterType::Pointer orthoRectifFilter = OrthoRectifFilterType::New();
  UtmMapProjectionType::Pointer  utmMapProjection = UtmMapProjectionType::New();

  writer->SetFileName(argv[2]);
  
  bool isComplex = atoi(argv[14]);

  if(isComplex)
    {
      cReader->SetFileName(argv[1]);
      cReader->GenerateOutputInformation();
      intensityFilter->SetInput(cReader->GetOutput());
      VectorImageType::PixelType no_data(cReader->GetOutput()->GetNumberOfComponentsPerPixel());
      no_data.Fill(0);
      orthoRectifFilter->SetEdgePaddingValue(no_data);
      orthoRectifFilter->SetInput(intensityFilter->GetOutput());
    }
  else
    {
      reader->SetFileName(argv[1]);
      reader->GenerateOutputInformation();
      VectorImageType::PixelType no_data(reader->GetOutput()->GetNumberOfComponentsPerPixel());
      no_data.Fill(0);
      orthoRectifFilter->SetEdgePaddingValue(no_data);
      orthoRectifFilter->SetInput(reader->GetOutput());
    }

  VectorImageType::IndexType start;
  start[0] = 0;
  start[1] = 0;
  orthoRectifFilter->SetOutputStartIndex(start);

  VectorImageType::SizeType size;
  size[0] = atoi(argv[5]);      // X size
  size[1] = atoi(argv[6]);            //Y size
  orthoRectifFilter->SetOutputSize(size);

  VectorImageType::SpacingType spacing;
  spacing[0] = atof(argv[7]);
  spacing[1] = atof(argv[8]);
  orthoRectifFilter->SetOutputSpacing(spacing);

  VectorImageType::PointType origin;
  origin[0] = strtod(argv[3], ITK_NULLPTR);         //Origin easting
  origin[1] = strtod(argv[4], ITK_NULLPTR);         //Origin northing
  orthoRectifFilter->SetOutputOrigin(origin);

  utmMapProjection->SetZone(atoi(argv[9]));
  utmMapProjection->SetHemisphere(argv[10][0]);
  orthoRectifFilter->SetMapProjection(utmMapProjection);

  // Displacement Field spacing
  VectorImageType::SpacingType  gridSpacing;
  gridSpacing[0] = atof(argv[11]);
  gridSpacing[1] = -atof(argv[11]);
  orthoRectifFilter->SetDisplacementFieldSpacing(gridSpacing);
  
  // manage demHandler
  if (atoi(argv[12])==1) //mode = no DEM
  {
	  otb::DEMHandler::Instance()->SetDefaultHeightAboveEllipsoid(135.8);
  }
  else if ( (atoi(argv[12])==2) || (atoi(argv[12])==3) ) //mode = DEM SRTM || DEM GTIFF
  {
	  otb::DEMHandler::Instance()->OpenDEMDirectory(argv[13]);
  }

  writer->SetInput(orthoRectifFilter->GetOutput());
  writer->SetNumberOfDivisionsTiledStreaming(4);
  writer->Update();

  return EXIT_SUCCESS;
}