/** * Use the height data in the grid and a colormap fill a bitmap with colors. * Any undefined heixels in the source will be fill with red (255,0,0). * * \param pBM The bitmap to be colored. * \param color_map A ColorMap which has already had GenerateColorTable() called. * \param nodata The color to use for NODATA areas, where there are no elevation values. * \param progress_callback If supplied, this function will be called back * with a value of 0 to 100 as the operation progresses. * * \return true if any invalid elevation values were encountered. */ bool vtHeightFieldGrid3d::ColorDibFromTable(vtBitmapBase *pBM, const ColorMap *color_map, const RGBAi &nodata, bool progress_callback(int)) const { VTLOG1(" ColorDibFromTable:"); const IPoint2 bitmap_size = pBM->GetSize(); int depth = pBM->GetDepth(); VTLOG(" dib size %d x %d, grid %d x %d.. ", bitmap_size.x, bitmap_size.y, m_iSize.x, m_iSize.y); const bool bExact = (bitmap_size == m_iSize); double ratiox = (double)(m_iSize.x - 1)/(bitmap_size.x - 1), ratioy = (double)(m_iSize.y - 1)/(bitmap_size.y - 1); bool has_invalid = false; const RGBi nodata_24bit(nodata.r, nodata.g, nodata.b); float elev; // now iterate over the texels for (int i = 0; i < bitmap_size.x; i++) { if (progress_callback != NULL && (i&40) == 0) progress_callback(i * 100 / bitmap_size.x); // find the corresponding location in the height grid const double x = i * ratiox; for (int j = 0; j < bitmap_size.y; j++) { const double y = j * ratioy; if (bExact) elev = GetElevation(i, j, true); // Always use true elevation else elev = GetInterpolatedElevation(x, y, true); // Always use true elevation if (elev == INVALID_ELEVATION) { if (depth == 32) pBM->SetPixel32(i, bitmap_size.y - 1 - j, nodata); else pBM->SetPixel24(i, bitmap_size.y - 1 - j, nodata_24bit); has_invalid = true; continue; } const RGBi &rgb = color_map->ColorFromTable(elev); if (depth == 32) pBM->SetPixel32(i, bitmap_size.y - 1 - j, rgb); else pBM->SetPixel24(i, bitmap_size.y - 1 - j, rgb); } } VTLOG("Done.\n"); return has_invalid; }
/** * Use the height data in the grid and a colormap fill a bitmap with colors. * Any undefined heixels in the source will be fill with red (255,0,0). * * \param pBM The bitmap to be colored. * \param table The table of colors. * \param fMin, fMax The range of valid elevation values expect in the input. * \param nodata The color to use for NODATA areas, where there are no elevation values. * \param progress_callback If supplied, this function will be called back * with a value of 0 to 100 as the operation progresses. * * \return true if any invalid elevation values were encountered. */ bool vtHeightFieldGrid3d::ColorDibFromTable(vtBitmapBase *pBM, std::vector<RGBi> &table, float fMin, float fMax, const RGBAi &nodata, bool progress_callback(int)) { VTLOG1(" ColorDibFromTable:"); int w = pBM->GetWidth(); int h = pBM->GetHeight(); int depth = pBM->GetDepth(); int gw, gh; GetDimensions(gw, gh); VTLOG(" dib size %d x %d, grid %d x %d.. ", w, h, gw, gh); bool bExact = (w == gw && h == gh); double ratiox = (double)(gw-1)/(w-1), ratioy = (double)(gh-1)/(h-1); float fRange = fMax - fMin; uint iGranularity = table.size()-1; bool has_invalid = false; RGBi nodata_24bit(nodata.r, nodata.g, nodata.b); double x, y; float elev; // now iterate over the texels for (int i = 0; i < w; i++) { if (progress_callback != NULL) { if ((i&7) == 0) progress_callback(i * 100 / w); } x = i * ratiox; // find corresponding location in height grid for (int j = 0; j < h; j++) { y = j * ratioy; if (bExact) elev = GetElevation(i, j); else elev = GetInterpolatedElevation(x, y); if (elev == INVALID_ELEVATION) { if (depth == 32) pBM->SetPixel32(i, h-1-j, nodata); else pBM->SetPixel24(i, h-1-j, nodata_24bit); has_invalid = true; continue; } uint table_entry = (uint) ((elev - fMin) / fRange * iGranularity); if (table_entry > iGranularity-1) table_entry = iGranularity-1; if (depth == 32) pBM->SetPixel32(i, h-1-j, table[table_entry]); else pBM->SetPixel24(i, h-1-j, table[table_entry]); } } VTLOG("Done.\n"); return has_invalid; }