chalk

kis_perspective_grid.h
1/*
2 * This file is part of Chalk
3 *
4 * Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21#ifndef KIS_PERSPECTIVE_GRID_H
22#define KIS_PERSPECTIVE_GRID_H
23
24#include <tqvaluelist.h>
25
26#include <kis_perspective_math.h>
27#include <kis_point.h>
28#include <ksharedptr.h>
29
30class KisPerspectiveGridNode : public KisPoint, public TDEShared {
31 public:
32 inline KisPerspectiveGridNode(double x, double y) : KisPoint(x,y) { }
33 inline KisPerspectiveGridNode(KisPoint p) : KisPoint(p) { }
34};
35typedef TDESharedPtr<KisPerspectiveGridNode> KisPerspectiveGridNodeSP;
36
37class KisSubPerspectiveGrid {
38 public:
39 KisSubPerspectiveGrid(KisPerspectiveGridNodeSP topLeft, KisPerspectiveGridNodeSP topRight, KisPerspectiveGridNodeSP bottomRight, KisPerspectiveGridNodeSP bottomLeft);
40
41 inline KisPoint topBottomVanishingPoint() { return computeVanishingPoint( topLeft(), topRight(), bottomLeft(), bottomRight() ); };
42 inline KisPoint leftRightVanishingPoint() { return computeVanishingPoint( topLeft(), bottomLeft(), topRight(), bottomRight() ); };
43
44 inline KisSubPerspectiveGrid* leftGrid() { return m_leftGrid; }
45 inline void setLeftGrid(KisSubPerspectiveGrid* g) { Q_ASSERT(m_leftGrid==0); m_leftGrid = g; }
46 inline KisSubPerspectiveGrid* rightGrid() { return m_rightGrid; }
47 inline void setRightGrid(KisSubPerspectiveGrid* g) { Q_ASSERT(m_rightGrid==0); m_rightGrid = g; }
48 inline KisSubPerspectiveGrid* topGrid() { return m_topGrid; }
49 inline void setTopGrid(KisSubPerspectiveGrid* g) { Q_ASSERT(m_topGrid==0); m_topGrid = g; }
50 inline KisSubPerspectiveGrid* bottomGrid() { return m_bottomGrid; }
51 inline void setBottomGrid(KisSubPerspectiveGrid* g) { Q_ASSERT(m_bottomGrid==0); m_bottomGrid = g; }
52 inline const KisPerspectiveGridNodeSP topLeft() const { return m_topLeft; }
53 inline KisPerspectiveGridNodeSP topLeft() { return m_topLeft; }
54 inline const KisPerspectiveGridNodeSP topRight() const { return m_topRight; }
55 inline KisPerspectiveGridNodeSP topRight() { return m_topRight; }
56 inline const KisPerspectiveGridNodeSP bottomLeft() const { return m_bottomLeft; }
57 inline KisPerspectiveGridNodeSP bottomLeft() { return m_bottomLeft; }
58 inline const KisPerspectiveGridNodeSP bottomRight() const { return m_bottomRight; }
59 inline KisPerspectiveGridNodeSP bottomRight() { return m_bottomRight; }
60 inline int subdivisions() const { return m_subdivisions; }
65 inline int index() const { return m_index; }
66
70 bool contains(const KisPoint p) const;
71 private:
72 inline KisPoint computeVanishingPoint(KisPerspectiveGridNodeSP p11, KisPerspectiveGridNodeSP p12, KisPerspectiveGridNodeSP p21, KisPerspectiveGridNodeSP p22)
73 {
74 KisPerspectiveMath::LineEquation d1 = KisPerspectiveMath::computeLineEquation( p11, p12 );
75 KisPerspectiveMath::LineEquation d2 = KisPerspectiveMath::computeLineEquation( p21, p22 );
76 return KisPerspectiveMath::computeIntersection(d1,d2);
77 }
78 private:
79 KisPerspectiveGridNodeSP m_topLeft, m_topRight, m_bottomLeft, m_bottomRight;
80 KisSubPerspectiveGrid *m_leftGrid, *m_rightGrid, *m_topGrid, *m_bottomGrid;
81 int m_subdivisions;
82 int m_index;
83 static int s_lastIndex;
84};
85
86class KisPerspectiveGrid {
87 public:
88 KisPerspectiveGrid();
89 ~KisPerspectiveGrid();
93 bool addNewSubGrid( KisSubPerspectiveGrid* ng );
94 inline TQValueList<KisSubPerspectiveGrid*>::const_iterator begin() const { return m_subGrids.begin(); }
95 inline TQValueList<KisSubPerspectiveGrid*>::const_iterator end() const { return m_subGrids.end(); }
96 inline bool hasSubGrids() const { return !m_subGrids.isEmpty(); }
97 void clearSubGrids();
98 inline int countSubGrids() const { return m_subGrids.size(); }
102 KisSubPerspectiveGrid* gridAt(KisPoint p);
103 private:
104 TQValueList<KisSubPerspectiveGrid*> m_subGrids;
105};
106
107#endif
A double-based point class that can return it's coordinates approximated to integers.
Definition kis_point.h:28