1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkCellArray.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 #include "vtkCellArray.h"
16 #include "vtkObjectFactory.h"
17
18 vtkStandardNewMacro(vtkCellArray);
19
20 //----------------------------------------------------------------------------
vtkCellArray()21 vtkCellArray::vtkCellArray()
22 {
23 this->Ia = vtkIdTypeArray::New();
24 this->NumberOfCells = 0;
25 this->InsertLocation = 0;
26 this->TraversalLocation = 0;
27 }
28
29 //----------------------------------------------------------------------------
DeepCopy(vtkCellArray * ca)30 void vtkCellArray::DeepCopy (vtkCellArray *ca)
31 {
32 // Do nothing on a NULL input.
33 if (ca == NULL)
34 {
35 return;
36 }
37
38 this->Ia->DeepCopy(ca->Ia);
39 this->NumberOfCells = ca->NumberOfCells;
40 this->InsertLocation = ca->InsertLocation;
41 this->TraversalLocation = ca->TraversalLocation;
42 }
43
44 //----------------------------------------------------------------------------
~vtkCellArray()45 vtkCellArray::~vtkCellArray()
46 {
47 this->Ia->Delete();
48 }
49
50 //----------------------------------------------------------------------------
Initialize()51 void vtkCellArray::Initialize()
52 {
53 this->Ia->Initialize();
54 this->NumberOfCells = 0;
55 this->InsertLocation = 0;
56 this->TraversalLocation = 0;
57 }
58
59 //----------------------------------------------------------------------------
60 // Returns the size of the largest cell. The size is the number of points
61 // defining the cell.
GetMaxCellSize()62 int vtkCellArray::GetMaxCellSize()
63 {
64 int i, npts=0, maxSize=0;
65
66 for (i=0; i<this->Ia->GetMaxId(); i+=(npts+1))
67 {
68 if ( (npts=this->Ia->GetValue(i)) > maxSize )
69 {
70 maxSize = npts;
71 }
72 }
73 return maxSize;
74 }
75
76 //----------------------------------------------------------------------------
77 // Specify a group of cells.
SetCells(vtkIdType ncells,vtkIdTypeArray * cells)78 void vtkCellArray::SetCells(vtkIdType ncells, vtkIdTypeArray *cells)
79 {
80 if ( cells && cells != this->Ia )
81 {
82 this->Modified();
83 this->Ia->Delete();
84 this->Ia = cells;
85 this->Ia->Register(this);
86
87 this->NumberOfCells = ncells;
88 this->InsertLocation = cells->GetMaxId() + 1;
89 this->TraversalLocation = 0;
90 }
91 }
92
93 //----------------------------------------------------------------------------
GetActualMemorySize()94 unsigned long vtkCellArray::GetActualMemorySize()
95 {
96 return this->Ia->GetActualMemorySize();
97 }
98
99 //----------------------------------------------------------------------------
GetNextCell(vtkIdList * pts)100 int vtkCellArray::GetNextCell(vtkIdList *pts)
101 {
102 vtkIdType npts, *ppts;
103 if (this->GetNextCell(npts, ppts))
104 {
105 pts->SetNumberOfIds(npts);
106 for (vtkIdType i = 0; i < npts; i++)
107 {
108 pts->SetId(i, ppts[i]);
109 }
110 return 1;
111 }
112 return 0;
113 }
114
115 //----------------------------------------------------------------------------
GetCell(vtkIdType loc,vtkIdList * pts)116 void vtkCellArray::GetCell(vtkIdType loc, vtkIdList *pts)
117 {
118 vtkIdType npts = this->Ia->GetValue(loc++);
119 vtkIdType *ppts = this->Ia->GetPointer(loc);
120 pts->SetNumberOfIds(npts);
121 for (vtkIdType i = 0; i < npts; i++)
122 {
123 pts->SetId(i, ppts[i]);
124 }
125 }
126
127 //----------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)128 void vtkCellArray::PrintSelf(ostream& os, vtkIndent indent)
129 {
130 this->Superclass::PrintSelf(os,indent);
131
132 os << indent << "Number Of Cells: " << this->NumberOfCells << endl;
133 os << indent << "Insert Location: " << this->InsertLocation << endl;
134 os << indent << "Traversal Location: " << this->TraversalLocation << endl;
135 }
136