VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkAbstractGridConnectivity.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 =========================================================================*/ 00041 #ifndef VTKABSTRACTGRIDCONNECTIVITY_H_ 00042 #define VTKABSTRACTGRIDCONNECTIVITY_H_ 00043 00044 // VTK includes 00045 #include "vtkFiltersGeometryModule.h" // For export macro 00046 #include "vtkObject.h" 00047 #include "vtkPoints.h" // for vtkPoints definition in STL vector 00048 #include "vtkPointData.h" // for vtkPointData definition in STL vector 00049 #include "vtkCellData.h" // for vtkCellData definition int STL vector 00050 #include "vtkUnsignedCharArray.h" // for vtkUnsignedCharArray definition 00051 00052 // Forward declarations 00053 class vtkPointData; 00054 class vtkCellData; 00055 class vtkUnsignedCharArray; 00056 class vtkPoints; 00057 00058 // C++ include directives 00059 #include <vector> // For STL vector 00060 #include <cassert> // For assert 00061 00062 class VTKFILTERSGEOMETRY_EXPORT vtkAbstractGridConnectivity : public vtkObject 00063 { 00064 public: 00065 vtkTypeMacro( vtkAbstractGridConnectivity, vtkObject ); 00066 void PrintSelf(ostream &os,vtkIndent indent ); 00067 00069 00070 vtkSetMacro( NumberOfGhostLayers, unsigned int ); 00071 vtkGetMacro( NumberOfGhostLayers, unsigned int); 00073 00079 virtual void SetNumberOfGrids( const unsigned int N ) = 0; 00080 00082 unsigned int GetNumberOfGrids() { return this->NumberOfGrids; }; 00083 00085 virtual void ComputeNeighbors( ) = 0; 00086 00091 virtual void CreateGhostLayers( const int N=1 ) = 0; 00092 00097 vtkUnsignedCharArray* GetGhostedPointGhostArray( const int gridID ); 00098 00103 vtkUnsignedCharArray* GetGhostedCellGhostArray( const int gridID ); 00104 00109 vtkPointData* GetGhostedGridPointData( const int gridID ); 00110 00115 vtkCellData* GetGhostedGridCellData( const int gridID ); 00116 00121 vtkPoints* GetGhostedPoints( const int gridID ); 00122 00123 protected: 00124 vtkAbstractGridConnectivity(); 00125 virtual ~vtkAbstractGridConnectivity(); 00126 00128 00129 virtual void FillGhostArrays( 00130 const int gridId, 00131 vtkUnsignedCharArray* nodesArray, 00132 vtkUnsignedCharArray* cellsArray ) = 0; 00134 00136 00137 void RegisterGridGhostArrays( 00138 const int gridID,vtkUnsignedCharArray *nodesArray, 00139 vtkUnsignedCharArray *cellsArray ); 00141 00143 00144 void RegisterFieldData( 00145 const int gridID, vtkPointData *PointData, vtkCellData *CellData ); 00147 00150 void RegisterGridNodes( const int gridID, vtkPoints *nodes ); 00151 00152 00154 00156 void AllocateUserRegisterDataStructures(); 00157 void DeAllocateUserRegisterDataStructures(); 00159 00161 00163 void AllocateInternalDataStructures(); 00164 void DeAllocateInternalDataStructures(); 00166 00167 // The total number of grids, set initially by the user. 00168 unsigned int NumberOfGrids; 00169 unsigned int NumberOfGhostLayers; 00170 00171 // BTX 00172 // Arrays registered by the user for each grid 00173 std::vector< vtkUnsignedCharArray* > GridPointGhostArrays; 00174 std::vector< vtkUnsignedCharArray* > GridCellGhostArrays; 00175 std::vector< vtkPointData* > GridPointData; 00176 std::vector< vtkCellData* > GridCellData; 00177 std::vector< vtkPoints* > GridPoints; 00178 00179 // Arrays computed internally for each grid 00180 bool AllocatedGhostDataStructures; 00181 std::vector< vtkPointData* > GhostedGridPointData; 00182 std::vector< vtkCellData* > GhostedGridCellData; 00183 std::vector< vtkUnsignedCharArray* > GhostedPointGhostArray; 00184 std::vector< vtkUnsignedCharArray* > GhostedCellGhostArray; 00185 std::vector< vtkPoints* > GhostedGridPoints; 00186 // ETX 00187 00188 private: 00189 vtkAbstractGridConnectivity(const vtkAbstractGridConnectivity&);// Not implemented 00190 void operator=(const vtkAbstractGridConnectivity&); // Not implemented 00191 }; 00192 00193 //------------------------------------------------------------------------------ 00194 inline vtkUnsignedCharArray* 00195 vtkAbstractGridConnectivity::GetGhostedPointGhostArray( const int gridID ) 00196 { 00197 if( !this->AllocatedGhostDataStructures ) 00198 { 00199 return NULL; 00200 } 00201 00202 00203 assert( "pre: GridID is out-of-bound GridPointData" && 00204 (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids) ) ); 00205 assert( "pre: Ghosted point ghost array" && 00206 (this->NumberOfGrids == this->GhostedPointGhostArray.size() ) ); 00207 00208 return( this->GhostedPointGhostArray[ gridID ] ); 00209 } 00210 00211 //------------------------------------------------------------------------------ 00212 inline vtkUnsignedCharArray* 00213 vtkAbstractGridConnectivity::GetGhostedCellGhostArray( const int gridID ) 00214 { 00215 if( !this->AllocatedGhostDataStructures ) 00216 { 00217 return NULL; 00218 } 00219 00220 assert( "pre: GridID is out-of-bound GridPointData" && 00221 (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids))); 00222 assert( "pre: Ghosted point ghost array" && 00223 (this->NumberOfGrids == this->GhostedCellGhostArray.size() ) ); 00224 00225 return( this->GhostedCellGhostArray[ gridID ] ); 00226 } 00227 00228 //------------------------------------------------------------------------------ 00229 inline vtkPointData* 00230 vtkAbstractGridConnectivity::GetGhostedGridPointData( const int gridID ) 00231 { 00232 if( !this->AllocatedGhostDataStructures ) 00233 { 00234 return NULL; 00235 } 00236 00237 assert( "pre: GridID is out-of-bound GridPointData" && 00238 (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids))); 00239 assert( "pre: Ghosted point ghost array" && 00240 (this->NumberOfGrids == this->GhostedGridPointData.size() ) ); 00241 00242 return( this->GhostedGridPointData[ gridID ] ); 00243 } 00244 00245 //------------------------------------------------------------------------------ 00246 inline vtkCellData* 00247 vtkAbstractGridConnectivity::GetGhostedGridCellData( const int gridID ) 00248 { 00249 if( !this->AllocatedGhostDataStructures ) 00250 { 00251 return NULL; 00252 } 00253 00254 assert( "pre: GridID is out-of-bound GridPointData" && 00255 (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids))); 00256 assert( "pre: Ghosted point ghost array" && 00257 (this->NumberOfGrids == this->GhostedGridCellData.size() ) ); 00258 00259 return( this->GhostedGridCellData[ gridID ] ); 00260 } 00261 00262 //------------------------------------------------------------------------------ 00263 inline vtkPoints* 00264 vtkAbstractGridConnectivity::GetGhostedPoints( const int gridID ) 00265 { 00266 if( !this->AllocatedGhostDataStructures ) 00267 { 00268 return NULL; 00269 } 00270 00271 assert( "pre: GridID is out-of-bound GridPointData" && 00272 (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids))); 00273 assert( "pre: Ghosted point ghost array" && 00274 (this->NumberOfGrids == this->GhostedGridPoints.size() ) ); 00275 00276 return( this->GhostedGridPoints[ gridID ] ); 00277 } 00278 00279 //------------------------------------------------------------------------------ 00280 inline void 00281 vtkAbstractGridConnectivity::AllocateUserRegisterDataStructures() 00282 { 00283 // Sanity Check 00284 assert( "pre: Allocating UserRegister for N > 0 grids" && 00285 (this->NumberOfGrids > 0) ); 00286 00287 this->GridPointGhostArrays.resize( this->NumberOfGrids, NULL ); 00288 this->GridCellGhostArrays.resize( this->NumberOfGrids, NULL ); 00289 this->GridPointData.resize( this->NumberOfGrids, NULL ); 00290 this->GridCellData.resize( this->NumberOfGrids, NULL ); 00291 this->GridPoints.resize( this->NumberOfGrids, NULL ); 00292 } 00293 00294 //------------------------------------------------------------------------------ 00295 inline void 00296 vtkAbstractGridConnectivity::DeAllocateUserRegisterDataStructures() 00297 { 00298 assert( "pre: Data-structure has not been properly allocated" && 00299 (this->GridPointGhostArrays.size() == this->NumberOfGrids ) ); 00300 assert( "pre: Data-structure has not been properly allocated" && 00301 (this->GridCellGhostArrays.size() == this->NumberOfGrids ) ); 00302 assert( "pre: Data-structure has not been properly allocated" && 00303 (this->GridPointData.size() == this->NumberOfGrids ) ); 00304 assert( "pre: Data-structure has not been properly allocated" && 00305 (this->GridCellData.size() == this->NumberOfGrids ) ); 00306 assert( "pre: Data-structure has not been properly allocated" && 00307 (this->GridPoints.size() == this->NumberOfGrids ) ); 00308 00309 for( unsigned int i=0; i < this->NumberOfGrids; ++i ) 00310 { 00311 // NOTE: Ghost arrays are not deleted here b/c when they are registered, they 00312 // are not shallow-copied. 00313 // if( this->GridPointGhostArrays[i] != NULL ) 00314 // { 00315 // this->GridPointGhostArrays[i]->Delete(); 00316 // } 00317 // if( this->GridCellGhostArrays[i] != NULL ) 00318 // { 00319 // this->GridCellGhostArrays[i]->Delete(); 00320 // } 00321 if( this->GridPointData[i] != NULL ) 00322 { 00323 this->GridPointData[i]->Delete(); 00324 } 00325 if( this->GridCellData[i] != NULL ) 00326 { 00327 this->GridCellData[i]->Delete(); 00328 } 00329 if( this->GridPoints[i] != NULL ) 00330 { 00331 this->GridPoints[i]->Delete(); 00332 } 00333 } // END for all grids 00334 00335 this->GridPointGhostArrays.clear(); 00336 this->GridCellGhostArrays.clear(); 00337 this->GridPointData.clear(); 00338 this->GridCellData.clear(); 00339 this->GridPoints.clear(); 00340 } 00341 00342 //------------------------------------------------------------------------------ 00343 inline void 00344 vtkAbstractGridConnectivity::AllocateInternalDataStructures() 00345 { 00346 assert( "pre: Allocating Internal data-structured for N > 0 grids" && 00347 (this->NumberOfGrids > 0) ); 00348 00349 this->GhostedGridPointData.resize( this->NumberOfGrids, NULL ); 00350 this->GhostedGridCellData.resize( this->NumberOfGrids, NULL ); 00351 this->GhostedPointGhostArray.resize( this->NumberOfGrids, NULL ); 00352 this->GhostedCellGhostArray.resize( this->NumberOfGrids, NULL ); 00353 this->GhostedGridPoints.resize( this->NumberOfGrids, NULL ); 00354 this->AllocatedGhostDataStructures = true; 00355 } 00356 00357 //------------------------------------------------------------------------------ 00358 inline void 00359 vtkAbstractGridConnectivity::DeAllocateInternalDataStructures() 00360 { 00361 if( !this->AllocatedGhostDataStructures ) 00362 { 00363 return; 00364 } 00365 00366 assert( "pre: Data-structure has not been properly allocated" && 00367 (this->GhostedGridPointData.size() == this->NumberOfGrids) ); 00368 assert( "pre: Data-structure has not been properly allocated" && 00369 (this->GhostedGridCellData.size() == this->NumberOfGrids) ); 00370 assert( "pre: Data-structure has not been properly allocated" && 00371 (this->GhostedPointGhostArray.size() == this->NumberOfGrids) ); 00372 assert( "pre: Data-structure has not been properly allocated" && 00373 (this->GhostedCellGhostArray.size() == this->NumberOfGrids ) ); 00374 assert( "pre: Data-structure has not been properly allocated" && 00375 (this->GhostedGridPoints.size() == this->NumberOfGrids ) ); 00376 00377 for( unsigned int i=0; i < this->NumberOfGrids; ++i ) 00378 { 00379 if( this->GhostedGridPointData[i] != NULL ) 00380 { 00381 this->GhostedGridPointData[i]->Delete(); 00382 } 00383 if( this->GhostedGridCellData[i] != NULL ) 00384 { 00385 this->GhostedGridCellData[i]->Delete(); 00386 } 00387 if( this->GhostedPointGhostArray[i] != NULL ) 00388 { 00389 this->GhostedPointGhostArray[i]->Delete(); 00390 } 00391 if( this->GhostedCellGhostArray[i] != NULL ) 00392 { 00393 this->GhostedCellGhostArray[i]->Delete(); 00394 } 00395 if( this->GhostedGridPoints[i] != NULL ) 00396 { 00397 this->GhostedGridPoints[i]->Delete(); 00398 } 00399 } // END for all grids 00400 00401 this->GhostedGridPointData.clear(); 00402 this->GhostedGridCellData.clear(); 00403 this->GhostedPointGhostArray.clear(); 00404 this->GhostedCellGhostArray.clear(); 00405 this->GhostedGridPoints.clear(); 00406 00407 this->AllocatedGhostDataStructures = false; 00408 } 00409 00410 //------------------------------------------------------------------------------ 00411 inline void vtkAbstractGridConnectivity::RegisterGridGhostArrays( 00412 const int gridID, 00413 vtkUnsignedCharArray *nodesArray, 00414 vtkUnsignedCharArray *cellsArray ) 00415 { 00416 // Sanity check 00417 assert( "pre: GridID is out-of-bound GridPointData" && 00418 (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids))); 00419 assert( "pre: GridPointGhostArrays has not been allocated" && 00420 (this->GridPointGhostArrays.size() == this->NumberOfGrids) ); 00421 assert( "pre: GridCellGhostArrays has not been allocated" && 00422 (this->GridCellGhostArrays.size() == this->NumberOfGrids ) ); 00423 00424 // NOTE: We should really shallow copy the objects here 00425 this->GridPointGhostArrays[ gridID ] = nodesArray; 00426 this->GridCellGhostArrays[ gridID ] = cellsArray; 00427 } 00428 00429 //------------------------------------------------------------------------------ 00430 inline void vtkAbstractGridConnectivity::RegisterFieldData( 00431 const int gridID, vtkPointData *PointData, vtkCellData *CellData ) 00432 { 00433 // Sanity check 00434 assert( "pre: GridID is out-of-bound GridPointData" && 00435 (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids))); 00436 assert( "pre: GridPointData has not been allocated!" && 00437 (this->GridPointData.size() == this->NumberOfGrids ) ); 00438 assert( "pre: GridCellData has not been allocated!" && 00439 (this->GridCellData.size() == this->NumberOfGrids ) ); 00440 00441 // Note: The size of these vectors is allocated in SetNumberOfGrids 00442 if( PointData != NULL ) 00443 { 00444 assert( "pre: GridPointData[gridID] must be NULL" && 00445 this->GridPointData[ gridID ]==NULL ); 00446 this->GridPointData[ gridID ] = vtkPointData::New(); 00447 this->GridPointData[ gridID ]->ShallowCopy( PointData ); 00448 } 00449 else 00450 { 00451 this->GridPointData[ gridID ] = NULL; 00452 } 00453 00454 if( CellData != NULL ) 00455 { 00456 assert( "pre: GridCellData[gridID] must be NULL" && 00457 this->GridCellData[gridID]==NULL ); 00458 this->GridCellData[ gridID ] = vtkCellData::New(); 00459 this->GridCellData[ gridID ]->ShallowCopy( CellData ); 00460 } 00461 else 00462 { 00463 this->GridCellData[ gridID ] = NULL; 00464 } 00465 } 00466 00467 //------------------------------------------------------------------------------ 00468 inline void vtkAbstractGridConnectivity::RegisterGridNodes( 00469 const int gridID, vtkPoints *nodes ) 00470 { 00471 // Sanity check 00472 assert( "pre: GridID is out-of-bound GridPointData" && 00473 (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids))); 00474 assert( "pre: GridPoints has not been allocated!" && 00475 (this->GridPoints.size() == this->NumberOfGrids) ); 00476 00477 if( nodes != NULL ) 00478 { 00479 assert( "pre:GridPoints[gridID] must be NULL" && 00480 this->GridPoints[gridID]==NULL ); 00481 this->GridPoints[ gridID ] = vtkPoints::New(); 00482 this->GridPoints[ gridID ]->SetDataTypeToDouble(); 00483 this->GridPoints[ gridID ]->ShallowCopy( nodes ); 00484 } 00485 else 00486 { 00487 this->GridPoints[ gridID ] = NULL; 00488 } 00489 } 00490 00491 #endif /* VTKABSTRACTGRIDCONNECTIVITY_H_ */