Debian package version of polhemus's g4display
Janis Streib
30.03.22 69b66ffc68dca173cf5f014f797e02ca69c7db83
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
// G4Trk.cpp: implementation of the CG4Trk class.
//
//////////////////////////////////////////////////////////////////////
#include <GL/glu.h>
#include "Quaternion.h"
#include "struct.h"
#include "G4Trk.h"
#include <unistd.h>
#include <string.h>
 
 
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
 
const int FRAMERATE=60;
 
 
 
CG4Trk::CG4Trk()
{
 
  m_bConnected=false;
  m_numHubs=0;
  m_hubList=NULL;
  m_pframeData=NULL;
  m_srcLoc=NULL;
 
}
 
CG4Trk::~CG4Trk()
{
 
  if (m_bConnected)
    g4_close_tracker();
  if (m_hubList)
    delete[] m_hubList;
  if (m_pframeData)
    delete[] m_pframeData;
  if (m_srcLoc)
    delete[] m_srcLoc;
 
}
 
bool CG4Trk::Connect(char* cfgFile)
{
  int res=g4_init_sys(&m_sysId,cfgFile,NULL);
  if (res==G4_ERROR_NONE){
    m_bConnected=true;
 
    // get a list of hubs
    G4_CMD_STRUCT cs;
    cs.cmd=G4_CMD_GET_ACTIVE_HUBS;
    cs.cds.id=G4_CREATE_ID(m_sysId,0,0);
    cs.cds.pParam=NULL;
 
    int count=0;
    do {                      // may need to spin awhile until system recognizes attached hubs
      usleep(100000);
      g4_set_query(&cs);
    } while ((cs.cds.iParam==0) && (++count<150));
 
    if (cs.cds.iParam==0){
      m_bConnected=false;
      g4_close_tracker();
      return false;
    }
 
    usleep(500000);    // one more time to catch any stragglers
    g4_set_query(&cs);
 
    m_numHubs=cs.cds.iParam;
 
    m_hubList=new int[m_numHubs];
    cs.cds.pParam=m_hubList;
    g4_set_query(&cs);
 
 
    usleep(100000);
 
    // set units
    // int u=G4_TYPE_INCH;
    // cs.cmd=G4_CMD_UNITS;
    // cs.cds.action=G4_ACTION_SET;
    // cs.cds.iParam=G4_DATA_POS;
    // cs.cds.pParam=&u;
    // int xx=g4_set_query(&cs);
        
    // set up struct for data acquisition
    m_pframeData=new G4_FRAMEDATA[m_numHubs];
    g4_get_frame_data(m_pframeData,m_sysId,m_hubList,m_numHubs);
 
    // get source qty and locations
    cs.cmd=G4_CMD_GET_SOURCE_MAP;
    cs.cds.id=G4_CREATE_ID(m_sysId,0,0);
    cs.cds.pParam=NULL;
    g4_set_query(&cs);
    m_numSrc=cs.cds.iParam;
 
    m_srcLoc=new float[m_numSrc][6];
 
    // build a structure
    LPG4_SRC_MAP map=new G4_SRC_MAP[m_numSrc];
    cs.cds.pParam=map;
    cs.cds.iParam=(G4_TYPE_INCH<<16)|G4_TYPE_EULER_DEGREE;
    g4_set_query(&cs);
    for (int i=0;i<m_numSrc;i++)
      memcpy(m_srcLoc[i],map[i].pos,sizeof(float)*6);
 
    delete[] map;
    return true;
  }
 
  return false;
 
}
//#include <stdio.h>
int CG4Trk::GetHubsPno(REND_STRUCT* prs)
{
  // get all pno
  int rv=g4_get_frame_data(m_pframeData,m_sysId,m_hubList,m_numHubs);
  int num_read=rv&0xffff;
 
  for (int i=0;i<num_read;i++){
    for (int a=0;a<m_numHubs;a++){
      if ((unsigned int)prs->hubList[a].GetId()==m_pframeData[i].hub){
    prs->hubreadmap|=(0x01<<a);
    for (int j=0;j<G4_SENSORS_PER_HUB;j++){
      if (m_pframeData[i].stationMap&(0x01<<j))
        prs->hubList[a].SetPnoData(m_pframeData[i].sfd[j].pos,j);    // set it
    }    // end for j
    break;
      }    // end if
    }    // end for a
  }    // end for i
 
 
 
 
  // /////////////////////////
  // for (int i=0;i<numHubs;i++){        // for ea hub asked for
  //   for (int a=0;a<m_numHubs;a++){        // check against all hubs we're tracking
  //     if (hubarr[i].GetId()==(int)m_pframeData[a].hub){    // a match
  //     if (m_pframeData[a].frame!=0xffffffff){            // make sure new data
  //       for (int j=0;j<G4_SENSORS_PER_HUB;j++){    
  //         if (m_pframeData[a].stationMap&(0x01<<j))    // for ea active sensor
  //           hubarr[i].SetPnoData(m_pframeData[a].sfd[j].pos,j);    // set it
 
  //       }    // end for j
  //     }// end if
  //     }// end if
  //   }// end for a
  // }// end for i
 
 
  return rv>>16;    // return total hubs on system
}
 
 
int CG4Trk::GetActHubs()
{
  return m_numHubs;
}
 
void CG4Trk::GetHubList(int *list, int numEl)
{
  for (int i=0;i<numEl;i++){
    if (i<m_numHubs)
      list[i]=m_hubList[i];
  }
 
}
 
void CG4Trk::GetSrcLoc(float (*loc)[6])
{
  memcpy(loc,m_srcLoc,sizeof(float)*m_numSrc*6);
}    
 
int CG4Trk::GetNumSrc()
{
  return m_numSrc;
 
}
 
void CG4Trk::Boresight(bool enable)
{
  float angle[3]={0.0f,0.0f,0.0f}    ;
  G4_CMD_STRUCT cs;
  cs.cmd=G4_CMD_BORESIGHT;
  cs.cds.id=G4_CREATE_ID(m_sysId,-1,0);    // all hubs,all sensors
  cs.cds.action=enable?G4_ACTION_SET:G4_ACTION_RESET;    // boresight or unboresight?
  cs.cds.iParam=G4_TYPE_EULER_DEGREE;
  cs.cds.pParam=angle;
  g4_set_query(&cs);
}
 
void CG4Trk::GetFilterValues(float *pfilt, float *ofilt)
{
  G4_CMD_STRUCT cs;
  cs.cmd=G4_CMD_FILTER;
  cs.cds.id=G4_CREATE_ID(m_sysId,m_hubList[0],0);
  cs.cds.action=G4_ACTION_GET;
  cs.cds.iParam=G4_DATA_POS;
  cs.cds.pParam=pfilt;
  g4_set_query(&cs);
 
  cs.cds.iParam=G4_DATA_ORI;
  cs.cds.pParam=ofilt;
  g4_set_query(&cs);
 
}
 
void CG4Trk::SetFilterValues(float *pfilt, float *ofilt)
{
  G4_CMD_STRUCT cs;
  cs.cmd=G4_CMD_FILTER;
  cs.cds.id=G4_CREATE_ID(m_sysId,-1,0);
  cs.cds.action=G4_ACTION_SET;
  cs.cds.iParam=G4_DATA_POS;
  cs.cds.pParam=pfilt;
  g4_set_query(&cs);
 
  cs.cds.iParam=G4_DATA_ORI;
  cs.cds.pParam=ofilt;
  g4_set_query(&cs);
 
}
 
void CG4Trk::GetSetIncr(float &posIncr, float &oriIncr,bool bSet)
{
  G4_CMD_STRUCT cs;
  cs.cmd=G4_CMD_INCREMENT;
  float fIncr[2];
 
  if (bSet){
    cs.cds.id=G4_CREATE_ID(m_sysId,-1,0);
    cs.cds.action=G4_ACTION_SET;
    fIncr[0]=posIncr;
    fIncr[1]=oriIncr;
  }
  else {
    cs.cds.id=G4_CREATE_ID(m_sysId,m_hubList[0],0);
    cs.cds.action=G4_ACTION_GET;
  }
  cs.cds.iParam=(G4_TYPE_INCH<<16)|G4_TYPE_EULER_DEGREE;
  cs.cds.pParam=fIncr;
  g4_set_query(&cs);
 
  if (!bSet){
    posIncr=fIncr[0];
    oriIncr=fIncr[1];
  }
 
 
 
}
 
int CG4Trk::UpdateHubs()
{
  // get a list of hubs
  G4_CMD_STRUCT cs;
  cs.cmd=G4_CMD_GET_ACTIVE_HUBS;
  cs.cds.id=G4_CREATE_ID(m_sysId,0,0);
  cs.cds.pParam=NULL;
  g4_set_query(&cs);
 
  if ((int)cs.cds.iParam!=m_numHubs){
    m_numHubs=cs.cds.iParam;
    delete[] m_hubList;
    delete[] m_pframeData;
    m_hubList=new int[m_numHubs];
    m_pframeData=new G4_FRAMEDATA[m_numHubs];
    cs.cds.pParam=m_hubList;
    g4_set_query(&cs);
  }
 
  return m_numHubs;
 
 
}