UsTK : Ultrasound ToolKit  version 2.0.1 under development (2023-12-07)
testUsNeedleJacobians.cpp

USTK usNeedleJacobians test

This example tests the Jacobian computation associated to the needle insertion models.

/****************************************************************************
*
* This file is part of the ustk software.
* Copyright (C) 2016 - 2017 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* ("GPL") version 2 as published by the Free Software Foundation.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ustk with software that can not be combined with the GNU
* GPL, please contact Inria about acquiring a ViSP Professional
* Edition License.
*
* This software was developed at:
* Inria Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
*
* If you have questions regarding the use of this file, please contact
* Inria at ustk@inria.fr
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author:
* Jason Chevrie
*
*****************************************************************************/
#include <visp3/core/vpConfig.h>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
#include <visp3/core/vpColVector.h>
#include <visp3/core/vpHomogeneousMatrix.h>
#include <visp3/core/vpImage.h>
#include <visp3/core/vpMatrix.h>
#include <visp3/core/vpRGBa.h>
#include <visp3/ustk_needle_modeling/usNeedleInsertionModelRayleighRitzSpline.h>
#include <visp3/ustk_needle_modeling/usNeedleInsertionModelVirtualSprings.h>
#include <visp3/ustk_needle_modeling/usNeedleJacobians.h>
int main()
{
std::cout << "Start test testUsNeedleJacobians" << std::endl;
needleRR.setBasePose(vpPoseVector(0,0,0,0,0,0));
needleRR.setSurfaceAtTip();
needleVS.setBasePose(vpPoseVector(0,0,0,0,0,0));
needleVS.setSurfaceAtTip();
for(int i=0 ; i<20 ; i++)
{
needleRR.moveBase(0.0005,0,0.001,0.0001,0,0);
needleVS.moveBase(0.0005,0,0.001,0.0001,0,0);
}
vpMatrix JRR;
vpMatrix JVS;
std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToWorldTipVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToWorldTipVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToTipVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTipVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToWorldTipVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToWorldTipVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToTipVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTipVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToBendingEnergy<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToBendingEnergy<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToBendingEnergy<usNeedleInsertionModelVirtualSprings>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToBendingEnergy<usNeedleInsertionModelVirtualSprings>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTissueEnergy<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToTissueEnergy<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToNeedleInsertionPointVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToSurfaceTissueStretch<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToMaxTissueStretch<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToMeanTissueStretch<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTissueEnergy<usNeedleInsertionModelVirtualSprings>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToTissueEnergy<usNeedleInsertionModelVirtualSprings>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToNeedleInsertionPointVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToSurfaceTissueStretch<usNeedleInsertionModelVirtualSprings>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToMaxTissueStretch<usNeedleInsertionModelVirtualSprings>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToMeanTissueStretch<usNeedleInsertionModelVirtualSprings>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToPointVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToPointVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToPointVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianWorldBaseVelocityToPointVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
vpColVector target(needleRR.accessNeedle().getTipPosition());
target[0] += 0.01;
target[2] += 0.02;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTransversalTargetDistance<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
if(!usNeedleJacobians::getJacobianBaseVelocityToTargetAngle(needleRR, JRR, target)) return 1;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTargetAngle<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTransversalTargetDistance<usNeedleInsertionModelVirtualSprings>" << std::endl;
if(!usNeedleJacobians::getJacobianBaseVelocityToTargetAngle(needleVS, JVS, target)) return 1;
std::cout << "done: usNeedleJacobians::getJacobianBaseVelocityToTargetAngle<usNeedleInsertionModelVirtualSprings>" << std::endl;
if(!usNeedleJacobians::getJacobianSpringVelocityToPointVelocity(needleVS, JVS, needleVS.getNbSprings()/2, 0.5 * needleVS.accessNeedle().getFullLength())) return 1;
std::cout << "done: usNeedleJacobians::getJacobianSpringVelocityToPointVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
vpColVector point(needleVS.accessNeedle().getPoint(0.5*needleVS.accessNeedle().getFullLength()));
point[0] += 0.005;
std::vector<vpColVector> points;
for(int i=0 ; i<10 ; i++)
{
point[2] += 0.002;
points.push_back(point);
}
if(!usNeedleJacobians::getJacobianSpringVelocityToPointsDistance(needleVS, JVS, needleVS.getNbSprings()/2, points)) return 1;
std::cout << "done: usNeedleJacobians::getJacobianSpringVelocityToPointsDistance<usNeedleInsertionModelVirtualSprings>" << std::endl;
std::vector<double> l;
for(int i=0 ; i<10 ; i++) l.push_back(i * needleRR.accessNeedle().getFullLength() / 10.);
std::cout << "done: usNeedleJacobians::getJacobianRestPathPointVelocityToPointsVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianRestPathPointVelocityToPointsDistance<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianStiffnessPerUnitLengthToPointsDistance<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianStiffnessPerUnitLengthToPointsDistance<usNeedleInsertionModelVirtualSprings>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianStiffnessPerUnitLengthToPointsVelocity<usNeedleInsertionModelRayleighRitzSpline>" << std::endl;
std::cout << "done: usNeedleJacobians::getJacobianStiffnessPerUnitLengthToPointsVelocity<usNeedleInsertionModelVirtualSprings>" << std::endl;
return 0;
}
int getNbSegments() const
Parameters setters and getters.
Definition: usBSpline3D.cpp:59
vpColVector getPoint(double param) const
Measure curve information.
bool moveBase(const vpColVector &v, double time)
void loadPreset(const ModelPreset preset)
Parameters saving and loading.
bool setBasePose(const vpPoseVector &p)
The following methods should be redefined in the derived classes.
const usTissueModelSpline & accessTissue() const
Tissue parameters.
const usNeedleModelSpline & accessNeedle() const
Parameters setters and getters.
bool setBasePose(const vpPoseVector &p)
The following methods should be redefined in the derived classes.
void loadPreset(const ModelPreset preset)
Parameters saving and loading.
const usNeedleModelSpline & accessNeedle() const
Model parameters.
vpColVector getTipPosition() const
const usBSpline3D & accessPath() const
bool getJacobianSpringVelocityToPointsDistance(const NeedleInsertionModel &model, vpMatrix &J, int spring, const std::vector< vpColVector > &points)
Springs to distance from points (nbPointsx6)
bool getJacobianBaseVelocityToTissueEnergy(const NeedleInsertionModel &model, vpMatrix &J)
Base to tissue deformation energy (1x6)
bool getJacobianBaseVelocityToTransversalTargetDistance(const NeedleInsertionModel &model, vpMatrix &J, const vpColVector &target)
Base to features (1x6)
bool getJacobianBaseVelocityToTipVelocity(const NeedleInsertionModel &model, vpMatrix &J)
bool getJacobianWorldBaseVelocityToTissueEnergy(const NeedleInsertionModel &model, vpMatrix &J)
bool getJacobianBaseVelocityToPointVelocity(const NeedleInsertionModel &model, vpMatrix &J, double l)
Base to needle point (3x6)
bool getJacobianBaseVelocityToSurfaceTissueStretch(const NeedleInsertionModel &model, vpMatrix &J)
bool getJacobianRestPathPointVelocityToPointsVelocity(const NeedleInsertionModel &model, vpMatrix &J, int restPoint, const std::vector< double > &l)
Rest path points to model point (3x3)
bool getJacobianWorldBaseVelocityToTipVelocity(const NeedleInsertionModel &model, vpMatrix &J)
Base to tip.
bool getJacobianRestPathPointVelocityToPointsDistance(const NeedleInsertionModel &model, vpMatrix &J, int restPoint, const std::vector< vpColVector > &points)
Rest path points distance from points (nbPointsx3)
bool getJacobianBaseVelocityToNeedleInsertionPointVelocity(const NeedleInsertionModel &model, vpMatrix &J)
bool getJacobianBaseVelocityToBendingEnergy(const NeedleInsertionModel &model, vpMatrix &J)
Base to bending energy (1x6)
bool getJacobianSpringVelocityToPointVelocity(const NeedleInsertionModel &model, vpMatrix &J, int spring, double l)
Springs to needle point (3x6)
bool getJacobianWorldBaseVelocityToBendingEnergy(const NeedleInsertionModel &model, vpMatrix &J)
bool getJacobianBaseVelocityToTargetAngle(const NeedleInsertionModel &model, vpMatrix &J, const vpColVector &target)
bool getJacobianWorldBaseVelocityToPointVelocity(const NeedleInsertionModel &model, vpMatrix &J, double l)
bool getJacobianBaseVelocityToMaxTissueStretch(const NeedleInsertionModel &model, vpMatrix &J)
bool getJacobianWorldBaseVelocityToWorldTipVelocity(const NeedleInsertionModel &model, vpMatrix &J)
Base to tip (manipulation Jacobian) (6x6)
bool getJacobianStiffnessPerUnitLengthToPointsVelocity(const NeedleInsertionModel &model, vpMatrix &J, const std::vector< double > &l)
Stiffness per unit length to needle point ( (3*nbPoints)x1 matrix)
bool getJacobianStiffnessPerUnitLengthToPointsDistance(const NeedleInsertionModel &model, vpMatrix &J, const std::vector< vpColVector > &points)
Stiffness per unit length to distance from points (nbPointsx1)
bool getJacobianBaseVelocityToWorldTipVelocity(const NeedleInsertionModel &model, vpMatrix &J)
bool getJacobianBaseVelocityToMeanTissueStretch(const NeedleInsertionModel &model, vpMatrix &J)