forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkAMRToMultiBlockFilter.cxx
123 lines (104 loc) · 4.18 KB
/
vtkAMRToMultiBlockFilter.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAMRToMultiBlockFilter.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 "vtkAMRToMultiBlockFilter.h"
#include "vtkObjectFactory.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkIndent.h"
#include "vtkMultiProcessController.h"
#include "vtkOverlappingAMR.h"
#include "vtkUniformGrid.h"
#include "vtkMultiBlockDataSet.h"
#include <cassert>
vtkStandardNewMacro(vtkAMRToMultiBlockFilter);
//------------------------------------------------------------------------------
vtkAMRToMultiBlockFilter::vtkAMRToMultiBlockFilter()
{
this->Controller = vtkMultiProcessController::GetGlobalController();
}
//------------------------------------------------------------------------------
vtkAMRToMultiBlockFilter::~vtkAMRToMultiBlockFilter()
{
}
//------------------------------------------------------------------------------
void vtkAMRToMultiBlockFilter::PrintSelf( std::ostream &oss, vtkIndent indent )
{
this->Superclass::PrintSelf( oss, indent );
}
//------------------------------------------------------------------------------
int vtkAMRToMultiBlockFilter::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation *info )
{
assert( "pre: information object is NULL!" && (info != NULL) );
info->Set(
vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkOverlappingAMR");
return 1;
}
//------------------------------------------------------------------------------
int vtkAMRToMultiBlockFilter::FillOutputPortInformation(
int vtkNotUsed(port), vtkInformation *info )
{
assert( "pre: information object is NULL!" && (info != NULL) );
info->Set( vtkDataObject::DATA_TYPE_NAME(), "vtkMultiBlockDataSet" );
return 1;
}
//------------------------------------------------------------------------------
void vtkAMRToMultiBlockFilter::CopyAMRToMultiBlock(
vtkOverlappingAMR *amr, vtkMultiBlockDataSet *mbds )
{
assert( "pre: input AMR dataset is NULL" && (amr != NULL) );
assert( "pre: output multi-block dataset is NULL" && (mbds != NULL) );
mbds->SetNumberOfBlocks( amr->GetTotalNumberOfBlocks( ) );
unsigned int blockIdx = 0;
unsigned int levelIdx = 0;
for( ; levelIdx < amr->GetNumberOfLevels(); ++levelIdx )
{
unsigned int dataIdx = 0;
for( ; dataIdx < amr->GetNumberOfDataSets( levelIdx ); ++dataIdx )
{
vtkUniformGrid *grid = amr->GetDataSet( levelIdx, dataIdx );
if( grid != NULL )
{
vtkUniformGrid *gridCopy = vtkUniformGrid::New();
gridCopy->ShallowCopy( grid );
mbds->SetBlock( blockIdx, gridCopy );
}
else
{
mbds->SetBlock( blockIdx, NULL );
}
++blockIdx;
} // END for all data
} // END for all levels
}
//------------------------------------------------------------------------------
int vtkAMRToMultiBlockFilter::RequestData(
vtkInformation* vtkNotUsed(rqst), vtkInformationVector** inputVector,
vtkInformationVector* outputVector )
{
// STEP 0: Get input object
vtkInformation *input = inputVector[0]->GetInformationObject( 0 );
assert( "pre: input information object is NULL" && (input != NULL) );
vtkOverlappingAMR *amrds=
vtkOverlappingAMR::SafeDownCast(
input->Get( vtkDataObject::DATA_OBJECT( ) ) );
assert( "pre: input data-structure is NULL" && (amrds != NULL) );
// STEP 1: Get output object
vtkInformation *output = outputVector->GetInformationObject( 0 );
assert( "pre: output Co information is NULL" && (output != NULL) );
vtkMultiBlockDataSet *mbds=
vtkMultiBlockDataSet::SafeDownCast(
output->Get( vtkDataObject::DATA_OBJECT() ) );
assert( "pre: output multi-block dataset is NULL" && (mbds != NULL) );
// STEP 2: Copy AMR data to multi-block
this->CopyAMRToMultiBlock( amrds, mbds );
return 1;
}