UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-11-21)
usNeedleTipActuated.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/usNeedleTipActuated.h>
34 
35 #include <visp3/core/vpException.h>
36 #include <visp3/core/vpHomogeneousMatrix.h>
37 
38 usNeedleTipActuated::usNeedleTipActuated() : usNeedleTip(), _diameter(0), _length(0), _angle(0), _steeringAngle(0) {}
39 
41  : usNeedleTip(tip), _diameter(tip._diameter), _length(tip._length), _angle(tip._angle),
42  _steeringAngle(tip._steeringAngle)
43 {
44 }
45 
47 
49 {
50  this->usNeedleTip::operator=(tip);
51 
52  _diameter = tip._diameter;
53  _length = tip._length;
54  _angle = tip._angle;
56 
57  return (*this);
58 }
59 
61 
62 void usNeedleTipActuated::setDiameter(double diameter)
63 {
64  if (diameter > 0)
65  _diameter = diameter;
66 }
67 
68 double usNeedleTipActuated::getDiameter() const { return _diameter; }
69 
71 {
72  if (l >= 0)
73  _length = l;
74 }
75 
76 double usNeedleTipActuated::getLength() const { return _length; }
77 
79 {
80  if (angle >= 0 && angle <= M_PI / 2)
81  _angle = angle;
82 }
83 
84 double usNeedleTipActuated::getTipAngleRad() const { return _angle; }
85 
87 {
88  if (angle >= 0 && angle <= 90)
89  _angle = M_PI / 180 * angle;
90 }
91 
92 double usNeedleTipActuated::getTipAngleDeg() const { return 180 / M_PI * _angle; }
93 
95 {
96  while (angle <= -M_PI)
97  angle += 2 * M_PI;
98  while (angle > M_PI)
99  angle -= 2 * M_PI;
100  _steeringAngle = angle;
101 }
102 
104 
106 {
107  while (angle <= -180)
108  angle += 360;
109  while (angle > 180)
110  angle -= 360;
111  _steeringAngle = M_PI / 180 * angle;
112 }
113 
114 double usNeedleTipActuated::getSteeringAngleDeg() const { return 180 / M_PI * _steeringAngle; }
115 
116 std::ostream &operator<<(std::ostream &s, const usNeedleTipActuated &tip)
117 {
118  s << "usNeedleTipActuated\n";
119  s << (const usNeedleTip &)tip;
120 
121  s << tip._diameter << '\n';
122  s << tip._length << '\n';
123  s << tip._angle << '\n';
124  s << tip._steeringAngle << '\n';
125 
126  s.flush();
127  return s;
128 }
129 
130 std::istream &operator>>(std::istream &s, usNeedleTipActuated &tip)
131 {
132  std::string c;
133  s >> c;
134  if (c != "usNeedleTipActuated") {
135  vpException e(vpException::ioError, "Stream does not contain usNeedleTipActuated data");
136  throw e;
137  }
138  s >> (usNeedleTip &)tip;
139  s >> tip._diameter;
140  s >> tip._length;
141  s >> tip._angle;
142  s >> tip._steeringAngle;
143  s.get();
144 
145  return s;
146 }
147 
148 std::ostream &operator<<=(std::ostream &s, const usNeedleTipActuated &tip)
149 {
150  s.write("usNeedleTipActuated", 20);
151 
152  s <<= (const usNeedleTip &)tip;
153  s.write((char *)&(tip._diameter), sizeof(double));
154  s.write((char *)&(tip._length), sizeof(double));
155  s.write((char *)&(tip._angle), sizeof(double));
156  s.write((char *)&(tip._steeringAngle), sizeof(double));
157 
158  s.flush();
159  return s;
160 }
161 
162 std::istream &operator>>=(std::istream &s, usNeedleTipActuated &tip)
163 {
164  char c[20];
165  s.read(c, 20);
166  if (strcmp(c, "usNeedleTipActuated")) {
167  vpException e(vpException::ioError, "Stream does not contain usNeedleTipActuated data");
168  throw e;
169  }
170 
171  s >>= (usNeedleTip &)tip;
172  s.read((char *)&(tip._diameter), sizeof(double));
173  s.read((char *)&(tip._length), sizeof(double));
174  s.read((char *)&(tip._angle), sizeof(double));
175  s.read((char *)&(tip._steeringAngle), sizeof(double));
176  return s;
177 }
178 
179 void usNeedleTipActuated::updateTipPose()
180 {
181  vpHomogeneousMatrix H(_length * cos(_steeringAngle) * sin(_angle), _length * sin(_steeringAngle) * sin(_angle),
182  _length * cos(_angle), -_angle * sin(_steeringAngle), _angle * cos(_steeringAngle), 0);
183 
185  m_tipPose.buildFrom(m_worldMtip);
186 }
virtual usNeedleTipActuated & operator=(const usNeedleTipActuated &needle)
void setTipAngleDeg(double angle)
double getSteeringAngleRad() const
double getTipAngleDeg() const
usNeedleTipActuated()
Constructors, destructors.
void setDiameter(double diameter)
Parameters setters and getters.
double getTipAngleRad() const
void setTipAngleRad(double angle)
double getSteeringAngleDeg() const
virtual usNeedleTipActuated * clone() const
void setSteeringAngleRad(double angle)
void setSteeringAngleDeg(double angle)
vpHomogeneousMatrix m_worldMbase
Definition: usNeedleTip.h:46
virtual usNeedleTip & operator=(const usNeedleTip &needle)
Definition: usNeedleTip.cpp:46
vpHomogeneousMatrix m_worldMtip
Definition: usNeedleTip.h:48
vpPoseVector m_tipPose
Definition: usNeedleTip.h:47