tahoma2d/toonz/sources/common/trop/raster_edge_iterator.h

126 lines
3.5 KiB
C
Raw Normal View History

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