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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkExtractLevel.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 "vtkExtractLevel.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkUniformGrid.h"
#include "vtkUniformGridAMR.h"
#include "vtkOverlappingAMR.h"
#include <set>
#include <vector>
class vtkExtractLevel::vtkSet : public std::set<unsigned int>
{
};
vtkStandardNewMacro(vtkExtractLevel);
//----------------------------------------------------------------------------
vtkExtractLevel::vtkExtractLevel()
{
this->Levels = new vtkExtractLevel::vtkSet();
}
//----------------------------------------------------------------------------
vtkExtractLevel::~vtkExtractLevel()
{
delete this->Levels;
}
//----------------------------------------------------------------------------
void vtkExtractLevel::AddLevel(unsigned int level)
{
this->Levels->insert(level);
this->Modified();
}
//----------------------------------------------------------------------------
void vtkExtractLevel::RemoveLevel(unsigned int level)
{
this->Levels->erase(level);
this->Modified();
}
//----------------------------------------------------------------------------
void vtkExtractLevel::RemoveAllLevels()
{
this->Levels->clear();
this->Modified();
}
//------------------------------------------------------------------------------
int vtkExtractLevel::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info )
{
info->Set(
vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkUniformGridAMR");
return 1;
}
//------------------------------------------------------------------------------
int vtkExtractLevel::FillOutputPortInformation(
int vtkNotUsed(port), vtkInformation *info )
{
info->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkMultiBlockDataSet");
return 1;
}
int vtkExtractLevel::RequestUpdateExtent(vtkInformation* , vtkInformationVector** inputVector,vtkInformationVector* )
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
// Check if metadata are passed downstream
if( inInfo->Has(vtkCompositeDataPipeline::COMPOSITE_DATA_META_DATA() ) )
{
vtkOverlappingAMR *metadata = vtkOverlappingAMR::SafeDownCast(
inInfo->Get(vtkCompositeDataPipeline::COMPOSITE_DATA_META_DATA()));
if(metadata)
{
// cout<<"Time dependent? "<<inInfo->Has(vtkStreamingDemandDrivenPipeline::TIME_DEPENDENT_INFORMATION())<<endl;
// std::cout<<"Receive Meta Data: ";
// for(int levelIdx=0 ; levelIdx < metadata->GetNumberOfLevels(); ++levelIdx )
// {
// std::cout << " \tL(" << levelIdx << ") = "
// << metadata->GetNumberOfDataSets( levelIdx ) << " ";
// std::cout.flush();
// } // END for levels
// std::cout<<endl;
// Tell reader to load all requested blocks.
inInfo->Set( vtkCompositeDataPipeline::LOAD_REQUESTED_BLOCKS(), 1 );
// request the blocks
std::vector<int> blocksToLoad;
for(vtkExtractLevel::vtkSet::iterator iter =this->Levels->begin(); iter!= this->Levels->end(); ++iter )
{
unsigned int level = (*iter);
for(unsigned int dataIdx=0;dataIdx < metadata->GetNumberOfDataSets(level);++dataIdx )
{
blocksToLoad.push_back(metadata->GetCompositeIndex(level,dataIdx));
}
}
inInfo->Set( vtkCompositeDataPipeline::UPDATE_COMPOSITE_INDICES(),&blocksToLoad[0], static_cast<int>(blocksToLoad.size()));
}
}
return 1;
}
//----------------------------------------------------------------------------
int vtkExtractLevel::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *outputVector )
{
// STEP 0: Get input object
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
vtkUniformGridAMR *input =
vtkUniformGridAMR::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
if( input == NULL )
{
return( 0 );
}
// STEP 1: Get output object
vtkInformation* info = outputVector->GetInformationObject(0);
vtkMultiBlockDataSet *output =
vtkMultiBlockDataSet::SafeDownCast(
info->Get(vtkDataObject::DATA_OBJECT()));
if( output == NULL )
{
return( 0 );
}
// STEP 2: Compute the total number of blocks to be loaded
unsigned int numBlocksToLoad = 0;
vtkExtractLevel::vtkSet::iterator iter;
for( iter =this->Levels->begin(); iter != this->Levels->end(); ++iter )
{
unsigned int level = (*iter);
numBlocksToLoad += input->GetNumberOfDataSets(level);
} // END for all requested levels
output->SetNumberOfBlocks( numBlocksToLoad );
// STEP 3: Load the blocks at the selected levels
if( numBlocksToLoad > 0 )
{
iter = this->Levels->begin();
unsigned int blockIdx = 0;
for( ;iter != this->Levels->end(); ++iter )
{
unsigned int level = (*iter);
unsigned int dataIdx = 0;
for(; dataIdx < input->GetNumberOfDataSets(level); ++dataIdx )
{
vtkUniformGrid* data = input->GetDataSet(level,dataIdx);
if( data != NULL )
{
vtkUniformGrid *copy = data->NewInstance();
copy->ShallowCopy( data );
output->SetBlock( blockIdx, copy );
copy->Delete();
++blockIdx;
} // END if data is not NULL
} // END for all data at level l
} // END for all requested levels
} // END if numBlocksToLoad is greater than 0
return( 1 );
}
//----------------------------------------------------------------------------
void vtkExtractLevel::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
|