255
bool iGenericParticlesDataSubject::ReadFortranRecordWithMask(iFile &F, long ntot0, int comp, vtkFloatArray *array, float updateStart, float updateDuration, float scale, float offset)
257
return this->ReadFortranRecordWithMaskTemplate(F,ntot0,comp,array,updateStart,updateDuration,scale,offset);
261
bool iGenericParticlesDataSubject::ReadFortranRecordWithMask(iFile &F, long ntot0, int comp, vtkDoubleArray *array, float updateStart, float updateDuration, double scale, double offset)
263
return this->ReadFortranRecordWithMaskTemplate(F,ntot0,comp,array,updateStart,updateDuration,scale,offset);
268
bool iGenericParticlesDataSubject::ReadFortranRecordWithMaskTemplate(iFile &F, long ntot0, int comp, vtkDataArray *array, float updateStart, float updateDuration, T scale, T offset)
272
vtkIdType l, idm, idt;
275
// Is component valid?
278
if(array==0 || comp<0 || comp>=(nComp = array->GetNumberOfComponents()))
280
this->GetErrorStatus()->Set("Invalid call to iGenericParticlesDataSubject::ReadFortranRecordWithMask.");
287
if(!this->ReadFortranHeaderFooter(F,lrec1) || lrec1!=sizeof(T)*ntot0)
289
this->GetErrorStatus()->Set("Corrupted data.");
294
// Direct access to data
296
T *ptr = (T *)array->GetVoidPointer(0) + comp;
299
this->GetErrorStatus()->Set("Not enough memory to create the data.");
304
// Decide how to read
306
vtkIdType ntot = array->GetNumberOfTuples();
307
vtkIdType lpiece1, lpiece = ntot0/1000;
308
if(lpiece < 1000) lpiece = 1000;
309
int npieces = (ntot0+lpiece-1)/lpiece;
314
T *d = new T[lpiece];
317
this->GetErrorStatus()->Set("Not enough memory to create the data.");
322
// parameters for the Progress Bar
324
updateDuration /= npieces;
327
// Read piece by piece
330
for(j=0; j<npieces; j++)
339
// Correct for the last record
341
lpiece1 = ntot0 - j*lpiece;
343
if(!this->ReadBlock(F,d,lpiece1,updateStart+j*updateDuration,updateDuration))
345
this->GetErrorStatus()->Set("Corrupted data.");
348
if(this->GetObserver()->IsAborted())
350
this->GetErrorStatus()->SetAbort();
353
for(l=0; l<lpiece1; l++, idt++) if(this->IsMasked(idm,idt))
356
if(idm>=ntot || idt>=ntot0)
361
ptr[nComp*idm] = d[l];
369
if(!this->ReadFortranHeaderFooter(F,lrec2) || lrec1!=lrec2)
371
this->GetErrorStatus()->Set("Corrupted data.");
378
// Do we need to scale?
380
if(fabs(scale) > iMath::_DoubleMin)
382
if(fabs(offset) > iMath::_DoubleMin)
385
// Scale as positions
387
for(l=0; l<ntot; l++)
389
ptr[nComp*l] = -1.0 + scale*(ptr[nComp*l]-offset);
397
for(l=0; l<ntot; l++)
399
ptr[nComp*l] *= scale;
404
if(this->GetObserver()->IsAborted())
406
this->GetErrorStatus()->SetAbort();
414
iProbeFilter* iGenericParticlesDataSubject::CreateProbeFilter(iViewSubject *vo) const
416
return iProbeFilter::New(vo);
420
iHistogramMaker* iGenericParticlesDataSubject::CreateHistogramMaker() const
422
return iHistogramMaker::New(this->GetViewModule());
426
void iGenericParticlesDataSubject::CreateArrays(vtkIdType ntot, int natt, bool paf, vtkPolyData *data, vtkPoints* &newPoints, vtkCellArray* &newVerts, vtkFloatArray* &newScalars)
428
vtkPoints *oldPoints = data->GetPoints();
429
vtkCellArray *oldVerts = data->GetVerts();
430
vtkFloatArray *oldScalars = iRequiredCast<vtkFloatArray>(data->GetPointData()->GetScalars());
432
int type = paf ? VTK_FLOAT : VTK_DOUBLE;
434
if(oldPoints==0 || oldPoints->GetNumberOfPoints()!=ntot || oldPoints->GetDataType()!=type)
437
newPoints = vtkPoints::New(type); IERROR_ASSERT(newPoints);
438
// Allocates and Sets MaxId
439
newPoints->SetNumberOfPoints(ntot);
443
newPoints = oldPoints;
444
newPoints->Register(0);
447
if(oldVerts==0 || oldVerts->GetNumberOfCells()!=ntot)
450
newVerts = vtkCellArray::New(); IERROR_ASSERT(newVerts);
451
// This allocates but does not Set Max Id
452
newVerts->Allocate(newVerts->EstimateSize(ntot,1));
454
for(l=0; l<ntot; l++)
456
newVerts->InsertNextCell(1);
457
newVerts->InsertCellPoint(l);
463
newVerts->Register(0);
466
if(oldScalars==0 || oldScalars->GetNumberOfTuples()!=ntot || oldScalars->GetNumberOfComponents()!=natt)
468
data->GetPointData()->SetScalars(0);
469
newScalars = vtkFloatArray::New(); IERROR_ASSERT(newScalars);
470
newScalars->SetNumberOfComponents(natt);
471
newScalars->SetNumberOfTuples(ntot);
475
newScalars = oldScalars;
476
newScalars->Register(0);
481
void iGenericParticlesDataSubject::AttachArrays(vtkPolyData *data, vtkPoints *newPoints, vtkCellArray *newVerts, vtkFloatArray *newScalars)
483
data->SetPoints(newPoints);
486
data->SetVerts(newVerts);
489
data->GetPointData()->SetScalars(newScalars);
490
newScalars->Delete();
495
if(mAdjustableLimits)
497
vtkFloatArray *att = iRequiredCast<vtkFloatArray>(data->GetPointData()->GetScalars());
499
if(att->GetNumberOfComponents() == this->GetLimits()->GetNumVars()) // just in case
501
iBuffer<float> aMin, aMax;
502
aMin.Extend(att->GetNumberOfComponents());
503
aMax.Extend(att->GetNumberOfComponents());
505
mHelper->FindRange(att->GetNumberOfComponents(),att->GetNumberOfTuples(),att->GetPointer(0),aMin,aMax);
508
for(i=0; i<att->GetNumberOfComponents(); i++)
510
this->GetLimits()->SetMin(i,aMin[i]);
511
this->GetLimits()->SetMax(i,aMax[i]);
250
527
void iGenericParticlesDataHelper::ShiftData(bool paf, int dim, long n, bool per[3], float dr, float *pf, double *pd)
260
537
this->ParallelExecute(1);
264
int iGenericParticlesDataHelper::ExecuteStep(int /*step*/, iParallel::ProcessorInfo &p)
541
void iGenericParticlesDataHelper::FindRange(int dim, long tot, float *pf, float *fMin, float *fMax)
547
mNumProcs = this->GetManager()->GetNumberOfProcessors();
548
mMin.Extend(mDim*mNumProcs);
549
mMax.Extend(mDim*mNumProcs);
551
this->ParallelExecute(2);
558
for(i=1; i<mNumProcs; i++)
560
if(fMin[n] > mMin[n+dim*i]) fMin[n] = mMin[n+dim*i];
561
if(fMax[n] < mMax[n+dim*i]) fMax[n] = mMax[n+dim*i];
567
int iGenericParticlesDataHelper::ExecuteStep(int step, iParallel::ProcessorInfo &p)
266
569
long l, kstp, kbeg, kend;
268
iParallel::SplitRange(p,mLtmp1,kbeg,kend,kstp);
275
float *x = mFarr1 + 3*kbeg;
276
for(l=kbeg; l<kend; l++)
280
if(this->IsMaster(p)) mSubject->GetObserver()->SetProgress((d+(float)(l-kbeg)/(kend-kbeg))/3.0);
281
if(mSubject->GetObserver()->IsAborted()) return 2;
286
if(x[d] > 1.0) x[d] -= 2.0;
287
if(x[d] < -1.0) x[d] += 2.0;
294
double *x = mDarr1 + 3*kbeg;
295
for(l=kbeg; l<kend; l++)
299
if(this->IsMaster(p)) mSubject->GetObserver()->SetProgress((float)(l-kbeg)/(kend-kbeg));
300
if(mSubject->GetObserver()->IsAborted()) return 2;
305
if(x[d] > 1.0) x[d] -= 2.0;
306
if(x[d] < -1.0) x[d] += 2.0;
572
iParallel::SplitRange(p,mTot,kbeg,kend,kstp);
582
float *x = mFarr + 3*kbeg;
583
for(l=kbeg; l<kend; l++)
587
if(this->IsMaster(p)) mSubject->GetObserver()->SetProgress((d+(float)(l-kbeg)/(kend-kbeg))/3.0);
588
if(mSubject->GetObserver()->IsAborted()) return 2;
593
if(x[d] > 1.0) x[d] -= 2.0;
594
if(x[d] < -1.0) x[d] += 2.0;
601
double *x = mDarr + 3*kbeg;
602
for(l=kbeg; l<kend; l++)
606
if(this->IsMaster(p)) mSubject->GetObserver()->SetProgress((float)(l-kbeg)/(kend-kbeg));
607
if(mSubject->GetObserver()->IsAborted()) return 2;
612
if(x[d] > 1.0) x[d] -= 2.0;
613
if(x[d] < -1.0) x[d] += 2.0;
623
float *f = mFarr + d*kbeg, *fmin = mMin + d*p.ThisProc, *fmax = mMax + d*p.ThisProc;
624
for(j=0; j<d; j++) fmin[j] = fmax[j] = f[j];
625
for(l=kbeg+1; l<kend; l++)
630
if(fmin[j] > f[j]) fmin[j] = f[j];
631
if(fmax[j] < f[j]) fmax[j] = f[j];