Public Member Functions
CUserDataArray Class Reference

Detailed Description

A CUserDataArray is an uni-dimensional array used to store binary values. CUserDataArray contains items of type CUserDataArray::Value which holds the data set on a user data map property.

The array is-zero based, which means that the first item index is 0 and the larger index is one less that the number of elements contained in the array.

See also:
UserDataMap::GetValues, UserDataMap::SetValues, UserDataMap::SetFixedSizeValues
Since:
5.0
Example:
        #include "xsi_application.h"
        #include "xsi_userdatamap.h"
        #include "xsi_userdataarray.h"
        #include "xsi_x3dobject.h"
        #include "xsi_model.h"
        #include "xsi_primitive.h"
        #include "xsi_geometry.h"
        #include "xsi_polygonmesh.h"
        #include "xsi_clusterpropertybuilder.h"
        #include "xsi_geometryaccessor.h"

        Application app;

        Model root = app.GetActiveSceneRoot();

        X3DObject mySphere;
        root.AddGeometry( L"Sphere", L"MeshSurface", L"", mySphere );

        PolygonMesh mesh = mySphere.GetActivePrimitive().GetGeometry();

        // Adds a user data map on a complete cluster vertices
        CClusterPropertyBuilder cpBuilder = mesh.GetClusterPropertyBuilder();

        UserDataMap udm = cpBuilder.AddUserDataMap(XSI::siClusterVertexType);

        // Set the new property with user data on vertex 10, 20, 30
        struct FooData
        {
            FooData(float a,float b,float c) : x(a), y(b), z(c) {}
            float x,y,z;
        };

        FooData f1(10,10,10);
        FooData f2(20,20,20);
        FooData f3(30,30,30);

        unsigned char* fds[] =
        {
            (unsigned char*)&f1,
            (unsigned char*)&f2,
            (unsigned char*)&f3,
        };

        LONG vtxIndices[] = {10,20,30};
        udm.SetFixedSizeValues( vtxIndices,
                                (const unsigned char**)fds,
                                3,
                                sizeof(FooData) );

        // Get all user data values from the user data map
        CGeometryAccessor ga = mesh.GetGeometryAccessor();
        CRefArray udmaps = ga.GetUserDataMaps( XSI::siClusterVertexType );

        for (LONG i=0; i<udmaps.GetCount(); i++)
        {
            udm = udmaps[i];

            CUserDataArray data;
            udm.GetValues( data );

            // Log all vertex user data
            for (LONG j=0; j<data.GetCount(); j++)
            {
                CUserDataArray::Value val = data[j];
                FooData* pfd = (FooData*)val.m_pData;
                if (pfd)
                {
                    app.LogMessage( CString(L"FooData[") + CString(j) + CString(L"]=")
                                    + CString(pfd->x) + L","
                                    + CString(pfd->y) + L","
                                    + CString(pfd->z) );
                }
                else
                {
                    app.LogMessage( CString(L"FooData[") + CString(j) + CString(L"]=empty") );
                }
            }
        }

        // Get only the user data values set on the user data map
        for (LONG i=0; i<udmaps.GetCount(); i++)
        {
            udm = udmaps[i];

            CUserDataArray data;
            CBitArray flags;
            udm.GetValues( data, flags );

            // Log only the vertex with user data
            LONG j = flags.GetIterator();
            while (flags.GetNextTrueBit(j))
            {
                CUserDataArray::Value val = data[j];
                FooData* pfd = (FooData*)val.m_pData;
                app.LogMessage( CString(L"FooData[") + CString(j) + CString(L"]=")
                                + CString(pfd->x) + L","
                                + CString(pfd->y) + L","
                                + CString(pfd->z) );
            }
        }

#include <xsi_userdataarray.h>

List of all members.

Public Member Functions

  CUserDataArray (LONG in_size=0)
  CUserDataArray (const CUserDataArray &in_array)
  ~CUserDataArray ()
CUserDataArray operator= (const CUserDataArray &in_array)
LONG  GetCount () const
CStatus  Add (const CUserDataArray::Value &in_val)
CStatus  Clear ()
CStatus  Resize (LONG in_size)
const CUserDataArray::Value &  operator[] (LONG in_index) const
CUserDataArray::Value &  operator[] (LONG in_index)
bool  operator== (const CUserDataArray &in_array) const
bool  operator!= (const CUserDataArray &in_array) const

Constructor & Destructor Documentation

CUserDataArray ( LONG  in_size = 0 )

Constructs a CUserDataArray and optionally initializes the array to a known size.

Parameters:
in_size Size of array, defaults to 0.
CUserDataArray ( const CUserDataArray in_array )

Constructs a CUserDataArray object from another CUserDataArray object.

Parameters:
in_array constant CUserDataArray object.

Default destructor.


Member Function Documentation

CUserDataArray& operator= ( const CUserDataArray in_array )

Assignment operator.

Parameters:
in_array constant class object.
Returns:
A reference to this array.
LONG GetCount ( ) const

Returns the number of items in this CUserDataArray

Returns:
The number of items in the array.
CStatus Add ( const CUserDataArray::Value &  in_val )

Adds a value to the end of this array.

Parameters:
in_val The new value.
Returns:
CStatus::OK success
CStatus Clear ( )

Erases all elements contained in the array.

Returns:
CStatus::OK success
CStatus Resize ( LONG  in_size )

Reallocates memory for the array, preserves its contents if new new size is larger than existing size.

Parameters:
in_size New size of the array.
Returns:
CStatus::OK success
CStatus::InvalidArgument in_size < 0
const CUserDataArray::Value& operator[] ( LONG  in_index ) const

Accessor to elements at a given index. This function can only be called by constant objects, the returned value is read-only.

Parameters:
in_index index in this zero based array.The index must be smaller than the number of element in the array, otherwise the results are unpredicted.
Returns:
A read only reference to the indexed item.
CUserDataArray::Value& operator[] ( LONG  in_index )

Accessor to elements at a given index.

Parameters:
in_index index in this zero based array.The index must be smaller than the number of element in the array, otherwise the results are unpredicted.
Returns:
A reference to the indexed item.
bool operator== ( const CUserDataArray in_array ) const

Equality operator.

Parameters:
in_array CUserDataArray to compare with.
Returns:
true if in_array contains the same number of elements as this array and that all members of in_array are equal to the corresponding one contained in this array.
bool operator!= ( const CUserDataArray in_array ) const

Inequality operator.

Parameters:
in_array CUserDataArray to compare with.
Returns:
true if one member of in_array is different of the corresponding members in this array or if the arrays are not of the same size.

The documentation for this class was generated from the following file: