#include <xsi_userdataarray.h>
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.
#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) ); } }
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 |
CUserDataArray | ( | LONG | in_size = 0 |
) |
Constructs a CUserDataArray and optionally initializes the array to a known size.
in_size | Size of array, defaults to 0. |
CUserDataArray | ( | const CUserDataArray & | in_array | ) |
Constructs a CUserDataArray object from another CUserDataArray object.
in_array | constant CUserDataArray object. |
~CUserDataArray | ( | ) |
Default destructor.
CUserDataArray& operator= | ( | const CUserDataArray & | in_array | ) |
Assignment operator.
in_array | constant class object. |
LONG GetCount | ( | ) | const |
Returns the number of items in this CUserDataArray
CStatus Add | ( | const CUserDataArray::Value & | in_val | ) |
Adds a value to the end of this array.
in_val | The new value. |
CStatus Clear | ( | ) |
CStatus Resize | ( | LONG | in_size | ) |
Reallocates memory for the array, preserves its contents if new new size is larger than existing size.
in_size | New size of the array. |
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.
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. |
CUserDataArray::Value& operator[] | ( | LONG | in_index | ) |
Accessor to elements at a given index.
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. |
bool operator== | ( | const CUserDataArray & | in_array | ) | const |
Equality operator.
in_array | CUserDataArray to compare with. |
bool operator!= | ( | const CUserDataArray & | in_array | ) | const |
Inequality operator.
in_array | CUserDataArray to compare with. |