/* * Copyright (C) 2005-2019 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 otbImageSeriesFileReader_hxx #define otbImageSeriesFileReader_hxx #include "otbImageSeriesFileReader.h" namespace otb { template ImageSeriesFileReader::ImageSeriesFileReader() { m_ExtractorList = ExtractSelectionListType::New(); } template void ImageSeriesFileReader::AllocateListOfComponents() { for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i) { this->m_ImageFileReaderList->PushBack(ReaderType::New()); this->m_OutputList->PushBack(OutputImageType::New()); m_ExtractorList->PushBack(ExtractSelectionListType::New()); } } template void ImageSeriesFileReader::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: " << this->m_FileName << "\n"; ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION); throw e; } /* ********************************************************** * Methods that are specific to instantiation with Image type * ********************************************************** */ template ImageSeriesFileReader, Image>::ImageSeriesFileReader() { m_ExtractorList = ExtractSelectionListType::New(); } /** * Allocation of the component... Here, based on ExtractROI */ template void ImageSeriesFileReader, Image>::AllocateListOfComponents() { for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i) { this->m_ImageFileReaderList->PushBack(ReaderType::New()); this->m_OutputList->PushBack(OutputImageType::New()); m_ExtractorList->PushBack(ExtractSelectionType::New()); } } /** * TestBandSelection tests if the templated Image type is compatible * with the bande selection provided in the Meta File */ template void ImageSeriesFileReader, Image>::TestBandSelection(std::vector& bands) { if (bands.size() != 1) { std::ostringstream msg; msg << "Unable to handle multicomponent file from Image<> class\n"; msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n"; ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION); throw e; } if (bands[0] != 1) { std::ostringstream msg; msg << "Unable to handle given band reading from multicomponent file with Image<> class\n"; msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n"; ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION); throw e; } return; } /** * GenerateData for Image type */ template void ImageSeriesFileReader, Image>::GenerateData(DataObjectPointerArraySizeType idx) { otbMsgDebugMacro(<< "Reading " << idx << "th image: " << this->m_ListOfFileNames[idx]); ReaderType* reader = static_cast(this->m_ImageFileReaderList->GetNthElement(idx)); reader->SetFileName(this->m_ListOfFileNames[idx]); ExtractSelectionType* selection = static_cast(m_ExtractorList->GetNthElement(idx)); selection->SetExtractionRegion(this->m_ListOfRegionSelection[idx]); selection->SetInput(reader->GetOutput()); selection->GraftOutput(this->m_OutputList->GetNthElement(idx)); selection->Update(); this->m_OutputList->GetNthElement(idx)->Graft(selection->GetOutput()); } /* ********************************************************************* * Methods that are specific to instantiation with Image type for TImage * and VectorImage as TInternalImage * ********************************************************************* */ /** * Constructor */ template ImageSeriesFileReader, VectorImage>::ImageSeriesFileReader() { // this->m_OutputList = OutputImageListType::New(); // this->m_ImageFileReaderList = ReaderListType::New(); m_ExtractorList = ExtractSelectionListType::New(); } /** * Allocation of the component... Here, based on MultiToMonoChannelExtractROI */ template void ImageSeriesFileReader, VectorImage>::AllocateListOfComponents() { for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i) { this->m_ImageFileReaderList->PushBack(ReaderType::New()); this->m_OutputList->PushBack(OutputImageType::New()); m_ExtractorList->PushBack(ExtractSelectionType::New()); } } /** * TestBandSelection tests if the templated Image type is compatible * with the bande selection provided in the Meta File */ template void ImageSeriesFileReader, VectorImage>::TestBandSelection(std::vector& bands) { if (bands.size() != 1) { std::ostringstream msg; msg << "Unable to handle multicomponent file from Image<> class as output\n"; msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n"; ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION); throw e; } return; } /** * GenerateData for Image type as output and VectorImage type for reading */ template void ImageSeriesFileReader, VectorImage>::GenerateData(DataObjectPointerArraySizeType idx) { otbMsgDebugMacro(<< "Reading " << idx << "th image: " << this->m_ListOfFileNames[idx]); ReaderType* reader = static_cast(this->m_ImageFileReaderList->GetNthElement(idx)); reader->SetFileName(this->m_ListOfFileNames[idx]); ExtractSelectionType* selection = static_cast(this->m_ExtractorList->GetNthElement(idx)); selection->SetExtractionRegion(this->m_ListOfRegionSelection[idx]); selection->SetChannel(this->m_ListOfBandSelection[idx][0]); selection->SetInput(reader->GetOutput()); selection->GraftOutput(this->m_OutputList->GetNthElement(idx)); selection->Update(); this->m_OutputList->GetNthElement(idx)->Graft(selection->GetOutput()); } /* ****************************************************************** * Methods that are specific to instantiation with VectorImage types * ****************************************************************** */ /** * Constructor */ template ImageSeriesFileReader, VectorImage>::ImageSeriesFileReader() { // this->m_OutputList = OutputImageListType::New(); // this->m_ImageFileReaderList = ReaderListType::New(); m_ExtractorList = ExtractSelectionListType::New(); } /** * Allocation of the component... Here, based on MultiChannelExtractROI */ template void ImageSeriesFileReader, VectorImage>::AllocateListOfComponents() { for (unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i) { this->m_ImageFileReaderList->PushBack(ReaderType::New()); this->m_OutputList->PushBack(OutputImageType::New()); m_ExtractorList->PushBack(ExtractSelectionType::New()); } } /** * GenerateData specialised for VectorImages */ template void ImageSeriesFileReader, VectorImage>::GenerateData(DataObjectPointerArraySizeType idx) { otbMsgDebugMacro(<< "Reading " << idx << "th image: " << this->m_ListOfFileNames[idx]); ReaderType* reader = static_cast(this->m_ImageFileReaderList->GetNthElement(idx)); reader->SetFileName(this->m_ListOfFileNames[idx]); ExtractSelectionType* selection = static_cast(this->m_ExtractorList->GetNthElement(idx)); selection->SetExtractionRegion(this->m_ListOfRegionSelection[idx]); for (std::vector::iterator band = this->m_ListOfBandSelection[idx].begin(); band != this->m_ListOfBandSelection[idx].end(); ++band) { selection->SetChannel(*band); } selection->SetInput(reader->GetOutput()); selection->GraftOutput(this->m_OutputList->GetNthElement(idx)); selection->Update(); this->m_OutputList->GetNthElement(idx)->Graft(selection->GetOutput()); } } // end of namespace otb #endif