//--------------------------------------------------------- bool CSTL_Export::On_Execute(void) { bool bBinary; int zField; float v[3]; CSG_String File; CSG_File Stream; CSG_TIN *pTIN; pTIN = Parameters("TIN") ->asTIN(); File = Parameters("FILE") ->asString(); zField = Parameters("ZFIELD") ->asInt(); bBinary = Parameters("BINARY") ->asInt() == 1; if( !Stream.Open(File, SG_FILE_W, bBinary) ) { return( false ); } //----------------------------------------------------- if( bBinary ) { char *sHeader = (char *)SG_Calloc(80, sizeof(char)); DWORD nFacets = pTIN->Get_Triangle_Count(); WORD nBytes = 0; Stream.Write(sHeader , sizeof(char), 80); Stream.Write(&nFacets, sizeof(DWORD)); SG_Free(sHeader); //------------------------------------------------- for(int iTriangle=0; iTriangle<pTIN->Get_Triangle_Count(); iTriangle++) { CSG_TIN_Triangle *pTriangle = pTIN->Get_Triangle(iTriangle); Get_Normal(pTriangle, zField, v); Stream.Write(v, sizeof(float), 3); // facet normal for(int iNode=0; iNode<3; iNode++) { CSG_TIN_Node *pNode = pTriangle->Get_Node(iNode); v[0] = (float)pNode->Get_X(); v[1] = (float)pNode->Get_Y(); v[2] = (float)pNode->asDouble(zField); Stream.Write(v, sizeof(float), 3); } Stream.Write(&nBytes, sizeof(WORD)); } } //----------------------------------------------------- else // ASCII { Stream.Printf(SG_T("solid %s\n"), SG_File_Get_Name(File, false).c_str()); for(int iTriangle=0; iTriangle<pTIN->Get_Triangle_Count(); iTriangle++) { CSG_TIN_Triangle *pTriangle = pTIN->Get_Triangle(iTriangle); Get_Normal(pTriangle, zField, v); Stream.Printf(SG_T(" facet normal %.4f %.4f %.4f\n"), v[0], v[1], v[2]); Stream.Printf(SG_T(" outer loop\n")); for(int iNode=0; iNode<3; iNode++) { CSG_TIN_Node *pNode = pTriangle->Get_Node(iNode); v[0] = (float)pNode->Get_X(); v[1] = (float)pNode->Get_Y(); v[2] = (float)pNode->asDouble(zField); Stream.Printf(SG_T(" vertex %.4f %.4f %.4f\n"), v[0], v[1], v[2]); } Stream.Printf(SG_T(" endloop\n")); Stream.Printf(SG_T(" endfacet\n")); } Stream.Printf(SG_T("endsolid %s\n"), SG_File_Get_Name(File, false).c_str()); } return( true ); }
//--------------------------------------------------------- bool CParam_Scale::On_Execute(void) { //----------------------------------------------------- bool bConstrain; int Index[6]; double zScale, Tol_Slope, Tol_Curve; CSG_Matrix Normal; //----------------------------------------------------- bConstrain = Parameters("CONSTRAIN")->asBool(); zScale = Parameters("ZSCALE" )->asDouble(); if( zScale <= 0.0 ) { zScale = 1.0; } Tol_Slope = Parameters("TOL_SLOPE")->asDouble(); Tol_Curve = Parameters("TOL_CURVE")->asDouble(); m_pDEM = Parameters("DEM" )->asGrid(); //----------------------------------------------------- CSG_Grid *pFeature = Parameters("FEATURES" )->asGrid(); CSG_Grid *pElevation = Parameters("ELEVATION")->asGrid(); CSG_Grid *pSlope = Parameters("SLOPE" )->asGrid(); CSG_Grid *pAspect = Parameters("ASPECT" )->asGrid(); CSG_Grid *pProfC = Parameters("PROFC" )->asGrid(); CSG_Grid *pPlanC = Parameters("PLANC" )->asGrid(); CSG_Grid *pLongC = Parameters("LONGC" )->asGrid(); CSG_Grid *pCrosC = Parameters("CROSC" )->asGrid(); CSG_Grid *pMiniC = Parameters("MINIC" )->asGrid(); CSG_Grid *pMaxiC = Parameters("MAXIC" )->asGrid(); //----------------------------------------------------- if( !Get_Weights() ) { return( false ); } if( !Get_Normal(Normal) ) { return( false ); } // To constrain the quadtratic through the central cell, ignore the calculations involving the // coefficient f. Since these are all in the last row and column of the matrix, simply redimension. if( !SG_Matrix_LU_Decomposition(bConstrain ? 5 : 6, Index, Normal.Get_Data()) ) { return( false ); } //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { CSG_Vector Observed; double elevation, slope, aspect, profc, planc, longc, crosc, minic, maxic; if( Get_Observed(x, y, Observed, bConstrain) && SG_Matrix_LU_Solve(bConstrain ? 5 : 6, Index, Normal, Observed.Get_Data()) ) { Get_Parameters(zScale, Observed.Get_Data(), elevation, slope, aspect, profc, planc, longc, crosc, minic, maxic); GRID_SET_VALUE(pFeature , Get_Feature(slope, minic, maxic, crosc, Tol_Slope, Tol_Curve)); GRID_SET_VALUE(pElevation, elevation + m_pDEM->asDouble(x, y)); // Add central elevation back GRID_SET_VALUE(pSlope , slope); GRID_SET_VALUE(pAspect , aspect); GRID_SET_VALUE(pProfC , profc); GRID_SET_VALUE(pPlanC , planc); GRID_SET_VALUE(pLongC , longc); GRID_SET_VALUE(pCrosC , crosc); GRID_SET_VALUE(pMiniC , minic); GRID_SET_VALUE(pMaxiC , maxic); } else { GRID_SET_NODATA(pFeature); GRID_SET_NODATA(pElevation); GRID_SET_NODATA(pSlope); GRID_SET_NODATA(pAspect); GRID_SET_NODATA(pProfC); GRID_SET_NODATA(pPlanC); GRID_SET_NODATA(pLongC); GRID_SET_NODATA(pCrosC); GRID_SET_NODATA(pMiniC); GRID_SET_NODATA(pMaxiC); } } } //----------------------------------------------------- CSG_Parameter *pLUT = DataObject_Get_Parameter(pFeature, "LUT"); if( pLUT && pLUT->asTable() ) { pLUT->asTable()->Del_Records(); LUT_SET_CLASS(FLAT , _TL("Planar" ), SG_GET_RGB(180, 180, 180)); LUT_SET_CLASS(PIT , _TL("Pit" ), SG_GET_RGB( 0, 0, 0)); LUT_SET_CLASS(CHANNEL, _TL("Channel" ), SG_GET_RGB( 0, 0, 255)); LUT_SET_CLASS(PASS , _TL("Pass (saddle)"), SG_GET_RGB( 0, 255, 0)); LUT_SET_CLASS(RIDGE , _TL("Ridge" ), SG_GET_RGB(255, 255, 0)); LUT_SET_CLASS(PEAK , _TL("Peak" ), SG_GET_RGB(255, 0, 0)); DataObject_Set_Parameter(pFeature, pLUT); DataObject_Set_Parameter(pFeature, "COLORS_TYPE", 1); // Color Classification Type: Lookup Table } //----------------------------------------------------- DataObject_Set_Colors(pSlope , 11, SG_COLORS_YELLOW_RED); DataObject_Set_Colors(pAspect, 11, SG_COLORS_ASPECT_3); DataObject_Set_Colors(pProfC , 11, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(pPlanC , 11, SG_COLORS_RED_GREY_BLUE, false); DataObject_Set_Colors(pLongC , 11, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(pCrosC , 11, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(pMiniC , 11, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(pMaxiC , 11, SG_COLORS_RED_GREY_BLUE, true); //----------------------------------------------------- return( true ); }