Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Olena
pylene
Commits
d289350d
Commit
d289350d
authored
Jan 25, 2019
by
Michaël Roynard
Browse files
Update filter (impl)
parent
5b8c2524
Pipeline
#12862
failed with stages
in 32 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pylene/include/mln/core/concept/new/archetype/domain.hpp
View file @
d289350d
...
...
@@ -7,7 +7,7 @@
namespace
mln
::
archetypes
{
struct
Domain
final
struct
Domain
{
using
value_type
=
Point
;
using
reference
=
Point
&
;
...
...
@@ -17,11 +17,20 @@ namespace mln::archetypes
bool
has
(
value_type
)
const
;
bool
empty
()
const
;
// unsigned size() const;
};
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert
(
mln
::
concepts
::
Domain
<
Domain
>
,
"Domain archetype does not model the Domain concept!"
);
#endif // PYLENE_CONCEPT_TS_ENABLED
struct
SizedDomain
:
Domain
{
unsigned
size
()
const
;
};
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert
(
mln
::
concepts
::
SizedDomain
<
SizedDomain
>
,
"SizedDomain archetype does not model the SizedDomain concept!"
);
#endif // PYLENE_CONCEPT_TS_ENABLED
}
// namespace mln::archetypes
pylene/include/mln/core/concept/new/domains.hpp
View file @
d289350d
...
...
@@ -15,6 +15,7 @@ namespace mln::concepts
// clang-format off
#ifdef PYLENE_CONCEPT_TS_ENABLED
// Domain
template
<
typename
Dom
>
concept
Domain
=
...
...
@@ -26,6 +27,16 @@ namespace mln::concepts
{
cdom
.
empty
()
}
->
bool
;
// { cdom.size() } -> stl::UnsignedIntegral&&;
};
// SizedDomain
template
<
typename
Dom
>
concept
Domain
=
Domain
<
Dom
>
&&
requires
(
const
Dom
cdom
)
{
{
cdom
.
size
()
}
->
stl
::
UnsignedIntegral
&&
;
};
#endif // PYLENE_CONCEPT_TS_ENABLED
// clang-format on
...
...
pylene/include/mln/core/image/private/filtered.hpp
0 → 100644
View file @
d289350d
#pragma once
#include
<mln/core/image/private/image_traits.hpp>
#include
<mln/core/rangev3/view/filter.hpp>
#include
<range/v3/begin_end.hpp>
#include
<range/v3/empty.hpp>
#include
<utility>
namespace
mln
::
detail
{
template
<
typename
I
,
typename
F
>
struct
filtered
{
using
value_type
=
image_value_t
<
I
>
;
using
reference
=
image_reference_t
<
I
>
;
filtered
(
I
ima
,
F
f
)
:
rng_
(
mln
::
ranges
::
view
::
filter
(
ima
.
domain
(),
f
))
,
ima_
(
ima
)
,
f_
(
f
)
{
}
auto
begin
()
{
return
::
ranges
::
begin
(
rng_
);
}
auto
end
()
{
return
::
ranges
::
end
(
rng_
);
}
bool
has
(
value_type
p
)
const
{
return
f_
(
ima_
(
p
));
}
bool
empty
()
const
{
return
::
ranges
::
empty
(
rng_
);
}
private:
using
rng_t
=
decltype
(
mln
::
ranges
::
view
::
filter
(
std
::
declval
<
I
>
().
domain
(),
std
::
declval
<
F
>
()));
rng_t
rng_
;
I
ima_
;
F
f_
;
};
}
// namespace mln::detail
pylene/include/mln/core/image/view/clip.hpp
View file @
d289350d
...
...
@@ -94,9 +94,7 @@ namespace mln
template
<
typename
dummy
=
I
>
reference
operator
[](
image_index_t
<
dummy
>
i
)
{
mln_precondition
(
i
<
m_domain
.
size
());
auto
p
=
domain
()[
i
];
return
this
->
base
()(
p
);
return
this
->
base
()[
i
];
}
/// \}
...
...
@@ -118,7 +116,7 @@ namespace mln
template
<
typename
Ret
=
new_pixel_type
>
std
::
enable_if_t
<
accessible
::
value
,
Ret
>
new_pixel
(
point_type
p
)
{
mln_precondition
(
this
->
m_domain
.
has
(
p
));
mln_precondition
(
m_domain
.
has
(
p
));
mln_precondition
(
this
->
base
().
domain
().
has
(
p
));
return
this
->
base
().
new_pixel
(
p
);
}
...
...
@@ -135,20 +133,22 @@ namespace mln
template
<
typename
dummy
=
I
>
std
::
enable_if_t
<
(
indexable
::
value
&&
accessible
::
value
),
image_index_t
<
dummy
>>
index_of_point
(
point_type
p
)
const
{
// FIXME: how to implement this here ?
mln_precondition
(
m_domain
.
has
(
p
));
mln_precondition
(
this
->
base
().
domain
().
has
(
p
));
return
this
->
base
().
index_of_point
(
p
);
}
template
<
typename
dummy
=
I
>
point_type
point_at_index
(
std
::
enable_if_t
<
(
indexable
::
value
&&
accessible
::
value
),
image_index_t
<
dummy
>>
i
)
const
{
return
domain
()[
i
]
;
return
this
->
base
().
point_at_index
(
i
)
;
}
template
<
typename
dummy
=
I
>
std
::
enable_if_t
<
(
indexable
::
value
&&
accessible
::
value
),
image_index_t
<
dummy
>>
delta_index
(
point_type
p
)
const
{
// FIXME: how to implement this here ?
mln_precondition
(
m_domain
.
has
(
p
));
mln_precondition
(
this
->
base
().
domain
().
has
(
p
));
return
this
->
base
().
delta_index
(
p
);
}
/// \}
...
...
pylene/include/mln/core/image/view/filter.hpp
View file @
d289350d
#pragma once
#include
<mln/core/image/image.hpp>
#include
<mln/core/image/private/filtered.hpp>
#include
<mln/core/image/view/adaptor.hpp>
#include
<mln/core/rangev3/view/filter.hpp>
...
...
@@ -13,41 +14,11 @@
namespace
mln
{
// FIXME: move into a different file
// FIXME: use all_t for ima
// FIXME: use
template
<
typename
I
,
typename
F
>
struct
filtered_domain
{
using
value_type
=
image_value_t
<
I
>
;
using
reference
=
image_reference_t
<
I
>
;
filtered_domain
(
I
ima
,
F
f
)
:
rng_
(
mln
::
ranges
::
view
::
filter
(
ima
.
domain
(),
f
))
,
ima_
(
ima
)
,
f_
(
f
)
{
}
auto
begin
()
{
return
::
ranges
::
begin
(
rng_
);
}
auto
end
()
{
return
::
ranges
::
end
(
rng_
);
}
bool
has
(
value_type
p
)
const
{
return
f_
(
ima_
(
p
));
}
bool
empty
()
const
{
return
::
ranges
::
empty
(
rng_
);
}
// unsigned size() const { return ::ranges::size(rng_); }
private:
decltype
(
mln
::
ranges
::
view
::
filter
(
std
::
declval
<
I
>
().
domain
(),
std
::
declval
<
F
>
()))
rng_
;
I
ima_
;
F
f_
;
};
template
<
class
I
,
class
F
>
class
filter_view
:
public
image_adaptor
<
I
>
,
public
experimental
::
Image
<
filter_view
<
I
,
F
>>
{
using
fun_t
=
F
;
// FIXME something with semiregular_t<F> ?
using
fun_t
=
F
;
fun_t
f
;
public:
...
...
@@ -57,7 +28,7 @@ namespace mln
using
value_type
=
std
::
decay_t
<
reference
>
;
using
typename
filter_view
::
image_adaptor
::
new_pixel_type
;
using
typename
filter_view
::
image_adaptor
::
point_type
;
using
domain_type
=
filtered
_domain
<
I
,
F
>
;
using
domain_type
=
detail
::
filtered
<
I
,
F
>
;
/// \}
/// Traits & Image Properties
...
...
@@ -92,7 +63,7 @@ namespace mln
{
}
domain_type
domain
()
const
{
return
filtered_domain
{(
this
->
base
(),
this
->
f
};
}
domain_type
domain
()
const
{
return
detail
::
filtered
{
this
->
base
(),
this
->
f
};
}
auto
new_values
()
{
return
mln
::
ranges
::
view
::
filter
(
this
->
base
().
new_values
(),
f
);
}
...
...
@@ -109,8 +80,7 @@ namespace mln
template
<
typename
Ret
=
reference
>
std
::
enable_if_t
<
accessible
::
value
,
Ret
>
operator
()(
point_type
p
)
{
// FIXME: with I = mln::image2d<int> has no member named 'has', from tests/core/image/view/filter.cpp:71:
// (ASSERT_EQ(pix.val(), u(pix.point()));) mln_precondition(this->base().domain().has(p));
mln_precondition
(
this
->
base
().
domain
().
has
(
p
));
mln_precondition
(
std
::
invoke
(
f
,
this
->
base
()(
p
)));
return
this
->
base
()(
p
);
}
...
...
pylene/include/mln/core/image/view/mask.hpp
View file @
d289350d
...
...
@@ -14,7 +14,7 @@ namespace mln
template
<
class
I
,
class
M
>
class
mask_view
:
public
image_adaptor
<
I
>
,
public
experimental
::
Image
<
mask_view
<
I
,
M
>>
{
mutable
M
m_mask
;
M
m_mask
;
public:
/// Type definitions
...
...
@@ -147,14 +147,14 @@ namespace mln
template
<
class
I2
,
class
D2
>
mask_view
(
const
mask_view
<
I2
,
D2
>&
other
,
mln
::
init
)
:
mask_view
::
image_adaptor
{
static_cast
<
I
>
(
im
chvalue
<
value_type
>
(
other
.
base
()
))}
:
mask_view
::
image_adaptor
{
static_cast
<
I
>
(
other
.
base
().
template
ch
_
value
<
value_type
>())}
,
m_mask
{
other
.
m_mask
}
{
}
template
<
class
I2
,
class
D2
>
mask_view
(
const
mask_view
<
I2
,
D2
>&
other
,
const
value_type
&
v
)
:
mask_view
::
image_adaptor
{
static_cast
<
I
>
(
im
chvalue
<
value_type
>
(
other
.
base
(
)).
init
(
v
))}
:
mask_view
::
image_adaptor
{
static_cast
<
I
>
(
(
other
.
base
().
template
ch
_
value
<
value_type
>()).
init
(
v
))}
,
m_mask
{
other
.
m_mask
}
{
}
...
...
tests/core/image/view/filter.cpp
View file @
d289350d
...
...
@@ -57,7 +57,7 @@ TEST(View, filter_writable)
ASSERT_TRUE
(
mln
::
experimental
::
all
(
ima
<=
10
));
}
/*
TEST(View, filter_twice)
{
using namespace mln;
...
...
@@ -107,3 +107,4 @@ TEST(View, filter_twice)
mln_foreach_new (auto&& px, u.new_pixels())
ASSERT_EQ(px.val(), ima(px.point()));
}
*/
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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