OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I386LINUX / util / I386LINUX / include / vtk / vtkLongArray.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkLongArray.h,v $
5   Language:  C++
6   Date:      $Date: 2002/11/12 18:32:04 $
7   Version:   $Revision: 1.37 $
8
9   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
10   All rights reserved.
11   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
12
13      This software is distributed WITHOUT ANY WARRANTY; without even 
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15      PURPOSE.  See the above copyright notice for more information.
16
17 =========================================================================*/
18 // .NAME vtkLongArray - dynamic, self-adjusting long integer array
19 // .SECTION Description
20 // vtkLongArray is an array of long integer numbers. It provides methods
21 // for insertion and retrieval of integer values, and will 
22 // automatically resize itself to hold new data.
23
24 #ifndef __vtkLongArray_h
25 #define __vtkLongArray_h
26
27 #include "vtkDataArray.h"
28
29 class VTK_COMMON_EXPORT vtkLongArray : public vtkDataArray
30 {
31 public:
32   static vtkLongArray *New();
33
34   vtkTypeRevisionMacro(vtkLongArray,vtkDataArray);
35   void PrintSelf(ostream& os, vtkIndent indent);
36
37   // Description:
38   // Allocate memory for this array. Delete old storage only if necessary.
39   // Note that ext is no longer used.
40   int Allocate(const vtkIdType sz, const vtkIdType ext=1000);
41
42   // Description:
43   // Release storage and reset array to initial state.
44   void Initialize();
45
46   // Description:
47   // Resize object to just fit data requirement. Reclaims extra memory.
48   void Squeeze() {this->ResizeAndExtend (this->MaxId+1);};
49
50   // Description:
51   // Resize the array while conserving the data.
52   virtual void Resize(vtkIdType numTuples);
53
54   // Description:
55   // Get the data type.
56   int GetDataType() {return VTK_LONG;};
57   
58   // Description:
59   // Return the size of the data type.
60   int GetDataTypeSize() { return sizeof(long); }
61   
62   // Description:
63   // Set the number of n-tuples in the array.
64   void SetNumberOfTuples(const vtkIdType number);
65   
66   // Description:
67   // Get a pointer to a tuple at the ith location. This is a dangerous method
68   // (it is not thread safe since a pointer is returned).
69   float *GetTuple(const vtkIdType i);
70
71   // Description:
72   // Copy the tuple value into a user-provided array.
73   void GetTuple(const vtkIdType i, float * tuple);
74   void GetTuple(const vtkIdType i, double * tuple);
75
76   // Description:
77   // Set the tuple value at the ith location in the array.
78   void SetTuple(const vtkIdType i, const float * tuple);
79   void SetTuple(const vtkIdType i, const double * tuple);
80
81   // Description:
82   // Insert (memory allocation performed) the tuple into the ith location
83   // in the array.
84   void InsertTuple(const vtkIdType i, const float * tuple);
85   void InsertTuple(const vtkIdType i, const double * tuple);
86
87   // Description:
88   // Insert (memory allocation performed) the tuple onto the end of the array.
89   vtkIdType InsertNextTuple(const float * tuple);
90   vtkIdType InsertNextTuple(const double * tuple);
91
92   // Description:
93   // Get the data at a particular index.
94   long GetValue(const vtkIdType id) {return this->Array[id];};
95
96   // Description:
97   // Specify the number of values for this object to hold. Does an
98   // allocation as well as setting the MaxId ivar. Used in conjunction with
99   // SetValue() method for fast insertion.
100   void SetNumberOfValues(const vtkIdType number);
101
102   // Description:
103   // Set the data at a particular index. Does not do range checking. Make sure
104   // you use the method SetNumberOfValues() before inserting data.
105   void SetValue(const vtkIdType id, const long value)
106     { this->Array[id] = value;};
107
108   // Description:
109   // Insert data at a specified position in the array.
110   void InsertValue(const vtkIdType id, const long i);
111
112   // Description:
113   // Insert data at the end of the array. Return its location in the array.
114   vtkIdType InsertNextValue(const long);
115
116   // Description:
117   // Return the data component at the ith tuple and jth component location.
118   // Note that i is less then NumberOfTuples and j is less then 
119   // NumberOfComponents.
120   float GetComponent(const vtkIdType i, const int j);
121   
122   // Description:
123   // Set the data component at the ith tuple and jth component location.
124   // Note that i is less then NumberOfTuples and j is less then 
125   // NumberOfComponents. Make sure enough memory has been allocated 
126   // (use SetNumberOfTuples() and SetNumberOfComponents()).
127   void SetComponent(const vtkIdType i, const int j, float c);
128   
129   // Description:
130   // Insert the data component at ith tuple and jth component location. 
131   // Note that memory allocation is performed as necessary to hold the data.
132   virtual void InsertComponent(const vtkIdType i, const int j, float c);
133
134   // Description:
135   // Get the address of a particular data index. Performs no checks
136   // to verify that the memory has been allocated etc.
137   long *GetPointer(const vtkIdType id) {return this->Array + id;}
138   void *GetVoidPointer(const vtkIdType id)
139     {return (void *)this->GetPointer(id);};
140
141   // Description:
142   // Get the address of a particular data index. Make sure data is allocated
143   // for the number of items requested. Set MaxId according to the number of
144   // data values requested.
145   long *WritePointer(const vtkIdType id, const vtkIdType number);
146   
147   // Description:
148   // Deep copy of another long array.
149   void DeepCopy(vtkDataArray *da);
150
151   // Description:
152   // This method lets the user specify data to be held by the array.  The 
153   // array argument is a pointer to the data.  size is the size of 
154   // the array supplied by the user.  Set save to 1 to keep the class
155   // from deleting the array when it cleans up or reallocates memory.
156   // The class uses the actual array provided; it does not copy the data 
157   // from the suppled array.
158   void SetArray(long* array, vtkIdType size, int save);
159   void SetVoidArray(void *array, vtkIdType size, int save) 
160     {this->SetArray((long*)array, size, save);};
161
162 protected:
163   vtkLongArray(vtkIdType numComp=1);
164   ~vtkLongArray();
165
166   long *Array;   // pointer to data
167   long *ResizeAndExtend(const vtkIdType sz);  // function to resize data
168
169   int TupleSize; //used for data conversion
170   float *Tuple;
171
172   int SaveUserArray;
173 private:
174   vtkLongArray(const vtkLongArray&);  // Not implemented.
175   void operator=(const vtkLongArray&);  // Not implemented.
176 };
177
178 inline void vtkLongArray::SetNumberOfValues(const vtkIdType number) 
179 {
180   this->Allocate(number);
181   this->MaxId = number - 1;
182 }
183
184 inline long *vtkLongArray::WritePointer(const vtkIdType id,
185                                         const vtkIdType number) 
186 {
187   vtkIdType newSize=id+number;
188   if ( newSize > this->Size )
189     {
190     this->ResizeAndExtend(newSize);
191     }
192   if ( (--newSize) > this->MaxId )
193     {
194     this->MaxId = newSize;
195     }
196   return this->Array + id;
197 }
198
199 inline void vtkLongArray::InsertValue(const vtkIdType id, const long i)
200 {
201   if ( id >= this->Size )
202     {
203     this->ResizeAndExtend(id+1);
204     }
205   this->Array[id] = i;
206   if ( id > this->MaxId )
207     {
208     this->MaxId = id;
209     }
210 }
211
212 inline vtkIdType vtkLongArray::InsertNextValue(const long i)
213 {
214   this->InsertValue (++this->MaxId,i); 
215   return this->MaxId;
216 }
217
218
219 #endif