1
1
import { vtkObject } from "../../../interfaces" ;
2
2
import { Bounds , TypedArray , Vector3 } from "../../../types" ;
3
+ import vtkPoints from "../../Core/Points" ;
4
+ import vtkCell from "../Cell" ;
3
5
4
6
export interface IPolygonInitialValues {
5
- firstPoint ?: Vector3 ,
6
- pointCount ?: number ,
7
- tris ?: Vector3 [ ] ,
7
+ pointCount ?: number ;
8
+ tris ?: Vector3 [ ] ;
8
9
}
9
10
10
11
/**
11
12
* Different states which pointInPolygon could return.
12
13
*/
13
- export enum PolygonIntersectionState {
14
+ export enum PolygonWithPointIntersectionState {
14
15
FAILURE ,
15
16
OUTSIDE ,
16
17
INSIDE ,
17
- INTERSECTION ,
18
- ON_LINE ,
18
+ }
19
+
20
+ /**
21
+ * Different states that intersectWith2DConvexCell could return.
22
+ */
23
+ export enum PolygonWithCellIntersectionState {
24
+ NO_INTERSECTION ,
25
+ LINE_INTERSECTION ,
26
+ POINT_INTERSECTION ,
27
+ OVERLAP ,
28
+ INCLUDED
29
+ }
30
+
31
+ interface IIntersectWithLine {
32
+ intersection : boolean ;
33
+ betweenPoints : boolean ;
34
+ t : number ;
35
+ x : Vector3 ;
19
36
}
20
37
21
38
export interface vtkPolygon extends vtkObject {
39
+ /**
40
+ * Set the polygon's points
41
+ * Points must be ordered in counterclockwise order
42
+ * @param {Vector3[]|Array<number> } points The polygon's points.
43
+ * @param {Array<number> } pointIds pointIds
44
+ */
45
+ setPoints ( points : Vector3 [ ] | Array < number > , pointIds ?: Array < number > ) : void ;
46
+
47
+ /**
48
+ * Get the bounds for this polygon as [xmin, xmax, ymin, ymax, zmin, zmax].
49
+ * @return {Bounds } bounds
50
+ */
51
+ getBounds ( ) : Bounds
52
+
53
+ /**
54
+ * Computes the polygon normal
55
+ * @return {number } norm of normal (before normalization)
56
+ */
57
+ computeNormal ( ) : number ;
22
58
23
59
/**
24
- * Get the array of triangles that triangulate the polygon.
60
+ * Determine whether a point is inside a polygon. The function uses a winding
61
+ * number calculation generalized to the 3D plane one which the polygon
62
+ * resides. Returns OUTSIDE if point is not in the polygon; INSIDE if it is inside. Can
63
+ * also return FAILURE to indicate a degenerate polygon (points non coplanar or on a line).
64
+ * This implementation is inspired by Dan Sunday's algorithm found in the book Practical
65
+ * Geometry Algorithms.
66
+ * @param {Vector3 } point Point to check
67
+ * @return {PolygonWithPointIntersectionState } type of intersection
25
68
*/
26
- getPointArray ( ) : Vector3 [ ] ;
69
+ pointInPolygon ( point : Vector3 ) : PolygonWithPointIntersectionState ;
27
70
28
71
/**
29
- * Set the polygon's points.
30
- * @param {Vector3[] } points The polygon's points.
72
+ * Compute ear triangulation of current polygon
73
+ * The polygon must be convex and have at least 3 points
74
+ * @return {boolean } whether triangulation failed or not
31
75
*/
32
- setPoints ( points : Vector3 [ ] ) : void ;
76
+ triangulate ( ) : boolean ;
33
77
34
78
/**
35
- * Triangulate this polygon.
36
- * The output data must be accessed through `getPointArray`.
37
- * The output data contains points by group of three: each three-group
38
- * defines one triangle.
79
+ * Returns the centroid of this polygon
80
+ * @return {Vector3 } centroid
39
81
*/
40
- triangulate ( ) : void ;
82
+ computeCentroid ( ) : Vector3 ;
41
83
84
+ /**
85
+ * Returns the area of the polygon
86
+ * @return {number } area
87
+ */
88
+ computeArea ( ) : number ;
89
+
90
+ /**
91
+ * Returns whether the polygon is convex or not
92
+ * Returns false for degenerate polygon
93
+ * @return {boolean } is convex or not
94
+ */
95
+ isConvex ( ) : boolean ;
96
+
97
+ /**
98
+ * Interpolates functions with polygon points
99
+ * @param {Vector3 } point point to compute the interpolation on
100
+ * @param {boolean } useMVCInterpolation
101
+ * @return weights corresponding to each point of polygon parametrizing the given point
102
+ */
103
+ interpolateFunctions (
104
+ point : Vector3 ,
105
+ useMVCInterpolation : boolean
106
+ ) : number [ ] ;
107
+
108
+ /**
109
+ * Computes intersection of polygon with a line defined by two points
110
+ * @param {Vector3 } x1 first point of line
111
+ * @param {Vector3 } x2 second point of line
112
+ * @return intersection point coordinates
113
+ */
114
+ intersectWithLine ( x1 : Vector3 , x2 : Vector3 ) : IIntersectWithLine ;
115
+
116
+ /**
117
+ * Computes intersection of polygon with another cell.
118
+ * It can be a line, a point, no intersection or coincident
119
+ * Note: Expects both polygons/cell to be convex
120
+ * @param {vtkCell } cell polygon or any object extending from vtkCell with which to compute intersection
121
+ * Note : the function intersectWithLine need to be implemented on the class of the cell given
122
+ * @return {PolygonWithCellIntersectionState } type of intersection
123
+ */
124
+ intersectConvex2DCells (
125
+ cell : vtkCell
126
+ ) : PolygonWithCellIntersectionState ;
42
127
}
43
128
129
+ // ---------------------------------------------------
130
+ /**
131
+ * Compute the normal of a polygon and return its squared norm.
132
+ * @param {vtkPoints } points
133
+ * @param {Vector3 } normal
134
+ * @return {number }
135
+ */
136
+ export function getNormal (
137
+ points : vtkPoints ,
138
+ normal : Vector3
139
+ ) : number ;
140
+
141
+ /**
142
+ * Get the bounds for these points as [xmin, xmax, ymin, ymax,zmin, zmax].
143
+ * @param {vtkPoints } points
144
+ * @return {Bounds }
145
+ */
146
+ export function getBounds ( points : vtkPoints ) : Bounds ;
147
+
148
+ /**
149
+ * Determines whether a polygon is convex
150
+ * @param {vtkPoints } points vtkPoints defining the polygon
151
+ * @return {boolean } whether the polygon is convex or not
152
+ */
153
+ export function isConvex ( points : vtkPoints ) : boolean ;
154
+
155
+ /**
156
+ * Given a set of points, computes the centroid of the corresponding polygon
157
+ * @param {vtkPoints } points vtkPoints defining the polygon
158
+ * @param {Vector3 } normal normal to the polygon of which the centroid is computed
159
+ * @return {Vector3 } centroid. Returns null for degenerate polygon
160
+ */
161
+ export function computeCentroid ( points : vtkPoints , normal : Vector3 ) : Vector3 ;
162
+
163
+ /**
164
+ * Given a set of points, computes the area of the corresponding polygon
165
+ * @param {vtkPoints } points vtkPoints defining the polygon
166
+ * @param {Vector3 } normal normal to the polygon of which the centroid is computed
167
+ * @return {number } area of polygon
168
+ */
169
+ export function computeArea ( points : vtkPoints , normal : Vector3 ) : number ;
170
+
44
171
/**
45
172
* Determine whether a point is inside a polygon. The function uses a winding
46
173
* number calculation generalized to the 3D plane one which the polygon
47
- * resides. Returns 0 if point is not in the polygon; 1 if it is inside. Can
48
- * also return -1 to indicate a degenerate polygon. This implementation is
174
+ * resides. Returns OUTSIDE if point is not in the polygon; INSIDE if it is inside. Can
175
+ * also return FAILURE to indicate a degenerate polygon. This implementation is
49
176
* inspired by Dan Sunday's algorithm found in the book Practical Geometry
50
177
* Algorithms.
51
178
*
52
179
* @param {Vector3 } point Point to check
53
- * @param {Array<Number >|TypedArray } vertices Vertices of the polygon
180
+ * @param {Array<number >|TypedArray } vertices Vertices of the polygon
54
181
* @param {Bounds } bounds Bounds of the vertices
55
182
* @param {Vector3 } normal Normal vector of the polygon
56
- * @returns { PolygonIntersectionState } Integer indicating the type of intersection
183
+ * @return { PolygonWithPointIntersectionState } Integer indicating the type of intersection
57
184
*/
58
185
export function pointInPolygon (
59
- point : Vector3 ,
60
- vertices : Array < number > | TypedArray ,
61
- bounds : Bounds ,
62
- normal : Vector3
63
- ) : PolygonIntersectionState ;
186
+ point : Vector3 ,
187
+ vertices : Array < number > | TypedArray ,
188
+ bounds : Bounds ,
189
+ normal : Vector3
190
+ ) : PolygonWithPointIntersectionState ;
191
+
192
+ /**
193
+ * Given a set of points that define a polygon, determines whether a line defined
194
+ * by two points intersect with the polygon. There can be no intersection, a point
195
+ * intersection or a line intersection.
196
+ * @param {Vector3 } p1 first point of the line
197
+ * @param {Vector3 } p2 second point of the line
198
+ * @param {vtkPoints } points points defining the polygon
199
+ * @param {Vector3 } normal normal to the polygon
200
+ * @return {IIntersectWithLine } type of intersection
201
+ */
202
+ export function intersectWithLine (
203
+ p1 : Vector3 ,
204
+ p2 : Vector3 ,
205
+ points : vtkPoints ,
206
+ normal : Vector3
207
+ ) : IIntersectWithLine ;
208
+
209
+ /**
210
+ * Given a set of points that define a polygon and another polygon, computes their
211
+ * intersection. It can be a line, a point, no intersection or coincident
212
+ * Note: Expects both polygons need to be convex
213
+ * @param {vtkCell } cell polygon or any object extending from vtkCell with which to compute intersection
214
+ * Note : the function intersectWithLine need to be implemented on the class of the cell given
215
+ * @param {vtkPoints } points points defining the polygon
216
+ * @param {Vector3 } normal normal to the polygon
217
+ * @return {PolygonWithCellIntersectionState } type of intersection
218
+ */
219
+ export function intersectConvex2DCells (
220
+ cell : vtkCell ,
221
+ points : vtkPoints ,
222
+ normal : Vector3
223
+ ) : PolygonWithCellIntersectionState ;
224
+
225
+ /**
226
+ * Given a set of points, computes the weights corresponding to the interpolation of the
227
+ * given point with regard to the points of the polygon. The returned array corresponds to
228
+ * the weights and therefore its size is the number of points in the polygon
229
+ * @param {Vector3 } point point we want the interpolation of
230
+ * @param {vtkPoints } points points defining the polygon
231
+ * @param {boolean } useMVCInterpolation whether to use MVC interpolation
232
+ */
233
+ export function interpolateFunctions (
234
+ point : Vector3 ,
235
+ points : vtkPoints ,
236
+ useMVCInterpolation : boolean
237
+ ) : Array < number > ;
64
238
65
239
/**
66
240
* Method used to decorate a given object (publicAPI+model) with vtkPolygon characteristics.
@@ -69,7 +243,11 @@ export function pointInPolygon(
69
243
* @param model object on which data structure will be bounds (protected)
70
244
* @param {IPolygonInitialValues } [initialValues] (default: {})
71
245
*/
72
- export function extend ( publicAPI : object , model : object , initialValues ?: IPolygonInitialValues ) : void ;
246
+ export function extend (
247
+ publicAPI : object ,
248
+ model : object ,
249
+ initialValues ?: IPolygonInitialValues
250
+ ) : void ;
73
251
74
252
/**
75
253
* Method used to create a new instance of vtkPolygon.
@@ -79,15 +257,14 @@ export function newInstance(initialValues?: IPolygonInitialValues): vtkPolygon;
79
257
80
258
/**
81
259
* vtkPolygon represents a 2D n-sided polygon.
82
- *
260
+ *
83
261
* The polygons cannot have any internal holes, and cannot self-intersect.
84
262
* Define the polygon with n-points ordered in the counter-clockwise direction.
85
263
* Do not repeat the last point.
86
264
*/
87
265
export declare const vtkPolygon : {
88
- newInstance : typeof newInstance ,
266
+ newInstance : typeof newInstance ;
89
267
extend : typeof extend ;
90
268
// static
91
-
92
269
} ;
93
270
export default vtkPolygon ;
0 commit comments