Several IPSDK algorithms use or return complex data as input or output arguments called data item. A data item is a structure aggregating heterogeneous data.
It can contain :
First of all, let us consider the following data item :
This data item is composed by four fields :
For some data items, creation wrappers allow to instantiate them and fill their data. Such functionalities, when they exist, are described in the IPL documentation.
Let's take as an example the Range
data item, from the IPSDKIPLAttributes library. This simple data item contains two Real64 leaves : Min
and Max
. We can create an instance of this data item by specifying the values of the leaves to the function createRange
. This is done in C++ with the instruction :
In Python, the command is :
This creation wrapper does not exist for all the data items. In this case, the data item can only be created and returned by an IPSDK algorithm. This is the case of GaussianNoiseStats
for instance, which is returned, among others, by the gaussianNoiseMsr
algorithm. The following instruction shows how to compute a GaussianNoiseStats
in C++ :
The equivalent command in Python is :
The getValue<>()
and setValue<>()
methods have to be used to access to a data item leaf. We consider in the following example that the leaf MyValue
in MyDataItem has type T
.
The simplest way to access to a node is to store its reference (in terms of C++) in a local variable :
myNode
can then be used as a classical data item by accessing to its components in the same way than for pMyDataItem
. The modifications applyed to myNode
will be repercuted to the node contained in pMyDataItem
.
In the same way, using a reference (in terms of C++) of the STL container gives access to a leaf collection. We consider in the following examples that MyLeafColl
is a collection of values with type T
:
The modifications applyed to myLeafColl
will be repercuted to the collection contained in pMyDataItem
.
Just like for leaf collections, the simplest way to access to a node collection is to retrieve the reference (in terms of C++) of the STL container. This collection contains shared pointers to the nodes instances. We consider in the following examples that MyNodeColl
is a collection of data item with type MyOtherDataItem
:
The modifications applyed to myNodeColl
will be repercuted to the collection contained in pMyDataItem
.
To use IPSDK in a Python script, the PyIPSDK
package must be imported :
We also consider here that the data item is stored in a variable called myDataItem
.
Accessing to a leaf, a node, etc., we just need to specify the object name followed by a '.' (dot) character and the name of the data item component :
It is important to note that the data item component's name begins by a capital letter whereas the python accessor begins by a lower case character.
It is also possible to easily convert the data item into a python dictionary thanks to the method toPyDict
. This allows for instance to display the data item. We use once more the data item range
to show how to use this function :
This will display :
To use the functions, you will need to add the following instruction :
It can be useful to save a data item in a file, to store the result of an algorithm for instance. To do so, the data item must be written in a XML file. In C++, this is done with the following instruction :
The functions returns false
if a problem occurred. You can check the bTestWritten
value to check if an error occured.
To read a data item from an existing XML file, this is only necessary to use the following instruction :
Once again, the value of bResultRead
can be tested to check if an error occured.
*pMyDataItem
instead of pMyDataItem
to the writeToXmlFile
or readFromXmlFile
function. However, this approach is not recommended since it is incompatible with a python script.Reading and writing a data item in a Python environment can be done with the following command lines :
bResultRead
is a tuple with two elements : the data item and the result informing whether the data item has been correctly read. If boolResult.getResult()
returns False
, it means that an error occured and more details can be obtained with boolResult.getMsg()
.
This page presented the data items and the most common way to use it. For a more specific use of a data item, please refer to its documentation page.