Interface MeasurementAsyncResult

Represents a measurement promise result.

This object is returned from FeatureManagerInterface.asyncComputeMeasurement.

/** 
* Sample to illustrate the asynchronous measurement between a geometry and an arc of circle.
*/
import {
AABB, ArcOfCircleFeature, DataSessionInterface, FeatureManagerInterface,
FeatureType, GeometryFeature, InfiniteEngineInterface, MeasurementAsyncResult, MeasurementType,
Unit, Vector3
} from 'generated_files/documentation/appinfiniteapi';

// the data session
// created previously
let lDataSession : DataSessionInterface;

// created previously
let lInfiniteEngine : InfiniteEngineInterface;

// the geometric instance to compute measurement from
let lGeometricInstanceId : number;

// retrieve the `feature` manager
const lFeatureManager : FeatureManagerInterface = lInfiniteEngine.getFeatureManager();

// retrieve the DMU center
const lDmuAABB : AABB = new AABB();
lDataSession.getDmuAABB(lDmuAABB);

// retrieve the up and front vectors of the scene
const lDmuUpVector : Vector3 = new Vector3();
const lDmuFrontVector : Vector3 = new Vector3();
lInfiniteEngine.getCameraManager().getFrameReference(lDmuFrontVector, lDmuUpVector);

// the arc of circle radius in meters
const lCircleFeatureRadiusInMeters : number = 1.3;

const makeMeasurement = async () : Promise<void> =>
{
// first `feature` is a geometry
const lFirstFeature : GeometryFeature = {
type: FeatureType.FT_Geometry,
geometricInstanceId: lGeometricInstanceId
};

// second `feature` is an arc of circle
const lSecondFeature : ArcOfCircleFeature = {
type: FeatureType.FT_ArcOfCircle,
center: lDmuAABB.mCenter,
normal: lDmuUpVector,
startDirection: lDmuFrontVector,
radius: lCircleFeatureRadiusInMeters * lDataSession.convertUnitFactor(Unit.U_Meter, lDataSession.getDmuBuildUnit()),
angle: Math.PI * 0.5
};

// and make a measurement between the geometry and the given arc of circle (do not use item centers)
// the measure is the smallest distance between the 2 elements
const lMeasureResult : MeasurementAsyncResult = await lFeatureManager.asyncComputeMeasurement(lFirstFeature, lSecondFeature, MeasurementType.MT_Item_Item);
if(lMeasureResult.value === undefined || lMeasureResult.value.contactPoint0 === undefined)
{
console.log('Failed to make measurement, is the geometric instance id correct ?');
}

console.log('Found 2 contact points', JSON.stringify(lMeasureResult.value.contactPoint0), JSON.stringify(lMeasureResult.value.contactPoint1));

// make two fancy points on the rendering
let lApplicationId : number = lFeatureManager.createPointApplicationFeature(lMeasureResult.value.contactPoint0);
if(lApplicationId <= 0)
{
console.log('feature creation failed');
}
lApplicationId = lFeatureManager.createPointApplicationFeature(lMeasureResult.value.contactPoint1);
if(lApplicationId <= 0)
{
console.log('feature creation failed');
}
// and show the result, we are here for that
console.log('Measurement distance', lMeasureResult.value.contactPoint0.distanceToVector(lMeasureResult.value.contactPoint1));
};

makeMeasurement();

Features

interface MeasurementAsyncResult {
    reason: AsyncResultReason;
    value?: MeasurementTypeAttachment;
}

Properties

Properties

The reason for the end of the promise.

The returned value of the promise. Undefined if the call failed.