@@ -5,25 +5,55 @@ import { ProjectProperties } from "."
5
5
import { numberSocket , numericDataSocket } from "../socket_types"
6
6
import { workerPool } from '../../../modelling/workerPool'
7
7
import { maskFromExtentAndShape } from "../bounding_box"
8
- import { NumericConstant } from "../numeric_constant"
9
8
import { NumericTileGrid } from "../tile_grid"
9
+ import { SelectControl , SelectControlOptions } from "../controls/select"
10
+ import { InterpolationType } from "../../../modelling/worker/interpolation"
11
+ import { NumericConstant } from "../numeric_constant"
12
+
13
+ interface InterpolationMethodOption extends SelectControlOptions {
14
+ value : InterpolationType
15
+ }
16
+
17
+ const InterpolationMethods : InterpolationMethodOption [ ] = [
18
+ {
19
+ id : 0 ,
20
+ name : 'Nearest Neighbour' ,
21
+ value : 'NearestNeighbour'
22
+ } ,
23
+ {
24
+ id : 1 ,
25
+ name : "Inverse Distance Weighting" ,
26
+ value : 'InverseDistanceWeighting'
27
+ }
28
+ ]
10
29
11
30
export class InterpolationComponent extends BaseComponent {
12
31
projectProps : ProjectProperties
13
32
maxdist : number
33
+ p : number
34
+ closest_points : number
14
35
cache : Map < number , Map < NumericTileGrid , NumericTileGrid > >
15
36
16
37
constructor ( projectProps : ProjectProperties ) {
17
38
super ( "Interpolation" )
18
39
this . category = "Calculations"
19
40
this . projectProps = projectProps
20
41
this . maxdist = 50
42
+ this . p = 2
43
+ this . closest_points = 10
21
44
this . cache = new Map ( )
22
45
}
23
46
24
47
async builder ( node : Node ) {
48
+
49
+ node . addControl ( new SelectControl ( this . editor , 'methodId' , ( ) => InterpolationMethods , ( ) => { } , 'Method' ) )
50
+
25
51
node . addInput ( new Input ( 'input' , 'Input' , numericDataSocket ) )
26
- node . addInput ( new Input ( 'maxdist' , `maxdist (default: ${ this . maxdist } )` , numberSocket ) )
52
+ node . addInput ( new Input ( 'maxdist' , `Max Distance (default: ${ this . maxdist } )` , numberSocket ) )
53
+ node . addInput ( new Input ( 'p' , `Power (default: ${ this . p } )` , numberSocket ) )
54
+ node . addInput ( new Input ( 'closest_points' , `Closest Points (default: ${ this . closest_points } )` , numberSocket ) )
55
+
56
+
27
57
node . addOutput ( new Output ( 'output' , 'Output' , numericDataSocket ) )
28
58
}
29
59
@@ -40,7 +70,12 @@ export class InterpolationComponent extends BaseComponent {
40
70
this . projectProps . mask
41
71
)
42
72
43
- const maxDist = inputs [ 'maxdist' ] . length > 0 ? ( inputs [ 'maxdist' ] [ 0 ] as NumericConstant ) . value : this . maxdist
73
+
74
+ const method = InterpolationMethods [ node . data . methodId as number ?? 0 ]
75
+
76
+ const maxDist = inputs [ 'maxdist' ] . length > 0 ? ( inputs [ 'maxdist' ] [ 0 ] as NumericConstant ) . value : this . maxdist
77
+ const p = inputs [ 'p' ] . length > 0 ? ( inputs [ 'p' ] [ 0 ] as NumericConstant ) . value : this . p
78
+ const closest_points = inputs [ 'closest_points' ] . length > 0 ? ( inputs [ 'closest_points' ] [ 0 ] as NumericConstant ) . value : this . closest_points
44
79
const input = inputs [ 'input' ] [ 0 ] as NumericTileGrid
45
80
46
81
// TODO: Caching doesn't work
@@ -53,9 +88,8 @@ export class InterpolationComponent extends BaseComponent {
53
88
}
54
89
}
55
90
56
-
57
91
const out = await workerPool . queue ( async worker =>
58
- worker . interpolateGrid ( inputs [ 'input' ] [ 0 ] , mask , "NearestNeighbour" , maxDist )
92
+ worker . interpolateGrid ( inputs [ 'input' ] [ 0 ] , mask , method . value , maxDist , p , closest_points )
59
93
)
60
94
61
95
const map = this . cache . get ( maxDist ) || new Map ( )
0 commit comments