MCPcopy Create free account
hub / github.com/Kitware/VTK / Move

Method Move

IO/MotionFX/vtkMotionFXCFGReader.cxx:636–739  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

634 bool read_position_file(const std::string& rootDir) const;
635
636 bool Move(vtkPoints* pts, double time) const override
637 {
638 if ((time < this->tstart_prescribe) || (this->positions.size() < 2))
639 {
640 // nothing to do, this motion hasn't been activated yet.
641 // if there's less than 2 position entries, the interpolation logic fails
642 // and hence we don't handle it.
643 return false;
644 }
645
646 time -= this->tstart_prescribe;
647
648 // let's clamp to end time in the position time to avoid complications.
649 time = std::min(this->positions.rbegin()->first, time);
650
651 auto iter = this->positions.lower_bound(time);
652 if (iter == this->positions.begin() && iter->first != time)
653 {
654 // first time is greater than `time`, nothing to do.
655 return false;
656 }
657
658 // iter can never be end since we've clamp time to the last time in the
659 // position file.
660 assert(iter != this->positions.end());
661
662 vtkNew<vtkTransform> transform;
663 transform->PostMultiply();
664 // center to the initial_centerOfMass.
665 if (this->initial_centerOfMass != vtkVector3d{ VTK_DOUBLE_MAX })
666 {
667 transform->Translate((initial_centerOfMass * -1.0).GetData());
668 }
669
670 vtkVector3d cumulativeS(0.0); //, cumulativeTheta(0.0);
671 if (!this->isOrientation)
672 {
673 for (auto citer = this->positions.begin(); citer != iter; ++citer)
674 {
675 assert(time >= citer->first);
676
677 auto next = std::next(citer);
678 assert(next != this->positions.end());
679
680 const double interval = (next->first - citer->first);
681 const double dt = std::min(time - citer->first, interval);
682
683 const double t = dt / interval; // normalized dt
684 const vtkVector3d s = t * (next->second.center_of_mass - citer->second.center_of_mass);
685
686 // theta = (w0 + w1)*dt / 2
687 const vtkVector3d theta =
688 (citer->second.angular_velocities + next->second.angular_velocities) * dt * 0.5;
689 transform->RotateWXYZ(
690 vtkMath::DegreesFromRadians(theta.Norm()), theta[0], theta[1], theta[2]);
691
692 cumulativeS = cumulativeS + s;
693 // cumulativeTheta = cumulativeTheta + theta;

Callers

nothing calls this directly

Calls 14

rbeginMethod · 0.80
lower_boundMethod · 0.80
RotateWXYZMethod · 0.80
NormMethod · 0.80
minFunction · 0.50
assertFunction · 0.50
nextFunction · 0.50
ExecuteFunction · 0.50
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
TranslateMethod · 0.45

Tested by

no test coverage detected