Shinya Kitaoka 810553
// #pragma once // could not use by INCLUDE_HPP
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef BORDERS_EXTRACTOR_H
Toshihiro Shimizu 890ddd
#define BORDERS_EXTRACTOR_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "traster.h"
Toshihiro Shimizu 890ddd
#include "runsmap.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "raster_edge_iterator.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace TRop {
Shinya Kitaoka 120a6e
namespace borders {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*******************************************************************
Toshihiro Shimizu 890ddd
//    Pixel Selector model
Toshihiro Shimizu 890ddd
//*******************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  This class is just a stub for pixel selector classes.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  Pixel Selectors are objects used in raster borders recognition
Toshihiro Shimizu 890ddd
  to interpret a raster's pixels and direct edge iterators.
Toshihiro Shimizu 890ddd
\n\n
Toshihiro Shimizu 890ddd
  The main purpose of this class is that of distinguishing pixels
Toshihiro Shimizu 890ddd
  from their  values <\I>. Values are the actual entities recognized
Toshihiro Shimizu 890ddd
  in the borders extraction process - adjacent pixels that are cast to
Toshihiro Shimizu 890ddd
  the same value will be included in the same border.
Toshihiro Shimizu 890ddd
\n\n
Toshihiro Shimizu 890ddd
  For example, if we want to extract the borders of a fullcolor image
Toshihiro Shimizu 890ddd
  that separate bright areas from dark ones, we can just have a pixel selector
Toshihiro Shimizu 890ddd
  cast each pixel to the integer value 0 if the pixel's value is below the
Toshihiro Shimizu 890ddd
  brigthness threshold, and 1 if above.
Toshihiro Shimizu 890ddd
\n\n
Toshihiro Shimizu 890ddd
  Also, pixel selectors tell whether pixels are to be intended as
Toshihiro Shimizu 890ddd
  completely transparent (virtual pixels outside the raster boundaries are).
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
template <typename pix,="" typename="" val=""></typename>
Shinya Kitaoka 120a6e
class pixel_selector {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef Pix pixel_type;  //!< The pixel type naming the selector
Shinya Kitaoka 120a6e
  typedef Val value_type;  //!< A value type representing pixel contents.
Shinya Kitaoka 120a6e
                           //!< Typically the pixel itself.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  value_type value(const pixel_type &pix) const;
Shinya Kitaoka 120a6e
  bool equal(const pixel_type &a, const pixel_type &b) const {
Shinya Kitaoka 120a6e
    return value(a) == value(b);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  value_type transparent() const;
Shinya Kitaoka 120a6e
  bool transparent(const pixel_type &pix) const {
Shinya Kitaoka 120a6e
    return value(pix) == transparent();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! Returns whether a border point must be read or not (corners are always
Shinya Kitaoka 120a6e
  //! read).
Shinya Kitaoka 120a6e
  bool skip(const value_type &prevLeftValue,
Shinya Kitaoka 120a6e
            const value_type &leftValue) const {
Shinya Kitaoka 120a6e
    return true;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
enum RunType {
Shinya Kitaoka 120a6e
  _BORDER_LEFT        = 0x20,
Shinya Kitaoka 120a6e
  _BORDER_RIGHT       = 0x10,
Shinya Kitaoka 120a6e
  _HIERARCHY_INCREASE = 0x8,
Shinya Kitaoka 120a6e
  _HIERARCHY_DECREASE = 0x4
Shinya Kitaoka 120a6e
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  Reads the borders of the input raster, according to the specified selector.
Shinya Kitaoka 120a6e
  Outputs the borders by supplying a container reader with the raster edge
Shinya Kitaoka 120a6e
  iterators
Toshihiro Shimizu 890ddd
  corresponding to border vertices. The runsmap used in the process can be
Toshihiro Shimizu 890ddd
  returned in output.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
template <typename containerreader="" pixel,="" pixelselector,="" typename=""></typename>
Toshihiro Shimizu 890ddd
void readBorders(const TRasterPT<pixel> &raster, const PixelSelector &selector,</pixel>
Shinya Kitaoka 120a6e
                 ContainerReader &reader, RunsMapP *rasterRunsMap = 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=====================================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename containersreader="" mesh,="" pixelselector,="" typename=""></typename>
Shinya Kitaoka 120a6e
void readMeshes(const TRasterPT<typename pixelselector::pixel_type=""> &raster,</typename>
Shinya Kitaoka 120a6e
                const PixelSelector &selector,
Shinya Kitaoka 120a6e
                ContainersReader &meshesDataReader,
Shinya Kitaoka 120a6e
                RunsMapP *rasterRunsMap = 0);
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
}  // namespace TRop::borders
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // BORDERS_EXTRACTOR_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=====================================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef INCLUDE_HPP
Toshihiro Shimizu 890ddd
#include "borders_extractor.hpp"
Shinya Kitaoka 120a6e
#endif  // INCLUDE_HPP