Skip to content

Commit

Permalink
Fix reality capture sdks examples and readme files.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbiguenet committed Oct 30, 2024
1 parent b062ae9 commit 2a767c5
Show file tree
Hide file tree
Showing 20 changed files with 113 additions and 91 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ lib/
coverage/
.env
.idea/

*.configStore/
dist/
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ Every change must be tested with proper unit tests.

### Build Instructions

See sub Readme files in typescript/packages, typescript/examples or python/ for more information about build instructions.
See Readme file for more information about build instructions.

> Note: It is a good idea to `npm install` after each `git pull` as dependencies may have changed.
> Note: It is a good idea to `pnpm install` after each `git pull` as dependencies may have changed.
### Making and Testing Changes

1. Make source code changes on a new Git branch
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright © 2023 Bentley Systems, Incorporated. All rights reserved.
Copyright © 2024 Bentley Systems, Incorporated. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Besides, a typescript web application example is available to show how to create

Reality data utils to upload and download results

- [Reality Data utils](./typescript/packages/reality-data-transfer/README.md)
- [Reality Data transfer utils](./typescript/packages/reality-data-transfer/README.md)

All the packages are available in python, except Reality Management

Expand All @@ -31,5 +31,5 @@ All the packages are available in python, except Reality Management

1. Clone repository (first time) with `git clone` or pull updates to the repository (subsequent times) with `git pull`
2. Install dependencies: `pnpm update` or `pnpm install`
3. Build source: `pnpm build`
4. Run unit tests : create a .env file based on template.env, then : `pnpm coverage`
3. Build source: `npm run build`
4. Run unit tests : create a .env file based on template.env, then : `npm run coverage`
21 changes: 14 additions & 7 deletions typescript/examples/code-samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ To build and run the source code locally you will need a few things:
- Build the project

```sh
pnpm run build
npm run build
```

- Create a new `.env` file, based on `template.env`. Fill in the required fields in the `.env` configuration file.
Expand All @@ -40,9 +40,16 @@ To build and run the source code locally you will need a few things:

- Run reality data creation example

- Run context capture example

```sh
cd examples/code-samples
npm run start-cc-example
```

```sh
cd examples/code-samples
npm run start-rd-example
npm run start-data-example
```

- Run 2d objects detection example
Expand All @@ -52,16 +59,16 @@ To build and run the source code locally you will need a few things:
npm run start-o2d-example
```

- Run 3d lines detection example
- Run reality conversion example

```sh
cd examples/code-samples
npm run start-l3d-example
npm run start-rcs-example
```

- Run context capture example
- Run 2d segmentation example

```sh
cd examples/code-samples
npm run start-cc-example
```
npm run start-s2d-example
```
6 changes: 3 additions & 3 deletions typescript/examples/code-samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"clean": "rimraf lib build .rush",
"lint": "eslint ./src --ext .ts,.tsx ",
"lint-fix": "eslint ./src --fix --ext .ts,.tsx",
"start-cc-example": "node ./lib/ContextCapture.js",
"start-l3d-example": "node ./lib/Lines3D.js",
"start-o2d-example": "node ./lib/Objects2D.js",
"start-modeling-example": "node ./lib/Modeling.js",
"start-data-example": "node ./lib/DataTransfer.js",
"start-o2d-example": "node ./lib/Objects2D.js",
"start-rcs-example": "node ./lib/RealityConversion.js",
"start-s2d-example": "node ./lib/Segmentation2D.js",
"coverage": "",
"integration-tests": ""
},
Expand Down
27 changes: 14 additions & 13 deletions typescript/examples/code-samples/src/DataTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import { RealityDataTransferNode, defaultProgressHook } from "@itwin/reality-dat
import { RealityDataType } from "@itwin/reality-capture-common";
import { NodeCliAuthorizationClient } from "@itwin/node-cli-authorization";


async function runRealityDataExample() {
const imageCollection = "path to the folder yu want to upload";
/**
* This example uploads an images folder in the cloud, and downloads it
*/
const images = "path to the images you want to upload";
const outputPath = "path to the folder where you want to save downloads";
const imageCollectionName = "Test Moto Photos";
const imagesName = "Test Upload Moto Photos";

dotenv.config();

const projectId = process.env.IMJS_PROJECT_ID ?? "";
const iTwinId = process.env.IMJS_PROJECT_ID ?? "";
const clientId = process.env.IMJS_CLIENT_ID ?? "";
const redirectUrl = process.env.IMJS_REDIRECT_URL ?? "";
const env = process.env.IMJS_ENV ?? "";
Expand All @@ -41,16 +43,15 @@ async function runRealityDataExample() {
realityDataService.setDownloadHook(defaultProgressHook);
console.log("Service initialized");

// Upload CCImageCollection
console.log("Uploading CCImagesCollection to cloud");
const id = await realityDataService.uploadRealityData(imageCollection, imageCollectionName,
RealityDataType.CC_IMAGE_COLLECTION, projectId);
console.log("CCImagesCollection uploaded successfully");
// Upload images
console.log("Uploading images to cloud");
const id = await realityDataService.uploadRealityData(images, imagesName, RealityDataType.CC_IMAGE_COLLECTION, iTwinId);
console.log("Images uploaded successfully");

// Download CCImageCollection
console.log("Downloading CCImagesCollection");
await realityDataService.downloadRealityData(id, outputPath, projectId);
console.log("CCImagesCollection downloaded successfully");
// Download images
console.log("Downloading images");
await realityDataService.downloadRealityData(id, outputPath, iTwinId);
console.log("Images downloaded successfully");
}

runRealityDataExample();
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ import { NodeCliAuthorizationClient } from "@itwin/node-cli-authorization";

export async function sleep(ms: number) { return new Promise(resolve => setTimeout(resolve, ms)); }

async function main() {
const ccImageCollection = "path to your image folder";
async function runModelingExample() {
/**
* This example submits a Full Modeling job (Calibration + Reconstruction), and will download the reconstruction output as a 3mx file.
*/
const images = "path to your image folder";
const ccOrientations = "path to the folder where your ccorientation file is";
const outputPath = "path to the folder where you want to save outputs";

dotenv.config();

const jobName = "Reality Modeling job SDK sample";
const workspaceName = "Reality Modeling test workspace";
const ccImageCollectionName = "Reality Modeling test photos";
const imagesName = "Reality Modeling test photos";
const ccOrientationsName = "Reality Modeling test ccorientations";

const projectId = process.env.IMJS_PROJECT_ID ?? "";
const iTwindId = process.env.IMJS_PROJECT_ID ?? "";
const clientId = process.env.IMJS_CLIENT_ID ?? "";
const redirectUrl = process.env.IMJS_REDIRECT_URL ?? "";
const env = process.env.IMJS_ENV ?? "";
Expand Down Expand Up @@ -60,40 +63,39 @@ async function main() {
console.log("Service initialized");

try {
// Creating reference table and uploading ccimageCollection, ccOrientations if necessary (not yet on the cloud)
// Creating reference table and uploading images, ccOrientations if necessary (not yet on the cloud)
const references = new ReferenceTableNode();
const referencesPath = path.join(outputPath, "test_references_typescript.txt");
if(fs.existsSync(referencesPath) && fs.lstatSync(referencesPath).isFile()) {
console.log("Loading preexistent references");
await references.load(referencesPath);
}

// Upload CCImageCollection
if(!references.hasLocalPath(ccImageCollection)) {
console.log("No reference to CCimage Collections found, uploading local files to cloud");
const id = await realityDataService.uploadRealityData(ccImageCollection, ccImageCollectionName,
RealityDataType.CC_IMAGE_COLLECTION, projectId);
references.addReference(ccImageCollection, id);
// Upload images
if(!references.hasLocalPath(images)) {
console.log("No reference to images found, uploading local files to cloud");
const id = await realityDataService.uploadRealityData(images, imagesName,
RealityDataType.CC_IMAGE_COLLECTION, iTwindId);
references.addReference(images, id);
}

// Upload Oriented photos (ccOrientations)
// Upload ccOrientations
if(!references.hasLocalPath(ccOrientations)) {
console.log("No reference to cc orientations found, uploading local files to cloud");
const id = await realityDataService.uploadCCOrientations(ccOrientations, ccOrientationsName, projectId, references);
const id = await realityDataService.uploadCCOrientations(ccOrientations, ccOrientationsName, iTwindId, references);
references.addReference(ccOrientations, id);
}

await references.save(referencesPath);
console.log("Checked data upload");

// Create workspace
const workspaceId = await contextCaptureService.createWorkspace(workspaceName, projectId);
const workspaceId = await contextCaptureService.createWorkspace(workspaceName, iTwindId);

const settings = new CCJobSettings();
settings.inputs = [references.getCloudIdFromLocalPath(ccImageCollection), references.getCloudIdFromLocalPath(ccOrientations)];
settings.inputs = [references.getCloudIdFromLocalPath(images), references.getCloudIdFromLocalPath(ccOrientations)];
settings.outputs.threeMX = "threeMX";
settings.meshQuality = CCJobQuality.MEDIUM;

settings.meshQuality = CCJobQuality.DRAFT;
console.log("Settings created");

const jobId = await contextCaptureService.createJob(CCJobType.FULL, settings, jobName, workspaceId);
Expand Down Expand Up @@ -129,12 +131,12 @@ async function main() {
const properties = await contextCaptureService.getJobProperties(jobId);
console.log("Downloading outputs");
const threeMXId = (properties.settings as CCJobSettings).outputs.threeMX;
realityDataService.downloadRealityData(threeMXId, outputPath, projectId);
realityDataService.downloadRealityData(threeMXId, outputPath, iTwindId);
console.log("Successfully downloaded output");
}
catch(error: any) {
console.log(error);
}
}

main();
runModelingExample();
32 changes: 19 additions & 13 deletions typescript/examples/code-samples/src/Objects2D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import * as fs from "fs";
import * as dotenv from "dotenv";
import { JobState, RealityDataType } from "@itwin/reality-capture-common";
import { NodeCliAuthorizationClient } from "@itwin/node-cli-authorization";
import { RealityDataTransferNode, ReferenceTableNode } from "@itwin/reality-data-transfer";
import { RealityDataTransferNode, ReferenceTableNode, defaultProgressHook } from "@itwin/reality-data-transfer";


export async function sleep(ms: number) { return new Promise(resolve => setTimeout(resolve, ms)); }

async function runObjects2DExample() {
const imageCollection = "path to your image collection";
const photoContextScene = "path to the folder where your context scene file is";
/**
* This example submits an objects2d analysis job, and downloads an annotations context scene
*/
const imageCollection = "path to your images";
const photoContextScene = "path to the folder where your context scene file is referenced";
const photoObjectDetector = "path to the folder where your detector is";
const outputPath = "path to the folder where you want to save outputs";
const outputPath = "path to the folder where you want to save the annotatations context scene";

dotenv.config();

Expand All @@ -27,7 +30,7 @@ async function runObjects2DExample() {
const contextSceneName = "Test Moto Scene";
const detectorName = "Test O2D Photo Detector";

const projectId = process.env.IMJS_PROJECT_ID ?? "";
const iTwinId = process.env.IMJS_PROJECT_ID ?? "";
const clientId = process.env.IMJS_CLIENT_ID ?? "";
const redirectUrl = process.env.IMJS_REDIRECT_URL ?? "";
const env = process.env.IMJS_ENV ?? "";
Expand All @@ -48,6 +51,9 @@ async function runObjects2DExample() {
else
realityDataService = new RealityDataTransferNode(authorizationClient.getAccessToken.bind(authorizationClient), "qa-");

realityDataService.setUploadHook(defaultProgressHook);
realityDataService.setDownloadHook(defaultProgressHook);

let realityDataAnalysisService;
if(env === "prod")
realityDataAnalysisService = new RealityDataAnalysisService(authorizationClient.getAccessToken.bind(authorizationClient));
Expand All @@ -57,34 +63,34 @@ async function runObjects2DExample() {
realityDataAnalysisService = new RealityDataAnalysisService(authorizationClient.getAccessToken.bind(authorizationClient), "dev-");
console.log("Service initialized");

// Creating reference table and uploading ccimageCollection, contextScene and detector if necessary (not yet on the cloud)
// Creating reference table and uploading images, contextScene and detector if necessary (not yet on the cloud)
const references = new ReferenceTableNode();
const referencesPath = path.join(outputPath, "test_references_typescript.txt");
if(fs.existsSync(referencesPath) && fs.lstatSync(referencesPath).isFile()) {
console.log("Loading preexistent references");
await references.load(referencesPath);
}

// Upload CCImageCollection
// Upload images
if(!references.hasLocalPath(imageCollection)) {
console.log("No reference to CCimage Collections found, uploading local files to cloud");
console.log("No reference to images found, uploading local files to cloud");
const id = await realityDataService.uploadRealityData(imageCollection, imageCollectionName,
RealityDataType.CC_IMAGE_COLLECTION, projectId);
RealityDataType.CC_IMAGE_COLLECTION, iTwinId);
references.addReference(imageCollection, id);
}

// Upload ContextScene
if(!references.hasLocalPath(photoContextScene)) {
console.log("No reference to ContextScene found, uploading local files to cloud");
const id = await realityDataService.uploadContextScene(photoContextScene, contextSceneName, projectId, references);
const id = await realityDataService.uploadContextScene(photoContextScene, contextSceneName, iTwinId, references);
references.addReference(photoContextScene, id);
}

// Upload Detector
if(!references.hasLocalPath(photoObjectDetector)) {
console.log("No reference to detector found, uploading local files to cloud");
const id = await realityDataService.uploadRealityData(photoObjectDetector, detectorName, RealityDataType.CONTEXT_DETECTOR,
projectId);
iTwinId);
references.addReference(photoObjectDetector, id);
}

Expand All @@ -97,7 +103,7 @@ async function runObjects2DExample() {
settings.outputs.objects2D = "objects2D";
console.log("Settings created");

const jobId = await realityDataAnalysisService.createJob(settings, jobName, projectId);
const jobId = await realityDataAnalysisService.createJob(settings, jobName, iTwinId);
console.log("Job created");

await realityDataAnalysisService.submitJob(jobId);
Expand Down Expand Up @@ -130,7 +136,7 @@ async function runObjects2DExample() {
const properties = await realityDataAnalysisService.getJobProperties(jobId);
console.log("Downloading outputs");
const objects2DId = (properties.settings as O2DJobSettings).outputs.objects2D;
realityDataService.downloadContextScene(objects2DId, outputPath, projectId, references);
realityDataService.downloadContextScene(objects2DId, outputPath, iTwinId, references);
console.log("Successfully downloaded output");
}

Expand Down
Loading

0 comments on commit 2a767c5

Please sign in to comment.