Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Local includes
Toshihiro Shimizu 890ddd
#include "pixelselectors.h"
Toshihiro Shimizu 890ddd
#include "runsmap.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// STD includes
Toshihiro Shimizu 890ddd
#include <stack></stack>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// tcg includes
Toshihiro Shimizu 890ddd
#include "tcg/tcg_traits.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
Toshihiro Shimizu 890ddd
#define INCLUDE_HPP
Toshihiro Shimizu 890ddd
#include "tcg/tcg_mesh.h"
Toshihiro Shimizu 890ddd
#include "raster_edge_iterator.h"
Toshihiro Shimizu 890ddd
#include "borders_extractor.h"
Toshihiro Shimizu 890ddd
#undef INCLUDE_HPP
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "trop_borders.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace TRop::borders;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//****************************************************************
Toshihiro Shimizu 890ddd
//    Container Reader for Borders Reader
Toshihiro Shimizu 890ddd
//****************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixelselector=""></typename>
Shinya Kitaoka 120a6e
class WrapperReader {
Shinya Kitaoka 120a6e
  TRop::borders::BordersReader &m_reader;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  WrapperReader(TRop::borders::BordersReader &reader) : m_reader(reader) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void openContainer(const RasterEdgeIterator<pixelselector> &it) {</pixelselector>
Shinya Kitaoka 120a6e
    m_reader.openContainer(it.pos(), it.dir(), it.rightColor(), it.leftColor());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  void addElement(const RasterEdgeIterator<pixelselector> &it) {</pixelselector>
Shinya Kitaoka 120a6e
    m_reader.addElement(it.pos(), it.dir(), it.leftColor());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  void closeContainer() { m_reader.closeContainer(); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//****************************************************************
Toshihiro Shimizu 890ddd
//    Borders Extractor instantiations
Toshihiro Shimizu 890ddd
//****************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace TRop {
Shinya Kitaoka 120a6e
namespace borders {
Toshihiro Shimizu 890ddd
2fc36c
//--------------------------------------------------------------------------------
2fc36c
2fc36c
// Standard type instantiations
2fc36c
shun_iwasawa 0cae24
template void DVAPI readMeshes<tpixel32>(const TRasterPT<tpixel32> &raster,</tpixel32></tpixel32>
shun_iwasawa 0cae24
                                         ImageMeshesReaderT<tpixel32> &reader);</tpixel32>
shun_iwasawa 0cae24
template void DVAPI readMeshes<tpixel64>(const TRasterPT<tpixel64> &raster,</tpixel64></tpixel64>
shun_iwasawa 0cae24
                                         ImageMeshesReaderT<tpixel64> &reader);</tpixel64>
2fc36c
template void DVAPI readMeshes<tpixelgr8>(</tpixelgr8>
2fc36c
    const TRasterPT<tpixelgr8> &raster, ImageMeshesReaderT<tpixelgr8> &reader);</tpixelgr8></tpixelgr8>
shun_iwasawa 0cae24
template void DVAPI
shun_iwasawa 0cae24
readMeshes<tpixelgr16>(const TRasterPT<tpixelgr16> &raster,</tpixelgr16></tpixelgr16>
shun_iwasawa 0cae24
                       ImageMeshesReaderT<tpixelgr16> &reader);</tpixelgr16>
shun_iwasawa 0cae24
template void DVAPI
shun_iwasawa 0cae24
readMeshes<tpixelcm32>(const TRasterPT<tpixelcm32> &raster,</tpixelcm32></tpixelcm32>
shun_iwasawa 0cae24
                       ImageMeshesReaderT<tpixelcm32> &reader);</tpixelcm32>
2fc36c
2fc36c
//--------------------------------------------------------------------------------
2fc36c
Toshihiro Shimizu 890ddd
template <typename pix=""></typename>
Shinya Kitaoka 120a6e
void readBorders_simple(const TRasterPT<pix> &raster, BordersReader &reader,</pix>
Shinya Kitaoka 120a6e
                        bool onlyCorners) {
Shinya Kitaoka 120a6e
  typedef PixelSelector<pix> pixel_selector;</pix>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  pixel_selector selector(onlyCorners);
Shinya Kitaoka 120a6e
  WrapperReader<pixel_selector> wrapReader(reader);</pixel_selector>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  raster->lock();
Shinya Kitaoka 120a6e
  readBorders(raster, selector, wrapReader);
Shinya Kitaoka 120a6e
  raster->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void readBorders_simple(const TRasterGR8P &raster, BordersReader &reader,
Shinya Kitaoka 120a6e
                        const TPixelGR8 &transparencyColor, bool onlyCorners) {
Shinya Kitaoka 120a6e
  typedef PixelSelector<tpixelgr8> pixel_selector;</tpixelgr8>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  pixel_selector selector(onlyCorners, transparencyColor);
Shinya Kitaoka 120a6e
  WrapperReader<pixel_selector> wrapReader(reader);</pixel_selector>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  raster->lock();
Shinya Kitaoka 120a6e
  readBorders(raster, selector, wrapReader);
Shinya Kitaoka 120a6e
  raster->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void readBorders_simple(const TRasterGR16P &raster, BordersReader &reader,
Shinya Kitaoka 120a6e
                        const TPixelGR16 &transparencyColor, bool onlyCorners) {
Shinya Kitaoka 120a6e
  typedef PixelSelector<tpixelgr16> pixel_selector;</tpixelgr16>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  pixel_selector selector(onlyCorners, transparencyColor);
Shinya Kitaoka 120a6e
  WrapperReader<pixel_selector> wrapReader(reader);</pixel_selector>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  raster->lock();
Shinya Kitaoka 120a6e
  readBorders(raster, selector, wrapReader);
Shinya Kitaoka 120a6e
  raster->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void readBorders_simple(const TRasterCM32P &raster, BordersReader &reader,
Shinya Kitaoka 120a6e
                        bool onlyCorners, int toneThreshold) {
Shinya Kitaoka 120a6e
  typedef PixelSelector<tpixelcm32> pixel_selector;</tpixelcm32>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  pixel_selector selector(onlyCorners, toneThreshold);
Shinya Kitaoka 120a6e
  WrapperReader<pixel_selector> wrapReader(reader);</pixel_selector>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  raster->lock();
Shinya Kitaoka 120a6e
  readBorders(raster, selector, wrapReader);
Shinya Kitaoka 120a6e
  raster->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void readBorders_simple(const TRasterP &raster, BordersReader &reader,
Shinya Kitaoka 120a6e
                        bool onlyCorners) {
Shinya Kitaoka 120a6e
  TRaster32P ras32(raster);
Shinya Kitaoka 120a6e
  if (ras32) {
Shinya Kitaoka 120a6e
    readBorders_simple(ras32, reader, onlyCorners);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRaster64P ras64(raster);
Shinya Kitaoka 120a6e
  if (ras64) {
Shinya Kitaoka 120a6e
    readBorders_simple(ras64, reader, onlyCorners);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRasterCM32P rasCM32(raster);
Shinya Kitaoka 120a6e
  if (rasCM32) {
Shinya Kitaoka 120a6e
    readBorders_simple(rasCM32, reader, onlyCorners);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRasterGR8P rasGR8(raster);
Shinya Kitaoka 120a6e
  if (rasGR8) {
Shinya Kitaoka 120a6e
    readBorders_simple(rasGR8, reader, onlyCorners);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRasterGR16P rasGR16(raster);
Shinya Kitaoka 120a6e
  if (rasGR16) {
Shinya Kitaoka 120a6e
    readBorders_simple(rasGR16, reader, onlyCorners);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
}  // namespace TRop::borders
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//****************************************************************
Toshihiro Shimizu 890ddd
//    Meshes Extraction (MeshesReader::Imp)
Toshihiro Shimizu 890ddd
//****************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace TRop {
Shinya Kitaoka 120a6e
namespace borders {
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class TRop::borders::ImageMeshesReader::Imp {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Face m_outerFace;
Shinya Kitaoka 120a6e
  tcg::list<imagemeshp> m_meshes;</imagemeshp>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::stack<face *=""> m_facesStack;</face>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int m_facesCount, m_edgesCount;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Imp() : m_facesCount(), m_edgesCount() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void clear() {
Shinya Kitaoka 120a6e
    assert(m_facesStack.empty());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_outerFace = Face();
Shinya Kitaoka 120a6e
    m_meshes.clear();
Shinya Kitaoka 120a6e
    m_facesCount = m_edgesCount = 0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//****************************************************************
Toshihiro Shimizu 890ddd
//    Meshes Extraction (MeshesReader)
Toshihiro Shimizu 890ddd
//****************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ImageMeshesReader::ImageMeshesReader() : m_imp(new Imp) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ImageMeshesReader::~ImageMeshesReader() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ImageMeshesReader::clear() { m_imp->clear(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const Face &ImageMeshesReader::outerFace() const { return m_imp->m_outerFace; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Face &ImageMeshesReader::outerFace() { return m_imp->m_outerFace; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const tcg::list<imagemeshp> &ImageMeshesReader::meshes() const {</imagemeshp>
Shinya Kitaoka 120a6e
  return m_imp->m_meshes;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
tcg::list<imagemeshp> &ImageMeshesReader::meshes() { return m_imp->m_meshes; }</imagemeshp>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ImageMeshesReader::openFace(ImageMesh *mesh, int faceIdx) {
Shinya Kitaoka 120a6e
  Face &fc        = mesh ? mesh->face(faceIdx) : m_imp->m_outerFace;
Shinya Kitaoka 120a6e
  fc.imageIndex() = m_imp->m_facesCount++;
Shinya Kitaoka 120a6e
  m_imp->m_facesStack.push(&fc);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ImageMeshesReader::addMesh(ImageMesh *mesh) {
Shinya Kitaoka 120a6e
  Face &fc = *m_imp->m_facesStack.top();
Shinya Kitaoka 120a6e
  fc.meshes().push_back(m_imp->m_meshes.push_back(mesh));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ImageMeshesReader::closeFace() { m_imp->m_facesStack.pop(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ImageMeshesReader::closeEdge(ImageMesh *mesh, int edgeIdx) {
Shinya Kitaoka 120a6e
  mesh->edge(edgeIdx).imageIndex() = m_imp->m_edgesCount++;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
}  //  namespace TRop::borders
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//****************************************************************
Toshihiro Shimizu 890ddd
//    Meshes Extraction (traits)
Toshihiro Shimizu 890ddd
//****************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace tcg {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace TRop::borders;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Reader traits
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixel=""></typename>
Shinya Kitaoka 120a6e
struct container_reader_traits<imagemeshesreadert<pixel>,</imagemeshesreadert<pixel>
Shinya Kitaoka 120a6e
                               ImageMesh::face_type> {
Shinya Kitaoka 120a6e
  typedef ImageMeshesReaderT<pixel> meshes_reader_type;</pixel>
Shinya Kitaoka 120a6e
  typedef typename meshes_reader_type::value_type value_type;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  inline static void openContainer(meshes_reader_type &reader, ImageMesh *mesh,
Shinya Kitaoka 120a6e
                                   int faceIdx, const value_type &colorValue) {
Shinya Kitaoka 120a6e
    reader.openFace(mesh, faceIdx, colorValue);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  inline static void addElement(meshes_reader_type &reader, ImageMesh *mesh) {
Shinya Kitaoka 120a6e
    reader.addMesh(mesh);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  inline static void closeContainer(meshes_reader_type &reader) {
Shinya Kitaoka 120a6e
    reader.closeFace();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixel=""></typename>
Shinya Kitaoka 120a6e
struct container_reader_traits<imagemeshesreadert<pixel>,</imagemeshesreadert<pixel>
Shinya Kitaoka 120a6e
                               ImageMesh::edge_type> {
Shinya Kitaoka 120a6e
  typedef ImageMeshesReaderT<pixel> meshes_reader_type;</pixel>
Shinya Kitaoka 120a6e
  typedef
Shinya Kitaoka 120a6e
      typename meshes_reader_type::raster_edge_iterator raster_edge_iterator;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  inline static void openContainer(meshes_reader_type &reader,
Shinya Kitaoka 120a6e
                                   const raster_edge_iterator &it) {
Shinya Kitaoka 120a6e
    reader.openEdge(it);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  inline static void addElement(meshes_reader_type &reader,
Shinya Kitaoka 120a6e
                                const raster_edge_iterator &it) {
Shinya Kitaoka 120a6e
    reader.addVertex(it);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  inline static void closeContainer(meshes_reader_type &reader, ImageMesh *mesh,
Shinya Kitaoka 120a6e
                                    int edgeIdx) {
Shinya Kitaoka 120a6e
    reader.closeEdge(mesh, edgeIdx);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace tcg
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//****************************************************************
Toshihiro Shimizu 890ddd
//    Meshes Extraction (functions)
Toshihiro Shimizu 890ddd
//****************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace TRop {
Shinya Kitaoka 120a6e
namespace borders {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pix=""></typename>
Shinya Kitaoka 120a6e
void readMeshes(const TRasterPT<pix> &raster, ImageMeshesReaderT<pix> &reader) {</pix></pix>
Shinya Kitaoka 120a6e
  typedef PixelSelector<pix> pixel_selector;</pix>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  reader.clear();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  raster->lock();
Shinya Kitaoka 120a6e
  readMeshes<pixel_selector, imagemesh,="" imagemeshesreadert<pix="">>(</pixel_selector,>
Shinya Kitaoka 120a6e
      raster, reader.pixelSelector(), reader);
Shinya Kitaoka 120a6e
  raster->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
}  // namespace TRop::borders