/* * DrawMap: Draw map in area described by params. */ void DrawMap( room_type *room, Draw3DParams *params, Bool bMiniMap ) { AREA area; HDC gDC; BYTE *bits; int width; long t1, t2, t3, t4, t5; static int count = 0; int num_visible_object_SavedForMiniMapHack; stretchfactor = params->stretchfactor; area.x = area.y = 0; area.cx = params->width & ~1; area.cy = params->height & ~1; if( !bMiniMap ) { if (stretchfactor == 1) { gDC = gBitsDC; bits = gBits; width = MAXX; } else { gDC = gBufferDC; bits = gBufferBits; width = 2 * MAXX; } } else { // It seems num_visible_objects needs to be zero initially, and as a result of processing, is left at some // actual value for number of objects in the room. Running this proc for the MiniMap is resulting in this // var being left zero at the end. Unsure why. For now preserve the old value of num_visible_objects to restore // after processing. ajw num_visible_object_SavedForMiniMapHack = num_visible_objects; gDC = gMiniMapDC; bits = gMiniMapBits; width = MINIMAP_MAX_WIDTH; } num_visible_objects = 0; t1 = timeGetTime(); // Trace BSP tree to see if more walls are visible DrawBSP(room, params, MAXX, False); t2 = timeGetTime(); t3 = timeGetTime(); MapDraw( gDC, bits, &area, room, width, bMiniMap ); DrawPostOverlayEffects(room, params); t4 = timeGetTime(); RecopyRoom3D( params->hdc, params->x, params->y, params->width, params->height, bMiniMap ); t5 = timeGetTime(); if( bMiniMap ) num_visible_objects = num_visible_object_SavedForMiniMapHack; if (count++ % 50 == 0) debug(("Map trace %ld, clear %ld, draw %ld, copy %ld\n", t2-t1, t3-t2, t4-t3, t5-t4)); }
int MakeMEM(MEMData *md) { int i, nc, ierr; double gain; string buf; void MapDraw(); if (!md) return 1; if (!md->obs) return 2; if (!md->mem) return 3; if (init_obs(md) <= 0) return CleanUpMEM(4); if (init_mem(md) <= 0) return CleanUpMEM(5); calc_PQR(md, 0); nc = 0; gain = md->aGain; for (i=0; i<md->aIter; i++) { ierr = solve_quick(md, gain); if (ierr != 0) return CleanUpMEM(6); calc_PQR(md, -i-1); if (c2_now > c2_prev) nc++; else nc = 0; if (nc >= 1) { set_back_to_old(); s_df = s_df_old; send_line("Increasing Chi^2 value! Aborting approx. iterations."); calc_PQR(md, -i-1); while (MyLoop(1)); break; } if (s_df > s_df_old && i > 0) { gain *= md->aGain; set_back_to_old(); s_df = s_df_old; sprintf(buf, "Lowering gain to %12.5e.", gain); send_line(buf); calc_PQR(md, -i-1); } save_mem_map(md); sprintf(buf, "Approx. %d, Chi^2=%f", i+1, c2_now); strcpy(md->mem->name, buf); if (s_df < md->aLimit) { sprintf(buf, "Approx. accuracy limit achieved: s_df=%10.3e < %10.3e.", s_df, md->aLimit); send_line(buf); MapDraw(NULL, md->mem, NULL); while (MyLoop(1)); break; } while (MyLoop(1)); if (QueryHaltMEM()) return CleanUpMEM(0); } for (i=0; i<md->eIter; i++) { calc_SE(md); ierr = solve_SE(); if (ierr != 0) return CleanUpMEM(7); calc_PQR(md, i+1); save_mem_map(md); sprintf(buf, "Iter=%d, Chi^2=%f", i+1, c2_now); strcpy(md->mem->name, buf); MapDraw(NULL, md->mem, NULL); if (s_df < md->eLimit) { sprintf(buf, "Exact accuracy limit achieved: s_df=%10.3e < %10.3e.", s_df, md->eLimit); send_line(buf); break; } while (MyLoop(1)); if (QueryHaltMEM()) return CleanUpMEM(0); } return CleanUpMEM(0); }
static void DoInterpolateMap(Widget w, StdForm *sf, XmListCallbackStruct *cb) { int i, j, nX, nY; int err, type, order, corners; double xspa, yspa; string buf; MAP *m, *old = (MAP *)sf->any; int **L; double **A; int FillHolesInArray(), InterpolateArray(); void FreeIntArray(), FreeDoubleArray(); int **AllocIntArray(); double **AllocDoubleArray(); void send_line(), wsscanf(), SetWatchCursor(); void MapDraw(), SetIntpOrder(); int GetIntpType(), GetIntpOrder(), GetIntpCorners(); MAP *new_map(); list *get_maplist(); if (!old) { PostErrorDialog(w, "No map selected to be interpolated."); return; } type = GetIntpType(); order = GetIntpOrder(); corners = GetIntpCorners(); if (order <= 0) { PostWarningDialog(w, "Selected interpolation order is zero."); return; } nX = old->i_no; nY = old->j_no; xspa = old->xspacing; yspa = old->yspacing; A = AllocDoubleArray(nX, nY); if (!A) { PostErrorDialog(NULL, "InterpolateMap: Out of memory."); return; } L = AllocIntArray(nX, nY); if (!L) { FreeDoubleArray(A, nX, nY); PostErrorDialog(NULL, "InterpolateMap: Out of memory."); return; } SetWatchCursor(True); for (i=0; i<nX; i++) { for (j=0; j<nY; j++) { A[i][j] = old->d[i][j]; if (old->f[i][j] <= BLANK) L[i][j] = EMPTY; else L[i][j] = FILLED; } } if (corners > 0) err = FillHolesInArray(A, L, nX, nY, corners); if ((i = order)) { while (i) { err = InterpolateArray(&A, &L, &nX, &nY, type); if (err != 0) { sprintf(buf, "Couldn't interpolate array. err=%d.", err); send_line(buf); if (A) FreeDoubleArray(A, nX, nY); if (L) FreeIntArray(L, nX, nY); SetWatchCursor(False); PostErrorDialog(NULL, buf); return; } xspa /= 2.0; yspa /= 2.0; i--; if (corners > 0) err = FillHolesInArray(A, L, nX, nY, corners); } } m = new_map(get_maplist(), nX, nY); m->type = old->type; m->swapped = old->swapped; m->memed = old->memed; m->original = old->original; m->x0 = old->x0; m->y0 = old->y0; m->xleft = old->xleft; m->xright = old->xright; m->ylower = old->ylower; m->yupper = old->yupper; m->date = old->date; strcpy(m->molecule, old->molecule); m->interpolated = old->interpolated + 1; m->equinox = old->equinox; m->epoch = old->epoch; m->ndata = nX * nY; m->i_min = NINT(m->xleft/xspa); m->i_max = NINT(m->xright/xspa); m->j_min = NINT(m->ylower/yspa); m->j_max = NINT(m->yupper/yspa); m->xspacing = xspa; m->yspacing = yspa; for (i=0; i<nX; i++) { for (j=0; j<nY; j++) { if (L[i][j] == FILLED) { m->f[i][j] = UNBLANK; m->d[i][j] = A[i][j]; m->e[i][j] = UNDEF; } else { m->f[i][j] = BLANK; m->d[i][j] = UNDEF; m->e[i][j] = UNDEF; } } } FreeDoubleArray(A, nX, nY); FreeIntArray(L, nX, nY); SetWatchCursor(False); wsscanf(sf->edit[0], m->name); sprintf(buf, "Interpolated map stored as '%s': %dx%d\n", m->name, nX, nY); send_line(buf); XtDestroyWidget(sf->form); SetIntpOrder(0); MapDraw(NULL, m, NULL); }