304 vtkDataArray* seedSource,
306 vtkDoubleArray* startTimes,
307 vtkIntArray* integrationDirections,
309 vtkAbstractInterpolatedVelocityField* func,
311 double& inPropagation,
312 vtkIdType& inNumSteps)
315 vtkIdType numLines = seedIds->GetNumberOfIds();
316 double propagation = inPropagation;
317 vtkIdType numSteps = inNumSteps;
320 vtkDataSetAttributes* outputPD = output->GetPointData();
321 vtkDataSetAttributes* outputCD = output->GetCellData();
322 vtkPointData* inputPD;
329 if ( maxCellSize > 0 )
331 weights =
new double[maxCellSize];
334 if (this->GetIntegrator() == 0)
336 vtkErrorMacro(
"No integrator is specified.");
341 vtkGenericCell* cell = vtkGenericCell::New();
344 vtkInitialValueProblemSolver* integrator =
345 this->GetIntegrator()->NewInstance();
346 integrator->SetFunctionSet(func);
354 vtkPoints* outputPoints = vtkPoints::New();
355 vtkCellArray* outputLines = vtkCellArray::New();
358 vtkDoubleArray* time = vtkDoubleArray::New();
359 time->SetName(
"IntegrationTime");
362 vtkIntArray* retVals = vtkIntArray::New();
363 retVals->SetName(
"ReasonForTermination");
365 vtkDoubleArray* cellVectors = 0;
366 vtkDoubleArray* velocityArray = 0;
367 vtkDoubleArray* speedArray = 0;
368 vtkDoubleArray* vorticity = 0;
369 vtkDoubleArray* rotation = 0;
370 vtkDoubleArray* angularVel = 0;
372 velocityArray = vtkDoubleArray::New();
373 velocityArray->SetName(
"Velocity");
374 velocityArray->SetNumberOfComponents(3);
376 speedArray = vtkDoubleArray::New();
377 speedArray->SetName(
"Speed");
379 if (this->ComputeVorticity)
381 cellVectors = vtkDoubleArray::New();
382 cellVectors->SetNumberOfComponents(3);
383 cellVectors->Allocate(3*VTK_CELL_SIZE);
385 vorticity = vtkDoubleArray::New();
386 vorticity->SetName(
"Vorticity");
387 vorticity->SetNumberOfComponents(3);
389 rotation = vtkDoubleArray::New();
390 rotation->SetName(
"Rotation");
392 angularVel = vtkDoubleArray::New();
393 angularVel->SetName(
"AngularVelocity");
416 vtkIdType numPtsTotal=0;
421 for(
int currentLine = 0; currentLine < numLines; currentLine++)
423 double progress =
static_cast<double>(currentLine)/numLines;
424 this->UpdateProgress(progress);
426 switch (integrationDirections->GetValue(currentLine))
437 double point1[3], point2[3], pcoords[3], vort[3], omega;
438 vtkIdType index, numPts=0;
442 func->ClearLastCellId();
444 double startTime = startTimes->GetValue(currentLine);
447 seedSource->GetTuple(seedIds->GetId(currentLine), point1);
448 memcpy(point2, point1, 3*
sizeof(
double));
451 memcpy(point1t, point1, 3*
sizeof(
double));
452 point1t[3] = startTime;
454 if (!func->FunctionValues(point1t, velocity))
459 if ( propagation >= this->MaximumPropagation ||
460 numSteps > this->MaximumNumberOfSteps)
467 vtkIdType nextPoint = outputPoints->InsertNextPoint(point1);
469 time->InsertNextValue(startTime);
475 stepSize.Unit = LENGTH_UNIT;
476 stepSize.Interval = 0;
478 aStep.Unit = LENGTH_UNIT;
479 double step, minStep=0, maxStep=0;
480 double stepTaken, accumTime=startTime;
483 int retVal=OUT_OF_LENGTH, tmp;
486 input = func->GetLastDataSet();
487 inputPD = input->GetPointData();
490 input->GetCell(func->GetLastCellId(), cell);
491 cellLength = sqrt(
static_cast<double>(cell->GetLength2()));
492 speed = vtkMath::Norm(velocity);
496 this->ConvertIntervals( stepSize.Interval, minStep, maxStep,
497 direction, cellLength );
501 func->GetLastWeights(weights);
505 velocityArray->InsertNextTuple(velocity);
506 speedArray->InsertNextValue(speed);
510 if (this->ComputeVorticity)
514 func->GetLastLocalCoordinates(pcoords);
515 vort[0] = vort[1] = vort[2] = 0.0;
517 vorticity->InsertNextTuple(vort);
522 omega = vtkMath::Dot(vort, velocity);
524 omega *= this->RotationScale;
530 angularVel->InsertNextValue(omega);
531 rotation->InsertNextValue(0.0);
538 while ( propagation < this->MaximumPropagation )
541 if (numSteps > this->MaximumNumberOfSteps)
543 retVal = OUT_OF_STEPS;
547 if ( numSteps++ % 1000 == 1 )
550 ( currentLine + propagation / this->MaximumPropagation ) / numLines;
551 this->UpdateProgress(progress);
553 if (this->GetAbortExecute())
561 if ( (speed == 0) || (speed <= this->TerminalSpeed) )
569 aStep.Interval = fabs( stepSize.Interval );
571 if ( ( propagation + aStep.Interval ) > this->MaximumPropagation )
573 aStep.Interval = this->MaximumPropagation - propagation;
574 if ( stepSize.Interval >= 0 )
576#if VMTK_USE_LEGACY_INTERVAL_INFORMATION
577 stepSize.Interval = this->ConvertToLength( aStep, cellLength );
579 stepSize.Interval = vtkIntervalInformation::ConvertToLength(aStep, cellLength);
584#if VMTK_USE_LEGACY_INTERVAL_INFORMATION
585 stepSize.Interval = this->ConvertToLength(aStep, cellLength) * (-1.0);
587 stepSize.Interval = vtkIntervalInformation::ConvertToLength(aStep, cellLength) * (-1.0);
590 maxStep = stepSize.Interval;
592 this->LastUsedStepSize = stepSize.Interval;
596 func->SetNormalizeVector(
true );
597 tmp = integrator->ComputeNextStep( point1, point2, accumTime, stepSize.Interval,
598 stepTaken, minStep, maxStep,
599 this->MaximumError, error );
600 func->SetNormalizeVector(
false );
604 memcpy(lastPoint, point2, 3*
sizeof(
double));
614 disp[i] = point2[i] - point1[i];
616 if ( (stepSize.Interval == 0) ||
617 (vtkMath::Norm(disp) / fabs(stepSize.Interval) <= this->TerminalSpeed) )
623 accumTime += stepTaken / speed;
625 propagation += fabs( stepSize.Interval );
630 point1[i] = point2[i];
634 memcpy(point2t, point2, 3*
sizeof(
double));
635 point2t[3] = accumTime;
638 if ( !func->FunctionValues(point2t, velocity) )
640 retVal = OUT_OF_DOMAIN;
641 memcpy(lastPoint, point2, 3*
sizeof(
double));
645 input = func->GetLastDataSet();
646 inputPD = input->GetPointData();
651 nextPoint = outputPoints->InsertNextPoint(point1);
652 time->InsertNextValue(accumTime);
655 input->GetCell(func->GetLastCellId(), cell);
656 cellLength = sqrt(
static_cast<double>(cell->GetLength2()));
658 velocityArray->InsertNextTuple(velocity);
660 speed = vtkMath::Norm(velocity);
662 speedArray->InsertNextValue(speed);
665 func->GetLastWeights(weights);
671 if (this->ComputeVorticity)
675 func->GetLastLocalCoordinates(pcoords);
676 vort[0] = vort[1] = vort[2] = 0.0;
678 vorticity->InsertNextTuple(vort);
682 omega = vtkMath::Dot(vort, velocity);
684 omega *= this->RotationScale;
685 index = angularVel->InsertNextValue(omega);
686 rotation->InsertNextValue(rotation->GetValue(index-1) +
687 (angularVel->GetValue(index-1) + omega)/2 *
688 (accumTime - time->GetValue(index-1)));
692 if ( (speed == 0) || (speed <= this->TerminalSpeed) )
699 this->ConvertIntervals( step, minStep, maxStep, direction, cellLength );
707 if (integrator->IsAdaptive())
709 if (fabs(stepSize.Interval) < fabs(minStep))
711 stepSize.Interval = fabs( minStep ) *
712 stepSize.Interval / fabs( stepSize.Interval );
714 else if (fabs(stepSize.Interval) > fabs(maxStep))
716 stepSize.Interval = fabs( maxStep ) *
717 stepSize.Interval / fabs( stepSize.Interval );
722 stepSize.Interval = step;
735 outputLines->InsertNextCell(numPts);
736 for (i=numPtsTotal-numPts; i<numPtsTotal; i++)
738 outputLines->InsertCellPoint(i);
740 retVals->InsertNextValue(retVal);
746 inPropagation = propagation;
747 inNumSteps = numSteps;
756 output->SetPoints(outputPoints);
757 outputPD->AddArray(time);
758 outputPD->AddArray(velocityArray);
759 outputPD->AddArray(speedArray);
762 outputPD->AddArray(vorticity);
763 outputPD->AddArray(rotation);
764 outputPD->AddArray(angularVel);
767 vtkIdType numPts = outputPoints->GetNumberOfPoints();
771 output->SetLines(outputLines);
772 if (this->GenerateNormalsInIntegrate)
778 outputCD->AddArray(retVals);
782 velocityArray->Delete();
783 speedArray->Delete();
789 angularVel->Delete();
794 cellVectors->Delete();
798 outputPoints->Delete();
799 outputLines->Delete();
804 integrator->Delete();