diff --git a/svcurve.cpp b/svcurve.cpp index b1ab2e3..6a31ba1 100644 --- a/svcurve.cpp +++ b/svcurve.cpp @@ -3,3 +3,13 @@ SvCurve::SvCurve() { } + +void SvCurve::addPoint(SvPoint *point) +{ + m_points.push_back(point); +} + +SvCurve *SvCurve::cut(SvPoint *point) +{ + +} diff --git a/svcurve.h b/svcurve.h index 36846fa..1f2d690 100644 --- a/svcurve.h +++ b/svcurve.h @@ -1,26 +1,33 @@ #ifndef SVCURVE_H #define SVCURVE_H -#include - #include "svdefs.h" #include "svpoint.h" #include "svsimplepoint.h" class SvPoint; +class SvFigure; class SvCurve { protected: - SvPoint *m_ends; - SvPoint *m_points; - SvSimplePoint *m_keyPoints; - QColor m_leftColor; - QColor m_rightColor; + SvFigure *m_inner; + SvFigure *m_outer; + QList m_points; + SvSimplePoint *m_keyPoints; + +private: + SvCurve(); public: - SvCurve(); + SvPoint* head() {return m_points.first(); } + SvPoint* tail() {return m_points.last(); } + SvPoint* tail() {return m_points.last(); } + void setInner(SvFigure *figure) {m_inner = figure; } + void setOuter(SvFigure *figure) {m_outer = figure; } + void addPoint(SvPoint *point); + SvCurve *cut(SvPoint *point); }; #endif // SVCURVE_H diff --git a/svdefs.h b/svdefs.h index ebd6d1a..5132cbe 100644 --- a/svdefs.h +++ b/svdefs.h @@ -3,7 +3,7 @@ #include -typedef unsigned int SvFrameId; +typedef unsigned int SvPointId; typedef unsigned int uint; #include "svpointcloud.h" diff --git a/svfigure.cpp b/svfigure.cpp index 3dab88b..47bad7c 100644 --- a/svfigure.cpp +++ b/svfigure.cpp @@ -1,5 +1,37 @@ #include "svfigure.h" -SvFigure::SvFigure() +SvFigure::SvFigure(SvCurve *curve) { + addCurve(curve); +} + +SvCurve *SvFigure::findCurveByPoint() +{ + foreach(SvCurve* curve, m_curves) { + if (curve->hasPoint(point)) { + return curve; + } + } + + return 0; +} + +SvFigure SvFigure::split(SvPoint *point) +{ + SvCurve *curve = findCurveByPoint(point); + SvFigure figure; + + if (curve) { + figure.addCurve(curve->cut(point)); + SvCurve *item = m_curves.last(); + + while(item != curve) { + figure.addCurve(item); + + m_curves.removeLast(); + item = m_curves.last(); + } + } + + return figure; } diff --git a/svfigure.h b/svfigure.h index 06a9936..beee5e5 100644 --- a/svfigure.h +++ b/svfigure.h @@ -7,11 +7,15 @@ class SvFigure { protected: - SvPoint *ends; - + QColor m_color; + QList m_curves; public: - SvFigure(); + SvFigure(SvCurve *curve); + + void addCurve(SvCurve *curve){m_curves.pop_back(curve); } + SvCurve *findCurveByPoint(); + SvFigure split(SvPoint *point); }; #endif // SVFIGURE_H diff --git a/svkernel.cpp b/svkernel.cpp index 5dad4cb..91e188f 100644 --- a/svkernel.cpp +++ b/svkernel.cpp @@ -35,8 +35,9 @@ int SvKernel::rgbDiff(QRgb left, QRgb right) return dsign * (abs(rightDiff - leftDiff)>>2) + diff /*+ (hsvDiff > 5 ? dsign * 10 : 0)*/; } -void SvKernel::exec(SvPointCloud *pcl, SvImage *image, int line) +void SvKernel::exec(SvPointCloud *pc, SvImage *image, int line) { + SvPoint p; QRgb vtop, top, right, bottom, vbottom, _xy, xy; int __dX, _dX, dX, dX_, @@ -88,8 +89,12 @@ void SvKernel::exec(SvPointCloud *pcl, SvImage *image, int line) } if (value > 0) { + p.setX(x - 1); + p.setY(line - 1); + p.setHorizontalValue(value); + p.setVerticalValue(value); - //m_result->putGrayPixel(x - 1, line - 1, value); + pc->addPoint(p); } __dX = _dX; diff --git a/svkernel.h b/svkernel.h index 2bdf616..22085b4 100644 --- a/svkernel.h +++ b/svkernel.h @@ -10,7 +10,7 @@ class SvKernel public: SvKernel(); virtual ~SvKernel(); - void exec(SvPointCloud *pcl, SvImage *image, int line); + void exec(SvPointCloud *pc, SvImage *image, int line); int rgbDiff(QRgb left, QRgb right); }; diff --git a/svpoint.cpp b/svpoint.cpp index 0550a9f..d6522b8 100644 --- a/svpoint.cpp +++ b/svpoint.cpp @@ -2,4 +2,15 @@ SvPoint::SvPoint() { + +} + +SvPoint::SvPoint(SvPoint &point) +{ + +} + +void SvPoint::addCurve(SvCurve *curve) +{ + m_curves[m_curveCount++] = curve; } diff --git a/svpoint.h b/svpoint.h index d2678b0..744e1ef 100644 --- a/svpoint.h +++ b/svpoint.h @@ -8,6 +8,7 @@ class SvCurve; class SvPoint: public SvSimplePoint { + public: enum Sides { TOP, @@ -24,11 +25,18 @@ public: }; protected: - SvCurve* m_curves; - FlowType m_type; + uint m_id; + uint m_curveCount; + SvCurve *m_curves[8]; + FlowType m_type; public: SvPoint(); + SvPoint(SvPoint &point); + + void addCurve(SvCurve *curve); + uint curveCount() {return m_curveCount; } + SvCurve *curve(uint index) {return m_curves[index]; } }; #endif // SVPOINT_H diff --git a/svpointcloud.cpp b/svpointcloud.cpp index 4b6e0ca..ddcbf16 100644 --- a/svpointcloud.cpp +++ b/svpointcloud.cpp @@ -5,23 +5,29 @@ SvPointCloud::SvPointCloud(uint width, uint height) m_pointFiledHeight = height; m_pointFiledWidth = width; - m_pointField = new SvPoint* [height]; + m_pointField = new SvPoint**[height](); for (uint y = 0; y < height; y++) { - m_pointField[y] = new SvPoint[width]; + m_pointField[y] = new SvPoint*[width](); } } SvPointCloud::~SvPointCloud() { for (uint y = 0; y < m_pointFiledHeight; y++) { + for (uint x = 0; x < m_pointFiledWidth; x++) { + if (m_pointField[y][x]) { + delete m_pointField[y][x]; + } + } + delete[] m_pointField[y]; } delete[] m_pointField; } -void SvPointCloud::addPoint(SvFrameId frame, SvPoint point) +void SvPointCloud::addPoint(SvPoint point) { - m_pointField[point.y()][point.x()] = point; + m_pointField[point.y()][point.x()] = new SvPoint(point); } diff --git a/svpointcloud.h b/svpointcloud.h index e17f56c..00da5d8 100644 --- a/svpointcloud.h +++ b/svpointcloud.h @@ -1,6 +1,8 @@ #ifndef SVPOINTCLOUD_H #define SVPOINTCLOUD_H +#include + #include "svdefs.h" #include "svpoint.h" #include "svcurve.h" @@ -11,12 +13,19 @@ class SvCurve; class SvFigure; class SvObject; -class SvPointCloud +class SvPointCloud: public QObject { + Q_OBJECT + + friend class SvCurve; + friend class SvPoint; + friend class SvFigure; + friend class SvObject; + protected: uint m_pointFiledHeight; uint m_pointFiledWidth; - SvPoint** m_pointField; + SvPoint*** m_pointField; QList m_curves; QList m_figures; QList m_objects; @@ -25,8 +34,11 @@ public: SvPointCloud(uint width, uint height); ~SvPointCloud(); - void addPoint(SvFrameId frame, SvPoint point); + SvCurve *createCurve(); + SvFigure *createFigure(); + SvObject *createObject(); + void addPoint(SvPoint point); }; #endif // SVPOINTCLOUD_H