Skip to content

Commit

Permalink
feat: 360 Image Annotation CDM support (#4954)
Browse files Browse the repository at this point in the history
* temp: checkpoint in work for enabling 360 CDM support

* chore: bring to compiling state

* chore: some more code shuffling

* chore: add missing files

* chore: remove unintended file

* chore: change up API a bit more

* chore: commit reasonable API changes

* chore: that one too, that's also reasonable

* chore: more API changes

* chore: corrections to API

* chore: fix a few more API changes

* chore: more fixes

* chore: lint fix

* chore: remove unnecessary changes

* chore: remove empty file

* chore: attempt to redo API by deprecating DataSourceType

* Revert "chore: attempt to redo API by deprecating DataSourceType"

This reverts commit 6ab203c.

* test: fix tests

* chore: some more fixes

* chore: correct types in examples

* chore: reintroduce ObjectDetection annotations etc

* chore: update Image360UI to work with CDM-360 images

* chore: last fixes to 360 image loading

* chore: add missing line in yarn lock

* chore: fix type in Image360 visual test

* chore: fix visual test (I hope)

* chore: fix overly pedantic type errors

* chore: update API again

* chore: cleanup imports somewhat

* chore: remove unnecessary file

* chore: a few more fixes / simplifications

* chore: fix annotation rotation

* chore: fix annotation rotation again

* chore: Add actual test

(Yeah, I know, crazy)
  • Loading branch information
haakonflatval-cognite authored Jan 14, 2025
1 parent 16ed4b2 commit bb8d80a
Show file tree
Hide file tree
Showing 88 changed files with 2,610 additions and 838 deletions.
16 changes: 11 additions & 5 deletions examples/src/utils/Image360UI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
Image360Collection,
Image360Annotation,
Image360AnnotationIntersection,
DataSourceType
DataSourceType,
Image360DataModelIdentifier
} from '@cognite/reveal';

import * as dat from 'dat.gui';
Expand All @@ -18,15 +19,17 @@ export class Image360UI {
private viewer: Cognite3DViewer<DataSourceType>;
private gui: dat.GUI;
private selectedEntity: Image360 | undefined;
private _lastAnnotation: Image360Annotation | undefined = undefined;
private _lastAnnotation: Image360Annotation<DataSourceType> | undefined = undefined;

private async handleIntersectionAsync(intersectionPromise: Promise<Image360AnnotationIntersection | null>) {
private async handleIntersectionAsync(
intersectionPromise: Promise<Image360AnnotationIntersection<DataSourceType> | null>
) {
const intersection = await intersectionPromise;
if (intersection === null) {
return;
}

console.log('Clicked annotation with data: ', intersection.annotation.annotation.data);
console.log('Clicked annotation with data: ', intersection.annotation.annotation);
intersection.annotation.setColor(new THREE.Color(0.8, 0.8, 1.0));
this.viewer.requestRedraw();
this._lastAnnotation = intersection.annotation;
Expand All @@ -41,6 +44,7 @@ export class Image360UI {
removeAll: () => this.removeAll360Images(),
saveToUrl: () => this.saveImage360SiteToUrl(),
assetId: '',
image360DmSource: 'cdm' as Image360DataModelIdentifier['source'],
findAsset: () => this.findAsset()
};

Expand Down Expand Up @@ -117,6 +121,7 @@ export class Image360UI {
// data models
optionsFolderFdm.add(this.params, 'siteId').name('External ID');
optionsFolderFdm.add(this.params, 'space').name('Space');
optionsFolderFdm.add(this.params, 'image360DmSource', ['cdm', 'dm']).name('Source');

this.gui.add(this.params, 'add').name('Add image set');
this.gui.add(this.params, 'remove').name('Remove image set');
Expand Down Expand Up @@ -236,7 +241,8 @@ export class Image360UI {
if (this.dataSource.type === 'dataModels') {
return this.viewer.add360ImageSet('datamodels', {
image360CollectionExternalId: this.params.siteId,
space: this.params.space
space: this.params.space,
source: this.params.image360DmSource
});
}

Expand Down
14 changes: 11 additions & 3 deletions viewer/api-entry-points/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export {
PointerEventDelegate,
PointerEventData,
DisposedDelegate,
DMInstanceRef,
ICustomObject,
CustomObject,
CustomObjectIntersection,
Expand All @@ -83,17 +84,23 @@ export {

export {
PointCloudObjectMetadata,
CoreDmImage360Annotation,
ImageAssetLinkAnnotationInfo,
Image360DataModelIdentifier,
DMInstanceRef,
Image360BaseIdentifier,
Image360CoreDataModelIdentifier,
Image360LegacyDataModelIdentifier,
Image360Id,
Image360RevisionId,
DataSourceType,
ClassicDataSourceType,
DMDataSourceType,
ClassicModelIdentifierType,
DMModelIdentifierType,
isDMPointCloudVolume,
isClassicPointCloudVolume,
CommonModelOptions
CommonModelOptions,
InstanceReference
} from '../packages/data-providers';

export { CogniteCadModel, BoundingBoxClipper, GeometryFilter, WellKnownUnit } from '../packages/cad-model';
Expand Down Expand Up @@ -127,7 +134,8 @@ export {
Image360AnnotationAssetFilter,
Image360AnnotationAssetQueryResult,
Image360AnnotationFilterOptions,
Image360Action
Image360Action,
InstanceLinkable360ImageAnnotationType
} from '../packages/360-images';

export {
Expand Down
7 changes: 6 additions & 1 deletion viewer/packages/360-images/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export {
Image360Collection,
Image360AnnotationAssetFilter,
Image360AnnotationAssetQueryResult,
InstanceLinkable360ImageAnnotationType,
AssetAnnotationImage360Info
} from './src/collection/Image360Collection';
export { Image360Facade } from './src/Image360Facade';
Expand All @@ -21,5 +22,9 @@ export { Image360AnnotationIntersection } from './src/annotation/Image360Annotat
export { Image360Annotation } from './src/annotation/Image360Annotation';
export { DefaultImage360Collection } from './src/collection/DefaultImage360Collection';
export { IconsOptions } from './src/icons/IconCollection';
export { Image360History } from './src/Image360History';
export { Image360CollectionSourceType, Image360IconIntersectionData } from './src/types';
export { Image360AnnotationFilter } from './src/annotation/Image360AnnotationFilter';
export { DEFAULT_IMAGE_360_OPACITY } from './src/entity/Image360VisualizationBox';
export { Image360Action } from './src/Image360Action';
export { Image360History } from './src/Image360History';
export { createCollectionIdString } from './src/collection/createCollectionIdString';
12 changes: 6 additions & 6 deletions viewer/packages/360-images/src/Image360Facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Image360IconIntersectionData } from './types';
export class Image360Facade<T extends DataSourceType> {
private readonly _image360Collections: DefaultImage360Collection<T>[];
private readonly _rayCaster: THREE.Raycaster;
private readonly _image360Cache: Image360LoadingCache;
private readonly _image360Cache: Image360LoadingCache<T>;

private readonly _loadSequencer = new AsyncSequencer();

Expand Down Expand Up @@ -49,23 +49,23 @@ export class Image360Facade<T extends DataSourceType> {
this._image360Collections.forEach(collection => collection.setCullingScheme(scheme));
}

constructor(private readonly _entityFactory: Image360CollectionFactory<T>) {
constructor(private readonly _entityFactory: Image360CollectionFactory) {
this._image360Collections = [];
this._rayCaster = new THREE.Raycaster();
this._image360Cache = new Image360LoadingCache();
}

public async create(
dataProviderFilter: T['image360Identifier'],
public async create<Image360CollectionSourceType extends DataSourceType>(
collectionIdentifier: Image360CollectionSourceType['image360Identifier'],
annotationFilter: Image360AnnotationFilterOptions = {},
postTransform = new THREE.Matrix4(),
preComputedRotation = true
): Promise<DefaultImage360Collection<T>> {
const sequencer = this._loadSequencer.getNextSequencer();

try {
const image360Collection = await this._entityFactory.create(
dataProviderFilter,
const image360Collection = await this._entityFactory.create<T>(
collectionIdentifier,
postTransform,
preComputedRotation,
annotationFilter
Expand Down
9 changes: 5 additions & 4 deletions viewer/packages/360-images/src/Image360History.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
* Copyright 2022 Cognite AS
*/

import { DataSourceType } from '@reveal/data-providers';
import { Image360 } from './entity/Image360';
import { Image360Action } from './Image360Action';

export class Image360History {
private readonly _images: Image360[] = [];
private readonly _images: Image360<DataSourceType>[] = [];
private _currentIndex: number = -1; // Negative mean no current index (avoid empty because of harder logic)

public start(image: Image360): void {
public start(image: Image360<DataSourceType>): void {
if (this.isLegalIndex(this._currentIndex + 1)) {
this._images.slice(this._currentIndex + 1);
}
Expand All @@ -20,7 +21,7 @@ export class Image360History {
this._currentIndex = this._images.length - 1;
}

private current(): Image360 | undefined {
private current(): Image360<DataSourceType> | undefined {
if (!this.isLegalIndex(this._currentIndex)) {
return undefined;
}
Expand Down Expand Up @@ -49,7 +50,7 @@ export class Image360History {
}
}

public doAction(action: Image360Action): Image360 | undefined {
public doAction(action: Image360Action): Image360<DataSourceType> | undefined {
let currentIndex = this._currentIndex;
switch (action) {
case Image360Action.Forward:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Copyright 2023 Cognite AS
*/

import { AnnotationModel, AnnotationStatus } from '@cognite/sdk';
import { Image360AnnotationFilterOptions } from './types';
import isArray from 'lodash/isArray';
import { DataSourceType } from '@reveal/data-providers';

export class Image360AnnotationFilter {
private readonly _annotationFilter: Required<Image360AnnotationFilterOptions>;
Expand All @@ -22,17 +22,17 @@ export class Image360AnnotationFilter {
this._annotationFilter = this.fillDefaultAnnotationOptionValues(options);
}

private filterStatus(annotation: AnnotationModel): boolean {
private filterStatus(annotation: DataSourceType['image360AnnotationType']): boolean {
if (this._annotationFilter.status === 'all') {
return true;
} else if (isArray(this._annotationFilter.status)) {
return this._annotationFilter.status.indexOf(annotation.status as AnnotationStatus) !== -1;
return this._annotationFilter.status.indexOf(annotation.status) !== -1;
} else {
return this._annotationFilter.status === annotation.status;
}
}

filter(annotation: AnnotationModel): boolean {
filter(annotation: DataSourceType['image360AnnotationType']): boolean {
return this.filterStatus(annotation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
* Copyright 2023 Cognite AS
*/

import { ClassicDataSourceType, DataSourceType } from '@reveal/data-providers';
import { Image360Annotation } from './Image360Annotation';
import { Vector3 } from 'three';

/**
* Describes an intersection with a 360 image annotation
*/
export type Image360AnnotationIntersection = {
export type Image360AnnotationIntersection<T extends DataSourceType = ClassicDataSourceType> = {
/**
* The intersection type.
*/
type: 'image360Annotation';
/**
* The intersected annotation
*/
annotation: Image360Annotation;
annotation: Image360Annotation<T>;
/**
* The world direction from the camera to the intersection point
*/
Expand Down
11 changes: 0 additions & 11 deletions viewer/packages/360-images/src/annotation/ImageAnnotationData.ts

This file was deleted.

Loading

0 comments on commit bb8d80a

Please sign in to comment.