Public Member Functions | Public Attributes

PerData Class Reference

Search for all occurrences

Detailed Description

This class is used for per -'something' floating-point information.

For example, it is used with Meshes to keep track of such per-vertex information as weighted (Affect Region or Soft) selections and vertex weights. It is used in MNMesh to store per-edge data (edge weights). Currently there's only one "type" of data supported, floating point values, but this may be extended in the future. PerData arrays in Meshes and MNMeshes cannot be reserved for plug-ins at this time; 3ds Max maintains the list in MESH.H of the reserved vertex data channels, and in MNMESH.H for the MNEdge data channels. The methods of this class are deliberately made to look like Tab<> methods. All methods of this class are implemented by the system.

See also:
Class Mesh.

#include <mesh.h>

Inheritance diagram for PerData:
Inheritance graph
[legend]

List of all members.

Public Member Functions

  PerData ()
  Constructor.
  PerData (int n, int tp)
  Constructor.
  ~PerData ()
  Destructor.
DllExport void *  AllocData (int num)
  Allocates and returns a pointer to an array of floats of the specified size.
DllExport void  FreeData (void *addr)
  Deletes the specified array of floats.
DllExport int  DataSize ()
  Returns the number of bytes used by the base data type for the vertex data.
void *  Addr (void *ptr, int at)
  Returns the address of the specified element in the array passed.
void *  Addr (int at)
  Returns the address of the specified element in the data array.
DllExport void  CopyData (void *to, void *from, int num=1)
  Copies the specified number of elements between the two data arrays.
void  CopyData (int to, int from, int num=1)
  Copies the specified number of elements between the two specified locations in the data array.
DllExport void  WeightedSum (void *to, void *fr1, float prop1, void *fr2, float prop2)
  Computes the weighted sum of the arguments passed.
void  WeightedSum (int to, int fr1, float prop1, int fr2, float prop2)
  Computes the weighted sum of the arguments passed.
DllExport void  setAlloc (int num, BOOL keep=TRUE)
  Sets the number of elements allocated in the data array.
void  SetCount (int num, BOOL keep=FALSE)
  Sets the number of elements allocated in the data array and sets the dnum member to num.
void  Shrink ()
  Reduces the size of the data array to contain dnum elements.
int  Count ()
  Returns the number of elements used (dnum)
DllExport void  Clear ()
  Clears (deletes) any allocated data and sets the count and type to 0.
DllExport void  DeleteSet (BitArray del)
  Removes any element whose corresponding element in the BitArray is not set.
DllExport void  Delete (int at, int num)
  Deletes the specifiec number of elements from the specified location in the data array.
DllExport void  Insert (int at, int num, void *el)
  Inserts the specified number of data elements into the specified location in the data array.
DllExport void  Append (int num, void *el)
  Appends the specified elements to the data array.
DllExport void  InsertCopies (int at, int num, void *el)
  Inserts the specified number of elements into the data array at the given location.
DllExport void  AppendCopies (int num, void *el)
  Appends the specified number of elements to the data array.
DllExport void  SwapContents (PerData &from)
  Swaps the contents of this PerData object and the specified one.
DllExport PerData operator= (const PerData &from)
  Assignment operator.
DllExport void  MyDebugPrint ()

Public Attributes

int  dnum
  The number of elements of per-vertex data.
int  type
  The type of data held by this class.
int  alloc
  The number of elements currently allocated in the data array.
void *  data
  Points to the actual data.

Constructor & Destructor Documentation

PerData ( ) [inline]

Constructor.

The number of elements is set to 0, the type is set to 0 and the data pointer is set to NULL.

{ data=NULL; dnum=0; alloc=0; type=0; }
PerData ( int  n,
int  tp 
) [inline]

Constructor.

Parameters:
n The number of elements to allocate.
tp The type to set.
{ data=NULL; dnum=0; alloc=0; type=tp; setAlloc (n, FALSE); }
~PerData ( ) [inline]

Destructor.

Any allocated data is freed and the count and type are set to 0.

{ Clear (); }

Member Function Documentation

DllExport void* AllocData ( int  num )

Allocates and returns a pointer to an array of floats of the specified size.

Parameters:
num The number of floats to allocate.
DllExport void FreeData ( void *  addr )

Deletes the specified array of floats.

Parameters:
addr Pointer to the array of floats to free.
DllExport int DataSize ( )

Returns the number of bytes used by the base data type for the vertex data.

This is only implemented for a type of VDATA_TYPE_FLOAT in which case it returns sizeof(float). Other cases simply return 0.

void* Addr ( void *  ptr,
int  at 
) [inline]

Returns the address of the specified element in the array passed.

Parameters:
ptr The array whose at-th element address is returned.
at The zero based index of the element.
{ BYTE *vd=(BYTE *)ptr; return (void *)(vd+at*DataSize()); }
void* Addr ( int  at ) [inline]

Returns the address of the specified element in the data array.

Parameters:
at The zero based index of the element.
{ return Addr(data,at); }
DllExport void CopyData ( void *  to,
void *  from,
int  num = 1 
)

Copies the specified number of elements between the two data arrays.

Parameters:
to Points to the destination data array.
from Points to the source data array.
num The number of elements to copy.
void CopyData ( int  to,
int  from,
int  num = 1 
) [inline]

Copies the specified number of elements between the two specified locations in the data array.

Parameters:
to The zero based index into the data array of the destination.
from The zero based index into the data array of the source.
num The number of elements to copy.
{ CopyData (Addr(to), Addr(from), num); }
DllExport void WeightedSum ( void *  to,
void *  fr1,
float  prop1,
void *  fr2,
float  prop2 
)

Computes the weighted sum of the arguments passed.

This is effectivly c = a*prop1 + b*prop2. This is used, for example, in splitting an edge, where we would want to interpolate the vertex weight values from the edge's endpoints to create the weight for the new vertex.

Parameters:
to A pointer to the location in which the result should be stored.
fr1 A pointer to the first value to be summed.
prop1 The weight given to the first value.
fr2 A pointer to the second value.
prop2 The weight given to the second value.
void WeightedSum ( int  to,
int  fr1,
float  prop1,
int  fr2,
float  prop2 
) [inline]

Computes the weighted sum of the arguments passed.

This is similar to the method above except to, fr1, and fr2 are indices of the values in the PerData array. That is, PerData::WeightedSum (c, a, prop1, b, prop2), where a, b, and c are ints between 0 and PerData::dnum-1, is equivalent to the call PerData::WeightedSum (PerData::Addr(c), PerData::Addr(a), prop1, PerData::Addr(b), prop2).

Parameters:
to The index in the PerData array of the location in which the result should be stored.
fr1 The index of the first value to be summed in the PerData array.
prop1 The weight given to the first value.
fr2 The index of the second value to be summed in the PerData array.
prop2 The weight given to the second value.
{ WeightedSum (Addr(to), Addr(fr1), prop1, Addr(fr2), prop2); }
DllExport void setAlloc ( int  num,
BOOL  keep = TRUE 
)

Sets the number of elements allocated in the data array.

Parameters:
num The number of elements to allocate.
keep If TRUE previous values are kept (copied to the new storage); otherwise they are discarded. Defaults to TRUE.
void SetCount ( int  num,
BOOL  keep = FALSE 
) [inline]

Sets the number of elements allocated in the data array and sets the dnum member to num.

Parameters:
num The number of elements to allocate.
keep If TRUE previous values are kept (copied to the new storage); otherwise they are discarded. Defaults to FALSE.
{ setAlloc (num, keep); dnum=num; }
void Shrink ( ) [inline]

Reduces the size of the data array to contain dnum elements.

{ if (alloc>dnum) setAlloc(dnum); }
int Count ( ) [inline]

Returns the number of elements used (dnum)

{ return dnum; }
DllExport void Clear ( )

Clears (deletes) any allocated data and sets the count and type to 0.

DllExport void DeleteSet ( BitArray  del )

Removes any element whose corresponding element in the BitArray is not set.

Parameters:
del Specifies which elements to delete. Data elelemts corresponding to bits that are on remain; for bits that are off the elements are deleted.
DllExport void Delete ( int  at,
int  num 
)

Deletes the specifiec number of elements from the specified location in the data array.

Parameters:
at The location to delete elements.
num The number of elements to delete.
DllExport void Insert ( int  at,
int  num,
void *  el 
)

Inserts the specified number of data elements into the specified location in the data array.

Parameters:
at The zero based index of the location for the insert.
num The number of elements to insert.
el The data to insert.
DllExport void Append ( int  num,
void *  el 
)

Appends the specified elements to the data array.

Parameters:
num The number of elements to append.
el The data to append.
DllExport void InsertCopies ( int  at,
int  num,
void *  el 
)

Inserts the specified number of elements into the data array at the given location.

Parameters:
at The zero based index of the location to insert the data.
num The number of elements to insert.
el The data to insert.
DllExport void AppendCopies ( int  num,
void *  el 
)

Appends the specified number of elements to the data array.

Parameters:
num The number of elements to append.
el The data to append.
DllExport void SwapContents ( PerData from )

Swaps the contents of this PerData object and the specified one.

Parameters:
from The object to swap with.
DllExport PerData& operator= ( const PerData from )

Assignment operator.

Parameters:
from The VertexData source.
DllExport void MyDebugPrint ( )

Member Data Documentation

int dnum

The number of elements of per-vertex data.

int type

The type of data held by this class.

See Data Types for Mash Vertices .

int alloc

The number of elements currently allocated in the data array.

void* data

Points to the actual data.


PerData PerData PerData PerData PerData PerData PerData PerData PerData PerData
PerData PerData PerData PerData PerData PerData PerData PerData PerData PerData