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  =========================================================================*/
42 #ifndef vtkAbstractGridConnectivity_h
43 #define vtkAbstractGridConnectivity_h
44 
45 // VTK includes
46 #include "vtkFiltersGeometryModule.h" // For export macro
47 #include "vtkObject.h"
48 #include "vtkPoints.h" // for vtkPoints definition in STL vector
49 #include "vtkPointData.h" // for vtkPointData definition in STL vector
50 #include "vtkCellData.h" // for vtkCellData definition int STL vector
51 #include "vtkUnsignedCharArray.h" // for vtkUnsignedCharArray definition
52 
53 // Forward declarations
54 class vtkPointData;
55 class vtkCellData;
57 class vtkPoints;
58 
59 // C++ include directives
60 #include <vector> // For STL vector
61 #include <cassert> // For assert
62 
63 class VTKFILTERSGEOMETRY_EXPORT vtkAbstractGridConnectivity : public vtkObject
64 {
65 public:
67  void PrintSelf(ostream &os,vtkIndent indent ) VTK_OVERRIDE;
68 
70 
73  vtkSetMacro( NumberOfGhostLayers, unsigned int );
74  vtkGetMacro( NumberOfGhostLayers, unsigned int);
76 
84  virtual void SetNumberOfGrids( const unsigned int N ) = 0;
85 
89  unsigned int GetNumberOfGrids() { return this->NumberOfGrids; };
90 
94  virtual void ComputeNeighbors( ) = 0;
95 
102  virtual void CreateGhostLayers( const int N=1 ) = 0;
103 
110  vtkUnsignedCharArray* GetGhostedPointGhostArray( const int gridID );
111 
118  vtkUnsignedCharArray* GetGhostedCellGhostArray( const int gridID );
119 
126  vtkPointData* GetGhostedGridPointData( const int gridID );
127 
134  vtkCellData* GetGhostedGridCellData( const int gridID );
135 
142  vtkPoints* GetGhostedPoints( const int gridID );
143 
144 protected:
146  ~vtkAbstractGridConnectivity() VTK_OVERRIDE;
147 
151  virtual void FillGhostArrays(
152  const int gridId,
153  vtkUnsignedCharArray* nodesArray,
154  vtkUnsignedCharArray* cellsArray ) = 0;
155 
159  void RegisterGridGhostArrays(
160  const int gridID,vtkUnsignedCharArray *nodesArray,
161  vtkUnsignedCharArray *cellsArray );
162 
166  void RegisterFieldData(
167  const int gridID, vtkPointData *PointData, vtkCellData *CellData );
168 
172  void RegisterGridNodes( const int gridID, vtkPoints *nodes );
173 
174 
176 
180  void AllocateUserRegisterDataStructures();
181  void DeAllocateUserRegisterDataStructures();
183 
185 
189  void AllocateInternalDataStructures();
190  void DeAllocateInternalDataStructures();
192 
193  // The total number of grids, set initially by the user.
194  unsigned int NumberOfGrids;
195  unsigned int NumberOfGhostLayers;
196 
197  // Arrays registered by the user for each grid
198  std::vector< vtkUnsignedCharArray* > GridPointGhostArrays;
199  std::vector< vtkUnsignedCharArray* > GridCellGhostArrays;
200  std::vector< vtkPointData* > GridPointData;
201  std::vector< vtkCellData* > GridCellData;
202  std::vector< vtkPoints* > GridPoints;
203 
204  // Arrays computed internally for each grid
205  bool AllocatedGhostDataStructures;
206  std::vector< vtkPointData* > GhostedGridPointData;
207  std::vector< vtkCellData* > GhostedGridCellData;
208  std::vector< vtkUnsignedCharArray* > GhostedPointGhostArray;
209  std::vector< vtkUnsignedCharArray* > GhostedCellGhostArray;
210  std::vector< vtkPoints* > GhostedGridPoints;
211 
212 private:
213  vtkAbstractGridConnectivity(const vtkAbstractGridConnectivity&) VTK_DELETE_FUNCTION;
214  void operator=(const vtkAbstractGridConnectivity&) VTK_DELETE_FUNCTION;
215 };
216 
217 //------------------------------------------------------------------------------
218 inline vtkUnsignedCharArray*
219 vtkAbstractGridConnectivity::GetGhostedPointGhostArray( const int gridID )
220 {
221  if( !this->AllocatedGhostDataStructures )
222  {
223  return NULL;
224  }
225 
226 
227  assert( "pre: GridID is out-of-bound GridPointData" &&
228  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids) ) );
229  assert( "pre: Ghosted point ghost array" &&
230  (this->NumberOfGrids == this->GhostedPointGhostArray.size() ) );
231 
232  return( this->GhostedPointGhostArray[ gridID ] );
233 }
234 
235 //------------------------------------------------------------------------------
236 inline vtkUnsignedCharArray*
238 {
239  if( !this->AllocatedGhostDataStructures )
240  {
241  return NULL;
242  }
243 
244  assert( "pre: GridID is out-of-bound GridPointData" &&
245  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
246  assert( "pre: Ghosted point ghost array" &&
247  (this->NumberOfGrids == this->GhostedCellGhostArray.size() ) );
248 
249  return( this->GhostedCellGhostArray[ gridID ] );
250 }
251 
252 //------------------------------------------------------------------------------
253 inline vtkPointData*
255 {
256  if( !this->AllocatedGhostDataStructures )
257  {
258  return NULL;
259  }
260 
261  assert( "pre: GridID is out-of-bound GridPointData" &&
262  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
263  assert( "pre: Ghosted point ghost array" &&
264  (this->NumberOfGrids == this->GhostedGridPointData.size() ) );
265 
266  return( this->GhostedGridPointData[ gridID ] );
267 }
268 
269 //------------------------------------------------------------------------------
270 inline vtkCellData*
272 {
273  if( !this->AllocatedGhostDataStructures )
274  {
275  return NULL;
276  }
277 
278  assert( "pre: GridID is out-of-bound GridPointData" &&
279  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
280  assert( "pre: Ghosted point ghost array" &&
281  (this->NumberOfGrids == this->GhostedGridCellData.size() ) );
282 
283  return( this->GhostedGridCellData[ gridID ] );
284 }
285 
286 //------------------------------------------------------------------------------
287 inline vtkPoints*
289 {
290  if( !this->AllocatedGhostDataStructures )
291  {
292  return NULL;
293  }
294 
295  assert( "pre: GridID is out-of-bound GridPointData" &&
296  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
297  assert( "pre: Ghosted point ghost array" &&
298  (this->NumberOfGrids == this->GhostedGridPoints.size() ) );
299 
300  return( this->GhostedGridPoints[ gridID ] );
301 }
302 
303 //------------------------------------------------------------------------------
304 inline void
306 {
307  // Sanity Check
308  assert( "pre: Allocating UserRegister for N > 0 grids" &&
309  (this->NumberOfGrids > 0) );
310 
311  this->GridPointGhostArrays.resize( this->NumberOfGrids, NULL );
312  this->GridCellGhostArrays.resize( this->NumberOfGrids, NULL );
313  this->GridPointData.resize( this->NumberOfGrids, NULL );
314  this->GridCellData.resize( this->NumberOfGrids, NULL );
315  this->GridPoints.resize( this->NumberOfGrids, NULL );
316 }
317 
318 //------------------------------------------------------------------------------
319 inline void
321 {
322  assert( "pre: Data-structure has not been properly allocated" &&
323  (this->GridPointGhostArrays.size() == this->NumberOfGrids ) );
324  assert( "pre: Data-structure has not been properly allocated" &&
325  (this->GridCellGhostArrays.size() == this->NumberOfGrids ) );
326  assert( "pre: Data-structure has not been properly allocated" &&
327  (this->GridPointData.size() == this->NumberOfGrids ) );
328  assert( "pre: Data-structure has not been properly allocated" &&
329  (this->GridCellData.size() == this->NumberOfGrids ) );
330  assert( "pre: Data-structure has not been properly allocated" &&
331  (this->GridPoints.size() == this->NumberOfGrids ) );
332 
333  for( unsigned int i=0; i < this->NumberOfGrids; ++i )
334  {
335 // NOTE: Ghost arrays are not deleted here b/c when they are registered, they
336 // are not shallow-copied.
337 // if( this->GridPointGhostArrays[i] != NULL )
338 // {
339 // this->GridPointGhostArrays[i]->Delete();
340 // }
341 // if( this->GridCellGhostArrays[i] != NULL )
342 // {
343 // this->GridCellGhostArrays[i]->Delete();
344 // }
345  if( this->GridPointData[i] != NULL )
346  {
347  this->GridPointData[i]->Delete();
348  }
349  if( this->GridCellData[i] != NULL )
350  {
351  this->GridCellData[i]->Delete();
352  }
353  if( this->GridPoints[i] != NULL )
354  {
355  this->GridPoints[i]->Delete();
356  }
357  } // END for all grids
358 
359  this->GridPointGhostArrays.clear();
360  this->GridCellGhostArrays.clear();
361  this->GridPointData.clear();
362  this->GridCellData.clear();
363  this->GridPoints.clear();
364 }
365 
366 //------------------------------------------------------------------------------
367 inline void
369 {
370  assert( "pre: Allocating Internal data-structured for N > 0 grids" &&
371  (this->NumberOfGrids > 0) );
372 
373  this->GhostedGridPointData.resize( this->NumberOfGrids, NULL );
374  this->GhostedGridCellData.resize( this->NumberOfGrids, NULL );
375  this->GhostedPointGhostArray.resize( this->NumberOfGrids, NULL );
376  this->GhostedCellGhostArray.resize( this->NumberOfGrids, NULL );
377  this->GhostedGridPoints.resize( this->NumberOfGrids, NULL );
378  this->AllocatedGhostDataStructures = true;
379 }
380 
381 //------------------------------------------------------------------------------
382 inline void
384 {
385  if( !this->AllocatedGhostDataStructures )
386  {
387  return;
388  }
389 
390  assert( "pre: Data-structure has not been properly allocated" &&
391  (this->GhostedGridPointData.size() == this->NumberOfGrids) );
392  assert( "pre: Data-structure has not been properly allocated" &&
393  (this->GhostedGridCellData.size() == this->NumberOfGrids) );
394  assert( "pre: Data-structure has not been properly allocated" &&
395  (this->GhostedPointGhostArray.size() == this->NumberOfGrids) );
396  assert( "pre: Data-structure has not been properly allocated" &&
397  (this->GhostedCellGhostArray.size() == this->NumberOfGrids ) );
398  assert( "pre: Data-structure has not been properly allocated" &&
399  (this->GhostedGridPoints.size() == this->NumberOfGrids ) );
400 
401  for( unsigned int i=0; i < this->NumberOfGrids; ++i )
402  {
403  if( this->GhostedGridPointData[i] != NULL )
404  {
405  this->GhostedGridPointData[i]->Delete();
406  }
407  if( this->GhostedGridCellData[i] != NULL )
408  {
409  this->GhostedGridCellData[i]->Delete();
410  }
411  if( this->GhostedPointGhostArray[i] != NULL )
412  {
413  this->GhostedPointGhostArray[i]->Delete();
414  }
415  if( this->GhostedCellGhostArray[i] != NULL )
416  {
417  this->GhostedCellGhostArray[i]->Delete();
418  }
419  if( this->GhostedGridPoints[i] != NULL )
420  {
421  this->GhostedGridPoints[i]->Delete();
422  }
423  } // END for all grids
424 
425  this->GhostedGridPointData.clear();
426  this->GhostedGridCellData.clear();
427  this->GhostedPointGhostArray.clear();
428  this->GhostedCellGhostArray.clear();
429  this->GhostedGridPoints.clear();
430 
431  this->AllocatedGhostDataStructures = false;
432 }
433 
434 //------------------------------------------------------------------------------
436  const int gridID,
437  vtkUnsignedCharArray *nodesArray,
438  vtkUnsignedCharArray *cellsArray )
439 {
440  // Sanity check
441  assert( "pre: GridID is out-of-bound GridPointData" &&
442  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
443  assert( "pre: GridPointGhostArrays has not been allocated" &&
444  (this->GridPointGhostArrays.size() == this->NumberOfGrids) );
445  assert( "pre: GridCellGhostArrays has not been allocated" &&
446  (this->GridCellGhostArrays.size() == this->NumberOfGrids ) );
447 
448  // NOTE: We should really shallow copy the objects here
449  this->GridPointGhostArrays[ gridID ] = nodesArray;
450  this->GridCellGhostArrays[ gridID ] = cellsArray;
451 }
452 
453 //------------------------------------------------------------------------------
455  const int gridID, vtkPointData *PointData, vtkCellData *CellData )
456 {
457  // Sanity check
458  assert( "pre: GridID is out-of-bound GridPointData" &&
459  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
460  assert( "pre: GridPointData has not been allocated!" &&
461  (this->GridPointData.size() == this->NumberOfGrids ) );
462  assert( "pre: GridCellData has not been allocated!" &&
463  (this->GridCellData.size() == this->NumberOfGrids ) );
464 
465  // Note: The size of these vectors is allocated in SetNumberOfGrids
466  if( PointData != NULL )
467  {
468  assert( "pre: GridPointData[gridID] must be NULL" &&
469  this->GridPointData[ gridID ]==NULL );
470  this->GridPointData[ gridID ] = vtkPointData::New();
471  this->GridPointData[ gridID ]->ShallowCopy( PointData );
472  }
473  else
474  {
475  this->GridPointData[ gridID ] = NULL;
476  }
477 
478  if( CellData != NULL )
479  {
480  assert( "pre: GridCellData[gridID] must be NULL" &&
481  this->GridCellData[gridID]==NULL );
482  this->GridCellData[ gridID ] = vtkCellData::New();
483  this->GridCellData[ gridID ]->ShallowCopy( CellData );
484  }
485  else
486  {
487  this->GridCellData[ gridID ] = NULL;
488  }
489 }
490 
491 //------------------------------------------------------------------------------
493  const int gridID, vtkPoints *nodes )
494 {
495  // Sanity check
496  assert( "pre: GridID is out-of-bound GridPointData" &&
497  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
498  assert( "pre: GridPoints has not been allocated!" &&
499  (this->GridPoints.size() == this->NumberOfGrids) );
500 
501  if( nodes != NULL )
502  {
503  assert( "pre:GridPoints[gridID] must be NULL" &&
504  this->GridPoints[gridID]==NULL );
505  this->GridPoints[ gridID ] = vtkPoints::New();
506  this->GridPoints[ gridID ]->SetDataTypeToDouble();
507  this->GridPoints[ gridID ]->ShallowCopy( nodes );
508  }
509  else
510  {
511  this->GridPoints[ gridID ] = NULL;
512  }
513 }
514 
515 #endif /* vtkAbstractGridConnectivity_h */
void RegisterFieldData(const int gridID, vtkPointData *PointData, vtkCellData *CellData)
Registers the grid's field data, i.e., the node and cell data.
static vtkPoints * New()
abstract base class for most VTK objects
Definition: vtkObject.h:59
represent and manipulate point attribute data
Definition: vtkPointData.h:37
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
represent and manipulate cell attribute data
Definition: vtkCellData.h:38
static vtkPointData * New()
vtkCellData * GetGhostedGridCellData(const int gridID)
Returns the ghosted grid cell data for the grid associated with the given grid ID.
void DeAllocateUserRegisterDataStructures()
Allocate/De-allocate the data-structures where the user-supplied grids will be registered.
static vtkCellData * New()
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkUnsignedCharArray * GetGhostedCellGhostArray(const int gridID)
Returns the ghosted cells ghost array for the grid associated with the given grid ID...
A superclass that defines the interface to be implemented by all concrete grid connectivity classes...
vtkPointData * GetGhostedGridPointData(const int gridID)
Returns the ghosted grid point data for the grid associated with the given grid ID.
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
dynamic, self-adjusting array of unsigned char
void RegisterGridGhostArrays(const int gridID, vtkUnsignedCharArray *nodesArray, vtkUnsignedCharArray *cellsArray)
Registers the ghostarrays for the given grid.
unsigned int GetNumberOfGrids()
Returns the total number of grids.
vtkPoints * GetGhostedPoints(const int gridID)
Returns the ghosted grid points for the grid associated with the given grid ID.
void RegisterGridNodes(const int gridID, vtkPoints *nodes)
Registers the grid nodes for the grid associated with the given gridID.
void AllocateUserRegisterDataStructures()
Allocate/De-allocate the data-structures where the user-supplied grids will be registered.
void AllocateInternalDataStructures()
Allocated/De-allocate the data-structures where the ghosted grid data will be stored.
void DeAllocateInternalDataStructures()
Allocated/De-allocate the data-structures where the ghosted grid data will be stored.
represent and manipulate 3D points
Definition: vtkPoints.h:39