OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / HP / util / HP / include / vtk / vtkUnsignedShortArray.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkUnsignedShortArray.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 vtkUnsignedShortArray - dynamic, self-adjusting unsigned short integer array
42 // .SECTION Description
43 // vtkUnsignedShortArray is an array of unsigned short 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 __vtkUnsignedShortArray_h
48 #define __vtkUnsignedShortArray_h
49
50 #include "vtkDataArray.h"
51
52 class VTK_EXPORT vtkUnsignedShortArray : public vtkDataArray 
53 {
54 public:
55   vtkUnsignedShortArray(int numComp=1);
56   ~vtkUnsignedShortArray();
57   int Allocate(const int sz, const int ext=1000);
58   void Initialize();
59   static vtkUnsignedShortArray *New() {return new vtkUnsignedShortArray;};
60   const char *GetClassName() {return "vtkUnsignedShortArray";};
61   void PrintSelf(ostream& os, vtkIndent indent);
62
63   // satisfy vtkDataArray API
64   vtkDataArray *MakeObject() {return new vtkUnsignedShortArray(this->NumberOfComponents);};
65   int GetDataType() {return VTK_UNSIGNED_SHORT;};
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   // overload vtkDataArray for efficiency
75   float GetComponent(const int i, const int j);
76   void SetComponent(const int i, const int j, const float c);
77   void InsertComponent(const int i, const int j, const float c);
78
79   // access/insertion methods
80   unsigned short GetValue(const int id);
81   void SetNumberOfValues(const int number);
82   void SetValue(const int id, const unsigned short value);
83   void InsertValue(const int id, const unsigned short i);
84   int InsertNextValue(const unsigned short);
85   unsigned short *GetPointer(const int id) {return this->Array + id;}
86   unsigned short *WritePointer(const int id, const int number);
87   void *GetVoidPointer(const int id) {return (void *)this->GetPointer(id);};
88   void DeepCopy(vtkDataArray& ia);
89
90   void SetArray(unsigned short* array, int size, int save);
91
92 private:
93   unsigned short *Array;   // pointer to data
94   unsigned short *Resize(const int sz);  // function to resize data
95
96   int TupleSize; //used for data conversion
97   float *Tuple;
98
99   int SaveUserArray;
100 };
101
102 // Description:
103 // Get the data at a particular index.
104 inline unsigned short vtkUnsignedShortArray::GetValue(const int id) {return this->Array[id];}
105
106 // Description:
107 // Specify the number of values for this object to hold. Does an
108 // allocation as well as setting the MaxId ivar. Used in conjunction with
109 // SetValue() method for fast insertion.
110 inline void vtkUnsignedShortArray::SetNumberOfValues(const int number) 
111 {
112   this->Allocate(number);
113   this->MaxId = number - 1;
114 }
115
116 // Description:
117 // Set the data at a particular index. Does not do range checking. Make sure
118 // you use the method SetNumberOfValues() before inserting data.
119 inline void vtkUnsignedShortArray::SetValue(const int id, const unsigned short value) 
120 {
121   this->Array[id] = value;
122 }
123
124 // Description:
125 // Get the address of a particular data index. Make sure data is allocated
126 // for the number of items requested. Set MaxId according to the number of
127 // data values requested.
128 inline unsigned short *vtkUnsignedShortArray::WritePointer(const int id, const int number) 
129 {
130   int newSize=id+number;
131   if ( newSize > this->Size ) this->Resize(newSize);
132   if ( (--newSize) > this->MaxId ) this->MaxId = newSize;
133   return this->Array + id;
134 }
135
136 // Description:
137 // Insert data at a specified position in the array.
138 inline void vtkUnsignedShortArray::InsertValue(const int id, const unsigned short i)
139 {
140   if ( id >= this->Size ) this->Resize(id+1);
141   this->Array[id] = i;
142   if ( id > this->MaxId ) this->MaxId = id;
143 }
144
145 // Description:
146 // Insert data at the end of the array. Return its location in the array.
147 inline int vtkUnsignedShortArray::InsertNextValue(const unsigned short i)
148 {
149   this->InsertValue (++this->MaxId,i); 
150   return this->MaxId;
151 }
152
153 // Description:
154 // Resize object to just fit data requirement. Reclaims extra memory.
155 inline void vtkUnsignedShortArray::Squeeze() {this->Resize (this->MaxId+1);}
156
157 #endif
158
159
160
161