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
|
/*
* 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.
*/
#include "otbSpectralAngleDataNodeFeatureFunction.h"
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#include "otbVectorData.h"
#include "otbVectorDataFileReader.h"
#include "otbVectorDataIntoImageProjectionFilter.h"
#include "otbVectorDataFileWriter.h"
#include "itkPreOrderTreeIterator.h"
int otbSpectralAngleDataNodeFeatureFunctionNew(int itkNotUsed(argc), char* itkNotUsed(argv) [])
{
typedef double CoordRepType;
typedef double PrecisionType;
typedef otb::VectorImage<double, 2> ImageType;
typedef otb::SpectralAngleDataNodeFeatureFunction<ImageType, CoordRepType, PrecisionType>
DataNodeFeaturefunctionType;
DataNodeFeaturefunctionType::Pointer featureFunction = DataNodeFeaturefunctionType::New();
std::cout << featureFunction << std::endl;
return EXIT_SUCCESS;
}
int otbSpectralAngleDataNodeFeatureFunction(int itkNotUsed(argc), char* argv[])
{
const char * inputVD = argv[1];
const char * inputImg = argv[2];
const char * DEMDir = argv[3];
const char * outputVD = argv[4];
int DisplayWarnings = atoi(argv[5]);
typedef double CoordRepType;
typedef double PrecisionType;
typedef otb::VectorImage<PrecisionType> ImageType;
typedef otb::ImageFileReader<ImageType> ImageReaderType;
typedef otb::VectorData<CoordRepType, 2, PrecisionType>
VectorDataType;
typedef VectorDataType::DataNodeType DataNodeType;
typedef otb::VectorDataFileReader<VectorDataType> VectorDataReaderType;
typedef otb::VectorDataIntoImageProjectionFilter<VectorDataType, ImageType>
VectorDataReProjFilter;
typedef otb::VectorDataFileWriter<VectorDataType> VectorDataWriterType;
typedef itk::PreOrderTreeIterator<VectorDataType::DataTreeType>
TreeIteratorType;
typedef otb::SpectralAngleDataNodeFeatureFunction<ImageType, CoordRepType, PrecisionType>
FeaturefunctionType;
typedef FeaturefunctionType::OutputType
FeatureOutputType;
ImageReaderType::Pointer imgReader = ImageReaderType::New();
VectorDataReaderType::Pointer vdReader = VectorDataReaderType::New();
VectorDataReProjFilter::Pointer vdReProjFilter = VectorDataReProjFilter::New();
VectorDataWriterType::Pointer vdWriter = VectorDataWriterType::New();
FeaturefunctionType::Pointer featureFunction = FeaturefunctionType::New();
if (!DisplayWarnings)
{
imgReader->SetGlobalWarningDisplay(0);
}
otb::DEMHandler::Instance()->OpenDEMDirectory(DEMDir);
vdReader->SetFileName(inputVD);
vdReader->Update();
imgReader->SetFileName(inputImg);
imgReader->UpdateOutputInformation();
imgReader->Update(); //Needed to set m_EndIndex, m_StartIndex in otbDataNodeImageFunction
vdReProjFilter->SetInputImage(imgReader->GetOutput());
vdReProjFilter->SetInputVectorData(vdReader->GetOutput());
vdReProjFilter->SetUseOutputSpacingAndOriginFromImage(true);
vdReProjFilter->Update();
std::cout<< "vdReProjFilter->GetOutput()->Size(): "
<< vdReProjFilter->GetOutput()->Size() << std::endl;
featureFunction->SetInputImage(imgReader->GetOutput());
featureFunction->SetRadius(0);
// Output
VectorDataType::Pointer outVD = VectorDataType::New();
// Retrieving root node
DataNodeType::Pointer root = outVD->GetDataTree()->GetRoot()->Get();
// Create the document node
DataNodeType::Pointer document = DataNodeType::New();
document->SetNodeType(otb::DOCUMENT);
// Adding the layer to the data tree
outVD->GetDataTree()->Add(document, root);
// Create the folder node
DataNodeType::Pointer folder = DataNodeType::New();
folder->SetNodeType(otb::FOLDER);
// Adding the layer to the data tree
outVD->GetDataTree()->Add(folder, document);
TreeIteratorType itVector(vdReProjFilter->GetOutput()->GetDataTree());
itVector.GoToBegin();
while (!itVector.IsAtEnd())
{
if (itVector.Get()->IsLineFeature() || itVector.Get()->IsPolygonFeature())
{
const DataNodeType::Pointer currentGeometry = itVector.Get();
FeatureOutputType currentResult;
currentResult = featureFunction->Evaluate(*(currentGeometry.GetPointer()));
currentGeometry->SetFieldAsDouble("RADIOM", (double)(currentResult[0]));
outVD->GetDataTree()->Add(currentGeometry, folder);
}
++itVector;
}
vdWriter->SetInput(outVD);
vdWriter->SetFileName(outputVD);
vdWriter->Update();
return EXIT_SUCCESS;
}
|