IDataContainer Interface#
Syntax#
C#
VB
The IDataContainer type exposes the following members.
Properties#
Name | Description | |
---|---|---|
Count | The number of components available in the container. | |
Item | Random access to items per index. |
Methods#
Name | Description | |
---|---|---|
GetEnumerator | Get access to the data components via IEnumerable interface. | |
Load | Load the data container from a file. | |
Save | 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 |
---|
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#
VB
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#
VB
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#
VB
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#
VB
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#
VB
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.