UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-05-21)
usNeedleTipPrebent.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/usNeedleTipPrebent.h>
34 
35 #include <visp3/core/vpColVector.h>
36 #include <visp3/core/vpDisplay.h>
37 #include <visp3/core/vpException.h>
38 
39 usNeedleTipPrebent::usNeedleTipPrebent() : usNeedleTip(), _diameter(0.001), _length(0.01), _angle(0) {}
40 
42  : usNeedleTip(tip), _diameter(tip._diameter), _length(tip._length), _angle(tip._angle)
43 {
44 }
45 
47 
49 {
50  this->usNeedleTip::operator=(tip);
51 
52  _diameter = tip._diameter;
53  _length = tip._length;
54  _angle = tip._angle;
55 
56  return (*this);
57 }
58 
60 
61 void usNeedleTipPrebent::setDiameter(double diameter)
62 {
63  if (diameter > 0)
64  _diameter = diameter;
65 }
66 
67 double usNeedleTipPrebent::getDiameter() const { return _diameter; }
68 
70 {
71  if (l >= 0)
72  _length = l;
73 }
74 
75 double usNeedleTipPrebent::getLength() const { return _length; }
76 
78 {
79  if (angle >= 0 && angle <= M_PI / 2)
80  _angle = angle;
81 }
82 
83 double usNeedleTipPrebent::getAngleRad() const { return _angle; }
84 
86 {
87  if (angle >= 0 && angle <= 90)
88  _angle = M_PI / 180 * angle;
89 }
90 
91 double usNeedleTipPrebent::getAngleDeg() const { return 180 / M_PI * _angle; }
92 
93 std::ostream &operator<<(std::ostream &s, const usNeedleTipPrebent &tip)
94 {
95  s << "usNeedleTipPrebent\n";
96  s << (const usNeedleTip &)tip;
97 
98  s << tip._diameter << '\n';
99  s << tip._length << '\n';
100  s << tip._angle << '\n';
101 
102  s.flush();
103  return s;
104 }
105 
106 std::istream &operator>>(std::istream &s, usNeedleTipPrebent &tip)
107 {
108  std::string c;
109  s >> c;
110  if (c != "usNeedleTipPrebent") {
111  vpException e(vpException::ioError, "Stream does not contain usNeedleTipPrebent data");
112  throw e;
113  }
114  s >> (usNeedleTip &)tip;
115  s >> tip._diameter;
116  s >> tip._length;
117  s >> tip._angle;
118  s.get();
119 
120  return s;
121 }
122 
123 std::ostream &operator<<=(std::ostream &s, const usNeedleTipPrebent &tip)
124 {
125  s.write("usNeedleTipPrebent", 19);
126 
127  s <<= (const usNeedleTip &)tip;
128  s.write((char *)&(tip._diameter), sizeof(double));
129  s.write((char *)&(tip._length), sizeof(double));
130  s.write((char *)&(tip._angle), sizeof(double));
131 
132  s.flush();
133  return s;
134 }
135 
136 std::istream &operator>>=(std::istream &s, usNeedleTipPrebent &tip)
137 {
138  char c[19];
139  s.read(c, 19);
140  if (strcmp(c, "usNeedleTipPrebent")) {
141  vpException e(vpException::ioError, "Stream does not contain usNeedleTipPrebent data");
142  throw e;
143  }
144 
145  s >>= (usNeedleTip &)tip;
146  s.read((char *)&(tip._diameter), sizeof(double));
147  s.read((char *)&(tip._length), sizeof(double));
148  s.read((char *)&(tip._angle), sizeof(double));
149  return s;
150 }
151 
152 void usNeedleTipPrebent::updateTipPose()
153 {
154  vpHomogeneousMatrix H(0, _length * sin(_angle), _length * cos(_angle), -_angle, 0, 0);
155 
157  m_tipPose.buildFrom(m_worldMtip);
158 }
double getDiameter() const
void setDiameter(double diameter)
Parameters setters and getters.
virtual usNeedleTipPrebent & operator=(const usNeedleTipPrebent &needle)
double getLength() const
usNeedleTipPrebent()
Constructors, destructors.
void setAngleDeg(double angle)
void setAngleRad(double angle)
void setLength(double l)
double getAngleDeg() const
virtual usNeedleTipPrebent * clone() const
double getAngleRad() const
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