Skip to content

Commit

Permalink
fix: correct point cloud volume <-> asset mapping (#4966)
Browse files Browse the repository at this point in the history
* fix(react-components): correct asset <-> point cloud volume mapping

* chore: correct list method with empty input

* test: fix tests

* chore: bump version to 4.23.1
  • Loading branch information
haakonflatval-cognite authored Jan 22, 2025
1 parent d36e312 commit bde1540
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export async function listMappedFdmNodes(
limit: number,
fdmSdk: FdmSDK
): Promise<NodeItem[]> {
if (revisionRefs.length === 0) {
return [];
}

const filter = makeSureNonEmptyFilterForRequest(instancesFilter);

const rawQuery = cadAndPointCloudAssetQuery(sourcesToSearch, filter, limit);
Expand Down
2 changes: 1 addition & 1 deletion viewer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cognite/reveal",
"version": "4.23.0",
"version": "4.23.1",
"description": "WebGL based 3D viewer for CAD and point clouds processed in Cognite Data Fusion.",
"homepage": "https://github.com/cognitedata/reveal/tree/master/viewer",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const mock = {
cdf_cdm: {
'CognitePointCloudVolume/v1': {
volume: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
volumeType: 'Box'
volumeType: 'Box',
object3D: { externalId: 'obj3d0', space: 'objSpace' }
}
}
}
Expand All @@ -59,7 +60,8 @@ const mock = {
cdf_cdm: {
'CognitePointCloudVolume/v1': {
volume: [-0.03, 0.1, -1000, -0.03, 0.1, 1000, 0.04],
volumeType: 'Cylinder'
volumeType: 'Cylinder',
object3D: { externalId: 'obj3d1', space: 'objSpace' }
}
}
}
Expand All @@ -72,15 +74,29 @@ const mock = {
space: 'test_space',
externalId: 'test_asset_1',
createdTime: 0,
lastUpdatedTime: 0
lastUpdatedTime: 0,
properties: {
cdf_cdm: {
'CogniteAsset/v1': {
object3D: { externalId: 'obj3d0', space: 'objSpace' }
}
}
}
},
{
instanceType: 'node',
version: 1,
space: 'test_space',
externalId: 'test_asset_2',
createdTime: 0,
lastUpdatedTime: 0
lastUpdatedTime: 0,
properties: {
cdf_cdm: {
'CogniteAsset/v1': {
object3D: { externalId: 'obj3d1', space: 'objSpace' }
}
}
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { PointCloudVolumeObject3DProperties } from './types';
import { CdfPointCloudObjectAnnotation } from '../types';
import { QueryNextCursors } from '../../types';

import { IShape, Box, Cylinder } from '@reveal/utilities';
import { IShape, Box, Cylinder, DMInstanceKey, dmInstanceRefToKey, DMInstanceRef } from '@reveal/utilities';
import { DMModelIdentifierType } from '../../DataSourceType';

type QueryResult = Awaited<ReturnType<typeof DataModelsSdk.prototype.queryNodesAndEdges<CdfDMPointCloudVolumeQuery>>>;
Expand Down Expand Up @@ -46,43 +46,62 @@ export async function getDMPointCloudObjects(
};
const query = getDMPointCloudVolumeCollectionQuery(modelIdentifier.revisionExternalId, modelIdentifier.revisionSpace);

const annotationLimit = query.with.pointCloudVolumes.limit;
const assetLimit = query.with.assets.limit;
const volumeLimit = query.with.pointCloudVolumes.limit;
let nextCursor: QueryNextCursors<CdfDMPointCloudVolumeQuery> | undefined = undefined;
let hasNext = true;

type AssetResult = ExhaustedQueryResult['assets'][number];

while (hasNext) {
const {
pointCloudVolumes,
assets,
nextCursor: currentCursor
}: QueryResult = await dmsSdk.queryNodesAndEdges(query, nextCursor);
if (result.pointCloudVolumes.length === 0) {
result.pointCloudVolumes.push(...pointCloudVolumes);
}
result.pointCloudVolumes.push(...pointCloudVolumes);
result.assets.push(...assets);

hasNext = assets.length === annotationLimit && currentCursor?.assets !== undefined;
nextCursor = {
assets: currentCursor?.assets
};
hasNext =
(assets.length === assetLimit && currentCursor?.assets !== undefined) ||
(pointCloudVolumes.length === volumeLimit && currentCursor?.pointCloudVolumes !== undefined);
nextCursor = currentCursor;
}

const annotations: CdfPointCloudObjectAnnotation[] = result.pointCloudVolumes.map((volume, index) => {
const pointCloudVolumeProperties = volume.properties.cdf_cdm[
'CognitePointCloudVolume/v1'
] as unknown as PointCloudVolumeObject3DProperties;
const region = pointCloudVolumeToRevealShapes(
pointCloudVolumeProperties.volume,
pointCloudVolumeProperties.volumeType
);

return {
volumeMetadata: {
instanceRef: { externalId: volume.externalId, space: volume.space },
asset: { externalId: result.assets[index].externalId, space: result.assets[index].space }
},
region: [region]
};
});
const object3DAndAssetPairs: [DMInstanceKey, AssetResult][] = result.assets.map(asset => [
dmInstanceRefToKey(asset.properties.cdf_cdm['CogniteAsset/v1'].object3D as DMInstanceRef),
asset
]);

const object3DToAssetMap = new Map<DMInstanceKey, AssetResult>(object3DAndAssetPairs);

const annotations: CdfPointCloudObjectAnnotation[] = result.pointCloudVolumes
.map(volume => {
const pointCloudVolumeProperties = volume.properties.cdf_cdm[
'CognitePointCloudVolume/v1'
] as unknown as PointCloudVolumeObject3DProperties;
const region = pointCloudVolumeToRevealShapes(
pointCloudVolumeProperties.volume,
pointCloudVolumeProperties.volumeType
);

const asset = object3DToAssetMap.get(
dmInstanceRefToKey(volume.properties.cdf_cdm['CognitePointCloudVolume/v1'].object3D as DMInstanceRef)
);

if (asset === undefined) {
return undefined;
}

return {
volumeMetadata: {
instanceRef: { externalId: volume.externalId, space: volume.space },
asset: { externalId: asset.externalId, space: asset.space }
},
region: [region]
};
})
.filter(result => result !== undefined);

return annotations;
}

0 comments on commit bde1540

Please sign in to comment.