UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-05-17)
usNeedleInsertionModelKinematic.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ustk software.
4  * Copyright (C) 2016 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ustk with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * This software was developed at:
17  * Inria Rennes - Bretagne Atlantique
18  * Campus Universitaire de Beaulieu
19  * 35042 Rennes Cedex
20  * France
21  *
22  * If you have questions regarding the use of this file, please contact
23  * Inria at ustk@inria.fr
24  *
25  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27  *
28  * Author:
29  * Jason Chevrie
30  *
31  *****************************************************************************/
32 
33 #include <visp3/ustk_needle_modeling/usNeedleInsertionModelKinematic.h>
34 
35 #include <visp3/core/vpColVector.h>
36 #include <visp3/core/vpExponentialMap.h>
37 #include <visp3/core/vpHomogeneousMatrix.h>
38 
40 
42  : m_needle(needle.m_needle), m_naturalCurvature(needle.m_naturalCurvature)
43 {
44 }
45 
47 
50 {
51  m_needle = needle.m_needle;
52 
54 
55  return (*this);
56 }
57 
59 {
60  return new usNeedleInsertionModelKinematic(*this);
61 }
62 
64 {
65  m_naturalCurvature = naturalCurvature;
66 }
67 
69 
71 
73 
74 bool usNeedleInsertionModelKinematic::moveBase(double vz, double wz, double time)
75 {
76  vpColVector command(6, 0);
77  command[2] = vz;
78  command[5] = wz;
79 
80  return this->usNeedleInsertionModelInterface::moveBase(command, time);
81 }
82 
83 bool usNeedleInsertionModelKinematic::moveBase(double controlCurvature, double vz, double wz, double time)
84 {
85  double naturalCurvature = m_naturalCurvature;
86  m_naturalCurvature = controlCurvature;
87 
88  bool moved = this->moveBase(vz, wz, time);
89 
90  m_naturalCurvature = naturalCurvature;
91 
92  return moved;
93 }
94 
95 bool usNeedleInsertionModelKinematic::setBasePose(const vpPoseVector &pose)
96 {
97  vpHomogeneousMatrix H(pose);
98  vpColVector baseVelocity = vpExponentialMap::inverse(m_needle.getWorldMbase().inverse() * H, 1);
99 
100  m_needle.setBasePose(pose);
101 
102  vpColVector tipVelocity(6, 0);
103  tipVelocity[2] = baseVelocity[2];
104  tipVelocity[3] = m_naturalCurvature * tipVelocity[2];
105  tipVelocity[5] = baseVelocity[5];
106 
107  m_needle.moveTip(tipVelocity, 1);
108 
109  return true;
110 }
111 
bool moveBase(const vpColVector &v, double time)
usNeedleInsertionModelKinematic()
Constructors, destructors.
bool moveBase(const vpColVector &v, double time)
Control of the needle.
virtual bool setBasePose(const vpPoseVector &pose)=0
The following methods should be redefined in the derived classes.
const usNeedleModelBaseTip & accessNeedle() const
Needle.
virtual usNeedleInsertionModelKinematic * clone() const
void setNaturalCurvature(double naturalCurvature)
Parameters setters and getters.
usNeedleInsertionModelKinematic & operator=(const usNeedleInsertionModelKinematic &needle)
double m_naturalCurvature
needle curvature parameter
vpPoseVector getBasePose() const
Parameters setters and getters.
void setBasePose(double tx, double ty, double tz, double thetax, double thetay, double thetaz)
Command of the needle.
void moveTip(const vpColVector &control, double time)
vpHomogeneousMatrix getWorldMbase() const