//--------------------------------------------------------- bool CPC_From_Shapes::On_Execute(void) { int zField, iField, nFields, *Fields; CSG_PointCloud *pPoints; CSG_Shapes *pShapes; pShapes = Parameters("SHAPES") ->asShapes(); pPoints = Parameters("POINTS") ->asPointCloud(); zField = Parameters("ZFIELD") ->asInt(); if( !pShapes->is_Valid() ) { return( false ); } //----------------------------------------------------- pPoints->Create(); pPoints->Set_Name(pShapes->Get_Name()); nFields = 0; Fields = new int[pShapes->Get_Field_Count()]; if( Parameters("OUTPUT")->asInt() == 1 ) { for(iField=0, nFields=0; iField<pShapes->Get_Field_Count(); iField++) { if( iField != zField && SG_Data_Type_Get_Size(pShapes->Get_Field_Type(iField)) > 0 ) { Fields[nFields++] = iField; pPoints->Add_Field(pShapes->Get_Field_Name(iField), pShapes->Get_Field_Type(iField)); } } } //----------------------------------------------------- for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++) { CSG_Shape *pShape = pShapes->Get_Shape(iShape); for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++) { for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++) { TSG_Point p = pShape->Get_Point(iPoint, iPart); pPoints->Add_Point(p.x, p.y, zField < 0 ? pShape->Get_Z(iPoint, iPart) : pShape->asDouble(zField)); for(iField=0; iField<nFields; iField++) { pPoints->Set_Value(3 + iField, pShape->asDouble(Fields[iField])); } } } } //----------------------------------------------------- delete [] Fields; return( pPoints->Get_Count() > 0 ); }
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- bool CSG_Grid::_Save_Binary(CSG_File &Stream, int xA, int yA, int xN, int yN, TSG_Data_Type File_Type, bool bFlip, bool bSwapBytes) { char *Line, *pValue; int x, y, i, ix, iy, dy, axBytes, nxBytes, nValueBytes; //----------------------------------------------------- if( Stream.is_Open() && m_System.is_Valid() && m_Type != SG_DATATYPE_Undefined ) { Set_File_Type(GRID_FILE_FORMAT_Binary); if( bFlip ) { y = yA + yN - 1; dy = -1; } else { y = yA; dy = 1; } //------------------------------------------------- if( File_Type == SG_DATATYPE_Bit ) { nxBytes = xN / 8 + 1; if( m_Type == File_Type && m_Memory_Type == GRID_MEMORY_Normal && xA % 8 == 0 ) { axBytes = xA / 8; for(iy=0; iy<yN && SG_UI_Process_Set_Progress(iy, yN); iy++, y+=dy) { Stream.Write((char *)m_Values[y] + axBytes, sizeof(char), nxBytes); } } else { Line = (char *)SG_Malloc(nxBytes); for(iy=0; iy<yN && SG_UI_Process_Set_Progress(iy, yN); iy++, y+=dy) { for(ix=0, x=xA, pValue=Line; ix<xN; pValue++) { for(i=0; i<8 && ix<xN; i++, ix++, x++) { *pValue = asChar(x, y) != 0.0 ? *pValue | m_Bitmask[i] : *pValue & (~m_Bitmask[i]); } } Stream.Write(Line, sizeof(char), nxBytes); } SG_Free(Line); } } //------------------------------------------------- else { nValueBytes = SG_Data_Type_Get_Size(File_Type); nxBytes = xN * nValueBytes; if( m_Type == File_Type && m_Memory_Type == GRID_MEMORY_Normal && !bSwapBytes ) { axBytes = xA * nValueBytes; for(iy=0; iy<yN && SG_UI_Process_Set_Progress(iy, yN); iy++, y+=dy) { Stream.Write((char *)m_Values[y] + axBytes, sizeof(char), nxBytes); } } else { Line = (char *)SG_Malloc(nxBytes); for(iy=0; iy<yN && SG_UI_Process_Set_Progress(iy, yN); iy++, y+=dy) { for(ix=0, x=xA, pValue=Line; ix<xN; ix++, x++, pValue+=nValueBytes) { switch( File_Type ) { default: break; case SG_DATATYPE_Byte: *(BYTE *)pValue = asChar (x, y); break; case SG_DATATYPE_Char: *(char *)pValue = asChar (x, y); break; case SG_DATATYPE_Word: *(WORD *)pValue = asShort (x, y); break; case SG_DATATYPE_Short: *(short *)pValue = asShort (x, y); break; case SG_DATATYPE_DWord: *(DWORD *)pValue = asInt (x, y); break; case SG_DATATYPE_Int: *(int *)pValue = asInt (x, y); break; case SG_DATATYPE_Float: *(float *)pValue = asFloat (x, y); break; case SG_DATATYPE_Double: *(double *)pValue = asDouble (x, y); break; } if( bSwapBytes ) { _Swap_Bytes(pValue, nValueBytes); } } Stream.Write(Line, sizeof(char), nxBytes); } SG_Free(Line); } } //------------------------------------------------- SG_UI_Process_Set_Ready(); return( true ); } return( false ); }
//--------------------------------------------------------- bool CSG_Grid::_Load_Binary(CSG_File &Stream, TSG_Data_Type File_Type, bool bFlip, bool bSwapBytes) { char *Line, *pValue; int x, y, i, iy, dy, nxBytes, nValueBytes; if( Stream.is_Open() && is_Valid() ) { Set_File_Type(GRID_FILE_FORMAT_Binary); if( bFlip ) { y = Get_NY() - 1; dy = -1; } else { y = 0; dy = 1; } //------------------------------------------------- if( File_Type == SG_DATATYPE_Bit ) { nxBytes = Get_NX() / 8 + 1; if( m_Type == File_Type && m_Memory_Type == GRID_MEMORY_Normal ) { for(iy=0; iy<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(iy, Get_NY()); iy++, y+=dy) { Stream.Read(m_Values[y], sizeof(char), nxBytes); } } else { Line = (char *)SG_Malloc(nxBytes); for(iy=0; iy<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(iy, Get_NY()); iy++, y+=dy) { Stream.Read(Line, sizeof(char), nxBytes); for(x=0, pValue=Line; x<Get_NX(); pValue++) { for(i=0; i<8 && x<Get_NX(); i++, x++) { Set_Value(x, y, (*pValue & m_Bitmask[i]) == 0 ? 0.0 : 1.0); } } } SG_Free(Line); } } //------------------------------------------------- else { nValueBytes = SG_Data_Type_Get_Size(File_Type); nxBytes = Get_NX() * nValueBytes; if( m_Type == File_Type && m_Memory_Type == GRID_MEMORY_Normal && !bSwapBytes ) { for(iy=0; iy<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(iy, Get_NY()); iy++, y+=dy) { Stream.Read(m_Values[y], sizeof(char), nxBytes); } } else { Line = (char *)SG_Malloc(nxBytes); for(iy=0; iy<Get_NY() && !Stream.is_EOF() && SG_UI_Process_Set_Progress(iy, Get_NY()); iy++, y+=dy) { Stream.Read(Line, sizeof(char), nxBytes); for(x=0, pValue=Line; x<Get_NX(); x++, pValue+=nValueBytes) { if( bSwapBytes ) { _Swap_Bytes(pValue, nValueBytes); } switch( File_Type ) { default: break; case SG_DATATYPE_Byte: Set_Value(x, y, *(BYTE *)pValue); break; case SG_DATATYPE_Char: Set_Value(x, y, *(char *)pValue); break; case SG_DATATYPE_Word: Set_Value(x, y, *(WORD *)pValue); break; case SG_DATATYPE_Short: Set_Value(x, y, *(short *)pValue); break; case SG_DATATYPE_DWord: Set_Value(x, y, *(DWORD *)pValue); break; case SG_DATATYPE_Int: Set_Value(x, y, *(int *)pValue); break; case SG_DATATYPE_Float: Set_Value(x, y, *(float *)pValue); break; case SG_DATATYPE_Double: Set_Value(x, y, *(double *)pValue); break; } } } SG_Free(Line); } } //------------------------------------------------- SG_UI_Process_Set_Ready(); return( true ); } return( false ); }