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 namespace 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();
59  delete m_pHandLocalisation;
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
HandLocalisationThread.h
visionx::HandLocalisationThread::GetResult
void GetResult(double *pEstimatedConfig, double &dConfidenceRating)
Definition: HandLocalisationThread.cpp:84
visionx::HandLocalisationThread::IsProcessing
bool IsProcessing()
Definition: HandLocalisationThread.cpp:72
visionx::HandLocalisationThread::HasResult
bool HasResult()
Definition: HandLocalisationThread.cpp:78
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:362
visionx::CHandLocalisation
Definition: HandLocalisation.h:71
visionx::HandLocalisationThread::Localise
void Localise(const CByteImage *pNewCamImageLeft, const CByteImage *pNewCamImageRight, const double *pSensorConfig)
Definition: HandLocalisationThread.cpp:101
DSHT_NUM_PARAMETERS
#define DSHT_NUM_PARAMETERS
Definition: HandLocalisationConstants.h:53
visionx::HandLocalisationThread::Stop
void Stop()
Definition: HandLocalisationThread.cpp:65
visionx::HandLocalisationThread::ThreadMethod
int ThreadMethod() override
Definition: HandLocalisationThread.cpp:122
visionx::HandLocalisationThread::HandLocalisationThread
HandLocalisationThread(int nNumParticles, int nNumAnnealingRuns, int nPredictionMode, CStereoCalibration *pCalibration, std::string sHandModelFileName)
Definition: HandLocalisationThread.cpp:38
visionx::HandLocalisationThread::~HandLocalisationThread
~HandLocalisationThread() override
Definition: HandLocalisationThread.cpp:56