Skip to content

Commit

Permalink
fix(tmp): tmp
Browse files Browse the repository at this point in the history
tmp
  • Loading branch information
joannacirillo committed Aug 10, 2022
1 parent 2bd06dd commit b9ec532
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 65 deletions.
201 changes: 142 additions & 59 deletions Sources/Common/DataModel/Polygon/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
import { vtkObject } from "../../../interfaces";
import { Bounds, Vector3 } from "../../../types";
import { vtkObject } from '../../../interfaces';
import { Bounds, Vector3 } from '../../../types';
import vtkPoints from '../../Core/Points';

export interface IPolygonInitialValues {
firstPoint?: Vector3,
pointCount?: number,
tris?: Vector3[],
pointCount?: number;
tris?: Vector3[];
}

/**
* Different states which pointInPolygon could return.
*/
export enum POINT_IN_POLYGON {
FAILURE,
OUTSIDE,
INSIDE,
INTERSECTION,
ON_LINE,
export enum PolygonWithPointIntersectionState {
FAILURE,
OUTSIDE,
INSIDE,
}

export enum INTERSECTION {
/**
* Different states which intersectWith2DConvexCell could return.
*/
export enum PolygonWithPolygonIntersectionState {
NO_INTERSECTION,
LINE_INTERSECTION,
POINT_INTERSECTION,
};

interface IIntersectWithLine {
intersection: boolean;
betweenPoints: boolean;
t: number;
x: Vector3;
}

export const INTERSECTION = {
NO_INTERSECTION: 0,
LINE_INTERSECTION: 1,
POINT_INTERSECTION: 2,
interface IIntersectWithLine {
intersection: boolean;
betweenPoints: boolean;
t: number;
x: Vector3;
}

export interface vtkPolygon extends vtkObject {

/**
/**
* Get the array of triangles that triangulate the polygon.
*/
getPointArray(): Vector3[];
Expand All @@ -51,6 +45,12 @@ export interface vtkPolygon extends vtkObject {
*/
setPoints(points: Vector3[]): void;

/**
* Computes the polygon normal
* @return {number} squared norm before normalization
*/
computeNormal(): number;

/**
* Triangulate this polygon.
* The output data must be accessed through `getPointArray`.
Expand All @@ -59,25 +59,18 @@ export interface vtkPolygon extends vtkObject {
*/
triangulate(): void;

/**
* Determine whether a point is inside a polygon. The function uses a winding
* number calculation generalized to the 3D plane one which the polygon
* resides. Returns 0 if point is not in the polygon; 1 if it is inside. Can
* also return -1 to indicate a degenerate polygon. This implementation is
* inspired by Dan Sunday's algorithm found in the book Practical Geometry
* Algorithms.
* @param {Vector3} point Point to check
* @param {Vector3[]} vertices Vertices of the polygon
* @param {Bounds} bounds Bounds of the vertices
* @param {Vector3} normal normal vector of the polygon
*/
pointInPolygon(
point: Vector3,
vertices: Vector3[],
bounds: Bounds,
normal: Vector3
): number;

/**
* Determine whether a point is inside a polygon. The function uses a winding
* number calculation generalized to the 3D plane one which the polygon
* resides. Returns OUTSIDE if point is not in the polygon; INSIDE if it is inside. Can
* also return FAILURE to indicate a degenerate polygon. This implementation is
* inspired by Dan Sunday's algorithm found in the book Practical Geometry
* Algorithms.
* @param {Vector3} point Point to check
* @return {PolygonWithPointIntersectionState} type of intersection
*/
pointInPolygon(point: Vector3): PolygonWithPointIntersectionState;

/**
* Compute ear triangulation of current polygon
* The polygon must be convex and have at least 3 points
Expand Down Expand Up @@ -107,33 +100,73 @@ export interface vtkPolygon extends vtkObject {
/**
* Interpolates functions with polygon points
* @param point point to compute the interpolation on
* @param useMVCInterpolation
* @param useMVCInterpolation
* @return weights corresponding to each point of polygon parametrizing the given point
*/
interpolateFunctions(point: Vector3, useMVCInterpolation: boolean): Number[]
interpolateFunctions(point: Vector3, useMVCInterpolation: boolean): Number[];

/**
* Computes intersection of polygon with a line defined by two points
* @param p1 first point of line
* @param p2 second point of line
* @param x1 first point of line
* @param x2 second point of line
* @return intersection point coordinates
*/
intersectWithLine(p1: Vector3, p2: Vector3): IIntersectWithLine
intersectWithLine(x1: Vector3, x2: Vector3): IIntersectWithLine;

/**
* Computes the intersection between two polygons
* The two points p0 and p1 describe the intersection. If no intersection is found, p0 and p1 are left null.
* If the intersection is only one point, p1 is left null
* @return {INTERSECTION} type of intersection (no, one point or line)
* Computes intersection of polygon with another polygon.
* It can be a line, a point or no intersection.
* Note: Expects both polygons to be convex
* @param polygon vtkPolygon with which to compute intersection
* @return {PolygonWithPolygonIntersectionState} type of intersection
*/
intersectConvex2DCells(polygon: vtkPolygon, tol: number, p0: Vector3, p1: Vector3): INTERSECTION
intersectConvex2DCells(
polygon: vtkPolygon
): PolygonWithPolygonIntersectionState;
}

// ---------------------------------------------------
/**
* Compute the normal of a polygon and return its squared norm.
* @param {Array<number>|TypedArray<number>} poly
* @param {vtkPoints} points
* @param {Vector3} normal
* @returns {number}
*/
export function getNormal(
poly: Vector3[],
points: vtkPoints,
normal: Vector3
): number;

/**
* Determines whether a polygon is convex
* @param points vtkPoints defining the polygon
* @return {boolean} whether the polygon is convex or not
*/
export function isConvex(points: vtkPoints): boolean;

/**
* Given a set of points, computes the centroid of the corresponding polygon
* @param points vtkPoints defining the polygon
* @param normal normal to the polygon of which the centroid is computed
* @return {Vector3} centroid. Returns null for degenerate polygon
*/
export function computeCentroid(points: vtkPoints, normal: Vector3): Vector3;

/**
* Given a set of points, computes the area of the corresponding polygon
* @param points vtkPoints defining the polygon
* @param normal normal to the polygon of which the centroid is computed
* @return {number} area of polygon
*/
export function computeArea(points: vtkPoints, normal: Vector3): number;

/**
* Determine whether a point is inside a polygon. The function uses a winding
* number calculation generalized to the 3D plane one which the polygon
* resides. Returns 0 if point is not in the polygon; 1 if it is inside. Can
* also return -1 to indicate a degenerate polygon. This implementation is
* resides. Returns OUTSIDE if point is not in the polygon; INSIDE if it is inside. Can
* also return FAILURE to indicate a degenerate polygon. This implementation is
* inspired by Dan Sunday's algorithm found in the book Practical Geometry
* Algorithms.
*
Expand All @@ -145,19 +178,69 @@ export interface vtkPolygon extends vtkObject {
*/
export function pointInPolygon(
point: Vector3,
vertices: Array|TypedArray,
vertices: Array | TypedArray,
bounds: Bounds,
normal: Vector3
): PolygonIntersectionState;

/**
* Given a set of points that define a polygon, determines whether a line defined
* by two points intersect with the polygon. There can be no intersection, a point
* intersection or a line intersection.
* @param p1 first point of the line
* @param p2 second point of the line
* @param points points defining the polygon
* @param normal normal to the polygon
* @return {IIntersectWithLine} type of intersection
*/
export function intersectWithLine(
p1: Vector3,
p2: Vector3,
points: vtkPoints,
normal: Vector3
): IIntersectWithLine;

/**
* Given a set of points that define a polygon and another polygon, computes their
* intersection. It can be a line, a point or no intersection.
* Note: Expects both polygons to be convex
* @param polygon vtkPolygon with which to compute intersection
* @param points points defining the polygon
* @param normal normal to the polygon
* @return {PolygonWithPolygonIntersectionState} type of intersection
*/
export function intersectConvex2DCells(
polygon: vtkPolygon,
points: vtkPoints,
normal: Vector3
): PolygonWithPolygonIntersectionState;

/**
* Given a set of points, computes the weights corresponding to the interpolation of the
* given point with regard to the points of the polygon. The returned array corresponds to
* the weights and therefore its size is the number of points in the polygon
* @param point point we want the interpolation of
* @param points points defining the polygon
* @param useMVCInterpolation whether to use MVC interpolation
*/
export function interpolateFunctions(
point: Vector3,
points: vtkPoints,
useMVCInterpolation: boolean
): Array<number>;

/**
* Method used to decorate a given object (publicAPI+model) with vtkPolygon characteristics.
*
* @param publicAPI object on which methods will be bounds (public)
* @param model object on which data structure will be bounds (protected)
* @param {IPolygonInitialValues} [initialValues] (default: {})
*/
export function extend(publicAPI: object, model: object, initialValues?: IPolygonInitialValues): void;
export function extend(
publicAPI: object,
model: object,
initialValues?: IPolygonInitialValues
): void;

/**
* Method used to create a new instance of vtkPolygon.
Expand All @@ -173,7 +256,7 @@ export function newInstance(initialValues?: IPolygonInitialValues): vtkPolygon;
* Do not repeat the last point.
*/
export declare const vtkPolygon: {
newInstance: typeof newInstance,
newInstance: typeof newInstance;
extend: typeof extend;
};
export default vtkPolygon;
12 changes: 6 additions & 6 deletions Sources/Common/DataModel/Polygon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export function getNormal(poly, points, normal) {
return norm2;
}

function isConvex(points) {
export function isConvex(points) {
let i;
const v = [
[0, 0, 0],
Expand Down Expand Up @@ -292,7 +292,7 @@ function isConvex(points) {
return true;
}

function computeCentroid(points, normal) {
export function computeCentroid(points, normal) {
const numPts = points.getNumberOfPoints();
// Strategy:
// - Compute centroid of projected polygon on (x,y) if polygon is projectible, (x,z) otherwise
Expand Down Expand Up @@ -357,7 +357,7 @@ function computeCentroid(points, normal) {
return c;
}

function computeArea(points, normal) {
export function computeArea(points, normal) {
const numPts = points.getNumberOfPoints();
if (numPts < 3) {
return 0.0;
Expand Down Expand Up @@ -601,7 +601,7 @@ function interpolateFunctionsUsingMVC(point, points) {
return weights;
}

function interpolateFunctions(point, points, useMVCInterpolation) {
export function interpolateFunctions(point, points, useMVCInterpolation) {
// Compute interpolation weights using mean value coordinate.
if (useMVCInterpolation) {
return interpolateFunctionsUsingMVC(point, points);
Expand Down Expand Up @@ -703,7 +703,7 @@ function evaluatePosition(point, points, normal) {
return res;
}

function intersectWithLine(p1, p2, points, normal) {
export function intersectWithLine(p1, p2, points, normal) {
let outObj = {
intersection: false,
betweenPoints: false,
Expand Down Expand Up @@ -735,7 +735,7 @@ function intersectWithLine(p1, p2, points, normal) {
}

//------------------------------------------------------------------------------
function intersectConvex2DCells(polygon, points, normal) {
export function intersectConvex2DCells(polygon, points, normal) {
// Intersect the six total edges of the two triangles against each other. Two points are
// all that are required.
const numPts = points.getNumberOfPoints();
Expand Down

0 comments on commit b9ec532

Please sign in to comment.