UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-05-17)
usNeedleInsertionModelInterface.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/usNeedleInsertionModelInterface.h>
34 
35 #include <limits>
36 
37 #include <visp3/core/vpException.h>
38 #include <visp3/core/vpExponentialMap.h>
39 
40 bool usNeedleInsertionModelInterface::setBasePose(double tx, double ty, double tz, double thetax, double thetay,
41  double thetaz)
42 {
43  return this->setBasePose(vpPoseVector(tx, ty, tz, thetax, thetay, thetaz));
44 }
45 
46 bool usNeedleInsertionModelInterface::setBasePose(const vpHomogeneousMatrix &Hpose)
47 {
48  return this->setBasePose(vpPoseVector(Hpose));
49 }
50 
52 {
53  return vpColVector(this->getBasePose().getTranslationVector());
54 }
55 
57 {
58  return vpHomogeneousMatrix(this->getBasePose());
59 }
60 
61 bool usNeedleInsertionModelInterface::moveBase(const vpColVector &v, double time)
62 {
63  if (v.size() != 6)
64  throw vpException(vpException::dimensionError,
65  "usNeedleInsertionModelInterface::moveBase(const vpColVector&): invalid vector dimension");
66  if (time < 0)
67  throw vpException(vpException::badValue,
68  "usNeedleInsertionModelInterface::moveBase(const vpColVector&): negative time period");
69 
70  if (time <= std::numeric_limits<double>::epsilon())
71  return true;
72  if (v.frobeniusNorm() <= std::numeric_limits<double>::epsilon())
73  return true;
74 
75  return this->moveBase(vpExponentialMap::direct(v, time));
76 }
77 
78 bool usNeedleInsertionModelInterface::moveBase(double tx, double ty, double tz, double thetax, double thetay,
79  double thetaz)
80 {
81  return this->moveBase(vpHomogeneousMatrix(tx, ty, tz, thetax, thetay, thetaz));
82 }
83 
84 bool usNeedleInsertionModelInterface::moveBase(const vpPoseVector &pose)
85 {
86  return this->moveBase(vpHomogeneousMatrix(pose));
87 }
88 
90 {
91  if (v.size() != 6)
92  throw vpException(vpException::dimensionError,
93  "usNeedleInsertionModelInterface::moveBase(const vpColVector&): invalid vector dimension");
94 
95  return this->moveBase(vpHomogeneousMatrix(v[0], v[1], v[2], v[3], v[4], v[5]));
96 }
97 
98 bool usNeedleInsertionModelInterface::moveBase(const vpHomogeneousMatrix &Hmotion)
99 {
100  // Move base
101  // Translation and rotation are expressed in base frame
102 
103  return this->setBasePose(this->getWorldMbase() * Hmotion);
104 }
105 
106 bool usNeedleInsertionModelInterface::moveBaseWorldFrame(const vpColVector &v, double time)
107 {
108  if (v.size() != 6)
109  throw vpException(
110  vpException::dimensionError,
111  "usNeedleInsertionModelInterface::moveBaseWorldFrame(const vpColVector&): invalid vector dimension");
112 
113  if (time <= std::numeric_limits<double>::epsilon())
114  return false;
115  if (v.frobeniusNorm() <= std::numeric_limits<double>::epsilon())
116  return false;
117 
118  return this->moveBaseWorldFrame(vpExponentialMap::direct(v, time));
119 }
120 
121 bool usNeedleInsertionModelInterface::moveBaseWorldFrame(double tx, double ty, double tz, double thetax, double thetay,
122  double thetaz)
123 {
124  return this->moveBaseWorldFrame(vpHomogeneousMatrix(tx, ty, tz, thetax, thetay, thetaz));
125 }
126 
128 {
129  return this->moveBaseWorldFrame(vpHomogeneousMatrix(pose));
130 }
131 
133 {
134  if (v.size() != 6)
135  throw vpException(
136  vpException::dimensionError,
137  "usNeedleInsertionModelInterface::moveBaseWorldFrame(const vpColVector&): invalid vector dimension");
138 
139  return this->moveBaseWorldFrame(vpHomogeneousMatrix(v[0], v[1], v[2], v[3], v[4], v[5]));
140 }
141 
142 bool usNeedleInsertionModelInterface::moveBaseWorldFrame(const vpHomogeneousMatrix &Hmotion)
143 {
144  // Move base
145  // Translation is expressed in world frame,
146  // Rotation is expressed in world frame but is done around the base position
147 
148  vpHomogeneousMatrix Hrotation0(this->getWorldMbase());
149 
150  Hrotation0[0][3] = 0;
151  Hrotation0[1][3] = 0;
152  Hrotation0[2][3] = 0;
153 
154  vpHomogeneousMatrix HmotionBaseFrame = Hrotation0.inverse() * Hmotion * Hrotation0;
155 
156  return this->moveBase(HmotionBaseFrame);
157 }
bool moveBase(const vpColVector &v, double time)
virtual bool setBasePose(const vpPoseVector &pose)=0
The following methods should be redefined in the derived classes.
bool moveBaseWorldFrame(const vpColVector &command, double time)
virtual vpPoseVector getBasePose() const =0