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