Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply graph filter on spatial cameras #324

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions debug/spatial.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@
spatial.configure(c);
}

var filterIndex = 0;
var filters = [
[],
["==", "fullPano", true],
["==", "sequenceKey", "s5I5m7BvYykB677MpFnOIw"],
["in", "sequenceKey", "s5I5m7BvYykB677MpFnOIw", "-aC4wx-8oOkCp6SFGXoyAg"],
];
function setFilter() {
filterIndex = (filterIndex + 1) % filters.length;
viewer.setFilter(filters[filterIndex]).then(
function (n) {
console.log("filter", filters[filterIndex]);
});
}

window.document.addEventListener(
"keydown",
e => {
Expand All @@ -98,6 +113,7 @@
case 'w': changeSize('pointSize', 1.1); break;
case 'a': changeSize('cameraSize', 0.9); break;
case 's': changeSize('cameraSize', 1.1); break;
case 'f': setFilter(); break;
default: break;
}

Expand Down
15 changes: 7 additions & 8 deletions spec/helper/GraphServiceMockCreator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import {Subject} from "rxjs";
import { Subject } from "rxjs";

import {MockCreator} from "./MockCreator.spec";
import {MockCreatorBase} from "./MockCreatorBase.spec";
import { MockCreator } from "./MockCreator.spec";
import { MockCreatorBase } from "./MockCreatorBase.spec";

import {EdgeDirection} from "../../src/Edge";
import {
GraphMode,
GraphService,
} from "../../src/Graph";
import GraphService from "../../src/graph/GraphService";
import GraphMode from "../../src/graph/GraphMode";
import { FilterFunction } from "../../src/graph/FilterCreator";

export class GraphServiceMockCreator extends MockCreatorBase<GraphService> {
public create(): GraphService {
const mock: GraphService = new MockCreator().create(GraphService, "GraphService");

this._mockProperty(mock, "graphMode$", new Subject<GraphMode>());
this._mockProperty(mock, "filter$", new Subject<FilterFunction>());

return mock;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export { RouteComponent } from "./component/RouteComponent";
export { SequenceComponent } from "./component/sequence/SequenceComponent";
export { SequenceDOMRenderer } from "./component/sequence/SequenceDOMRenderer";
export { SequenceMode } from "./component/sequence/SequenceMode";
export { NodeData, SpatialDataCache } from "./component/spatialdata/SpatialDataCache";
export { SpatialDataCache } from "./component/spatialdata/SpatialDataCache";
export { SpatialDataComponent } from "./component/spatialdata/SpatialDataComponent";
export { SpatialDataScene } from "./component/spatialdata/SpatialDataScene";
export { ImagePlaneComponent } from "./component/imageplane/ImagePlaneComponent";
Expand Down
92 changes: 14 additions & 78 deletions src/component/spatialdata/SpatialDataCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,12 @@ import {
filter,
} from "rxjs/operators";

import {
IGPano,
} from "../../API";
import {
AbortMapillaryError,
} from "../../Error";
import {
GraphService,
Node,
} from "../../Graph";
import { CameraProjectionType } from "../../api/interfaces/CameraProjectionType";
import { IDataProvider } from "../../api/interfaces/interfaces";
import AbortMapillaryError from "../../error/AbortMapillaryError";
import GraphService from "../../graph/GraphService";
import IDataProvider from "../../api/interfaces/IDataProvider";
import IClusterReconstruction from "../../api/interfaces/IClusterReconstruction";
import ICellCorners from "../../api/interfaces/ICellCorners";

export type NodeData = {
alt: number;
cameraProjectionType: CameraProjectionType;
clusterKey: string;
clusterUrl: string;
focal: number;
gpano: IGPano;
height: number;
k1: number;
k2: number;
key: string,
lat: number;
lon: number;
mergeCC: number;
orientation: number;
originalLat: number;
originalLon: number;
rotation: number[];
scale: number;
sequenceKey: string;
width: number;
};
import Node from "../../graph/Node";

type ClusterData = {
key: string;
Expand All @@ -65,14 +34,14 @@ export class SpatialDataCache {
private _data: IDataProvider;

private _cacheRequests: { [hash: string]: Function[] };
private _tiles: { [hash: string]: NodeData[] };
private _tiles: { [hash: string]: Node[] };

private _clusterReconstructions: { [key: string]: IClusterReconstruction };
private _clusterReconstructionTiles: { [key: string]: string[] };
private _tileClusters: { [hash: string]: ClusterData[] };

private _cachingClusterReconstructions$: { [hash: string]: Observable<IClusterReconstruction> };
private _cachingTiles$: { [hash: string]: Observable<NodeData[]> };
private _cachingTiles$: { [hash: string]: Observable<Node[]> };

constructor(graphService: GraphService, provider: IDataProvider) {
this._graphService = graphService;
Expand Down Expand Up @@ -104,12 +73,12 @@ export class SpatialDataCache {

const duplicatedClusters: ClusterData[] = this.getTile(hash)
.filter(
(nd: NodeData): boolean => {
return !!nd.clusterKey && !!nd.clusterUrl;
(n: Node): boolean => {
return !!n.clusterKey && !!n.clusterUrl;
})
.map(
(nd: NodeData): ClusterData => {
return { key: nd.clusterKey, url: nd.clusterUrl };
(n: Node): ClusterData => {
return { key: n.clusterKey, url: n.clusterUrl };
});

const clusters: ClusterData[] = Array
Expand Down Expand Up @@ -186,7 +155,7 @@ export class SpatialDataCache {
return this._cachingClusterReconstructions$[hash];
}

public cacheTile$(hash: string): Observable<NodeData[]> {
public cacheTile$(hash: string): Observable<Node[]> {
if (this.hasTile(hash)) {
throw new Error("Cannot cache tile that already exists.");
}
Expand All @@ -205,22 +174,14 @@ export class SpatialDataCache {

return observableEmpty();
}),
map(
(nodes: Node[]): NodeData[] => {
return nodes
.map(
(n: Node): NodeData => {
return this._createNodeData(n);
});
}),
filter(
(): boolean => {
return !(hash in this._tiles);
}),
tap(
(nodeData: NodeData[]): void => {
(node: Node[]): void => {
this._tiles[hash] = [];
this._tiles[hash].push(...nodeData);
this._tiles[hash].push(...node);

delete this._cachingTiles$[hash];
}),
Expand Down Expand Up @@ -277,7 +238,7 @@ export class SpatialDataCache {
[];
}

public getTile(hash: string): NodeData[] {
public getTile(hash: string): Node[] {
return hash in this._tiles ? this._tiles[hash] : [];
}

Expand Down Expand Up @@ -331,31 +292,6 @@ export class SpatialDataCache {
}
}

private _createNodeData(node: Node): NodeData {
return {
alt: node.alt,
cameraProjectionType: node.cameraProjectionType,
clusterKey: node.clusterKey,
clusterUrl: node.clusterUrl,
focal: node.focal,
gpano: node.gpano,
height: node.height,
k1: node.ck1,
k2: node.ck2,
key: node.key,
lat: node.latLon.lat,
lon: node.latLon.lon,
mergeCC: node.mergeCC,
orientation: node.orientation,
originalLat: node.originalLatLon.lat,
originalLon: node.originalLatLon.lon,
rotation: [node.rotation[0], node.rotation[1], node.rotation[2]],
scale: node.scale,
sequenceKey: node.sequenceKey,
width: node.width,
};
}

private _getClusterReconstruction(key: string): IClusterReconstruction {
return this._clusterReconstructions[key];
}
Expand Down
Loading