bool BoundaryCheck(const Vector3& CameraPosition) { Vector3 MaxPoint(240, 240, 240); Vector3 MinPoint(-240, -240, -240); if (CameraPosition.x > MinPoint.x && CameraPosition.x < MaxPoint.x && CameraPosition.y > MinPoint.y && CameraPosition.y < MaxPoint.y && CameraPosition.z > MinPoint.z && CameraPosition.z < MaxPoint.z) { return true; } else { return false; } }
/* Calculates one pixel from output map, given the input maps. * Puts all values of input pixels in a list and determines the value of * the output pixel according to these values and the overlapping areas. * Returns 0 if no error occurs, 1 otherwise. */ static int CalcPixel( MAP *out, /* write-only output map */ MAP **in, /* read-only list input maps */ size_t nrCoverCells, /* min. nr. non-MV cells for non-MV */ size_t nrMaps, /* nr. of input maps */ double rOut, /* row number pixel */ double cOut, /* column number pixel */ BOOL aligned, /* maps are aligned */ REAL8 angle) /* angle of output map */ { PTYPE tlX, tlY, trX, trY, brX, brY, blX, blY; double r, c; DATA *list = NULL; /* areas and values of input cells */ size_t i, nrList = 0; /* number of items in list */ POINT2D *outputCell; /* polygon of output cell */ size_t nr = 4; /* nr of points of cell */ CSF_VS vs; /* value scale of first input map */ if(nrCoverCells > 0 && nrMaps > 1) raster = InitRaster(raster); /* initialize the raster */ /* Determine the four corners of output pixel */ RrowCol2Coords(out, rOut, cOut, &tlX, &tlY); /* top left */ RrowCol2Coords(out, rOut, cOut + 1, &trX, &trY); /* top right */ RrowCol2Coords(out, rOut + 1, cOut, &blX, &blY); /* bottom left */ RrowCol2Coords(out, rOut + 1, cOut + 1, &brX, &brY); /* bottom right */ outputCell = PutInPol(tlX, tlY, trX, trY, brX, brY, blX, blY); if(outputCell == NULL) return 1; POSTCOND(outputCell[0].x == outputCell[nr].x); POSTCOND(outputCell[0].y == outputCell[nr].y); /* Get pixel on every input map */ for(i = 0; i < nrMaps; i++) { MAP *X = in[i]; /* input map number i */ PTYPE tlC, tlR, trC, trR, brC, brR, blC, blR; PTYPE tlX2, tlY2, trX2, trY2, brX2, brY2, blX2, blY2; double leftB, belowB, rightB, upperB; /* boundaries */ /* Corners: (tlX, tlY), (trX, trY), (blX, blY) and * (brX, brY). Translate for input map. */ Rcoords2RowCol(X, tlX, tlY, &tlC, &tlR); /* top left */ Rcoords2RowCol(X, trX, trY, &trC, &trR); /* top right */ Rcoords2RowCol(X, blX, blY, &blC, &blR); /* bottom left */ Rcoords2RowCol(X, brX, brY, &brC, &brR); /* bottom right */ /* Boundaries in the input map */ rightB = ceil(MaxPoint(tlR, trR, blR, brR)); belowB = ceil(MaxPoint(tlC, trC, blC, brC)); leftB = floor(MinPoint(tlR, trR, blR, brR)); upperB = floor(MinPoint(tlC, trC, blC, brC)); PRECOND(upperB <= belowB); PRECOND(leftB <= rightB); /* Check all cells between the boundaries */ for(r = upperB; r < belowB; r++) { REAL8 *currRow; if(0 <= r && r <= RgetNrRows(X)) currRow = (REAL8 *)CacheGetRow(in, i, r); for(c = leftB; c < rightB; c++) { /* Cells that might be in pixel */ POINT2D *inputCell; /* polygon input cell */ if(r < 0 || RgetNrRows(X) <= r || c < 0 || RgetNrCols(X) <= c) continue; /* Top left & right, bottom left & right */ RrowCol2Coords(X, r, c, &tlX2, &tlY2); RrowCol2Coords(X, r, c+1, &trX2, &trY2); RrowCol2Coords(X, r+1, c, &blX2, &blY2); RrowCol2Coords(X, r+1, c+1, &brX2, &brY2); inputCell = PutInPol(tlX2, tlY2, trX2, trY2, brX2, brY2, blX2, blY2); if(inputCell == NULL) return 1; POSTCOND(inputCell[0].x == inputCell[nr].x); POSTCOND(inputCell[0].y == inputCell[nr].y); /* Add item to list for cell */ if(AddCell(&list, raster, &nrList, inputCell, outputCell, currRow, X, nrMaps, (size_t)c, nrCoverCells, aligned, angle)) return 1; Free(inputCell); /* deallocate */ } } } /* calculate output value of pixel according value scale */ vs = RgetValueScale(in[0]); if(vs != VS_DIRECTION) CalcScalarOut(out, (size_t)rOut, (size_t)cOut, nrList, list, nrCoverCells, nrMaps); else CalcDirectionOut(out, (size_t) rOut, (size_t) cOut, nrList, list, nrCoverCells, nrMaps); Free(outputCell); /* deallocate */ Free(list); /* deallocate */ return 0; /* successfully terminated */ }