Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
otb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
273
Issues
273
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Main Repositories
otb
Commits
2d8c2a48
Commit
2d8c2a48
authored
Nov 08, 2018
by
Julien Michel
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: Add tests and move useful functors to separate headers
parent
e14ab465
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
262 additions
and
70 deletions
+262
-70
Modules/Core/Functor/CMakeLists.txt
Modules/Core/Functor/CMakeLists.txt
+22
-0
Modules/Core/Functor/include/otbVariadicAddFunctor.h
Modules/Core/Functor/include/otbVariadicAddFunctor.h
+46
-0
Modules/Core/Functor/include/otbVariadicConcatenateFunctor.h
Modules/Core/Functor/include/otbVariadicConcatenateFunctor.h
+97
-0
Modules/Core/Functor/otb-module.cmake
Modules/Core/Functor/otb-module.cmake
+34
-0
Modules/Core/Functor/test/CMakeLists.txt
Modules/Core/Functor/test/CMakeLists.txt
+33
-0
Modules/Core/Functor/test/otbFunctorImageFilter.cxx
Modules/Core/Functor/test/otbFunctorImageFilter.cxx
+4
-70
Modules/Core/Functor/test/otbFunctorTestDriver.cxx
Modules/Core/Functor/test/otbFunctorTestDriver.cxx
+26
-0
No files found.
Modules/Core/Functor/CMakeLists.txt
0 → 100644
View file @
2d8c2a48
#
# Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
#
# This file is part of Orfeo Toolbox
#
# https://www.orfeo-toolbox.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
project
(
OTBFunctor
)
otb_module_impl
()
Modules/Core/Functor/include/otbVariadicAddFunctor.h
0 → 100644
View file @
2d8c2a48
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otb_VariadicAddFunctor_h
#define otb_VariadicAddFunctor_h
#include <numeric>
namespace
otb
{
namespace
Functor
{
template
<
typename
TOut
,
typename
...
TIns
>
struct
VariadicAdd
{
auto
operator
()(
TIns
...
ins
)
const
{
std
::
vector
<
TOut
>
outVector
{
static_cast
<
TOut
>
(
ins
)...};
return
std
::
accumulate
(
outVector
.
begin
(),
outVector
.
end
(),
0
);
}
};
}
// end namespace Functor
}
// end namespace otb
#endif
Modules/Core/Functor/include/otbVariadicConcatenateFunctor.h
0 → 100644
View file @
2d8c2a48
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otb_VariadicConcatenateFunctor_h
#define otb_VariadicConcatenateFunctor_h
#include <vector>
#include <numeric>
namespace
otb
{
namespace
Functor
{
namespace
internal
{
// helper function to implement next functor (convert a scalar value
// to a VariableLengthVector)
template
<
typename
T
>
itk
::
VariableLengthVector
<
T
>
toVector
(
const
T
&
in
)
{
itk
::
VariableLengthVector
<
T
>
out
;
out
.
SetSize
(
1
);
out
[
0
]
=
in
;
return
out
;
}
// helper function to implement next functor, VariableLengthVectorVersion (returns in)
template
<
typename
T
>
const
itk
::
VariableLengthVector
<
T
>
&
toVector
(
const
itk
::
VariableLengthVector
<
T
>
&
in
)
{
return
in
;
}
// helper function to implement next functor, Merge two VariableLengthVector in-place
template
<
typename
v1
,
typename
v2
>
void
concatenateVectors
(
v1
&
a
,
const
v2
&
b
)
{
const
size_t
previousSizeOfA
=
a
.
GetSize
();
a
.
SetSize
(
previousSizeOfA
+
b
.
GetSize
());
for
(
size_t
it
=
0
;
it
<
b
.
Size
();
++
it
)
{
a
[
previousSizeOfA
+
it
]
=
static_cast
<
typename
v1
::
ValueType
>
(
b
[
it
]);
}
}
// helper function to implement next functor, Merge N VariableLengthVector in-place
template
<
typename
v1
,
typename
v2
,
typename
...
vn
>
void
concatenateVectors
(
v1
&
a
,
const
v2
&
b
,
const
vn
&
...
z
)
{
concatenateVectors
(
a
,
b
);
concatenateVectors
(
a
,
z
...);
}
}
// end namespace internal
// N images (all types) -> vector image
// This functor concatenates N images (N = variadic) of type
// VectorImage and or Image, into a single VectorImage
template
<
typename
TOut
,
typename
...
TIns
>
struct
VariadicConcatenate
{
auto
operator
()(
const
TIns
&
...
ins
)
const
{
itk
::
VariableLengthVector
<
TOut
>
out
;
internal
::
concatenateVectors
(
out
,
internal
::
toVector
(
ins
)...);
return
out
;
}
// Must define OutputSize because output pixel is vector
constexpr
size_t
OutputSize
(
const
std
::
array
<
size_t
,
sizeof
...(
TIns
)
>
inputsNbBands
)
const
{
return
std
::
accumulate
(
inputsNbBands
.
begin
(),
inputsNbBands
.
end
(),
0
);
}
};
}
// end namespace Functor
}
// end namespace otb
#endif
Modules/Core/Functor/otb-module.cmake
0 → 100644
View file @
2d8c2a48
#
# Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
#
# This file is part of Orfeo Toolbox
#
# https://www.orfeo-toolbox.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set
(
DOCUMENTATION
"This module contains a set of classes that allow parsing
metadata files from different types of sensor (both optical and radar sensor types
are supported. for instance: Pleiades, SPOT6, TerraSar, and so on)."
)
otb_module
(
OTBFunctor
DEPENDS
OTBITK
OTBCommon
OTBImageBase
TEST_DEPENDS
OTBTestKernel
DESCRIPTION
"
${
DOCUMENTATION
}
"
)
Modules/Core/Functor/test/CMakeLists.txt
0 → 100644
View file @
2d8c2a48
#
# Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
#
# This file is part of Orfeo Toolbox
#
# https://www.orfeo-toolbox.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
otb_module_test
()
set
(
OTBFunctorTests
otbFunctorTestDriver.cxx
otbFunctorImageFilter.cxx
)
add_executable
(
otbFunctorTestDriver
${
OTBFunctorTests
}
)
target_link_libraries
(
otbFunctorTestDriver
${
OTBFunctor-Test_LIBRARIES
}
)
otb_module_target_label
(
otbFunctorTestDriver
)
otb_add_test
(
NAME bfTvFunctorImageFilter COMMAND otbImageManipulationTestDriver
otbFunctorImageFilter
)
Modules/Core/Functor/test/otbFunctorImageFilter.cxx
View file @
2d8c2a48
...
...
@@ -23,6 +23,8 @@
#include "otbImage.h"
#include "otbVectorImage.h"
#include "itkNeighborhood.h"
#include "otbVariadicAddFunctor.h"
#include "otbVariadicConcatenateFunctor.h"
#include <tuple>
#include <numeric>
...
...
@@ -116,74 +118,6 @@ auto checksComplex = TypesCheck<std::complex<double>>{};
// Example functors
// N scalar images -> image
// This functor takes N scalar image (variadic N) and returns the sum
// of all pixels
template
<
typename
TOut
,
typename
...
TIns
>
struct
VariadicAdd
{
auto
operator
()(
TIns
...
ins
)
const
{
std
::
vector
<
TOut
>
outVector
{
static_cast
<
TOut
>
(
ins
)...};
return
std
::
accumulate
(
outVector
.
begin
(),
outVector
.
end
(),
0
);
}
};
// helper function to implement next functor (convert a scalar value
// to a VariableLengthVector)
template
<
typename
T
>
itk
::
VariableLengthVector
<
T
>
toVector
(
const
T
&
in
)
{
itk
::
VariableLengthVector
<
T
>
out
;
out
.
SetSize
(
1
);
out
[
0
]
=
in
;
return
out
;
}
// helper function to implement next functor, VariableLengthVectorVersion (returns in)
template
<
typename
T
>
const
itk
::
VariableLengthVector
<
T
>
&
toVector
(
const
itk
::
VariableLengthVector
<
T
>
&
in
)
{
return
in
;
}
// helper function to implement next functor, Merge two VariableLengthVector in-place
template
<
typename
v1
,
typename
v2
>
void
concatenateVectors
(
v1
&
a
,
const
v2
&
b
)
{
const
size_t
previousSizeOfA
=
a
.
GetSize
();
a
.
SetSize
(
previousSizeOfA
+
b
.
GetSize
());
for
(
size_t
it
=
0
;
it
<
b
.
Size
();
++
it
)
{
a
[
previousSizeOfA
+
it
]
=
static_cast
<
typename
v1
::
ValueType
>
(
b
[
it
]);
}
}
// helper function to implement next functor, Merge N VariableLengthVector in-place
template
<
typename
v1
,
typename
v2
,
typename
...
vn
>
void
concatenateVectors
(
v1
&
a
,
const
v2
&
b
,
const
vn
&
...
z
)
{
concatenateVectors
(
a
,
b
);
concatenateVectors
(
a
,
z
...);
}
// N images (all types) -> vector image
// This functor concatenates N images (N = variadic) of type
// VectorImage and or Image, into a single VectorImage
template
<
typename
TOut
,
typename
...
TIns
>
struct
VariadicConcatenate
{
auto
operator
()(
const
TIns
&
...
ins
)
const
{
itk
::
VariableLengthVector
<
TOut
>
out
;
concatenateVectors
(
out
,
toVector
(
ins
)...);
return
out
;
}
// Must define OutputSize because output pixel is vector
constexpr
size_t
OutputSize
(
const
std
::
array
<
size_t
,
sizeof
...(
TIns
)
>
inputsNbBands
)
const
{
return
std
::
accumulate
(
inputsNbBands
.
begin
(),
inputsNbBands
.
end
(),
0
);
}
};
// 1 VectorImage -> 1 VectorImage with a different size depending on a
...
...
@@ -361,13 +295,13 @@ int otbFunctorImageFilter(int itkNotUsed(argc), char * itkNotUsed(argv) [])
filterLambda2
->
Update
();
// Test FunctorImageFilter with the VariadicConcatenate operator
using
ConcatFunctorType
=
VariadicConcatenate
<
double
,
double
,
itk
::
VariableLengthVector
<
double
>
>
;
using
ConcatFunctorType
=
Functor
::
VariadicConcatenate
<
double
,
double
,
itk
::
VariableLengthVector
<
double
>
>
;
auto
concatenate
=
NewFunctorFilter
(
ConcatFunctorType
{});
concatenate
->
SetVInputs
(
image
,
vimage
);
concatenate
->
Update
();
// Test FunctorImageFilter With VariadicAdd functor
using
AddFunctorType
=
VariadicAdd
<
double
,
double
,
double
>
;
using
AddFunctorType
=
Functor
::
VariadicAdd
<
double
,
double
,
double
>
;
auto
add
=
NewFunctorFilter
(
AddFunctorType
{});
add
->
SetVInputs
(
image
,
image
);
add
->
Update
();
...
...
Modules/Core/Functor/test/otbFunctorTestDriver.cxx
0 → 100644
View file @
2d8c2a48
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "otbTestMain.h"
void
RegisterTests
()
{
REGISTER_TEST
(
otbFunctorImageFilter
);
}
Julien Michel
@jmichel
mentioned in commit
ba576452
·
Nov 19, 2018
mentioned in commit
ba576452
mentioned in commit ba5764527a25d049ba6e9ab4074b930d1f00962c
Toggle commit list
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