//--------------------------------------------------------- inline void CSG_3DView_Canvas::_Draw_Pixel(int x, int y, double z, int color) { if( x >= 0 && x < m_Image_NX && y >= 0 && y < m_Image_NY && z < m_Image_zMax[y][x] ) { BYTE *RGB = m_Image_pRGB + 3 * (y * m_Image_NX + x); switch( m_Color_Mode ) { case COLOR_MODE_RGB: RGB[0] = SG_GET_R(color); RGB[1] = SG_GET_G(color); RGB[2] = SG_GET_B(color); break; case COLOR_MODE_RED: RGB[0] = (SG_GET_R(color) + SG_GET_G(color) + SG_GET_B(color)) / 3; break; case COLOR_MODE_GREEN: RGB[1] = (SG_GET_R(color) + SG_GET_G(color) + SG_GET_B(color)) / 3; break; case COLOR_MODE_BLUE: RGB[2] = (SG_GET_R(color) + SG_GET_G(color) + SG_GET_B(color)) / 3; break; case COLOR_MODE_CYAN: RGB[1] = RGB[2] = (SG_GET_R(color) + SG_GET_G(color) + SG_GET_B(color)) / 3; break; } m_Image_zMax[y][x] = z; } }
//--------------------------------------------------------- void CSG_3DView_Canvas::_Draw_Background(void) { BYTE r, g, b; if( m_bStereo ) // greyscale { r = g = b = (int)((SG_GET_R(m_bgColor) + SG_GET_G(m_bgColor) + SG_GET_B(m_bgColor)) / 3.0); } else { r = SG_GET_R(m_bgColor); g = SG_GET_G(m_bgColor); b = SG_GET_B(m_bgColor); } #pragma omp parallel for for(int y=0; y<m_Image_NY; y++) { BYTE *pRGB = m_Image_pRGB + y * 3 * m_Image_NX; for(int x=0; x<m_Image_NX; x++) { *pRGB = r; pRGB++; *pRGB = g; pRGB++; *pRGB = b; pRGB++; } } }
//--------------------------------------------------------- wxString CWKSP_PointCloud::Get_Value(CSG_Point ptWorld, double Epsilon) { CSG_Shape *pShape; if( (pShape = m_pPointCloud->Get_Shape(ptWorld, Epsilon)) != NULL ) { if( m_Color_Field >= 0 ) { switch( m_pClassify->Get_Mode() ) { case CLASSIFY_LUT: return( m_pClassify->Get_Class_Name_byValue(pShape->asDouble(m_Color_Field)) ); case CLASSIFY_METRIC: default: return( pShape->asString(m_Color_Field) ); case CLASSIFY_RGB: double Value = pShape->asDouble(m_Color_Field); return( wxString::Format(wxT("R%03d G%03d B%03d"), SG_GET_R((int)Value), SG_GET_G((int)Value), SG_GET_B((int)Value)) ); } } else { return( wxString::Format(wxT("%s: %d"), LNG("[CAP] Index"), pShape->Get_Index() + 1) ); } } return( LNG("") ); }
CSG_String CSG_Doc_SVG::_Get_SVGColor(int iColor) { CSG_String s; if (iColor == SG_COLOR_NONE) { return SG_T("none"); } else if (iColor == SG_COLOR_RANDOM) { s.Append(SG_T("rgb(")); s.Append(SG_Get_String((int)(255.0 * (double)rand() / (double)RAND_MAX),0)); s.Append(SG_T(",")); s.Append(SG_Get_String((int)(255.0 * (double)rand() / (double)RAND_MAX),0)); s.Append(SG_T(",")); s.Append(SG_Get_String((int)(255.0 * (double)rand() / (double)RAND_MAX),0)); s.Append(SG_T(")")); return s; } else { s.Append(SG_T("rgb(")); s.Append(SG_Get_String(SG_GET_R(iColor),0)); s.Append(SG_T(",")); s.Append(SG_Get_String(SG_GET_G(iColor),0)); s.Append(SG_T(",")); s.Append(SG_Get_String(SG_GET_B(iColor),0)); s.Append(SG_T(")")); return s; } }
//--------------------------------------------------------- int CSG_3DView_Canvas::Dim_Color(int Color, double dim) { if( dim <= 0.0 ) { return( m_bgColor ); } if( dim != 1.0 ) { int r = SG_GET_R(m_bgColor) + (int)(dim * (SG_GET_R(Color) - SG_GET_R(m_bgColor))); if( r > 255 ) r = 255; int g = SG_GET_G(m_bgColor) + (int)(dim * (SG_GET_G(Color) - SG_GET_G(m_bgColor))); if( g > 255 ) g = 255; int b = SG_GET_B(m_bgColor) + (int)(dim * (SG_GET_B(Color) - SG_GET_B(m_bgColor))); if( b > 255 ) b = 255; Color = SG_GET_RGB(r, g, b); } return( Color ); }
//--------------------------------------------------------- inline void CPoints_View_Extent::_Draw_Pixel(int x, int y, int color) { if( x >= 0 && x < m_Image.GetWidth() && y >= 0 && y < m_Image.GetHeight() ) { BYTE *pRGB = m_Image.GetData() + 3 * ((m_Image.GetHeight() - y - 1) * m_Image.GetWidth() + x); *pRGB = SG_GET_R(color); pRGB++; *pRGB = SG_GET_G(color); pRGB++; *pRGB = SG_GET_B(color); } }
//--------------------------------------------------------- void CWKSP_PointCloud::On_Parameters_Changed(void) { if( (m_Color_Field = m_Parameters("COLORS_ATTRIB")->asInt()) >= m_pPointCloud->Get_Field_Count() ) { m_Color_Field = -1; } long DefColor = m_Parameters("UNISYMBOL_COLOR")->asColor(); m_Color_Pen = wxColour(SG_GET_R(DefColor), SG_GET_G(DefColor), SG_GET_B(DefColor)); m_PointSize = m_Parameters("DISPLAY_SIZE") ->asInt(); }
//--------------------------------------------------------- void CWKSP_TIN::On_Parameters_Changed(void) { CWKSP_Layer::On_Parameters_Changed(); if( (m_fValue = m_Parameters("METRIC_ATTRIB")->asInt()) >= asTIN()->Get_Field_Count() ) { m_fValue = -1; } long DefColor = m_Parameters("UNISYMBOL_COLOR")->asColor(); m_Color_Pen = wxColour(SG_GET_R(DefColor), SG_GET_G(DefColor), SG_GET_B(DefColor)); }
//--------------------------------------------------------- void CGrid_3D_Image::_Get_Line(int y, T3DPoint *p) { for(int x=0; x<Get_NX(); x++) { if( m_pDEM->is_NoData(x, y) || m_pImage->is_NoData(x, y) ) { p[x].bOk = false; } else { p[x].r = SG_GET_R(m_pImage->asInt(x, y)); p[x].g = SG_GET_G(m_pImage->asInt(x, y)); p[x].b = SG_GET_B(m_pImage->asInt(x, y)); _Get_Position(x, y, m_pDEM->asDouble(x, y), p[x]); } } }
//--------------------------------------------------------- bool DLG_Font(wxFont *pFont, long &_Colour) { wxColour Colour(SG_GET_R(_Colour), SG_GET_G(_Colour), SG_GET_B(_Colour)); wxFontDialog dlg(MDI_Get_Top_Window()); dlg.GetFontData().SetInitialFont(*pFont); dlg.GetFontData().SetColour(Colour); if( dlg.ShowModal() == wxID_OK ) { *pFont = dlg.GetFontData().GetChosenFont(); Colour = dlg.GetFontData().GetColour(); _Colour = Get_Color_asInt(Colour); return( true ); } return( false ); }
//--------------------------------------------------------- bool CGrid_RGB_Split::On_Execute(void) { CSG_Grid *pRGB = Parameters("RGB")->asGrid(); if( SG_Data_Type_Get_Size(pRGB->Get_Type()) < 4 ) { Message_Add(_TL("warning, input uses less than 4 bytes per value")); } bool bNoData = Parameters("NODATA")->asBool(); CSG_Grid *pR = Parameters("R")->asGrid(); if( bNoData && pR ) pR->Set_NoData_Value(-1); CSG_Grid *pG = Parameters("G")->asGrid(); if( bNoData && pG ) pG->Set_NoData_Value(-1); CSG_Grid *pB = Parameters("B")->asGrid(); if( bNoData && pB ) pB->Set_NoData_Value(-1); CSG_Grid *pA = Parameters("A")->asGrid(); if( bNoData && pA ) pA->Set_NoData_Value(-1); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( bNoData || !pRGB->is_NoData(x, y) ) { int RGB = pRGB->asInt(x, y); if( pR ) pR->Set_Value(x, y, SG_GET_R(RGB)); if( pG ) pG->Set_Value(x, y, SG_GET_G(RGB)); if( pB ) pB->Set_Value(x, y, SG_GET_B(RGB)); if( pA ) pA->Set_Value(x, y, SG_GET_A(RGB)); } else { if( pR ) pR->Set_NoData(x, y); if( pG ) pG->Set_NoData(x, y); if( pB ) pB->Set_NoData(x, y); if( pA ) pA->Set_NoData(x, y); } } } return( true ); }
//--------------------------------------------------------- void CSG_3DView_Canvas::_Draw_Box(void) { if( !m_bBox ) { return; } int color = SG_GET_RGB(SG_GET_R(m_bgColor) + 128, SG_GET_G(m_bgColor) + 128, SG_GET_B(m_bgColor) + 128); TSG_Point_Z p[2][4], Buffer; Buffer.x = 0.01 * (m_Data_Max.x - m_Data_Min.x); Buffer.y = 0.01 * (m_Data_Max.y - m_Data_Min.y); Buffer.z = 0.01 * (m_Data_Max.z - m_Data_Min.z); for(int i=0; i<2; i++) { p[i][0].x = m_Data_Min.x - Buffer.x; p[i][0].y = m_Data_Min.y - Buffer.y; p[i][1].x = m_Data_Max.x + Buffer.x; p[i][1].y = m_Data_Min.y - Buffer.y; p[i][2].x = m_Data_Max.x + Buffer.x; p[i][2].y = m_Data_Max.y + Buffer.y; p[i][3].x = m_Data_Min.x - Buffer.x; p[i][3].y = m_Data_Max.y + Buffer.y; p[i][0].z = p[i][1].z = p[i][2].z = p[i][3].z = i == 0 ? m_Data_Min.z - Buffer.z : m_Data_Max.z + Buffer.z; for(int j=0; j<4; j++) { m_Projector.Get_Projection(p[i][j]); } Draw_Line(p[i][0], p[i][1], color); Draw_Line(p[i][1], p[i][2], color); Draw_Line(p[i][2], p[i][3], color); Draw_Line(p[i][3], p[i][0], color); } Draw_Line(p[0][0], p[1][0], color); Draw_Line(p[0][1], p[1][1], color); Draw_Line(p[0][2], p[1][2], color); Draw_Line(p[0][3], p[1][3], color); }
//--------------------------------------------------------- void CWKSP_Layer_Legend::_Draw_Box_Image(wxDC &dc, int ay, CSG_Grid *pGrid) { int x, y, nx, ny, Color; double d, dx, dy; wxImage img; //----------------------------------------------------- if( pGrid->Get_NX() > pGrid->Get_NY() ) { nx = m_dxBox; d = (int)(pGrid->Get_NX() / nx); ny = (int)(pGrid->Get_NY() / d); } else { ny = m_dxBox; d = (int)(pGrid->Get_NY() / ny); nx = (int)(pGrid->Get_NX() / d); } img.Create(nx, ny); for(y=0, dy=0.0; y<ny; y++, dy+=d) { for(x=0, dx=0.0; x<nx; x++, dx+=d) { Color = m_pClassify->Get_Class_Color_byValue(pGrid->asDouble((int)dx, (int)dy)); img.SetRGB(x, ny - 1 - y, SG_GET_R(Color), SG_GET_G(Color), SG_GET_B(Color)); } } dc.DrawBitmap(wxBitmap(img), m_xBox, ay, false); Draw_Edge(dc, EDGE_STYLE_SIMPLE, m_xBox, ay, m_xBox + nx, ay + ny); //----------------------------------------------------- _Set_Size(0, ny); ny += BOX_SPACE; }
//--------------------------------------------------------- bool DLG_Color(long &_Colour) { static wxColourData Colours; Colours.SetChooseFull(true); wxColour Colour(SG_GET_R(_Colour), SG_GET_G(_Colour), SG_GET_B(_Colour)); wxColourDialog dlg(MDI_Get_Top_Window(), &Colours); dlg.GetColourData().SetColour(Colour); if( dlg.ShowModal() == wxID_OK ) { Colours = dlg.GetColourData(); Colour = dlg.GetColourData().GetColour(); _Colour = Get_Color_asInt(Colour); return( true ); } return( false ); }
//--------------------------------------------------------- bool CGrid_Import::On_Execute(void) { bool bTransform; int x, y, yy, Method; double ax, ay, dx, dy, rx, ry, xMin, yMin, Cellsize; CSG_Colors Colors; CSG_String fImage, fWorld, Name; CSG_Grid *pImage; CSG_File Stream; wxImage Image; wxImageHistogram Histogram; //----------------------------------------------------- fImage = Parameters("FILE") ->asString(); Method = Parameters("METHOD") ->asInt(); Name = SG_File_Get_Name(fImage, false); //----------------------------------------------------- wxImageHandler *pImgHandler = NULL; if( !SG_UI_Get_Window_Main() ) { CSG_String fName = SG_File_Get_Name(fImage, true); if( SG_File_Cmp_Extension(fName, SG_T("jpg")) ) pImgHandler = new wxJPEGHandler; else if( SG_File_Cmp_Extension(fName, SG_T("pcx")) ) pImgHandler = new wxPCXHandler; else if( SG_File_Cmp_Extension(fName, SG_T("tif")) ) pImgHandler = new wxTIFFHandler; else if( SG_File_Cmp_Extension(fName, SG_T("gif")) ) pImgHandler = new wxGIFHandler; else if( SG_File_Cmp_Extension(fName, SG_T("pnm")) ) pImgHandler = new wxPNMHandler; else if( SG_File_Cmp_Extension(fName, SG_T("xpm")) ) pImgHandler = new wxXPMHandler; #ifdef _SAGA_MSW else if( SG_File_Cmp_Extension(fName, SG_T("bmp")) ) pImgHandler = new wxBMPHandler; #endif else // if( SG_File_Cmp_Extension(fName, SG_T("png")) ) pImgHandler = new wxPNGHandler; wxImage::AddHandler(pImgHandler); } if( !Image.LoadFile(fImage.c_str()) ) { return( false ); } //----------------------------------------------------- if( SG_File_Cmp_Extension(fImage, SG_T("bmp")) ) { fWorld = SG_File_Make_Path(NULL, fImage, SG_T("bpw")); } else if( SG_File_Cmp_Extension(fImage, SG_T("jpg")) ) { fWorld = SG_File_Make_Path(NULL, fImage, SG_T("jgw")); } else if( SG_File_Cmp_Extension(fImage, SG_T("png")) ) { fWorld = SG_File_Make_Path(NULL, fImage, SG_T("pgw")); } else if( SG_File_Cmp_Extension(fImage, SG_T("tif")) ) { fWorld = SG_File_Make_Path(NULL, fImage, SG_T("tfw")); } else { fWorld = SG_File_Make_Path(NULL, fImage, SG_T("world")); } bTransform = false; xMin = 0.0; yMin = 0.0; Cellsize = 1.0; if( Stream.Open(fWorld, SG_FILE_R, false) && fscanf(Stream.Get_Stream(), "%lf %lf %lf %lf %lf %lf ", &dx, &ry, &rx, &dy, &ax, &ay) == 6 ) { if( dx != -dy || rx != 0.0 || ry != 0.0 ) { bTransform = true; } else { xMin = ax; yMin = ay + dy * (Image.GetHeight() - 1); Cellsize = dx; } } //----------------------------------------------------- // color look-up table... if( Method == 0 && (yy = Image.ComputeHistogram(Histogram)) <= 256 ) { Colors.Set_Count(yy); for(wxImageHistogram::iterator i=Histogram.begin(); i!=Histogram.end(); ++i) { Colors.Set_Color(i->second.index, SG_GET_R(i->first), SG_GET_G(i->first), SG_GET_B(i->first)); } pImage = SG_Create_Grid(yy <= 2 ? SG_DATATYPE_Bit : SG_DATATYPE_Byte, Image.GetWidth(), Image.GetHeight(), Cellsize, xMin, yMin); for(y=0; y<pImage->Get_NY() && Set_Progress(y, pImage->Get_NY()); y++) { yy = bTransform ? y : pImage->Get_NY() - 1 - y; for(x=0; x<pImage->Get_NX(); x++) { pImage->Set_Value(x, y, Histogram[SG_GET_RGB(Image.GetRed(x, yy), Image.GetGreen(x, yy), Image.GetBlue(x, yy))].index); } } if( bTransform ) { Set_Transformation(&pImage, ax, ay, dx, dy, rx, ry); } pImage->Set_Name(Name); pImage->Get_Projection().Load(SG_File_Make_Path(NULL, fImage, SG_T("prj"))); Parameters("OUT_GRID")->Set_Value(pImage); DataObject_Set_Colors(pImage, Colors); DataObject_Update(pImage, 0, Colors.Get_Count() - 1); } //----------------------------------------------------- else // true color... { pImage = SG_Create_Grid(SG_DATATYPE_Int, Image.GetWidth(), Image.GetHeight(), Cellsize, xMin, yMin); pImage ->Set_Name(Name); for(y=0; y<pImage->Get_NY() && Set_Progress(y, pImage->Get_NY()); y++) { yy = bTransform ? y : pImage->Get_NY() - 1 - y; for(x=0; x<pImage->Get_NX(); x++) { pImage->Set_Value(x, y, SG_GET_RGB(Image.GetRed(x, yy), Image.GetGreen(x, yy), Image.GetBlue(x, yy))); } } if( bTransform ) { Set_Transformation(&pImage, ax, ay, dx, dy, rx, ry); } //------------------------------------------------- if( Method != 1 ) // true color... { pImage->Get_Projection().Load(fImage, SG_PROJ_FMT_WKT); pImage->Set_Name(Name); pImage->Get_Projection().Load(SG_File_Make_Path(NULL, fImage, SG_T("prj"))); Parameters("OUT_GRID")->Set_Value(pImage); DataObject_Set_Colors(pImage, 100, SG_COLORS_BLACK_WHITE); DataObject_Set_Parameter(pImage, "COLORS_TYPE", 6); // Color Classification Type: RGB } //------------------------------------------------- else // split channels... { CSG_Grid *pR, *pG, *pB; pR = SG_Create_Grid(pImage->Get_System(), SG_DATATYPE_Byte); pG = SG_Create_Grid(pImage->Get_System(), SG_DATATYPE_Byte); pB = SG_Create_Grid(pImage->Get_System(), SG_DATATYPE_Byte); for(y=0; y<pImage->Get_NY() && Set_Progress(y, pImage->Get_NY()); y++) { for(x=0; x<pImage->Get_NX(); x++) { pR->Set_Value(x, y, SG_GET_R(pImage->asInt(x, y))); pG->Set_Value(x, y, SG_GET_G(pImage->asInt(x, y))); pB->Set_Value(x, y, SG_GET_B(pImage->asInt(x, y))); } } pR->Get_Projection().Load(fImage, SG_PROJ_FMT_WKT); pG->Get_Projection().Load(fImage, SG_PROJ_FMT_WKT); pB->Get_Projection().Load(fImage, SG_PROJ_FMT_WKT); pR->Set_Name(CSG_String::Format(SG_T("%s [R]"), Name.c_str())); pG->Set_Name(CSG_String::Format(SG_T("%s [G]"), Name.c_str())); pB->Set_Name(CSG_String::Format(SG_T("%s [B]"), Name.c_str())); pR->Get_Projection().Load(SG_File_Make_Path(NULL, fImage, SG_T("prj"))); pG->Get_Projection().Load(SG_File_Make_Path(NULL, fImage, SG_T("prj"))); pB->Get_Projection().Load(SG_File_Make_Path(NULL, fImage, SG_T("prj"))); Parameters("OUT_RED") ->Set_Value(pR); Parameters("OUT_GREEN") ->Set_Value(pG); Parameters("OUT_BLUE") ->Set_Value(pB); DataObject_Set_Colors(pR, 100, SG_COLORS_BLACK_RED); DataObject_Set_Colors(pG, 100, SG_COLORS_BLACK_GREEN); DataObject_Set_Colors(pB, 100, SG_COLORS_BLACK_BLUE); } } //----------------------------------------------------- if( !SG_UI_Get_Window_Main() && pImgHandler != NULL) { wxImage::RemoveHandler(pImgHandler->GetName()); } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- wxColour Get_Color_asWX(int Color) { return( wxColour(SG_GET_R(Color), SG_GET_G(Color), SG_GET_B(Color)) ); }
//--------------------------------------------------------- inline bool CWKSP_Shapes_Point::Draw_Initialize(CWKSP_Map_DC &dc_Map, int &Size, CSG_Shape *pShape, int Selection) { //----------------------------------------------------- double dSize; if( m_iSize < 0 ) // default size { dSize = m_Size; } else // size by attribute { if( m_Size_Scale == 0 ) // take value as is { dSize = pShape->asDouble(m_iSize); } else // scale to size range { dSize = (pShape->asDouble(m_iSize) - m_Size_Min) * m_dSize + m_Size; } } switch( m_Size_Type ) { default: case 0: dSize *= dc_Map.m_Scale; break; case 1: dSize *= dc_Map.m_World2DC; break; } Size = (int)(0.5 + dSize); //----------------------------------------------------- if( Size > 0 ) { if( Selection ) { dc_Map.dc.SetBrush(wxBrush(m_Sel_Color_Fill , wxSOLID)); dc_Map.dc.SetPen (wxPen(m_Sel_Color, Selection == 1 ? 2 : 0, wxSOLID)); } else { int Color; if( Get_Class_Color(pShape, Color) ) { wxBrush Brush(m_Brush); Brush.SetColour(SG_GET_R(Color), SG_GET_G(Color), SG_GET_B(Color)); dc_Map.dc.SetBrush(Brush); if( !m_bOutline ) { wxPen Pen(m_Pen); Pen.SetColour(SG_GET_R(Color), SG_GET_G(Color), SG_GET_B(Color)); dc_Map.dc.SetPen(Pen); } } } return( true ); } return( false ); }
//--------------------------------------------------------- bool CGrid_Export::On_Execute(void) { //----------------------------------------------------- int y, iy, Method; double dTrans; CSG_Grid *pGrid, *pShade, Grid, Shade; //----------------------------------------------------- pGrid = Parameters("GRID" )->asGrid(); pShade = Parameters("SHADE" )->asGrid(); Method = Parameters("COLOURING" )->asInt (); dTrans = Parameters("SHADE_TRANS" )->asDouble() / 100.0; if( !pGrid ) { return( false ); } //----------------------------------------------------- if( Method == 5 ) // same as in graphical user interface { if( !SG_UI_DataObject_asImage(pGrid, &Grid) ) { Error_Set("could not retrieve colour coding from graphical user interface."); return( false ); } } else { double zMin, zScale; CSG_Colors Colors; CSG_Table LUT; if( SG_UI_Get_Window_Main() ) { Colors.Assign(Parameters("COL_PALETTE")->asColors()); } else { Colors.Set_Palette( Parameters("COL_PALETTE")->asInt (), Parameters("COL_REVERT" )->asBool(), Parameters("COL_COUNT" )->asInt () ); } switch( Method ) { case 0: // stretch to grid's standard deviation zMin = pGrid->Get_Mean() - Parameters("STDDEV")->asDouble() * pGrid->Get_StdDev(); zScale = Colors.Get_Count() / (2 * Parameters("STDDEV")->asDouble() * pGrid->Get_StdDev()); break; case 1: // stretch to grid's value range zMin = pGrid->Get_ZMin(); zScale = Colors.Get_Count() / pGrid->Get_ZRange(); break; case 2: // stretch to specified value range zMin = Parameters("STRETCH")->asRange()->Get_LoVal(); if( zMin >= (zScale = Parameters("STRETCH")->asRange()->Get_HiVal()) ) { Error_Set(_TL("invalid user specified value range.")); return( false ); } zScale = Colors.Get_Count() / (zScale - zMin); break; case 3: // lookup table if( !Parameters("LUT")->asTable() || Parameters("LUT")->asTable()->Get_Field_Count() < 5 ) { Error_Set(_TL("invalid lookup table.")); return( false ); } LUT.Create(*Parameters("LUT")->asTable()); break; case 4: // rgb coded values break; } //------------------------------------------------- Grid.Create(*Get_System(), SG_DATATYPE_Int); for(y=0, iy=Get_NY()-1; y<Get_NY() && Set_Progress(y); y++, iy--) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { double z = pGrid->asDouble(x, y); if( Method == 3 ) // lookup table { int i, iColor = -1; for(i=0; iColor<0 && i<LUT.Get_Count(); i++) { if( z == LUT[i][3] ) { Grid.Set_Value(x, iy, LUT[iColor = i].asInt(0)); } } for(i=0; iColor<0 && i<LUT.Get_Count(); i++) { if( z >= LUT[i][3] && z <= LUT[i][4] ) { Grid.Set_Value(x, iy, LUT[iColor = i].asInt(0)); } } if( iColor < 0 ) { Grid.Set_NoData(x, iy); } } else if( pGrid->is_NoData(x, y) ) { Grid.Set_NoData(x, iy); } else if( Method == 4 ) // rgb coded values { Grid.Set_Value(x, iy, z); } else { int i = (int)(zScale * (z - zMin)); Grid.Set_Value(x, iy, Colors[i < 0 ? 0 : i >= Colors.Get_Count() ? Colors.Get_Count() - 1 : i]); } } } } //----------------------------------------------------- if( !pShade || pShade->Get_ZRange() <= 0.0 ) { pShade = NULL; } else { double dMinBright, dMaxBright; dMinBright = Parameters("SHADE_BRIGHT")->asRange()->Get_LoVal() / 100.0; dMaxBright = Parameters("SHADE_BRIGHT")->asRange()->Get_HiVal() / 100.0; if( dMinBright >= dMaxBright ) { SG_UI_Msg_Add_Error(_TL("Minimum shade brightness must be lower than maximum shade brightness!")); return( false ); } int nColors = 100; CSG_Colors Colors(nColors, SG_COLORS_BLACK_WHITE, true); //------------------------------------------------- Shade.Create(*Get_System(), SG_DATATYPE_Int); for(y=0, iy=Get_NY()-1; y<Get_NY() && Set_Progress(y); y++, iy--) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( pShade->is_NoData(x, y) ) { Shade.Set_NoData(x, iy); } else { Shade.Set_Value (x, iy, Colors[(int)(nColors * (dMaxBright - dMinBright) * (pShade->asDouble(x, y) - pShade->Get_ZMin()) / pShade->Get_ZRange() + dMinBright)]); } } } } //----------------------------------------------------- wxImage Image(Get_NX(), Get_NY()); if( Grid.Get_NoData_Count() > 0 ) { Image.SetAlpha(); } for(y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( Grid.is_NoData(x, y) || (pShade != NULL && Shade.is_NoData(x, y)) ) { if( Image.HasAlpha() ) { Image.SetAlpha(x, y, wxIMAGE_ALPHA_TRANSPARENT); } Image.SetRGB(x, y, 255, 255, 255); } else { if( Image.HasAlpha() ) { Image.SetAlpha(x, y, wxIMAGE_ALPHA_OPAQUE); } int r, g, b, c = Grid.asInt(x, y); r = SG_GET_R(c); g = SG_GET_G(c); b = SG_GET_B(c); if( pShade ) { c = Shade.asInt(x, y); r = dTrans * r + SG_GET_R(c) * (1.0 - dTrans); g = dTrans * g + SG_GET_G(c) * (1.0 - dTrans); b = dTrans * b + SG_GET_B(c) * (1.0 - dTrans); } Image.SetRGB(x, y, r, g, b); } } } //------------------------------------------------- CSG_String fName(Parameters("FILE")->asString()); if( !SG_File_Cmp_Extension(fName, SG_T("bmp")) && !SG_File_Cmp_Extension(fName, SG_T("jpg")) && !SG_File_Cmp_Extension(fName, SG_T("pcx")) && !SG_File_Cmp_Extension(fName, SG_T("png")) && !SG_File_Cmp_Extension(fName, SG_T("tif")) ) { fName = SG_File_Make_Path(NULL, fName, SG_T("png")); Parameters("FILE")->Set_Value(fName); } //----------------------------------------------------- wxImageHandler *pImgHandler = NULL; if( !SG_UI_Get_Window_Main() ) { if( SG_File_Cmp_Extension(fName, SG_T("jpg")) ) pImgHandler = new wxJPEGHandler; else if( SG_File_Cmp_Extension(fName, SG_T("pcx")) ) pImgHandler = new wxPCXHandler; else if( SG_File_Cmp_Extension(fName, SG_T("tif")) ) pImgHandler = new wxTIFFHandler; #ifdef _SAGA_MSW else if( SG_File_Cmp_Extension(fName, SG_T("bmp")) ) pImgHandler = new wxBMPHandler; #endif else // if( SG_File_Cmp_Extension(fName, SG_T("png")) ) pImgHandler = new wxPNGHandler; wxImage::AddHandler(pImgHandler); } if( !Image.SaveFile(fName.c_str()) ) { Error_Set(CSG_String::Format(SG_T("%s [%s]"), _TL("could not save image file"), fName.c_str())); return( false ); } pGrid->Get_Projection().Save(SG_File_Make_Path(NULL, fName, SG_T("prj")), SG_PROJ_FMT_WKT); //----------------------------------------------------- CSG_File Stream; if( SG_File_Cmp_Extension(fName, SG_T("bmp")) ) Stream.Open(SG_File_Make_Path(NULL, fName, SG_T("bpw")), SG_FILE_W, false); else if( SG_File_Cmp_Extension(fName, SG_T("jpg")) ) Stream.Open(SG_File_Make_Path(NULL, fName, SG_T("jgw")), SG_FILE_W, false); else if( SG_File_Cmp_Extension(fName, SG_T("pcx")) ) Stream.Open(SG_File_Make_Path(NULL, fName, SG_T("pxw")), SG_FILE_W, false); else if( SG_File_Cmp_Extension(fName, SG_T("png")) ) Stream.Open(SG_File_Make_Path(NULL, fName, SG_T("pgw")), SG_FILE_W, false); else if( SG_File_Cmp_Extension(fName, SG_T("tif")) ) Stream.Open(SG_File_Make_Path(NULL, fName, SG_T("tfw")), SG_FILE_W, false); if( Stream.is_Open() ) { Stream.Printf(SG_T("%.10f\n%f\n%f\n%.10f\n%.10f\n%.10f\n"), pGrid->Get_Cellsize(), 0.0, 0.0, -pGrid->Get_Cellsize(), pGrid->Get_XMin(), pGrid->Get_YMax() ); } //----------------------------------------------------- if( Parameters("FILE_KML")->asBool() ) { CSG_MetaData KML; KML.Set_Name("kml"); KML.Add_Property("xmlns", "http://www.opengis.net/kml/2.2"); // CSG_MetaData *pFolder = KML.Add_Child("Folder"); // pFolder->Add_Child("name" , "Raster exported from SAGA"); // pFolder->Add_Child("description", "System for Automated Geoscientific Analyses - www.saga-gis.org"); // CSG_MetaData *pOverlay = pFolder->Add_Child("GroundOverlay"); CSG_MetaData *pOverlay = KML.Add_Child("GroundOverlay"); pOverlay->Add_Child("name" , pGrid->Get_Name()); pOverlay->Add_Child("description", pGrid->Get_Description()); pOverlay->Add_Child("Icon" )->Add_Child("href", SG_File_Get_Name(fName, true)); pOverlay->Add_Child("LatLonBox" ); pOverlay->Get_Child("LatLonBox" )->Add_Child("north", pGrid->Get_YMax()); pOverlay->Get_Child("LatLonBox" )->Add_Child("south", pGrid->Get_YMin()); pOverlay->Get_Child("LatLonBox" )->Add_Child("east" , pGrid->Get_XMax()); pOverlay->Get_Child("LatLonBox" )->Add_Child("west" , pGrid->Get_XMin()); KML.Save(fName, SG_T("kml")); } //----------------------------------------------------- if( !SG_UI_Get_Window_Main() && pImgHandler != NULL) { wxImage::RemoveHandler(pImgHandler->GetName()); } //----------------------------------------------------- return( true ); }