Commit 9146ac45 authored by Jon Woodring's avatar Jon Woodring
Browse files

Sped up the Cosmo reader by preallocating point and cell memory.

Change-Id: I639a7f4daf66070ff0d9a15ab4c2099cb2dedebc
parent a218f1e8
......@@ -79,6 +79,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vtkPointData.h"
#include "vtkDataObject.h"
#include "vtkStdString.h"
#include "vtkCellArray.h"
#include "vtkstd/vector"
......@@ -299,25 +300,26 @@ int vtkPCosmoReader::RequestData(
vtkPoints* points = vtkPoints::New();
points->SetDataTypeToFloat();
points->Allocate(numberOfParticles);
vtkCellArray* cells = vtkCellArray::New();
cells->EstimateSize(numberOfParticles, 1);
vtkFloatArray* vel = vtkFloatArray::New();
vel->SetName("velocity");
vel->SetNumberOfComponents(DIMENSION);
vel->Allocate(numberOfParticles);
vtkFloatArray* m = vtkFloatArray::New();
m->SetName("mass");
m->Allocate(numberOfParticles);
vtkIntArray* uid = vtkIntArray::New();
uid->SetName("tag");
uid->Allocate(numberOfParticles);
vtkIntArray* owner = vtkIntArray::New();
owner->SetName("ghost");
owner->Allocate(numberOfParticles);
vtkUnsignedCharArray* ghost = vtkUnsignedCharArray::New();
ghost->SetName("vtkGhostLevels");
output->Allocate(numberOfParticles);
output->SetPoints(points);
output->GetPointData()->AddArray(vel);
output->GetPointData()->AddArray(m);
output->GetPointData()->AddArray(uid);
output->GetPointData()->AddArray(owner);
output->GetPointData()->AddArray(ghost);
ghost->Allocate(numberOfParticles);
// put it into the correct VTK structure
for(vtkIdType i = 0; i < numberOfParticles; i = i + 1)
......@@ -333,7 +335,7 @@ int vtkPCosmoReader::RequestData(
zz->pop_back();
vtkIdType pid = points->InsertNextPoint(pt);
output->InsertNextCell(1, 1, &pid);
cells->InsertNextCell(1, &pid);
// insert velocity
pt[0] = vx->back();
......@@ -367,7 +369,18 @@ int vtkPCosmoReader::RequestData(
}
// cleanup
output->SetPoints(points);
output->SetCells(1, cells);
output->GetPointData()->AddArray(vel);
output->GetPointData()->AddArray(m);
output->GetPointData()->AddArray(uid);
output->GetPointData()->AddArray(owner);
output->GetPointData()->AddArray(ghost);
output->Squeeze();
points->Delete();
cells->Delete();
vel->Delete();
m->Delete();
uid->Delete();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment