vtkAMRDataSetCache.cxx 6.84 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*=========================================================================

 Program:   Visualization Toolkit
 Module:    vtkAMRDataSetCache.cxx

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

 This software is distributed WITHOUT ANY WARRANTY; without even
 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 PURPOSE.  See the above copyright notice for more information.

 =========================================================================*/

#include "vtkAMRDataSetCache.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
20
#include "vtkDataArray.h"
21
#include "vtkUniformGrid.h"
George Zagaris's avatar
George Zagaris committed
22
#include "vtkTimerLog.h"
23
24
25
26
27
28
29
30
31
32
33
#include <cassert>

vtkStandardNewMacro( vtkAMRDataSetCache );

vtkAMRDataSetCache::vtkAMRDataSetCache()
{
}

//------------------------------------------------------------------------------
vtkAMRDataSetCache::~vtkAMRDataSetCache()
{
34
35
36
  AMRCacheType::iterator iter = this->Cache.begin();
  for( ; iter != this->Cache.end(); ++iter )
    {
37
38
39
40
41
    if( iter->second != NULL )
      {
      iter->second->Delete();
      }
    this->Cache.erase( iter );
42
    }
43
44
45
46
47
48
49
50
51
52
}

//------------------------------------------------------------------------------
void vtkAMRDataSetCache::PrintSelf( std::ostream &os, vtkIndent indent )
{
  this->Superclass::PrintSelf( os, indent );
}

//------------------------------------------------------------------------------
void vtkAMRDataSetCache::InsertAMRBlock(
53
    int compositeIdx, vtkUniformGrid *amrGrid)
54
55
56
{
  assert( "pre: AMR block is NULL" && (amrGrid != NULL) );

George Zagaris's avatar
George Zagaris committed
57
  vtkTimerLog::MarkStartEvent( "AMRCache::InsertBlock" );
58
59
  if( !this->HasAMRBlock( compositeIdx ) )
    {
60
    this->Cache[ compositeIdx ] = amrGrid;
61
    }
George Zagaris's avatar
George Zagaris committed
62
  vtkTimerLog::MarkEndEvent( "AMRCache::InsertBlock" );
63
64
65
66
}

//------------------------------------------------------------------------------
void vtkAMRDataSetCache::InsertAMRBlockPointData(
67
   int compositeIdx, vtkDataArray *dataArray )
68
69
70
71
{
  assert( "pre: AMR array is NULL" && (dataArray != NULL) );
  assert( "pre: AMR block is cached" && ( this->HasAMRBlock( compositeIdx ) ) );

George Zagaris's avatar
George Zagaris committed
72
73
  vtkTimerLog::MarkStartEvent( "AMRCache::InsertAMRBlockPointData" );

74
75
76
77
78
79
80
  vtkUniformGrid *amrBlock = this->GetAMRBlock( compositeIdx );
  assert( "pre: AMR block should not be NULL" && ( amrBlock != NULL ) );

  vtkPointData *PD = amrBlock ->GetPointData();
  assert( "pre: PointData should not be NULL" && ( PD != NULL ) );

  if( !PD->HasArray( dataArray->GetName() ) )
81
    {
82
    PD->AddArray( dataArray );
83
    }
George Zagaris's avatar
George Zagaris committed
84
85

  vtkTimerLog::MarkEndEvent( "AMRCache::InsertAMRBlockPointData" );
86
87
88
89
}

//------------------------------------------------------------------------------
void vtkAMRDataSetCache::InsertAMRBlockCellData(
90
   int compositeIdx, vtkDataArray *dataArray )
91
92
93
94
{
  assert( "pre: AMR array is NULL" && (dataArray != NULL) );
  assert( "pre: AMR block is cached" && ( this->HasAMRBlock( compositeIdx ) ) );

George Zagaris's avatar
George Zagaris committed
95
96
  vtkTimerLog::MarkStartEvent( "AMRCache::InsertAMRBlockCellData" );

97
98
99
100
101
102
103
104
  vtkUniformGrid *amrBlock = this->GetAMRBlock( compositeIdx );
  assert( "pre: AMR block should not be NULL" &&
          (this->HasAMRBlock( compositeIdx ) ) );

  vtkCellData *CD = amrBlock ->GetCellData();
  assert( "pre: CellData should not be NULL" && (CD != NULL) );

  if( !CD->HasArray( dataArray->GetName() ) )
105
    {
106
    CD->AddArray( dataArray );
107
    }
George Zagaris's avatar
George Zagaris committed
108
109

  vtkTimerLog::MarkEndEvent( "AMRCache::InsertAMRBlockCellData" );
110
111
112
113
}

//------------------------------------------------------------------------------
vtkDataArray* vtkAMRDataSetCache::GetAMRBlockCellData(
114
    int compositeIdx, const char *dataName )
115
116
117
{
  if( this->HasAMRBlockCellData( compositeIdx, dataName ) )
    {
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
    vtkUniformGrid *amrBlock = this->GetAMRBlock( compositeIdx );
    assert( "pre: AMR block should not be NULL" &&
            (this->HasAMRBlock( compositeIdx ) ) );

    vtkCellData *CD = amrBlock ->GetCellData();
    assert( "pre: CellData should not be NULL" && (CD != NULL) );

    if( CD->HasArray( dataName ) )
      {
      return CD->GetArray( dataName );
      }
    else
      {
      return NULL;
      }
133
134
135
136
137
138
    }
  return NULL;
}

//------------------------------------------------------------------------------
vtkDataArray* vtkAMRDataSetCache::GetAMRBlockPointData(
139
    int compositeIdx, const char *dataName )
140
141
142
143
{

  if( this->HasAMRBlockPointData( compositeIdx, dataName ) )
    {
144
145
146
147
148
149
150
151
152
153
154
155
156
157
    vtkUniformGrid *amrBlock = this->GetAMRBlock( compositeIdx );
    assert( "pre: AMR block should not be NULL" && ( amrBlock != NULL ) );

    vtkPointData *PD = amrBlock ->GetPointData();
    assert( "pre: PointData should not be NULL" && ( PD != NULL ) );

    if( PD->HasArray( dataName ) )
      {
      return PD->GetArray( dataName );
      }
    else
      {
      return NULL;
      }
158
159
160
161
162
163
164
165
    }
  return NULL;
}

//------------------------------------------------------------------------------
vtkUniformGrid* vtkAMRDataSetCache::GetAMRBlock( const int compositeIdx )
{
  if( this->HasAMRBlock( compositeIdx ) )
166
    {
167
    return this->Cache[ compositeIdx ];
168
    }
169
170
171
172
173
  return NULL;
}

//------------------------------------------------------------------------------
bool vtkAMRDataSetCache::HasAMRBlockCellData(
174
    int compositeIdx, const char *name)
175
176
177
178
179
{
  assert( "pre: array name is NULL" && (name != NULL) );

  if( this->HasAMRBlock( compositeIdx ) )
    {
180
181
    vtkUniformGrid *gridPtr = this->GetAMRBlock( compositeIdx );
    assert( "pre: cachedk block is NULL!" && (gridPtr != NULL) );
182

183
184
    vtkCellData *CD = gridPtr->GetCellData();
    assert( "pre: cell data is NULL" && (CD != NULL) );
185

186
187
188
189
190
191
192
193
    if( CD->HasArray( name ) )
      {
      return true;
      }
    else
      {
      return false;
      }
194
195
196
197
198
199
    }
  return false;
}

//------------------------------------------------------------------------------
bool vtkAMRDataSetCache::HasAMRBlockPointData(
200
    int compositeIdx, const char *name)
201
202
203
204
205
{
  assert( "pre: array name is NULL" && (name != NULL) );

  if( this->HasAMRBlock( compositeIdx ) )
    {
206
207
    vtkUniformGrid *gridPtr = this->GetAMRBlock( compositeIdx );
    assert( "pre: cachedk block is NULL!" && (gridPtr != NULL) );
208

209
210
    vtkPointData *PD = gridPtr->GetPointData();
    assert( "pre: point data is NULL" && (PD != NULL) );
211

212
213
214
215
216
217
218
219
    if( PD->HasArray( name ) )
      {
      return true;
      }
    else
      {
      return false;
      }
220
221
222
223
224
    }
  return false;
}

//------------------------------------------------------------------------------
225
bool vtkAMRDataSetCache::HasAMRBlock(int compositeIdx )
226
{
George Zagaris's avatar
George Zagaris committed
227
228
  vtkTimerLog::MarkStartEvent( "AMRCache::CheckIfBlockExists" );

229
  if( this->Cache.empty( ) )
George Zagaris's avatar
George Zagaris committed
230
    {
231
232
    vtkTimerLog::MarkEndEvent( "AMRCache::CheckIfBlockExists" );
    return false;
George Zagaris's avatar
George Zagaris committed
233
    }
234

235
  if( this->Cache.find( compositeIdx ) != this->Cache.end() )
George Zagaris's avatar
George Zagaris committed
236
    {
237
238
    vtkTimerLog::MarkEndEvent( "AMRCache::CheckIfBlockExists" );
    return true;
George Zagaris's avatar
George Zagaris committed
239
    }
240

George Zagaris's avatar
George Zagaris committed
241
  vtkTimerLog::MarkEndEvent( "AMRCache::CheckIfBlockExists" );
242
243
  return false;
}