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 */
32 #include "HandLocalisationThread.h"
33 
34 #include <Image/ImageProcessor.h>
35 
36 
37 
38 namespace visionx
39 {
40  HandLocalisationThread::HandLocalisationThread(int nNumParticles, int nNumAnnealingRuns, int nPredictionMode, CStereoCalibration* pCalibration, std::string sHandModelFileName)
41  {
42  m_pHandLocalisation = new CHandLocalisation(nNumParticles, nNumAnnealingRuns, nPredictionMode, pCalibration, sHandModelFileName);
43  m_bIsProcessing = false;
44  m_bHasResult = false;
45  m_bReadyForLocalising = false;
46 
47  m_pSensorConfig = new double[DSHT_NUM_PARAMETERS];
48  m_pEstimatedConfig = new double[DSHT_NUM_PARAMETERS];
49 
50  m_bStopped = false;
51  }
52 
53 
55  {
56  Stop();
57  delete m_pHandLocalisation;
58  delete [] m_pSensorConfig;
59  delete [] m_pEstimatedConfig;
60  }
61 
62 
64  {
65  m_bStopped = true;
66  CThread::Stop();
67  }
68 
69 
71  {
72  return m_bIsProcessing;
73  }
74 
75 
77  {
78  return m_bHasResult;
79  }
80 
81 
82  void HandLocalisationThread::GetResult(double* pEstimatedConfig, double& dConfidenceRating)
83  {
84  printf("HandLocalisationThread::GetResult\n");
85  m_mMutex.Lock();
86  if (m_bHasResult)
87  {
88  for (int i = 0; i < DSHT_NUM_PARAMETERS; i++)
89  {
90  pEstimatedConfig[i] = m_pEstimatedConfig[i];
91  }
92  dConfidenceRating = m_dConfidenceRating;
93  m_bHasResult = false;
94  }
95  m_mMutex.UnLock();
96  }
97 
98 
99  void HandLocalisationThread::Localise(const CByteImage* pNewCamImageLeft, const CByteImage* pNewCamImageRight, const double* pSensorConfig)
100  {
101  printf("HandLocalisationThread::Localise\n");
102  m_mMutex.Lock();
103  if (!m_bIsProcessing)
104  {
105  ImageProcessor::CopyImage(pNewCamImageLeft, m_pNewCamImageLeft);
106  ImageProcessor::CopyImage(pNewCamImageRight, m_pNewCamImageRight);
107  for (int i = 0; i < DSHT_NUM_PARAMETERS; i++)
108  {
109  m_pSensorConfig[i] = pSensorConfig[i];
110  }
111  m_bIsProcessing = true;
112  m_bReadyForLocalising = true;
113  }
114  m_mMutex.UnLock();
115  }
116 
117 
118 
119 
121  {
122  while (!m_bStopped)
123  {
124  if (m_bReadyForLocalising)
125  {
126  printf("HandLocalisationThread: Starting localisation\n");
127  m_pHandLocalisation->LocaliseHand(m_pNewCamImageLeft, m_pNewCamImageRight, m_pSensorConfig, m_pEstimatedConfig, m_dConfidenceRating);
128  m_bHasResult = true;
129  m_bIsProcessing = false;
130  m_bReadyForLocalising = false;
131  printf("HandLocThread: Confidence %f\n", m_dConfidenceRating);
132  printf("HandLocalisationThread: Localisation finished\n");
133  }
134  else
135  {
136  Threading::SleepThread(10);
137  }
138  }
139 
140  return 0;
141  }
142 }
143 
144 
HandLocalisationThread.h
visionx::HandLocalisationThread::GetResult
void GetResult(double *pEstimatedConfig, double &dConfidenceRating)
Definition: HandLocalisationThread.cpp:82
visionx::HandLocalisationThread::IsProcessing
bool IsProcessing()
Definition: HandLocalisationThread.cpp:70
visionx::HandLocalisationThread::HasResult
bool HasResult()
Definition: HandLocalisationThread.cpp:76
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::HandLocalisationThread::m_pHandLocalisation
CHandLocalisation * m_pHandLocalisation
Definition: HandLocalisationThread.h:69
visionx::CHandLocalisation::LocaliseHand
void LocaliseHand(const CByteImage *pNewCamImageLeft, const CByteImage *pNewCamImageRight, const double *pSensorConfig, double *pEstimatedConfig, double &dConfidenceRating)
Definition: HandLocalisation.cpp:333
visionx::CHandLocalisation
Definition: HandLocalisation.h:72
visionx::HandLocalisationThread::Localise
void Localise(const CByteImage *pNewCamImageLeft, const CByteImage *pNewCamImageRight, const double *pSensorConfig)
Definition: HandLocalisationThread.cpp:99
DSHT_NUM_PARAMETERS
#define DSHT_NUM_PARAMETERS
Definition: HandLocalisationConstants.h:53
visionx::HandLocalisationThread::Stop
void Stop()
Definition: HandLocalisationThread.cpp:63
visionx::HandLocalisationThread::ThreadMethod
int ThreadMethod() override
Definition: HandLocalisationThread.cpp:120
visionx::HandLocalisationThread::HandLocalisationThread
HandLocalisationThread(int nNumParticles, int nNumAnnealingRuns, int nPredictionMode, CStereoCalibration *pCalibration, std::string sHandModelFileName)
Definition: HandLocalisationThread.cpp:40
visionx::HandLocalisationThread::~HandLocalisationThread
~HandLocalisationThread() override
Definition: HandLocalisationThread.cpp:54