Commit f5ba335e authored by Julien Michel's avatar Julien Michel
Browse files

Suite de l'intégration de la DXF lib.

parent e12e377b
......@@ -159,7 +159,7 @@ protected:
};
} // end namespace otb
#ifndef ITK_MANUAL_INSTANTIATION
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbSpatialObjectToImageDrawingFilter.txx"
#endif
......
......@@ -53,7 +53,7 @@ class ITK_EXPORT SpatialObjectSource
/**
* Get the output spatial object.
* \return The outptu spatial object.
* \return The output spatial object.
*/
virtual SpatialObjectType * GetOutput(void);
......@@ -62,6 +62,8 @@ class ITK_EXPORT SpatialObjectSource
SpatialObjectSource();
/** Destructor */
~SpatialObjectSource() {}
/** Main computation method */
virtual void GenerateData(void) {};
/** PrintSelf method */
void PrintSelf(std::ostream& os, itk::Indent indent) const;
......
......@@ -29,8 +29,9 @@ template <class TSpatialObject>
SpatialObjectSource<TSpatialObject>
::SpatialObjectSource()
{
SpatialObjectPointerType output = SpatialObjectType::New();
this->Superclass::SetNumberOfRequiredOutputs(1);
this->Superclass::SetNthOutput(0,SpatialObjectType::New().GetPointer());
this->Superclass::SetNthOutput(0,output.GetPointer());
}
/**
* Get the output image list
......
/*=========================================================================
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 __otbDXFToSpatialObjectGroupFilter_h
#define __otbDXFToSpatialObjectGroupFilter_h
#include "dl_creationadapter.h"
#include "itkGroupSpatialObject.h"
#include "otbSpatialObjectSource.h"
#include "itkEllipseSpatialObject.h"
/* #include <iostream> */
/* #include <stdio.h> */
#include "itkGroupSpatialObject.h"
#include "itkSpatialObjectPoint.h"
#include "itkLandmarkSpatialObject.h"
#include "otbLineSpatialObject.h"
#include "itkLineSpatialObjectPoint.h"
#include "otbArcSpatialObject.h"
namespace otb
{
/** \class DXFToSpatialObjectGroupFilter
* \brief
*
*/
template <unsigned int VDimension = 3>
class ITK_EXPORT DXFToSpatialObjectGroupFilter
: public DL_CreationAdapter, public SpatialObjectSource< itk::GroupSpatialObject<VDimension> >
{
public:
/** Standard typedefs */
typedef DXFToSpatialObjectGroupFilter Self;
typedef SpatialObjectSource< itk::GroupSpatialObject<VDimension> > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(SpatialObjectReader,SpatialObjectSource);
/** Spatial objects typedefs */
typedef itk::GroupSpatialObject<VDimension> GroupSpatialObjectType;
typedef typename GroupSpatialObjectType::Pointer GroupPointer;
typedef itk::SpatialObjectPoint<VDimension> PointType;
typedef itk::LandmarkSpatialObject<VDimension> LandmarkType;
typedef typename LandmarkType::Pointer LandmarkPointer;
typedef typename LandmarkType::PointListType LandmarkListType;
typedef LineSpatialObject<VDimension> LineType;
typedef typename LineType::Pointer LinePointer;
typedef itk::LineSpatialObjectPoint<VDimension> LinePointType;
typedef typename LineType::PointListType LineListType;
typedef otb::ArcSpatialObject<VDimension> ArcType;
typedef typename ArcType::Pointer ArcPointer;
typedef itk::EllipseSpatialObject<VDimension> EllipseType;
typedef typename EllipseType::Pointer EllipsePointer;
typedef std::vector< LinePointType > PointListType;
virtual void addLayer(const DL_LayerData& data);
virtual void addPoint(const DL_PointData& data);
virtual void addLine(const DL_LineData& data);
virtual void add3DFace(const DL_3DFaceData& data);
virtual void addArc(const DL_ArcData& data);
virtual void addCircle(const DL_CircleData& data);
virtual void addPolyline(const DL_PolylineData& data);
virtual void addVertex(const DL_VertexData& data);
virtual void SetLayer(const char* layer);
/** Main computation method */
void GenerateData(void);
protected:
/** Constructor */
DXFToSpatialObjectGroupFilter();
/** Destructor */
virtual ~DXFToSpatialObjectGroupFilter() {}
/** PrintSelf method */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
DXFToSpatialObjectGroupFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
int m_CurrentObjectType;
LineListType m_PointList;
LinePointType m_PremierPoint;
int m_PolylineClosed; //(=1 if the polyline is closed,else =0 );
const char* m_layer;
bool layerspecified;
};
}
#ifndef ITK_MANUAL_INSTANTIATION
#include "otbDXFToSpatialObjectGroupFilter.txx"
#endif
#endif
/*=========================================================================
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 __otbDXFToSpatialObjectGroupFilter_txx
#define __otbDXFToSpatialObjectGroupFilter_txx
#include "otbDXFToSpatialObjectGroupFilter.h"
namespace otb
{
/**
* Constructor.
*/
template <unsigned int VDimension>
DXFToSpatialObjectGroupFilter<VDimension>
::DXFToSpatialObjectGroupFilter()
{
m_CurrentObjectType=0;
m_PointList.clear();
m_layer="";
layerspecified=false;
}
/**
* Set the layer to read
*/
template <unsigned int VDimension>
void
DXFToSpatialObjectGroupFilter<VDimension>
::SetLayer(const char* layer) {
m_layer=layer;
layerspecified=true;
}
/**
* Sample implementation of the method which handles layers.
*/
template <unsigned int VDimension>
void
DXFToSpatialObjectGroupFilter<VDimension>
::addLayer(const DL_LayerData& data)
{
GroupPointer grpPtr = this->GetOutput();
//If the previous object is a vertex we create the polyline:
if (m_CurrentObjectType==6)
{
//If the polyline is closed then we add the first point at the end of the list:
if (m_PolylineClosed==1)
{
m_PointList.push_back(m_PremierPoint);
}
LinePointer m_CurrentPolyLine=LineType::New();
m_CurrentPolyLine->SetPoints(m_PointList);
if(layerspecified)
{
if (!strcmp(attributes.getLayer().c_str(),m_layer))
{
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
}
else
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
m_CurrentObjectType=0;
otbMsgDebugMacro(<<"LAYER: "<< data.name <<" flags: "<<data.flags);
}
/**
* Sample implementation of the method which handles point entities.
*/
template <unsigned int VDimension>
void
DXFToSpatialObjectGroupFilter<VDimension>
::addPoint(const DL_PointData& data)
{
GroupPointer grpPtr = this->GetOutput();
//If the previous object is a vertex we create the polyline:
if (m_CurrentObjectType==6)
{
//If the polyline is closed then we add the first point at the end of the list:
if (m_PolylineClosed==1)
{
m_PointList.push_back(m_PremierPoint);
}
LinePointer m_CurrentPolyLine=LineType::New();
m_CurrentPolyLine->SetPoints(m_PointList);
if(layerspecified)
{
if (!strcmp( attributes.getLayer().c_str(),m_layer))
{
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
}
else
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
m_CurrentObjectType=1;
LandmarkPointer landmark=LandmarkType::New();
PointType point;
LandmarkListType list;
point.SetPosition(data.x, data.y, data.z );
list.push_back(point);
landmark->SetPoints(list);
if(layerspecified)
{
if (!strcmp(attributes.getLayer().c_str(),m_layer))
{
grpPtr->AddSpatialObject(landmark);
}
}
else
grpPtr->AddSpatialObject(landmark);
otbMsgDebugMacro(<<"POINT ("<<data.x<<", "<<data.y<<", "<<data.z<<") ( nb objects "<<grpPtr->GetNumberOfChildren()<<")");
}
/**
* Sample implementation of the method which handles line entities.
*/
template <unsigned int VDimension>
void
DXFToSpatialObjectGroupFilter<VDimension>
::addLine(const DL_LineData& data)
{
GroupPointer grpPtr = this->GetOutput();
//If the previous object is a vertex we create the polyline:
if (m_CurrentObjectType==6)
{
//If the polyline is closed then we add the first point at the end of the list:
if (m_PolylineClosed==1)
{
m_PointList.push_back(m_PremierPoint);
}
LinePointer m_CurrentPolyLine=LineType::New();
m_CurrentPolyLine->SetPoints(m_PointList);
if(layerspecified)
{
if (!strcmp( attributes.getLayer().c_str(),m_layer))
{
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
}
else
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
m_CurrentObjectType=2;
LinePointer line=LineType::New();
LinePointType point1,point2;
LineListType list,pointlist;
pointlist.clear();
point1.SetPosition(data.x1, data.y1, data.z1);
list.push_back(point1);
point2.SetPosition(data.x2, data.y2, data.z2);
list.push_back(point2);
line->SetPoints(list);
if(layerspecified)
{
if (!strcmp(attributes.getLayer().c_str(),m_layer))
{
grpPtr->AddSpatialObject(line);
}
}
else
grpPtr->AddSpatialObject(line);
otbMsgDebugMacro(<<"LINE "<<"("<<data.x1<<", "<<data.y1<<", "<<data.z1<<") ("
<<data.x2<<", "<<data.y2<<", "<<data.z2 <<grpPtr->GetNumberOfChildren()<<")");
}
/**
* Sample implementation of the method which handles 3DFace entities.
*/
template <unsigned int VDimension>
void
DXFToSpatialObjectGroupFilter<VDimension>
::add3DFace(const DL_3DFaceData& data)
{
GroupPointer grpPtr = this->GetOutput();
//If the previous object is a vertex we create the polyline:
if (m_CurrentObjectType==6)
{
//If the polyline is closed then we add the first point at the end of the list:
if (m_PolylineClosed==1)
{
m_PointList.push_back(m_PremierPoint);
}
LinePointer m_CurrentPolyLine=LineType::New();
m_CurrentPolyLine->SetPoints(m_PointList);
if(layerspecified)
{
if (!strcmp(attributes.getLayer().c_str(),m_layer))
{
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
}
else
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
m_CurrentObjectType=7;
LinePointer line=LineType::New();
LinePointType point1,point2,point3,point4;
LineListType list,pointlist;
pointlist.clear();
point1.SetPosition(data.x1, data.y1, data.z1);
list.push_back(point1);
point2.SetPosition(data.x2, data.y2, data.z2);
list.push_back(point2);
point3.SetPosition(data.x3, data.y3, data.z3);
list.push_back(point3);
point4.SetPosition(data.x4, data.y4, data.z4);
list.push_back(point4);
list.push_back(point1);
line->SetPoints(list);
if(layerspecified)
{
if (!strcmp(attributes.getLayer().c_str(),m_layer))
{
grpPtr->AddSpatialObject(line);
}
}
else
grpPtr->AddSpatialObject(line);
otbMsgDebugMacro(<<"3D Face "<<"("<<data.x1<<", "<<data.y1<<", "<<data.z1<<") ("
<<data.x2<<", "<<data.y2<<", "<<data.z2<<") ("
<<data.x3<<", "<<data.y3<<", "<<data.z3<<") ("
<<data.x4<<", "<<data.y4<<", "<<data.z4<<") ("
<<grpPtr->GetNumberOfChildren()<<")");
}
/**
* Sample implementation of the method which handles arc entities.
*/
template <unsigned int VDimension>
void
DXFToSpatialObjectGroupFilter<VDimension>
::addArc(const DL_ArcData& data)
{
GroupPointer grpPtr = this->GetOutput();
//If the previous object is a vertex we create the polyline:
if (m_CurrentObjectType==6)
{
//If the polyline is closed then we add the first point at the end of the list:
if (m_PolylineClosed==1)
{
m_PointList.push_back(m_PremierPoint);
}
LinePointer m_CurrentPolyLine=LineType::New();
m_CurrentPolyLine->SetPoints(m_PointList);
if(layerspecified)
{
if (!strcmp(attributes.getLayer().c_str(),m_layer))
{
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
}
else
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
otbMsgDebugMacro(<<"ARC ("<<data.cx<<", "<<data.cy<<", "<<data.cz<<") "
<<data.radius<<", "<<data.angle1<<", "<<data.angle2
<<" (nb objects "<<grpPtr->GetNumberOfChildren()<<")");
}
/**
* Sample implementation of the method which handles circle entities.
*/
template <unsigned int VDimension>
void
DXFToSpatialObjectGroupFilter<VDimension>
::addCircle(const DL_CircleData& data)
{
GroupPointer grpPtr = this->GetOutput();
//If the previous object is a vertex we create the polyline:
if (m_CurrentObjectType==6)
{
//If the polyline is closed then we add the first point at the end of the list:
if (m_PolylineClosed==1)
{
m_PointList.push_back(m_PremierPoint);
}
LinePointer m_CurrentPolyLine=LineType::New();
m_CurrentPolyLine->SetPoints(m_PointList);
if(layerspecified)
{
if (!strcmp(attributes.getLayer().c_str(),m_layer))
{
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
}
else
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
m_CurrentObjectType=4;
EllipsePointer ellipse=EllipseType::New();
ellipse->SetRadius(data.radius);
double offset[VDimension];
offset[ 0 ] = data.cx;
offset[ 1 ] = data.cy;
if (VDimension==3)
{
offset[ 2 ] = data.cz;
}
ellipse->GetObjectToParentTransform()->SetOffset(offset);
ellipse->ComputeObjectToWorldTransform();
if(layerspecified)
{
if (!strcmp(attributes.getLayer().c_str(),m_layer))
{
grpPtr->AddSpatialObject(ellipse);
}
}
else
grpPtr->AddSpatialObject(ellipse);
otbMsgDebugMacro(<<"CIRCLE ("<<data.cx<<", "<<data.cy<<", "<<data.cz<<") "
<<data.radius
<<" (nb objects "<<grpPtr->GetNumberOfChildren()<<")");
}
/**
* Sample implementation of the method which handles polyline entities.
*/
template <unsigned int VDimension>
void
DXFToSpatialObjectGroupFilter<VDimension>
::addPolyline(const DL_PolylineData& data)
{
GroupPointer grpPtr = this->GetOutput();
//If the previous object is a vertex we create the polyline:
if (m_CurrentObjectType==6)
{
//If the polyline is closed then we add the first point at the end of the list:
if (m_PolylineClosed==1)
{
m_PointList.push_back(m_PremierPoint);
}
LinePointer m_CurrentPolyLine=LineType::New();
m_CurrentPolyLine->SetPoints(m_PointList);
if(layerspecified)
{
if (!strcmp( attributes.getLayer().c_str(),m_layer))
{
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
}
else
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
m_CurrentObjectType=5;
m_PointList.clear();//reset list
if ((int)data.flags==1)
{
m_PolylineClosed=1;
}
else
m_PolylineClosed=0;
otbMsgDebugMacro(<<"POLYLINE ");
otbMsgDebugMacro(<<"flags: "<< data.flags <<",nombre de sommets: "<< data.number);
}
/**
* Sample implementation of the method which handles vertices.
*/
template <unsigned int VDimension>
void
DXFToSpatialObjectGroupFilter<VDimension>
::addVertex(const DL_VertexData& data)
{
GroupPointer grpPtr = this->GetOutput();
m_CurrentObjectType=6;
LinePointType point;
point.SetPosition(data.x, data.y, data.z);
m_PointList.push_back(point);
m_PremierPoint=m_PointList[0];
otbMsgDebugMacro(<<"VERTEX ("<<data.x<<", "<<data.y<<", "<<data.z<<") "
<<data.bulge
<<" (nb objects "<<grpPtr->GetNumberOfChildren()<<")");
}
template <unsigned int VDimension>
void
DXFToSpatialObjectGroupFilter<VDimension>
::GenerateData()
{
GroupPointer grpPtr = this->GetOutput();
//If the previous object is a vertex we create the polyline:
if (m_CurrentObjectType==6)
{
//If the polyline is closed then we add the first point at the end of the list:
if (m_PolylineClosed==1)
{
m_PointList.push_back(m_PremierPoint);
}
LinePointer m_CurrentPolyLine=LineType::New();
m_CurrentPolyLine->SetPoints(m_PointList);
if(layerspecified)
{
if (!strcmp( attributes.getLayer().c_str(),m_layer))
{
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
}
else
grpPtr->AddSpatialObject(m_CurrentPolyLine);
}
}
template <unsigned int VDimension>
void
DXFToSpatialObjectGroupFilter<VDimension>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
}
} //namespace otb
#endif
/*=========================================================================
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 __otbSpatialObjectDXFReader_h
#define __otbSpatialObjectDXFReader_h
#include "itkGroupSpatialObject.h"
#include "otbSpatialObjectSource.h"
namespace otb
{
/** \class SpatialObjectDXFReader
* \brief
* \ingroups
*/
template <unsigned int VDimension = 2>
class ITK_EXPORT SpatialObjectDXFReader
: public SpatialObjectSource< itk::GroupSpatialObject<VDimension> >
{
public:
typedef SpatialObjectDXFReader Self;
typedef SpatialObjectSource< itk::GroupSpatialObject<VDimension> > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory */
itkNewMacro(Self);
/** Run-time type information (and rel