//--------------------------------------------------------- bool CAddCoordinates::On_Execute(void) { CSG_Shapes *pShapes = Parameters("OUTPUT")->asShapes(); if( pShapes ) { pShapes->Assign(Parameters("INPUT")->asShapes()); } else { pShapes = Parameters("INPUT")->asShapes(); } //----------------------------------------------------- int xField = pShapes->Get_Field_Count(); pShapes->Add_Field("X", SG_DATATYPE_Double); int yField = pShapes->Get_Field_Count(); pShapes->Add_Field("Y", SG_DATATYPE_Double); //----------------------------------------------------- for(int i=0; i<pShapes->Get_Count(); i++) { CSG_Shape *pShape = pShapes->Get_Shape(i); pShape->Set_Value(xField, pShape->Get_Point(0).x); pShape->Set_Value(yField, pShape->Get_Point(0).y); } return( true ); }
//--------------------------------------------------------- bool CCRS_Transform_Shapes::On_Execute_Transformation(void) { if( m_bList ) { CSG_Parameter_Shapes_List *pSources, *pTargets; pSources = Parameters("SOURCE")->asShapesList(); pTargets = Parameters("TARGET")->asShapesList(); pTargets->Del_Items(); for(int i=0; i<pSources->Get_Count() && Process_Get_Okay(false); i++) { CSG_Shapes *pSource = pSources->asShapes(i); CSG_Shapes *pTarget = SG_Create_Shapes(pSource); if( Transform(pSource, pTarget) ) { pTargets->Add_Item(pTarget); } else { delete(pTarget); } } return( pTargets->Get_Count() > 0 ); } else { CSG_Shapes *pSource = Parameters("SOURCE")->asShapes(); CSG_Shapes *pTarget = Parameters("TARGET")->asShapes(); if( pSource == pTarget ) { pTarget = SG_Create_Shapes(pSource); if( Transform(pSource, pTarget) ) { pSource->Assign(pTarget); return( true ); } else { delete(pTarget); return( false ); } } else { pTarget->Create(pSource->Get_Type(), pSource->Get_Name(), pSource, pSource->Get_Vertex_Type()); } return( Transform(pSource, pTarget) ); } }
//--------------------------------------------------------- bool CAddCoordinates::On_Execute(void) { CSG_Shapes *pShapes = Parameters("OUTPUT")->asShapes(); if( pShapes ) { pShapes->Assign(Parameters("INPUT")->asShapes()); } else { pShapes = Parameters("INPUT")->asShapes(); } //----------------------------------------------------- int xField = pShapes->Get_Field_Count(); pShapes->Add_Field("X", SG_DATATYPE_Double); int yField = pShapes->Get_Field_Count(); pShapes->Add_Field("Y", SG_DATATYPE_Double); int zField = 0, mField = 0; if( pShapes->Get_Vertex_Type() != SG_VERTEX_TYPE_XY ) { zField = pShapes->Get_Field_Count(); pShapes->Add_Field("Z", SG_DATATYPE_Double); if( pShapes->Get_Vertex_Type() == SG_VERTEX_TYPE_XYZM ) { mField = pShapes->Get_Field_Count(); pShapes->Add_Field("M", SG_DATATYPE_Double); } } //----------------------------------------------------- for(int i=0; i<pShapes->Get_Count(); i++) { CSG_Shape *pShape = pShapes->Get_Shape(i); pShape->Set_Value(xField, pShape->Get_Point(0).x); pShape->Set_Value(yField, pShape->Get_Point(0).y); if( pShapes->Get_Vertex_Type() != SG_VERTEX_TYPE_XY ) { pShape->Set_Value(zField, pShape->Get_Z(0)); if( pShapes->Get_Vertex_Type() == SG_VERTEX_TYPE_XYZM ) { pShape->Set_Value(mField, pShape->Get_M(0)); } } } DataObject_Update(pShapes); return( true ); }
bool CSimplifyShapes::On_Execute(void){ bool bCopy; CSG_Shapes *pIn = Parameters("IN")->asShapes(); CSG_Shapes *pOut= Parameters("OUT")->asShapes(); double dError = Parameters("ERROR")->asDouble(); double dPercentage = Parameters("PERCENTAGE")->asDouble(); double dTolerance = Parameters("TOLERANCE")->asDouble(); int iNumPoints = Parameters("NUMPOINTS")->asInt(); int iMethod = Parameters("METHOD")->asInt(); TSG_Point Pt; CSG_Shape *pShape, *pShape2; int i; if(pIn == pOut){ bCopy = true; pOut = SG_Create_Shapes(); }//if else{ bCopy = false; }//else pOut->Create(pIn->Get_Type(), _TL("Simplified Lines"), pIn); vector<float> vx(5000),vy(5000); for(i=0; i<pIn->Get_Count(); i++){ pShape = pIn->Get_Shape(i); pShape2 = pOut->Add_Shape(); for(int j=0; j<pShape->Get_Part_Count(); j++){ vx.clear(); vy.clear(); for(int k=0; k<pShape->Get_Point_Count(j); k++){ Pt = pShape->Get_Point(k,j); vx.push_back(Pt.x); vy.push_back(Pt.y); }//for CDPHullF dp; dp.SetPoints(vx,vy); dp.GetKeys(vx,vy); dp.SetTol(dTolerance); try{ switch (iMethod){ case 0: dp.Simplify(); break; case 1: dp.ShrinkNorm(dPercentage / 100., dError); break; case 2: dp.Shrink(iNumPoints, ceil(dError)); break; }//switch } catch(TCHAR* str){} const CDPHullF::KeyContainer& kc=dp.GetKeys(); CDPHullF::KeyContainer::const_iterator it; TPoint<float> key; for (it=kc.begin(); it!=kc.end(); ++it){ pShape2->Add_Point((*it)->x, (*it)->y, j); }//for }//for }//for if(bCopy){ pIn->Assign(pOut); delete(pOut); }//if return true; }//method