Skip to content

Commit

Permalink
fix: point cloud custom transformation (#2550)
Browse files Browse the repository at this point in the history
* fix: point cloud bounding box shenanigans

* test: add test for point cloud transformation

* fix: height visualization for point clouds

* chore: add type to test utility function

* Update viewer/test-utilities/src/createPointCloudModel.ts

Co-authored-by: Christopher J. Tannum <christopher.tannum@cognite.com>

* chore: reduce number of characters in code

Not in commit message

* chore: lint fix

Co-authored-by: Christopher J. Tannum <christopher.tannum@cognite.com>
  • Loading branch information
haakonflatval-cognite and christjt committed Oct 14, 2022
1 parent 97de3e6 commit 3322ba8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function cdfAnnotationsToPointCloudObjects(cdfAnnotations: CdfPointCloudObjectAn
return {
annotationId: cdfAnnotation.annotationId,
assetId: cdfAnnotation.assetId,
boundingBox: stylableObject.shape.createBoundingBox().applyMatrix4(cadFromCdfToThreeMatrix),
boundingBox: stylableObject.shape.createBoundingBox(),
stylableObject
};
});
Expand Down
22 changes: 22 additions & 0 deletions viewer/packages/pointclouds/src/PointCloudNode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*!
* Copyright 2022 Cognite AS
*/

import { PointCloudNode } from './PointCloudNode';
import { createPointCloudNode } from '../../../test-utilities';

import * as THREE from 'three';

describe(PointCloudNode.name, () => {
test('getModelTransformation returns transformation set by setModelTransformation', () => {
const node = createPointCloudNode();
const transform = new THREE.Matrix4()
.makeRotationFromEuler(new THREE.Euler(190, 35, 230))
.setPosition(new THREE.Vector3(12, 34, 12));

node.setModelTransformation(transform.clone());
const receivedTransform = node.getModelTransformation();

expect(receivedTransform).toEqual(transform);
});
});
9 changes: 3 additions & 6 deletions viewer/packages/pointclouds/src/PointCloudNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,14 @@ export class PointCloudNode extends THREE.Group {
return this._potreeNode.classNames;
}

getBoundingBox(outBbox?: THREE.Box3): THREE.Box3 {
outBbox = outBbox || new THREE.Box3();
getBoundingBox(outBbox: THREE.Box3 = new THREE.Box3()): THREE.Box3 {
outBbox.copy(this._potreeNode.boundingBox);
outBbox.applyMatrix4(this.matrixWorld);
return outBbox;
}

setModelTransformation(matrix: THREE.Matrix4): void {
this._potreeNode.octree.applyMatrix4(matrix);
this._potreeNode.octree.updateMatrix();
this._potreeNode.octree.updateWorldMatrix(true, true);
this.matrix.copy(matrix);
this.updateMatrixWorld(true);
}

getModelTransformation(out = new THREE.Matrix4()): THREE.Matrix4 {
Expand Down
6 changes: 2 additions & 4 deletions viewer/packages/pointclouds/src/PotreeNodeWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ export class PotreeNodeWrapper {
const box: THREE.Box3 =
this.octree.pcoGeometry.tightBoundingBox || this.octree.pcoGeometry.boundingBox || this.octree.boundingBox;
// Apply transformation to switch axes
const min = new THREE.Vector3(box.min.x, box.min.z, -box.min.y);
const max = new THREE.Vector3(box.max.x, box.max.z, -box.max.y);
return new THREE.Box3().setFromPoints([min, max]);
return box.clone().applyMatrix4(this.octree.matrixWorld);
}

get pointColorType(): PotreePointColorType {
Expand Down Expand Up @@ -178,7 +176,7 @@ export class PotreeNodeWrapper {
return {
annotationId: a.annotationId,
assetId: a.assetId,
boundingBox: a.boundingBox
boundingBox: a.boundingBox.clone().applyMatrix4(this.octree.matrixWorld)
};
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export class PointCloudOctree extends PointCloudTree {
}

private updateMaterial(): void {
this.material.heightMin = this.pcoGeometry.tightBoundingBox.min.clone().applyMatrix4(this.matrix).y;
this.material.heightMax = this.pcoGeometry.tightBoundingBox.max.clone().applyMatrix4(this.matrix).y;
this.material.heightMin = this.pcoGeometry.tightBoundingBox.min.clone().applyMatrix4(this.matrixWorld).y;
this.material.heightMax = this.pcoGeometry.tightBoundingBox.max.clone().applyMatrix4(this.matrixWorld).y;
}

dispose(): void {
Expand Down
2 changes: 1 addition & 1 deletion viewer/test-utilities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export { createV9SceneSectorMetadata } from './src/createSceneSectorMetadata';

export { createCadModelMetadata } from './src/createCadModelMetadata';
export { createCadModel } from './src/createCadModel';
export { createPointCloudModel } from './src/createPointCloudModel';
export { createPointCloudModel, createPointCloudNode } from './src/createPointCloudModel';

export { mockClientAuthentication } from './src/cogniteClientAuth';

Expand Down
12 changes: 7 additions & 5 deletions viewer/test-utilities/src/createPointCloudModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import { LocalModelDataProvider } from '../../packages/data-providers';
import { IPointCloudTreeGeometry } from '../../packages/pointclouds/src/potree-three-loader/geometry/IPointCloudTreeGeometry';

export function createPointCloudModel(modelId: number, revisionId: number): CognitePointCloudModel {
const pointCloudNode = createPointCloudNode();

return new CognitePointCloudModel(modelId, revisionId, pointCloudNode);
}

export function createPointCloudNode(): PointCloudNode {
const modelDataProvider = new LocalModelDataProvider();
const potreeInstance = new Potree(modelDataProvider);

Expand All @@ -39,9 +45,5 @@ export function createPointCloudModel(modelId: number, revisionId: number): Cogn

const nodeWrapper = new PotreeNodeWrapper(pointCloudOctree, [], Symbol('dummy'), { classificationSets: [] });

const pointCloudNode = new PointCloudNode(potreeGroup, nodeWrapper);

const pointCloudModel = new CognitePointCloudModel(modelId, revisionId, pointCloudNode);

return pointCloudModel;
return new PointCloudNode(potreeGroup, nodeWrapper);
}

0 comments on commit 3322ba8

Please sign in to comment.