otbIce.cxx 2.49 KB
Newer Older
1
/*
2
 * Copyright (C) 2005-2020 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.
 */
Julien Michel's avatar
Julien Michel committed
20 21 22 23 24

#include "otbIceViewer.h"
#include "otbDEMHandler.h"


25
void error_callback(int, const char* description)
Julien Michel's avatar
Julien Michel committed
26
{
27
  std::cerr << description << std::endl;
Julien Michel's avatar
Julien Michel committed
28 29
}

30
int main(int argc, char* argv[])
Julien Michel's avatar
Julien Michel committed
31
{
32 33 34 35
  if (argc < 2)
  {
    std::cerr << "Usage: " << argv[0] << " img1 ... imgN" << std::endl << std::endl;

Julien Michel's avatar
Julien Michel committed
36
    return EXIT_FAILURE;
37
  }
Julien Michel's avatar
Julien Michel committed
38

39 40
  char* demdir    = getenv("OTB_DEM_DIR");
  char* geoidfile = getenv("OTB_GEOID_FILE");
Julien Michel's avatar
Julien Michel committed
41

42
  otb::DEMHandler::Pointer demHandler = otb::DEMHandler::Instance();
43 44 45 46

  if (demdir != nullptr)
  {
    std::cout << "Configuring DEM directory: " << demdir << std::endl;
Julien Michel's avatar
Julien Michel committed
47
    demHandler->OpenDEMDirectory(demdir);
48
  }
Julien Michel's avatar
Julien Michel committed
49

50 51 52
  if (geoidfile != nullptr)
  {
    std::cout << "Configuring geoid file: " << geoidfile << std::endl;
Julien Michel's avatar
Julien Michel committed
53
    demHandler->OpenGeoidFile(geoidfile);
54
  }
Julien Michel's avatar
Julien Michel committed
55

56
  otb::IceViewer::Pointer viewer = otb::IceViewer::New();
Julien Michel's avatar
Julien Michel committed
57 58

  // Initialize viewer
59
  try
60 61 62 63 64 65
  {
    viewer->Initialize(800, 600);
  }
  catch (itk::ExceptionObject& err)
  {
    std::cerr << "Failed to initialized viewer: " << err << std::endl;
66
    return EXIT_FAILURE;
67
  }
Julien Michel's avatar
Julien Michel committed
68

69 70
  for (int i = 1; i < argc; ++i)
  {
71
    try
72 73 74 75 76 77 78
    {
      viewer->AddImage(argv[i], argv[i]);
    }
    catch (itk::ExceptionObject& err)
    {
      std::cerr << "Failed to open object as image: " << err << std::endl;
      try
79
      {
80
        viewer->AddVector(argv[i], argv[i]);
81
      }
82
      catch (itk::ExceptionObject& err2)
83
      {
84 85
        std::cerr << "Failed to open object as vector: " << err2 << std::endl;
        std::cerr << "Could not open file " << argv[i] << " as an image or a vector, skipping." << std::endl;
86
      }
87 88 89 90
    }
    catch (std::runtime_error& err)
    {
      std::cerr << "Runtime error: " << err.what() << std::endl;
91
      return EXIT_FAILURE;
Julien Michel's avatar
Julien Michel committed
92
    }
93
  }
Julien Michel's avatar
Julien Michel committed
94

95
  std::cout << "Press F1 for help" << std::endl;
Julien Michel's avatar
Julien Michel committed
96

Julien Michel's avatar
Julien Michel committed
97
  viewer->Start();
98 99


Julien Michel's avatar
Julien Michel committed
100 101
  return EXIT_SUCCESS;
}