diff --git a/Code/Visualization/otbVectorDataModel.h b/Code/Visualization/otbVectorDataModel.h index b8bd72b75324de11fd4a71c45464ef566e21dfb6..45291ca2b0eaf1d93e1bf0baeac71907348f1c2b 100644 --- a/Code/Visualization/otbVectorDataModel.h +++ b/Code/Visualization/otbVectorDataModel.h @@ -76,10 +76,6 @@ public: void AddVectorData( VectorDataPointer vData ); void AddNode( TreeNodeType * node ); - /** Load a vector data using image reprojection. */ - template <typename TImage> void AddVectorData( VectorDataPointer vData, TImage * image ); - template <typename TImage> void AddNode( TreeNodeType * node, TImage * image ); - void AddPointToGeometry(VertexType& vertex, bool callUpdate = true); void EndGeometry(void); void DeleteGeometry(void); @@ -127,8 +123,4 @@ private: }; // end class } // end namespace otb -#ifndef OTB_MANUAL_INSTANTIATION -#include "otbVectorDataModel.txx" -#endif - #endif diff --git a/Code/Visualization/otbVectorDataModel.txx b/Code/Visualization/otbVectorDataModel.txx deleted file mode 100644 index 341f639e6ca5333cc4e7a26330e8c51769494c82..0000000000000000000000000000000000000000 --- a/Code/Visualization/otbVectorDataModel.txx +++ /dev/null @@ -1,127 +0,0 @@ -/*========================================================================= - - 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 __otbVectorDataModel_txx -#define __otbVectorDataModel_txx - -#include "otbVectorDataModel.h" - - -namespace otb -{ - - - - -template <typename TImage> -void -VectorDataModel::AddVectorData( VectorDataPointer vData, TImage * image ) -{ - this->EndGeometry(); - DataTreeType::Pointer tree = vData->GetDataTree(); - TreeNodeType * root = const_cast<TreeNodeType *>(tree->GetRoot()); - this->AddNode( root, image ); - this->Update(); -} - - -template <typename TImage> -void -VectorDataModel::AddNode( TreeNodeType * node, TImage * image ) -{ - // From VEctorDataGlComponent - // Render the current node - switch (node->Get()->GetNodeType()) - { - case FEATURE_POINT: - { - m_CurrentNodeType = FEATURE_POINT; - typename TImage::IndexType id; - const PointType point = node->Get()->GetPoint(); - image->TransformPhysicalPointToIndex(point, id); - - VertexType vertex; - vertex[0] = id[0]; - vertex[1] = id[1]; - this->AddPointToGeometry(vertex, false); - - this->EndGeometry(); - break; - } - case FEATURE_LINE: - { - m_CurrentNodeType = FEATURE_LINE; - const LineType * line = node->Get()->GetLine(); - LineType::VertexListType::ConstIterator vIt = line->GetVertexList()->Begin(); - - while (vIt != line->GetVertexList()->End()) - { - typename TImage::IndexType id; - const PointType point = vIt.Value(); - image->TransformPhysicalPointToIndex(point, id); - - VertexType vertex; - vertex[0] = id[0]; - vertex[1] = id[1]; - this->AddPointToGeometry(vertex, false ); - } - this->EndGeometry(); - break; - } - case FEATURE_POLYGON: - { - m_CurrentNodeType = FEATURE_POLYGON; - const PolygonType * extRing = node->Get()->GetPolygonExteriorRing(); - PolygonType::VertexListType::ConstIterator vIt = extRing->GetVertexList()->Begin(); - - while (vIt != extRing->GetVertexList()->End()) - { - typename TImage::IndexType id; - const PointType point = vIt.Value(); - image->TransformPhysicalPointToIndex(point, id); - - VertexType vertex; - vertex[0] = id[0]; - vertex[1] = id[1]; - this->AddPointToGeometry(vertex, false); - vIt++; - } - this->EndGeometry(); - break; - } - default: - { - // discard - break; - } - } - - // Get the children list from the input node - ChildrenListType children = node->GetChildrenList(); - - // Render each child - ChildrenListType::iterator it = children.begin(); - while ( it != children.end() ) - { - this->AddNode(*it, image); - ++it; - } -} - -} - -#endif diff --git a/Testing/Code/Visualization/otbVectorDataModelAddVectorDataTest.cxx b/Testing/Code/Visualization/otbVectorDataModelAddVectorDataTest.cxx index 858ce96ffd1d8ddffd2a1821e4c6602934250dac..ca5835d687200c3eef8977d6e585e8fbff8c6141 100644 --- a/Testing/Code/Visualization/otbVectorDataModelAddVectorDataTest.cxx +++ b/Testing/Code/Visualization/otbVectorDataModelAddVectorDataTest.cxx @@ -41,6 +41,8 @@ #include "otbVectorDataModel.h" #include "otbVectorDataActionHandler.h" #include "otbVectorDataFileReader.h" +#include "otbVectorDataProjectionFilter.h" + int otbVectorDataModelAddVectorDataTest(int argc, char * argv[]) { @@ -210,7 +212,26 @@ int otbVectorDataModelAddVectorDataTest(int argc, char * argv[]) VectorDataReaderType::Pointer vdReader = VectorDataReaderType::New(); vdReader->SetFileName(vdataName); vdReader->Update(); - vdModel->AddVectorData(vdReader->GetOutput(), reader->GetOutput()); + typedef otb::VectorDataProjectionFilter<VectorDataType,VectorDataType> ProjectionFilterType; + ProjectionFilterType::Pointer vectorDataProjection = ProjectionFilterType::New(); + vectorDataProjection->SetInput(vdReader->GetOutput()); + + ImageType::PointType lNewOrigin; + // polygons are recorded with a 0.5 shift... + lNewOrigin[0] = reader->GetOutput()->GetOrigin()[0]+0.5; + lNewOrigin[1] = reader->GetOutput()->GetOrigin()[1]+0.5; + + vectorDataProjection->SetOutputOrigin(lNewOrigin); + vectorDataProjection->SetOutputSpacing(reader->GetOutput()->GetSpacing()); + + std::string projectionRef; + itk::ExposeMetaData<std::string>(reader->GetOutput()->GetMetaDataDictionary(), + otb::MetaDataKey::ProjectionRefKey, projectionRef ); + vectorDataProjection->SetOutputProjectionRef(projectionRef); + vectorDataProjection->SetOutputKeywordList(reader->GetOutput()->GetImageKeywordlist()); + vectorDataProjection->Update(); + + vdModel->AddVectorData(vectorDataProjection->GetOutput()); if (run) {