//--------------------------------------------------------- bool CFragmentation_Classify::On_Execute(void) { CSG_Grid *pDensity, *pConnectivity, *pFragmentation; pDensity = Parameters("DENSITY") ->asGrid(); pConnectivity = Parameters("CONNECTIVITY") ->asGrid(); pFragmentation = Parameters("FRAGMENTATION") ->asGrid(); m_Weight = Parameters("WEIGHT") ->asDouble(); m_Density_Min = Parameters("DENSITY_MIN") ->asDouble() / 100.0; m_Density_Interior = Parameters("DENSITY_INT") ->asDouble() / 100.0; //----------------------------------------------------- CSG_Parameters Parms; DataObject_Set_Colors(pFragmentation, 100, SG_COLORS_WHITE_GREEN, true); if( DataObject_Get_Parameters(pFragmentation, Parms) && Parms("COLORS_TYPE") && Parms("LUT") ) { Parms("LUT")->asTable()->Assign_Values(&m_LUT); // Lookup Table Parms("COLORS_TYPE")->Set_Value(1); // Color Classification Type: Lookup Table DataObject_Set_Parameters(pFragmentation, Parms); } // pFragmentation->Set_NoData_Value(CLASS_NONE); //----------------------------------------------------- if( 1 ) { for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { if( !pDensity->is_NoData(x, y) && !pConnectivity->is_NoData(x, y) ) { double Density = pDensity ->asDouble(x, y) / 100.0; double Connectivity = pConnectivity ->asDouble(x, y) / 100.0; // pFragmentation ->Set_Value (x, y, 100.0 * Density * Connectivity); pFragmentation ->Set_Value (x, y, Get_Classification(Density, Connectivity)); } else { pFragmentation ->Set_NoData(x, y); } } } //------------------------------------------------- if( Parameters("BORDER")->asBool() ) { Add_Border(pFragmentation); } return( true ); } return( false ); }
//--------------------------------------------------------- bool CDecision_Tree::On_Execute(void) { CSG_Grid *pClasses; //----------------------------------------------------- pClasses = Parameters("CLASSES") ->asGrid(); pClasses ->Set_NoData_Value(-1); //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { pClasses->Set_Value(x, y, Get_Class(Parameters("ROOT")->asParameters(), Get_System()->Get_Grid_to_World(x, y))); } } //----------------------------------------------------- CSG_Parameters P; if( DataObject_Get_Parameters(pClasses, P) && P("COLORS_TYPE") && P("LUT") ) { CSG_Table *pTable = P("LUT")->asTable(); pTable->Del_Records(); Get_Class(Parameters("ROOT")->asParameters(), pTable); P("COLORS_TYPE")->Set_Value(1); // Color Classification Type: Lookup Table DataObject_Set_Parameters(pClasses, P); } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CChange_Detection::On_Execute(void) { bool bNoChange; int iInitial, iFinal; CSG_Matrix Identity; CSG_Table Initial, Final, *pChanges; CSG_Grid *pInitial, *pFinal, *pChange; //----------------------------------------------------- pInitial = Parameters("INITIAL") ->asGrid(); pFinal = Parameters("FINAL") ->asGrid(); pChange = Parameters("CHANGE") ->asGrid(); pChanges = Parameters("CHANGES") ->asTable(); bNoChange = Parameters("NOCHANGE")->asBool(); if( !Get_Classes(Initial, pInitial, true) ) { Error_Set(_TL("no class definitions for initial state")); return( false ); } if( !Get_Classes(Final, pFinal, false) ) { Error_Set(_TL("no class definitions for final state")); return( false ); } if( !Get_Changes(Initial, Final, pChanges, Identity) ) { return( false ); } //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { iInitial = Get_Class(Initial, pInitial->asDouble(x, y)); iFinal = Get_Class(Final , pFinal ->asDouble(x, y)); if( bNoChange || !Identity[iInitial][iFinal] ) { pChanges->Get_Record(iInitial)->Add_Value(1 + iFinal, 1); pChange->Set_Value(x, y, (pChanges->Get_Field_Count() - 1) * iInitial + iFinal); } else { pChange->Set_Value(x, y, -1); } } } //----------------------------------------------------- CSG_Parameters P; if( DataObject_Get_Parameters(pChange, P) && P("COLORS_TYPE") && P("LUT") ) { CSG_Table *pLUT = P("LUT")->asTable(); CSG_Colors cRandom(pChanges->Get_Count()); cRandom.Random(); pLUT->Del_Records(); for(iInitial=0; iInitial<pChanges->Get_Count(); iInitial++) { CSG_Colors cRamp(pChanges->Get_Field_Count() - 1); cRamp.Set_Ramp(cRandom[iInitial], cRandom[iInitial]); cRamp.Set_Ramp_Brighness(225, 50); for(iFinal=0; iFinal<pChanges->Get_Field_Count()-1; iFinal++) { if( pChanges->Get_Record(iInitial)->asInt(1 + iFinal) > 0 ) { CSG_Table_Record *pClass = pLUT->Add_Record(); pClass->Set_Value(0, cRamp.Get_Color(iFinal)); pClass->Set_Value(1, CSG_String::Format(SG_T("%s >> %s"), pChanges->Get_Record(iInitial)->asString(0), pChanges->Get_Field_Name(1 + iFinal))); pClass->Set_Value(3, (pChanges->Get_Field_Count() - 1) * iInitial + iFinal); pClass->Set_Value(4, (pChanges->Get_Field_Count() - 1) * iInitial + iFinal); } } } P("COLORS_TYPE")->Set_Value(1); // Color Classification Type: Lookup Table DataObject_Set_Parameters(pChange, P); } //----------------------------------------------------- double Factor; switch( Parameters("OUTPUT")->asInt() ) { default: Factor = 1.0; break; // cells case 1: Factor = 100.0 / Get_NCells(); break; // percent case 2: Factor = M_SQR(Get_Cellsize()); break; // area } if( Factor != 1.0 ) { for(iInitial=0; iInitial<pChanges->Get_Count(); iInitial++) { for(iFinal=0; iFinal<pChanges->Get_Field_Count()-1; iFinal++) { pChanges->Get_Record(iInitial)->Mul_Value(1 + iFinal, Factor); } } } //----------------------------------------------------- pChanges ->Set_Name(CSG_String::Format(SG_T("%s [%s >> %s]"), _TL("Changes"), pInitial->Get_Name(), pFinal->Get_Name())); pChange ->Set_Name(CSG_String::Format(SG_T("%s [%s >> %s]"), _TL("Changes"), pInitial->Get_Name(), pFinal->Get_Name())); pChange ->Set_NoData_Value(-1); return( true ); }
//--------------------------------------------------------- bool CPointCloud_From_Text_File::On_Execute(void) { CSG_String fileName; int iField, iType; TSG_Data_Type Type; CSG_String Name, Types, s; CSG_PointCloud *pPoints; CSG_Parameters P; CSG_Parameter *pNode; int xField, yField, zField, nAttribs, max_iField; bool bSkipHeader; char fieldSep; std::vector<int> vCol; std::ifstream tabStream; std::string tabLine; double lines; long cntPt, cntInvalid; double x, y, z, value; //----------------------------------------------------- fileName = Parameters("FILE") ->asString(); xField = Parameters("XFIELD") ->asInt() - 1; yField = Parameters("YFIELD") ->asInt() - 1; zField = Parameters("ZFIELD") ->asInt() - 1; nAttribs = Parameters("ATTRIBS") ->asInt(); bSkipHeader = Parameters("SKIP_HEADER") ->asBool(); switch (Parameters("FIELDSEP")->asInt()) { default: case 0: fieldSep = '\t'; break; case 1: fieldSep = ' '; break; case 2: fieldSep = ','; break; } Types.Printf(SG_T("%s|%s|%s|%s|%s|"), _TL("1 byte integer"), _TL("2 byte integer"), _TL("4 byte integer"), _TL("4 byte floating point"), _TL("8 byte floating point") ); P.Set_Name(_TL("Attribute Field Properties")); for(iField=1; iField<=nAttribs; iField++) { s.Printf(SG_T("NODE_%03d") , iField); pNode = P.Add_Node(NULL, s, CSG_String::Format(SG_T("%d. %s"), iField, _TL("Field")), _TL("")); s.Printf(SG_T("FIELD_%03d"), iField); P.Add_String(pNode, s, _TL("Name"), _TL(""), s); s.Printf(SG_T("COLUMN_%03d"), iField); P.Add_Value(pNode, s, _TL("Attribute is Column ..."), _TL(""), PARAMETER_TYPE_Int, iField+3, 1, true); s.Printf(SG_T("TYPE_%03d") , iField); P.Add_Choice(pNode, s, _TL("Type"), _TL(""), Types, 3); } //----------------------------------------------------- if( nAttribs > 0 ) { if( Dlg_Parameters(&P, _TL("Field Properties")) ) { pPoints = SG_Create_PointCloud(); pPoints->Set_Name(SG_File_Get_Name(fileName, false)); Parameters("POINTS")->Set_Value(pPoints); for(iField=0; iField<nAttribs; iField++) { Name = P(CSG_String::Format(SG_T("FIELD_%03d" ), iField + 1).c_str())->asString(); iType = P(CSG_String::Format(SG_T("TYPE_%03d" ), iField + 1).c_str())->asInt(); vCol.push_back(P(CSG_String::Format(SG_T("COLUMN_%03d"), iField + 1).c_str())->asInt() - 1); switch( iType ) { default: case 0: Type = SG_DATATYPE_Char; break; case 1: Type = SG_DATATYPE_Short; break; case 2: Type = SG_DATATYPE_Int; break; case 3: Type = SG_DATATYPE_Float; break; case 4: Type = SG_DATATYPE_Double; break; } pPoints->Add_Field(Name, Type); } } else return( false ); } else { pPoints = SG_Create_PointCloud(); pPoints->Create(); pPoints->Set_Name(SG_File_Get_Name(fileName, false)); Parameters("POINTS")->Set_Value(pPoints); } max_iField = M_GET_MAX(xField, yField); max_iField = M_GET_MAX(max_iField, zField); for( unsigned int i=0; i<vCol.size(); i++ ) { if( max_iField < vCol.at(i) ) max_iField = vCol.at(i); } // open input stream //--------------------------------------------------------- tabStream.open(fileName.b_str(), std::ifstream::in); if( !tabStream ) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Unable to open input file!"))); return (false); } tabStream.seekg(0, std::ios::end); // get length of file lines = (double)tabStream.tellg(); tabStream.seekg(0, std::ios::beg); std::getline(tabStream, tabLine); // as a workaround we assume the number of lines from the length of the first line lines = lines / (double)tabStream.tellg(); if( !bSkipHeader ) { tabStream.clear(); // let's forget we may have reached the EOF tabStream.seekg(0, std::ios::beg); // and rewind to the beginning } // import //--------------------------------------------------------- cntPt = cntInvalid = 0; SG_UI_Process_Set_Text(CSG_String::Format(_TL("Importing data ..."))); while( std::getline(tabStream, tabLine) ) { std::istringstream stream(tabLine); std::vector<std::string> tabCols; std::string tabEntry; if( cntPt%10000 == 0 ) SG_UI_Process_Set_Progress((double)cntPt, lines); cntPt++; while( std::getline(stream, tabEntry, fieldSep) ) // read every column in this line and fill vector { if (tabEntry.length() == 0) continue; tabCols.push_back(tabEntry); } if ((int)tabCols.size() < max_iField - 1 ) { SG_UI_Msg_Add(CSG_String::Format(_TL("WARNING: Skipping misformatted line (%.0f)!"), cntPt), true); cntInvalid++; continue; } x = strtod(tabCols[xField].c_str(), NULL); y = strtod(tabCols[yField].c_str(), NULL); z = strtod(tabCols[zField].c_str(), NULL); pPoints->Add_Point(x, y, z); for( int i=0; i<nAttribs; i++ ) { value = strtod(tabCols.at(vCol.at(i)).c_str(), NULL); pPoints->Set_Attribute(i, value); } } // finalize //--------------------------------------------------------- tabStream.close(); CSG_Parameters sParms; DataObject_Get_Parameters(pPoints, sParms); if (sParms("COLORS_ATTRIB") && sParms("COLORS_TYPE") && sParms("METRIC_COLORS") && sParms("METRIC_ZRANGE") && sParms("COLORS_AGGREGATE")) { sParms("COLORS_AGGREGATE")->Set_Value(3); // highest z sParms("COLORS_TYPE")->Set_Value(2); // graduated color sParms("METRIC_COLORS")->asColors()->Set_Count(255); // number of colors sParms("COLORS_ATTRIB")->Set_Value(2); // z attrib sParms("METRIC_ZRANGE")->asRange()->Set_Range(pPoints->Get_Minimum(2),pPoints->Get_Maximum(2)); DataObject_Set_Parameters(pPoints, sParms); DataObject_Update(pPoints); } if (cntInvalid > 0) SG_UI_Msg_Add(CSG_String::Format(_TL("WARNING: Skipped %d invalid points!"), cntInvalid), true); SG_UI_Msg_Add(CSG_String::Format(_TL("%d points sucessfully imported."), (cntPt-cntInvalid)), true); return( true ); }
//--------------------------------------------------------- bool CPointCloud_From_Text_File::On_Execute(void) { CSG_String fileName; int iField, iType; CSG_String Name, Types, s; CSG_PointCloud *pPoints; CSG_Parameters P; CSG_Parameter *pNode; int xField, yField, zField, nAttribs; bool bSkipHeader; char fieldSep; std::vector<int> vCol; std::ifstream tabStream; std::string tabLine; double lines; long cntPt, cntInvalid; double x, y, z; //----------------------------------------------------- fileName = Parameters("FILE") ->asString(); xField = Parameters("XFIELD") ->asInt() - 1; yField = Parameters("YFIELD") ->asInt() - 1; zField = Parameters("ZFIELD") ->asInt() - 1; bSkipHeader = Parameters("SKIP_HEADER") ->asBool(); switch (Parameters("FIELDSEP")->asInt()) { default: case 0: fieldSep = '\t'; break; case 1: fieldSep = ' '; break; case 2: fieldSep = ','; break; } pPoints = SG_Create_PointCloud(); pPoints->Create(); pPoints->Set_Name(SG_File_Get_Name(fileName, false)); Parameters("POINTS")->Set_Value(pPoints); DataObject_Add(pPoints); //----------------------------------------------------- if (SG_UI_Get_Window_Main()) { nAttribs = Parameters("ATTRIBS") ->asInt(); Types.Printf(SG_T("%s|%s|%s|%s|%s|"), _TL("1 byte integer"), _TL("2 byte integer"), _TL("4 byte integer"), _TL("4 byte floating point"), _TL("8 byte floating point") ); P.Set_Name(_TL("Attribute Field Properties")); for(iField=1; iField<=nAttribs; iField++) { s.Printf(SG_T("NODE_%03d") , iField); pNode = P.Add_Node(NULL, s, CSG_String::Format(SG_T("%d. %s"), iField, _TL("Field")), _TL("")); s.Printf(SG_T("FIELD_%03d"), iField); P.Add_String(pNode, s, _TL("Name"), _TL(""), s); s.Printf(SG_T("COLUMN_%03d"), iField); P.Add_Value(pNode, s, _TL("Attribute is Column ..."), _TL(""), PARAMETER_TYPE_Int, iField+3, 1, true); s.Printf(SG_T("TYPE_%03d") , iField); P.Add_Choice(pNode, s, _TL("Type"), _TL(""), Types, 3); } //----------------------------------------------------- if( nAttribs > 0 ) { if( Dlg_Parameters(&P, _TL("Field Properties")) ) { for(iField=0; iField<nAttribs; iField++) { Name = P(CSG_String::Format(SG_T("FIELD_%03d" ), iField + 1).c_str())->asString(); iType = P(CSG_String::Format(SG_T("TYPE_%03d" ), iField + 1).c_str())->asInt(); vCol.push_back(P(CSG_String::Format(SG_T("COLUMN_%03d"), iField + 1).c_str())->asInt() - 1); pPoints->Add_Field(Name, Get_Data_Type(iType)); } } else return( false ); } } else // CMD { CSG_String sFields, sNames, sTypes; CSG_String token; int iValue; std::vector<int> vTypes; sFields = Parameters("FIELDS")->asString(); sNames = Parameters("FIELDNAMES")->asString(); sTypes = Parameters("FIELDTYPES")->asString(); CSG_String_Tokenizer tkz_fields(sFields, ";", SG_TOKEN_STRTOK); while( tkz_fields.Has_More_Tokens() ) { token = tkz_fields.Get_Next_Token(); if( token.Length() == 0 ) break; if( !token.asInt(iValue) ) { SG_UI_Msg_Add_Error(_TL("Error parsing attribute fields: can't convert to number")); return( false ); } iValue -= 1; if( iValue < 1) { SG_UI_Msg_Add_Error(_TL("Error parsing attribute fields: field index out of range")); return( false ); } else vCol.push_back(iValue); } CSG_String_Tokenizer tkz_datatypes(sTypes, ";", SG_TOKEN_STRTOK); while( tkz_datatypes.Has_More_Tokens() ) { token = tkz_datatypes.Get_Next_Token(); if( token.Length() == 0 ) break; if( !token.asInt(iValue) ) { SG_UI_Msg_Add_Error(_TL("Error parsing field type: can't convert to number")); return( false ); } vTypes.push_back(iValue); } CSG_String_Tokenizer tkz_datanames(sNames, ";", SG_TOKEN_STRTOK); int iter = 0; while( tkz_datanames.Has_More_Tokens() ) { token = tkz_datanames.Get_Next_Token(); if( token.Length() == 0 ) break; pPoints->Add_Field(token, Get_Data_Type(vTypes.at(iter))); iter++; } if( vCol.size() != vTypes.size() || (int)vCol.size() != iter ) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Number of arguments for attribute fields (%d), names (%d) and types (%d) do not match!"), vCol.size(), iter, vTypes.size())); return( false ); } } // open input stream //--------------------------------------------------------- tabStream.open(fileName.b_str(), std::ifstream::in); if( !tabStream ) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Unable to open input file!"))); return (false); } tabStream.seekg(0, std::ios::end); // get length of file lines = (double)tabStream.tellg(); tabStream.seekg(0, std::ios::beg); std::getline(tabStream, tabLine); // as a workaround we assume the number of lines from the length of the first line lines = lines / (double)tabStream.tellg(); if( !bSkipHeader ) { tabStream.clear(); // let's forget we may have reached the EOF tabStream.seekg(0, std::ios::beg); // and rewind to the beginning } // import //--------------------------------------------------------- cntPt = cntInvalid = 0; SG_UI_Process_Set_Text(CSG_String::Format(_TL("Importing data ..."))); while( std::getline(tabStream, tabLine) ) { std::istringstream stream(tabLine); std::vector<std::string> tabCols; std::string tabEntry; if( cntPt%10000 == 0 ) { SG_UI_Process_Set_Progress((double)cntPt, lines); } cntPt++; while( std::getline(stream, tabEntry, fieldSep) ) // read every column in this line and fill vector { if (tabEntry.length() == 0) continue; tabCols.push_back(tabEntry); } if ((int)tabCols.size() < (vCol.size() + 3) ) { SG_UI_Msg_Add(CSG_String::Format(_TL("WARNING: Skipping misformatted line: %d!"), cntPt), true); cntInvalid++; continue; } //parse line tokens std::vector<double> fieldValues; fieldValues.resize(vCol.size()); x = strtod(tabCols[xField].c_str(), NULL); y = strtod(tabCols[yField].c_str(), NULL); z = strtod(tabCols[zField].c_str(), NULL); for( int i=0; i<(int)vCol.size(); i++ ) { fieldValues[i] = strtod(tabCols.at(vCol.at(i)).c_str(), NULL); } pPoints->Add_Point(x, y, z); for( int i=0; i<(int)vCol.size(); i++ ) { pPoints->Set_Attribute(i, fieldValues[i]); } } // finalize //--------------------------------------------------------- tabStream.close(); CSG_Parameters sParms; DataObject_Get_Parameters(pPoints, sParms); if (sParms("METRIC_ATTRIB") && sParms("COLORS_TYPE") && sParms("METRIC_COLORS") && sParms("METRIC_ZRANGE") && sParms("DISPLAY_VALUE_AGGREGATE")) { sParms("DISPLAY_VALUE_AGGREGATE")->Set_Value(3); // highest z sParms("COLORS_TYPE")->Set_Value(2); // graduated color sParms("METRIC_COLORS")->asColors()->Set_Count(255); // number of colors sParms("METRIC_ATTRIB")->Set_Value(2); // z attrib sParms("METRIC_ZRANGE")->asRange()->Set_Range(pPoints->Get_Minimum(2),pPoints->Get_Maximum(2)); DataObject_Set_Parameters(pPoints, sParms); DataObject_Update(pPoints); } if (cntInvalid > 0) SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %d %s"), _TL("WARNING"), cntInvalid, _TL("invalid points have been skipped")), true); SG_UI_Msg_Add(CSG_String::Format(SG_T("%d %s"), (cntPt-cntInvalid), _TL("points have been imported with success")), true); return( true ); }
//--------------------------------------------------------- bool CTOBIA::On_Execute(void) { double fB = Parameters("fB")->asDouble(); double fC = Parameters("fC")->asDouble(); CSG_Grid *pA, *pB, *pC, *pD, *pE, *pF; pA = Parameters("A" )->asGrid(); //slope pB = Parameters("B" )->asGrid(); //aspect pC = Parameters("C" )->asGrid(); //dip grid pD = Parameters("D" )->asGrid(); //dip dir grid pE = Parameters("E" )->asGrid(); //output TOBIA classes pF = Parameters("F" )->asGrid(); //output TOBIA index for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { double a, b, c, d, e, f; a = pA->asDouble(x, y); b = pB->asDouble(x, y); //Abfrage ob Raster oder Globalwerte c = pC ? pC->asDouble(x, y) : fB; d = pC ? pD->asDouble(x, y) : fC; if (pA->is_NoData(x, y)) { pE->Set_NoData(x, y); if (pF) pF->Set_NoData(x, y); } else if ((pC || pD) && (pC->is_NoData(x, y) || (pD->is_NoData(x, y)))) { pE->Set_NoData(x, y); if (pF) pF->Set_NoData(x, y); } else { e = pow(pow((cos(d/57.2958) - cos(b)), 2) + pow((sin(d/57.2958) - sin(b)), 2), 0.5); //TOBIA-classes if (((0 <= e) && (e < 0.7654)) && ((c - (a*57.2958)) > 5)) pE->Set_Value(x, y, TO_UNDERDIP_SLOPE); else if (((0 <= e) && (e < 0.7654)) && ((-5 <= (c - (a*57.2958))) && ((c - (a*57.2958) <= 5)))) pE->Set_Value(x, y, TO_DIP_SLOPE); else if (((0 <= e) && (e < 0.7654)) && ((c - (a*57.2958)) < -5)) pE->Set_Value(x, y, TO_OVERDIP_SLOPE); else if (((1.8478 < e) && (e <= 2)) && ((c - (a*57.2958)) < -5)) pE->Set_Value(x, y, TO_STEEPENED_ESCARPMENT); else if (((1.8478 < e) && (e <= 2)) && ((-5 <= (c - (a*57.2958))) && ((c - (a*57.2958) <= 5)))) pE->Set_Value(x, y, TO_NORMAL_ESCARPMENT); else if (((1.8478 < e) && (e <= 2)) && ((c - (a*57.2958)) > 5)) pE->Set_Value(x, y, TO_SUBDUED_ESCARPMENT); else if ((0.7654 < e) && (e <= 1.8478)) pE->Set_Value(x, y, TO_ORTHOCLINAL_SLOPE); else pE->Set_NoData_Value(0); if (pF) { f = (cos((c/57.2958)) * (cos(a))) + (sin(c/57.2958) * sin(a) * ((cos((d/57.2958) - b)))); //TOBIA-index pF->Set_Value(x, y, f); } } } } //----------------------------------------------------- CSG_Parameters P; if( DataObject_Get_Parameters(pE, P) && P("COLORS_TYPE") && P("LUT") ) { int TO_Colors[TO_COUNT] = { SG_GET_RGB(255, 255, 0), // TO_UNDERDIP SG_GET_RGB(255, 128, 0), // TO_DIP SG_GET_RGB(255, 0, 0), // TO_OVERDIP SG_GET_RGB( 0, 0, 128), // TO_STEEPENED SG_GET_RGB( 0, 128, 255), // TO_NORMAL SG_GET_RGB(128, 255, 255), // TO_SUBDUED SG_GET_RGB( 0, 255, 64), // TO_ORTHOCLINAL }; //------------------------------------------------- CSG_Strings Name, Desc; Name += _TL("Underdip slope"); Desc += _TL(""); Name += _TL("Dip slope"); Desc += _TL(""); Name += _TL("Overdip slope"); Desc += _TL(""); Name += _TL("Steepened escarpment"); Desc += _TL(""); Name += _TL("Normal escarpment"); Desc += _TL(""); Name += _TL("Subdued escarpment"); Desc += _TL(""); Name += _TL("Orthoclinal slope"); Desc += _TL(""); //------------------------------------------------- CSG_Table *pTable = P("LUT")->asTable(); pTable->Del_Records(); for(int i=0; i<TO_COUNT; i++) { CSG_Table_Record *pRecord = pTable->Add_Record(); pRecord->Set_Value(0, TO_Colors[i]); pRecord->Set_Value(1, Name[i].c_str()); pRecord->Set_Value(2, Desc[i].c_str()); pRecord->Set_Value(3, i); pRecord->Set_Value(4, i); } P("COLORS_TYPE")->Set_Value(1); // Color Classification Type: Lookup Table DataObject_Set_Parameters(pE, P); } return( true ); }
//--------------------------------------------------------- bool CWMS_Import::Get_Map(wxHTTP *pServer, const CSG_String &Directory, CWMS_Capabilities &Cap) { bool bResult = false; int i, n; CSG_Rect r(Cap.m_Extent); CSG_Parameters p; //----------------------------------------------------- // if( Cap.m_MaxWidth > 2 && NX > Cap.m_MaxWidth ) NX = Cap.m_MaxWidth; // if( Cap.m_MaxHeight > 2 && NY > Cap.m_MaxHeight ) NY = Cap.m_MaxHeight; p.Add_Range (NULL , "X_RANGE" , _TL("X Range") , _TL(""), r.Get_XMin(), r.Get_XMax(), r.Get_XMin(), r.Get_XRange() > 0.0, r.Get_XMax(), r.Get_XRange() > 0.0); p.Add_Range (NULL , "Y_RANGE" , _TL("Y Range") , _TL(""), r.Get_YMin(), r.Get_YMax(), r.Get_YMin(), r.Get_YRange() > 0.0, r.Get_YMax(), r.Get_YRange() > 0.0); p.Add_Value (NULL , "CELLSIZE", _TL("Cellsize") , _TL(""), PARAMETER_TYPE_Double, r.Get_XRange() / 2001.0, 0.0, true); p.Add_Choice(NULL , "FORMAT" , _TL("Format") , _TL(""), Cap.m_Formats); p.Add_Choice(NULL , "PROJ" , _TL("Projections"), _TL(""), Cap.m_Projections); CSG_Parameter *pNode = p("FORMAT"); for(i=0; i<pNode->asChoice()->Get_Count(); i++) { CSG_String s(pNode->asChoice()->Get_Item(i)); if( !s.CmpNoCase(SG_T("image/png")) ) pNode->Set_Value(i); } for(i=0; i<Cap.m_Layers_Name.Get_Count(); i++) { p.Add_Value(NULL, Cap.m_Layers_Name[i], Cap.m_Layers_Title[i], "", PARAMETER_TYPE_Bool, false); } //----------------------------------------------------- if( pServer && Dlg_Parameters(&p, _TL("WMS Import")) ) { int NX, NY; double Cellsize; CSG_String Layers, Format; //------------------------------------------------- r.Assign( p("X_RANGE")->asRange()->Get_LoVal(), p("Y_RANGE")->asRange()->Get_LoVal(), p("X_RANGE")->asRange()->Get_HiVal(), p("Y_RANGE")->asRange()->Get_HiVal() ); Cellsize = p("CELLSIZE") ->asDouble(); NX = 1 + (int)(r.Get_XRange() / Cellsize); NY = 1 + (int)(r.Get_YRange() / Cellsize); //------------------------------------------------- Layers.Clear(); for(i=0, n=0; i<Cap.m_Layers_Name.Get_Count(); i++) { if( p(Cap.m_Layers_Name[i])->asBool() ) { if( n++ > 0 ) Layers += ","; Layers += Cap.m_Layers_Name[i]; } } if( n == 0 ) { return( false ); } //------------------------------------------------- wxBitmapType tFormat; Format = p("FORMAT")->asString(); if( Format.Contains(SG_T("image/gif" )) ) tFormat = wxBITMAP_TYPE_GIF ; else if( Format.Contains(SG_T("image/jpeg")) ) tFormat = wxBITMAP_TYPE_JPEG; else if( Format.Contains(SG_T("image/png" )) ) tFormat = wxBITMAP_TYPE_PNG ; else if( Format.Contains(SG_T("image/wbmp")) ) tFormat = wxBITMAP_TYPE_BMP ; else if( Format.Contains(SG_T("image/bmp" )) ) tFormat = wxBITMAP_TYPE_BMP ; else if( Format.Contains(SG_T("image/tiff")) ) tFormat = wxBITMAP_TYPE_TIF ; else if( Format.Contains(SG_T("GIF" )) ) tFormat = wxBITMAP_TYPE_GIF ; else if( Format.Contains(SG_T("JPEG" )) ) tFormat = wxBITMAP_TYPE_JPEG; else if( Format.Contains(SG_T("PNG" )) ) tFormat = wxBITMAP_TYPE_PNG ; else { return( false ); } //------------------------------------------------- CSG_String sRequest(Directory); sRequest += SG_T("?SERVICE=WMS"); sRequest += SG_T("&VERSION=") + Cap.m_Version; sRequest += SG_T("&REQUEST=GetMap"); sRequest += SG_T("&LAYERS=") + Layers; if( Cap.m_Projections.Length() > 0 ) sRequest += CSG_String(S_SRS(Cap.m_Version)) + p("PROJ")->asString(); sRequest += SG_T("&FORMAT=") + Format; sRequest += CSG_String::Format(SG_T("&WIDTH=%d&HEIGHT=%d"), NX, NY); sRequest += CSG_String::Format(SG_T("&BBOX=%f,%f,%f,%f"), r.m_rect.xMin, r.m_rect.yMin, r.m_rect.xMax, r.m_rect.yMax); Message_Add(sRequest, true); //------------------------------------------------- wxInputStream *pStream; if( (pStream = pServer->GetInputStream(sRequest.c_str())) == NULL ) { Message_Add(_TL("could not open GetMap stream")); } else { wxImage Image; if( Image.LoadFile(*pStream, tFormat) == false ) { Message_Add(_TL("could not read image")); CSG_String s = SG_T("\n"); pStream->SeekI(0, wxFromStart); while( !pStream->Eof() ) { s += (char)pStream->GetC(); } Message_Add(s); } else { CSG_Grid *pGrid = SG_Create_Grid(SG_DATATYPE_Int, Image.GetWidth(), Image.GetHeight(), Cellsize, r.m_rect.xMin, r.m_rect.yMin); for(int y=0, yy=pGrid->Get_NY()-1; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++, yy--) { for(int x=0; x<pGrid->Get_NX(); x++) { pGrid->Set_Value(x, y, SG_GET_RGB(Image.GetRed(x, yy), Image.GetGreen(x, yy), Image.GetBlue(x, yy))); } } //----------------------------------------- pGrid->Set_Name(Cap.m_Title); Parameters("MAP")->Set_Value(pGrid); DataObject_Set_Colors(pGrid, 100, SG_COLORS_BLACK_WHITE); CSG_Parameters Parms; if( DataObject_Get_Parameters(pGrid, Parms) && Parms("COLORS_TYPE") ) { Parms("COLORS_TYPE")->Set_Value(3); // Color Classification Type: RGB DataObject_Set_Parameters(pGrid, Parms); } bResult = true; } delete(pStream); } } return( bResult ); }
//--------------------------------------------------------- bool CPC_Cluster_Analysis::On_Execute(void) { int nCluster; long nElements; double SP; CSG_Parameters Parms; m_bUpdateView = false; //----------------------------------------------------- nCluster = Parameters("NCLUSTER")->asInt(); pInput = Parameters("PC_IN") ->asPointCloud(); pResult = Parameters("PC_OUT") ->asPointCloud(); if( SG_UI_Get_Window_Main() ) m_bUpdateView = Parameters("UPDATEVIEW")->asBool(); //------------------------------------------------- m_Features = (int *)Parameters("FIELDS")->asPointer(); m_nFeatures = Parameters("FIELDS")->asInt (); if( !m_Features || m_nFeatures <= 0 ) { Error_Set(_TL("no features in selection")); return( false ); } //----------------------------------------------------- pResult->Create(pInput); pResult->Set_Name(CSG_String::Format(SG_T("%s_cluster"), pInput->Get_Name())); pResult->Add_Field(SG_T("CLUSTER"), SG_DATATYPE_Int); DataObject_Update(pResult); pResult->Set_NoData_Value(-1.0); clustField = pResult->Get_Field_Count() - 1; //----------------------------------------------------- Process_Set_Text(_TL("Initializing ...")); for( int i=0; i<m_nFeatures; i++ ) vValues.push_back( std::vector<double>() ); for( int i=0; i<pInput->Get_Record_Count() && SG_UI_Process_Set_Progress(i, pInput->Get_Record_Count()); i++ ) { pResult->Add_Point(pInput->Get_X(i), pInput->Get_Y(i), pInput->Get_Z(i)); for( int j=0; j<pInput->Get_Attribute_Count(); j++ ) pResult->Set_Attribute(i, j, pInput->Get_Attribute(i, j)); pResult->Set_NoData(i, clustField); bool bNoData = false; for( int j=0; j<m_nFeatures; j++) { if( pInput->is_NoData(i, m_Features[j]) ) { bNoData = true; break; } } if( !bNoData ) { for( int j=0; j<m_nFeatures; j++ ) { if( Parameters("NORMALISE")->asBool() ) vValues.at(j).push_back( (pInput->Get_Value(i, m_Features[j]) - pInput->Get_Mean(m_Features[j])) / pInput->Get_StdDev(m_Features[j]) ); else vValues.at(j).push_back(pInput->Get_Value(i, m_Features[j])); } } else { for( int j=0; j<m_nFeatures; j++ ) { vValues.at(j).push_back(pInput->Get_NoData_Value()); } } } if( m_bUpdateView ) { if( DataObject_Get_Parameters(pResult, Parms) && Parms("COLORS_TYPE") && Parms("METRIC_ATTRIB") && Parms("METRIC_COLORS") && Parms("METRIC_ZRANGE") ) { Parms("COLORS_TYPE") ->Set_Value(2); // graduated color Parms("METRIC_COLORS")->asColors() ->Set_Count(nCluster); Parms("METRIC_ATTRIB") ->Set_Value(clustField); Parms("METRIC_ZRANGE")->asRange() ->Set_Range(0, nCluster); } DataObject_Set_Parameters(pResult, Parms); DataObject_Update(pResult, SG_UI_DATAOBJECT_SHOW_LAST_MAP); } nMembers = (int *)SG_Malloc(nCluster * sizeof(int)); Variances = (double *)SG_Malloc(nCluster * sizeof(double)); Centroids = (double **)SG_Malloc(nCluster * sizeof(double *)); for( int i=0; i<nCluster; i++ ) { Centroids[i] = (double *)SG_Malloc(m_nFeatures * sizeof(double)); } //------------------------------------------------- nElements = pInput->Get_Point_Count(); switch( Parameters("METHOD")->asInt() ) { case 0: SP = MinimumDistance (nElements, nCluster); break; case 1: SP = HillClimbing (nElements, nCluster); break; case 2: SP = MinimumDistance (nElements, nCluster); nElements = pInput->Get_Point_Count(); // may have been diminished because of no data values... SP = HillClimbing (nElements, nCluster); break; } //------------------------------------------------- if( Parameters("NORMALISE")->asBool() ) { int iv = 0; for( int i=0; i<m_nFeatures; i++ ) { for( int j=0; j<nCluster; j++ ) { Centroids[j][iv] = sqrt(pInput->Get_Variance(m_Features[i])) * Centroids[j][iv] + pInput->Get_Mean(m_Features[i]); } iv++; } } Write_Result(Parameters("STATISTICS")->asTable(), nElements, nCluster, SP); //------------------------------------------------- if( DataObject_Get_Parameters(pResult, Parms) && Parms("COLORS_TYPE") && Parms("LUT") && Parms("LUT_ATTRIB") ) { CSG_Table_Record *pClass; CSG_Table *pLUT = Parms("LUT")->asTable(); for( int i=0; i<nCluster; i++ ) { if( (pClass = pLUT->Get_Record(i)) == NULL ) { pClass = pLUT->Add_Record(); pClass->Set_Value(0, SG_GET_RGB(rand() * 255.0 / RAND_MAX, rand() * 255.0 / RAND_MAX, rand() * 255.0 / RAND_MAX)); } pClass->Set_Value(1, CSG_String::Format(SG_T("%s %d"), _TL("Class"), i)); pClass->Set_Value(2, CSG_String::Format(SG_T("%s %d"), _TL("Class"), i)); pClass->Set_Value(3, i); pClass->Set_Value(4, i); } while( pLUT->Get_Record_Count() > nCluster ) { pLUT->Del_Record(pLUT->Get_Record_Count() - 1); } Parms("COLORS_TYPE") ->Set_Value(1); // Color Classification Type: Lookup Table Parms("LUT_ATTRIB") ->Set_Value(clustField); DataObject_Set_Parameters(pResult, Parms); } //------------------------------------------------- for( int i=0; i<nCluster; i++ ) { SG_Free(Centroids[i]); } SG_Free(Centroids); SG_Free(Variances); SG_Free(nMembers); vValues.clear(); return( true ); }
//--------------------------------------------------------- bool CGeoref_Grid::Get_Conversion(void) { //----------------------------------------------------- CSG_Rect Extent; CSG_Grid *pSource = Parameters("GRID")->asGrid(); //----------------------------------------------------- if( !Get_Target_Extent(Extent, true) || !m_Grid_Target.Set_User_Defined(Get_Parameters("TARGET"), Extent, pSource->Get_NY()) ) { Error_Set(_TL("failed to estimate target extent")); return( false ); } if( !Dlg_Parameters("TARGET") ) { return( false ); } //----------------------------------------------------- TSG_Grid_Resampling Resampling; switch( Parameters("RESAMPLING")->asInt() ) { default: Resampling = GRID_RESAMPLING_NearestNeighbour; break; case 1: Resampling = GRID_RESAMPLING_Bilinear; break; case 2: Resampling = GRID_RESAMPLING_BicubicSpline; break; case 3: Resampling = GRID_RESAMPLING_BSpline; break; } CSG_Grid *pReferenced = m_Grid_Target.Get_Grid(Resampling == GRID_RESAMPLING_NearestNeighbour ? pSource->Get_Type() : SG_DATATYPE_Float); if( !pReferenced ) { Error_Set(_TL("failed to initialize target grid")); return( false ); } //----------------------------------------------------- if( !Set_Grid(pSource, pReferenced, Resampling) ) { Error_Set(_TL("failed to project target grid")); return( false ); } //----------------------------------------------------- CSG_Parameters P; if( DataObject_Get_Parameters(pSource, P) ) { DataObject_Add(pReferenced); DataObject_Set_Parameters(pReferenced, P); } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CPC_Merge::On_Execute(void) { CSG_PointCloud *pMain, *pAdd, *pResult; bool bID; int iStartValue; int iAccept = 0; CSG_Parameter_PointCloud_List *pPointCloudList; std::vector<CSG_String> FieldNames; std::vector<TSG_Data_Type> FieldTypes; pMain = Parameters("PC_IN")->asPointCloud(); pPointCloudList = Parameters("PC_LAYERS")->asPointCloudList(); pResult = Parameters("PC_OUT")->asPointCloud(); bID = Parameters("ADD_IDENTIFIER")->asBool(); iStartValue = Parameters("START_VALUE")->asInt(); pResult->Create(pMain); pResult->Set_Name(CSG_String::Format(_TL("%s_merged"), pMain->Get_Name())); if( bID ) pResult->Add_Field(SG_T("ID"), SG_DATATYPE_Int); DataObject_Update(pResult); //copy main layer into destination for(int iField=0; iField<pMain->Get_Attribute_Count(); iField++) { FieldNames.push_back(pMain->Get_Attribute_Name(iField)); FieldTypes.push_back(pMain->Get_Attribute_Type(iField)); } for(int i=0; i<pMain->Get_Count() && Set_Progress(i, pMain->Get_Count()); i++) { pResult->Add_Point(pMain->Get_X(i), pMain->Get_Y(i), pMain->Get_Z(i)); for(int iField=0; iField<pMain->Get_Attribute_Count(); iField++) { pResult->Set_Attribute(iAccept, iField, pMain->Get_Attribute(i, iField)); } if( bID ) pResult->Set_Attribute(iAccept, pMain->Get_Attribute_Count(), iStartValue); iAccept++; } //copy additional layer into destination if( (pPointCloudList = Parameters("PC_LAYERS")->asPointCloudList()) != NULL && pPointCloudList->Get_Count() > 0 ) { for(int iLayer=0; iLayer<pPointCloudList->Get_Count(); iLayer++) { if( (pAdd = pPointCloudList->asPointCloud(iLayer)) != NULL ) { if( pAdd->Get_Type() == pMain->Get_Type() ) { pAdd = pPointCloudList->asPointCloud(iLayer); std::vector<int> FieldMapping(FieldNames.size(), -1); // pMain to pAdd for(int iField=0; iField<pAdd->Get_Attribute_Count(); iField++) { CSG_String ThisField = pAdd->Get_Attribute_Name(iField); for(int j=0; j<FieldNames.size(); j++) { if( !ThisField.CmpNoCase(FieldNames[j]) ) { if( pAdd->Get_Attribute_Type(iField) == FieldTypes[j] ) { FieldMapping[j] = iField; break; } } } } for(int i=0; i<pAdd->Get_Count() && Set_Progress(i, pAdd->Get_Count()); i++) { pResult->Add_Point(pAdd->Get_X(i), pAdd->Get_Y(i), pAdd->Get_Z(i)); for(int iField=0; iField<pMain->Get_Attribute_Count(); iField++) { if( FieldMapping[iField] > -1 ) pResult->Set_Attribute(iAccept, iField, pAdd->Get_Attribute(i, FieldMapping[iField])); else pResult->Set_Attribute(iAccept, iField, pMain->Get_NoData_Value()); } if( bID ) { pResult->Set_Attribute(iAccept, pMain->Get_Attribute_Count(), iLayer + iStartValue + 1); } iAccept++; } } } } } CSG_Parameters sParms; DataObject_Get_Parameters(pResult, sParms); if( sParms("METRIC_ATTRIB") && sParms("COLORS_TYPE") && sParms("METRIC_COLORS") && sParms("METRIC_ZRANGE") && sParms("DISPLAY_VALUE_AGGREGATE") ) { sParms("DISPLAY_VALUE_AGGREGATE") ->Set_Value(3); sParms("COLORS_TYPE") ->Set_Value(2); sParms("METRIC_COLORS")->asColors() ->Set_Count(255); sParms("METRIC_ATTRIB") ->Set_Value(2); sParms("METRIC_ZRANGE")->asRange() ->Set_Range(pResult->Get_Minimum(2), pResult->Get_Maximum(2)); } DataObject_Set_Parameters(pResult, sParms); DataObject_Update(pResult); return( true ); }
//--------------------------------------------------------- bool CLAS_Import::On_Execute(void) { CSG_Parameter_PointCloud_List *pPointsList; bool bValidity; CSG_Strings Files; int RGBrange; int cntInvalid = 0; bValidity = Parameters("VALID")->asBool(); RGBrange = Parameters("RGB_RANGE")->asInt(); //----------------------------------------------------- if( !Parameters("FILES")->asFilePath()->Get_FilePaths(Files) ) { return( false ); } //----------------------------------------------------- pPointsList = Parameters("POINTS")->asPointCloudList(); pPointsList ->Del_Items(); for(int i=0; i<Files.Get_Count(); i++) { SG_UI_Msg_Add(CSG_String::Format(_TL("Parsing %s ... "), SG_File_Get_Name(Files[i], true).c_str()), true); std::ifstream ifs; ifs.open(Files[i].b_str(), std::ios::in | std::ios::binary); if( !ifs ) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Unable to open LAS file!"))); continue; } //----------------------------------------------------- // Check if LAS version is supported liblas::LASReader *pReader; try { pReader = new liblas::LASReader(ifs); } catch(std::exception &e) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("LAS header exception: %s"), e.what())); ifs.close(); return( false ); } catch(...) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Unknown LAS header exception!"))); ifs.close(); return( false ); } delete (pReader); ifs.clear(); //----------------------------------------------------- liblas::LASReader reader(ifs); liblas::LASHeader const& header = reader.GetHeader(); //----------------------------------------------------- int nFields, iField[VAR_Count]; CSG_PointCloud *pPoints = SG_Create_PointCloud(); pPoints->Set_Name(SG_File_Get_Name(Files[i], false)); nFields = 3; ADD_FIELD("T", VAR_T, _TL("gps-time") , SG_DATATYPE_Double); // SG_DATATYPE_Long ADD_FIELD("i", VAR_i, _TL("intensity") , SG_DATATYPE_Float); // SG_DATATYPE_Word ADD_FIELD("a", VAR_a, _TL("scan angle") , SG_DATATYPE_Float); // SG_DATATYPE_Byte ADD_FIELD("r", VAR_r, _TL("number of the return") , SG_DATATYPE_Int); ADD_FIELD("c", VAR_c, _TL("classification") , SG_DATATYPE_Int); // SG_DATATYPE_Byte ADD_FIELD("u", VAR_u, _TL("user data") , SG_DATATYPE_Double); // SG_DATATYPE_Byte ADD_FIELD("n", VAR_n, _TL("number of returns of given pulse") , SG_DATATYPE_Int); ADD_FIELD("R", VAR_R, _TL("red channel color") , SG_DATATYPE_Int); // SG_DATATYPE_Word ADD_FIELD("G", VAR_G, _TL("green channel color") , SG_DATATYPE_Int); ADD_FIELD("B", VAR_B, _TL("blue channel color") , SG_DATATYPE_Int); ADD_FIELD("e", VAR_e, _TL("edge of flight line flag") , SG_DATATYPE_Char); ADD_FIELD("d", VAR_d, _TL("direction of scan flag") , SG_DATATYPE_Char); ADD_FIELD("p", VAR_p, _TL("point source ID") , SG_DATATYPE_Int); // SG_DATATYPE_Word ADD_FIELD("C", VAR_C, _TL("rgb color") , SG_DATATYPE_Int); //----------------------------------------------------- int iPoint = 0; try { while( reader.ReadNextPoint() ) { if (iPoint % 100000) SG_UI_Process_Set_Progress(iPoint, header.GetPointRecordsCount()); liblas::LASPoint const& point = reader.GetPoint(); if( bValidity ) { if( !point.IsValid() ) { cntInvalid++; continue; } } pPoints->Add_Point(point.GetX(), point.GetY(), point.GetZ()); if( iField[VAR_T] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_T], point.GetTime()); if( iField[VAR_i] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_i], point.GetIntensity()); if( iField[VAR_a] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_a], point.GetScanAngleRank()); if( iField[VAR_r] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_r], point.GetReturnNumber()); if( iField[VAR_c] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_c], point.GetClassification()); if( iField[VAR_u] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_u], point.GetUserData()); if( iField[VAR_n] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_n], point.GetNumberOfReturns()); if( iField[VAR_R] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_R], point.GetColor().GetRed()); if( iField[VAR_G] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_G], point.GetColor().GetGreen()); if( iField[VAR_B] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_B], point.GetColor().GetBlue()); if( iField[VAR_e] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_e], point.GetFlightLineEdge()); if( iField[VAR_d] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_d], point.GetScanDirection()); if( iField[VAR_p] > 0 ) pPoints->Set_Value(iPoint, iField[VAR_p], point.GetPointSourceID()); if( iField[VAR_C] > 0 ) { double r, g, b; r = point.GetColor().GetRed(); g = point.GetColor().GetGreen(); b = point.GetColor().GetBlue(); if (RGBrange == 0) // 16 bit { r = r / 65535 * 255; g = g / 65535 * 255; b = b / 65535 * 255; } pPoints->Set_Value(iPoint, iField[VAR_C], SG_GET_RGB(r, g, b)); } iPoint++; } } catch(std::exception &e) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("LAS reader exception: %s"), e.what())); ifs.close(); return( false ); } catch(...) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Unknown LAS reader exception!"))); ifs.close(); return( false ); } ifs.close(); pPointsList->Add_Item(pPoints); DataObject_Add(pPoints); //----------------------------------------------------- CSG_Parameters sParms; DataObject_Get_Parameters(pPoints, sParms); if (sParms("METRIC_ATTRIB") && sParms("COLORS_TYPE") && sParms("METRIC_COLORS") && sParms("METRIC_ZRANGE") && sParms("DISPLAY_VALUE_AGGREGATE")) { sParms("DISPLAY_VALUE_AGGREGATE")->Set_Value(3); // highest z sParms("COLORS_TYPE")->Set_Value(2); // graduated color sParms("METRIC_COLORS")->asColors()->Set_Count(255); // number of colors sParms("METRIC_ATTRIB")->Set_Value(2); // z attrib sParms("METRIC_ZRANGE")->asRange()->Set_Range(pPoints->Get_Minimum(2),pPoints->Get_Maximum(2)); } DataObject_Set_Parameters(pPoints, sParms); SG_UI_Msg_Add(_TL("okay"), false); } //----------------------------------------------------- if( bValidity && cntInvalid > 0 ) SG_UI_Msg_Add(CSG_String::Format(_TL("WARNING: %d invalid points skipped!"), cntInvalid), true); return( true ); }
//--------------------------------------------------------- bool CSoil_Texture::On_Execute(void) { CSG_Grid *pSand, *pSilt, *pClay, *pTexture, *pSum; //----------------------------------------------------- pSand = Parameters("SAND") ->asGrid(); pSilt = Parameters("SILT") ->asGrid(); pClay = Parameters("CLAY") ->asGrid(); pTexture = Parameters("TEXTURE") ->asGrid(); pSum = Parameters("SUM") ->asGrid(); //----------------------------------------------------- if( (pSand ? 1 : 0) + (pSilt ? 1 : 0) + (pClay ? 1 : 0) < 2 ) { Error_Set(_TL("at least two contents (sand, silt, clay) have to be given")); return( false ); } //----------------------------------------------------- pTexture->Set_NoData_Value(0.0); CSG_Parameters P; if( DataObject_Get_Parameters(pTexture, P) && P("COLORS_TYPE") && P("LUT") ) { CSG_Table *pLUT = P("LUT")->asTable(); for(int iClass=0; iClass<12; iClass++) { CSG_Table_Record *pClass; if( (pClass = pLUT->Get_Record(iClass)) == NULL ) { pClass = pLUT->Add_Record(); } pClass->Set_Value(0, Classes[iClass].Color); pClass->Set_Value(1, Classes[iClass].Name); pClass->Set_Value(2, Classes[iClass].Name); pClass->Set_Value(3, Classes[iClass].ID); pClass->Set_Value(4, Classes[iClass].ID); } while( pLUT->Get_Record_Count() > 12 ) { pLUT->Del_Record(pLUT->Get_Record_Count() - 1); } P("COLORS_TYPE")->Set_Value(1); // Color Classification Type: Lookup Table DataObject_Set_Parameters(pTexture, P); } //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { int Texture = 0; double Sum = 0.0; if( !(pSand && pSand->is_NoData(x, y)) && !(pSilt && pSilt->is_NoData(x, y)) && !(pClay && pClay->is_NoData(x, y)) ) { double Sand = pSand ? pSand->asDouble(x, y) : 100.0 - (pSilt->asDouble(x, y) + pClay->asDouble(x, y)); double Silt = pSilt ? pSilt->asDouble(x, y) : 100.0 - (pSand->asDouble(x, y) + pClay->asDouble(x, y)); double Clay = pClay ? pClay->asDouble(x, y) : 100.0 - (pSand->asDouble(x, y) + pSilt->asDouble(x, y)); if( (Sum = Sand + Silt + Clay) > 0.0 ) { if( Sum != 100.0 ) { Sand *= 100.0 / Sum; Clay *= 100.0 / Sum; } Texture = Get_Texture(Sand, Clay); } } if( Texture ) { pTexture->Set_Value(x, y, Texture); if( pSum ) { pSum->Set_Value(x, y, Sum); } } else { pTexture->Set_NoData(x, y); if( pSum ) { pSum->Set_NoData(x, y); } } } } //----------------------------------------------------- return( true ); }
bool CSHALSTAB::On_Execute(void) { double fCmin = Parameters("fCmin")->asDouble(); double fDmin = Parameters("fDmin")->asDouble(); double fEmin = Parameters("fEmin")->asDouble(); double fFmin = Parameters("fFmin")->asDouble(); double fJmin = Parameters("fJmin")->asDouble(); double fCmax = Parameters("fCmax")->asDouble(); double fDmax = Parameters("fDmax")->asDouble(); double fEmax = Parameters("fEmax")->asDouble(); double fFmax = Parameters("fFmax")->asDouble(); double fJmax = Parameters("fJmax")->asDouble(); double fK = Parameters("fK")->asInt(); double grav = 9.81; CSG_Grid *pA, *pB, *pCmin, *pDmin, *pEmin, *pFmin, *pG, *pH, *pJmin, *pCmax, *pDmax, *pEmax, *pFmax, *pJmax; pA = Parameters("A" )->asGrid(); //slope pB = Parameters("B" )->asGrid(); //flow accumulation pCmin = Parameters("Cmin" )->asGrid(); //density pDmin = Parameters("Dmin" )->asGrid(); //conductivity pEmin = Parameters("Emin" )->asGrid(); //depth pFmin = Parameters("Fmin" )->asGrid(); //friction pCmax = Parameters("Cmax" )->asGrid(); //density pDmax = Parameters("Dmax" )->asGrid(); //conductivity pEmax = Parameters("Emax" )->asGrid(); //depth pFmax = Parameters("Fmax" )->asGrid(); //friction pG = Parameters("G" )->asGrid(); //output critical recharge pH = Parameters("H" )->asGrid(); //optional output classified grid pJmin = Parameters("Jmin" )->asGrid(); //bulk cohesion pJmax = Parameters("Jmax" )->asGrid(); //bulk cohesion for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { double a, b, c, d, e, f, g, j, l; double cmin, dmin, emin, fmin, jmin; double cmax, dmax, emax, fmax, jmax; double cc, dd, ee, ff, jj; int cperc, dperc, eperc, fperc, jperc; int rand_int, k, n; a = pA->asDouble(x, y); b = pB->asDouble(x, y); //Abfrage ob Raster oder Globalwerte: cmin = pCmin ? pCmin->asDouble(x, y) : fCmin; dmin = pDmin ? pDmin->asDouble(x, y) : fDmin; emin = pEmin ? pEmin->asDouble(x, y) : fEmin; fmin = pFmin ? pFmin->asDouble(x, y) : fFmin; jmin = pJmin ? pJmin->asDouble(x, y) : fJmin; cmax = pCmax ? pCmax->asDouble(x, y) : fCmax; dmax = pDmax ? pDmax->asDouble(x, y) : fDmax; emax = pEmax ? pEmax->asDouble(x, y) : fEmax; fmax = pFmax ? pFmax->asDouble(x, y) : fFmax; jmax = pJmax ? pJmax->asDouble(x, y) : fJmax; k = fK; if (pA->is_NoData(x, y) || pB->is_NoData(x, y)) { pG->Set_NoData(x, y); if (pH) pH->Set_Value(x, y, CR_NODATA); } else if ((pCmin || pCmax || pDmin || pDmax || pEmin || pEmax || pFmin || pFmax || pJmin || pJmax) && (pCmin && pCmax->is_NoData(x, y) || pDmin && pDmax->is_NoData(x, y) || pEmin && pEmax->is_NoData(x, y) || pFmin && pFmax->is_NoData(x, y) || pJmin && pJmax->is_NoData(x, y))) { pG->Set_NoData(x, y); if (pH) pH->Set_Value(x, y, CR_NODATA); } else { cperc = ((cmax - cmin) / cmax) * 100; //calculate parameter range %: density if (cperc > 0) { n = 0; cc = 0; while ( n < k) //loop through specified random number iterations: { rand_int = rand() % cperc + 0; //calculate random percentage c = ((cmax/100) * rand_int) + cmin; //calculate value cc = cc + c; //sum n = n + 1; } c = cc / n; // calculate mean from random values } else { c = cmax; } dperc = ((dmax - dmin) / dmax) * 100; if (dperc > 0) { n = 0; dd = 0; while ( n < k) { rand_int = rand() % dperc + 0; d = ((dmax/100) * rand_int) + dmin; dd = dd + d; n = n + 1; } d = dd / n; } else { d = dmax; } eperc = ((emax - emin) / emax) * 100; if (eperc > 0) { n = 0; ee = 0; while ( n < k) { rand_int = rand() % eperc + 0; e = ((emax/100) * rand_int) + emin; ee = ee + e; n = n + 1; } e = ee / n; } else { e = emax; } fperc = ((fmax - fmin) / fmax) * 100; if (fperc > 0) { n = 0; ff = 0; while ( n < k) { rand_int = rand() % fperc + 0; f = ((fmax/100) * rand_int) + fmin; ff = ff + f; n = n + 1; } f = ff / n; } else { f = fmax; } jperc = ((jmax - jmin) / jmax) * 100; if (jperc > 0) { n = 0; jj = 0; while ( n < k) { rand_int = rand() % jperc + 0; j = ((jmax/100) * rand_int) + jmin; jj = jj + j; n = n + 1; } j = jj / n; } else { j = jmax; } l = j/((e/cos(a))*c*grav); //calculate dimensionless cohesion //g = ((((sin(a) * (d*24*e)) * c)/(b/pB->Get_Cellsize())) * (1-(tan(a)/tan(f/57.2958)))) *1000; //cohesionless SHALSTAB calculation g = ((((sin(a) * (d*24*e)) * c)/(b/pB->Get_Cellsize())) * (1-((sin(a) - l)/(cos(a)*tan(f/57.2958))))) *1000; //SHALSTAB calculation //if ((tan(a) > (tan(f/57.2958) * (1-(1/c))))) //general stability criterion if (tan(a) > ((tan(f/57.2958) * (1-(1/c)))+(j/cos(a)))) { if (g > 0) //critical recharge pG->Set_Value(x, y, g); else pG->Set_Value(x, y, 0); //unconditionally unstable = 0 } //else if (tan(a) <= (tan(f/57.2958) * (1-(1/c)))) else if (tan(a) <= ((tan(f/57.2958) * (1-(1/c)))+(l/cos(a)))) { pG->Set_NoData(x, y); //unconditionally stable = nodata } if (pH) //calculate optional classified grid { //if ((tan(a) > (tan(f/57.2958) * (1-(1/c))))) if (tan(a) > ((tan(f/57.2958) * (1-(1/c)))+(l/cos(a)))) { if (g <= 0) pH->Set_Value(x, y, CR_UNSTABLE); else if ((g > 0) && (g <= 50)) pH->Set_Value(x, y, CR_0_TO_50); else if ((g > 50) && (g <= 100)) pH->Set_Value(x, y, CR_50_TO_100); else if ((g > 100) && (g <= 200)) pH->Set_Value(x, y, CR_100_TO_200); else if ((g > 200) && (g <= 400)) pH->Set_Value(x, y, CR_200_TO_400); else if (g > 400) pH->Set_Value(x, y, CR_GR_400); } //else if (tan(a) <= (tan(f/57.2958) * (1-(1/c)))) else if (tan(a) <= ((tan(f/57.2958) * (1-(1/c)))+(l/cos(a)))) { pH->Set_Value(x, y, CR_STABLE); } } } } } //----------------------------------------------------- CSG_Parameters P; if( DataObject_Get_Parameters(pH, P) && P("COLORS_TYPE") && P("LUT") ) { int CR_Colors[CR_COUNT] = { SG_GET_RGB(255, 255, 255), // CR_NODATA SG_GET_RGB(255, 0, 0), // CR_UNSTAB SG_GET_RGB(255, 128, 64), // CR_0-50 SG_GET_RGB(255, 255, 0), // CR_50-100 SG_GET_RGB( 0, 255, 0), // CR_100-200 SG_GET_RGB(128, 255, 255), // CR_200-400 SG_GET_RGB( 0, 0, 255), // CR_>400 SG_GET_RGB(128, 128, 128), // CR_STABLE }; //------------------------------------------------- CSG_Strings Name, Desc; Name += _TL("No data"); Desc += _TL(""); Name += _TL("Uncond. unstable"); Desc += _TL(""); Name += _TL("0-50 mm/day"); Desc += _TL(""); Name += _TL("50-100 mm/day"); Desc += _TL(""); Name += _TL("100-200 mm/day"); Desc += _TL(""); Name += _TL("200-400 mm/day"); Desc += _TL(""); Name += _TL(">400 mm/day"); Desc += _TL(""); Name += _TL("Uncond. stable"); Desc += _TL(""); //------------------------------------------------- CSG_Table *pTable = P("LUT")->asTable(); pTable->Del_Records(); for(int i=0; i<CR_COUNT; i++) { CSG_Table_Record *pRecord = pTable->Add_Record(); pRecord->Set_Value(0, CR_Colors[i]); pRecord->Set_Value(1, Name[i].c_str()); pRecord->Set_Value(2, Desc[i].c_str()); pRecord->Set_Value(3, i); pRecord->Set_Value(4, i); } P("COLORS_TYPE")->Set_Value(1); // Color Classification Type: Lookup Table DataObject_Set_Parameters(pH, P); } return( true ); }
//--------------------------------------------------------- bool CCRS_Transform_Grid::Transform(CSG_Parameter_Grid_List *pSources, CSG_Parameter_Grid_List *pTargets, const CSG_Grid_System &Target_System) { if( !m_Projector.Set_Inverse(true) || !pTargets || !pSources || pSources->Get_Count() < 1 ) { return( false ); } //----------------------------------------------------- CSG_Grid *pX, *pY; if( (pX = m_Grid_Target.Get_Grid("OUT_X")) != NULL ) { pX->Assign_NoData(); pX->Set_Name(_TL("X Coordinates")); pX->Get_Projection().Create(m_Projector.Get_Target()); } if( (pY = m_Grid_Target.Get_Grid("OUT_Y")) != NULL ) { pY->Assign_NoData(); pY->Set_Name(_TL("Y Coordinates")); pY->Get_Projection().Create(m_Projector.Get_Target()); } //----------------------------------------------------- bool bGeogCS_Adjust = m_Projector.Get_Source().Get_Type() == SG_PROJ_TYPE_CS_Geographic && pSources->asGrid(0)->Get_System().Get_XMax() > 180.0; Set_Target_Area(pSources->asGrid(0)->Get_System(), Target_System); bool bKeepType = m_Resampling == GRID_RESAMPLING_NearestNeighbour || Parameters("KEEP_TYPE")->asBool(); //----------------------------------------------------- int i, n = pTargets->Get_Count(); for(i=0; i<pSources->Get_Count(); i++) { CSG_Grid *pSource = pSources->asGrid(i); CSG_Grid *pTarget = SG_Create_Grid(Target_System, bKeepType ? pSource->Get_Type() : SG_DATATYPE_Float); if( pTarget ) { pTargets->Add_Item(pTarget); pTarget->Set_NoData_Value_Range (pSource->Get_NoData_Value(), pSource->Get_NoData_hiValue()); pTarget->Set_Scaling (pSource->Get_Scaling(), pSource->Get_Offset()); pTarget->Set_Name (pSource->Get_Name()); pTarget->Set_Unit (pSource->Get_Unit()); pTarget->Get_Projection().Create(m_Projector.Get_Target()); pTarget->Assign_NoData(); CSG_Parameters Parms; if( DataObject_Get_Parameters(pSource, Parms) ) { DataObject_Add(pTarget); DataObject_Set_Parameters(pTarget, Parms); } } } //------------------------------------------------- for(int y=0; y<Target_System.Get_NY() && Set_Progress(y, Target_System.Get_NY()); y++) { double yTarget = Target_System.Get_YMin() + y * Target_System.Get_Cellsize(); // #pragma omp parallel for private(i) for(int x=0; x<Target_System.Get_NX(); x++) { double z, ySource, xSource = Target_System.Get_XMin() + x * Target_System.Get_Cellsize(); if( is_In_Target_Area(x, y) && m_Projector.Get_Projection(xSource, ySource = yTarget) ) { if( bGeogCS_Adjust ) { if( xSource < 0.0 ) { xSource += 360.0; } else if( xSource >= 360.0 ) { xSource -= 360.0; } } if( pX ) pX->Set_Value(x, y, xSource); if( pY ) pY->Set_Value(x, y, ySource); for(i=0; i<pSources->Get_Count(); i++) { if( pSources->asGrid(i)->Get_Value(xSource, ySource, z, m_Resampling, false, true) ) { pTargets->asGrid(n + i)->Set_Value(x, y, z); } } } } } //----------------------------------------------------- m_Target_Area.Destroy(); return( true ); }
//--------------------------------------------------------- bool CGrid_Aspect_Slope_Map::On_Execute(void) { CSG_Grid *pAspect, *pSlope, *pAspectSlope; CSG_Table *pLUT; int iAspectCount = 9; static const double AspectBreaks[] = {0.000, 0.393, 1.178, 1.963, 2.749, 3.534, 4.320, 5.105, 5.890, 6.283}; static const int AspectClass[] = {1, 2, 3, 4, 5, 6, 7, 8, 1}; int iSlopeCount = 4; static const double SlopeBreaks[] = {0.000, 0.087, 0.349, 0.698, 1.571}; static const int SlopeClass[] = {10, 20, 30, 40}; pAspect = Parameters("ASPECT")->asGrid(); pSlope = Parameters("SLOPE")->asGrid(); pAspectSlope = Parameters("ASPECT_SLOPE")->asGrid(); pLUT = Parameters("LUT")->asTable(); //----------------------------------------------------- if( pLUT == NULL ) pLUT = new CSG_Table(); else pLUT->Destroy(); pLUT->Set_Name(SG_T("LUT_Aspect-Slope")); pLUT->Add_Field(SG_T("COLOR"), SG_DATATYPE_Int); pLUT->Add_Field(SG_T("NAME"), SG_DATATYPE_String); pLUT->Add_Field(SG_T("DESCRIPTION"), SG_DATATYPE_String); pLUT->Add_Field(SG_T("MINIMUM"), SG_DATATYPE_Int); pLUT->Add_Field(SG_T("MAXIMUM"), SG_DATATYPE_Int); for(int i=0; i<25; i++) { CSG_Table_Record *pRecord = pLUT->Add_Record(); pRecord->Set_Value(0, LUT_COLOR[i]); pRecord->Set_Value(1, LUT_NAME[i]); pRecord->Set_Value(2, SG_T("")); pRecord->Set_Value(3, LUT_BREAK[i]); pRecord->Set_Value(4, LUT_BREAK[i+1]); } //----------------------------------------------------- #pragma omp parallel for for(sLong n=0; n<Get_NCells(); n++) { int iAspectClass, iSlopeClass; if( pAspect->is_NoData(n) || pSlope->is_NoData(n) ) { pAspectSlope->Set_NoData(n); } else { iAspectClass = Get_Class(pAspect->asDouble(n), iAspectCount, AspectBreaks, AspectClass); iSlopeClass = Get_Class(pSlope->asDouble(n), iSlopeCount, SlopeBreaks, SlopeClass); pAspectSlope->Set_Value(n, iAspectClass + iSlopeClass); } } //----------------------------------------------------- CSG_Parameters Parms; if( DataObject_Get_Parameters(pAspectSlope, Parms) && Parms("COLORS_TYPE") && Parms("LUT") ) { Parms("LUT")->asTable()->Assign(pLUT); Parms("COLORS_TYPE")->Set_Value(1); DataObject_Set_Parameters(pAspectSlope, Parms); } if( Parameters("LUT")->asTable() == NULL ) { delete pLUT; } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CPC_Reclass_Extract::On_Execute(void) { int method; CSG_Parameters sParms; m_pInput = Parameters("INPUT")->asPointCloud(); m_pResult = Parameters("RESULT")->asPointCloud(); method = Parameters("METHOD")->asInt(); m_AttrField = Parameters("ATTRIB")->asInt(); m_bExtract = Parameters("MODE")->asInt() == 0 ? false : true; m_bCreateAttrib = Parameters("CREATE_ATTRIB")->asBool(); m_pResult->Create(m_pInput); if (m_bExtract) m_pResult->Set_Name(CSG_String::Format(SG_T("%s_subset_%s"), m_pInput->Get_Name(), m_pInput->Get_Field_Name(m_AttrField))); else { m_pResult->Set_Name(CSG_String::Format(SG_T("%s_reclass_%s"), m_pInput->Get_Name(), m_pInput->Get_Field_Name(m_AttrField))); if( m_bCreateAttrib ) m_pResult->Add_Field(CSG_String::Format(SG_T("%s_reclass"), m_pInput->Get_Field_Name(m_AttrField)), m_pInput->Get_Field_Type(m_AttrField)); } m_iOrig = 0; // counter of unchanged points //----------------------------------------------------- switch( method ) { case 0: Reclass_Single(); break; case 1: Reclass_Range(); break; case 2: if( Reclass_Table(false) ) break; else return( false ); case 3: if( Reclass_Table(true) ) break; else return( false ); default: break; } //----------------------------------------------------- DataObject_Update(m_pResult); DataObject_Get_Parameters(m_pResult, sParms); if (m_bExtract) Set_Display_Attributes(m_pResult, 2, sParms); else { if( m_bCreateAttrib ) Set_Display_Attributes(m_pResult, m_pResult->Get_Field_Count()-1, sParms); else Set_Display_Attributes(m_pResult, m_AttrField, sParms); } if( m_bExtract) SG_UI_Msg_Add(CSG_String::Format(_TL("%d points out of %d extracted."), m_pInput->Get_Point_Count()-m_iOrig, m_pInput->Get_Point_Count()), true); else SG_UI_Msg_Add(CSG_String::Format(_TL("%d points out of %d reclassified."), m_pInput->Get_Point_Count()-m_iOrig, m_pInput->Get_Point_Count()), true); return( true ); }
//--------------------------------------------------------- bool CSoil_Texture::On_Execute(void) { int x,y,intSoilType, MaxX, MaxY; float Sand_Input,Clay_Input; CSG_Grid *pSandInput, *pClayInput, *pOutTexture; pSandInput = Parameters("SAND")->asGrid(); pClayInput = Parameters("CLAY")->asGrid(); pOutTexture = Parameters("TEXTURE")->asGrid(); if(pSandInput->Get_NX()==pClayInput->Get_NX() && pSandInput->Get_NY()==pSandInput->Get_NY() ) { MaxX= pSandInput->Get_NX(); MaxY= pSandInput->Get_NY(); } else { MaxX= 0; MaxY= 0; } for(y=0;y<MaxY;y++) { for(x=0;x<MaxX;x++) { Sand_Input = pSandInput->asFloat(x, y); Clay_Input = pClayInput->asFloat(x, y); intSoilType = OutTexture(Sand_Input, Clay_Input); if (intSoilType<0 || intSoilType>12)//verify range validity pOutTexture->Set_NoData(x, y); else pOutTexture->Set_Value(x, y, intSoilType); } } //------------------------------------------------- if( 1 ) { CSG_Parameters Parms; if( DataObject_Get_Parameters(pOutTexture, Parms) && Parms("COLORS_TYPE") && Parms("LUT") ) { CSG_Table *pLUT = Parms("LUT")->asTable(); for(int iClass=0; iClass<12; iClass++) { CSG_Table_Record *pClass; if( (pClass = pLUT->Get_Record(iClass)) == NULL ) { pClass = pLUT->Add_Record(); } pClass->Set_Value(0, TEXTURE_COLOR[iClass]); pClass->Set_Value(1, TEXTURE_NAMES[iClass]); pClass->Set_Value(2, TEXTURE_NAMES[iClass]); pClass->Set_Value(3, iClass + 1); pClass->Set_Value(4, iClass + 1); } while( pLUT->Get_Record_Count() > 12 ) { pLUT->Del_Record(pLUT->Get_Record_Count() - 1); } Parms("COLORS_TYPE")->Set_Value(1); // Color Classification Type: Lookup Table DataObject_Set_Parameters(pOutTexture, Parms); } } //------------------------------------------------- Message_Add(_TL("Hello by G. Massei")); return( true ); }