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

 Program:   Visualization Toolkit
 Module:    vtkAMRFlashReader.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 "vtkAMRFlashReader.h"
#include "vtkObjectFactory.h"
#include "vtkHierarchicalBoxDataSet.h"
#include "vtkAMRUtilities.h"
19
20
#include "vtkByteSwap.h"
#include "vtkUniformGrid.h"
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "vtkDataArraySelection.h"

#include "vtkDataSet.h"
#include "vtkCellData.h"
#include "vtkIntArray.h"
#include "vtkLongArray.h"
#include "vtkShortArray.h"
#include "vtkFloatArray.h"
#include "vtkDoubleArray.h"
#include "vtkLongLongArray.h"
#include "vtkUnsignedIntArray.h"
#include "vtkUnsignedCharArray.h"
#include "vtkUnsignedShortArray.h"
34
35
36
37
38
39
40

#include <cassert>
#include <vtkstd/vector>
#include <vtkstd/map>

#define H5_USE_16_API
#include <hdf5.h>
41

42
#include "vtkAMRFlashReaderInternal.hpp"
43

44
vtkStandardNewMacro(vtkAMRFlashReader);
45

46
47
48
//------------------------------------------------------------------------------
vtkAMRFlashReader::vtkAMRFlashReader()
{
49
  this->Internal = new vtkFlashReaderInternal;
50
51
52
53
54
55
  this->Initialize();
}

//------------------------------------------------------------------------------
vtkAMRFlashReader::~vtkAMRFlashReader()
{
56
57
  delete this->Internal;
  this->Internal = NULL;
58
59
60
61
62
63
64
65
66
67
68
}

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

//-----------------------------------------------------------------------------
void vtkAMRFlashReader::SetFileName( const char* fileName )
{
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  assert( "pre: Internal Flash Reader is NULL" && (this->Internal != NULL) );

  if( fileName && strcmp(fileName,"") &&
     ( ( this->FileName == NULL ) || strcmp( fileName, this->FileName ) ) )
    {

      if( this->FileName )
        {
          delete [] this->FileName;
          this->FileName = NULL;
          this->Internal->SetFileName( NULL );
        }

      this->FileName = new char[ strlen(fileName)+1 ];
      strcpy( this->FileName, fileName );
      this->FileName[ strlen( fileName ) ] = '\0';

      this->Internal->SetFileName( this->FileName );
    }

89
90
  this->SetUpDataArraySelections();
  this->InitializeArraySelections();
91
  this->Modified();
92
93
94
95
96
}

//-----------------------------------------------------------------------------
void vtkAMRFlashReader::ReadMetaData()
{
97
98
  assert( "pre: Internal Flash Reader is NULL" && (this->Internal != NULL) );
  this->Internal->ReadMetaData();
99
100
101
102
103
}

//-----------------------------------------------------------------------------
void vtkAMRFlashReader::GenerateBlockMap()
{
104
105
106
107
108
109
110
111
112
113
114
115
  assert( "pre: Internal Flash Reader is NULL" && (this->Internal!=NULL) );

  this->BlockMap.clear();
  this->Internal->ReadMetaData();

  for( int i=0; i < this->Internal->NumberOfBlocks; ++i )
    {
      if( this->GetBlockLevel( i ) <= this->MaxLevel )
        {
          this->BlockMap.push_back( i );
        }
    }
116
117
118
119
120
}

//-----------------------------------------------------------------------------
int vtkAMRFlashReader::GetBlockLevel( const int blockIdx )
{
121
122
123
124
125
126
127
128
129
  assert( "pre: Internal Flash Reader is NULL" && (this->Internal != NULL) );

  this->Internal->ReadMetaData();
  if( blockIdx < 0 || blockIdx >= this->Internal->NumberOfBlocks )
    {
      vtkErrorMacro( "Block Index (" << blockIdx << ") is out-of-bounds!" );
      return( -1 );
    }
  return( this->Internal->Blocks[ blockIdx ].Level );
130
131
132
133
134
}

//-----------------------------------------------------------------------------
int vtkAMRFlashReader::GetNumberOfBlocks()
{
135
136
137
138
  assert( "pre: Internal Flash Reader is NULL" && (this->Internal != NULL) );

  this->Internal->ReadMetaData();
  return( this->Internal->NumberOfBlocks );
139
140
141
142
143
}

//-----------------------------------------------------------------------------
int vtkAMRFlashReader::GetNumberOfLevels()
{
144
145
146
  assert( "pre: Internal Flash Reader is NULL" && (this->Internal != NULL) );
  this->Internal->ReadMetaData();
  return( this->Internal->NumberOfLevels );
147
148
149
150
151
152
153
}

//-----------------------------------------------------------------------------
void vtkAMRFlashReader::GetBlock(
    int index, vtkHierarchicalBoxDataSet *hbds,
    vtkstd::vector< int > &idxcounter)
{
154
155
156
157
158
159
  assert( "pre: Internal Flash Reader is NULL" && (this->Internal != NULL) );
  assert( "pre: Output AMR dataset is NULL" && (hbds != NULL)  );

  this->Internal->ReadMetaData();

  int blockIdx = this->BlockMap[ index ];
160
161
162

  // Start numbering levels from 0!
  int level    = this->Internal->Blocks[ blockIdx ].Level-1;
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
  double blockMin[3];
  double blockMax[3];
  double spacings[3];
  for( int i=0; i < 3; ++i )
    {
     blockMin[i] = this->Internal->Blocks[ blockIdx ].MinBounds[i];
     blockMax[i] = this->Internal->Blocks[ blockIdx ].MaxBounds[i];
     spacings[i] = (this->Internal->BlockGridDimensions[i] > 1)?
     (blockMax[i]-blockMin[i])/(this->Internal->BlockGridDimensions[i]-1.0):1.0;
    }

  vtkUniformGrid *ug = vtkUniformGrid::New();
  ug->SetDimensions( this->Internal->BlockGridDimensions );
  ug->SetOrigin( blockMin[0], blockMin[1], blockMin[2] );
  ug->SetSpacing( spacings );

179
180
181
182
183
184
185
186
187
188
  int numAttrs = static_cast< int >( this->Internal->AttributeNames.size() );
  for( int i=0; i < numAttrs; ++i )
    {
      if( this->GetCellArrayStatus(
            this->Internal->AttributeNames[i].c_str() ) )
        {
          this->Internal->GetBlockAttribute(
              this->Internal->AttributeNames[i].c_str(),blockIdx, ug );
        }
    }
189
190
191
192

  hbds->SetDataSet(level,idxcounter[level],ug);
  ug->Delete();
  idxcounter[ level ]++;
193
194
195
196
197
}

//-----------------------------------------------------------------------------
void vtkAMRFlashReader::SetUpDataArraySelections()
{
198
199
200
201
202
203
204
205
206
207
  assert( "pre: Internal Flash Reader is NULL" && (this->Internal != NULL) );
  this->Internal->ReadMetaData();

  int numAttrs = static_cast< int >( this->Internal->AttributeNames.size() );
  for( int i=0; i < numAttrs; ++i )
    {
      this->CellDataArraySelection->AddArray(
          this->Internal->AttributeNames[ i ].c_str()  );
    }

208
}