void RadarCanvas::RenderCursor(int w, int h) { double distance; double bearing; if (m_ri->m_mouse_vrm != 0.0) { distance = m_ri->m_mouse_vrm * 1852.; bearing = m_ri->m_mouse_ebl; } else { if ((m_ri->m_mouse_lat == 0.0 && m_ri->m_mouse_lon == 0.0) || !m_pi->m_bpos_set) { return; } // Can't compute this upfront, ownship may move... distance = local_distance(m_pi->m_ownship_lat, m_pi->m_ownship_lon, m_ri->m_mouse_lat, m_ri->m_mouse_lon) * 1852.; bearing = local_bearing(m_pi->m_ownship_lat, m_pi->m_ownship_lon, m_ri->m_mouse_lat, m_ri->m_mouse_lon); if (!m_ri->IsDisplayNorthUp()) { bearing -= m_pi->m_hdt; } // LOG_DIALOG(wxT("BR24radar_pi: Chart Mouse vrm=%f ebl=%f"), distance / 1852.0, bearing); } double full_range = wxMax(w, h) / 2.0; int display_range = m_ri->GetDisplayRange(); double range = distance * full_range / display_range; #define CURSOR_SCALE 1 double center_x = w / 2.0; double center_y = h / 2.0; double angle = deg2rad(bearing); double x = center_x + sin(angle) * range - CURSOR_WIDTH * CURSOR_SCALE / 2; double y = center_y - cos(angle) * range - CURSOR_WIDTH * CURSOR_SCALE / 2; // LOG_DIALOG(wxT("BR24radar_pi: draw cursor angle=%.1f bearing=%.1f"), rad2deg(angle), bearing); if (!m_cursor_texture) { glGenTextures(1, &m_cursor_texture); glBindTexture(GL_TEXTURE_2D, m_cursor_texture); FillCursorTexture(); LOG_DIALOG(wxT("BR24radar_pi: generated cursor texture # %u"), m_cursor_texture); } glColor3f(1.0f, 1.0f, 1.0f); glBindTexture(GL_TEXTURE_2D, m_cursor_texture); glBegin(GL_QUADS); glTexCoord2i(0, 0); glVertex2i(x, y); glTexCoord2i(1, 0); glVertex2i(x + CURSOR_SCALE * CURSOR_WIDTH, y); glTexCoord2i(1, 1); glVertex2i(x + CURSOR_SCALE * CURSOR_WIDTH, y + CURSOR_SCALE * CURSOR_HEIGHT); glTexCoord2i(0, 1); glVertex2i(x, y + CURSOR_SCALE * CURSOR_HEIGHT); glEnd(); }
inline float Recognizer::dtw(float *s, unsigned int n, float *t, unsigned int m) { /* Compare an input sequence with a reference sequence. s: input sequence n: number of vectors in s t: reference sequence m: number of vectors in t */ unsigned int i, j; float cost; float *t_start, *tmp; t_start = t; /* Initialize the edge cells */ for (i=1; i < m; i++) dtw1[i] = FLT_MAX; dtw1[0] = 0; dtw2[0] = FLT_MAX; s += VEC_DIM_MAX; /* Iterate over columns */ for (i=1; i < n; i++) { t = t_start + VEC_DIM_MAX; /* Iterate over cells of that column */ for (j=1; j < m; j++) { cost = local_distance(s, t); /* Inductive step */ dtw2[j] = cost + MIN3(dtw2[j-1],dtw1[j],dtw1[j-1]); t += VEC_DIM_MAX; } SWAP(dtw1,dtw2,tmp); *dtw2 = FLT_MAX; s += VEC_DIM_MAX; } return dtw1[m-1]; }