vtkTableExtentTranslator.cxx 9.31 KB
Newer Older
1
2
3
4
5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkTableExtentTranslator.cxx

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7
8
9
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

10
11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
13
14
15
16
17
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkTableExtentTranslator.h"
#include "vtkObjectFactory.h"

Ken Martin's avatar
Ken Martin committed
18
vtkCxxRevisionMacro(vtkTableExtentTranslator, "1.7");
19
20
21
22
23
24
25
vtkStandardNewMacro(vtkTableExtentTranslator);

//----------------------------------------------------------------------------
vtkTableExtentTranslator::vtkTableExtentTranslator()
{
  this->ExtentTable = 0;
  this->MaximumGhostLevel = 0;
26
  this->PieceAvailable = 0;
27
28
29
30
31
}

//----------------------------------------------------------------------------
vtkTableExtentTranslator::~vtkTableExtentTranslator()
{
32
  this->SetNumberOfPieces(0);
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
}

//----------------------------------------------------------------------------
void vtkTableExtentTranslator::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  if(this->ExtentTable)
    {
    vtkIndent nextIndent = indent.GetNextIndent();
    int* extent = this->ExtentTable;
    int i;
    
    os << indent << "ExtentTable: 0: "
       << extent[0] << " " << extent[1] << " "
       << extent[2] << " " << extent[3] << " "
       << extent[4] << " " << extent[5] << "\n";
    for(i=1;i < this->NumberOfPieces;++i)
      {
      extent += 6;
      os << nextIndent << "             " << i << ": "
         << extent[0] << " " << extent[1] << " "
         << extent[2] << " " << extent[3] << " "
         << extent[4] << " " << extent[5] << "\n";
      }
    }
  else
    {
    os << indent << "ExtentTable: (none)\n";
    }
  os << indent << "MaximumGhostLevel: " << this->MaximumGhostLevel << "\n";
Ken Martin's avatar
Ken Martin committed
63
64
  os << indent << "NumberOfPiecesInTable: " 
     << this->NumberOfPiecesInTable << "\n";
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  if(this->PieceAvailable)
    {
    vtkIndent nextIndent = indent.GetNextIndent();
    int* available = this->PieceAvailable;
    int i;
    
    os << indent << "PieceAvailable: 0: " << *available << "\n";
    for(i=1;i < this->NumberOfPieces;++i)
      {
      ++available;
      os << nextIndent << "                " << i << ": "
         << *available << "\n";
      }
    }
  else
    {
    os << indent << "PieceAvailable: (none)\n";
    }
83
84
85
86
}

//----------------------------------------------------------------------------
void vtkTableExtentTranslator::SetNumberOfPieces(int pieces)
87
88
89
90
91
92
93
94
95
96
97
{
  // Allocate a table for this number of pieces.
  if(this->NumberOfPiecesInTable == 0)
    {
    this->SetNumberOfPiecesInTable(pieces);
    }
  this->Superclass::SetNumberOfPieces(pieces);
}

//----------------------------------------------------------------------------
void vtkTableExtentTranslator::SetNumberOfPiecesInTable(int pieces)
98
99
{
  // Make sure we are really changing the number of pieces.
100
  if(this->NumberOfPiecesInTable == pieces)
101
102
103
    {
    return;
    }
104
105
106

  // The default number of pieces returned is the real number of
  // pieces.
107
  this->Superclass::SetNumberOfPieces(pieces);
108

109
110
111
112
113
114
  // Clean out any old extent table.
  if(this->ExtentTable)
    {
    delete [] this->ExtentTable;
    this->ExtentTable = 0;
    }
115
116
117
118
119
  if(this->PieceAvailable)
    {
    delete [] this->PieceAvailable;
    this->PieceAvailable = 0;
    }
120
121
  
  // Create and initialize a new extent table if there are any pieces.
122
  // Assume all pieces are available.
123
  if(this->NumberOfPiecesInTable > 0)
124
    {
125
126
    this->ExtentTable = new int[this->NumberOfPiecesInTable*6];
    this->PieceAvailable = new int[this->NumberOfPiecesInTable];
127
    int i;
128
    for(i=0;i < this->NumberOfPiecesInTable;++i)
129
130
131
132
      {
      int* extent = this->ExtentTable + i*6;
      extent[0] = extent[2] = extent[4] = 0;
      extent[1] = extent[3] = extent[5] = -1;
133
      this->PieceAvailable[i] = 1;
134
135
136
137
138
139
140
      }
    }
}

//----------------------------------------------------------------------------
void vtkTableExtentTranslator::SetExtentForPiece(int piece, int* extent)
{
141
142
  if((!this->ExtentTable) || (piece < 0) ||
     (piece >= this->NumberOfPiecesInTable))
143
144
145
146
147
148
149
150
151
152
    {
    vtkErrorMacro("Piece " << piece << " does not exist.");
    return;
    }
  memcpy(this->ExtentTable+piece*6, extent, sizeof(int)*6);
}

//----------------------------------------------------------------------------
void vtkTableExtentTranslator::GetExtentForPiece(int piece, int* extent)
{
153
154
  if((!this->ExtentTable) || (piece < 0) ||
     (piece >= this->NumberOfPiecesInTable))
155
156
157
158
159
160
161
162
163
164
165
166
167
    {
    vtkErrorMacro("Piece " << piece << " does not exist.");
    extent[0] = extent[2] = extent[4] = 0;
    extent[1] = extent[3] = extent[5] = -1;
    return;
    }
  memcpy(extent, this->ExtentTable+piece*6, sizeof(int)*6);
}

//----------------------------------------------------------------------------
int* vtkTableExtentTranslator::GetExtentForPiece(int piece)
{
  static int emptyExtent[6] = {0,-1,0,-1,0,-1};
168
169
  if((!this->ExtentTable) || (piece < 0) ||
     (piece >= this->NumberOfPiecesInTable))
170
171
172
173
174
175
176
    {
    vtkErrorMacro("Piece " << piece << " does not exist.");
    return emptyExtent;
    }
  return this->ExtentTable+piece*6;
}

177
178
179
//----------------------------------------------------------------------------
void vtkTableExtentTranslator::SetPieceAvailable(int piece, int available)
{
180
181
  if((!this->ExtentTable) || (piece < 0) ||
     (piece >= this->NumberOfPiecesInTable))
182
183
184
185
186
187
188
189
190
    {
    vtkErrorMacro("Piece " << piece << " does not exist.");
    }
  this->PieceAvailable[piece] = available?1:0;
}

//----------------------------------------------------------------------------
int vtkTableExtentTranslator::GetPieceAvailable(int piece)
{
191
192
  if((!this->ExtentTable) || (piece < 0) ||
     (piece >= this->NumberOfPiecesInTable))
193
194
195
196
197
198
199
    {
    vtkErrorMacro("Piece " << piece << " does not exist.");
    return 0;
    }
  return this->PieceAvailable[piece];
}

200
201
202
203
204
205
206
207
208
//----------------------------------------------------------------------------
int vtkTableExtentTranslator::PieceToExtentByPoints()
{
  vtkErrorMacro("PieceToExtentByPoints not supported.");
  return 0;
}

//----------------------------------------------------------------------------
int
209
210
211
212
vtkTableExtentTranslator::PieceToExtentThreadSafe(int piece, int numPieces, 
                                                  int ghostLevel, 
                                                  int *wholeExtent, 
                                                  int *resultExtent, 
Andy Cedilnik's avatar
Andy Cedilnik committed
213
                                                  int vtkNotUsed(splitMode), 
214
                                                  int byPoints)
215
{
216
217
218
219
220
  if (byPoints)
    {
    vtkErrorMacro("PieceToExtentByPoints not supported.");
    return 0;
    }
221

222
223
  if((!this->ExtentTable) || (piece < 0) ||
     (piece >= numPieces))
224
    {
225
    vtkErrorMacro("Piece " << piece << " does not exist.");
226
227
228
    return 0;
    }
  
229
  if(ghostLevel > this->MaximumGhostLevel)
230
    {
231
    vtkWarningMacro("Ghost level " << ghostLevel
232
233
                    << " is larger than MaximumGhostLevel "
                    << this->MaximumGhostLevel << ".  Using the maximum.");
234
    ghostLevel = this->MaximumGhostLevel;
235
    }
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257

  if(numPieces == 1)
    {
    // The number of pieces requested is one.  Return the whole extent.
    memcpy(resultExtent, wholeExtent, sizeof(int)*6);
    }
  else if(piece < this->NumberOfPiecesInTable)
    {
    // The requested piece is beyond the table.  Return an empty extent.
    resultExtent[0] = 0;
    resultExtent[1] = -1;
    resultExtent[2] = 0;
    resultExtent[3] = -1;
    resultExtent[4] = 0;
    resultExtent[5] = -1;
    }
  else
    {
    // Return the extent from the table entry.
    memcpy(resultExtent, this->ExtentTable+piece*6, sizeof(int)*6);
    }

258
259
260
  if(((resultExtent[1] - resultExtent[0] + 1)*
      (resultExtent[3] - resultExtent[2] + 1)*
      (resultExtent[5] - resultExtent[4] + 1)) == 0)
261
262
263
264
    {
    return 0;
    }

265
  if(ghostLevel > 0)
266
    {
267
268
269
270
271
272
    resultExtent[0] -= this->GhostLevel;
    resultExtent[1] += this->GhostLevel;
    resultExtent[2] -= this->GhostLevel;
    resultExtent[3] += this->GhostLevel;
    resultExtent[4] -= this->GhostLevel;
    resultExtent[5] += this->GhostLevel;
273
    
274
    if (resultExtent[0] < wholeExtent[0])
275
      {
276
      resultExtent[0] = wholeExtent[0];
277
      }
278
    if (resultExtent[1] > wholeExtent[1])
279
      {
280
      resultExtent[1] = wholeExtent[1];
281
      }
282
    if (resultExtent[2] < wholeExtent[2])
283
      {
284
      resultExtent[2] = wholeExtent[2];
285
      }
286
    if (resultExtent[3] > wholeExtent[3])
287
      {
288
      resultExtent[3] = wholeExtent[3];
289
      }
290
    if (resultExtent[4] < wholeExtent[4])
291
      {
292
      resultExtent[4] = wholeExtent[4];
293
      }
294
    if (resultExtent[5] > wholeExtent[5])
295
      {
296
      resultExtent[5] = wholeExtent[5];
297
298
299
300
      }
    }
  
  return 1;
301
302
303
304
305
306
307
308
309
310
311
312

}

//----------------------------------------------------------------------------
int vtkTableExtentTranslator::PieceToExtent()
{
  return this->PieceToExtentThreadSafe(this->Piece, this->NumberOfPieces,
                                       this->GhostLevel,
                                       this->WholeExtent,
                                       this->Extent,
                                       this->SplitMode,
                                       0);
313
}