Skip to content

Commit d69b7c9

Browse files
use IDW in 3D
1 parent 553213a commit d69b7c9

File tree

14 files changed

+112
-52
lines changed

14 files changed

+112
-52
lines changed

frontend/__test_support__/three_d_mocks.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import * as THREE from "three";
1010
import React, { ReactNode } from "react";
1111
import { TransitionFn, UseSpringProps } from "@react-spring/three";
1212
import { ThreeElements, ThreeEvent } from "@react-three/fiber";
13-
import { Cloud, Clouds, Image, Plane, Trail, Tube } from "@react-three/drei";
13+
import {
14+
Cloud, Clouds, Image, Instance, Instances, Plane, Trail, Tube,
15+
} from "@react-three/drei";
1416

1517
const GroupForTests = (props: ThreeElements["group"]) =>
1618
// @ts-expect-error Property does not exist on type JSX.IntrinsicElements
@@ -561,6 +563,10 @@ jest.mock("@react-three/drei", () => {
561563
...jest.requireActual("@react-three/drei"),
562564
useGLTF,
563565
shaderMaterial: jest.fn(),
566+
Instances: (props: React.ComponentProps<typeof Instances>) =>
567+
<div className={"instances"}>{props.children}</div>,
568+
Instance: (props: React.ComponentProps<typeof Instance>) =>
569+
<div className={"instance"}>{props.name}</div>,
564570
RoundedBox: ({ name }: { name: string }) =>
565571
<div className={"cylinder"}>{name}</div>,
566572
Plane: (props: React.ComponentProps<typeof Plane>) =>

frontend/farm_designer/__tests__/three_d_garden_map_test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ describe("<ThreeDGardenMap />", () => {
6161
sensors: [],
6262
sensorReadings: [],
6363
cameraCalibrationData: fakeCameraCalibrationData(),
64+
farmwareEnvs: [],
6465
});
6566

6667
it("converts props", () => {

frontend/farm_designer/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ export class RawFarmDesigner
238238
images={this.props.latestImages}
239239
sensorReadings={this.props.sensorReadings}
240240
sensors={this.props.sensors}
241+
farmwareEnvs={this.props.farmwareEnvs}
241242
cameraCalibrationData={this.props.cameraCalibrationData}
242243
getWebAppConfigValue={this.props.getConfigValue} />
243244
: <div

frontend/farm_designer/map/interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export interface GardenMapLegendProps {
6767
}
6868

6969
export type MapTransformProps = {
70-
quadrant: BotOriginQuadrant,
71-
gridSize: AxisNumberProperty
70+
quadrant: BotOriginQuadrant;
71+
gridSize: AxisNumberProperty;
7272
xySwap: boolean;
7373
};
7474

frontend/farm_designer/map/layers/points/interpolation_map.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
TaggedFarmwareEnv,
44
TaggedGenericPointer, TaggedPoint, TaggedSensorReading, Xyz,
55
} from "farmbot";
6-
import { MapTransformProps } from "../../interfaces";
6+
import { AxisNumberProperty, MapTransformProps } from "../../interfaces";
77
import { transformXY } from "../../util";
88
import { isUndefined, range, round, sum } from "lodash";
99
import { distance, findNearest } from "../../../../point_groups/other_sort_methods";
@@ -80,7 +80,7 @@ export const getZAtLocation =
8080
interface GenerateInterpolationMapDataProps {
8181
kind: "Point" | "SensorReading";
8282
points: (TaggedGenericPointer | TaggedSensorReading)[];
83-
mapTransformProps: MapTransformProps;
83+
gridSize: AxisNumberProperty;
8484
getColor(z: number): string;
8585
options: InterpolationOptions;
8686
}
@@ -104,10 +104,10 @@ const convertToPointObject =
104104

105105
export const generateData = (props: GenerateInterpolationMapDataProps) => {
106106
const points = selectMostRecentPoints(props.points);
107-
const { gridSize } = props.mapTransformProps;
107+
const { gridSize } = props;
108108
const { stepSize } = props.options;
109109
const hash = [
110-
JSON.stringify(points),
110+
JSON.stringify(points.map(p => p.uuid)),
111111
JSON.stringify(gridSize),
112112
JSON.stringify(props.options),
113113
].join("");

frontend/farm_designer/map/layers/points/point_layer.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ export function PointLayer(props: PointLayerProps) {
3636
props.interactions ? {} : { pointerEvents: "none" };
3737
const options = fetchInterpolationOptions(props.farmwareEnvs);
3838
generateData({
39-
kind: "Point", points: soilHeightPoints, mapTransformProps, getColor, options,
39+
kind: "Point",
40+
points: soilHeightPoints,
41+
gridSize: mapTransformProps.gridSize,
42+
getColor,
43+
options,
4044
});
4145
return <g id={"point-layer"} style={style}>
4246
{props.overlayVisible &&

frontend/farm_designer/map/layers/sensor_readings/sensor_readings_layer.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export function SensorReadingsLayer(props: SensorReadingsLayerProps) {
4343
filterMoistureReadings(sensorReadings, sensors);
4444
generateData({
4545
kind: "SensorReading",
46-
points: moistureReadings, mapTransformProps, getColor: getMoistureColor,
46+
points: moistureReadings,
47+
gridSize: mapTransformProps.gridSize,
48+
getColor: getMoistureColor,
4749
options,
4850
});
4951
return <g id="sensor-readings-layer">
@@ -66,7 +68,7 @@ export function SensorReadingsLayer(props: SensorReadingsLayerProps) {
6668
</g>;
6769
}
6870

69-
const getMoistureColor = (value: number) => {
71+
export const getMoistureColor = (value: number) => {
7072
const normalizedValue = round(255 * value / 1024);
7173
if (value > 900) { return "rgb(255, 255, 255)"; }
7274
return `rgb(0, 0, ${normalizedValue})`;

frontend/farm_designer/three_d_garden_map.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
import { clone } from "lodash";
88
import { BotPosition, SourceFbosConfig } from "../devices/interfaces";
99
import {
10-
ConfigurationName, TaggedCurve, TaggedGenericPointer, TaggedImage, TaggedPoint,
10+
ConfigurationName, TaggedCurve, TaggedFarmwareEnv, TaggedGenericPointer,
11+
TaggedImage, TaggedPoint,
1112
TaggedPointGroup, TaggedSensor, TaggedSensorReading, TaggedWeedPointer,
1213
} from "farmbot";
1314
import { CameraCalibrationData, DesignerState } from "./interfaces";
@@ -22,6 +23,7 @@ import { DeviceAccountSettings } from "farmbot/dist/resources/api_resources";
2223
import { SCENES } from "../settings/three_d_settings";
2324
import { get3DTime, latLng } from "../three_d_garden/time_travel";
2425
import { parseCalibrationData } from "./map/layers/images/map_image";
26+
import { fetchInterpolationOptions } from "./map/layers/points/interpolation_map";
2527

2628
export interface ThreeDGardenMapProps {
2729
botSize: BotSize;
@@ -48,6 +50,7 @@ export interface ThreeDGardenMapProps {
4850
sensorReadings: TaggedSensorReading[];
4951
sensors: TaggedSensor[];
5052
cameraCalibrationData: CameraCalibrationData;
53+
farmwareEnvs: TaggedFarmwareEnv[];
5154
}
5255

5356
export const ThreeDGardenMap = (props: ThreeDGardenMapProps) => {
@@ -162,6 +165,11 @@ export const ThreeDGardenMap = (props: ThreeDGardenMapProps) => {
162165
config.imgCenterX = camCalData.centerX;
163166
config.imgCenterY = camCalData.centerY;
164167

168+
const options = fetchInterpolationOptions(props.farmwareEnvs);
169+
config.interpolationStepSize = options.stepSize;
170+
config.interpolationUseNearest = options.useNearest;
171+
config.interpolationPower = options.power;
172+
165173
config.zoom = true;
166174
config.pan = true;
167175
config.rotate = !props.designer.threeDTopDownView;

frontend/three_d_garden/bed/__tests__/bed_test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ describe("<Bed />", () => {
100100
activeFocus: "",
101101
mapPoints: [],
102102
soilSurfaceGeometry: new BufferGeometry(),
103-
moistureSurfaceGeometry: new BufferGeometry(),
104103
getZ: () => 0,
105104
showMoistureMap: true,
105+
sensors: [],
106106
sensorReadings: [],
107107
showMoistureReadings: true,
108108
});

frontend/three_d_garden/bed/bed.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
import { AxisNumberProperty } from "../../farm_designer/map/interfaces";
2525
import {
2626
TaggedCurve, TaggedGenericPointer, TaggedImage,
27+
TaggedSensor,
2728
TaggedSensorReading,
2829
} from "farmbot";
2930
import { GetWebAppConfigValue } from "../../config_storage/actions";
@@ -108,9 +109,9 @@ export interface BedProps {
108109
getZ(x: number, y: number): number;
109110
images?: TaggedImage[];
110111
soilSurfaceGeometry: BufferGeometry;
111-
moistureSurfaceGeometry: BufferGeometry;
112112
showMoistureMap: boolean;
113113
showMoistureReadings: boolean;
114+
sensors: TaggedSensor[];
114115
sensorReadings: TaggedSensorReading[];
115116
}
116117

@@ -249,13 +250,13 @@ export const Bed = (props: BedProps) => {
249250
const moistureTexture = React.useMemo(() =>
250251
<MoistureTexture
251252
config={props.config}
253+
sensors={props.sensors}
252254
sensorReadings={props.sensorReadings}
253-
showMoistureReadings={props.showMoistureReadings}
254-
geometry={props.moistureSurfaceGeometry} />, [
255+
showMoistureReadings={props.showMoistureReadings} />, [
255256
props.config,
257+
props.sensors,
256258
props.sensorReadings,
257259
props.showMoistureReadings,
258-
props.moistureSurfaceGeometry,
259260
]);
260261

261262
const SurfaceHeightMaterial = (props: { children: React.ReactNode }) =>
@@ -394,7 +395,7 @@ export const Bed = (props: BedProps) => {
394395
</React.Suspense>
395396
{props.config.moistureDebug &&
396397
<MoistureSurface
397-
geometry={props.moistureSurfaceGeometry}
398+
sensors={props.sensors}
398399
sensorReadings={props.sensorReadings}
399400
showMoistureReadings={true}
400401
config={props.config}

0 commit comments

Comments
 (0)