krita
kis_perspective_grid.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KIS_PERSPECTIVE_GRID_H
00022 #define KIS_PERSPECTIVE_GRID_H
00023
00024 #include <qvaluelist.h>
00025
00026 #include <kis_perspective_math.h>
00027 #include <kis_point.h>
00028 #include <ksharedptr.h>
00029
00030 class KisPerspectiveGridNode : public KisPoint, public KShared {
00031 public:
00032 inline KisPerspectiveGridNode(double x, double y) : KisPoint(x,y) { }
00033 inline KisPerspectiveGridNode(KisPoint p) : KisPoint(p) { }
00034 };
00035 typedef KSharedPtr<KisPerspectiveGridNode> KisPerspectiveGridNodeSP;
00036
00037 class KisSubPerspectiveGrid {
00038 public:
00039 KisSubPerspectiveGrid(KisPerspectiveGridNodeSP topLeft, KisPerspectiveGridNodeSP topRight, KisPerspectiveGridNodeSP bottomRight, KisPerspectiveGridNodeSP bottomLeft);
00040
00041 inline KisPoint topBottomVanishingPoint() { return computeVanishingPoint( topLeft(), topRight(), bottomLeft(), bottomRight() ); };
00042 inline KisPoint leftRightVanishingPoint() { return computeVanishingPoint( topLeft(), bottomLeft(), topRight(), bottomRight() ); };
00043
00044 inline KisSubPerspectiveGrid* leftGrid() { return m_leftGrid; }
00045 inline void setLeftGrid(KisSubPerspectiveGrid* g) { Q_ASSERT(m_leftGrid==0); m_leftGrid = g; }
00046 inline KisSubPerspectiveGrid* rightGrid() { return m_rightGrid; }
00047 inline void setRightGrid(KisSubPerspectiveGrid* g) { Q_ASSERT(m_rightGrid==0); m_rightGrid = g; }
00048 inline KisSubPerspectiveGrid* topGrid() { return m_topGrid; }
00049 inline void setTopGrid(KisSubPerspectiveGrid* g) { Q_ASSERT(m_topGrid==0); m_topGrid = g; }
00050 inline KisSubPerspectiveGrid* bottomGrid() { return m_bottomGrid; }
00051 inline void setBottomGrid(KisSubPerspectiveGrid* g) { Q_ASSERT(m_bottomGrid==0); m_bottomGrid = g; }
00052 inline const KisPerspectiveGridNodeSP topLeft() const { return m_topLeft; }
00053 inline KisPerspectiveGridNodeSP topLeft() { return m_topLeft; }
00054 inline const KisPerspectiveGridNodeSP topRight() const { return m_topRight; }
00055 inline KisPerspectiveGridNodeSP topRight() { return m_topRight; }
00056 inline const KisPerspectiveGridNodeSP bottomLeft() const { return m_bottomLeft; }
00057 inline KisPerspectiveGridNodeSP bottomLeft() { return m_bottomLeft; }
00058 inline const KisPerspectiveGridNodeSP bottomRight() const { return m_bottomRight; }
00059 inline KisPerspectiveGridNodeSP bottomRight() { return m_bottomRight; }
00060 inline int subdivisions() const { return m_subdivisions; }
00065 inline int index() const { return m_index; }
00066
00070 bool contains(const KisPoint p) const;
00071 private:
00072 inline KisPoint computeVanishingPoint(KisPerspectiveGridNodeSP p11, KisPerspectiveGridNodeSP p12, KisPerspectiveGridNodeSP p21, KisPerspectiveGridNodeSP p22)
00073 {
00074 KisPerspectiveMath::LineEquation d1 = KisPerspectiveMath::computeLineEquation( p11, p12 );
00075 KisPerspectiveMath::LineEquation d2 = KisPerspectiveMath::computeLineEquation( p21, p22 );
00076 return KisPerspectiveMath::computeIntersection(d1,d2);
00077 }
00078 private:
00079 KisPerspectiveGridNodeSP m_topLeft, m_topRight, m_bottomLeft, m_bottomRight;
00080 KisSubPerspectiveGrid *m_leftGrid, *m_rightGrid, *m_topGrid, *m_bottomGrid;
00081 int m_subdivisions;
00082 int m_index;
00083 static int s_lastIndex;
00084 };
00085
00086 class KisPerspectiveGrid {
00087 public:
00088 KisPerspectiveGrid();
00089 ~KisPerspectiveGrid();
00093 bool addNewSubGrid( KisSubPerspectiveGrid* ng );
00094 inline QValueList<KisSubPerspectiveGrid*>::const_iterator begin() const { return m_subGrids.begin(); }
00095 inline QValueList<KisSubPerspectiveGrid*>::const_iterator end() const { return m_subGrids.end(); }
00096 inline bool hasSubGrids() const { return !m_subGrids.isEmpty(); }
00097 void clearSubGrids();
00098 inline int countSubGrids() const { return m_subGrids.size(); }
00102 KisSubPerspectiveGrid* gridAt(KisPoint p);
00103 private:
00104 QValueList<KisSubPerspectiveGrid*> m_subGrids;
00105 };
00106
00107 #endif
|