Shinya Kitaoka 810553
// #pragma once // could not use by INCLUDE_HPP
Shinya Kitaoka 810553
Toshihiro Shimizu 890ddd
#ifndef TROP_BORDERS_H
Toshihiro Shimizu 890ddd
#define TROP_BORDERS_H
Toshihiro Shimizu 890ddd
Shinya Kitaoka 262a92
#include <memory></memory>
Shinya Kitaoka 262a92
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tsmartpointer.h"
Toshihiro Shimizu 890ddd
#include "tgeometry.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "traster.h"
Toshihiro Shimizu 890ddd
#include "trastercm.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// tcg includes
Toshihiro Shimizu 890ddd
#include "tcg_wrap.h"
Toshihiro Shimizu 890ddd
#include "tcg/tcg_vertex.h"
Toshihiro Shimizu 890ddd
#include "tcg/tcg_edge.h"
Toshihiro Shimizu 890ddd
#include "tcg/tcg_face.h"
Toshihiro Shimizu 890ddd
#include "tcg/tcg_mesh.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TRop::borders includes
Toshihiro Shimizu 890ddd
#include "../common/trop/pixelselectors.h"
Toshihiro Shimizu 890ddd
#include "../common/trop/raster_edge_iterator.h"
Toshihiro Shimizu 890ddd
#include "../common/trop/borders_extractor.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TROP_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  The TRop::borders namespace contains functions and classes that perform
Toshihiro Shimizu 890ddd
  contours extraction of a specified raster (either greyscale, fullcolor
Toshihiro Shimizu 890ddd
  or colormap).
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  Image contours are currently extracted in a not-hierarchycal fashion
Toshihiro Shimizu 890ddd
  (ie in succession) and supplied through a reimplementable reader class.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace TRop {
Shinya Kitaoka 120a6e
namespace borders {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************
Toshihiro Shimizu 890ddd
//    Borders Extraction Reader  (callbacks container)
Toshihiro Shimizu 890ddd
//**********************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  The BordersReader class defines the supported callbacks fired from the
Toshihiro Shimizu 890ddd
  borders extraction routines.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
class DVAPI BordersReader {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  virtual void openContainer(const TPoint &pos, const TPoint &dir,
Shinya Kitaoka 120a6e
                             const TPixel32 &innerColor,
Shinya Kitaoka 120a6e
                             const TPixel32 &outerColor) {}
Shinya Kitaoka 120a6e
  virtual void openContainer(const TPoint &pos, const TPoint &dir,
Shinya Kitaoka 120a6e
                             const TPixel64 &innerColor,
Shinya Kitaoka 120a6e
                             const TPixel64 &outerColor) {}
Shinya Kitaoka 120a6e
  virtual void openContainer(const TPoint &pos, const TPoint &dir,
Shinya Kitaoka 120a6e
                             const TPixelGR8 &innerColor,
Shinya Kitaoka 120a6e
                             const TPixelGR8 &outerColor) {}
Shinya Kitaoka 120a6e
  virtual void openContainer(const TPoint &pos, const TPoint &dir,
Shinya Kitaoka 120a6e
                             const TPixelGR16 &innerColor,
Shinya Kitaoka 120a6e
                             const TPixelGR16 &outerColor) {}
Shinya Kitaoka 120a6e
  virtual void openContainer(const TPoint &pos, const TPoint &dir,
Shinya Kitaoka 120a6e
                             TUINT32 innerColorIdx, TUINT32 outerColorIdx) {
Shinya Kitaoka 120a6e
  }  // colormap
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  virtual void addElement(const TPoint &pos, const TPoint &dir,
Shinya Kitaoka 120a6e
                          const TPixel32 &outerColor) {}
Shinya Kitaoka 120a6e
  virtual void addElement(const TPoint &pos, const TPoint &dir,
Shinya Kitaoka 120a6e
                          const TPixel64 &outerColor) {}
Shinya Kitaoka 120a6e
  virtual void addElement(const TPoint &pos, const TPoint &dir,
Shinya Kitaoka 120a6e
                          const TPixelGR8 &outerColor) {}
Shinya Kitaoka 120a6e
  virtual void addElement(const TPoint &pos, const TPoint &dir,
Shinya Kitaoka 120a6e
                          const TPixelGR16 &outerColor) {}
Shinya Kitaoka 120a6e
  virtual void addElement(const TPoint &pos, const TPoint &dir,
Shinya Kitaoka 120a6e
                          TUINT32 outerColorIdx) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  virtual void closeContainer() {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************
Toshihiro Shimizu 890ddd
//    Borders Extraction functions
Toshihiro Shimizu 890ddd
//**********************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// Generic readBorders
Shinya Kitaoka 120a6e
void DVAPI readBorders_simple(const TRasterP &raster, BordersReader &reader,
Shinya Kitaoka 120a6e
                              bool onlyCorners = true);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// Greymap readBorders with transparency color
Toshihiro Shimizu 890ddd
void DVAPI readBorders_simple(const TRasterGR8P &raster, BordersReader &reader,
Shinya Kitaoka 120a6e
                              const TPixelGR8 &transparencyColor,
Shinya Kitaoka 120a6e
                              bool onlyCorners = true);
Toshihiro Shimizu 890ddd
void DVAPI readBorders_simple(const TRasterGR16P &raster, BordersReader &reader,
Shinya Kitaoka 120a6e
                              const TPixelGR16 &transparencyColor,
Shinya Kitaoka 120a6e
                              bool onlyCorners = true);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// Colormap readBorders with ink/paint antialias chooser
Toshihiro Shimizu 890ddd
void DVAPI readBorders_simple(const TRasterCM32P &raster, BordersReader &reader,
Shinya Kitaoka 120a6e
                              bool onlyCorners = true, int toneThreshold = 128);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************
Toshihiro Shimizu 890ddd
//    Mesh Extraction (classes)
Toshihiro Shimizu 890ddd
//**********************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef tcg::Vertex<tpoint> Vertex;</tpoint>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class Edge final : public tcg::Edge {
Shinya Kitaoka 120a6e
  TPoint m_directions[2];
Shinya Kitaoka 120a6e
  int m_imageIndex;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  const TPoint &direction(int i) const { return m_directions[i]; }
Shinya Kitaoka 120a6e
  TPoint &direction(int i) { return m_directions[i]; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! The edge index in the overall image extraction procedure. This value can
Shinya Kitaoka 120a6e
  //! be used to
Shinya Kitaoka 120a6e
  //! univocally associate external data to an image edge.
Shinya Kitaoka 120a6e
  int imageIndex() const { return m_imageIndex; }
Shinya Kitaoka 120a6e
  int &imageIndex() { return m_imageIndex; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class Face final : public tcg::Face {
Shinya Kitaoka 120a6e
  tcg::list<int> m_meshes;</int>
Shinya Kitaoka 120a6e
  int m_imageIndex;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  const tcg::list<int> &meshes() const { return m_meshes; }</int>
Shinya Kitaoka 120a6e
  tcg::list<int> &meshes() { return m_meshes; }</int>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int meshesCount() const { return m_meshes.size(); }
Shinya Kitaoka 120a6e
  int mesh(int m) const { return m_meshes[m]; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  //! The face index in the overall image extraction procedure. This value can
Shinya Kitaoka 120a6e
  //! be used to
Shinya Kitaoka 120a6e
  //! univocally associate external data to an image face.
Shinya Kitaoka 120a6e
  int imageIndex() const { return m_imageIndex; }
Shinya Kitaoka 120a6e
  int &imageIndex() { return m_imageIndex; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class ImageMesh final : public TSmartObject,
Shinya Kitaoka d1f6c4
                        public tcg::Mesh<vertex, edge,="" face=""> {};</vertex,>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
template class TSmartPointerT<imagemesh>;</imagemesh>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
typedef TSmartPointerT<imagemesh> ImageMeshP;</imagemesh>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************
Toshihiro Shimizu 890ddd
//    Mesh Extraction (reader)
Toshihiro Shimizu 890ddd
//**********************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI ImageMeshesReader {
Shinya Kitaoka 120a6e
  class Imp;
Shinya Kitaoka 120a6e
  std::unique_ptr<imp> m_imp;</imp>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  ImageMeshesReader();
Shinya Kitaoka 120a6e
  virtual ~ImageMeshesReader();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const Face &outerFace() const;
Shinya Kitaoka 120a6e
  Face &outerFace();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const tcg::list<imagemeshp> &meshes() const;</imagemeshp>
Shinya Kitaoka 120a6e
  tcg::list<imagemeshp> &meshes();</imagemeshp>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void clear();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  // Face reader functions. Nested meshes are stored by default in a
Shinya Kitaoka 120a6e
  // global list of meshes retrievable with the meshes() accessor.
Shinya Kitaoka 120a6e
  // Each Mesh Face will be filled with the list of its sub-meshes in
Shinya Kitaoka 120a6e
  // the form of indices to the global list.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void openFace(ImageMesh *mesh, int faceIdx);
Shinya Kitaoka 120a6e
  void addMesh(ImageMesh *mesh);
Shinya Kitaoka 120a6e
  void closeFace();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  void closeEdge(ImageMesh *mesh, int edgeIdx);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // Not implemented
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  ImageMeshesReader(const ImageMeshesReader &);
Shinya Kitaoka 120a6e
  ImageMeshesReader &operator=(const ImageMeshesReader &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixel=""></typename>
Shinya Kitaoka 120a6e
class ImageMeshesReaderT : public ImageMeshesReader {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef PixelSelector<pixel> pixel_selector_type;</pixel>
Shinya Kitaoka 120a6e
  typedef typename pixel_selector_type::value_type value_type;
Shinya Kitaoka 120a6e
  typedef RasterEdgeIterator<pixel_selector_type> raster_edge_iterator;</pixel_selector_type>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  pixel_selector_type m_selector;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  ImageMeshesReaderT() : m_selector(false) {}
Shinya Kitaoka 120a6e
  ImageMeshesReaderT(const pixel_selector_type &selector)
Shinya Kitaoka 120a6e
      : m_selector(selector) {}
Shinya Kitaoka 120a6e
  ~ImageMeshesReaderT() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const pixel_selector_type &pixelSelector() const { return m_selector; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  virtual void openFace(ImageMesh *mesh, int faceIdx,
Shinya Kitaoka 120a6e
                        const value_type &colorValue) {
Shinya Kitaoka 120a6e
    ImageMeshesReader::openFace(mesh, faceIdx);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  virtual void addMesh(ImageMesh *mesh) { ImageMeshesReader::addMesh(mesh); }
Shinya Kitaoka 120a6e
  virtual void closeFace() { ImageMeshesReader::closeFace(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  // Edge reader functions. Edges are not stored by default.
Shinya Kitaoka 120a6e
  // Users should reimplement these methods to store or process edge
Shinya Kitaoka 120a6e
  // data for the required purpose.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  virtual void openEdge(const raster_edge_iterator &it) {}
Shinya Kitaoka 120a6e
  virtual void addVertex(const raster_edge_iterator &it) {}
Shinya Kitaoka 120a6e
  virtual void closeEdge(ImageMesh *mesh, int edgeIdx) {
Shinya Kitaoka 120a6e
    ImageMeshesReader::closeEdge(mesh, edgeIdx);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************
Toshihiro Shimizu 890ddd
//    Mesh Extraction (functions)
Toshihiro Shimizu 890ddd
//**********************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixel=""></typename>
Shinya Kitaoka 120a6e
void readMeshes(const TRasterPT<pixel> &raster,</pixel>
Shinya Kitaoka 120a6e
                ImageMeshesReaderT<pixel> &reader);</pixel>
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
}  // namespace TRop::borders
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // TROP_BORDERS_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef INCLUDE_HPP
Toshihiro Shimizu 890ddd
#include "../common/trop/borders_extractor.hpp"
Toshihiro Shimizu 890ddd
#include "../common/trop/raster_edge_iterator.hpp"
Toshihiro Shimizu 890ddd
#endif