Skip to content

IDataContainer Interface#

Provides methods for accessing grab results consisting of multiple components

Syntax#

C#

public interface IDataContainer : IDisposable, 
    IEnumerable

VB

Public Interface IDataContainer
    Inherits IDisposable, IEnumerable

The IDataContainer type exposes the following members.

Properties#

NameDescription
Public propertyCount The number of components available in the container.
Public propertyItem Random access to items per index.
 

Methods#

NameDescription
Public methodGetEnumerator Get access to the data components via IEnumerable interface.
Public methodLoad Load the data container from a file.
Public methodSave Store the data container as a file.
 

Remarks#

Some cameras can return complex grab results consisting of multiple components. For example, Basler blaze cameras return a data stream that is composed of range, intensity, and confidence components. To access the individual components, you can use the IDataContainer class.

An IDataContainer can hold one or more components. You can obtain a container by calling IGrabResult::Container. You can then use the container to query for the number of components by calling Count. To retrieve a specific component, you can call Item(Int32). Each component in the container can be used to access the actual data, e.g., the range values, and its metadata. To iterate through the components, use an enumerator returned by GetEnumerator(). If you use a foreach loop as in the example below, this is called implicitly.

A container can be stored on disk using Save(String) or restored from disk using Load(String).

Note Note
Any IDataContainer or IDataComponent must be disposed explicitly.

Examples#

This sample shows how the enumerator is used implicitly.

// Retrieve a grab result and show all data components.
IGrabResult grabResult = camera.StreamGrabber.RetrieveResult( 5000, TimeoutHandling.ThrowException );

Console.WriteLine( "Found {0} components in the container.", grabResult.Container.Count );
// Display each component in a separate window.
int displayId = 1;
foreach( IDataComponent dataComponent in grabResult.Container )
{
    if (dataComponent.IsValid)
    {
        Console.WriteLine( "Component type {0}", dataComponent.ComponentType.ToString() );
        Console.WriteLine( "2D Size is {0}*{1} pixel", dataComponent.Width, dataComponent.Height );
        Console.WriteLine( "Origins from ({0},{1})", dataComponent.OffsetX, dataComponent.OffsetY );
        Console.WriteLine( "Pixel type is {0}", dataComponent.PixelTypeValue.ToString() );
        Console.WriteLine( "Timestamp is {0}", dataComponent.Timestamp );
        Console.WriteLine( "See image in display {0}:", displayId );
        dataComponent.Display( displayId );
    }
}

IDataContainer.GetEnumerator Method#

Get access to the data components via IEnumerable interface.

Syntax#

C#

IEnumerator GetEnumerator()

VB

Function GetEnumerator As IEnumerator

Return Value#

Type: IEnumerator
Returns an IEnumerator object that can be used to iterate through the collection of data components, e.g., in a foreach loop.

Implements#

IEnumerable.GetEnumerator()

Remarks#

Preconditions: The data container must be valid.

Thread Safety: The method is not thread-safe.

IDataContainer.Load Method#

Load the data container from a file.

Syntax#

C#

void Load(
    string filename
)

VB

Sub Load ( 
    filename As String
)

Parameters#

 

filename
Type: System.String
Path to an existing file.

Remarks#

Postconditions: The data container is valid.

Thread Safety:This method is not thread-safe.

Error Safety:This method throws

FileLoadException If the file cannot be loaded.

FileNotFoundException If the file was not found.

IDataContainer.Save Method#

Store the data container as a file.

Syntax#

C#

void Save(
    string filename
)

VB

Sub Save ( 
    filename As String
)

Parameters#

 

filename
Type: System.String
Path to a file.

Remarks#

Preconditions: The data container must be valid.

Thread Safety: The method is not thread-safe.

Error Safety: Throws exceptions if the container cannot be saved.

IDataContainer.Count Property#

The number of components available in the container.

Syntax#

C#

int Count { get; }

VB

ReadOnly Property Count As Integer
    Get

Property Value#

Type: Int32

Remarks#

Preconditions: The data container must be valid.

Thread Safety:This method is not thread-safe.

Error Safety: Does not throw exceptions.

IDataContainer.Item Property#

Random access to items per index.

Syntax#

C#

IDataComponent this[
    int index
] { get; }

VB

ReadOnly Default Property Item ( 
    index As Integer
) As IDataComponent
    Get

Parameters#

 

index
Type: System.Int32
The index of an item.

Return Value#

Type: IDataComponent
Returns a single data component.

Remarks#

Preconditions: The data container must be valid.

Thread Safety: The method is not thread-safe.Error Safety:Throws exception if index is out of range.