Interface FilterSolverInterface

The FilterSolverInterface interface is used to create sets of part instances.

The FilterItemInterface serves to elect a list of part instances based on a criterion (or a list of criteria), for example (others can be found in Filters examples):

  • Find all part instances whose size is lower than 3 cms
  • Find all part instances that overlaps a given 3D cube
  • Find all part instances that have a metadata "type" equal to "electrical" (electrical part instances)
  • Find all part instances that have a metadata "mounted" to true (mounted part instances).

A FilterSolverInterface is the expression of a combination of multiple FilterItemInterfaces with a specific operator (union/intersection/exclusion), a FilterOperator.
The order of FilterItemInterface in the FilterSolverInterface is relevant and changing the order of the FilterItemInterfaces may (or not) change the final result.

The FilterSolverInterface MUST be intersected with a filtering context : VisibilityContextInterface (see Filtering Context). Such a filtering context will intersect the FilterSolverInterface with a specific configuration and optionally a union of other FilterSolverInterfaces (setVisibilityContext).

The FilterSolverInterface result is gotten asynchronously when triggered by a update call. The FilterSolverInterface sends the event SolverReady when it the result is ready to be fetched. The result of a FilterSolverInterface is represented as a set of {geometric instance ids} and optionally {part instance ids}.

When a FilterItemInterface is modified, there is no automatic update of the content of a FilterSolverInterface : indeed, you may want to modify a lot of FilterItemInterface, ConfContextInterfaces, VisibilityContextInterfaces before getting the expected result. Moreover, VisibilityContextInterfaces may depend on FilterSolverInterfaces that could lead to massive dependency graphs. For this reason, VisibilityContextInterfaces, FilterSolverInterfaces and FilterItemInterfaces are not updated through a dedicated function on each interface but with the update function.
The dependency graph of ConfContextInterfaces, VisibilityContextInterfaces and FilterItemInterfaces is handled by the DataSessionInterface, this also prevent too many requests to be sent to the server for nothing.
To sum up : modify your FilterItemInterfaces, ConfContextInterfaces, VisibilityContextInterfaces and FilterSolverInterfaces without taking into account any dependency that may have between them, and when you want the server to compute the result, remember to call update.

The FilterSolverInterface interface is created through the createFilterSolver and is bound to this given DataSessionInterface.

/** 
* Sample to illustrate the use of multiple FilterSolverInterfaces to define a set of visible pieces, and
* colorize a subset.
* The visibility is composed of all the part instances included in a Box, that have the "CompletionStatus" attribute
* set to "done".
* The colorization set is based on the visibility, the part instances that have the attribute "ToBeRedesigned"
* true should be colored in yellow.
* This colors all part instance in yellow in the given box, that ave the attribute "ToBeRedesigned"
* true and "CompletionStatus" attribute set to "done".
* This sample uses multiple FilterSolverInterface, VisibilityContextInterface,
* It uses some FilterAABBInterface, FilterAttributeInterface, FilterBooleanInterface.
*/
import {
AttributesDictionaryInterface, AttributeInfoInterface, AttributeType, DataSessionInterface,
InfiniteEngineInterface, ConfContextInterface, Vector3, AABB, FilterSolverInterface, VisibilityContextInterface, FilterAABBInterface, FilterAttributeInterface, FilterOperator, FilterSolverInterfaceSignal, VisualStates, FilterBooleanInterface,
} from 'generated/documentation/appinfiniteapi';

// lEngineInterface has been created previously
let lEngineInterface : InfiniteEngineInterface;
// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;

// MAKE SURE the attributes "CompletionStatus", "ToBeRedesigned" are relevant
const lAttributeDictionary : AttributesDictionaryInterface = lDataSession.getAttributesDictionary();
let lAttributeInfo : AttributeInfoInterface | undefined = lAttributeDictionary.getAttributeInfo('CompletionStatus');
// make sure the attribute is a string one
console.assert((lAttributeInfo !== undefined) && (lAttributeInfo.getAttributeType() === AttributeType.ATTR_STRING));

lAttributeInfo = lAttributeDictionary.getAttributeInfo('ToBeRedesigned');
// make sure the attribute is a date one
console.assert((lAttributeInfo !== undefined) && (lAttributeInfo.getAttributeType() === AttributeType.ATTR_BOOLEAN));

// create a custom material yellow
const lMaterialId : number = lEngineInterface.getMaterialManager().createNewMaterial(new Vector3(1, 1, 0));
// create a conf context
const lConfContext : ConfContextInterface = lDataSession.createConfContext();
// no configuration for the moment (all `part instances`)
lConfContext.setActiveConfs([]);
// the AABB to use
const lABB : AABB = new AABB();
lABB.mCenter.x = 3.0;
lABB.mCenter.y = 3.0;
lABB.mCenter.z = 3.0;

lABB.mHalfExtent.x = 10.0;
lABB.mHalfExtent.y = 10.0;
lABB.mHalfExtent.z = 10.0;

// create the visibility Filter Solver
const lVisibilityFilterSolver : FilterSolverInterface = lDataSession.createFilterSolver();

// create the filtering context of the filter solver
const lInnerFilteringContext : VisibilityContextInterface = lDataSession.createVisibilityContext();
lInnerFilteringContext.setConfContext(lConfContext);
lVisibilityFilterSolver.setVisibilityContext(lInnerFilteringContext);

// create a box filter
const lFilterAABB : FilterAABBInterface = lDataSession.createFilterAABB();
// useless, FilterOperator.FO_UNION is the default operator when creating a new filter
// lFilterAABB.setFilterOperator(FilterOperator.FO_UNION);
lFilterAABB.setAABB(lABB);

// create a FilterAttributeInterface
const lFilterAttributes : FilterAttributeInterface = lDataSession.createFilterAttribute();
// completion status to done
lFilterAttributes.setAttributeName('CompletionStatus');
lFilterAttributes.setExactValues(['done']);
// no n/a
lFilterAttributes.setNaValueChecked(false);

// intersection is the way to go since intersection of box and instances that have the field "CompletionStatus"
// to "done"
// only change the operator of the filters except the first
lFilterAttributes.setFilterOperator(FilterOperator.FO_INTERSECTION);

// and add the filters
// push back (-1) the AABB filter
lVisibilityFilterSolver.insertFilter(-1, lFilterAABB);
// push back (-1) the FilterAttributeInterface, as it is the second one, its operator is used and therefore
// intersection is used
lVisibilityFilterSolver.insertFilter(-1, lFilterAttributes);

// create the filtering context
const lFilteringContext : VisibilityContextInterface = lDataSession.createVisibilityContext();
// sets the conf context
lFilteringContext.setConfContext(lConfContext);
// the colorize filter should be set a sub set of the visibility
lFilteringContext.insertFilterSolver(-1, lVisibilityFilterSolver);

lVisibilityFilterSolver.addEventListener(FilterSolverInterfaceSignal.SolverReady, () =>
{
const lGeometries : Uint32Array | undefined = lVisibilityFilterSolver.getGeometricInstanceIds();
if (lGeometries)
{
// set hidden and not ghosted for everyone
lEngineInterface.updateGeometricStateForAll(VisualStates.S_Ghost | VisualStates.S_Hidden, (~VisualStates.S_Ghost) | VisualStates.S_Hidden);
// and set not hidden for the given geometries
lEngineInterface.updateGeometricState(lGeometries, VisualStates.S_Hidden, ~VisualStates.S_Hidden);
}
});

// create the colorize Filter Solver
const lColorizeFilterSolver : FilterSolverInterface = lDataSession.createFilterSolver();
// create an attribute filter
const lColorizeFilterAttributes : FilterBooleanInterface = lDataSession.createBooleanFilter();
// search ToBeRedesigned attribute
lColorizeFilterAttributes.setAttributeName('ToBeRedesigned');
// value should be true
lColorizeFilterAttributes.setBooleanValue(true);

// when the FilterSolverInterface is ready, colorize the given `geometric instances`
lColorizeFilterSolver.addEventListener(FilterSolverInterfaceSignal.SolverReady, () =>
{
const lGeomIds : Uint32Array | undefined = lColorizeFilterSolver.getGeometricInstanceIds();
if (lGeomIds)
{
// change material for these elements
lEngineInterface.getMaterialManager().changeMaterialOfInstances(lGeomIds, lMaterialId);
}
});

// set the filtering context of the given `part instances` list
lColorizeFilterSolver.setVisibilityContext(lFilteringContext);
// add the colorize filter
lColorizeFilterSolver.insertFilter(-1, lColorizeFilterAttributes);
// and tell the DataSessionInterface to update the modified ConfContextInterface, VisibilityContextInterface and FilterSolverInterfaces
lDataSession.update();
// the filtering context may then be used to restrict a search, or a metadata retrieval to the given FilteringContext.

or asynchronously :
/** 
* Sample to illustrate the asynchronous use of multiple FilterSolverInterfaces to define a set of visible pieces, and
* colorize a subset.
* The visibility is composed of all the part instances included in a Box, that have the "CompletionStatus" attribute
* set to "done".
* The colorization set is based on the visibility, the part instances that have the attribute "ToBeRedesigned"
* true should be colored in yellow.
* This colors all part instance in yellow in the given box, that ave the attribute "ToBeRedesigned"
* true and "CompletionStatus" attribute set to "done".
* This sample uses multiple FilterSolverInterface, VisibilityContextInterface,
* It uses some FilterAABBInterface, FilterAttributeInterface, FilterBooleanInterface.
*/
import {
AttributesDictionaryInterface, AttributeInfoInterface, AttributeType, DataSessionInterface,
InfiniteEngineInterface, ConfContextInterface, Vector3, AABB, FilterSolverInterface, VisibilityContextInterface,
FilterAABBInterface, FilterAttributeInterface, FilterOperator, VisualStates, FilterBooleanInterface,
AsyncUInt32ArrayResult,
} from 'generated/documentation/appinfiniteapi';

// lEngineInterface has been created previously
let lEngineInterface : InfiniteEngineInterface;
// the DataSessionInterface has been created previously and is connected
let lDataSession : DataSessionInterface;

// MAKE SURE the attributes "CompletionStatus", "ToBeRedesigned" are relevant
const lAttributeDictionary : AttributesDictionaryInterface = lDataSession.getAttributesDictionary();
let lAttributeInfo : AttributeInfoInterface | undefined = lAttributeDictionary.getAttributeInfo('CompletionStatus');
// make sure the attribute is a string one
console.assert((lAttributeInfo !== undefined) && (lAttributeInfo.getAttributeType() === AttributeType.ATTR_STRING));

lAttributeInfo = lAttributeDictionary.getAttributeInfo('ToBeRedesigned');
// make sure the attribute is a date one
console.assert((lAttributeInfo !== undefined) && (lAttributeInfo.getAttributeType() === AttributeType.ATTR_BOOLEAN));

// create a custom material yellow
const lMaterialId : number = lEngineInterface.getMaterialManager().createNewMaterial(new Vector3(1, 1, 0));
// create a conf context
const lConfContext : ConfContextInterface = lDataSession.createConfContext();
// no configuration for the moment (all `part instances`)
lConfContext.setActiveConfs([]);
// the AABB to use
const lABB : AABB = new AABB();
lABB.mCenter.x = 3.0;
lABB.mCenter.y = 3.0;
lABB.mCenter.z = 3.0;

lABB.mHalfExtent.x = 10.0;
lABB.mHalfExtent.y = 10.0;
lABB.mHalfExtent.z = 10.0;

// create the visibility Filter Solver
const lVisibilityFilterSolver : FilterSolverInterface = lDataSession.createFilterSolver();

// create the filtering context of the filter solver
const lInnerFilteringContext : VisibilityContextInterface = lDataSession.createVisibilityContext();
lInnerFilteringContext.setConfContext(lConfContext);
lVisibilityFilterSolver.setVisibilityContext(lInnerFilteringContext);

// create a box filter
const lFilterAABB : FilterAABBInterface = lDataSession.createFilterAABB();
// useless, FilterOperator.FO_UNION is the default operator when creating a new filter
// lFilterAABB.setFilterOperator(FilterOperator.FO_UNION);
lFilterAABB.setAABB(lABB);

// create a FilterAttributeInterface
const lFilterAttributes : FilterAttributeInterface = lDataSession.createFilterAttribute();
// completion status to done
lFilterAttributes.setAttributeName('CompletionStatus');
lFilterAttributes.setExactValues(['done']);
// no n/a
lFilterAttributes.setNaValueChecked(false);

// intersection is the way to go since intersection of box and instances that have the field "CompletionStatus"
// to "done"
// only change the operator of the filters except the first
lFilterAttributes.setFilterOperator(FilterOperator.FO_INTERSECTION);

// and add the filters
// push back (-1) the AABB filter
lVisibilityFilterSolver.insertFilter(-1, lFilterAABB);
// push back (-1) the FilterAttributeInterface, as it is the second one, its operator is used and therefore
// intersection is used
lVisibilityFilterSolver.insertFilter(-1, lFilterAttributes);

// create the filtering context
const lFilteringContext : VisibilityContextInterface = lDataSession.createVisibilityContext();
// sets the conf context
lFilteringContext.setConfContext(lConfContext);
// the colorize filter should be set a sub set of the visibility
lFilteringContext.insertFilterSolver(-1, lVisibilityFilterSolver);

// create the colorize Filter Solver
const lColorizeFilterSolver : FilterSolverInterface = lDataSession.createFilterSolver();
// create an attribute filter
const lColorizeFilterAttributes : FilterBooleanInterface = lDataSession.createBooleanFilter();
// search ToBeRedesigned attribute
lColorizeFilterAttributes.setAttributeName('ToBeRedesigned');
// value should be true
lColorizeFilterAttributes.setBooleanValue(true);

// set the filtering context of the given `part instances` list
lColorizeFilterSolver.setVisibilityContext(lFilteringContext);
// add the colorize filter
lColorizeFilterSolver.insertFilter(-1, lColorizeFilterAttributes);

// the filtering context may then be used to restrict a search, or a metadata retrieval to the given FilteringContext.

const waitForResult = async () : Promise<any> =>
{
// and tell the DataSessionInterface to update the modified ConfContextInterface, VisibilityContextInterface and FilterSolverInterfaces (true)
const lVisibleResult : AsyncUInt32ArrayResult = await lVisibilityFilterSolver.asyncGetGeometricInstanceIds(true);
// no need to call DataSessionInterface update again (false)
const lColorizeResult : AsyncUInt32ArrayResult = await lColorizeFilterSolver.asyncGetGeometricInstanceIds(false);

if (lVisibleResult.value)
{
// set hidden and not ghosted for everyone
lEngineInterface.updateGeometricStateForAll(VisualStates.S_Ghost | VisualStates.S_Hidden, (~VisualStates.S_Ghost) | VisualStates.S_Hidden);
// and set not hidden for the given geometries
lEngineInterface.updateGeometricState(lVisibleResult.value, VisualStates.S_Hidden, ~VisualStates.S_Hidden);
}
if (lColorizeResult.value)
{
// change material for these elements
lEngineInterface.getMaterialManager().changeMaterialOfInstances(lColorizeResult.value, lMaterialId);
}
}

waitForResult();

Please make sure the destination browser supports promises before using async calls.
Metadata

See

Hierarchy

Methods

  • Adds a listener to an event type.

    When an event of the type pType fires, the callback pListener will be called. This function returns a unique string id that may be used in removeEventListenerById to allow simple listener removal. It is possible to add an object that will be included in the callback to avoid creating too many closures.

    Returns

    The id of the inserted callback (actually an UUID).

    Parameters

    • pType: string
      in
      The type of the event pListener will be called upon.
    • pListener: tListenerCallback
      in
      The listener function that fires when the given event type occurs.
    • pObject: undefined | Object
      in
      The optional object the callback will be called with when the given event fires.

    Returns string

  • Adds a listener to an event type.

    When an event of the type pType fires, the callback pListener will be called. This function returns a unique string id that may be used in removeEventListenerById to allow simple listener removal.

    Returns

    The id of the inserted callback (actually an UUID).

    Parameters

    • pType: string
      in
      The type of the event pListener will be called upon.
    • pListener: tListenerCallback
      in
      The listener function that fires when the given event type occurs.

    Returns string

  • Gets the list of all the geometric Instance ids represented by this FilterSolverInterface.

    These geometric instance ids are the resulting set from the list of FilterItemInterface(s) with their operators intersected with the geometric instance ids represented by the VisibilityContextInterface set by setVisibilityContext.


    if pRunUpdate is true (by default), a update is automatically called.

    Returns

    A promise. The promise is resolved with the reason (success, cancelled, reset, bad input), or rejected in case of an unexpected error. In case of success, the promise is resolved with the list of geometric instances ids represented by this FilterSolverInterface.

    Parameters

    • Optional pRunUpdate: boolean
      in
      If set to true, a [update](DataSessionInterface.html#update) is called (defaults to true).

    Returns Promise<AsyncUInt32ArrayResult>

  • Gets the identifier of the FilterSolverInterface.

    Returns

    The identifier of the FilterSolverInterface.

    Deprecated

    Please use getFilterSolverId.

    Returns string

  • Gets the order of the FilterItemInterface represented by the given identifier.

    Returns

    The order of the FilterItemInterface in the FilterSolverInterface, or -1 if not found.

    Parameters

    • pFilterId: string
      in
      The identifier of the [FilterItemInterface](FilterItemInterface.html) to query.

    Returns number

  • Gets the identifier of the FilterSolverInterface.

    Returns

    The identifier of the FilterSolverInterface.

    Returns string

  • Gets the list of all the geometric instance ids represented by this FilterSolverInterface.

    These geometric instance ids are the resulting set from the list of FilterItemInterface(s) with their operators intersected with the geometric instance ids represented by the VisibilityContextInterface set by setVisibilityContext.
    The value is returned if the FilterSolverInterface has finished computing.
    Use addEventListener on the event SolverReady to know when the FilterSolverInterface is ready (isRunning() is false).

    DO NOT modify this array in place, this results in undefined behavior.

    Returns

    const
    The list of geometric instances ids represented by this FilterSolverInterface, or undefined if the FilterSolverInterface is computing (([isRunning()](FilterSolverInterface.html#isRunning) is `false`)) or cancelled ([isCancelled()](FilterSolverInterface.html#isCancelled) is true) .

    Returns undefined | Uint32Array

  • Gets the last error returned by the update of the FilterSolverInterface.

    The error message is updated :

    If the FilterSolverInterface is running, returns an empty string.

    Returns

    A string containing the last error message (if any, or an empty string if no error occurred).

    Returns string

  • Gets the list of all the part instance ids of the part instances represented by this FilterSolverInterface.

    These part instance ids are the resulting set from the list of FilterItemInterface(s) with their operators intersected with the part instance ids represented by the VisibilityContextInterface set by setVisibilityContext.
    The value is returned if the FilterSolverInterface has finished computing and if setRetrievePartInstanceIds(true) has been called.
    Use addEventListener on the event SolverReady to know when the FilterSolverInterface is ready.

    Returns

    const
    The list of part instances ids represented by this FilterSolverInterface, or undefined if it is computing ([isRunning()](FilterSolverInterface.html#isRunning) is false) or cancelled ([isCancelled()](FilterSolverInterface.html#isCancelled) is true) or if it should not retrieve part instance ids ([setRetrievePartInstanceIds(false)](FilterSolverInterface.html#setRetrievePartInstanceIds)).

    Returns undefined | Uint32Array

  • Gets the number of triangles of all the geometric instances represented by this FilterSolverInterface.

    This should be called after the FilterSolverInterface has finished its computation.
    Use addEventListener on the event SolverReady to know when the FilterSolverInterface is ready.
    getTrianglesCount should return -1 if the FilterSolverInterface is running or has never been computed.

    Returns

    The number of triangles of the geometric instances of this FilterSolverInterface.

    Returns number

  • Tells if the EventDispatcher has such a callback registered for the given event type.

    Returns

    true if such a listener is installed for the given type of event.

    Parameters

    • pType: string
      in
      The type of the event to test.
    • pListener: tListenerCallback
      in
      The listener function that gets tested.

    Returns boolean

  • Tells if the FilterSolverInterface has been cancelled.

    This is the case after calling cancelUpdate when the FilterSolverInterface is updating (ie isRunning() is true). The SolverReady signal will be sent shortly after cancelUpdate has been called.

    Returns

    true if the FilterSolverInterface is cancelled.

    See

    cancelUpdate

    Returns boolean

  • Tells if the FilterSolverInterface should retrieve the part instance ids.

    The isRetrievePartInstanceIds() is false by default.

    Returns

    true if the FilterSolverInterface should also retrieve part instance ids.

    Returns boolean

  • Tells if the FilterSolverInterface is updating (running).

    This is the case after calling update.

    Returns

    true if the FilterSolverInterface is updating.

    See

    update

    Returns boolean

  • Changes the order of the given FilterItemInterface in the container list by its filter id.

    Orders number must be in the range of existing orders i.e. [0,getFilterCount()-1].

    Returns

    true if the FilterItemInterface was found and changed.

    Parameters

    • pFilterId: string
      in
      The identifier of the [FilterItemInterface](FilterItemInterface.html) to move.
    • pOrder: number
      in
      The new order of the [FilterItemInterface](FilterItemInterface.html).

    Returns boolean

  • Removes a listener from an event type.

    If no such listener is found, then the function returns false and does nothing. You must use the exact parameters that were used in addEventListener to actually remove the listener.

    Returns

    true if the callback was removed else false.

    Parameters

    • pType: string
      in
      The type of the listener that gets removed.
    • pListener: tListenerCallback

      The listener function that gets removed.

    • pObject: undefined | Object

      The listener object that was used when addEventListener was called.

    Returns boolean

  • Removes a listener from an event type.

    If no such listener is found, then the function returns false and does nothing. You must use the exact parameters that were used in addEventListener to actually remove the listener.

    Returns

    true if the callback was removed else false.

    Parameters

    • pType: string
      in
      The type of the listener that gets removed.
    • pListener: tListenerCallback

      The listener function that gets removed.

    Returns boolean

  • Removes a listener by its id.

    If no such listener is found, then the function returns false and does nothing. You must use the return value of addEventListener to actually remove the listener.

    Returns

    true if the callback was removed else false.

    Parameters

    • pId: string
      in
      The id returned by the call to [addEventListener](FilterSolverInterface.html#addEventListener) that you want to remove.

    Returns boolean

  • Sets the identifier of the FilterSolverInterface. Make sure the id is unique. A unique FilterSolverInterface identifier is created if the identifier is not overridden.

    Parameters

    • pFilterSolverId: string
      in
      The new identifier of the FilterSolverInterface.

    Returns void

  • Tells the FilterSolverInterface to compute the result as a list of part instance ids.

    You may choose not to get the part instance ids to save memory and network bandwidth.
    isRetrievePartInstanceIds() is false by default.

    Parameters

    • pRetrievePartInstanceIds: boolean
      in
      If set to true, part instance ids will also be retrieved and available when [SolverReady](../enums/FilterSolverInterfaceSignal.html#SolverReady) is triggered.

    Returns void