VTK
dox/Filters/Geometry/vtkStructuredGridConnectivity.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003  Program:   Visualization Toolkit
00004  Module:    vtkStructuredGridConnectivity.h
00005 
00006  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007  All rights reserved.
00008  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010  This software is distributed WITHOUT ANY WARRANTY; without even
00011  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012  PURPOSE.  See the above copyright notice for more information.
00013 
00014  =========================================================================*/
00031 #ifndef vtkStructuredGridConnectivity_H_
00032 #define vtkStructuredGridConnectivity_H_
00033 
00034 #define VTK_NO_OVERLAP      0
00035 #define VTK_NODE_OVERLAP    1
00036 #define VTK_EDGE_OVERLAP    2
00037 #define VTK_PARTIAL_OVERLAP 3
00038 
00039 // VTK include directives
00040 #include "vtkFiltersGeometryModule.h" // For export macro
00041 #include "vtkAbstractGridConnectivity.h"
00042 #include "vtkStructuredNeighbor.h" // For Structured Neighbor object definition
00043 #include "vtkStructuredData.h" // For data description definitions
00044 
00045 // C++ include directives
00046 #include <iostream> // For cout
00047 #include <vector>   // For STL vector
00048 #include <map>      // For STL map
00049 #include <utility>  // For STL pair and overloaded relational operators
00050 #include <cassert>  // For assert()
00051 
00052 // Forward Declarations
00053 class vtkIdList;
00054 class vtkUnsignedCharArray;
00055 class vtkPointData;
00056 class vtkCellData;
00057 class vtkPoints;
00058 
00059 class VTKFILTERSGEOMETRY_EXPORT vtkStructuredGridConnectivity :
00060   public vtkAbstractGridConnectivity
00061 {
00062 public:
00063   static vtkStructuredGridConnectivity* New();
00064   vtkTypeMacro( vtkStructuredGridConnectivity, vtkAbstractGridConnectivity );
00065   void PrintSelf(ostream& os, vtkIndent  indent );
00066 
00068 
00069   vtkSetVector6Macro(WholeExtent,int);
00070   vtkGetVector6Macro(WholeExtent,int);
00072 
00074 
00075   vtkGetMacro(DataDimension,int);
00077 
00079   virtual void SetNumberOfGrids( const unsigned int N );
00080 
00082 
00084   virtual void RegisterGrid( const int gridID, int extents[6],
00085       vtkUnsignedCharArray* nodesGhostArray,
00086       vtkUnsignedCharArray* cellGhostArray,
00087       vtkPointData* pointData,
00088       vtkCellData* cellData,
00089       vtkPoints* gridNodes );
00091 
00094   void GetGridExtent( const int gridID, int extent[6] );
00095 
00098   void SetGhostedGridExtent( const int gridID, int ext[6] );
00099 
00101   void GetGhostedGridExtent( const int gridID, int ext[6] );
00102 
00104   virtual void ComputeNeighbors();
00105 
00107 
00109   int GetNumberOfNeighbors( const int gridID )
00110     { return( static_cast<int>(this->Neighbors[ gridID ].size() )); };
00112 
00115   vtkStructuredNeighbor GetGridNeighbor(const int gridID, const int nei);
00116 
00120   vtkIdList* GetNeighbors( const int gridID, int *extents );
00121 
00123 
00126   void FillGhostArrays(
00127      const int gridID,
00128      vtkUnsignedCharArray *nodesArray,
00129      vtkUnsignedCharArray *cellsArray );
00131 
00133   virtual void CreateGhostLayers( const int N=1 );
00134 
00135 protected:
00136   vtkStructuredGridConnectivity();
00137   virtual ~vtkStructuredGridConnectivity();
00138 
00140 
00141   bool InBounds( const int idx, const int Lo, const int Hi )
00142   { return( (idx>=Lo) && (idx<=Hi) ); };
00144 
00146 
00147   bool StrictlyInsideBounds( const int idx, const int Lo, const int Hi )
00148   { return( (idx > Lo) && (idx < Hi) ); };
00150 
00152 
00153   bool IsSubset( int A[2], int B[2] )
00154   { return( this->InBounds(A[0], B[0], B[1]) &&
00155             this->InBounds(A[1], B[0], B[1]) ); };
00157 
00159   int Cardinality( int S[2] ) { return( S[1]-S[0]+1 ); };
00160 
00162 
00164   int GetNumberOfNodesPerCell( const int dim )
00165     {
00166       int numNodes = 0;
00167       switch( dim )
00168         {
00169         case 1:
00170          numNodes = 2; // line cell
00171          break;
00172         case 2:
00173          numNodes = 4; // quad cell
00174          break;
00175         case 3:
00176          numNodes = 8; // hex cell
00177          break;
00178         default:
00179          assert( "ERROR: code should not reach here!" && false );
00180         } // END switch
00181       return( numNodes );
00182     }
00184 
00186 
00187   void FillNodesGhostArray(
00188       const int gridID, const int dataDescription,
00189       int GridExtent[6], int RealExtent[6], vtkUnsignedCharArray *nodeArray );
00191 
00193 
00194   void FillCellsGhostArray(
00195       const int dataDescription, const int numNodesPerCell,
00196       int dims[3], int CellExtent[6], vtkUnsignedCharArray *nodesArray,
00197       vtkUnsignedCharArray *cellsArray );
00199 
00201 
00204   void SearchNeighbors(
00205       const int gridID,
00206       const int i, const int j, const int k,
00207       vtkIdList *neiList );
00209 
00211 
00213   void MarkNodeProperty(
00214       const int gridID,
00215       const int i, const int j, const int k,
00216       int ext[6], int RealExtent[6], unsigned char &pfield );
00218 
00220 
00222   void MarkCellProperty(
00223       unsigned char &pfield,
00224       unsigned char *nodeGhostFields, const int numNodes );
00226 
00228   void GetRealExtent( const int gridID, int GridExtent[6],int RealExtent[6] );
00229 
00231 
00233   bool IsGhostNode(
00234       int GridExtent[6], int RealExtent[6],
00235       const int i, const int j, const int k );
00237 
00239 
00241   bool IsNodeOnBoundaryOfExtent(
00242       const int i, const int j, const int k, int ext[6] );
00244 
00246 
00249   bool IsNodeOnSharedBoundary(
00250       const int gridID, int RealExtent[6],
00251       const int i, const int j, const int k );
00253 
00257   bool IsNodeOnBoundary( const int i, const int j, const int k );
00258 
00260 
00262   bool IsNodeInterior(
00263       const int i, const int j, const int k,
00264       int GridExtent[6] );
00266 
00268 
00271   bool IsNodeWithinExtent(
00272       const int i, const int j, const int k,
00273       int GridExtent[6] )
00274   {
00275     bool status = false;
00277 
00278     switch( this->DataDescription )
00279       {
00280       case VTK_X_LINE:
00281         if( (GridExtent[0] <= i) && (i <= GridExtent[1]) )
00282           {
00283           status = true;
00284           }
00285         break;
00286       case VTK_Y_LINE:
00287         if( (GridExtent[2] <= j) && (j <= GridExtent[3] ) )
00288           {
00289           status = true;
00290           }
00291         break;
00292       case VTK_Z_LINE:
00293         if( (GridExtent[4] <= k) && (k <= GridExtent[5] ) )
00294           {
00295           status = true;
00296           }
00297         break;
00298       case VTK_XY_PLANE:
00299         if( (GridExtent[0] <= i) && (i <= GridExtent[1]) &&
00300             (GridExtent[2] <= j) && (j <= GridExtent[3])  )
00301           {
00302           status = true;
00303           }
00304         break;
00305       case VTK_YZ_PLANE:
00306         if( (GridExtent[2] <= j) && (j <= GridExtent[3] ) &&
00307             (GridExtent[4] <= k) && (k <= GridExtent[5] ) )
00308           {
00309           status = true;
00310           }
00311         break;
00312       case VTK_XZ_PLANE:
00313         if( (GridExtent[0] <= i) && (i <= GridExtent[1] ) &&
00314             (GridExtent[4] <= k) && (k <= GridExtent[5] ) )
00315           {
00316           status = true;
00317           }
00318         break;
00319       case VTK_XYZ_GRID:
00320         if( (GridExtent[0] <= i) && (i <= GridExtent[1]) &&
00321             (GridExtent[2] <= j) && (j <= GridExtent[3]) &&
00322             (GridExtent[4] <= k) && (k <= GridExtent[5]) )
00323           {
00324           status = true;
00325           }
00326         break;
00327       default:
00328         std::cout << "Data description is: " << this->DataDescription << "\n";
00329         std::cout.flush();
00330         assert( "pre: Undefined data-description!" && false );
00331       } // END switch
00332 
00333     return( status );
00334   }
00335 
00337 
00338   void SetNeighbors(
00339       const int i, const int j,
00340       int i2jOrientation[3], int j2iOrientation[3],
00341       int overlapExtent[6] );
00343 
00345 
00351   void DetermineNeighborOrientation(
00352       const int  idx, int A[2], int B[2], int overlap[2], int orient[3] );
00354 
00356 
00359   void DetectNeighbors(
00360       const int i, const int j, int ex1[6], int ex2[6],
00361       int orientation[3], int ndim);
00363 
00369   int IntervalOverlap( int A[2], int B[2], int overlap[2] );
00370 
00376   int DoPartialOverlap( int s[2], int S[2], int overlap[2] );
00377 
00379 
00384   int PartialOverlap(
00385       int A[2], const int CofA,
00386       int B[2], const int CofB,
00387       int overlap[2] );
00389 
00392   void EstablishNeighbors( const int i, const int j );
00393 
00397   void AcquireDataDescription();
00398 
00406   bool HasBlockConnection( const int gridID, const int blockDirection );
00407 
00415   void RemoveBlockConnection( const int gridID, const int blockDirection );
00416 
00424   void AddBlockConnection( const int gridID, const int blockDirection );
00425 
00428   void ClearBlockConnections( const int gridID );
00429 
00435   int GetNumberOfConnectingBlockFaces( const int gridID );
00436 
00439   void SetBlockTopology( const int gridID );
00440 
00442 
00447   void GetIJKBlockOrientation(
00448       const int i, const int j, const int k, int ext[6], int orientation[3] );
00450 
00452 
00454   int Get1DOrientation(
00455       const int idx, const int ExtentLo, const int ExtentHi,
00456       const int OnLo, const int OnHi, const int NotOnBoundary );
00458 
00461   void CreateGhostedExtent( const int gridID, const int N );
00462 
00464 
00467   void GetGhostedExtent(
00468       int *ghostedExtent, int GridExtent[6],
00469       const int minIdx, const int maxIdx, const int N);
00471 
00475   void CreateGhostedMaskArrays(const int gridID);
00476 
00481   void InitializeGhostData( const int gridID );
00482 
00486   void AllocatePointData( vtkPointData *RPD, const int N, vtkPointData *PD );
00487 
00491   void AllocateCellData( vtkCellData *RCD, const int N, vtkCellData *CD );
00492 
00495   void TransferRegisteredDataToGhostedData( const int gridID );
00496 
00499   void ComputeNeighborSendAndRcvExtent( const int gridID, const int N );
00500 
00504   virtual void TransferGhostDataFromNeighbors( const int gridID );
00505 
00507 
00508   void TransferLocalNeighborData(
00509       const int gridID, const vtkStructuredNeighbor& Neighor);
00511 
00513 
00514   void CopyCoordinates(
00515       vtkPoints *source, vtkIdType sourceIdx,
00516       vtkPoints *target, vtkIdType targetIdx );
00518 
00520 
00525   void CopyFieldData(
00526       vtkFieldData *source, vtkIdType sourceIdx,
00527       vtkFieldData *target, vtkIdType targetIdx );
00529 
00533   int GetNeighborIndex( const int gridIdx, const int NeighborGridIdx );
00534 
00536   void PrintExtent( int extent[6] );
00537 
00538   int DataDimension;
00539   int DataDescription;
00540   int WholeExtent[6];
00541 
00542   // BTX
00543   std::vector< int > GridExtents;
00544   std::vector< int > GhostedExtents;
00545   std::vector< unsigned char  > BlockTopology;
00546   std::vector< std::vector<vtkStructuredNeighbor> > Neighbors;
00547   std::map< std::pair< int,int >, int > NeighborPair2NeighborListIndex;
00548   // ETX
00549 
00550 private:
00551   vtkStructuredGridConnectivity( const vtkStructuredGridConnectivity& ); // Not implemented
00552   void operator=(const vtkStructuredGridConnectivity& ); // Not implemented
00553 };
00554 
00555 //=============================================================================
00556 //  INLINE METHODS
00557 //=============================================================================
00558 
00559 //------------------------------------------------------------------------------
00560 inline int vtkStructuredGridConnectivity::GetNeighborIndex(
00561     const int gridIdx, const int NeighborGridIdx )
00562 {
00563   assert("pre: Grid index is out-of-bounds!" &&
00564          (gridIdx >= 0) &&
00565          (gridIdx < static_cast<int>(this->NumberOfGrids)));
00566   assert("pre: Neighbor grid index is out-of-bounds!" &&
00567          (NeighborGridIdx >= 0) &&
00568          (NeighborGridIdx < static_cast<int>(this->NumberOfGrids) ) );
00569 
00570   std::pair<int,int> gridPair = std::make_pair(gridIdx,NeighborGridIdx);
00571   assert("pre: Neighboring grid pair does not exist in hash!" &&
00572          (this->NeighborPair2NeighborListIndex.find(gridPair) !=
00573              this->NeighborPair2NeighborListIndex.end() ) );
00574 
00575   return(this->NeighborPair2NeighborListIndex[gridPair]);
00576 }
00577 
00578 //------------------------------------------------------------------------------
00579 inline void vtkStructuredGridConnectivity::GetGhostedExtent(
00580     int *ghostedExtent, int GridExtent[6],
00581     const int minIdx, const int maxIdx, const int N )
00582 {
00583   assert( "pre: Number of ghost layers must be N >= 1" && (N >= 1) );
00584   assert( "pre: ghosted extent pointer is NULL" && ghostedExtent != NULL);
00585 
00586   ghostedExtent[minIdx] = GridExtent[minIdx]-N;
00587   ghostedExtent[maxIdx] = GridExtent[maxIdx]+N;
00588 
00589   // Clamp the ghosted extent to be within the WholeExtent
00590   ghostedExtent[minIdx] =
00591    (ghostedExtent[minIdx] < this->WholeExtent[minIdx] )?
00592        this->WholeExtent[minIdx] : ghostedExtent[minIdx];
00593   ghostedExtent[maxIdx] =
00594    (ghostedExtent[maxIdx] > this->WholeExtent[maxIdx])?
00595        this->WholeExtent[maxIdx] : ghostedExtent[maxIdx];
00596 }
00597 
00598 //------------------------------------------------------------------------------
00599 inline void vtkStructuredGridConnectivity::SetGhostedGridExtent(
00600     const int gridID, int ext[6] )
00601 {
00602   assert( "pre: gridID is out-of-bounds" &&
00603           (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids)));
00604   assert( "pre: ghosted-extents vector has not been allocated" &&
00605           (this->NumberOfGrids == this->GhostedExtents.size()/6 ) );
00606 
00607   for( int i=0; i < 6; ++i )
00608     {
00609     this->GhostedExtents[ gridID*6+i ] = ext[i];
00610     }
00611 }
00612 
00613 //------------------------------------------------------------------------------
00614 inline void vtkStructuredGridConnectivity::GetGridExtent(
00615     const int gridID, int ext[6])
00616 {
00617   assert( "pre: gridID out-of-bounds!" &&
00618         (gridID >= 0  && gridID < static_cast<int>(this->NumberOfGrids)));
00619   for( int i=0; i < 6; ++i )
00620     {
00621     ext[i] = this->GridExtents[ gridID*6+i ];
00622     }
00623 }
00624 
00625 //------------------------------------------------------------------------------
00626 inline void vtkStructuredGridConnectivity::GetGhostedGridExtent(
00627     const int gridID, int ext[6])
00628 {
00629   assert( "pre: gridID out-of-bounds!" &&
00630         (gridID >= 0  && gridID < static_cast<int>(this->NumberOfGrids)));
00631 
00632   if( this->GhostedExtents.size() == 0 )
00633     {
00634     vtkErrorMacro( "No ghosted extents found for registered grid extends!!!" );
00635     return;
00636     }
00637 
00638   assert( "GhostedExtents are not aligned with registered grid extents" &&
00639         ( this->GhostedExtents.size() == this->GridExtents.size() ) );
00640   for( int i=0; i < 6; ++i )
00641     {
00642     ext[i] = this->GhostedExtents[ gridID*6+i ];
00643     }
00644 }
00645 
00646 //------------------------------------------------------------------------------
00647 inline bool vtkStructuredGridConnectivity::IsNodeOnBoundaryOfExtent(
00648     const int i, const int j, const int k, int ext[6] )
00649 {
00650   if( !this->IsNodeWithinExtent( i,j,k, ext) )
00651     {
00652     return false;
00653     }
00654 
00655   bool status = false;
00656   switch( this->DataDescription )
00657     {
00658     case VTK_X_LINE:
00659        if( i==ext[0] || i==ext[1] )
00660          {
00661          status = true;
00662          }
00663        break;
00664      case VTK_Y_LINE:
00665        if( j==ext[2] || j==ext[3] )
00666          {
00667          status = true;
00668          }
00669        break;
00670      case VTK_Z_LINE:
00671        if( k==ext[4] || k==ext[5] )
00672          {
00673          status = true;
00674          }
00675        break;
00676      case VTK_XY_PLANE:
00677        if( (i==ext[0] || i==ext[1]) ||
00678            (j==ext[2] || j==ext[3]) )
00679          {
00680          status = true;
00681          }
00682        break;
00683      case VTK_YZ_PLANE:
00684        if( (j==ext[2] || j==ext[3]) ||
00685            (k==ext[4] || k==ext[5]) )
00686          {
00687          status = true;
00688          }
00689        break;
00690      case VTK_XZ_PLANE:
00691        if( (i==ext[0] || i==ext[1]) ||
00692            (k==ext[4] || k==ext[5]) )
00693          {
00694          status = true;
00695          }
00696        break;
00697      case VTK_XYZ_GRID:
00698        if( (i==ext[0] || i==ext[1]) ||
00699            (j==ext[2] || j==ext[3]) ||
00700            (k==ext[4] || k==ext[5]) )
00701          {
00702          status = true;
00703          }
00704        break;
00705      default:
00706        std::cout << "Data description is: " << this->DataDescription << "\n";
00707        std::cout.flush();
00708        assert( "pre: Undefined data-description!" && false );
00709     } // END switch
00710 
00711   return( status );
00712 }
00713 
00714 //------------------------------------------------------------------------------
00715 inline bool vtkStructuredGridConnectivity::IsNodeInterior(
00716     const int i, const int j, const int k,
00717     int GridExtent[6] )
00718 {
00719   bool status = false;
00720 
00721   switch( this->DataDescription )
00722     {
00723     case VTK_X_LINE:
00724       if( (GridExtent[0] < i) && (i < GridExtent[1]) )
00725         {
00726         status = true;
00727         }
00728       break;
00729     case VTK_Y_LINE:
00730       if( (GridExtent[2] < j) && (j < GridExtent[3] ) )
00731         {
00732         status = true;
00733         }
00734       break;
00735     case VTK_Z_LINE:
00736       if( (GridExtent[4] < k) && (k < GridExtent[5] ) )
00737         {
00738         status = true;
00739         }
00740       break;
00741     case VTK_XY_PLANE:
00742       if( (GridExtent[0] < i) && (i < GridExtent[1]) &&
00743           (GridExtent[2] < j) && (j < GridExtent[3])  )
00744         {
00745         status = true;
00746         }
00747       break;
00748     case VTK_YZ_PLANE:
00749       if( (GridExtent[2] < j) && (j < GridExtent[3] ) &&
00750           (GridExtent[4] < k) && (k < GridExtent[5] ) )
00751         {
00752         status = true;
00753         }
00754       break;
00755     case VTK_XZ_PLANE:
00756       if( (GridExtent[0] < i) && (i < GridExtent[1] ) &&
00757           (GridExtent[4] < k) && (k < GridExtent[5] ) )
00758         {
00759         status = true;
00760         }
00761       break;
00762     case VTK_XYZ_GRID:
00763       if( (GridExtent[0] < i) && (i < GridExtent[1]) &&
00764           (GridExtent[2] < j) && (j < GridExtent[3]) &&
00765           (GridExtent[4] < k) && (k < GridExtent[5]) )
00766         {
00767         status = true;
00768         }
00769       break;
00770     default:
00771       std::cout << "Data description is: " << this->DataDescription << "\n";
00772       std::cout.flush();
00773       assert( "pre: Undefined data-description!" && false );
00774     } // END switch
00775 
00776   return( status );
00777 }
00778 
00779 //------------------------------------------------------------------------------
00780 inline void vtkStructuredGridConnectivity::DetermineNeighborOrientation(
00781     const int idx, int A[2], int B[2], int overlap[2], int orient[3] )
00782 {
00783   assert( "pre: idx is out-of-bounds" && (idx >= 0) && (idx < 3)  );
00784 
00785   // A. Non-overlapping cases
00786   if( overlap[0] == overlap[1] )
00787     {
00788     if( A[1] == B[0] )
00789       {
00790       orient[ idx ] = vtkStructuredNeighbor::HI;
00791       }
00792     else if( A[0] == B[1] )
00793       {
00794       orient[ idx ] = vtkStructuredNeighbor::LO;
00795       }
00796     else
00797       {
00798       orient[ idx ] = vtkStructuredNeighbor::UNDEFINED;
00799       assert( "ERROR: Code should not reach here!" && false );
00800       }
00801     } // END non-overlapping cases
00802   // B. Sub-set cases
00803   else if( this->IsSubset( A, B) )
00804     {
00805     if( (A[0] == B[0]) && (A[1] == B[1]) )
00806       {
00807       orient[ idx ] = vtkStructuredNeighbor::ONE_TO_ONE;
00808       }
00809     else if( this->StrictlyInsideBounds( A[0], B[0], B[1] ) &&
00810              this->StrictlyInsideBounds( A[1], B[0], B[1] ) )
00811       {
00812       orient[ idx ] = vtkStructuredNeighbor::SUBSET_BOTH;
00813       }
00814     else if( A[0] == B[0] )
00815       {
00816       orient[ idx ] = vtkStructuredNeighbor::SUBSET_HI;
00817       }
00818     else if( A[1] == B[1] )
00819       {
00820       orient[ idx ] = vtkStructuredNeighbor::SUBSET_LO;
00821       }
00822     else
00823       {
00824       orient[ idx ] = vtkStructuredNeighbor::UNDEFINED;
00825       assert( "ERROR: Code should not reach here!" && false );
00826       }
00827     }
00828   // C. Super-set cases
00829   else if( this->IsSubset( B, A ) )
00830     {
00831     orient[ idx ] = vtkStructuredNeighbor::SUPERSET;
00832     }
00833   // D. Partially-overlapping (non-subset) cases
00834   else if( !(this->IsSubset(A,B) || this->IsSubset(A,B)) )
00835     {
00836     if( this->InBounds( A[0], B[0], B[1] ) )
00837       {
00838       orient[ idx ] = vtkStructuredNeighbor::LO;
00839       }
00840     else if( this->InBounds( A[1], B[0], B[1] ) )
00841       {
00842       orient[ idx ] = vtkStructuredNeighbor::HI;
00843       }
00844     else
00845       {
00846       orient[ idx ] = vtkStructuredNeighbor::UNDEFINED;
00847       assert( "ERROR: Code should not reach here!" && false );
00848       }
00849     }
00850   else
00851     {
00852     orient[ idx ] = vtkStructuredNeighbor::UNDEFINED;
00853     assert( "ERROR: Code should not reach here!" && false );
00854     }
00855 }
00856 
00857 //------------------------------------------------------------------------------
00858 inline int vtkStructuredGridConnectivity::Get1DOrientation(
00859         const int idx, const int ExtentLo, const int ExtentHi,
00860         const int OnLo, const int OnHi, const int NotOnBoundary )
00861 {
00862   if( idx == ExtentLo )
00863     {
00864     return OnLo;
00865     }
00866   else if( idx == ExtentHi )
00867     {
00868     return OnHi;
00869     }
00870   return NotOnBoundary;
00871 }
00872 
00873 //------------------------------------------------------------------------------
00874 inline bool vtkStructuredGridConnectivity::HasBlockConnection(
00875     const int gridID, const int blockDirection )
00876 {
00877   // Sanity check
00878   assert("pre: gridID is out-of-bounds" &&
00879         (gridID >=0) && (gridID < static_cast<int>(this->NumberOfGrids)));
00880   assert("pre: BlockTopology has not been properly allocated" &&
00881         (this->NumberOfGrids == this->BlockTopology.size()));
00882   assert("pre: blockDirection is out-of-bounds" &&
00883         (blockDirection >= 0) && (blockDirection < 6) );
00884   bool status = false;
00885   if( this->BlockTopology[ gridID ] & (1 << blockDirection) )
00886     {
00887     status = true;
00888     }
00889   return( status );
00890 }
00891 
00892 //------------------------------------------------------------------------------
00893 inline void vtkStructuredGridConnectivity::RemoveBlockConnection(
00894     const int gridID, const int blockDirection )
00895 {
00896   // Sanity check
00897   assert("pre: gridID is out-of-bounds" &&
00898         (gridID >=0) && (gridID < static_cast<int>(this->NumberOfGrids)));
00899   assert("pre: BlockTopology has not been properly allocated" &&
00900         (this->NumberOfGrids == this->BlockTopology.size()));
00901   assert("pre: blockDirection is out-of-bounds" &&
00902         (blockDirection >= 0) && (blockDirection < 6) );
00903 
00904   this->BlockTopology[ gridID ] &= ~(1 << blockDirection);
00905 }
00906 
00907 //------------------------------------------------------------------------------
00908 inline void vtkStructuredGridConnectivity::AddBlockConnection(
00909     const int gridID, const int blockDirection )
00910 {
00911   // Sanity check
00912   assert("pre: gridID is out-of-bounds" &&
00913         (gridID >=0) && (gridID < static_cast<int>(this->NumberOfGrids)));
00914   assert("pre: BlockTopology has not been properly allocated" &&
00915         (this->NumberOfGrids == this->BlockTopology.size()));
00916   assert("pre: blockDirection is out-of-bounds" &&
00917         (blockDirection >= 0) && (blockDirection < 6) );
00918   this->BlockTopology[ gridID ] |= (1 << blockDirection);
00919 }
00920 
00921 //------------------------------------------------------------------------------
00922 inline void vtkStructuredGridConnectivity::ClearBlockConnections(
00923     const int gridID )
00924 {
00925   // Sanity check
00926   assert("pre: gridID is out-of-bounds" &&
00927         (gridID >=0) && (gridID < static_cast<int>(this->NumberOfGrids)));
00928   assert("pre: BlockTopology has not been properly allocated" &&
00929         (this->NumberOfGrids == this->BlockTopology.size()));
00930   for( int i=0; i < 6; ++i )
00931     {
00932     this->RemoveBlockConnection( gridID, i );
00933     } // END for all block directions
00934 }
00935 
00936 //------------------------------------------------------------------------------
00937 inline int vtkStructuredGridConnectivity::GetNumberOfConnectingBlockFaces(
00938     const int gridID )
00939 {
00940   // Sanity check
00941   assert("pre: gridID is out-of-bounds" &&
00942         (gridID >=0) && (gridID < static_cast<int>(this->NumberOfGrids)));
00943   assert("pre: BlockTopology has not been properly allocated" &&
00944         (this->NumberOfGrids == this->BlockTopology.size()));
00945 
00946   int count = 0;
00947   for( int i=0; i < 6; ++i )
00948     {
00949     if( this->HasBlockConnection( gridID, i ) )
00950       {
00951       ++count;
00952       }
00953     }
00954   assert( "post: count must be in [0,5]" && (count >=0 && count <= 6) );
00955   return( count );
00956 }
00957 
00958 //------------------------------------------------------------------------------
00959 inline void vtkStructuredGridConnectivity::SetNumberOfGrids(
00960     const unsigned int N )
00961 {
00962   this->NumberOfGrids = N;
00963   this->AllocateUserRegisterDataStructures();
00964 
00965   this->GridExtents.resize( 6*N,-1);
00966   this->Neighbors.resize( N );
00967   this->BlockTopology.resize( N );
00968 }
00969 #endif /* vtkStructuredGridConnectivity_H_ */