Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Main Repositories
otb
Commits
561d7fdd
Commit
561d7fdd
authored
Feb 19, 2016
by
Guillaume Pasero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: move template function to txx file
parent
a5ec67b7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
170 additions
and
135 deletions
+170
-135
Modules/Learning/Sampling/include/otbPolygonClassStatisticsAccumulator.h
...g/Sampling/include/otbPolygonClassStatisticsAccumulator.h
+4
-0
Modules/Learning/Sampling/include/otbPolygonClassStatisticsAccumulator.txx
...Sampling/include/otbPolygonClassStatisticsAccumulator.txx
+166
-0
Modules/Learning/Sampling/src/otbPolygonClassStatisticsAccumulator.cxx
...ing/Sampling/src/otbPolygonClassStatisticsAccumulator.cxx
+0
-135
No files found.
Modules/Learning/Sampling/include/otbPolygonClassStatisticsAccumulator.h
View file @
561d7fdd
...
...
@@ -81,4 +81,8 @@ private:
}
// end of namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbPolygonClassStatisticsAccumulator.txx"
#endif
#endif
Modules/Learning/Sampling/include/otbPolygonClassStatisticsAccumulator.txx
0 → 100644
View file @
561d7fdd
/*=========================================================================
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 __otbPolygonClassStatisticsAccumulator_txx
#define __otbPolygonClassStatisticsAccumulator_txx
#include "otbPolygonClassStatisticsAccumulator.h"
#include "otbMacro.h"
namespace otb
{
template <typename TIterator>
void
PolygonClassStatisticsAccumulator
::Add(otb::ogr::Layer::const_iterator& featIt,
TIterator& imgIt)
{
// Get class name
std::string className(featIt->ogr().GetFieldAsString(this->m_FieldIndex));
// Get Feature Id
unsigned long featureId = featIt->ogr().GetFID();
if (m_ElmtsInClass.count(className) == 0)
{
m_ElmtsInClass[className] = 0UL;
}
if (m_Polygon.count(featureId) == 0)
{
m_Polygon[featureId] = 0UL;
}
typename TIterator::ImageType::PointType imgPoint;
typename TIterator::IndexType imgIndex;
OGRPoint tmpPoint(0.0,0.0,0.0);
imgIt.GoToBegin();
OGRGeometry * geom = featIt->ogr().GetGeometryRef();
switch (geom->getGeometryType())
{
case wkbPoint:
case wkbPoint25D:
{
OGRPoint* castPoint = dynamic_cast<OGRPoint*>(geom);
if (castPoint == NULL)
{
// Wrong Type !
break;
}
imgPoint[0] = castPoint->getX();
imgPoint[1] = castPoint->getY();
imgIt.GetImageIterator().GetImage()->TransformPhysicalPointToIndex(imgPoint,imgIndex);
while (!imgIt.IsAtEnd())
{
if (imgIndex == imgIt.GetIndex())
{
m_NbPixelsGlobal++;
m_ElmtsInClass[className]++;
m_Polygon[featureId]++;
break;
}
}
break;
}
case wkbLineString:
case wkbLineString25D:
{
OGRPolygon tmpPolygon;
OGRLinearRing ring;
ring.addPoint(0.0,0.0,0.0);
ring.addPoint(1.0,0.0,0.0);
ring.addPoint(1.0,1.0,0.0);
ring.addPoint(0.0,1.0,0.0);
ring.addPoint(0.0,0.0,0.0);
tmpPolygon.addRing(&ring);
typename TIterator::ImageType::SpacingType imgAbsSpacing;
imgAbsSpacing = imgIt.GetImageIterator().GetImage()->GetSpacing();
if (imgAbsSpacing[0] < 0) imgAbsSpacing[0] = -imgAbsSpacing[0];
if (imgAbsSpacing[1] < 0) imgAbsSpacing[1] = -imgAbsSpacing[1];
while (!imgIt.IsAtEnd())
{
imgIt.GetImageIterator().GetImage()->TransformIndexToPhysicalPoint(imgIt.GetIndex(),imgPoint);
ring.setPoint(0
,imgPoint[0]-0.5*imgAbsSpacing[0]
,imgPoint[1]-0.5*imgAbsSpacing[1]
,0.0);
ring.setPoint(1
,imgPoint[0]+0.5*imgAbsSpacing[0]
,imgPoint[1]-0.5*imgAbsSpacing[1]
,0.0);
ring.setPoint(2
,imgPoint[0]+0.5*imgAbsSpacing[0]
,imgPoint[1]+0.5*imgAbsSpacing[1]
,0.0);
ring.setPoint(3
,imgPoint[0]-0.5*imgAbsSpacing[0]
,imgPoint[1]+0.5*imgAbsSpacing[1]
,0.0);
ring.setPoint(4
,imgPoint[0]-0.5*imgAbsSpacing[0]
,imgPoint[1]-0.5*imgAbsSpacing[1]
,0.0);
if (geom->Intersects(&tmpPolygon))
{
m_NbPixelsGlobal++;
m_ElmtsInClass[className]++;
m_Polygon[featureId]++;
}
++imgIt;
}
break;
}
case wkbPolygon:
case wkbPolygon25D:
{
while (!imgIt.IsAtEnd())
{
imgIt.GetImageIterator().GetImage()->TransformIndexToPhysicalPoint(imgIt.GetIndex(),imgPoint);
tmpPoint.setX(imgPoint[0]);
tmpPoint.setY(imgPoint[1]);
if (geom->Contains(&tmpPoint))
{
m_NbPixelsGlobal++;
m_ElmtsInClass[className]++;
m_Polygon[featureId]++;
}
++imgIt;
}
break;
}
case wkbMultiPoint:
case wkbMultiPoint25D:
case wkbMultiLineString:
case wkbMultiLineString25D:
case wkbMultiPolygon:
case wkbMultiPolygon25D:
case wkbGeometryCollection:
case wkbGeometryCollection25D:
{
otbWarningMacro("Geometry not handled: " << geom->getGeometryName());
break;
}
default:
{
otbWarningMacro("Geometry not handled: " << geom->getGeometryName());
break;
}
}
}
} // end of namespace otb
#endif
Modules/Learning/Sampling/src/otbPolygonClassStatisticsAccumulator.cxx
View file @
561d7fdd
...
...
@@ -21,141 +21,6 @@
namespace
otb
{
template
<
typename
TIterator
>
void
PolygonClassStatisticsAccumulator
::
Add
(
otb
::
ogr
::
Layer
::
const_iterator
&
featIt
,
TIterator
&
imgIt
)
{
// Get class name
std
::
string
className
(
featIt
->
ogr
().
GetFieldAsString
(
this
->
m_FieldIndex
));
// Get Feature Id
unsigned
long
featureId
=
featIt
->
ogr
().
GetFID
();
if
(
m_ElmtsInClass
.
count
(
className
)
==
0
)
{
m_ElmtsInClass
[
className
]
=
0UL
;
}
if
(
m_Polygon
.
count
(
featureId
)
==
0
)
{
m_Polygon
[
featureId
]
=
0UL
;
}
typename
TIterator
::
ImageType
::
PointType
imgPoint
;
typename
TIterator
::
IndexType
imgIndex
;
OGRPoint
tmpPoint
(
0.0
,
0.0
,
0.0
);
imgIt
.
GoToBegin
();
OGRGeometry
*
geom
=
featIt
->
ogr
().
GetGeometryRef
();
switch
(
geom
->
getGeometryType
())
{
case
wkbPoint
:
case
wkbPoint25D
:
{
OGRPoint
*
castPoint
=
dynamic_cast
<
OGRPoint
*>
(
geom
);
if
(
castPoint
==
NULL
)
{
// Wrong Type !
break
;
}
imgPoint
[
0
]
=
castPoint
->
getX
();
imgPoint
[
1
]
=
castPoint
->
getY
();
imgIt
.
GetImage
()
->
TransformPhysicalPointToIndex
(
imgPoint
,
imgIndex
);
while
(
!
imgIt
.
IsAtEnd
())
{
if
(
imgIndex
==
imgIt
.
GetIndex
())
{
m_NbPixelsGlobal
++
;
m_ElmtsInClass
[
className
]
++
;
m_Polygon
[
featureId
]
++
;
break
;
}
}
break
;
}
case
wkbLineString
:
case
wkbLineString25D
:
{
OGRPolygon
tmpPolygon
;
tmpPolygon
.
getExteriorRing
()
->
addPoint
(
0.0
,
0.0
,
0.0
);
tmpPolygon
.
getExteriorRing
()
->
addPoint
(
1.0
,
0.0
,
0.0
);
tmpPolygon
.
getExteriorRing
()
->
addPoint
(
1.0
,
1.0
,
0.0
);
tmpPolygon
.
getExteriorRing
()
->
addPoint
(
0.0
,
1.0
,
0.0
);
tmpPolygon
.
getExteriorRing
()
->
addPoint
(
0.0
,
0.0
,
0.0
);
typename
TIterator
::
ImageType
::
SpacingType
imgAbsSpacing
;
imgAbsSpacing
=
imgIt
.
GetImage
()
->
GetSpacing
();
if
(
imgAbsSpacing
[
0
]
<
0
)
imgAbsSpacing
[
0
]
=
-
imgAbsSpacing
[
0
];
if
(
imgAbsSpacing
[
1
]
<
0
)
imgAbsSpacing
[
1
]
=
-
imgAbsSpacing
[
1
];
while
(
!
imgIt
.
IsAtEnd
())
{
imgIt
.
GetImage
()
->
TransformIndexToPhysicalPoint
(
imgIt
.
GetIndex
(),
imgPoint
);
tmpPolygon
.
getExteriorRing
()
->
setPoint
(
imgPoint
[
0
]
-
0.5
*
imgAbsSpacing
[
0
],
imgPoint
[
1
]
-
0.5
*
imgAbsSpacing
[
1
]
,
0.0
);
tmpPolygon
.
getExteriorRing
()
->
setPoint
(
imgPoint
[
0
]
+
0.5
*
imgAbsSpacing
[
0
],
imgPoint
[
1
]
-
0.5
*
imgAbsSpacing
[
1
]
,
0.0
);
tmpPolygon
.
getExteriorRing
()
->
setPoint
(
imgPoint
[
0
]
+
0.5
*
imgAbsSpacing
[
0
],
imgPoint
[
1
]
+
0.5
*
imgAbsSpacing
[
1
]
,
0.0
);
tmpPolygon
.
getExteriorRing
()
->
setPoint
(
imgPoint
[
0
]
-
0.5
*
imgAbsSpacing
[
0
],
imgPoint
[
1
]
+
0.5
*
imgAbsSpacing
[
1
]
,
0.0
);
tmpPolygon
.
getExteriorRing
()
->
setPoint
(
imgPoint
[
0
]
-
0.5
*
imgAbsSpacing
[
0
],
imgPoint
[
1
]
-
0.5
*
imgAbsSpacing
[
1
]
,
0.0
);
if
(
geom
->
Intersects
(
&
tmpPolygon
))
{
m_NbPixelsGlobal
++
;
m_ElmtsInClass
[
className
]
++
;
m_Polygon
[
featureId
]
++
;
}
++
imgIt
;
}
break
;
}
case
wkbPolygon
:
case
wkbPolygon25D
:
{
while
(
!
imgIt
.
IsAtEnd
())
{
imgIt
.
GetImage
()
->
TransformIndexToPhysicalPoint
(
imgIt
.
GetIndex
(),
imgPoint
);
tmpPoint
.
setX
(
imgPoint
[
0
]);
tmpPoint
.
setY
(
imgPoint
[
1
]);
if
(
geom
->
Contains
(
&
tmpPoint
))
{
m_NbPixelsGlobal
++
;
m_ElmtsInClass
[
className
]
++
;
m_Polygon
[
featureId
]
++
;
}
++
imgIt
;
}
break
;
}
case
wkbMultiPoint
:
case
wkbMultiPoint25D
:
case
wkbMultiLineString
:
case
wkbMultiLineString25D
:
case
wkbMultiPolygon
:
case
wkbMultiPolygon25D
:
case
wkbGeometryCollection
:
case
wkbGeometryCollection25D
:
{
//otbWarningMacro("Geometry not handled: " << geom->getGeometryName());
break
;
}
default:
{
//otbWarningMacro("Geometry not handled: " << geom->getGeometryName());
break
;
}
}
}
void
PolygonClassStatisticsAccumulator
::
Reset
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment