diff --git a/Code/BasicFilters/otbConcatenateVectorDataFilter.h b/Code/BasicFilters/otbConcatenateVectorDataFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..3f56dd7f23d9a091cce2e47e43ec8e5be993f33d --- /dev/null +++ b/Code/BasicFilters/otbConcatenateVectorDataFilter.h @@ -0,0 +1,102 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbConcatenateVectorDataFilter_h +#define __otbConcatenateVectorDataFilter_h + +#include "otbVectorDataToVectorDataFilter.h" +#include "otbVectorData.h" +#include "itkPreOrderTreeIterator.h" + +namespace otb +{ +/** \class ConcatenateVectorDataFilter + * \brief Produces a VectorData from the concatenation + * of several input vectordatas. + * + * This generator produces a unique vector by concatening several + * inputs set via the method AddInput(VectorData *) + * + * Note that the input vectordatas must have the same node type, + * this is due that vectordata creation does not support multiple geomtries + * in a single vectordata. + * + */ +template <class TVectorData> +class ITK_EXPORT ConcatenateVectorDataFilter : + public VectorDataSource<TVectorData> +{ +public: + /** Standard class typedefs */ + typedef ConcatenateVectorDataFilter Self; + typedef VectorDataSource<TVectorData > Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(ConcatenateVectorDataFilter, + VectorDataSource); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + typedef TVectorData VectorDataType; + typedef typename VectorDataType::Pointer VectorDataPointerType; + typedef typename VectorDataType::DataNodeType DataNodeType; + typedef typename DataNodeType::Pointer DataNodePointerType; + typedef typename DataNodeType::PolygonType::RegionType RegionType; + typedef typename DataNodeType::PointType PointType; + typedef typename DataNodeType::PolygonType::VertexType VertexType; + typedef typename DataNodeType::LineType LineType; + typedef typename VectorDataType::DataTreeType DataTreeType; + typedef typename DataTreeType::TreeNodeType TreeNodeType; + typedef typename TreeNodeType::ChildrenListType ChildrenListType; + + typedef typename std::vector<PointType> PointVectorType; + + /** Connects the VectorDatas from which the localizations are going to be extracted. */ + void AddInput(const VectorDataType *); + + const VectorDataType * GetInput(unsigned int idx) const; + +protected: + ConcatenateVectorDataFilter(); + virtual ~ConcatenateVectorDataFilter() {} + void PrintSelf(std::ostream& os, itk::Indent indent) const; + + /** Triggers the Computation of the sample list */ + void GenerateData(void); + + /** Recursive method to visit efficiently the vectordata*/ + void ProcessNode(TreeNodeType * source); + +private: + ConcatenateVectorDataFilter(const Self &); //purposely not implemented + void operator =(const Self&); //purposely not implemented + + DataNodePointerType m_Folder; + DataNodePointerType m_Document; + +}; + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbConcatenateVectorDataFilter.txx" +#endif + +#endif diff --git a/Code/BasicFilters/otbConcatenateVectorDataFilter.txx b/Code/BasicFilters/otbConcatenateVectorDataFilter.txx new file mode 100644 index 0000000000000000000000000000000000000000..86fd019bf64a514fc691ad1921b2b14f14b5a83c --- /dev/null +++ b/Code/BasicFilters/otbConcatenateVectorDataFilter.txx @@ -0,0 +1,181 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbConcatenateVectorDataFilter_txx +#define __otbConcatenateVectorDataFilter_txx + +#include "otbConcatenateVectorDataFilter.h" + +#include "otbMath.h" + +namespace otb +{ +template<class TVectorData> +ConcatenateVectorDataFilter<TVectorData> +::ConcatenateVectorDataFilter() +{ + this->SetNumberOfRequiredInputs(1); + this->SetNumberOfRequiredOutputs(1); + + m_Folder = DataNodeType::New() ; + m_Folder->SetNodeType(otb::FOLDER); + + m_Document = DataNodeType::New() ; + m_Document->SetNodeType(otb::DOCUMENT); + +} + +template <class TVectorData> +void +ConcatenateVectorDataFilter<TVectorData> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + this->Superclass::PrintSelf(os, indent); +} + +template <class TVectorData> +void +ConcatenateVectorDataFilter<TVectorData> +::AddInput(const VectorDataType * vectorData) +{ + this->Superclass::SetNthInput(this->GetNumberOfInputs(), + const_cast<VectorDataType *>(vectorData)); +} + +template <class TVectorData> +const TVectorData * +ConcatenateVectorDataFilter<TVectorData> +::GetInput(unsigned int idx) const +{ + if (this->GetNumberOfInputs() < idx) + { + return 0; + } + return static_cast<const VectorDataType *>(this->Superclass::GetInput(idx)); +} + +template <class TVectorData> +void +ConcatenateVectorDataFilter<TVectorData> +::GenerateData() +{ + // TODO : no checking is done on the inputs, do checking to avoid + // TODO : Check if they are in the same coordinate system (tricky) + + // Start recursive processing + + // Copy the input MetaDataDictionary in the output VectorData + //this->GetOutput()->SetMetaDataDictionary(this->GetInput(0)->GetMetaDataDictionary()); + + // Prepare the output + typename DataNodeType::Pointer outputRoot = this->GetOutput()->GetDataTree()->GetRoot()->Get(); + + // Adding the layer to the data tree + this->GetOutput()->GetDataTree()->Add(m_Folder, outputRoot); + this->GetOutput()->GetDataTree()->Add(m_Document , m_Folder); + + // Retrieve all the inputs + for(unsigned int idx = 0; idx < this->GetNumberOfInputs(); idx++) + { + // Add the current vectordata + TreeNodeType * + inputRoot = const_cast<TreeNodeType *>(this->GetInput(idx)->GetDataTree()->GetRoot()); + // + ProcessNode(inputRoot); + } + +} + + +template <class TVectorData> +void +ConcatenateVectorDataFilter<TVectorData> +::ProcessNode(TreeNodeType * source) +{ + if (source == 0) + return; + + // Get the children list from the input node + ChildrenListType children = source->GetChildrenList(); + + // For each child + typename ChildrenListType::iterator it; + for (it = children.begin(); it != children.end(); ++it) + { + // get the data node + DataNodePointerType dataNode = (*it)->Get(); + + switch (dataNode->GetNodeType()) + { + case ROOT: + { + ProcessNode((*it)); + break; + } + case DOCUMENT: + { + ProcessNode((*it)); + break; + } + case FOLDER: + { + ProcessNode((*it)); + break; + } + case FEATURE_POINT: + { + this->GetOutput()->GetDataTree()->Add(dataNode, m_Document); + break; + } + case FEATURE_LINE: + { + this->GetOutput()->GetDataTree()->Add(dataNode, m_Document); + break; + } + case FEATURE_POLYGON: + { + this->GetOutput()->GetDataTree()->Add(dataNode, m_Document); + break; + } + case FEATURE_MULTIPOINT: + { + ProcessNode((*it)); + break; + } + case FEATURE_MULTILINE: + { + ProcessNode((*it)); + break; + } + case FEATURE_MULTIPOLYGON: + { + ProcessNode((*it)); + break; + } + case FEATURE_COLLECTION: + { + ProcessNode((*it)); + break; + } + } + } +} + + +} // end namespace otb + +#endif