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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkXMLPUnstructuredGridReader.cxx,v $
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 "vtkXMLPUnstructuredGridReader.h"
#include "vtkCellArray.h"
#include "vtkIdTypeArray.h"
#include "vtkObjectFactory.h"
#include "vtkUnsignedCharArray.h"
#include "vtkUnstructuredGrid.h"
#include "vtkXMLDataElement.h"
#include "vtkXMLUnstructuredGridReader.h"
#include "vtkInformation.h"
#include "vtkStreamingDemandDrivenPipeline.h"
vtkCxxRevisionMacro(vtkXMLPUnstructuredGridReader, "$Revision: 1.9 $");
vtkStandardNewMacro(vtkXMLPUnstructuredGridReader);
//----------------------------------------------------------------------------
vtkXMLPUnstructuredGridReader::vtkXMLPUnstructuredGridReader()
{
// Copied from vtkUnstructuredGridReader constructor:
vtkUnstructuredGrid *output = vtkUnstructuredGrid::New();
this->SetOutput(output);
// Releasing data for pipeline parallism.
// Filters will know it is empty.
output->ReleaseData();
output->Delete();
}
//----------------------------------------------------------------------------
vtkXMLPUnstructuredGridReader::~vtkXMLPUnstructuredGridReader()
{
}
//----------------------------------------------------------------------------
void vtkXMLPUnstructuredGridReader::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
void vtkXMLPUnstructuredGridReader::SetOutput(vtkUnstructuredGrid *output)
{
this->GetExecutive()->SetOutputData(0, output);
}
//----------------------------------------------------------------------------
vtkUnstructuredGrid* vtkXMLPUnstructuredGridReader::GetOutput()
{
return this->GetOutput(0);
}
//----------------------------------------------------------------------------
vtkUnstructuredGrid* vtkXMLPUnstructuredGridReader::GetOutput(int idx)
{
return vtkUnstructuredGrid::SafeDownCast( this->GetOutputDataObject(idx) );
}
//----------------------------------------------------------------------------
const char* vtkXMLPUnstructuredGridReader::GetDataSetName()
{
return "PUnstructuredGrid";
}
//----------------------------------------------------------------------------
void vtkXMLPUnstructuredGridReader::GetOutputUpdateExtent(int& piece,
int& numberOfPieces,
int& ghostLevel)
{
this->GetOutput()->GetUpdateExtent(piece, numberOfPieces, ghostLevel);
}
//----------------------------------------------------------------------------
void vtkXMLPUnstructuredGridReader::SetupOutputTotals()
{
this->Superclass::SetupOutputTotals();
// Find the total size of the output.
int i;
this->TotalNumberOfCells = 0;
for(i=this->StartPiece; i < this->EndPiece; ++i)
{
if(this->PieceReaders[i])
{
this->TotalNumberOfCells += this->PieceReaders[i]->GetNumberOfCells();
}
}
// Data reading will start at the beginning of the output.
this->StartCell = 0;
}
//----------------------------------------------------------------------------
void vtkXMLPUnstructuredGridReader::SetupOutputData()
{
this->Superclass::SetupOutputData();
vtkUnstructuredGrid* output = this->GetOutput();
// Setup the output's cell arrays.
vtkUnsignedCharArray* cellTypes = vtkUnsignedCharArray::New();
cellTypes->SetNumberOfTuples(this->GetNumberOfCells());
vtkCellArray* outCells = vtkCellArray::New();
vtkIdTypeArray* locations = vtkIdTypeArray::New();
locations->SetNumberOfTuples(this->GetNumberOfCells());
output->SetCells(cellTypes, locations, outCells);
locations->Delete();
outCells->Delete();
cellTypes->Delete();
}
//----------------------------------------------------------------------------
void vtkXMLPUnstructuredGridReader::SetupNextPiece()
{
this->Superclass::SetupNextPiece();
if(this->PieceReaders[this->Piece])
{
this->StartCell += this->PieceReaders[this->Piece]->GetNumberOfCells();
}
}
//----------------------------------------------------------------------------
int vtkXMLPUnstructuredGridReader::ReadPieceData()
{
if(!this->Superclass::ReadPieceData()) { return 0; }
vtkPointSet* ips = this->GetPieceInputAsPointSet(this->Piece);
vtkUnstructuredGrid* input = static_cast<vtkUnstructuredGrid*>(ips);
vtkUnstructuredGrid* output = this->GetOutput();
// Save the start location where the new cell connectivity will be
// appended.
vtkIdType startLoc = 0;
if(output->GetCells()->GetData())
{
startLoc = output->GetCells()->GetData()->GetNumberOfTuples();
}
// Copy the Cells.
this->CopyCellArray(this->TotalNumberOfCells, input->GetCells(),
output->GetCells());
// Copy the cell locations with offset adjustment.
vtkIdTypeArray* inLocations = input->GetCellLocationsArray();
vtkIdTypeArray* outLocations = output->GetCellLocationsArray();
vtkIdType* inLocs = inLocations->GetPointer(0);
vtkIdType* outLocs = outLocations->GetPointer(this->StartCell);
vtkIdType numCells = inLocations->GetNumberOfTuples();
vtkIdType i;
for(i=0;i < numCells; ++i)
{
outLocs[i] = inLocs[i] + startLoc;
}
// Copy the cooresponding cell types.
vtkUnsignedCharArray* inTypes = input->GetCellTypesArray();
vtkUnsignedCharArray* outTypes = output->GetCellTypesArray();
vtkIdType components = outTypes->GetNumberOfComponents();
memcpy(outTypes->GetVoidPointer(this->StartCell*components),
inTypes->GetVoidPointer(0),
inTypes->GetNumberOfTuples()*components*inTypes->GetDataTypeSize());
return 1;
}
//----------------------------------------------------------------------------
void vtkXMLPUnstructuredGridReader::CopyArrayForCells(vtkDataArray* inArray,
vtkDataArray* outArray)
{
if(!this->PieceReaders[this->Piece])
{
return;
}
if(!inArray || !outArray)
{
return;
}
vtkIdType numCells = this->PieceReaders[this->Piece]->GetNumberOfCells();
vtkIdType components = outArray->GetNumberOfComponents();
vtkIdType tupleSize = inArray->GetDataTypeSize()*components;
memcpy(outArray->GetVoidPointer(this->StartCell*components),
inArray->GetVoidPointer(0), numCells*tupleSize);
}
//----------------------------------------------------------------------------
vtkXMLDataReader* vtkXMLPUnstructuredGridReader::CreatePieceReader()
{
return vtkXMLUnstructuredGridReader::New();
}
int vtkXMLPUnstructuredGridReader::FillOutputPortInformation(int, vtkInformation *info)
{
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkUnstructuredGrid");
return 1;
}
|