UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-05-21)
usTissueModelSpline.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/usTissueModelSpline.h>
34 
35 usTissueModelSpline::usTissueModelSpline() : m_surface(), m_path() {}
36 
38  : m_surface(tissue.m_surface), m_path(tissue.m_path)
39 {
40 }
41 
43 
45 {
46  m_surface = tissue.m_surface;
47  m_path = tissue.m_path;
48 
49  return *this;
50 }
51 
53 
55 
57 
59 
61 
62 bool usTissueModelSpline::moveInWorldFrame(const vpHomogeneousMatrix &H)
63 {
65  m_path.move(H);
66 
67  return true;
68 }
69 
70 bool usTissueModelSpline::moveInWorldFrame(double x, double y, double z, double tx, double ty, double tz)
71 {
72  return this->moveInWorldFrame(vpHomogeneousMatrix(x, y, z, tx, ty, tz));
73 }
74 
75 bool usTissueModelSpline::move(const vpHomogeneousMatrix &H)
76 {
77  vpPoseVector ptu(this->getPose());
78 
79  vpHomogeneousMatrix M(ptu);
80  M = M * H * M.inverse();
82  m_path.move(M);
83 
84  return true;
85 }
86 
87 bool usTissueModelSpline::move(double x, double y, double z, double tx, double ty, double tz)
88 {
89  return this->move(vpHomogeneousMatrix(x, y, z, tx, ty, tz));
90 }
91 
92 bool usTissueModelSpline::setPose(const vpPoseVector &p)
93 {
94  vpPoseVector ptu(this->getPose());
95 
96  vpHomogeneousMatrix M(vpHomogeneousMatrix(p) * vpHomogeneousMatrix(ptu).inverse());
98  m_path.move(M);
99 
100  return true;
101 }
102 
103 vpPoseVector usTissueModelSpline::getPose() const
104 {
105  vpPoseVector ptu = m_surface.getPose();
106 
107  if (m_path.getNbSegments() > 0) {
108  vpColVector p = m_path.getPoint(0);
109  for (int i = 0; i < 3; i++)
110  ptu[i] = p[i];
111  }
112 
113  return ptu;
114 }
115 
116 std::ostream &operator<<(std::ostream &s, const usTissueModelSpline &tissue)
117 {
118  s << "usTissueModelSpline\n";
119  s << tissue.m_surface;
120  s << tissue.m_path;
121 
122  s.flush();
123  return s;
124 }
125 
126 std::istream &operator>>(std::istream &s, usTissueModelSpline &tissue)
127 {
128  std::string c;
129  s >> c;
130  if (c != "usTissueModelSpline") {
131  vpException e(vpException::ioError, "Stream does not contain usTissueModelSpline data");
132  throw e;
133  }
134  s >> tissue.m_surface;
135  s >> tissue.m_path;
136  return s;
137 }
138 
139 std::ostream &operator<<=(std::ostream &s, const usTissueModelSpline &tissue)
140 {
141  s.write("usTissueModelSpline", 20);
142  s <<= tissue.m_surface;
143  s <<= tissue.m_path;
144 
145  s.flush();
146  return s;
147 }
148 
149 std::istream &operator>>=(std::istream &s, usTissueModelSpline &tissue)
150 {
151  char c[20];
152  s.read(c, 20);
153  if (strcmp(c, "usTissueModelSpline")) {
154  vpException e(vpException::ioError, "Stream does not contain usTissueModelSpline data");
155  throw e;
156  }
157  s >>= tissue.m_surface;
158  s >>= tissue.m_path;
159  return s;
160 }
int getNbSegments() const
Parameters setters and getters.
Definition: usBSpline3D.cpp:59
bool move(const vpHomogeneousMatrix &H)
Move.
vpColVector getPoint(double param) const
Measure curve information.
void moveInWorldFrame(const vpHomogeneousMatrix &H)
vpPoseVector getPose() const
const usBSpline3D & accessPath() const
const usTissueModelSpline & operator=(const usTissueModelSpline &tissue)
usTissueModelSpline()
Constructors, destructor.
bool moveInWorldFrame(const vpHomogeneousMatrix &H)
bool setPose(const vpPoseVector &p)
vpPoseVector getPose() const
usOrientedPlane3D m_surface
Tissue parameters.
bool move(const vpHomogeneousMatrix &H)
const usOrientedPlane3D & accessSurface() const
Parameters setters and getters.
virtual usTissueModelSpline * clone() const