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

feat: point cloud styling #2569

Merged
merged 75 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
6b13666
feat: Add ability to style objects in point clouds (#2104)
haakonflatval-cognite May 30, 2022
b893b29
fix: matrix rotation math (#2177)
haakonflatval-cognite May 31, 2022
31286a0
fix: cylinder handling (#2178)
haakonflatval-cognite May 31, 2022
c18b3be
Latest master
Savokr Jun 21, 2022
64d7c46
lint
Savokr Jun 21, 2022
3613a77
feat: Add ability to style objects in point clouds (#2104)
haakonflatval-cognite May 30, 2022
3308c6e
fix: matrix rotation math (#2177)
haakonflatval-cognite May 31, 2022
4609e1d
fix: cylinder handling (#2178)
haakonflatval-cognite May 31, 2022
d24e24f
Merge branch 'feat/point-cloud-styling' of https://github.com/cognite…
Savokr Jun 21, 2022
abb6642
chore: Fix triple import error and sdk-playground version from latest…
Savokr Jun 22, 2022
5414b2a
chore: update point cloud feature branch (#2264)
haakonflatval-cognite Jul 4, 2022
ac3e0f8
chore: update point cloud feature branch (#2277)
haakonflatval-cognite Jul 15, 2022
aecf717
feat: point cloud API for styling (#2179)
haakonflatval-cognite Jul 18, 2022
5018205
feat: libraries in workers (#2269)
haakonflatval-cognite Aug 2, 2022
af815bc
improvement: Return annotationId of clicked point cloud object when d…
Savokr Aug 4, 2022
1ce4078
feat: add workerize for cleaner interop with workers (#2321)
christjt Aug 5, 2022
a400e08
Merge branch 'master' into hflatval/update-point-cloud-feature-branch…
haakonflatval-cognite Aug 26, 2022
8795a53
feat: Webassembly setup (#2353)
haakonflatval-cognite Aug 26, 2022
0e754a9
Update point cloud feature branch from master (#2416)
haakonflatval-cognite Sep 9, 2022
269dea0
feat: Rust/Webassembly octree implementation for faster point-object …
haakonflatval-cognite Sep 16, 2022
d2c61a3
chore: update feature branch from master
haakonflatval-cognite Sep 27, 2022
1c84ab5
Merge commit '22fd033caa5317c6fe92f57bcc529928d2465e41' into temp/poi…
haakonflatval-cognite Oct 11, 2022
3ae0e11
feat: custom classification (#2320)
haakonflatval-cognite Sep 29, 2022
ca1fcc1
docs: finalize point cloud styling docs (#2500)
haakonflatval-cognite Oct 4, 2022
97de3e6
refactor: move point cloud object provider to data-providers and expo…
haakonflatval-cognite Oct 5, 2022
3322ba8
fix: point cloud custom transformation (#2550)
haakonflatval-cognite Oct 10, 2022
d903b99
improvement: various fixes for point clouds (#2551)
haakonflatval-cognite Oct 10, 2022
b22e987
Merge branch 'master' into hflatval/update-point-cloud-feature-branch6
haakonflatval-cognite Oct 12, 2022
a923c5f
fix: export point cloud object metadata (#2552)
haakonflatval-cognite Oct 12, 2022
4f349e2
refactor: point cloud styling package (#2560)
haakonflatval-cognite Oct 14, 2022
ada4be2
Merge branch 'master' into feat/point-cloud-styling
haakonflatval-cognite Oct 14, 2022
c4dd3ad
chore: lint fix
haakonflatval-cognite Oct 14, 2022
27f8fca
fix: add back file that shouldn't be removed here
haakonflatval-cognite Oct 14, 2022
3fd1d3f
chore: revert unnecessary changes to ci.yml
haakonflatval-cognite Oct 14, 2022
054500f
cleanup: remove unnecessary change in README.md
haakonflatval-cognite Oct 14, 2022
bab3b41
docs: remove misleading doc entry
haakonflatval-cognite Oct 14, 2022
b3dcb10
fix: remove merge conflict marker
haakonflatval-cognite Oct 14, 2022
893b54a
fix: remove more merge conflict marks
haakonflatval-cognite Oct 14, 2022
499705f
fix: visual test constructor signature change
haakonflatval-cognite Oct 17, 2022
9fb7dc7
Merge refs/heads/master into feat/point-cloud-styling
cognite-bulldozer[bot] Oct 17, 2022
0ec16ba
Merge refs/heads/master into feat/point-cloud-styling
cognite-bulldozer[bot] Oct 17, 2022
88afb0f
Merge refs/heads/master into feat/point-cloud-styling
cognite-bulldozer[bot] Oct 17, 2022
9779360
fix: revert changes to GLSL
haakonflatval-cognite Oct 17, 2022
30e44b7
fix: initialize point cloud material manager earlier
haakonflatval-cognite Oct 17, 2022
a668f09
improvement: remove unnecessary change in Viewer.tsx
haakonflatval-cognite Oct 17, 2022
2656c74
improvement: revert irrelevant changes in examples
haakonflatval-cognite Oct 17, 2022
353dcf4
improvement: revert change to examples/yarn.lock
haakonflatval-cognite Oct 17, 2022
2bb3382
fix: correct wasm:clean manifest path
haakonflatval-cognite Oct 17, 2022
a8ee872
improvement: revert irrelevant line deletion
haakonflatval-cognite Oct 17, 2022
412d528
improvement: remove cad-models and pointclouds
haakonflatval-cognite Oct 17, 2022
54ebb63
improvement: fix grammar mistake in tsdoc
haakonflatval-cognite Oct 17, 2022
6775bbc
improvement: revert a couple of moves
haakonflatval-cognite Oct 17, 2022
9fd1e72
improvement: reorder arguments to PotreeNodeWrapper constructor
haakonflatval-cognite Oct 17, 2022
0d834ad
improvement: rename inner getter
haakonflatval-cognite Oct 17, 2022
ae9e469
improvement: remove unused type definition
haakonflatval-cognite Oct 17, 2022
12552f9
fix: remove package dependencies from yarn.lock too
haakonflatval-cognite Oct 17, 2022
2372fc0
improvement: remove yet another unused type definition
haakonflatval-cognite Oct 17, 2022
69b74c0
improvement: rename classification type
haakonflatval-cognite Oct 17, 2022
77b7c5d
fix: remove outdated wasm folder from gitignore
haakonflatval-cognite Oct 17, 2022
6b17354
fix: revert bad removal in package.json
haakonflatval-cognite Oct 17, 2022
421c510
refactor: use map's built-in index counter
haakonflatval-cognite Oct 17, 2022
5619fa0
improvement: split doc sentences to separate lines
haakonflatval-cognite Oct 17, 2022
7a38233
improvement: invert if
haakonflatval-cognite Oct 17, 2022
a912da2
fix: clarify promise awaiting with Promise.all
haakonflatval-cognite Oct 17, 2022
5df85f2
chore: lint fix
haakonflatval-cognite Oct 17, 2022
3aea2f0
improvement: contract return statement
haakonflatval-cognite Oct 17, 2022
b9f36b8
improvement: factor out types for point cloud worker
haakonflatval-cognite Oct 17, 2022
7386117
chore: lint fix
haakonflatval-cognite Oct 17, 2022
4fab476
fix: correct object ID assignment in annotation transformation
haakonflatval-cognite Oct 18, 2022
91c9730
fix: put back a couple more characters in viewer/package.json
haakonflatval-cognite Oct 18, 2022
8a02b97
refactor: rename SchemaEntry
haakonflatval-cognite Oct 18, 2022
e8aa2aa
improvement: reduce worker pool size
haakonflatval-cognite Oct 18, 2022
ebbb217
cleanup: remove legacy compile script
haakonflatval-cognite Oct 18, 2022
00abb8a
fix: lower-case lib field in tsconfig
haakonflatval-cognite Oct 18, 2022
13864dc
Merge branch 'master' into feat/point-cloud-styling
haakonflatval-cognite Oct 18, 2022
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
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ jobs:
continue-on-error: false
run: yarn run lint

- name: Rust fmt
working-directory: viewer
continue-on-error: false
run: |
rustup component add rustfmt
cargo fmt --check

# Skip to save time - development version is enough
# - name: Build prod version
# working-directory: viewer
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
target
**/wasm/pkg/

**/.DS_Store
**/dist
Expand Down Expand Up @@ -31,6 +32,7 @@ target
# Viewer ignores
.eslintcache
__diff_output__/
viewer/wasm/pkg/*
haakonflatval-cognite marked this conversation as resolved.
Show resolved Hide resolved

# Examples

Expand Down
17 changes: 17 additions & 0 deletions documentation/docs/examples/click-reactions-pointcloud.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,20 @@ viewer.on('click', async event => {
};
});
```

## Getting information about object assigned to a clicked point
Using Cognite's Annotations API, a user can define objects within a point cloud model. In order to retrieve information
about a clicked object, users may get the `annotationId` that is assigned to each point.
The `annotationId` is available in the `intersection` object returned from `viewer.getIntersectionFromPixel`. An annotation id of 0 means that the clicked point
is not assigned to any object.
haakonflatval-cognite marked this conversation as resolved.
Show resolved Hide resolved

```js runnable
viewer.on('click', async event => {
const intersection = await viewer.getIntersectionFromPixel(
event.offsetX, event.offsetY
);
if (intersection) {
alert(`Clicked object: ${intersection.annotationId}`);
};
});
```
91 changes: 91 additions & 0 deletions documentation/docs/examples/pointcloud-styling.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
id: pointcloud-styling
title: Pointcloud styling
description: Usage of the styling API for pointcloud models
---

Cognite Data Fusion has a concept of "objects" in point clouds, represented by one or more bounding volumes for
each object. The objects are backed by the [CDF Annotations API](https://docs.cognite.com/api/v1/#tag/Annotations).
Reveal supports styling individual objects within a point cloud.

import { DemoWrapper } from '@site/versioned_docs/version-4.x/components/DemoWrapper';

<DemoWrapper modelType="pointcloud" />

In this context, a _stylable object_ is represented by a volume in space. Styling an object results in all points that lie within the corresponding volume to attain the assigned style.

Stylable objects must be supplied separately from the model itself. Upon adding a new point cloud model to the viewer, Reveal will automatically fetch data describing the point cloud objects from CDF's Annotations API, if any are available. To get the number of fetched stylable objects, use the property `model.stylableObjectCount`, where `model` is a `CognitePointCloudModel`.

After the model and associated stylable objects are loaded, you may list the objects using `model.traverseStylableObjects`. This method traverses all objects as instances of `PointCloudObjectMetadata`, containing the following fields:

| Field | Field type | Description |
|----------------------------|---------------------------------|---------------------------------------------------------------------------------------|
| `annotationId` | `number` | The ID of the CDF annotation that this stylable object corresponds to. |
| `assetId` | `number?` | The ID of the CDF asset associated with the annotation, if any. |
| `boundingBox` | `THREE.Box3` | The bounding box of the stylable object in Reveal space. |

To visualize all bounding boxes associated with the stylable objects:

```js runnable
const boxGroup = new THREE.Group();

model.traverseStylableObjects(obj => boxGroup.add(new THREE.Box3Helper(obj.boundingBox)));

viewer.addObject3D(boxGroup);
```

Point cloud objects can be styled with a `PointCloudAppearance` object, containing the following attributes:

| Field | Field type | Description |
|----------------------------|---------------------------------|---------------------------------------------------------------------------------------|
| `color` | `[number, number, number]?` | Override color by setting RGB values in range [0,255]. `[0, 0, 0]` means no override. |
| `visible` | `boolean?` | When false, stylable object will be invisible. Default value is `true`. |

To assign a style to one or more stylable objects, you must first create an instance of the abstract class `PointCloudObjectCollection`. Currently, the only implementation of this class provided by Reveal is `AnnotationIdPointCloudObjectCollection`, which is initialized with a list of annotation IDs corresponding to stylable objects. To see all available annotation IDs associated with the model, you may use the method `model.traverseStylableObjects`.

To color all stylable objects green:

```js runnable
const annotationIds = [];

model.traverseStylableObjects(objectMetadata => annotationIds.push(objectMetadata.annotationId));

const objectCollection = new AnnotationIdPointCloudObjectCollection(annotationIds);
const appearance = { color: [0, 255, 0] };

model.assignStyledObjectCollection(objectCollection, appearance);
```

After assigning style to an object collection, you may use the property `model.styledCollections` to get a list of all object collections and their assigned styles registered on the model.

## Default appearance

It is also possible to set a default appearance for the point cloud using the `model.setDefaultPointCloudAppearance`. The following example makes all annotated objects visible, while hiding everything else:

```js runnable
const annotationIds = [];

model.traverseStylableObjects(annotationMetadata => annotationIds.push(annotationMetadata.annotationId));

const objectCollection = new AnnotationIdPointCloudObjectCollection(annotationIds);
const appearance = { visible: true };

model.assignStyledObjectCollection(objectCollection, appearance);
model.setDefaultPointCloudAppearance({ visible: false });
```

Like in CAD styling, stylable objects that are part of multiple styled object collections will attain the appearance of the object set whose first style assignment was last.

## Unassigning styled object collections

To reset style of an object collection, use `model.unassignStyledObjectCollection` with the previously styled `PointCloudObjectCollection` as argument. To reset all styled objects use `model.removeAllStyledCollections`

## Reset all styled object collections

To reset all styled object collections, use the method `model.removeAllStyledObjectCollections()`.

This example removes all style on stylable object collections and makes sure the rest of the point cloud is visible.
```js runnable
model.removeAllStyledObjectCollections();
model.setDefaultPointCloudAppearance({ visible: true });
```
3 changes: 2 additions & 1 deletion documentation/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
collapsed: false,
items: [
'examples/cad-basic',
'examples/pointcloud',
{
"Styling CAD models": [
'examples/cad-styling',
Expand All @@ -26,14 +27,14 @@ module.exports = {
'examples/cad-styling-custom',
]
},
'examples/pointcloud-styling',
'examples/cad-prioritized-nodes',
'examples/cad-transform-override',
'examples/cad-2doverlay',
'examples/cad-3dobjects',
'examples/node-visiting',
'examples/clipping',
'examples/cad-save-viewerstate',
'examples/pointcloud',
'examples/click-reactions-cad',
'examples/click-reactions-pointcloud',
'examples/antialiasing',
Expand Down
5 changes: 5 additions & 0 deletions documentation/src/plugins/remark-runnable-reveal-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const versionedImportNode = {
type: 'import',
value:
"import { LiveCodeSnippet } from '@site/versioned_docs/version-3.x/components/LiveCodeSnippet';",
},
'runnable-4x': {
type: 'import',
value:
"import { LiveCodeSnippet } from '@site/versioned_docs/version-4.x/components/LiveCodeSnippet';",
}
};

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 48 additions & 1 deletion documentation/yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions examples/src/pages/Viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { PointCloudUi } from '../utils/PointCloudUi';
import { ModelUi } from '../utils/ModelUi';
import { createSDKFromEnvironment } from '../utils/example-helpers';
import { PointCloudClassificationFilterUI } from '../utils/PointCloudClassificationFilterUI';
import { PointCloudObjectStylingUI } from '../utils/PointCloudObjectStylingUI';
import { CustomCameraManager } from '../utils/CustomCameraManager';
import { MeasurementUi } from '../utils/MeasurementUi';

Expand Down Expand Up @@ -183,8 +184,10 @@ export function Viewer() {
new NodeStylingUI(gui.addFolder(`Node styling #${modelUi.cadModels.length}`), client, viewer, model);
new BulkHtmlOverlayUI(gui.addFolder(`Node tagging #${modelUi.cadModels.length}`), viewer, model, client);
} else if (model instanceof CognitePointCloudModel) {
new PointCloudClassificationFilterUI(gui.addFolder(`Class filter #${modelUi.pointCloudModels.length}`), model);
const modelIndex = modelUi.pointCloudModels.length
new PointCloudClassificationFilterUI(gui.addFolder(`Class filter #${modelIndex}`), model);
pointCloudUi.applyToAllModels();
new PointCloudObjectStylingUI(gui.addFolder(`Point cloud object styling #${modelIndex}`), model, viewer);
}
}
const modelUi = new ModelUi(gui.addFolder('Models'), viewer, handleModelAdded);
Expand Down Expand Up @@ -338,8 +341,11 @@ export function Viewer() {
break;
case 'pointcloud':
{
const { pointIndex, point } = intersection;
console.log(`Clicked point with pointIndex ${pointIndex} at`, point);
const { point } = intersection;
console.log(`Clicked point assigned to the object with annotationId: ${intersection.annotationId} at`, point);
const sphere = new THREE.Mesh(new THREE.SphereGeometry(0.1), new THREE.MeshBasicMaterial({ color: 'red' }));
sphere.position.copy(point);
viewer.addObject3D(sphere);
}
break;
}
Expand Down
Loading