Skip to content
Snippets Groups Projects
Commit 07a2d8a4 authored by Jordi Inglada's avatar Jordi Inglada
Browse files

Example VectorDataIO

parent 8ff15ae2
Branches
Tags
No related merge requests found
......@@ -52,6 +52,9 @@ TARGET_LINK_LIBRARIES(MetadataExample OTBCommon OTBIO ITKCommon ITKIO)
ADD_EXECUTABLE(DXFReaderExample DXFReaderExample.cxx )
TARGET_LINK_LIBRARIES(DXFReaderExample OTBCommon OTBIO ITKCommon ITKIO dxf)
ADD_EXECUTABLE(VectorDataIOExample VectorDataIOExample.cxx )
TARGET_LINK_LIBRARIES(VectorDataIOExample OTBCommon OTBIO ITKCommon ITKIO)
ADD_EXECUTABLE(DEMToImageGenerator DEMToImageGenerator.cxx )
TARGET_LINK_LIBRARIES(DEMToImageGenerator OTBProjections OTBIO OTBCommon ITKCommon ITKIO otbossim otbossimElevation )
......
......@@ -27,7 +27,7 @@
// Software Guide : BeginLatex
//
// This example illustrates how to read a DXF file and how to draw objects
// \label{DXFExample}This example illustrates how to read a DXF file and how to draw objects
// on a $2D$ binary image. The graphical DXF objects which can be read are the following : Point, Line
// Polyline, Circle and 3DFace.
// The example begins by including the appropriate headers.
......
/*=========================================================================
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.
=========================================================================*/
// Software Guide : BeginLatex
//
// Although \ref{DXFExample}
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
#include "otbVectorData.h"
#include "otbVectorDataFileReader.h"
#include "otbVectorDataFileWriter.h"
#include "itkPreOrderTreeIterator.h"
#include "otbObjectList.h"
#include "otbPolygon.h"
// Software Guide : EndCodeSnippet
int main(int argc, char * argv[])
{
if( argc != 3 )
{
std::cerr << "Usage: " << argv[0] ;
std::cerr << "inputFile outputFile" << std::endl;
return EXIT_FAILURE;
}
typedef short unsigned int PixelType;
typedef otb::VectorData<PixelType,2> VectorDataType;
typedef VectorDataType::Pointer VectorDataPointerType;
typedef otb::VectorDataFileReader<VectorDataType>
VectorDataFileReaderType;
typedef VectorDataFileReaderType::Pointer VectorDataFileReaderPointerType;
typedef VectorDataType::DataTreeType DataTreeType;
typedef DataTreeType::Pointer DataTreePointerType;
typedef itk::PreOrderTreeIterator<DataTreeType> TreeIteratorType;
VectorDataFileReaderPointerType reader = VectorDataFileReaderType::New();
reader->SetFileName(argv[1]);
reader->Update();
typedef otb::Polygon<PixelType> PolygonType;
typedef PolygonType::VertexListIteratorType PolygonIteratorType;
typedef otb::ObjectList<PolygonType> PolygonListType;
typedef PolygonListType::Iterator PolygonListIteratorType;
PolygonListType::Pointer polygonList = PolygonListType::New();
TreeIteratorType it(reader->GetOutput()->GetDataTree());
it.GoToBegin();
while(!it.IsAtEnd())
{
if(it.Get()->IsPolygonFeature())
{
polygonList->PushBack(it.Get()->GetPolygonExteriorRing());
}
++it;
}
polygonList->PushBack(PolygonType::New());
//polygonList->Back()->SetValue(m_LeftViewer->GetNextROILabel());
typedef VectorDataType::DataNodeType DataNodeType;
typedef DataNodeType::PointType PointType;
typedef DataNodeType::LineType LineType;
typedef LineType::VertexType VertexType;
VectorDataType::Pointer data = VectorDataType::New();
DataNodeType::Pointer document = DataNodeType::New();
DataNodeType::Pointer folder1 = DataNodeType::New();
DataNodeType::Pointer folder2 = DataNodeType::New();
DataNodeType::Pointer folder3 = DataNodeType::New();
DataNodeType::Pointer line = DataNodeType::New();
document->SetNodeType(otb::DOCUMENT);
folder1->SetNodeType(otb::FOLDER);
folder2->SetNodeType(otb::FOLDER);
folder3->SetNodeType(otb::FOLDER);
line->SetNodeType(otb::FEATURE_LINE);
document->SetNodeId("DOCUMENT");
folder1->SetNodeId("FOLDER1");
folder2->SetNodeId("FOLDER2");
folder3->SetNodeId("FOLDER3");
line->SetNodeId("FEATURE_LINE");
VertexType p1;
p1.Fill(5);
VertexType p3;
p3.Fill(0);
VertexType p2;
p2[0]=0;
p2[1]=10;
LineType::Pointer l = LineType::New();
l->AddVertex(p1);
l->AddVertex(p2);
l->AddVertex(p3);
line->SetLine(l);
DataNodeType::Pointer root = data->GetDataTree()->GetRoot()->Get();
data->GetDataTree()->Add(document,root);
data->GetDataTree()->Add(folder1,document);
data->GetDataTree()->Add(folder2,document);
data->GetDataTree()->Add(folder3,document);
data->GetDataTree()->Add(line,folder2);
typedef otb::VectorDataFileWriter<VectorDataType> WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(argv[2]);
writer->SetInput(data);
writer->Update();
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment