|
Shinya Kitaoka |
810553 |
// #pragma once // could not use by INCLUDE_HPP
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef RASTER_EDGE_ITERATOR_H
|
|
Toshihiro Shimizu |
890ddd |
#define RASTER_EDGE_ITERATOR_H
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "traster.h"
|
|
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 |
// RasterEdgeIterator class
|
|
Toshihiro Shimizu |
890ddd |
//*********************************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
The RasterEdgeIterator class models a forward iterator traversing a border of a
|
|
Toshihiro Shimizu |
890ddd |
raster image.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
template <typename pixelselector=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
class RasterEdgeIterator
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
typedef PixelSelector selector_type;
|
|
Toshihiro Shimizu |
890ddd |
typedef typename PixelSelector::pixel_type pixel_type;
|
|
Toshihiro Shimizu |
890ddd |
typedef typename PixelSelector::value_type value_type;
|
|
Toshihiro Shimizu |
890ddd |
typedef TRasterT<pixel_type> raster_type;</pixel_type>
|
|
Toshihiro Shimizu |
890ddd |
typedef TRasterPT<pixel_type> raster_typeP;</pixel_type>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
enum { STRAIGHT = 0x0,
|
|
Toshihiro Shimizu |
890ddd |
LEFT = 0x1,
|
|
Toshihiro Shimizu |
890ddd |
RIGHT = 0x2,
|
|
Toshihiro Shimizu |
890ddd |
AMBIGUOUS = 0x4,
|
|
Toshihiro Shimizu |
890ddd |
AMBIGUOUS_LEFT = LEFT | AMBIGUOUS,
|
|
Toshihiro Shimizu |
890ddd |
AMBIGUOUS_RIGHT = RIGHT | AMBIGUOUS,
|
|
Toshihiro Shimizu |
890ddd |
UNKNOWN = 0x8 };
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Toshihiro Shimizu |
890ddd |
raster_typeP m_ras;
|
|
Toshihiro Shimizu |
890ddd |
selector_type m_selector;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int m_lx_1, m_ly_1, m_wrap;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
value_type m_leftColor, m_rightColor, m_elbowColor;
|
|
Toshihiro Shimizu |
890ddd |
pixel_type *m_leftPix, *m_rightPix;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool m_rightSide;
|
|
Toshihiro Shimizu |
890ddd |
int m_turn;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPoint m_pos, m_dir;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
RasterEdgeIterator(const raster_typeP &rin, const selector_type &selector,
|
|
Toshihiro Shimizu |
890ddd |
const TPoint &pos, const TPoint &dir, int adherence = RIGHT);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void setEdge(const TPoint &pos, const TPoint &dir);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const raster_typeP &raster() const { return m_ras; }
|
|
Toshihiro Shimizu |
890ddd |
const selector_type &selector() const { return m_selector; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const TPoint &pos() const { return m_pos; }
|
|
Toshihiro Shimizu |
890ddd |
const TPoint &dir() const { return m_dir; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const value_type &leftColor() const { return m_leftColor; }
|
|
Toshihiro Shimizu |
890ddd |
const value_type &rightColor() const { return m_rightColor; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const value_type &color() const { return m_rightSide ? m_rightColor : m_leftColor; }
|
|
Toshihiro Shimizu |
890ddd |
const value_type &otherColor() const { return m_rightSide ? m_leftColor : m_rightColor; }
|
|
Toshihiro Shimizu |
890ddd |
const value_type &elbowColor() const { return m_elbowColor; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pixel_type *leftPix() const { return m_leftPix; }
|
|
Toshihiro Shimizu |
890ddd |
pixel_type *rightPix() const { return m_rightPix; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pixel_type *pix() const { return m_rightSide ? m_rightPix : m_leftPix; }
|
|
Toshihiro Shimizu |
890ddd |
pixel_type *otherPix() const { return m_rightSide ? m_leftPix : m_rightPix; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int turn() const { return m_turn; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void setAdherence(int side) { m_rightSide = (side == RIGHT); }
|
|
Toshihiro Shimizu |
890ddd |
int adherence() const { return m_rightSide ? RIGHT : LEFT; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
RasterEdgeIterator &operator++();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool operator==(const RasterEdgeIterator &it) const { return m_pos == it.m_pos && m_dir == it.m_dir; }
|
|
Toshihiro Shimizu |
890ddd |
bool operator!=(const RasterEdgeIterator &it) const { return !operator==(it); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Toshihiro Shimizu |
890ddd |
void pixels(pixel_type *&pixLeft, pixel_type *&pixRight);
|
|
Toshihiro Shimizu |
890ddd |
void colors(value_type &leftColor, value_type &rightColor);
|
|
Toshihiro Shimizu |
890ddd |
void turn(const value_type &newLeftColor, const value_type &newRightColor);
|
|
Toshihiro Shimizu |
890ddd |
void turnLeft()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int temp = m_dir.x;
|
|
Toshihiro Shimizu |
890ddd |
m_dir.x = -m_dir.y;
|
|
Toshihiro Shimizu |
890ddd |
m_dir.y = temp;
|
|
Toshihiro Shimizu |
890ddd |
m_turn = LEFT;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void turnRight()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int temp = m_dir.x;
|
|
Toshihiro Shimizu |
890ddd |
m_dir.x = m_dir.y;
|
|
Toshihiro Shimizu |
890ddd |
m_dir.y = -temp;
|
|
Toshihiro Shimizu |
890ddd |
m_turn = RIGHT;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void turnAmbiguous(const value_type &newLeftColor, const value_type &newRightColor);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} // namespace TRop::borders
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif //RASTER_EDGE_ITERATOR_H
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=====================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef INCLUDE_HPP
|
|
Toshihiro Shimizu |
890ddd |
#include "raster_edge_iterator.hpp"
|
|
Toshihiro Shimizu |
890ddd |
#endif //INCLUDE_HPP
|