|
1 #ifndef __RIPATH_H |
|
2 #define __RIPATH_H |
|
3 |
|
4 /*------------------------------------------------------------------------ |
|
5 * |
|
6 * OpenVG 1.1 Reference Implementation |
|
7 * ----------------------------------- |
|
8 * |
|
9 * Copyright (c) 2007 The Khronos Group Inc. |
|
10 * |
|
11 * Permission is hereby granted, free of charge, to any person obtaining a |
|
12 * copy of this software and /or associated documentation files |
|
13 * (the "Materials "), to deal in the Materials without restriction, |
|
14 * including without limitation the rights to use, copy, modify, merge, |
|
15 * publish, distribute, sublicense, and/or sell copies of the Materials, |
|
16 * and to permit persons to whom the Materials are furnished to do so, |
|
17 * subject to the following conditions: |
|
18 * |
|
19 * The above copyright notice and this permission notice shall be included |
|
20 * in all copies or substantial portions of the Materials. |
|
21 * |
|
22 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
25 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
|
26 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
|
27 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR |
|
28 * THE USE OR OTHER DEALINGS IN THE MATERIALS. |
|
29 * |
|
30 *//** |
|
31 * \file |
|
32 * \brief Path class. |
|
33 * \note |
|
34 *//*-------------------------------------------------------------------*/ |
|
35 |
|
36 #ifndef _OPENVG_H |
|
37 #include "openvg.h" |
|
38 #endif |
|
39 |
|
40 #ifndef __RIMATH_H |
|
41 #include "riMath.h" |
|
42 #endif |
|
43 |
|
44 #ifndef __RIARRAY_H |
|
45 #include "riArray.h" |
|
46 #endif |
|
47 |
|
48 #ifndef __RIRASTERIZER_H |
|
49 #include "riRasterizer.h" |
|
50 #endif |
|
51 |
|
52 //============================================================================================== |
|
53 |
|
54 namespace OpenVGRI |
|
55 { |
|
56 |
|
57 /*-------------------------------------------------------------------*//*! |
|
58 * \brief Storage and operations for VGPath. |
|
59 * \param |
|
60 * \return |
|
61 * \note |
|
62 *//*-------------------------------------------------------------------*/ |
|
63 |
|
64 class Path |
|
65 { |
|
66 public: |
|
67 Path(VGint format, VGPathDatatype datatype, RIfloat scale, RIfloat bias, int segmentCapacityHint, int coordCapacityHint, VGbitfield caps); //throws bad_alloc |
|
68 ~Path(); |
|
69 |
|
70 VGint getFormat() const { return m_format; } |
|
71 VGPathDatatype getDatatype() const { return m_datatype; } |
|
72 RIfloat getScale() const { return m_scale; } |
|
73 RIfloat getBias() const { return m_bias; } |
|
74 VGbitfield getCapabilities() const { return m_capabilities; } |
|
75 void setCapabilities(VGbitfield caps) { m_capabilities = caps; } |
|
76 int getNumSegments() const { return m_segments.size(); } |
|
77 int getNumCoordinates() const { return m_data.size() / getBytesPerCoordinate(m_datatype); } |
|
78 void addReference() { m_referenceCount++; } |
|
79 int removeReference() { m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; } |
|
80 |
|
81 void clear(VGbitfield capabilities); |
|
82 void appendData(const RIuint8* segments, int numSegments, const RIuint8* data); //throws bad_alloc |
|
83 void append(const Path* srcPath); //throws bad_alloc |
|
84 void modifyCoords(int startIndex, int numSegments, const RIuint8* data); |
|
85 void transform(const Path* srcPath, const Matrix3x3& matrix); //throws bad_alloc |
|
86 //returns true if interpolation succeeds, false if start and end paths are not compatible |
|
87 bool interpolate(const Path* startPath, const Path* endPath, RIfloat amount); //throws bad_alloc |
|
88 void fill(const Matrix3x3& pathToSurface, Rasterizer& rasterizer); //throws bad_alloc |
|
89 void stroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const Array<RIfloat>& dashPattern, RIfloat dashPhase, bool dashPhaseReset, RIfloat strokeWidth, VGCapStyle capStyle, VGJoinStyle joinStyle, RIfloat miterLimit); //throws bad_alloc |
|
90 |
|
91 void getPointAlong(int startIndex, int numSegments, RIfloat distance, Vector2& p, Vector2& t); //throws bad_alloc |
|
92 RIfloat getPathLength(int startIndex, int numSegments); //throws bad_alloc |
|
93 void getPathBounds(RIfloat& minx, RIfloat& miny, RIfloat& maxx, RIfloat& maxy); //throws bad_alloc |
|
94 void getPathTransformedBounds(const Matrix3x3& pathToSurface, RIfloat& minx, RIfloat& miny, RIfloat& maxx, RIfloat& maxy); //throws bad_alloc |
|
95 |
|
96 private: |
|
97 enum VertexFlags |
|
98 { |
|
99 START_SUBPATH = (1<<0), |
|
100 END_SUBPATH = (1<<1), |
|
101 START_SEGMENT = (1<<2), |
|
102 END_SEGMENT = (1<<3), |
|
103 CLOSE_SUBPATH = (1<<4), |
|
104 IMPLICIT_CLOSE_SUBPATH = (1<<5) |
|
105 }; |
|
106 struct Vertex |
|
107 { |
|
108 Vertex() : userPosition(), userTangent(), pathLength(0.0f), flags(0) {} |
|
109 Vector2 userPosition; |
|
110 Vector2 userTangent; |
|
111 RIfloat pathLength; |
|
112 unsigned int flags; |
|
113 }; |
|
114 struct StrokeVertex |
|
115 { |
|
116 StrokeVertex() : p(), t(), ccw(), cw(), pathLength(0.0f), flags(0), inDash(false) {} |
|
117 Vector2 p; |
|
118 Vector2 t; |
|
119 Vector2 ccw; |
|
120 Vector2 cw; |
|
121 RIfloat pathLength; |
|
122 unsigned int flags; |
|
123 bool inDash; |
|
124 }; |
|
125 |
|
126 Path(const Path&); //!< Not allowed. |
|
127 const Path& operator=(const Path&); //!< Not allowed. |
|
128 |
|
129 static VGPathSegment getPathSegment(RIuint8 data) { return (VGPathSegment)(data & 0x1e); } |
|
130 static VGPathAbsRel getPathAbsRel(RIuint8 data) { return (VGPathAbsRel)(data & 0x1); } |
|
131 static int segmentToNumCoordinates(VGPathSegment segment); |
|
132 static int countNumCoordinates(const RIuint8* segments, int numSegments); |
|
133 static int getBytesPerCoordinate(VGPathDatatype datatype); |
|
134 |
|
135 static void setCoordinate(Array<RIuint8>& data, VGPathDatatype datatype, RIfloat scale, RIfloat bias, int i, RIfloat c); |
|
136 |
|
137 RIfloat getCoordinate(int i) const; |
|
138 void setCoordinate(int i, RIfloat c) { setCoordinate(m_data, m_datatype, m_scale, m_bias, i, c); } |
|
139 |
|
140 void addVertex(const Vector2& p, const Vector2& t, RIfloat pathLength, unsigned int flags); //throws bad_alloc |
|
141 void addEdge(const Vector2& p0, const Vector2& p1, const Vector2& t0, const Vector2& t1, unsigned int startFlags, unsigned int endFlags); //throws bad_alloc |
|
142 |
|
143 void addEndPath(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, bool subpathHasGeometry, unsigned int flags); //throws bad_alloc |
|
144 bool addLineTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, bool subpathHasGeometry); //throws bad_alloc |
|
145 bool addQuadTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, const Vector2& p2, bool subpathHasGeometry, float strokeWidth); //throws bad_alloc |
|
146 bool addCubicTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, const Vector2& p2, const Vector2& p3, bool subpathHasGeometry, float strokeWidth); //throws bad_alloc |
|
147 bool addArcTo(const Matrix3x3& pathToSurface, const Vector2& p0, RIfloat rh, RIfloat rv, RIfloat rot, const Vector2& p1, const Vector2& p1r, VGPathSegment segment, bool subpathHasGeometry, float strokeWidth); //throws bad_alloc |
|
148 |
|
149 void tessellate(const Matrix3x3& pathToSurface, float strokeWidth); //throws bad_alloc |
|
150 |
|
151 void normalizeForInterpolation(const Path* srcPath); //throws bad_alloc |
|
152 |
|
153 void interpolateStroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v0, const StrokeVertex& v1, RIfloat strokeWidth) const; //throws bad_alloc |
|
154 void doCap(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v, RIfloat strokeWidth, VGCapStyle capStyle) const; //throws bad_alloc |
|
155 void doJoin(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v0, const StrokeVertex& v1, RIfloat strokeWidth, VGJoinStyle joinStyle, RIfloat miterLimit) const; //throws bad_alloc |
|
156 |
|
157 //input data |
|
158 VGint m_format; |
|
159 VGPathDatatype m_datatype; |
|
160 RIfloat m_scale; |
|
161 RIfloat m_bias; |
|
162 VGbitfield m_capabilities; |
|
163 int m_referenceCount; |
|
164 Array<RIuint8> m_segments; |
|
165 Array<RIuint8> m_data; |
|
166 |
|
167 //data produced by tessellation |
|
168 struct VertexIndex |
|
169 { |
|
170 int start; |
|
171 int end; |
|
172 }; |
|
173 Array<Vertex> m_vertices; |
|
174 int m_numTessVertices; |
|
175 Array<VertexIndex> m_segmentToVertex; |
|
176 RIfloat m_userMinx; |
|
177 RIfloat m_userMiny; |
|
178 RIfloat m_userMaxx; |
|
179 RIfloat m_userMaxy; |
|
180 }; |
|
181 |
|
182 //============================================================================================== |
|
183 |
|
184 } //namespace OpenVGRI |
|
185 |
|
186 //============================================================================================== |
|
187 |
|
188 #endif /* __RIPATH_H */ |