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