vtkPoints.h 9.16 KB
Newer Older
1 2
/*=========================================================================

Ken Martin's avatar
Ken Martin committed
3
  Program:   Visualization Toolkit
Ken Martin's avatar
Ken Martin committed
4
  Module:    vtkPoints.h
5

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9

10 11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
13 14

=========================================================================*/
15 16 17 18 19 20 21
/**
 * @class   vtkPoints
 * @brief   represent and manipulate 3D points
 *
 * vtkPoints represents 3D points. The data model for vtkPoints is an
 * array of vx-vy-vz triplets accessible by (point or cell) id.
*/
22

23 24
#ifndef vtkPoints_h
#define vtkPoints_h
Will Schroeder's avatar
Will Schroeder committed
25

26
#include "vtkCommonCoreModule.h" // For export macro
27
#include "vtkObject.h"
28 29

#include "vtkDataArray.h" // Needed for inline methods
Will Schroeder's avatar
Will Schroeder committed
30

Ken Martin's avatar
Ken Martin committed
31
class vtkIdList;
Will Schroeder's avatar
Will Schroeder committed
32

33
class VTKCOMMONCORE_EXPORT vtkPoints : public vtkObject
Will Schroeder's avatar
Will Schroeder committed
34 35
{
public:
36

37
  static vtkPoints *New(int dataType);
38

39
  static vtkPoints *New();
40

41
  vtkTypeMacro(vtkPoints,vtkObject);
42
  void PrintSelf(ostream& os, vtkIndent indent) override;
Will Schroeder's avatar
Will Schroeder committed
43

44 45 46
  /**
   * Allocate initial memory size. ext is no longer used.
   */
47
  virtual int Allocate(vtkIdType sz, vtkIdType ext = 1000);
48

49 50 51
  /**
   * Return object to instantiated state.
   */
52 53
  virtual void Initialize();

54 55 56 57 58 59 60 61
  /**
   * Set/Get the underlying data array. This function must be implemented
   * in a concrete subclass to check for consistency. (The tuple size must
   * match the type of data. For example, 3-tuple data array can be assigned to
   * a vector, normal, or points object, but not a tensor object, which has a
   * tuple dimension of 9. Scalars, on the other hand, can have tuple dimension
   * from 1-4, depending on the type of scalar.)
   */
62
  virtual void SetData(vtkDataArray *);
63
  vtkDataArray *GetData() { return this->Data; }
64

65 66 67 68
  /**
   * Return the underlying data type. An integer indicating data type is
   * returned as specified in vtkSetGet.h.
   */
69 70
  virtual int GetDataType();

71 72 73
  /**
   * Specify the underlying data type of the object.
   */
74
  virtual void SetDataType(int dataType);
75 76 77 78 79 80 81 82 83 84 85
  void SetDataTypeToBit() { this->SetDataType(VTK_BIT); }
  void SetDataTypeToChar() { this->SetDataType(VTK_CHAR); }
  void SetDataTypeToUnsignedChar() { this->SetDataType(VTK_UNSIGNED_CHAR); }
  void SetDataTypeToShort() { this->SetDataType(VTK_SHORT); }
  void SetDataTypeToUnsignedShort() { this->SetDataType(VTK_UNSIGNED_SHORT); }
  void SetDataTypeToInt() { this->SetDataType(VTK_INT); }
  void SetDataTypeToUnsignedInt() { this->SetDataType(VTK_UNSIGNED_INT); }
  void SetDataTypeToLong() { this->SetDataType(VTK_LONG); }
  void SetDataTypeToUnsignedLong() { this->SetDataType(VTK_UNSIGNED_LONG); }
  void SetDataTypeToFloat() { this->SetDataType(VTK_FLOAT); }
  void SetDataTypeToDouble() { this->SetDataType(VTK_DOUBLE); }
86

87 88 89 90
  /**
   * Return a void pointer. For image pipeline interface and other
   * special pointer manipulation.
   */
91
  void *GetVoidPointer(const int id) { return this->Data->GetVoidPointer(id); }
92

93 94 95
  /**
   * Reclaim any extra memory.
   */
96
  virtual void Squeeze() { this->Data->Squeeze(); }
97

98 99 100
  /**
   * Make object look empty but do not delete memory.
   */
101
  virtual void Reset();
102

103 104 105 106 107 108
  //@{
  /**
   * Different ways to copy data. Shallow copy does reference count (i.e.,
   * assigns pointers and updates reference count); deep copy runs through
   * entire data array assigning values.
   */
109 110
  virtual void DeepCopy(vtkPoints *ad);
  virtual void ShallowCopy(vtkPoints *ad);
111 112 113 114 115 116 117 118 119 120
  //@}

  /**
   * Return the memory in kibibytes (1024 bytes) consumed by this attribute data.
   * Used to support streaming and reading/writing data. The value
   * returned is guaranteed to be greater than or equal to the
   * memory required to actually represent the data represented
   * by this object. The information returned is valid only after
   * the pipeline has been updated.
   */
121
  unsigned long GetActualMemorySize();
Ken Martin's avatar
Ken Martin committed
122

123 124 125
  /**
   * Return number of points in array.
   */
126
  vtkIdType GetNumberOfPoints() { return this->Data->GetNumberOfTuples(); }
Ken Martin's avatar
Ken Martin committed
127

128 129 130 131 132 133
  /**
   * Return a pointer to a double point x[3] for a specific id.
   * WARNING: Just don't use this error-prone method, the returned pointer
   * and its values are only valid as long as another method invocation is not
   * performed. Prefer GetPoint() with the return value in argument.
   */
David Gobbi's avatar
David Gobbi committed
134 135
  double *GetPoint(vtkIdType id)
    VTK_EXPECTS(0 <= id && id < GetNumberOfPoints())
Ben Boeckel's avatar
Ben Boeckel committed
136
    VTK_SIZEHINT(3)
David Gobbi's avatar
David Gobbi committed
137
    { return this->Data->GetTuple(id); }
Ken Martin's avatar
Ken Martin committed
138

139 140 141 142
  /**
   * Copy point components into user provided array v[3] for specified
   * id.
   */
David Gobbi's avatar
David Gobbi committed
143 144
  void GetPoint(vtkIdType id, double x[3])
    VTK_EXPECTS(0 <= id && id < GetNumberOfPoints())
Ben Boeckel's avatar
Ben Boeckel committed
145
    VTK_SIZEHINT(3)
David Gobbi's avatar
David Gobbi committed
146
    { this->Data->GetTuple(id,x); }
Ken Martin's avatar
Ken Martin committed
147

148 149 150
  /**
   * Insert point into object. No range checking performed (fast!).
   * Make sure you use SetNumberOfPoints() to allocate memory prior
151 152
   * to using SetPoint(). You should call Modified() finally after
   * changing points using this method as it will not do it itself.
153
   */
David Gobbi's avatar
David Gobbi committed
154 155 156 157 158 159 160 161
  void SetPoint(vtkIdType id, const float x[3])
    VTK_EXPECTS(0 <= id && id < GetNumberOfPoints())
    { this->Data->SetTuple(id,x); }
  void SetPoint(vtkIdType id, const double x[3])
    VTK_EXPECTS(0 <= id && id < GetNumberOfPoints())
    { this->Data->SetTuple(id,x); }
  void SetPoint(vtkIdType id, double x, double y, double z)
    VTK_EXPECTS(0 <= id && id < GetNumberOfPoints());
Ken Martin's avatar
Ken Martin committed
162

163 164 165 166 167
  //@{
  /**
   * Insert point into object. Range checking performed and memory
   * allocated as necessary.
   */
168
  void InsertPoint(vtkIdType id, const float x[3])
David Gobbi's avatar
David Gobbi committed
169
    VTK_EXPECTS(0 <= id)
170 171
    { this->Data->InsertTuple(id,x);};
  void InsertPoint(vtkIdType id, const double x[3])
David Gobbi's avatar
David Gobbi committed
172
    VTK_EXPECTS(0 <= id)
173
    {this->Data->InsertTuple(id,x);};
David Gobbi's avatar
David Gobbi committed
174 175
  void InsertPoint(vtkIdType id, double x, double y, double z)
    VTK_EXPECTS(0 <= id);
176
  //@}
177

178 179 180 181 182
  /**
   * Copy the points indexed in srcIds from the source array to the tuple
   * locations indexed by dstIds in this array.
   * Note that memory allocation is performed as necessary to hold the data.
   */
David C. Lonie's avatar
David C. Lonie committed
183 184 185
  void InsertPoints(vtkIdList *dstIds, vtkIdList *srcIds, vtkPoints *source)
    { this->Data->InsertTuples(dstIds, srcIds, source->Data); }

186 187 188 189 190
  /**
   * Copy n consecutive points starting at srcStart from the source array to
   * this array, starting at the dstStart location.
   * Note that memory allocation is performed as necessary to hold the data.
   */
191 192 193 194
  void InsertPoints(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
                    vtkPoints* source)
    { this->Data->InsertTuples(dstStart, n, srcStart, source->Data); }

195 196 197
  /**
   * Insert point into next available slot. Returns id of slot.
   */
198 199 200 201
  vtkIdType InsertNextPoint(const float x[3])
    { return this->Data->InsertNextTuple(x); }
  vtkIdType InsertNextPoint(const double x[3])
    { return this->Data->InsertNextTuple(x); }
202
  vtkIdType InsertNextPoint(double x, double y, double z);
Ken Martin's avatar
Ken Martin committed
203

204 205 206 207 208
  /**
   * Specify the number of points for this object to hold. Does an
   * allocation as well as setting the MaxId ivar. Used in conjunction with
   * SetPoint() method for fast insertion.
   */
209
  void SetNumberOfPoints(vtkIdType numPoints);
Ken Martin's avatar
Ken Martin committed
210

211 212 213 214
  /**
   * Resize the internal array while conserving the data.  Returns 1 if
   * resizing succeeded and 0 otherwise.
   */
215 216
  int Resize(vtkIdType numPoints);

217 218 219
  /**
   * Given a list of pt ids, return an array of points.
   */
220
  void GetPoints(vtkIdList *ptId, vtkPoints *fp);
221

222 223 224
  /**
   * Determine (xmin,xmax, ymin,ymax, zmin,zmax) bounds of points.
   */
Will Schroeder's avatar
Will Schroeder committed
225
  virtual void ComputeBounds();
226

227 228 229
  /**
   * Return the bounds of the points.
   */
Ben Boeckel's avatar
Ben Boeckel committed
230
  double *GetBounds() VTK_SIZEHINT(6);
231

232 233 234
  /**
   * Return the bounds of the points.
   */
Ken Martin's avatar
Ken Martin committed
235
  void GetBounds(double bounds[6]);
Will Schroeder's avatar
Will Schroeder committed
236

237 238 239
  /**
   * The modified time of the points.
   */
240
  vtkMTimeType GetMTime() override;
241

242 243 244
  /**
   * Update the modification time for this object and its Data.
   * As this object acts as a shell around a DataArray and
luz.paz's avatar
luz.paz committed
245
   * forwards Set methods it needs to forward Modified as well.
246
   */
247
  void Modified() override;
248

Will Schroeder's avatar
Will Schroeder committed
249
protected:
250
  vtkPoints(int dataType = VTK_FLOAT);
251
  ~vtkPoints() override;
252

Ken Martin's avatar
Ken Martin committed
253
  double Bounds[6];
Ken Martin's avatar
Ken Martin committed
254
  vtkTimeStamp ComputeTime; // Time at which bounds computed
255
  vtkDataArray *Data;  // Array which represents data
Will Schroeder's avatar
Will Schroeder committed
256

257
private:
258 259
  vtkPoints(const vtkPoints&) = delete;
  void operator=(const vtkPoints&) = delete;
Will Schroeder's avatar
Will Schroeder committed
260 261
};

262 263 264 265 266 267 268
inline void vtkPoints::Reset()
{
  this->Data->Reset();
  this->Modified();
}

inline void vtkPoints::SetNumberOfPoints(vtkIdType numPoints)
269 270
{
  this->Data->SetNumberOfComponents(3);
271 272
  this->Data->SetNumberOfTuples(numPoints);
  this->Modified();
273 274
}

275 276 277
inline int vtkPoints::Resize(vtkIdType numPoints)
{
  this->Data->SetNumberOfComponents(3);
278
  this->Modified();
279 280 281
  return this->Data->Resize(numPoints);
}

282
inline void vtkPoints::SetPoint(vtkIdType id, double x, double y, double z)
283
{
284 285
  double p[3] = { x, y, z };
  this->Data->SetTuple(id, p);
Jim Miller's avatar
Jim Miller committed
286
}
287

288
inline void vtkPoints::InsertPoint(vtkIdType id, double x, double y, double z)
289
{
290 291
  double p[3] = { x, y, z };
  this->Data->InsertTuple(id, p);
292 293
}

294
inline vtkIdType vtkPoints::InsertNextPoint(double x, double y, double z)
295
{
296
  double p[3] = { x, y, z };
297 298 299
  return this->Data->InsertNextTuple(p);
}

Will Schroeder's avatar
Will Schroeder committed
300
#endif
301