vtkMaterialInterfaceCommBuffer.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
3 // SPDX-License-Identifier: BSD-3-Clause
4 #ifndef vtkMaterialInterfaceCommBuffer_h
5 #define vtkMaterialInterfaceCommBuffer_h
6 
7 #include "vtkPVVTKExtensionsFiltersMaterialInterfaceModule.h" //needed for exports
8 #include "vtkType.h" // for vtkIdType
9 
10 #include <vector> // for std::vector
11 
12 class vtkDoubleArray;
13 class vtkFloatArray;
14 // class vtkMaterialInterfaceCommBuffer;
15 // ostream &operator<<(ostream &sout,const vtkMaterialInterfaceCommBuffer &fcb);
16 
17 //============================================================================
18 // Description:
19 // FIFO buffer.
20 // Can be used to send all attributes and ids
21 // in a single send. UnPack in the same order that you
22 // packed.
24 {
25 public:
26  // header layout
27  enum
28  {
29  PROC_ID = 0, // sender's id
30  BUFFER_SIZE = 1, // size of buffer(bytes)
31  DESCR_BASE = 2
32  }; // index to first descriptor
33  // descriptor is nfragments
34  // in each block. Each block gets a descriptor.
35  //
37  //
39  // Description:
40  // Initialize for outgoing comm.
41  void Initialize(int procId, int nBlocks, vtkIdType nBytes);
42  // Description:
43  // Set up for an incoming header.
44  void SizeHeader(int nBlocks);
45  // Description:
46  // Set up for a set of incoming header.
47  static void SizeHeader(std::vector<vtkMaterialInterfaceCommBuffer>& buffers, int nBlocks);
48  // Description:
49  // Initialize the buffer.
50  void SizeBuffer(vtkIdType nBytes);
51  // Description:
52  // Initialize the buffer from incoming header.
53  void SizeBuffer();
54  // Description:
55  // Free resources set to invalid state.
56  void Clear();
57  // Description:
58  // Get size in bytes of the buffer.
59  vtkIdType GetBufferSize() const { return this->Header[BUFFER_SIZE]; }
60  // Description:
61  // Get a pointer to the buffer
62  char* GetBuffer() const { return this->Buffer; }
63  // Description:
64  // Get the byte that the next rerad or write will occur at
65  vtkIdType GetEOD() const { return this->EOD; }
66  // Description:
67  // Get size in bytes of the header.
68  int GetHeaderSize() const { return this->HeaderSize; }
69  // Description:
70  // Get a pointer to the header.
71  vtkIdType* GetHeader() const { return this->Header; }
72  // Description:
73  // Get the total memory used.
74  vtkIdType Capacity() { return this->GetHeaderSize() + this->GetBufferSize(); }
75  // Description:
76  // Set the number of tuples for a given block.
77  void SetNumberOfTuples(int blockId, vtkIdType nFragments)
78  {
79  int idx = DESCR_BASE + blockId;
80  this->Header[idx] = nFragments;
81  }
82  // Description:
83  // Get the number of tuples for a given block
84  vtkIdType GetNumberOfTuples(int blockId) const
85  {
86  int idx = DESCR_BASE + blockId;
87  return this->Header[idx];
88  }
89  // Description:
90  // Append the data to the buffer. Return the index where
91  // the data was written.
92  vtkIdType Pack(const double* pData, int nComps, vtkIdType nTups);
93  vtkIdType Pack(const float* pData, int nComps, vtkIdType nTups);
94  vtkIdType Pack(const int* pData, int nComps, vtkIdType nTups);
95  vtkIdType Pack(vtkDoubleArray* da);
96  vtkIdType Pack(vtkFloatArray* da);
97  // Description:
98  // Prepare to un pack the buffer.
99  void InitUnpack() { this->EOD = 0; }
100  // Description:
101  // Extract the next array from the buffer
102  int UnPack(double*& rData, int nComps, vtkIdType nTups, bool copyFlag);
103  int UnPack(float*& rData, int nComps, vtkIdType nTups, bool copyFlag);
104  int UnPack(int*& rData, int nComps, vtkIdType nTups, bool copyFlag);
105  int UnPack(vtkDoubleArray* da, int nComps, vtkIdType nTups, bool copyFlag);
106  int UnPack(vtkFloatArray* da, int nComps, vtkIdType nTups, bool copyFlag);
107  // static void Resize(std::vector<vtkMaterialInterfaceCommBuffer> &buffers);
108 private:
109  vtkIdType EOD;
110  char* Buffer;
111  int HeaderSize;
112  vtkIdType* Header;
113 };
114 #endif
#define VTKPVVTKEXTENSIONSFILTERSMATERIALINTERFACE_EXPORT
int vtkIdType
void SetNumberOfTuples(int blockId, vtkIdType nFragments)
vtkIdType GetNumberOfTuples(int blockId) const