------------------------------------------------------------------------------
| 212 | |
| 213 | //------------------------------------------------------------------------------ |
| 214 | vtkPolyData* vtkAMREnzoParticlesReader::GetParticles(const char* file, int blockIdx) |
| 215 | { |
| 216 | vtkPolyData* particles = vtkPolyData::New(); |
| 217 | vtkPoints* positions = vtkPoints::New(); |
| 218 | positions->SetDataTypeToDouble(); |
| 219 | vtkPointData* pdata = particles->GetPointData(); |
| 220 | |
| 221 | hid_t fileIndx = H5Fopen(file, H5F_ACC_RDONLY, H5P_DEFAULT); |
| 222 | if (fileIndx < 0) |
| 223 | { |
| 224 | vtkErrorMacro("Failed opening particles file!"); |
| 225 | return nullptr; |
| 226 | } |
| 227 | |
| 228 | hid_t rootIndx; |
| 229 | if (!FindBlockIndex(fileIndx, blockIdx + 1, rootIndx)) |
| 230 | { |
| 231 | vtkErrorMacro("Could not locate target block!"); |
| 232 | return nullptr; |
| 233 | } |
| 234 | |
| 235 | // |
| 236 | // Load the particles position arrays by name. |
| 237 | // In Enzo the following arrays are available: |
| 238 | // ( 1 ) particle_position_i |
| 239 | // ( 2 ) tracer_particle_position_i |
| 240 | // |
| 241 | // where i \in {x,y,z}. |
| 242 | std::vector<double> xcoords; |
| 243 | std::vector<double> ycoords; |
| 244 | std::vector<double> zcoords; |
| 245 | |
| 246 | // TODO: should we handle 2-D particle datasets? |
| 247 | GetDoubleArrayByName(rootIndx, "particle_position_x", xcoords); |
| 248 | GetDoubleArrayByName(rootIndx, "particle_position_y", ycoords); |
| 249 | GetDoubleArrayByName(rootIndx, "particle_position_z", zcoords); |
| 250 | |
| 251 | vtkIntArray* particleTypes = vtkArrayDownCast<vtkIntArray>(this->GetParticlesTypeArray(blockIdx)); |
| 252 | |
| 253 | assert("Coordinate arrays must have the same size: " && (xcoords.size() == ycoords.size())); |
| 254 | assert("Coordinate arrays must have the same size: " && (ycoords.size() == zcoords.size())); |
| 255 | |
| 256 | int TotalNumberOfParticles = static_cast<int>(xcoords.size()); |
| 257 | positions->SetNumberOfPoints(TotalNumberOfParticles); |
| 258 | |
| 259 | vtkIdList* ids = vtkIdList::New(); |
| 260 | ids->SetNumberOfIds(TotalNumberOfParticles); |
| 261 | |
| 262 | vtkIdType NumberOfParticlesLoaded = 0; |
| 263 | for (int i = 0; i < TotalNumberOfParticles; ++i) |
| 264 | { |
| 265 | if ((i % this->Frequency) == 0) |
| 266 | { |
| 267 | if (this->CheckLocation(xcoords[i], ycoords[i], zcoords[i]) && |
| 268 | this->CheckParticleType(i, particleTypes)) |
| 269 | { |
| 270 | int pidx = NumberOfParticlesLoaded; |
| 271 | ids->InsertId(pidx, i); |
no test coverage detected