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
Toshihiro Shimizu 890ddd
namespace TRop
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
namespace borders
Toshihiro Shimizu 890ddd
{
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
*/
Toshihiro Shimizu 890ddd
class DVAPI BordersReader
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	virtual void openContainer(const TPoint &pos, const TPoint &dir,
Toshihiro Shimizu 890ddd
							   const TPixel32 &innerColor, const TPixel32 &outerColor) {}
Toshihiro Shimizu 890ddd
	virtual void openContainer(const TPoint &pos, const TPoint &dir,
Toshihiro Shimizu 890ddd
							   const TPixel64 &innerColor, const TPixel64 &outerColor) {}
Toshihiro Shimizu 890ddd
	virtual void openContainer(const TPoint &pos, const TPoint &dir,
Toshihiro Shimizu 890ddd
							   const TPixelGR8 &innerColor, const TPixelGR8 &outerColor) {}
Toshihiro Shimizu 890ddd
	virtual void openContainer(const TPoint &pos, const TPoint &dir,
Toshihiro Shimizu 890ddd
							   const TPixelGR16 &innerColor, const TPixelGR16 &outerColor) {}
Toshihiro Shimizu 890ddd
	virtual void openContainer(const TPoint &pos, const TPoint &dir,
Toshihiro Shimizu 890ddd
							   TUINT32 innerColorIdx, TUINT32 outerColorIdx) {} //colormap
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void addElement(const TPoint &pos, const TPoint &dir, const TPixel32 &outerColor) {}
Toshihiro Shimizu 890ddd
	virtual void addElement(const TPoint &pos, const TPoint &dir, const TPixel64 &outerColor) {}
Toshihiro Shimizu 890ddd
	virtual void addElement(const TPoint &pos, const TPoint &dir, const TPixelGR8 &outerColor) {}
Toshihiro Shimizu 890ddd
	virtual void addElement(const TPoint &pos, const TPoint &dir, const TPixelGR16 &outerColor) {}
Toshihiro Shimizu 890ddd
	virtual void addElement(const TPoint &pos, const TPoint &dir, TUINT32 outerColorIdx) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void closeContainer() {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************
Toshihiro Shimizu 890ddd
//    Borders Extraction functions
Toshihiro Shimizu 890ddd
//**********************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//Generic readBorders
Toshihiro Shimizu 890ddd
void DVAPI readBorders_simple(const TRasterP &raster, BordersReader &reader, bool onlyCorners = true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//Greymap readBorders with transparency color
Toshihiro Shimizu 890ddd
void DVAPI readBorders_simple(const TRasterGR8P &raster, BordersReader &reader,
Toshihiro Shimizu 890ddd
							  const TPixelGR8 &transparencyColor, bool onlyCorners = true);
Toshihiro Shimizu 890ddd
void DVAPI readBorders_simple(const TRasterGR16P &raster, BordersReader &reader,
Toshihiro Shimizu 890ddd
							  const TPixelGR16 &transparencyColor, bool onlyCorners = true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//Colormap readBorders with ink/paint antialias chooser
Toshihiro Shimizu 890ddd
void DVAPI readBorders_simple(const TRasterCM32P &raster, BordersReader &reader,
Toshihiro Shimizu 890ddd
							  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
Toshihiro Shimizu 890ddd
class Edge : public tcg::Edge
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TPoint m_directions[2];
Toshihiro Shimizu 890ddd
	int m_imageIndex;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	const TPoint &direction(int i) const { return m_directions[i]; }
Toshihiro Shimizu 890ddd
	TPoint &direction(int i) { return m_directions[i]; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! The edge index in the overall image extraction procedure. This value can be used to
Toshihiro Shimizu 890ddd
	//! univocally associate external data to an image edge.
Toshihiro Shimizu 890ddd
	int imageIndex() const { return m_imageIndex; }
Toshihiro Shimizu 890ddd
	int &imageIndex() { return m_imageIndex; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class Face : public tcg::Face
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	tcg::list<int> m_meshes;</int>
Toshihiro Shimizu 890ddd
	int m_imageIndex;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	const tcg::list<int> &meshes() const { return m_meshes; }</int>
Toshihiro Shimizu 890ddd
	tcg::list<int> &meshes() { return m_meshes; }</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int meshesCount() const { return m_meshes.size(); }
Toshihiro Shimizu 890ddd
	int mesh(int m) const { return m_meshes[m]; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! The face index in the overall image extraction procedure. This value can be used to
Toshihiro Shimizu 890ddd
	//! univocally associate external data to an image face.
Toshihiro Shimizu 890ddd
	int imageIndex() const { return m_imageIndex; }
Toshihiro Shimizu 890ddd
	int &imageIndex() { return m_imageIndex; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class ImageMesh : public TSmartObject, public tcg::Mesh<vertex, edge,="" face=""></vertex,>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
};
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
Toshihiro Shimizu 890ddd
class DVAPI ImageMeshesReader
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	class Imp;
Shinya Kitaoka 262a92
	std::unique_ptr<imp> m_imp;</imp>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	ImageMeshesReader();
Toshihiro Shimizu 890ddd
	virtual ~ImageMeshesReader();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const Face &outerFace() const;
Toshihiro Shimizu 890ddd
	Face &outerFace();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const tcg::list<imagemeshp> &meshes() const;</imagemeshp>
Toshihiro Shimizu 890ddd
	tcg::list<imagemeshp> &meshes();</imagemeshp>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void clear();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	// Face reader functions. Nested meshes are stored by default in a
Toshihiro Shimizu 890ddd
	// global list of meshes retrievable with the meshes() accessor.
Toshihiro Shimizu 890ddd
	// Each Mesh Face will be filled with the list of its sub-meshes in
Toshihiro Shimizu 890ddd
	// the form of indices to the global list.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void openFace(ImageMesh *mesh, int faceIdx);
Toshihiro Shimizu 890ddd
	void addMesh(ImageMesh *mesh);
Toshihiro Shimizu 890ddd
	void closeFace();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	void closeEdge(ImageMesh *mesh, int edgeIdx);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	//Not implemented
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ImageMeshesReader(const ImageMeshesReader &);
Toshihiro Shimizu 890ddd
	ImageMeshesReader &operator=(const ImageMeshesReader &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixel=""></typename>
Toshihiro Shimizu 890ddd
class ImageMeshesReaderT : public ImageMeshesReader
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef PixelSelector<pixel> pixel_selector_type;</pixel>
Toshihiro Shimizu 890ddd
	typedef typename pixel_selector_type::value_type value_type;
Toshihiro Shimizu 890ddd
	typedef RasterEdgeIterator<pixel_selector_type> raster_edge_iterator;</pixel_selector_type>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	pixel_selector_type m_selector;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	ImageMeshesReaderT() : m_selector(false) {}
Toshihiro Shimizu 890ddd
	ImageMeshesReaderT(const pixel_selector_type &selector) : m_selector(selector) {}
Toshihiro Shimizu 890ddd
	~ImageMeshesReaderT() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const pixel_selector_type &pixelSelector() const { return m_selector; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	virtual void openFace(ImageMesh *mesh, int faceIdx, const value_type &colorValue)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		ImageMeshesReader::openFace(mesh, faceIdx);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	virtual void addMesh(ImageMesh *mesh) { ImageMeshesReader::addMesh(mesh); }
Toshihiro Shimizu 890ddd
	virtual void closeFace() { ImageMeshesReader::closeFace(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	// Edge reader functions. Edges are not stored by default.
Toshihiro Shimizu 890ddd
	// Users should reimplement these methods to store or process edge
Toshihiro Shimizu 890ddd
	// data for the required purpose.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void openEdge(const raster_edge_iterator &it) {}
Toshihiro Shimizu 890ddd
	virtual void addVertex(const raster_edge_iterator &it) {}
Toshihiro Shimizu 890ddd
	virtual void closeEdge(ImageMesh *mesh, int edgeIdx)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		ImageMeshesReader::closeEdge(mesh, edgeIdx);
Toshihiro Shimizu 890ddd
	}
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>
Toshihiro Shimizu 890ddd
void readMeshes(const TRasterPT<pixel> &raster, ImageMeshesReaderT<pixel> &reader);</pixel></pixel>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
} //namespace TRop::borders
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#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