1 #ifndef TIL_REGIONGROWING_H 2 #define TIL_REGIONGROWING_H 4 #include <cartobase/config/cartobase_config.h> 54 typedef std::vector<numeric_array<int,3> >
VoxelList;
56 template <
class TExpr,
class TImage >
62 m_im(im), m_expr(expr) {};
68 static bool stop() {
return false; }
78 template <
class PixelTest >
84 typedef typename PixelTest::TImage
TImage;
101 static bool stop() {
return false; }
106 const PixelTest *m_test;
111 template <
class PixelTest,
class Plugin >
116 typedef typename PixelTest::TImage
TImage;
122 m_im.shallowCopy(im);
134 static bool stop() {
return false; }
139 const PixelTest *m_test;
149 template <
class TImage,
class Ghost >
157 typename TImage::value_type newColor
160 if (
contains(seg, pos) && seg(pos) != newColor && ghost.test(pos))
174 template <
class TImage,
class Ghost >
181 typename TImage::value_type newColor
184 if (seg(pos) != newColor && ghost.test(pos))
202 template <
class TImage,
class Ghost >
203 std::unique_ptr<VoxelList>
208 typename TImage::value_type newColor)
210 std::unique_ptr<VoxelList> newVl(
new VoxelList);
212 newVl->reserve(3 * vl.size());
213 VoxelList::const_iterator iVl;
215 std::vector<numeric_array<int,3> >::const_iterator iVnh;
219 for (iVl = vl.begin(); iVl != vl.end(); ++iVl)
221 for (iVnh = vnh.begin(); iVnh != vnh.end(); ++iVnh)
224 neighborCoord = *iVl + *iVnh;
226 _addPoint(*(newVl.get()), seg, neighborCoord, ghost, newColor);
228 if (ghost.stop())
goto endloop;
240 #define ADD_NEIGHBORS2(i,j,k) \ 241 if (nh.template isNeighbor<(i),(j),(k)>() && containsNeighbor<(i),(j),(k)>(iSeg)) \ 243 addTo<(i),(j),(k)>(*iVl, neighborCoord); \ 244 _addPoint2(*(newVl.get()), seg, neighborCoord, ghost, newColor); \ 245 if (ghost.stop()) break; \ 249 template <
class TImage,
class Ghost,
class TNeighborhood >
250 std::unique_ptr<VoxelList>
254 const VoxelList & vl,
255 const TNeighborhood & nh,
257 typename TImage::value_type newColor
260 std::unique_ptr<VoxelList> newVl(
new VoxelList);
262 newVl->reserve(3 * vl.size());
263 VoxelList::const_iterator iVl;
269 for (iVl = vl.begin(); iVl != vl.end(); ++iVl)
271 iSeg.setUnsafePos(*iVl);
310 #undef ADD_NEIGHBORS2 313 template <
class TImage,
class Ghost>
314 std::unique_ptr<VoxelList>
320 typename TImage::value_type newColor
323 catro::unique_ptr<VoxelList> newVl(
new VoxelList);
324 VoxelList::const_iterator iVl;
326 for (iVl = vl.begin(); iVl != vl.end(); ++iVl)
328 _addPoint(*(newVl.get()), seg, *iVl, ghost, newColor);
330 if (ghost.stop())
break;
337 template <
typename TImage,
typename RegionGrowingGhost,
typename TNeighborhood >
341 const VoxelList & seeds,
342 const TNeighborhood & nh,
343 RegionGrowingGhost & ghost,
344 typename TImage::value_type color
348 std::unique_ptr<VoxelList> vl;
359 vl =
addSeeds(seg, seeds, ghost, color);
362 size_t nPoints = vl->size();
364 while (vl->size() > 0 && !ghost.stop())
367 nPoints += vl->size();
376 template <
typename TImage,
typename RegionGrowingGhost >
380 const VoxelList & seeds,
382 RegionGrowingGhost & ghost,
383 typename TImage::value_type color
387 std::unique_ptr<VoxelList> vl;
398 vl =
addSeeds(seg, seeds, ghost, color);
401 std::vector<numeric_array<int,3> > vnh;
406 size_t nPoints = vl->size();
408 while (vl->size() > 0 && !ghost.stop())
411 nPoints += vl->size();
418 template <
typename TImage,
typename RegionGrowingGhost >
424 RegionGrowingGhost & ghost,
425 typename TImage::value_type color
429 seeds.push_back(seed);
A trait class to assign iterators to image types.
RegionGrowingExpr(TImage &im, TExpr expr)
std::unique_ptr< VoxelList > addSeeds(TImage &seg, const VoxelList &vl, Ghost &ghost, typename TImage::value_type newColor)
INLINE void _addPoint2(VoxelList &vl, TImage &seg, const numeric_array< int, 3 > &pos, Ghost &ghost, typename TImage::value_type newColor)
bool test(const numeric_array< int, 3 > &pos) const
static void update(const numeric_array< int, 3 > &pos)
static void update(const numeric_array< int, 3 > &)
PluginGhost(TImage &im, const PixelTest &test, Plugin &plugin)
Belongs to package Box Do not include directly, include til/Box.h instead.
size_t regionGrowing(TImage &seg, const VoxelList &seeds, const Neighborhood &nh, RegionGrowingGhost &ghost, typename TImage::value_type color)
size_t regionGrowing2(TImage &seg, const VoxelList &seeds, const TNeighborhood &nh, RegionGrowingGhost &ghost, typename TImage::value_type color)
#define ADD_NEIGHBORS2(i, j, k)
TIL_API void getNeighbors(const Neighborhood &nh, std::vector< numeric_array< int, 3 > > &res)
Pushes the neighbor coordinates in a container.
General macros, definitions and functions.
SimpleGhost(TImage &im, const PixelTest &test)
bool test(const numeric_array< int, 3 > &pos) const
std::unique_ptr< VoxelList > addNeighbors(TImage &seg, const std::vector< numeric_array< int, 3 > > &vl, const std::vector< numeric_array< int, 3 > > &vnh, Ghost &ghost, typename TImage::value_type newColor)
< New boundary points
void update(const numeric_array< int, 3 > &pos)
boost::enable_if< is_numeric_container< TStorage >, bool >::type contains(const Box< T, D > &box, const TStorage &v)
Check whether a point lies within box.
std::vector< numeric_array< int, 3 > > VoxelList
INLINE void _addPoint(VoxelList &vl, TImage &seg, const numeric_array< int, 3 > &pos, Ghost &ghost, typename TImage::value_type newColor)
If point at position 'pos' satisfy region-growing criteria, it is added to the list of voxel 'vl' and...
bool test(const numeric_array< int, 3 > &pos) const
std::unique_ptr< VoxelList > addNeighbors2(TImage &seg, const VoxelList &vl, const TNeighborhood &nh, Ghost &ghost, typename TImage::value_type newColor)