OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / HP / util / HP / include / vtk / vtkUnsignedIntArray.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkUnsignedIntArray.h,v $
5   Language:  C++
6   Date:      $Date: 2002/02/01 06:33:15 $
7   Version:   $Revision: 1.1.1.1 $
8
9
10 Copyright (c) 1993-1998 Ken Martin, Will Schroeder, Bill Lorensen.
11
12 This software is copyrighted by Ken Martin, Will Schroeder and Bill Lorensen.
13 The following terms apply to all files associated with the software unless
14 explicitly disclaimed in individual files. This copyright specifically does
15 not apply to the related textbook "The Visualization Toolkit" ISBN
16 013199837-4 published by Prentice Hall which is covered by its own copyright.
17
18 The authors hereby grant permission to use, copy, and distribute this
19 software and its documentation for any purpose, provided that existing
20 copyright notices are retained in all copies and that this notice is included
21 verbatim in any distributions. Additionally, the authors grant permission to
22 modify this software and its documentation for any purpose, provided that
23 such modifications are not distributed without the explicit consent of the
24 authors and that existing copyright notices are retained in all copies. Some
25 of the algorithms implemented by this software are patented, observe all
26 applicable patent law.
27
28 IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
29 DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
30 OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
31 EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
34 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
35 PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON AN
36 "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
37 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
38
39
40 =========================================================================*/
41 // .NAME vtkUnsignedIntArray - dynamic, self-adjusting unsigned int integer array
42 // .SECTION Description
43 // vtkUnsignedIntArray is an array of unsigned int integer numbers. It provides methods
44 // for insertion and retrieval of integer values, and will 
45 // automatically resize itself to hold new data.
46
47 #ifndef __vtkUnsignedIntArray_h
48 #define __vtkUnsignedIntArray_h
49
50 #include "vtkDataArray.h"
51
52 class VTK_EXPORT vtkUnsignedIntArray : public vtkDataArray 
53 {
54 public:
55   vtkUnsignedIntArray(int numComp=1);
56   ~vtkUnsignedIntArray();
57   int Allocate(const int sz, const int ext=1000);
58   void Initialize();
59   static vtkUnsignedIntArray *New() {return new vtkUnsignedIntArray;};
60   const char *GetClassName() {return "vtkUnsignedIntArray";};
61   void PrintSelf(ostream& os, vtkIndent indent);
62
63   // satisfy vtkDataArray API
64   vtkDataArray *MakeObject() {return new vtkUnsignedIntArray(this->NumberOfComponents);};
65   int GetDataType() {return VTK_UNSIGNED_INT;};
66   void SetNumberOfTuples(const int number);
67   float *GetTuple(const int i);
68   void GetTuple(const int i, float * tuple);
69   void SetTuple(const int i, const float * tuple);
70   void InsertTuple(const int i, const float * tuple);
71   int InsertNextTuple(const float * tuple);
72   void Squeeze();
73
74   // access/insertion methods
75   unsigned int GetValue(const int id);
76   void SetNumberOfValues(const int number);
77   void SetValue(const int id, const unsigned int value);
78   void InsertValue(const int id, const unsigned int i);
79   int InsertNextValue(const unsigned int);
80   unsigned int *GetPointer(const int id) {return this->Array + id;}
81   unsigned int *WritePointer(const int id, const int number);
82   void *GetVoidPointer(const int id) {return (void *)this->GetPointer(id);};
83   void DeepCopy(vtkDataArray& da);
84
85   void SetArray(unsigned int* array, int size, int save);
86
87 private:
88   unsigned int *Array;   // pointer to data
89   unsigned int *Resize(const int sz);  // function to resize data
90
91   int TupleSize; //used for data conversion
92   float *Tuple;
93
94   int SaveUserArray;
95 };
96
97 // Description:
98 // Get the data at a particular index.
99 inline unsigned int vtkUnsignedIntArray::GetValue(const int id) {return this->Array[id];};
100
101 // Description:
102 // Specify the number of values for this object to hold. Does an
103 // allocation as well as setting the MaxId ivar. Used in conjunction with
104 // SetValue() method for fast insertion.
105 inline void vtkUnsignedIntArray::SetNumberOfValues(const int number) 
106 {
107   this->Allocate(number);
108   this->MaxId = number - 1;
109 }
110
111 // Description:
112 // Set the data at a particular index. Does not do range checking. Make sure
113 // you use the method SetNumberOfValues() before inserting data.
114 inline void vtkUnsignedIntArray::SetValue(const int id, const unsigned int value) 
115 {
116   this->Array[id] = value;
117 }
118
119 // Description:
120 // Get the address of a particular data index. Make sure data is allocated
121 // for the number of items requested. Set MaxId according to the number of
122 // data values requested.
123 inline unsigned int *vtkUnsignedIntArray::WritePointer(const int id, const int number) 
124 {
125   int newSize=id+number;
126   if ( newSize > this->Size ) this->Resize(newSize);
127   if ( (--newSize) > this->MaxId ) this->MaxId = newSize;
128   return this->Array + id;
129 }
130
131 // Description:
132 // Insert data at a specified position in the array.
133 inline void vtkUnsignedIntArray::InsertValue(const int id, const unsigned int i)
134 {
135   if ( id >= this->Size ) this->Resize(id+1);
136   this->Array[id] = i;
137   if ( id > this->MaxId ) this->MaxId = id;
138 }
139
140 // Description:
141 // Insert data at the end of the array. Return its location in the array.
142 inline int vtkUnsignedIntArray::InsertNextValue(const unsigned int i)
143 {
144   this->InsertValue (++this->MaxId,i); 
145   return this->MaxId;
146 }
147
148 // Description:
149 // Resize object to just fit data requirement. Reclaims extra memory.
150 inline void vtkUnsignedIntArray::Squeeze() {this->Resize (this->MaxId+1);};
151
152 #endif
153
154
155
156