Commit 8f6e5870 authored by Roland Levillain's avatar Roland Levillain
Browse files

Factor connectivity_numbers_3d and connectivity_numbers_3d_tbb.

	* tools/connectivity_numbers_3d.hh (connectivity_numbers_3d):
	Reindent.
	(connectivity_number_3d__6_26_one)
	(connectivity_number_3d__6p_18_one)
	(connectivity_number_3d__18_6p_one):
	Fix types: s/config_3d_t/conn_number_t/.
	(usage): New function.
	(display_connectivity_numbers): New function.
	Use it to simplify...
	* tools/connectivity_numbers_3d.cc,
	* tools/connectivity_numbers_3d_tbb.cc (main): ...these functions.
	(usage): Remove.
	* tools/compute_local_configurations.cc,
	* tools/connectivity_numbers_3d_tbb.hh:
	Add a comment.
parent dcb65af6
2011-05-31 Roland Levillain <roland@lrde.epita.fr>
Factor connectivity_numbers_3d and connectivity_numbers_3d_tbb.
* tools/connectivity_numbers_3d.hh (connectivity_numbers_3d):
Reindent.
(connectivity_number_3d__6_26_one)
(connectivity_number_3d__6p_18_one)
(connectivity_number_3d__18_6p_one):
Fix types: s/config_3d_t/conn_number_t/.
(usage): New function.
(display_connectivity_numbers): New function.
Use it to simplify...
* tools/connectivity_numbers_3d.cc,
* tools/connectivity_numbers_3d_tbb.cc (main): ...these functions.
(usage): Remove.
* tools/compute_local_configurations.cc,
* tools/connectivity_numbers_3d_tbb.hh:
Add a comment.
2011-05-25 Roland Levillain <roland@lrde.epita.fr>
 
Add a parallel version of connectivity_numbers_3d using TBB.
......@@ -54,6 +54,10 @@ int main()
for (unsigned i = 0; i < 256; i++)
{
/* Create the local i-th configuration around P.
Note that the value corresponding to P is always `false', to
prevent the connection of two components through P. */
data::fill(ima, false);
int_u8 tmp = i;
......
......@@ -28,19 +28,6 @@
#include "connectivity_numbers_3d.hh"
void
usage(const std::string& program)
{
std::cerr <<
"usage: " << program << " <nbhs>" << std::endl <<
"where <nbhs> is one of these values:\n\n"
" `6_26' : 6-c foreground, 26-c background\n"
" `26_6' : 26-c foreground, 6-c background\n"
" `6p_18' : 6+-c foreground, 18-c background\n"
" `18_6p' : 18-c foreground, 6+-c background\n" << std::endl;
std::exit(1);
}
int main(int argc, char* argv[])
{
if (argc != 2)
......@@ -55,12 +42,5 @@ int main(int argc, char* argv[])
else
usage(argv[0]);
// Display numbers.
for (size_t i = 0; i < conn_numbers.size(); ++i)
{
std::cout << std::setw(2) << conn_numbers[i] << ", ";
if (! ((i + 1) % 4)) std::cout << " ";
if (! ((i + 1) % 16)) std::cout << std::endl;
if (! ((i + 1) % 64)) std::cout << std::endl;
}
display_connectivity_numbers(conn_numbers);
}
......@@ -217,19 +217,22 @@ connectivity_numbers_3d(F f)
N nbh = c26();
for (config_3d_t i = 0; i < nconfigs; ++i)
{
// Create the local i-th configuration around P.
data::fill(ima, false);
config_3d_t tmp = i;
mln_fwd_niter_(N) n(nbh, p);
for_all(n)
{
if (tmp % 2)
ima(n) = true;
tmp = tmp >> 1;
/* Create the local i-th configuration around P.
Note that the value corresponding to P is always `false', to
prevent the connection of two components through P. */
data::fill(ima, false);
config_3d_t tmp = i;
mln_fwd_niter_(N) n(nbh, p);
for_all(n)
{
if (tmp % 2)
ima(n) = true;
tmp = tmp >> 1;
}
numbers[i] = f(ima);
}
numbers[i] = f(ima);
}
return numbers;
}
......@@ -255,11 +258,11 @@ connectivity_number_3d__6_26_one(const mln::image3d<bool>& ima)
// thread-unsafe accesses to this neighborhood (see the long
// explanation above).
mln::neighb3d nbh = c6();
config_3d_t unused_nl;
conn_number_t unused_nl;
// Restrict the image to the 18-c neighborhood of P.
image_if<image3d<config_3d_t>, within_c18> lab =
image_if<image3d<conn_number_t>, within_c18> lab =
labeling::blobs(ima | within_c18(), nbh, unused_nl);
std::set<config_3d_t> s;
std::set<conn_number_t> s;
mln_niter_(N) n(nbh, p);
for_all(n)
if (lab(n) != 0)
......@@ -318,9 +321,9 @@ connectivity_number_3d__6p_18_one(const mln::image3d<bool>& ima)
// thread-unsafe accesses to this neighborhood (see the long
// explanation above).
mln::neighb3d nbh = c6();
config_3d_t unused_nl;
image3d<config_3d_t> lab = labeling::blobs(ima, nbh, unused_nl);
std::set<config_3d_t> s;
conn_number_t unused_nl;
image3d<conn_number_t> lab = labeling::blobs(ima, nbh, unused_nl);
std::set<conn_number_t> s;
mln_niter_(N) n(nbh, p);
for_all(n)
if (lab(n) != 0)
......@@ -353,9 +356,9 @@ connectivity_number_3d__18_6p_one(const mln::image3d<bool>& ima)
// thread-unsafe accesses to this neighborhood (see the long
// explanation above).
mln::neighb3d nbh = c18();
config_3d_t unused_nl;
image3d<config_3d_t> lab = labeling::blobs(ima, nbh, unused_nl);
std::set<config_3d_t> s;
conn_number_t unused_nl;
image3d<conn_number_t> lab = labeling::blobs(ima, nbh, unused_nl);
std::set<conn_number_t> s;
mln_niter_(N) n(nbh, p);
for_all(n)
if (lab(n) != 0)
......@@ -369,4 +372,34 @@ connectivity_numbers_3d__18_6p()
return connectivity_numbers_3d(connectivity_number_3d__18_6p_one);
}
/*----------------------.
| Helpers for drivers. |
`----------------------*/
void
usage(const std::string& program)
{
std::cerr <<
"usage: " << program << " <nbhs>" << std::endl <<
"where <nbhs> is one of these values:\n\n"
" `6_26' : 6-c foreground, 26-c background\n"
" `26_6' : 26-c foreground, 6-c background\n"
" `6p_18' : 6+-c foreground, 18-c background\n"
" `18_6p' : 18-c foreground, 6+-c background\n" << std::endl;
std::exit(1);
}
void
display_connectivity_numbers(const conn_numbers_t& conn_numbers)
{
for (size_t i = 0; i < conn_numbers.size(); ++i)
{
std::cout << std::setw(2) << conn_numbers[i] << ", ";
if (! ((i + 1) % 4)) std::cout << " ";
if (! ((i + 1) % 16)) std::cout << std::endl;
if (! ((i + 1) % 64)) std::cout << std::endl;
}
}
#endif // ! TOOLS_CONNECTIVITY_NUMBERS_3D_HH
......@@ -23,24 +23,13 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
/// \brief Compute 3D connectivity numbers.
/// \brief Compute 3D connectivity numbers in parallel, using Intel
/// Threading Building Blocks.
#include "connectivity_numbers_3d_tbb.hh"
void
usage(const std::string& program)
{
std::cerr <<
"usage: " << program << " <nbhs>" << std::endl <<
"where <nbhs> is one of these values:\n\n"
" `6_26' : 6-c foreground, 26-c background\n"
" `26_6' : 26-c foreground, 6-c background\n"
" `6p_18' : 6+-c foreground, 18-c background\n"
" `18_6p' : 18-c foreground, 6+-c background\n" << std::endl;
std::exit(1);
}
int main(int argc, char* argv[])
int
main(int argc, char* argv[])
{
if (argc != 2)
usage(argv[0]);
......@@ -54,12 +43,5 @@ int main(int argc, char* argv[])
else
usage(argv[0]);
// Display numbers.
for (size_t i = 0; i < conn_numbers.size(); ++i)
{
std::cout << std::setw(2) << conn_numbers[i] << ", ";
if (! ((i + 1) % 4)) std::cout << " ";
if (! ((i + 1) % 16)) std::cout << std::endl;
if (! ((i + 1) % 64)) std::cout << std::endl;
}
display_connectivity_numbers(conn_numbers);
}
......@@ -69,7 +69,10 @@ struct connectivity_numbers_3d_tbb_range
for (config_3d_t i = r.begin(); i != r.end(); ++i)
{
// Create the local i-th configuration around P.
/* Create the local i-th configuration around P.
Note that the value corresponding to P is always `false',
to prevent the connection of two components through P. */
data::fill(ima, false);
config_3d_t tmp = i;
mln_fwd_niter_(N) n(nbh_, p);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment