UsTK : Ultrasound ToolKit  version 2.0.1 under development (2024-05-20)
usConfidenceMapController.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  * Authors:
29  * Marc Pouliquen
30  *
31  *****************************************************************************/
32 
38 #include <visp3/ustk_gui/usConfidenceMapController.h>
39 
40 #if (defined(USTK_HAVE_VTK_QT) || defined(USTK_HAVE_QT5)) && defined(VISP_HAVE_MODULE_USTK_CONFIDENCE_MAP)
41 
45 usConfidenceMapController::usConfidenceMapController(QObject *parent)
46  : QObject(parent), m_confidenceProcessor(), m_confidenceMap(), m_gain(5), m_activated(false)
47 {
48 }
49 
50 usConfidenceMapController::~usConfidenceMapController() {}
51 
52 void usConfidenceMapController::updateImage(usImagePreScan2D<unsigned char> image)
53 {
54  m_confidenceProcessor.run(m_confidenceMap, image);
55 
56  // robot orientation control law
57 
58  // confidence barycenter
59  double I_sum = 0.0;
60  for (unsigned int i = 0; i < m_confidenceMap.getHeight(); ++i)
61  for (unsigned int j = 0; j < m_confidenceMap.getWidth(); ++j)
62  I_sum += static_cast<double>(m_confidenceMap[i][j]);
63 
64  double yc = 0.0;
65  for (unsigned int x = 0; x < m_confidenceMap.getHeight(); ++x)
66  for (unsigned int y = 0; y < m_confidenceMap.getWidth(); ++y) {
67  yc += y * m_confidenceMap[x][y];
68  }
69  yc /= I_sum;
70 
71  // compute error angle (taget = barycenter on the central scanline)
72  double thetaError = yc * m_confidenceMap.getScanLinePitch() - m_confidenceMap.getFieldOfView() / 2.0;
73 
74  // emit current confidence barycenter angle (in rad) for display purpose
75 
76  emit(confidenceMap(m_confidenceMap));
77  emit(confidenceBarycenterAngle(yc));
78 
79  // proportionnal control (unit 10-1 deg per second)
80  if (m_activated)
81  emit(updateProbeOrientation(vpMath::deg(m_gain * thetaError) * 10));
82 }
83 
84 void usConfidenceMapController::setPropotionnalControlGain(const double gain) { m_gain = gain; }
85 
86 double usConfidenceMapController::getPropotionnalControlGain() const { return m_gain; }
87 
88 void usConfidenceMapController::activateController(bool activate) { m_activated = activate; }
89 
90 #endif