VMTK
Loading...
Searching...
No Matches
vtkvmtkItems Class Referenceabstract

Control allocation and memory footprint of item instances. More...

#include <vtkvmtkItems.h>

Inheritance diagram for vtkvmtkItems:
[legend]
Collaboration diagram for vtkvmtkItems:
[legend]

Public Types

typedef vtkObject Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkItems * NewInstance () const
void Allocate (vtkIdType numItems, vtkIdType ext=1000)
vtkvmtkItem * GetItem (vtkIdType id)
void Squeeze ()
void Reset ()
void Initialize ()
void ReleaseArray ()
void AllocateItem (vtkIdType i, vtkIdType itemType)
void DeepCopy (vtkvmtkItems *src)
void ShallowCopy (vtkvmtkItems *src)
virtual void SetItemType (int)
virtual int GetItemType ()
void SetNumberOfItems (vtkIdType numberOfItems)
vtkIdType GetNumberOfItems ()

Static Public Member Functions

static int IsTypeOf (const char *type)
static vtkvmtkItems * SafeDownCast (vtkObjectBase *o)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkItems ()
 ~vtkvmtkItems ()
virtual vtkvmtkItem * InstantiateNewItem (int itemType)=0
vtkvmtkItem ** Resize (vtkIdType sz)

Protected Attributes

vtkvmtkItem ** Array
vtkIdType Size
vtkIdType MaxId
vtkIdType Extend
int ItemType

Detailed Description

Control allocation and memory footprint of item instances.

vtkvmtkItems is an abstract, reference-counted, resizable array of vtkvmtkItem pointers (modeled after VTK's own vtkCellArray/vtkPoints-style container classes). Allocate() creates and takes ownership of numItems items (each instantiated through the subclass-provided InstantiateNewItem() factory method), AllocateItem() replaces a single slot with a new item of a possibly different type, and Resize()/Squeeze() grow or shrink the backing array as needed. DeepCopy()/ShallowCopy() copy or share another collection's items. vtkvmtkDataSetItems is the concrete subclass used to hold one item per point of a vtkDataSet.

See also
vtkvmtkItem, vtkvmtkDataSetItems, vtkvmtkNeighborhoods

Definition at line 43 of file vtkvmtkItems.h.

Member Typedef Documentation

◆ Superclass

typedef vtkObject vtkvmtkItems::Superclass

Definition at line 47 of file vtkvmtkItems.h.

Constructor & Destructor Documentation

◆ vtkvmtkItems()

vtkvmtkItems::vtkvmtkItems ( )
inlineprotected

Definition at line 114 of file vtkvmtkItems.h.

114:Array(NULL),Size(0),MaxId(-1),Extend(1000) {};
vtkIdType Extend
vtkIdType Size
vtkIdType MaxId
vtkvmtkItem ** Array

◆ ~vtkvmtkItems()

vtkvmtkItems::~vtkvmtkItems ( )
protected

Definition at line 30 of file vtkvmtkItems.cxx.

31{
32 if ( this->Array != NULL )
33 {
34 this->ReleaseArray();
35
36 delete [] this->Array;
37 this->Array = NULL;
38 }
39}
void ReleaseArray()

Member Function Documentation

◆ IsTypeOf()

int vtkvmtkItems::IsTypeOf ( const char * type)
static

◆ IsA()

virtual int vtkvmtkItems::IsA ( const char * type)
virtual

◆ SafeDownCast()

vtkvmtkItems * vtkvmtkItems::SafeDownCast ( vtkObjectBase * o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkItems::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkItems * vtkvmtkItems::NewInstance ( ) const

◆ SetItemType()

virtual void vtkvmtkItems::SetItemType ( int )
virtual

Set/get the item type (as understood by the subclass's InstantiateNewItem()) used by Allocate() to create new items.

◆ GetItemType()

virtual int vtkvmtkItems::GetItemType ( )
virtual

Set/get the item type (as understood by the subclass's InstantiateNewItem()) used by Allocate() to create new items.

◆ Allocate()

void vtkvmtkItems::Allocate ( vtkIdType numItems,
vtkIdType ext = 1000 )

Allocate the specified number of items (i.e., number of points) that will be built.

Definition at line 41 of file vtkvmtkItems.cxx.

42{
43 if ( this->Array != NULL )
44 {
45 this->ReleaseArray();
46 delete [] this->Array;
47 this->Array = NULL;
48 }
49
50 this->Size = sz;
51 this->Array = new vtkvmtkItem*[sz];
52 this->Extend = ext;
53 this->MaxId = -1;
54
55 for (vtkIdType i=0; i<sz; i++)
56 {
57 this->Array[i] = InstantiateNewItem(this->ItemType);
58 }
59}
virtual vtkvmtkItem * InstantiateNewItem(int itemType)=0

◆ GetItem()

vtkvmtkItem * vtkvmtkItems::GetItem ( vtkIdType id)
inline

Get the item stored at index id.

Definition at line 66 of file vtkvmtkItems.h.

66{return this->Array[id];};

◆ SetNumberOfItems()

void vtkvmtkItems::SetNumberOfItems ( vtkIdType numberOfItems)
inline

Set/get the number of valid items in the collection (i.e. MaxId + 1). Setting this only moves the MaxId marker; it does not allocate or free storage.

Definition at line 73 of file vtkvmtkItems.h.

73{ this->MaxId = numberOfItems - 1;};

◆ GetNumberOfItems()

vtkIdType vtkvmtkItems::GetNumberOfItems ( )
inline

Set/get the number of valid items in the collection (i.e. MaxId + 1). Setting this only moves the MaxId marker; it does not allocate or free storage.

Definition at line 74 of file vtkvmtkItems.h.

74{return this->MaxId + 1;};

◆ Squeeze()

void vtkvmtkItems::Squeeze ( )

Reclaim any unused memory.

Definition at line 75 of file vtkvmtkItems.cxx.

76 {
77 this->Resize (this->MaxId+1);
78 }
vtkvmtkItem ** Resize(vtkIdType sz)

◆ Reset()

void vtkvmtkItems::Reset ( )

Reset to a state of no entries without freeing the memory.

Definition at line 80 of file vtkvmtkItems.cxx.

81 {
82 this->MaxId = -1;
83 }

◆ Initialize()

void vtkvmtkItems::Initialize ( )

Reset to a state of no entries freeing the memory.

Definition at line 85 of file vtkvmtkItems.cxx.

86 {
87 this->Reset();
88 this->Squeeze();
89 }

◆ ReleaseArray()

void vtkvmtkItems::ReleaseArray ( )

Releases the stencil array.

Definition at line 67 of file vtkvmtkItems.cxx.

68 {
69 for (vtkIdType i=0; i<this->Size; i++)
70 {
71 this->Array[i]->UnRegister(this);
72 }
73 }

◆ AllocateItem()

void vtkvmtkItems::AllocateItem ( vtkIdType i,
vtkIdType itemType )

Replace the item at index i with a newly instantiated item of the given itemType, deleting the previous item at that index.

Definition at line 61 of file vtkvmtkItems.cxx.

62 {
63 this->Array[i]->Delete();
64 this->Array[i] = InstantiateNewItem(itemType);
65 }

◆ DeepCopy()

void vtkvmtkItems::DeepCopy ( vtkvmtkItems * src)

Standard DeepCopy method.

Definition at line 125 of file vtkvmtkItems.cxx.

126 {
127 vtkIdType i, numItems;
128
129 numItems = src->GetNumberOfItems();
130
131 this->Allocate(src->Size, src->Extend);
132 for (i=0; i<numItems; i++)
133 {
134 this->GetItem(i)->DeepCopy(src->GetItem(i));
135 }
136
137 this->MaxId = src->MaxId;
138 }
virtual void DeepCopy(vtkvmtkItem *src)
vtkvmtkItem * GetItem(vtkIdType id)
void Allocate(vtkIdType numItems, vtkIdType ext=1000)
vtkIdType GetNumberOfItems()

◆ ShallowCopy()

void vtkvmtkItems::ShallowCopy ( vtkvmtkItems * src)

Standard ShallowCopy method.

Definition at line 140 of file vtkvmtkItems.cxx.

141 {
142 if ( this->Array != NULL )
143 {
144 this->ReleaseArray();
145 delete [] this->Array;
146 this->Array = NULL;
147 }
148
149 this->Array = new vtkvmtkItem*[src->Size];
150
151 for (vtkIdType i=0; i<src->Size; i++)
152 {
153 this->Array[i] = src->Array[i];
154 this->Array[i]->Register(this);
155 }
156
157 this->MaxId = src->MaxId;
158 this->Extend = src->Extend;
159 this->Size = src->Size;
160 }

◆ InstantiateNewItem()

virtual vtkvmtkItem * vtkvmtkItems::InstantiateNewItem ( int itemType)
protectedpure virtual

Implemented in vtkvmtkNeighborhoods, and vtkvmtkStencils.

◆ Resize()

vtkvmtkItem ** vtkvmtkItems::Resize ( vtkIdType sz)
protected

Definition at line 91 of file vtkvmtkItems.cxx.

92{
93 vtkIdType i;
94 vtkvmtkItem** newArray;
95 vtkIdType newSize;
96
97 if ( sz >= this->Size )
98 {
99 newSize = this->Size + sz;
100 }
101 else
102 {
103 newSize = sz;
104 }
105
106 newArray = new vtkvmtkItem*[newSize];
107
108 for (i=0; i<sz && i<this->Size; i++)
109 {
110 newArray[i] = this->Array[i];
111 }
112
113 for (i=this->Size; i<newSize ; i++)
114 {
115 newArray[i] = this->InstantiateNewItem(this->ItemType);
116 }
117
118 this->Size = newSize;
119 delete [] this->Array;
120 this->Array = newArray;
121
122 return NULL;
123}

Member Data Documentation

◆ Array

vtkvmtkItem** vtkvmtkItems::Array
protected

Definition at line 119 of file vtkvmtkItems.h.

◆ Size

vtkIdType vtkvmtkItems::Size
protected

Definition at line 120 of file vtkvmtkItems.h.

◆ MaxId

vtkIdType vtkvmtkItems::MaxId
protected

Definition at line 121 of file vtkvmtkItems.h.

◆ Extend

vtkIdType vtkvmtkItems::Extend
protected

Definition at line 122 of file vtkvmtkItems.h.

◆ ItemType

int vtkvmtkItems::ItemType
protected

Definition at line 125 of file vtkvmtkItems.h.


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