1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkPoints.h,v $
6 Date: $Date: 2002/12/26 18:24:21 $
7 Version: $Revision: 1.63 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
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.
17 =========================================================================*/
18 // .NAME vtkPoints - represent and manipulate 3D points
19 // .SECTION Description
20 // vtkPoints represents 3D points. The data model for vtkPoints is an
21 // array of vx-vy-vz triplets accessible by (point or cell) id.
26 #include "vtkObject.h"
28 #include "vtkDataArray.h" // Needed for inline methods
33 class VTK_COMMON_EXPORT vtkPoints : public vtkObject
37 static vtkPoints *New(int dataType);
39 static vtkPoints *New();
41 vtkTypeRevisionMacro(vtkPoints,vtkObject);
42 void PrintSelf(ostream& os, vtkIndent indent);
45 // Allocate initial memory size.
46 virtual int Allocate(const vtkIdType sz, const vtkIdType ext=1000);
49 // Return object to instantiated state.
50 virtual void Initialize();
52 #ifndef VTK_REMOVE_LEGACY_CODE
54 // For legacy compatibility. Do not use.
55 vtkPoints* MakeObject();
59 // Set/Get the underlying data array. This function must be implemented
60 // in a concrete subclass to check for consistency. (The tuple size must
61 // match the type of data. For example, 3-tuple data array can be assigned to
62 // a vector, normal, or points object, but not a tensor object, which has a
63 // tuple dimension of 9. Scalars, on the other hand, can have tuple dimension
64 // from 1-4, depending on the type of scalar.)
65 virtual void SetData(vtkDataArray *);
66 vtkDataArray *GetData() {return this->Data;};
69 // Return the underlying data type. An integer indicating data type is
70 // returned as specified in vtkSetGet.h.
71 virtual int GetDataType();
74 // Specify the underlying data type of the object.
75 virtual void SetDataType(int dataType);
76 void SetDataTypeToBit() {this->SetDataType(VTK_BIT);};
77 void SetDataTypeToChar() {this->SetDataType(VTK_CHAR);};
78 void SetDataTypeToUnsignedChar() {this->SetDataType(VTK_UNSIGNED_CHAR);};
79 void SetDataTypeToShort() {this->SetDataType(VTK_SHORT);};
80 void SetDataTypeToUnsignedShort() {this->SetDataType(VTK_UNSIGNED_SHORT);};
81 void SetDataTypeToInt() {this->SetDataType(VTK_INT);};
82 void SetDataTypeToUnsignedInt() {this->SetDataType(VTK_UNSIGNED_INT);};
83 void SetDataTypeToLong() {this->SetDataType(VTK_LONG);};
84 void SetDataTypeToUnsignedLong() {this->SetDataType(VTK_UNSIGNED_LONG);};
85 void SetDataTypeToFloat() {this->SetDataType(VTK_FLOAT);};
86 void SetDataTypeToDouble() {this->SetDataType(VTK_DOUBLE);};
89 // Return a void pointer. For image pipeline interface and other
90 // special pointer manipulation.
91 void *GetVoidPointer(const int id) {return this->Data->GetVoidPointer(id);};
94 // Reclaim any extra memory.
95 virtual void Squeeze() {this->Data->Squeeze();};
98 // Make object look empty but do not delete memory.
99 virtual void Reset() {this->Data->Reset();};
102 // Different ways to copy data. Shallow copy does reference count (i.e.,
103 // assigns pointers and updates reference count); deep copy runs through
104 // entire data array assigning values.
105 virtual void DeepCopy(vtkPoints *ad);
106 virtual void ShallowCopy(vtkPoints *ad);
109 // Return the memory in kilobytes consumed by this attribute data.
110 // Used to support streaming and reading/writing data. The value
111 // returned is guaranteed to be greater than or equal to the
112 // memory required to actually represent the data represented
113 // by this object. The information returned is valid only after
114 // the pipeline has been updated.
115 unsigned long GetActualMemorySize();
118 // Return number of points in array.
119 vtkIdType GetNumberOfPoints() { return this->Data->GetNumberOfTuples();};
122 // Return a pointer to a float point x[3] for a specific id.
123 float *GetPoint(vtkIdType id) { return this->Data->GetTuple(id);};
126 // Copy point components into user provided array v[3] for specified
128 void GetPoint(vtkIdType id, float x[3]) { this->Data->GetTuple(id,x);};
129 void GetPoint(vtkIdType id, double x[3]) { this->Data->GetTuple(id,x);};
132 // Insert point into object. No range checking performed (fast!).
133 // Make sure you use SetNumberOfPoints() to allocate memory prior
134 // to using SetPoint().
135 void SetPoint(vtkIdType id, const float x[3]) { this->Data->SetTuple(id,x);};
136 void SetPoint(vtkIdType id, const double x[3]) { this->Data->SetTuple(id,x);};
137 void SetPoint(vtkIdType id, double x, double y, double z);
140 // Insert point into object. Range checking performed and memory
141 // allocated as necessary.
142 void InsertPoint(vtkIdType id, const float x[3])
143 { this->Data->InsertTuple(id,x);};
144 void InsertPoint(vtkIdType id, const double x[3])
145 {this->Data->InsertTuple(id,x);};
146 void InsertPoint(vtkIdType id, double x, double y, double z);
149 // Insert point into next available slot. Returns id of slot.
150 vtkIdType InsertNextPoint(const float x[3]) {
151 return this->Data->InsertNextTuple(x);};
152 vtkIdType InsertNextPoint(const double x[3]) {
153 return this->Data->InsertNextTuple(x);};
154 vtkIdType InsertNextPoint(double x, double y, double z);
157 // Specify the number of points for this object to hold. Does an
158 // allocation as well as setting the MaxId ivar. Used in conjunction with
159 // SetPoint() method for fast insertion.
160 void SetNumberOfPoints(vtkIdType number);
163 // Given a list of pt ids, return an array of points.
164 void GetPoints(vtkIdList *ptId, vtkPoints *fp);
167 // Determine (xmin,xmax, ymin,ymax, zmin,zmax) bounds of points.
168 virtual void ComputeBounds();
171 // Return the bounds of the points.
175 // Return the bounds of the points.
176 void GetBounds(float bounds[6]);
179 vtkPoints(int dataType=VTK_FLOAT);
183 vtkTimeStamp ComputeTime; // Time at which bounds computed
184 vtkDataArray *Data; // Array which represents data
187 vtkPoints(const vtkPoints&); // Not implemented.
188 void operator=(const vtkPoints&); // Not implemented.
191 inline void vtkPoints::SetNumberOfPoints(vtkIdType number)
193 this->Data->SetNumberOfComponents(3);
194 this->Data->SetNumberOfTuples(number);
197 inline void vtkPoints::SetPoint(vtkIdType id, double x, double y, double z)
203 this->Data->SetTuple(id,p);
206 inline void vtkPoints::InsertPoint(vtkIdType id, double x, double y, double z)
213 this->Data->InsertTuple(id,p);
216 inline vtkIdType vtkPoints::InsertNextPoint(double x, double y, double z)
223 return this->Data->InsertNextTuple(p);