UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-05-17)
usVirtualSpring.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/usVirtualSpring.h>
34 
36  : usOrientedPlane3D(), m_stiffness(0),
37 
38  m_IsActive(true), m_IsRemovable(true), m_AllowPositionUpdate(true), m_AllowDirectionUpdate(true),
39  m_AllowStiffnessUpdate(true)
40 {
41 }
42 
44  : usOrientedPlane3D(spring),
45 
46  m_stiffness(spring.m_stiffness),
47 
48  m_IsActive(spring.m_IsActive), m_IsRemovable(spring.m_IsRemovable),
49  m_AllowPositionUpdate(spring.m_AllowPositionUpdate), m_AllowDirectionUpdate(spring.m_AllowDirectionUpdate),
50  m_AllowStiffnessUpdate(spring.m_AllowStiffnessUpdate)
51 {
52 }
53 
54 usVirtualSpring::usVirtualSpring(const vpColVector &p, const vpColVector &d, double K)
55  : usOrientedPlane3D(p, d), m_stiffness(0),
56 
57  m_IsActive(true), m_IsRemovable(true), m_AllowPositionUpdate(true), m_AllowDirectionUpdate(true),
58  m_AllowStiffnessUpdate(true)
59 {
60  this->setStiffness(K);
61 }
62 
64 
66 {
67  this->usOrientedPlane3D::operator=(spring);
68  m_stiffness = spring.m_stiffness;
69 
70  m_IsActive = spring.m_IsActive;
75 
76  return *this;
77 }
78 
80 {
81  if (K > 0)
82  m_stiffness = K;
83 }
84 
85 double usVirtualSpring::getStiffness() const { return m_stiffness; }
86 
88 {
89  if (m_stiffness + dK > 0)
90  m_stiffness += dK;
91 }
92 
94 
96 
97 bool usVirtualSpring::IsActive() const { return m_IsActive; }
98 
99 void usVirtualSpring::AllowRemoval(bool flag) { m_IsRemovable = flag; }
100 
102 
104 
106 
108 
110 
112 
114 
115 std::ostream &operator<<(std::ostream &s, const usVirtualSpring &spg)
116 {
117  s << "usVirtualSpring\n";
118 
119  s << *((usOrientedPlane3D *)&spg);
120 
121  s << spg.m_stiffness << '\n';
122  s << spg.m_IsActive << '\n';
123  s << spg.m_IsRemovable << '\n';
124  s << spg.m_AllowPositionUpdate << '\n';
125  s << spg.m_AllowDirectionUpdate << '\n';
126  s << spg.m_AllowStiffnessUpdate << '\n';
127  s.flush();
128  return s;
129 }
130 
131 std::istream &operator>>(std::istream &s, usVirtualSpring &spg)
132 {
133  std::string c;
134  s >> c;
135  if (c != "usVirtualSpring") {
136  vpException e(vpException::ioError,
137  "operator>>=(std::istream&, usVirtualSpring&): Stream does not contain usVirtualSpring data");
138  throw e;
139  }
140 
141  s >> *((usOrientedPlane3D *)&spg);
142 
143  s >> spg.m_stiffness;
144  s >> spg.m_IsActive;
145  s >> spg.m_IsRemovable;
146  s >> spg.m_AllowPositionUpdate;
147  s >> spg.m_AllowDirectionUpdate;
148  s >> spg.m_AllowStiffnessUpdate;
149  s.get();
150 
151  return s;
152 }
153 
154 std::ostream &operator<<=(std::ostream &s, const usVirtualSpring &spg)
155 {
156  s.write("usVirtualSpring", 16);
157  s <<= *((usOrientedPlane3D *)&spg);
158  s.write((char *)&(spg.m_stiffness), sizeof(double));
159  s.write((char *)&(spg.m_IsActive), sizeof(bool));
160  s.write((char *)&(spg.m_IsRemovable), sizeof(bool));
161  s.write((char *)&(spg.m_AllowPositionUpdate), sizeof(bool));
162  s.write((char *)&(spg.m_AllowDirectionUpdate), sizeof(bool));
163  s.write((char *)&(spg.m_AllowStiffnessUpdate), sizeof(bool));
164  s.flush();
165  return s;
166 }
167 
168 std::istream &operator>>=(std::istream &s, usVirtualSpring &spg)
169 {
170  char c[16];
171  s.read(c, 16);
172  if (strcmp(c, "usVirtualSpring")) {
173  vpException e(vpException::ioError,
174  "operator>>=(std::istream&, usVirtualSpring&): Stream does not contain usVirtualSpring data");
175  throw e;
176  }
177  s >>= *((usOrientedPlane3D *)&spg);
178 
179  s.read((char *)&(spg.m_stiffness), sizeof(double));
180  s.read((char *)&(spg.m_IsActive), sizeof(bool));
181  s.read((char *)&(spg.m_IsRemovable), sizeof(bool));
182  s.read((char *)&(spg.m_AllowPositionUpdate), sizeof(bool));
183  s.read((char *)&(spg.m_AllowDirectionUpdate), sizeof(bool));
184  s.read((char *)&(spg.m_AllowStiffnessUpdate), sizeof(bool));
185  return s;
186 }
const usOrientedPlane3D & operator=(const usOrientedPlane3D &plane)
bool IsRemovable() const
void AllowDirectionUpdate(bool flag)
const usVirtualSpring & operator=(const usVirtualSpring &spring)
virtual ~usVirtualSpring()
double getStiffness() const
void AllowStiffnessUpdate(bool flag)
void addStiffness(double dK)
bool IsStiffnessUpdateAllowed() const
usVirtualSpring()
Constructors, destructor.
void AllowPositionUpdate(bool flag)
void AllowRemoval(bool flag)
bool IsPositionUpdateAllowed() const
void setStiffness(double K)
Parameters setters and getters.
bool IsDirectionUpdateAllowed() const
bool IsActive() const