Commit 176f3fd8 authored by Roland Levillain's avatar Roland Levillain
Browse files

Sequential computation of simple 3D points look-up tables.

	* tools/simple_point_3d_lut.hh,
	* tools/simple_point_3d_lut.cc:
	New.
	* tools/Makefile.am (noinst_HEADERS): Add simple_point_3d_lut.hh.
	(EXTRA_PROGRAMS): Add simple_point_3d_lut.
	(simple_point_3d_lut_SOURCES): New.
parent 5f10622a
2011-05-31 Roland Levillain <roland@lrde.epita.fr>
Sequential computation of simple 3D points look-up tables.
* tools/simple_point_3d_lut.hh,
* tools/simple_point_3d_lut.cc:
New.
* tools/Makefile.am (noinst_HEADERS): Add simple_point_3d_lut.hh.
(EXTRA_PROGRAMS): Add simple_point_3d_lut.
(simple_point_3d_lut_SOURCES): New.
2013-08-28 Roland Levillain <roland@lrde.epita.fr>
 
Improve mln::topo::is_simple_2d_t.
......@@ -22,12 +22,12 @@ bin_PROGRAMS = \
seed2tiling \
area_flooding
# FIXME: Rename this program.
noinst_PROGRAMS = compute_local_configurations
noinst_HEADERS = connectivity_numbers_3d.hh
noinst_PROGRAMS += connectivity_numbers_3d
connectivity_numbers_3d_SOURCES = \
connectivity_numbers_3d.hh \
connectivity_numbers_3d.cc
connectivity_numbers_3d_SOURCES = connectivity_numbers_3d.cc
# FIXME: Hard-coded paths.
......@@ -37,10 +37,12 @@ LDFLAGS_TBB = -L/opt/local/lib -ltbb
.PHONY: extra
extra: $(EXTRA_PROGRAMS)
noinst_HEADERS += connectivity_numbers_3d_tbb.hh
EXTRA_PROGRAMS = connectivity_numbers_3d_tbb
connectivity_numbers_3d_tbb_SOURCES = \
connectivity_numbers_3d.hh \
connectivity_numbers_3d_tbb.hh \
connectivity_numbers_3d_tbb.cc
connectivity_numbers_3d_tbb_SOURCES = connectivity_numbers_3d_tbb.cc
connectivity_numbers_3d_tbb_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS_TBB)
connectivity_numbers_3d_tbb_LDFLAGS = $(LDFLAGS_TBB)
noinst_HEADERS += simple_point_3d_lut.hh
EXTRA_PROGRAMS += simple_point_3d_lut
simple_point_3d_lut_SOURCES = simple_point_3d_lut.cc
// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
/// \brief Compute a compressed look-up table (LUT) showing whether a
/// 3D point is simple or not.
#include "simple_point_3d_lut.hh"
int
main(int argc, char* argv[])
{
if (argc != 2)
usage(argv[0]);
std::string nbhs = argv[1];
simple_point_lut_t simple_point_lut;
if (nbhs == "6_26") simple_point_lut = simple_point_3d_lut__6_26();
else if (nbhs == "26_6") simple_point_lut = simple_point_3d_lut__26_6();
else if (nbhs == "6p_18") simple_point_lut = simple_point_3d_lut__6p_18();
else if (nbhs == "18_6p") simple_point_lut = simple_point_3d_lut__18_6p();
else
usage(argv[0]);
// Display the compressed (8-bit packs) LUT.
display_simple_point_lut(simple_point_lut);
}
// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
/// \brief Elements to compute a look-up table (LUT) showing whether a
/// 3D point is simple or not.
#ifndef TOOLS_SIMPLE_POINT_3D_LUT_HH
# define TOOLS_SIMPLE_POINT_3D_LUT_HH
#include "connectivity_numbers_3d.hh"
/// Type of the look-up table (LUT).
typedef std::vector<bool> simple_point_lut_t;
/*------------------------------------------------------------------.
| Sequential computation of a look-up table (LUT) showing whether a |
| 3D point is simple or not. |
`------------------------------------------------------------------*/
/// Canevas to compute a look-up table (LUT) showing whether a 3D
/// point is simple or not.
///
/// \param fg_fun A function computing the connectivity number for
/// each configuration (as a 3x3x3 3D image) of the
/// foreground.
/// \param bg_fun A function computing the connectivity number for
/// each configuration (as a 3x3x3 3D image) of the
/// background.
template <typename FG, typename BG>
simple_point_lut_t
simple_point_3d_lut(FG fg_fun, BG bg_fun)
{
using namespace mln;
typedef image3d<bool> I;
// B must be a model of mln::Box.
typedef mln_domain(I) B;
typedef mln_psite(I) P;
B b = make::box3d(-1,-1,-1, 1,1,1);
I fg_ima(b, 0);
I bg_ima(b, 0);
P p(0, 0, 0);
const unsigned dim = 3;
const unsigned max_nneighbs = mlc_pow_int(3, dim) - 1;
const unsigned nconfigs = mlc_pow_int(2, max_nneighbs);
simple_point_lut_t simple_point_lut(nconfigs, false);
typedef neighb3d N;
N nbh = c26();
for (config_3d_t i = 0; i < nconfigs; ++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(fg_ima, false);
data::fill(bg_ima, false);
config_3d_t tmp = i;
mln_fwd_niter_(N) n(nbh, p);
for_all(n)
{
if (tmp % 2)
fg_ima(n) = true;
else
bg_ima(n) = true;
tmp = tmp >> 1;
}
simple_point_lut[i] = ( fg_fun(fg_ima) == 1
&& bg_fun(bg_ima) == 1);
}
return simple_point_lut;
}
/*-------------------------------------------------------------.
| (6, 26) configurations: 6-connected foreground, 26-connected |
| background. |
`-------------------------------------------------------------*/
simple_point_lut_t
simple_point_3d_lut__6_26()
{
return simple_point_3d_lut(connectivity_number_3d__6_26_one,
connectivity_number_3d__26_6_one);
}
/*-------------------------------------------------------------.
| (26, 6) configurations: 26-connected foreground, 6-connected |
| background. |
`-------------------------------------------------------------*/
simple_point_lut_t
simple_point_3d_lut__26_6()
{
return simple_point_3d_lut(connectivity_number_3d__26_6_one,
connectivity_number_3d__6_26_one);
}
/*---------------------------------------------------------------.
| (6+, 18) configurations: 6+-connected foreground, 18-connected |
| background. |
`---------------------------------------------------------------*/
simple_point_lut_t
simple_point_3d_lut__6p_18()
{
return simple_point_3d_lut(connectivity_number_3d__6p_18_one,
connectivity_number_3d__18_6p_one);
}
/*---------------------------------------------------------------.
| (18, 6+) configurations: 18-connected foreground, 6+-connected |
| background. |
`---------------------------------------------------------------*/
simple_point_lut_t
simple_point_3d_lut__18_6p()
{
return simple_point_3d_lut(connectivity_number_3d__18_6p_one,
connectivity_number_3d__6p_18_one);
}
/*----------------------.
| Helpers for drivers. |
`----------------------*/
void
display_simple_point_lut(const simple_point_lut_t& simple_point_lut)
{
const unsigned bits_per_byte = 8;
// Set up the output format.
std::cout << std::hex << std::setfill ('0');
std::string prefix = "0x";
size_t i = 0;
while (i < simple_point_lut.size())
{
mln::value::int_u8 pack = 0;
mln::value::int_u8 mask = 1;
for (unsigned j = 0; i < simple_point_lut.size() && j < bits_per_byte;
++j, ++i)
{
if (simple_point_lut[i])
pack = pack | mask;
mask = mask << 1;
}
/* Display.
Note that except maybe after for the last iteration of the
outer loop, I is always a multiple of 8. */
std::cout << prefix << std::setw(2) << pack << ", ";
if (i % 64 == 0) std::cout << std::endl;
if (i % 256 == 0) std::cout << std::endl;
}
}
#endif // ! TOOLS_SIMPLE_POINT_3D_LUT_HH
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