VMTK
Loading...
Searching...
No Matches
vtkvmtkItems.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkItems.cxx,v $
5 Language: C++
6 Date: $Date: 2005/11/15 17:39:25 $
7 Version: $Revision: 1.4 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
22#include "vtkvmtkItems.h"
23
24#include "vtkObjectFactory.h"
25#include "vtkIdList.h"
26#include "vtkCell.h"
27
28
29
31{
32 if ( this->Array != NULL )
33 {
34 this->ReleaseArray();
35
36 delete [] this->Array;
37 this->Array = NULL;
38 }
39}
40
41void vtkvmtkItems::Allocate(vtkIdType sz, vtkIdType ext)
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}
60
61void vtkvmtkItems::AllocateItem(vtkIdType i, vtkIdType itemType)
62 {
63 this->Array[i]->Delete();
64 this->Array[i] = InstantiateNewItem(itemType);
65 }
66
68 {
69 for (vtkIdType i=0; i<this->Size; i++)
70 {
71 this->Array[i]->UnRegister(this);
72 }
73 }
74
76 {
77 this->Resize (this->MaxId+1);
78 }
79
81 {
82 this->MaxId = -1;
83 }
84
86 {
87 this->Reset();
88 this->Squeeze();
89 }
90
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}
124
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 }
139
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 }
Serves as the base class for constructing neighborhoods and stencils from a set of points.
Definition vtkvmtkItem.h:42
virtual void DeepCopy(vtkvmtkItem *src)
vtkIdType Extend
void ReleaseArray()
vtkIdType Size
virtual vtkvmtkItem * InstantiateNewItem(int itemType)=0
void ShallowCopy(vtkvmtkItems *src)
void AllocateItem(vtkIdType i, vtkIdType itemType)
vtkvmtkItem * GetItem(vtkIdType id)
void Allocate(vtkIdType numItems, vtkIdType ext=1000)
vtkIdType GetNumberOfItems()
vtkvmtkItem ** Resize(vtkIdType sz)
vtkIdType MaxId
vtkvmtkItem ** Array
void DeepCopy(vtkvmtkItems *src)