You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
243 lines
5.7 KiB
243 lines
5.7 KiB
#ifndef __SHADOW_MASKS_HEADER__
|
|
#define __SHADOW_MASKS_HEADER__
|
|
|
|
#include "../../components/base/basicLogCollection.h"
|
|
#include "../../components/base/basicTypes.h"
|
|
#include "../../hardware/soc/general/3DLRF.h"
|
|
|
|
#if (defined(__linux__) && ! defined(__GUI__)) || defined(_MEKOROT_)
|
|
typedef struct
|
|
{
|
|
private:
|
|
|
|
int16_t m_x;
|
|
int16_t m_y;
|
|
|
|
public:
|
|
|
|
void setX(int a)
|
|
{
|
|
m_x = a;
|
|
}
|
|
|
|
void setY(int a)
|
|
{
|
|
m_y = a;
|
|
}
|
|
|
|
int16_t x(void)
|
|
{
|
|
return m_x;
|
|
}
|
|
|
|
int16_t y(void)
|
|
{
|
|
return m_y;
|
|
}
|
|
|
|
} simplePoint;
|
|
|
|
typedef struct
|
|
{
|
|
uint8_t color[3];
|
|
simplePoint * points;
|
|
uint8_t count;
|
|
} simplePolygone;
|
|
|
|
typedef std::vector<simplePolygone *> vectorMasking;
|
|
typedef std::vector<simplePolygone *> vectorQPoly;
|
|
#else
|
|
#include "../../gui/gui.h"
|
|
typedef QPoint simplePoint;
|
|
|
|
// typedef QPolygon simplePolygone;
|
|
typedef struct
|
|
{
|
|
uint8_t color[3];
|
|
QPoint * points;
|
|
uint8_t count;
|
|
} simplePolygone;
|
|
|
|
typedef std::vector<simplePolygone *> vectorMasking;
|
|
typedef std::vector<QPolygon *> vectorQPoly;
|
|
#endif
|
|
|
|
typedef struct
|
|
{
|
|
uint16_t start;
|
|
uint16_t stop;
|
|
} raySegment;
|
|
|
|
typedef struct
|
|
{
|
|
uint16_t column;
|
|
uint16_t count;
|
|
raySegment * zones;
|
|
} rawRay;
|
|
|
|
typedef std::vector<rawRay *> vectorZoneMask;
|
|
|
|
/*
|
|
// Given three collinear points p, q, r, the function checks if
|
|
// point q lies on line segment 'pr'
|
|
inline bool onSegment( simplePoint p, simplePoint q, simplePoint r ){
|
|
if (q.x() <= max(p.x(), r.x()) && q.x() >= min(p.x(), r.x()) &&
|
|
q.y() <= max(p.y(), r.y()) && q.y() >= min(p.y(), r.y()))
|
|
return true;
|
|
return false;
|
|
};
|
|
|
|
// To find orientation of ordered triplet (p, q, r).
|
|
// The function returns following values
|
|
// 0 --> p, q and r are collinear
|
|
// 1 --> Clockwise
|
|
// 2 --> Counterclockwise
|
|
inline int orientation( simplePoint p, simplePoint q, simplePoint r ){
|
|
int val = (q.y() - p.y()) * (r.x() - q.x()) -
|
|
(q.x() - p.x()) * (r.y() - q.y());
|
|
|
|
if (val == 0) return 0; // collinear
|
|
return (val > 0)? 1: 2; // clock or counterclock wise
|
|
};
|
|
|
|
// The function that returns true if line segment 'p1q1'
|
|
// and 'p2q2' intersect.
|
|
inline bool doIntersect(simplePoint p1, simplePoint q1, simplePoint p2, simplePoint q2){
|
|
// Find the four orientations needed for general and
|
|
// special cases
|
|
int o1 = orientation(p1, q1, p2);
|
|
int o2 = orientation(p1, q1, q2);
|
|
int o3 = orientation(p2, q2, p1);
|
|
int o4 = orientation(p2, q2, q1);
|
|
|
|
// General case
|
|
if (o1 != o2 && o3 != o4)
|
|
return true;
|
|
|
|
// Special Cases
|
|
// p1, q1 and p2 are collinear and p2 lies on segment p1q1
|
|
if (o1 == 0 && onSegment(p1, p2, q1)) return true;
|
|
|
|
// p1, q1 and p2 are collinear and q2 lies on segment p1q1
|
|
if (o2 == 0 && onSegment(p1, q2, q1)) return true;
|
|
|
|
// p2, q2 and p1 are collinear and p1 lies on segment p2q2
|
|
if (o3 == 0 && onSegment(p2, p1, q2)) return true;
|
|
|
|
// p2, q2 and q1 are collinear and q1 lies on segment p2q2
|
|
if (o4 == 0 && onSegment(p2, q1, q2)) return true;
|
|
|
|
return false; // Doesn't fall in any of the above cases
|
|
}
|
|
|
|
// Returns true if the point p lies inside the polygon[] with n vertices
|
|
inline bool isInside( simplePoint polygon[], int n, simplePoint p ){
|
|
// There must be at least 3 vertices in polygon[]
|
|
if( n < 3 ) return false;
|
|
|
|
// Create a point for line segment from p to infinite
|
|
simplePoint extreme;
|
|
extreme.setX(10000);
|
|
extreme.setY(p.y());
|
|
// Count intersections of the above line with sides of polygon
|
|
int count = 0, i = 0;
|
|
do
|
|
{
|
|
int next = (i+1)%n;
|
|
|
|
// Check if the line segment from 'p' to 'extreme' intersects
|
|
// with the line segment from 'polygon[i]' to 'polygon[next]'
|
|
if (doIntersect(polygon[i], polygon[next], p, extreme))
|
|
{
|
|
// If the point 'p' is collinear with line segment 'i-next',
|
|
// then check if it lies on segment. If it lies, return true,
|
|
// otherwise false
|
|
if (orientation(polygon[i], p, polygon[next]) == 0)
|
|
return onSegment(polygon[i], p, polygon[next]);
|
|
|
|
count++;
|
|
}
|
|
i = next;
|
|
} while (i != 0);
|
|
|
|
// Return true if count is odd, false otherwise
|
|
return count&1; // Same as (count%2 == 1)
|
|
}
|
|
*/
|
|
|
|
class ShadowMask
|
|
{
|
|
private:
|
|
|
|
basicLogCollection * m_pLog;
|
|
vectorZoneMask m_vZoneMask;
|
|
bool m_bActive;
|
|
bool m_bAutoSave;
|
|
vectorMasking m_vVectorMask;
|
|
bool m_bRasterized;
|
|
#if defined(__linux__) && ! defined(__GUI__)
|
|
CSTR m_pRasterFileName;
|
|
CSTR m_pVertexFileName;
|
|
bool onSegment(simplePoint p, simplePoint q, simplePoint r);
|
|
int orientation(simplePoint p, simplePoint q, simplePoint r);
|
|
bool doIntersect(simplePoint p1, simplePoint q1, simplePoint p2, simplePoint q2);
|
|
bool isInside(simplePolygone * polygon, simplePoint p);
|
|
#endif
|
|
public:
|
|
|
|
ShadowMask();
|
|
~ShadowMask();
|
|
#if defined(__linux__) && ! defined(__GUI__)
|
|
bool loadRastered(CSTR fName = NULL);
|
|
bool saveRastered(CSTR fName = NULL);
|
|
bool saveVertexes(CSTR fName = NULL);
|
|
bool loadVertexes(CSTR fName = NULL);
|
|
#endif
|
|
bool getMPoly(vectorMasking & VM);
|
|
bool getZoneMask(vectorZoneMask & ZM);
|
|
simplePolygone * getPoly(int id);
|
|
bool addPoly(simplePolygone * SP);
|
|
bool clear(void);
|
|
bool deletePoly(int ID);
|
|
|
|
uint8_t getPolyCount(void)
|
|
{
|
|
return (m_vVectorMask.size() & 0xFF);
|
|
}
|
|
|
|
uint16_t getRayCount(void)
|
|
{
|
|
return (m_vZoneMask.size() & 0xFFFF);
|
|
}
|
|
|
|
bool rasterizeVertexes(void);
|
|
#if defined(WIN32) || defined(__GUI__)
|
|
|
|
bool getQPoly(vectorQPoly & VM);
|
|
bool addVertex(uint16_t polyID, simplePoint SP);
|
|
bool addVertex(uint16_t polyID, uint32_t SP); // Binary Data to Vertex
|
|
#endif
|
|
bool isOutside(uint16_t x, uint16_t y);
|
|
bool isOutside(simplePoint);
|
|
|
|
bool isActive(void)
|
|
{
|
|
return m_bActive;
|
|
}
|
|
|
|
void setActive(bool tVal);
|
|
bool addRay(uint16_t column, raySegment RS);
|
|
bool addRay(uint16_t column, uint32_t RS); // Binary Data to RaySegment
|
|
|
|
void disableAutoSave(void)
|
|
{
|
|
m_bAutoSave = false;
|
|
}
|
|
|
|
void enableAutoSave(void)
|
|
{
|
|
m_bAutoSave = false;
|
|
}
|
|
};
|
|
|
|
#endif
|