HandLocalisationThread.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24/*
25 * @file HandLocalisationThread.cpp
26 *
27 * @author David Schiebener
28 * @date 21.02.2010
29 */
30
31/* includes */
33
34#include <Image/ImageProcessor.h>
35
36namespace visionx
37{
39 int nNumAnnealingRuns,
40 int nPredictionMode,
41 CStereoCalibration* pCalibration,
42 std::string sHandModelFileName)
43 {
45 nNumParticles, nNumAnnealingRuns, nPredictionMode, pCalibration, sHandModelFileName);
46 m_bIsProcessing = false;
47 m_bHasResult = false;
48 m_bReadyForLocalising = false;
49
50 m_pSensorConfig = new double[DSHT_NUM_PARAMETERS];
51 m_pEstimatedConfig = new double[DSHT_NUM_PARAMETERS];
52
53 m_bStopped = false;
54 }
55
57 {
58 Stop();
60 delete[] m_pSensorConfig;
61 delete[] m_pEstimatedConfig;
62 }
63
64 void
66 {
67 m_bStopped = true;
68 CThread::Stop();
69 }
70
71 bool
73 {
74 return m_bIsProcessing;
75 }
76
77 bool
79 {
80 return m_bHasResult;
81 }
82
83 void
84 HandLocalisationThread::GetResult(double* pEstimatedConfig, double& dConfidenceRating)
85 {
86 printf("HandLocalisationThread::GetResult\n");
87 m_mMutex.Lock();
88 if (m_bHasResult)
89 {
90 for (int i = 0; i < DSHT_NUM_PARAMETERS; i++)
91 {
92 pEstimatedConfig[i] = m_pEstimatedConfig[i];
93 }
94 dConfidenceRating = m_dConfidenceRating;
95 m_bHasResult = false;
96 }
97 m_mMutex.UnLock();
98 }
99
100 void
101 HandLocalisationThread::Localise(const CByteImage* pNewCamImageLeft,
102 const CByteImage* pNewCamImageRight,
103 const double* pSensorConfig)
104 {
105 printf("HandLocalisationThread::Localise\n");
106 m_mMutex.Lock();
107 if (!m_bIsProcessing)
108 {
109 ImageProcessor::CopyImage(pNewCamImageLeft, m_pNewCamImageLeft);
110 ImageProcessor::CopyImage(pNewCamImageRight, m_pNewCamImageRight);
111 for (int i = 0; i < DSHT_NUM_PARAMETERS; i++)
112 {
113 m_pSensorConfig[i] = pSensorConfig[i];
114 }
115 m_bIsProcessing = true;
116 m_bReadyForLocalising = true;
117 }
118 m_mMutex.UnLock();
119 }
120
121 int
123 {
124 while (!m_bStopped)
125 {
126 if (m_bReadyForLocalising)
127 {
128 printf("HandLocalisationThread: Starting localisation\n");
129 m_pHandLocalisation->LocaliseHand(m_pNewCamImageLeft,
130 m_pNewCamImageRight,
131 m_pSensorConfig,
132 m_pEstimatedConfig,
133 m_dConfidenceRating);
134 m_bHasResult = true;
135 m_bIsProcessing = false;
136 m_bReadyForLocalising = false;
137 printf("HandLocThread: Confidence %f\n", m_dConfidenceRating);
138 printf("HandLocalisationThread: Localisation finished\n");
139 }
140 else
141 {
142 Threading::SleepThread(10);
143 }
144 }
145
146 return 0;
147 }
148} // namespace visionx
#define DSHT_NUM_PARAMETERS
HandLocalisationThread(int nNumParticles, int nNumAnnealingRuns, int nPredictionMode, CStereoCalibration *pCalibration, std::string sHandModelFileName)
void Localise(const CByteImage *pNewCamImageLeft, const CByteImage *pNewCamImageRight, const double *pSensorConfig)
void GetResult(double *pEstimatedConfig, double &dConfidenceRating)
ArmarX headers.