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
a25ac627
Commit
a25ac627
authored
Feb 19, 2016
by
Guillaume Pasero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TEST: implement test for OGRDataToClassStatisticsFilter
parent
53c8bf2b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
4 deletions
+57
-4
Modules/Learning/Sampling/test/CMakeLists.txt
Modules/Learning/Sampling/test/CMakeLists.txt
+3
-1
Modules/Learning/Sampling/test/otbOGRDataToClassStatisticsFilterTest.cxx
...g/Sampling/test/otbOGRDataToClassStatisticsFilterTest.cxx
+54
-3
No files found.
Modules/Learning/Sampling/test/CMakeLists.txt
View file @
a25ac627
...
...
@@ -15,4 +15,6 @@ otb_add_test(NAME leTuOGRDataToClassStatisticsFilterNew COMMAND otbSamplingTestD
otbOGRDataToClassStatisticsFilterNew
)
otb_add_test
(
NAME leTvOGRDataToClassStatisticsFilter COMMAND otbSamplingTestDriver
otbOGRDataToClassStatisticsFilter
)
otbOGRDataToClassStatisticsFilter
${
INPUTDATA
}
/variousVectors.sqlite
${
TEMP
}
/leTvOGRDataToClassStatisticsFilterOutput.txt
)
Modules/Learning/Sampling/test/otbOGRDataToClassStatisticsFilterTest.cxx
View file @
a25ac627
...
...
@@ -19,6 +19,7 @@
#include "otbOGRDataToClassStatisticsFilter.h"
#include "otbVectorImage.h"
#include "otbImage.h"
#include <fstream>
int
otbOGRDataToClassStatisticsFilterNew
(
int
itkNotUsed
(
argc
),
char
*
itkNotUsed
(
argv
)
[])
{
...
...
@@ -48,12 +49,16 @@ int otbOGRDataToClassStatisticsFilter(int argc, char* argv[])
otb
::
ogr
::
DataSource
::
Pointer
vectors
=
otb
::
ogr
::
DataSource
::
New
(
vectorPath
);
InputImageType
::
RegionType
region
;
region
.
SetSize
(
0
,
100
);
region
.
SetSize
(
0
,
99
);
region
.
SetSize
(
1
,
50
);
InputImageType
::
PointType
origin
;
origin
.
Fill
(
0.5
);
InputImageType
::
SpacingType
spacing
;
spacing
[
0
]
=
1.0
;
spacing
[
1
]
=
-
1.0
;
InputImageType
::
PixelType
pixel
(
3
);
pixel
.
Fill
(
1
);
...
...
@@ -61,12 +66,14 @@ int otbOGRDataToClassStatisticsFilter(int argc, char* argv[])
inputImage
->
SetNumberOfComponentsPerPixel
(
3
);
inputImage
->
SetRegions
(
region
);
inputImage
->
SetOrigin
(
origin
);
inputImage
->
SetSpacing
(
spacing
);
inputImage
->
Allocate
();
inputImage
->
FillBuffer
(
pixel
);
MaskImageType
::
Pointer
mask
=
MaskImageType
::
New
();
mask
->
SetRegions
(
region
);
mask
->
SetOrigin
(
origin
);
mask
->
SetSpacing
(
spacing
);
mask
->
Allocate
();
itk
::
ImageRegionIterator
<
MaskImageType
>
it
(
mask
,
region
);
unsigned
int
count
=
0
;
...
...
@@ -82,15 +89,59 @@ int otbOGRDataToClassStatisticsFilter(int argc, char* argv[])
filter
->
SetMask
(
mask
);
filter
->
SetOGRData
(
vectors
);
filter
->
SetFieldName
(
fieldName
);
filter
->
SetLayerIndex
(
0
);
filter
->
Update
();
FilterType
::
ClassCountMapType
&
classCount
=
filter
->
GetClassCountOutput
()
->
Get
();
FilterType
::
PolygonSizeMapType
&
polySize
=
filter
->
GetPolygonSizeOutput
()
->
Get
();
FilterType
::
ClassCountMapType
::
const_iterator
itClass
;
FilterType
::
PolygonSizeMapType
::
const_iterator
itPoly
;
FilterType
::
ClassCountMapType
::
const_iterator
itClass
=
classCount
.
begin
();
std
::
ofstream
ofs
;
ofs
.
open
(
outputPath
.
c_str
());
ofs
<<
"# Layer 0 : polygons"
<<
std
::
endl
;
ofs
<<
"# Class statistics ( label : sampleCount)"
<<
std
::
endl
;
for
(
itClass
=
classCount
.
begin
();
itClass
!=
classCount
.
end
()
;
++
itClass
)
{
ofs
<<
itClass
->
first
<<
" : "
<<
itClass
->
second
<<
std
::
endl
;
}
ofs
<<
"# Vector sizes ( featureId : sampleCount)"
<<
std
::
endl
;
for
(
itPoly
=
polySize
.
begin
()
;
itPoly
!=
polySize
.
end
()
;
++
itPoly
)
{
ofs
<<
itPoly
->
first
<<
" : "
<<
itPoly
->
second
<<
std
::
endl
;
}
filter
->
SetLayerIndex
(
1
);
filter
->
Update
();
std
::
cout
<<
filter
<<
std
::
endl
;
ofs
<<
"# Layer 1 : lines"
<<
std
::
endl
;
ofs
<<
"# Class statistics ( label : sampleCount)"
<<
std
::
endl
;
for
(
itClass
=
classCount
.
begin
()
;
itClass
!=
classCount
.
end
()
;
++
itClass
)
{
ofs
<<
itClass
->
first
<<
" : "
<<
itClass
->
second
<<
std
::
endl
;
}
ofs
<<
"# Vector sizes ( featureId : sampleCount)"
<<
std
::
endl
;
for
(
itPoly
=
polySize
.
begin
()
;
itPoly
!=
polySize
.
end
()
;
++
itPoly
)
{
ofs
<<
itPoly
->
first
<<
" : "
<<
itPoly
->
second
<<
std
::
endl
;
}
filter
->
SetLayerIndex
(
2
);
filter
->
Update
();
ofs
<<
"# Layer 2 : points"
<<
std
::
endl
;
ofs
<<
"# Class statistics ( label : sampleCount)"
<<
std
::
endl
;
for
(
itClass
=
classCount
.
begin
();
itClass
!=
classCount
.
end
()
;
++
itClass
)
{
ofs
<<
itClass
->
first
<<
" : "
<<
itClass
->
second
<<
std
::
endl
;
}
ofs
<<
"# Vector sizes ( featureId : sampleCount)"
<<
std
::
endl
;
for
(
itPoly
=
polySize
.
begin
()
;
itPoly
!=
polySize
.
end
()
;
++
itPoly
)
{
ofs
<<
itPoly
->
first
<<
" : "
<<
itPoly
->
second
<<
std
::
endl
;
}
ofs
.
close
();
return
EXIT_SUCCESS
;
}
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