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