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