//--------------------------------------------------------- void CGrid_Cluster_Analysis::Save_LUT(CSG_Grid *pCluster) { CSG_Parameter *pLUT = DataObject_Get_Parameter(pCluster, "LUT"); if( pLUT && pLUT->asTable() ) { CSG_Parameter_Grid_List *pGrids = Parameters("GRIDS")->asGridList(); CSG_Table &Statistics = *Parameters("STATISTICS")->asTable(); bool bRGB = pGrids->Get_Count() >= 3 && Parameters("RGB_COLORS")->asBool(); for(int iCluster=0; iCluster<Statistics.Get_Count(); iCluster++) { CSG_Table_Record *pClass = pLUT->asTable()->Get_Record(iCluster); if( !pClass ) { (pClass = pLUT->asTable()->Add_Record())->Set_Value(0, SG_Color_Get_Random()); } pClass->Set_Value(1, CSG_String::Format("%s %d", _TL("Cluster"), iCluster + 1)); pClass->Set_Value(2, ""); pClass->Set_Value(3, iCluster + 1); pClass->Set_Value(4, iCluster + 1); if( bRGB ) { #define SET_COLOR_COMPONENT(c, i) c = (int)(127 + (Statistics[iCluster].asDouble(3 + i) - pGrids->asGrid(i)->Get_Mean()) * 127 / pGrids->asGrid(i)->Get_StdDev()); if( c < 0 ) c = 0; else if( c > 255 ) c = 255; int r; SET_COLOR_COMPONENT(r, 2); int g; SET_COLOR_COMPONENT(g, 1); int b; SET_COLOR_COMPONENT(b, 0); pClass->Set_Value(0, SG_GET_RGB(r, g, b)); } } pLUT->asTable()->Set_Record_Count(Statistics.Get_Count()); DataObject_Set_Parameter(pCluster, pLUT); DataObject_Set_Parameter(pCluster, "COLORS_TYPE", 1); // Color Classification Type: Lookup Table } }
//--------------------------------------------------------- bool CGrid_Classify_Supervised::Set_Classification(CSG_Classifier_Supervised &Classifier) { //----------------------------------------------------- CSG_Grid *pClasses = Parameters("CLASSES")->asGrid(); //----------------------------------------------------- CSG_Parameter *pLUT = DataObject_Get_Parameter(pClasses, "LUT"); if( pLUT && pLUT->asTable() ) { CSG_Parameter_Grid_List *pGrids = Parameters("GRIDS")->asGridList(); bool bRGB = pGrids->Get_Count() >= 3 && Parameters("RGB_COLORS")->asBool(); for(int iClass=0; iClass<Classifier.Get_Class_Count(); iClass++) { CSG_Table_Record *pClass = pLUT->asTable()->Get_Record(iClass); if( !pClass ) { (pClass = pLUT->asTable()->Add_Record())->Set_Value(0, SG_Color_Get_Random()); } pClass->Set_Value(1, Classifier.Get_Class_ID(iClass).c_str()); pClass->Set_Value(2, ""); pClass->Set_Value(3, iClass + 1); pClass->Set_Value(4, iClass + 1); if( bRGB ) { #define SET_COLOR_COMPONENT(c, i) c = (int)(127 + (Classifier.Get_Class_Mean(iClass, i) - pGrids->asGrid(i)->Get_Mean()) * 127 / pGrids->asGrid(i)->Get_StdDev()); if( c < 0 ) c = 0; else if( c > 255 ) c = 255; int r; SET_COLOR_COMPONENT(r, 2); int g; SET_COLOR_COMPONENT(g, 1); int b; SET_COLOR_COMPONENT(b, 0); pClass->Set_Value(0, SG_GET_RGB(r, g, b)); } } pLUT->asTable()->Set_Record_Count(Classifier.Get_Class_Count()); DataObject_Set_Parameter(pClasses, pLUT); DataObject_Set_Parameter(pClasses, "COLORS_TYPE", 1); // Color Classification Type: Lookup Table } pClasses->Set_Name(CSG_String::Format("%s [%s]", _TL("Classification"), CSG_Classifier_Supervised::Get_Name_of_Method(Parameters("METHOD")->asInt()).c_str())); //----------------------------------------------------- CSG_Grid *pQuality = Parameters("QUALITY")->asGrid(); if( pQuality ) { DataObject_Set_Colors(pQuality, 11, SG_COLORS_YELLOW_GREEN); pQuality->Set_Name(CSG_String::Format("%s [%s]", _TL("Classification Quality"), CSG_Classifier_Supervised::Get_Name_of_Quality(Parameters("METHOD")->asInt()).c_str())); } //----------------------------------------------------- return( true ); }