//--------------------------------------------------------- bool CTIN_Gradient::On_Execute(void) { bool bDegree; int iTriangle, zField; double a, b; CSG_TIN_Triangle *pTriangle; CSG_TIN *pTIN; CSG_Shape *pShape; CSG_Shapes *pShapes; //----------------------------------------------------- pTIN = Parameters("TIN") ->asTIN(); zField = Parameters("ZFIELD") ->asInt(); pShapes = Parameters("GRADIENT") ->asShapes(); bDegree = Parameters("DEGREE") ->asInt() == 1; //----------------------------------------------------- pShapes->Create(SHAPE_TYPE_Polygon, CSG_String::Format(SG_T("%s [%s], %s [%s]"), _TL("TIN_Gradient"), pTIN->Get_Field_Name(zField), _TL("TIN"), pTIN->Get_Name())); pShapes->Add_Field(_TL("ID") , SG_DATATYPE_Int); pShapes->Add_Field(_TL("AREA") , SG_DATATYPE_Double); pShapes->Add_Field(_TL("DECLINE"), SG_DATATYPE_Double); pShapes->Add_Field(_TL("AZIMUTH"), SG_DATATYPE_Double); //----------------------------------------------------- for(iTriangle=0; iTriangle<pTIN->Get_Triangle_Count() && Set_Progress(iTriangle, pTIN->Get_Triangle_Count()); iTriangle++) { pTriangle = pTIN->Get_Triangle(iTriangle); if( pTriangle->Get_Gradient(zField, a, b) ) { if( bDegree ) { a *= M_RAD_TO_DEG; b *= M_RAD_TO_DEG; } pShape = pShapes->Add_Shape(); pShape->Add_Point(pTriangle->Get_Node(0)->Get_Point()); pShape->Add_Point(pTriangle->Get_Node(1)->Get_Point()); pShape->Add_Point(pTriangle->Get_Node(2)->Get_Point()); pShape->Set_Value(0, iTriangle + 1); pShape->Set_Value(1, pTriangle->Get_Area()); pShape->Set_Value(2, a); pShape->Set_Value(3, b); } } return( true ); }
//--------------------------------------------------------- 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 ); }