VTK
vtkAbstractGridConnectivity.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkAbstractGridConnectivity.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14  =========================================================================*/
41 #ifndef VTKABSTRACTGRIDCONNECTIVITY_H_
42 #define VTKABSTRACTGRIDCONNECTIVITY_H_
43 
44 // VTK includes
45 #include "vtkFiltersGeometryModule.h" // For export macro
46 #include "vtkObject.h"
47 #include "vtkPoints.h" // for vtkPoints definition in STL vector
48 #include "vtkPointData.h" // for vtkPointData definition in STL vector
49 #include "vtkCellData.h" // for vtkCellData definition int STL vector
50 #include "vtkUnsignedCharArray.h" // for vtkUnsignedCharArray definition
51 
52 // Forward declarations
53 class vtkPointData;
54 class vtkCellData;
56 class vtkPoints;
57 
58 // C++ include directives
59 #include <vector> // For STL vector
60 #include <cassert> // For assert
61 
63 {
64 public:
66  void PrintSelf(ostream &os,vtkIndent indent );
67 
69 
70  vtkSetMacro( NumberOfGhostLayers, unsigned int );
71  vtkGetMacro( NumberOfGhostLayers, unsigned int);
73 
79  virtual void SetNumberOfGrids( const unsigned int N ) = 0;
80 
82  unsigned int GetNumberOfGrids() { return this->NumberOfGrids; };
83 
85  virtual void ComputeNeighbors( ) = 0;
86 
91  virtual void CreateGhostLayers( const int N=1 ) = 0;
92 
97  vtkUnsignedCharArray* GetGhostedPointGhostArray( const int gridID );
98 
103  vtkUnsignedCharArray* GetGhostedCellGhostArray( const int gridID );
104 
109  vtkPointData* GetGhostedGridPointData( const int gridID );
110 
115  vtkCellData* GetGhostedGridCellData( const int gridID );
116 
121  vtkPoints* GetGhostedPoints( const int gridID );
122 
123 protected:
125  virtual ~vtkAbstractGridConnectivity();
126 
128 
129  virtual void FillGhostArrays(
130  const int gridId,
131  vtkUnsignedCharArray* nodesArray,
132  vtkUnsignedCharArray* cellsArray ) = 0;
134 
136 
137  void RegisterGridGhostArrays(
138  const int gridID,vtkUnsignedCharArray *nodesArray,
139  vtkUnsignedCharArray *cellsArray );
141 
143 
144  void RegisterFieldData(
145  const int gridID, vtkPointData *PointData, vtkCellData *CellData );
147 
150  void RegisterGridNodes( const int gridID, vtkPoints *nodes );
151 
152 
154 
156  void AllocateUserRegisterDataStructures();
157  void DeAllocateUserRegisterDataStructures();
159 
161 
163  void AllocateInternalDataStructures();
164  void DeAllocateInternalDataStructures();
166 
167  // The total number of grids, set initially by the user.
168  unsigned int NumberOfGrids;
169  unsigned int NumberOfGhostLayers;
170 
171  // BTX
172  // Arrays registered by the user for each grid
173  std::vector< vtkUnsignedCharArray* > GridPointGhostArrays;
174  std::vector< vtkUnsignedCharArray* > GridCellGhostArrays;
175  std::vector< vtkPointData* > GridPointData;
176  std::vector< vtkCellData* > GridCellData;
177  std::vector< vtkPoints* > GridPoints;
178 
179  // Arrays computed internally for each grid
181  std::vector< vtkPointData* > GhostedGridPointData;
182  std::vector< vtkCellData* > GhostedGridCellData;
183  std::vector< vtkUnsignedCharArray* > GhostedPointGhostArray;
184  std::vector< vtkUnsignedCharArray* > GhostedCellGhostArray;
185  std::vector< vtkPoints* > GhostedGridPoints;
186  // ETX
187 
188 private:
190  void operator=(const vtkAbstractGridConnectivity&); // Not implemented
191 };
192 
193 //------------------------------------------------------------------------------
194 inline vtkUnsignedCharArray*
196 {
197  if( !this->AllocatedGhostDataStructures )
198  {
199  return NULL;
200  }
201 
202 
203  assert( "pre: GridID is out-of-bound GridPointData" &&
204  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids) ) );
205  assert( "pre: Ghosted point ghost array" &&
206  (this->NumberOfGrids == this->GhostedPointGhostArray.size() ) );
207 
208  return( this->GhostedPointGhostArray[ gridID ] );
209 }
210 
211 //------------------------------------------------------------------------------
212 inline vtkUnsignedCharArray*
214 {
215  if( !this->AllocatedGhostDataStructures )
216  {
217  return NULL;
218  }
219 
220  assert( "pre: GridID is out-of-bound GridPointData" &&
221  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
222  assert( "pre: Ghosted point ghost array" &&
223  (this->NumberOfGrids == this->GhostedCellGhostArray.size() ) );
224 
225  return( this->GhostedCellGhostArray[ gridID ] );
226 }
227 
228 //------------------------------------------------------------------------------
229 inline vtkPointData*
231 {
232  if( !this->AllocatedGhostDataStructures )
233  {
234  return NULL;
235  }
236 
237  assert( "pre: GridID is out-of-bound GridPointData" &&
238  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
239  assert( "pre: Ghosted point ghost array" &&
240  (this->NumberOfGrids == this->GhostedGridPointData.size() ) );
241 
242  return( this->GhostedGridPointData[ gridID ] );
243 }
244 
245 //------------------------------------------------------------------------------
246 inline vtkCellData*
248 {
249  if( !this->AllocatedGhostDataStructures )
250  {
251  return NULL;
252  }
253 
254  assert( "pre: GridID is out-of-bound GridPointData" &&
255  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
256  assert( "pre: Ghosted point ghost array" &&
257  (this->NumberOfGrids == this->GhostedGridCellData.size() ) );
258 
259  return( this->GhostedGridCellData[ gridID ] );
260 }
261 
262 //------------------------------------------------------------------------------
263 inline vtkPoints*
265 {
266  if( !this->AllocatedGhostDataStructures )
267  {
268  return NULL;
269  }
270 
271  assert( "pre: GridID is out-of-bound GridPointData" &&
272  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
273  assert( "pre: Ghosted point ghost array" &&
274  (this->NumberOfGrids == this->GhostedGridPoints.size() ) );
275 
276  return( this->GhostedGridPoints[ gridID ] );
277 }
278 
279 //------------------------------------------------------------------------------
280 inline void
282 {
283  // Sanity Check
284  assert( "pre: Allocating UserRegister for N > 0 grids" &&
285  (this->NumberOfGrids > 0) );
286 
287  this->GridPointGhostArrays.resize( this->NumberOfGrids, NULL );
288  this->GridCellGhostArrays.resize( this->NumberOfGrids, NULL );
289  this->GridPointData.resize( this->NumberOfGrids, NULL );
290  this->GridCellData.resize( this->NumberOfGrids, NULL );
291  this->GridPoints.resize( this->NumberOfGrids, NULL );
292 }
293 
294 //------------------------------------------------------------------------------
295 inline void
297 {
298  assert( "pre: Data-structure has not been properly allocated" &&
299  (this->GridPointGhostArrays.size() == this->NumberOfGrids ) );
300  assert( "pre: Data-structure has not been properly allocated" &&
301  (this->GridCellGhostArrays.size() == this->NumberOfGrids ) );
302  assert( "pre: Data-structure has not been properly allocated" &&
303  (this->GridPointData.size() == this->NumberOfGrids ) );
304  assert( "pre: Data-structure has not been properly allocated" &&
305  (this->GridCellData.size() == this->NumberOfGrids ) );
306  assert( "pre: Data-structure has not been properly allocated" &&
307  (this->GridPoints.size() == this->NumberOfGrids ) );
308 
309  for( unsigned int i=0; i < this->NumberOfGrids; ++i )
310  {
311 // NOTE: Ghost arrays are not deleted here b/c when they are registered, they
312 // are not shallow-copied.
313 // if( this->GridPointGhostArrays[i] != NULL )
314 // {
315 // this->GridPointGhostArrays[i]->Delete();
316 // }
317 // if( this->GridCellGhostArrays[i] != NULL )
318 // {
319 // this->GridCellGhostArrays[i]->Delete();
320 // }
321  if( this->GridPointData[i] != NULL )
322  {
323  this->GridPointData[i]->Delete();
324  }
325  if( this->GridCellData[i] != NULL )
326  {
327  this->GridCellData[i]->Delete();
328  }
329  if( this->GridPoints[i] != NULL )
330  {
331  this->GridPoints[i]->Delete();
332  }
333  } // END for all grids
334 
335  this->GridPointGhostArrays.clear();
336  this->GridCellGhostArrays.clear();
337  this->GridPointData.clear();
338  this->GridCellData.clear();
339  this->GridPoints.clear();
340 }
341 
342 //------------------------------------------------------------------------------
343 inline void
345 {
346  assert( "pre: Allocating Internal data-structured for N > 0 grids" &&
347  (this->NumberOfGrids > 0) );
348 
349  this->GhostedGridPointData.resize( this->NumberOfGrids, NULL );
350  this->GhostedGridCellData.resize( this->NumberOfGrids, NULL );
351  this->GhostedPointGhostArray.resize( this->NumberOfGrids, NULL );
352  this->GhostedCellGhostArray.resize( this->NumberOfGrids, NULL );
353  this->GhostedGridPoints.resize( this->NumberOfGrids, NULL );
354  this->AllocatedGhostDataStructures = true;
355 }
356 
357 //------------------------------------------------------------------------------
358 inline void
360 {
361  if( !this->AllocatedGhostDataStructures )
362  {
363  return;
364  }
365 
366  assert( "pre: Data-structure has not been properly allocated" &&
367  (this->GhostedGridPointData.size() == this->NumberOfGrids) );
368  assert( "pre: Data-structure has not been properly allocated" &&
369  (this->GhostedGridCellData.size() == this->NumberOfGrids) );
370  assert( "pre: Data-structure has not been properly allocated" &&
371  (this->GhostedPointGhostArray.size() == this->NumberOfGrids) );
372  assert( "pre: Data-structure has not been properly allocated" &&
373  (this->GhostedCellGhostArray.size() == this->NumberOfGrids ) );
374  assert( "pre: Data-structure has not been properly allocated" &&
375  (this->GhostedGridPoints.size() == this->NumberOfGrids ) );
376 
377  for( unsigned int i=0; i < this->NumberOfGrids; ++i )
378  {
379  if( this->GhostedGridPointData[i] != NULL )
380  {
381  this->GhostedGridPointData[i]->Delete();
382  }
383  if( this->GhostedGridCellData[i] != NULL )
384  {
385  this->GhostedGridCellData[i]->Delete();
386  }
387  if( this->GhostedPointGhostArray[i] != NULL )
388  {
389  this->GhostedPointGhostArray[i]->Delete();
390  }
391  if( this->GhostedCellGhostArray[i] != NULL )
392  {
393  this->GhostedCellGhostArray[i]->Delete();
394  }
395  if( this->GhostedGridPoints[i] != NULL )
396  {
397  this->GhostedGridPoints[i]->Delete();
398  }
399  } // END for all grids
400 
401  this->GhostedGridPointData.clear();
402  this->GhostedGridCellData.clear();
403  this->GhostedPointGhostArray.clear();
404  this->GhostedCellGhostArray.clear();
405  this->GhostedGridPoints.clear();
406 
407  this->AllocatedGhostDataStructures = false;
408 }
409 
410 //------------------------------------------------------------------------------
412  const int gridID,
413  vtkUnsignedCharArray *nodesArray,
414  vtkUnsignedCharArray *cellsArray )
415 {
416  // Sanity check
417  assert( "pre: GridID is out-of-bound GridPointData" &&
418  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
419  assert( "pre: GridPointGhostArrays has not been allocated" &&
420  (this->GridPointGhostArrays.size() == this->NumberOfGrids) );
421  assert( "pre: GridCellGhostArrays has not been allocated" &&
422  (this->GridCellGhostArrays.size() == this->NumberOfGrids ) );
423 
424  // NOTE: We should really shallow copy the objects here
425  this->GridPointGhostArrays[ gridID ] = nodesArray;
426  this->GridCellGhostArrays[ gridID ] = cellsArray;
427 }
428 
429 //------------------------------------------------------------------------------
431  const int gridID, vtkPointData *PointData, vtkCellData *CellData )
432 {
433  // Sanity check
434  assert( "pre: GridID is out-of-bound GridPointData" &&
435  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
436  assert( "pre: GridPointData has not been allocated!" &&
437  (this->GridPointData.size() == this->NumberOfGrids ) );
438  assert( "pre: GridCellData has not been allocated!" &&
439  (this->GridCellData.size() == this->NumberOfGrids ) );
440 
441  // Note: The size of these vectors is allocated in SetNumberOfGrids
442  if( PointData != NULL )
443  {
444  assert( "pre: GridPointData[gridID] must be NULL" &&
445  this->GridPointData[ gridID ]==NULL );
446  this->GridPointData[ gridID ] = vtkPointData::New();
447  this->GridPointData[ gridID ]->ShallowCopy( PointData );
448  }
449  else
450  {
451  this->GridPointData[ gridID ] = NULL;
452  }
453 
454  if( CellData != NULL )
455  {
456  assert( "pre: GridCellData[gridID] must be NULL" &&
457  this->GridCellData[gridID]==NULL );
458  this->GridCellData[ gridID ] = vtkCellData::New();
459  this->GridCellData[ gridID ]->ShallowCopy( CellData );
460  }
461  else
462  {
463  this->GridCellData[ gridID ] = NULL;
464  }
465 }
466 
467 //------------------------------------------------------------------------------
469  const int gridID, vtkPoints *nodes )
470 {
471  // Sanity check
472  assert( "pre: GridID is out-of-bound GridPointData" &&
473  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
474  assert( "pre: GridPoints has not been allocated!" &&
475  (this->GridPoints.size() == this->NumberOfGrids) );
476 
477  if( nodes != NULL )
478  {
479  assert( "pre:GridPoints[gridID] must be NULL" &&
480  this->GridPoints[gridID]==NULL );
481  this->GridPoints[ gridID ] = vtkPoints::New();
482  this->GridPoints[ gridID ]->SetDataTypeToDouble();
483  this->GridPoints[ gridID ]->ShallowCopy( nodes );
484  }
485  else
486  {
487  this->GridPoints[ gridID ] = NULL;
488  }
489 }
490 
491 #endif /* VTKABSTRACTGRIDCONNECTIVITY_H_ */
void RegisterFieldData(const int gridID, vtkPointData *PointData, vtkCellData *CellData)
static vtkPoints * New()
abstract base class for most VTK objects
Definition: vtkObject.h:61
represent and manipulate point attribute data
Definition: vtkPointData.h:36
std::vector< vtkUnsignedCharArray * > GhostedPointGhostArray
represent and manipulate cell attribute data
Definition: vtkCellData.h:37
std::vector< vtkPoints * > GridPoints
static vtkPointData * New()
vtkCellData * GetGhostedGridCellData(const int gridID)
std::vector< vtkUnsignedCharArray * > GridPointGhostArrays
static vtkCellData * New()
vtkUnsignedCharArray * GetGhostedPointGhostArray(const int gridID)
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkUnsignedCharArray * GetGhostedCellGhostArray(const int gridID)
std::vector< vtkUnsignedCharArray * > GridCellGhostArrays
std::vector< vtkPointData * > GhostedGridPointData
vtkPointData * GetGhostedGridPointData(const int gridID)
dynamic, self-adjusting array of unsigned char
void RegisterGridGhostArrays(const int gridID, vtkUnsignedCharArray *nodesArray, vtkUnsignedCharArray *cellsArray)
vtkPoints * GetGhostedPoints(const int gridID)
std::vector< vtkCellData * > GhostedGridCellData
std::vector< vtkUnsignedCharArray * > GhostedCellGhostArray
void RegisterGridNodes(const int gridID, vtkPoints *nodes)
std::vector< vtkPoints * > GhostedGridPoints
#define VTKFILTERSGEOMETRY_EXPORT
std::vector< vtkPointData * > GridPointData
represent and manipulate 3D points
Definition: vtkPoints.h:38
std::vector< vtkCellData * > GridCellData