VTK
dox/IO/vtkLSDynaPartCollection.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkLSDynaPartCollection.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 
00015 #ifndef __vtkLSDynaPartCollection_h
00016 #define __vtkLSDynaPartCollection_h
00017 
00018 #include "LSDynaMetaData.h" //needed for LSDynaMetaData::LSDYNA_TYPES enum
00019 #include "vtkObject.h"
00020 
00021 class vtkDataArray;
00022 class vtkUnstructuredGrid;
00023 class vtkPoints;
00024 class vtkUnsignedCharArray;
00025 class vtkLSDynaPart;
00026 
00027 class VTK_IO_EXPORT vtkLSDynaPartCollection: public vtkObject
00028 {
00029 public:
00030   class LSDynaPart;
00031   static vtkLSDynaPartCollection *New();
00032 
00033   vtkTypeMacro(vtkLSDynaPartCollection,vtkObject);
00034   virtual void PrintSelf(ostream &os, vtkIndent indent);
00035 
00036   //Description:
00037   //Pass in the metadata to setup this collection.
00038   //The optional min and max cell Id are used when in parallel to load balance the nodes.
00039   //Meaning the collection will only store subsections of parts that fall within
00040   //the range of the min and max
00041   //Note: min is included, and max is excluded from the valid range of cells.
00042   void InitCollection(LSDynaMetaData *metaData,
00043     vtkIdType* mins=NULL, vtkIdType* maxs=NULL);
00044 
00045 
00046   //Description:
00047   //For a given part type returns the number of cells to read and the number
00048   //of cells to skip first to not read
00049   void GetPartReadInfo(const int& partType, vtkIdType& numberOfCells,
00050     vtkIdType& numCellsToSkip,vtkIdType& numCellsToSkipEnd) const;
00051 
00052   //Description:
00053   //Finalizes the cell topology by mapping the cells point indexes
00054   //to a relative number based on the cells this collection is storing
00055   void FinalizeTopology();
00056 
00057 
00058   //Description: Register a cell of a given type and material index to the
00059   //correct part
00060   //NOTE: the cellIndex is relative to the collection. So in parallel
00061   //the cellIndex will be from 0 to MaxId-MinId
00062   void RegisterCellIndexToPart(const int& partType,const vtkIdType& matIdx,
00063                      const vtkIdType& cellIndex,const vtkIdType& npts);
00064 
00065   void InitCellInsertion();
00066 
00067   void AllocateParts();
00068 
00069   //Description: Insert a cell of a given type and material index to the 
00070   //collection.
00071   //NOTE: the cellIndex is relative to the collection. So in parallel
00072   //the cellIndex will be from 0 to MaxId-MinId
00073   void InsertCell(const int& partType,const vtkIdType& matIdx,
00074                   const int& cellType,const vtkIdType& npts, vtkIdType conn[8]);
00075 
00076   //Description:
00077   //Set for each part type what cells are deleted/dead
00078   void SetCellDeadFlags(const int& partType, vtkUnsignedCharArray *death,
00079                         const int& deadCellsAsGhostArray);
00080 
00081   bool IsActivePart(const int& id) const;
00082 
00083   //Description:
00084   //Given a part will return the unstructured grid for the part.
00085   //Note: You must call finalize before using this method
00086   vtkUnstructuredGrid* GetGridForPart(const int& index) const;
00087 
00088   int GetNumberOfParts() const;
00089 
00090   void DisbleDeadCells();
00091 
00092   //Description:
00093   void ReadPointUserIds(const vtkIdType& numTuples,const char* name);
00094 
00095   //Description:
00096   void ReadPointProperty(
00097                          const vtkIdType& numTuples,
00098                          const vtkIdType& numComps,
00099                          const char* name,
00100                          const bool &isProperty=true,
00101                          const bool& isGeometryPoints=false,
00102                          const bool& isRoadPoints=false);
00103 
00104 
00105 
00106   //Description:
00107   //Adds a property for all parts of a certain type
00108   void AddProperty(const LSDynaMetaData::LSDYNA_TYPES& type, const char* name,
00109                     const int& offset, const int& numComps);  
00110   void FillCellProperties(float *buffer,const LSDynaMetaData::LSDYNA_TYPES& type,
00111                           const vtkIdType& startId, const vtkIdType& numCells,
00112                           const int& numPropertiesInCell);
00113   void FillCellProperties(double *buffer,const LSDynaMetaData::LSDYNA_TYPES& type,
00114                           const vtkIdType& startId, const vtkIdType& numCells,
00115                           const int& numPropertiesInCell);
00116 
00117   //Description:
00118   //Adds User Ids for all parts of a certain type
00119   void ReadCellUserIds(
00120       const LSDynaMetaData::LSDYNA_TYPES& type, const int& status);
00121   
00122   template<typename T>
00123   void FillCellUserId(T *buffer,const LSDynaMetaData::LSDYNA_TYPES& type,
00124     const vtkIdType& startId, const vtkIdType& numCells)
00125     {
00126     this->FillCellUserIdArray(buffer,type,startId,numCells);
00127     }
00128 
00129 protected:
00130   vtkLSDynaPartCollection();
00131   ~vtkLSDynaPartCollection();
00132 
00133   vtkIdType* MinIds;
00134   vtkIdType* MaxIds;
00135 
00136   //Builds up the basic meta information needed for topology storage
00137   void BuildPartInfo();
00138 
00139   //Description:
00140   //Breaks down the buffer of cell properties to the cell properties we
00141   //are interested in. This will remove all properties that aren't active or
00142   //for parts we are not loading
00143   template<typename T>
00144   void FillCellArray(T *buffer,const LSDynaMetaData::LSDYNA_TYPES& type,
00145      const vtkIdType& startId, vtkIdType numCells, const int& numTuples);
00146 
00147   template<typename T>
00148   void FillCellUserIdArray(T *buffer,const LSDynaMetaData::LSDYNA_TYPES& type,
00149      const vtkIdType& startId, vtkIdType numCells);
00150 
00151   //Description:
00152   //Methods for adding points to the collection
00153   void SetupPointPropertyForReading(
00154                          const vtkIdType& numTuples,
00155                          const vtkIdType& numComps,
00156                          const char* name,
00157                          const bool& isIdType,
00158                          const bool& isProperty,
00159                          const bool& isGeometryPoints,
00160                          const bool& isRoadPoints);
00161   template<typename T>
00162   void FillPointProperty(const vtkIdType& numTuples,
00163                          const vtkIdType& numComps,
00164                          vtkLSDynaPart** parts, const vtkIdType numParts);
00165 
00166 private:
00167   vtkLSDynaPartCollection( const vtkLSDynaPartCollection& ); // Not implemented.
00168   void operator = ( const vtkLSDynaPartCollection& ); // Not implemented.
00169 
00170   LSDynaMetaData *MetaData;
00171   
00172   class LSDynaPartStorage;
00173   LSDynaPartStorage* Storage;
00174 };
00175 
00176 
00177 
00178 #endif // LSDYNAPARTS_H