//--------------------------------------------------------- bool CSG_PRQuadTree::Create(const CSG_Rect &Extent, bool bStatistics) { Destroy(); if( Extent.Get_XRange() > 0.0 && Extent.Get_YRange() > 0.0 ) { if( bStatistics ) { m_pRoot = new CSG_PRQuadTree_Node_Statistics( Extent.Get_XCenter(), Extent.Get_YCenter(), (0.5 + 0.01) * (Extent.Get_XRange() > Extent.Get_YRange() ? Extent.Get_XRange() : Extent.Get_YRange()) ); } else { m_pRoot = new CSG_PRQuadTree_Node( Extent.Get_XCenter(), Extent.Get_YCenter(), (0.5 + 0.01) * (Extent.Get_XRange() > Extent.Get_YRange() ? Extent.Get_XRange() : Extent.Get_YRange()) ); } return( true ); } return( false ); }
//--------------------------------------------------------- bool CGrid_Merge::Set_Target(CSG_Parameters *pParameters, CSG_Parameter_Grid_List *pGrids) { if( pParameters && pGrids && pGrids->Get_Count() > 0 ) { double d = pGrids->asGrid(0)->Get_Cellsize(); CSG_Rect r = pGrids->asGrid(0)->Get_Extent(); for(int i=1; i<pGrids->Get_Count(); i++) { if( d > pGrids->asGrid(i)->Get_Cellsize() ) { d = pGrids->asGrid(i)->Get_Cellsize(); } r.Union(pGrids->asGrid(i)->Get_Extent()); } int nx = 1 + (int)(r.Get_XRange() / d); int ny = 1 + (int)(r.Get_YRange() / d); m_Grid_Target.Set_User_Defined(pParameters, r.Get_XMin(), r.Get_YMin(), d, nx, ny); } return( false ); }
//--------------------------------------------------------- bool CShapes_Cut_Interactive::Get_Extent(CSG_Rect &r) { CSG_Parameters *pParameters = Get_Parameters("CUT"); pParameters->Get_Parameter("AX")->Set_Value(r.Get_XMin()); pParameters->Get_Parameter("AY")->Set_Value(r.Get_YMin()); pParameters->Get_Parameter("BX")->Set_Value(r.Get_XMax()); pParameters->Get_Parameter("BY")->Set_Value(r.Get_YMax()); pParameters->Get_Parameter("DX")->Set_Value(r.Get_XRange()); pParameters->Get_Parameter("DY")->Set_Value(r.Get_YRange()); if( Dlg_Parameters("CUT") ) { r.Assign( pParameters->Get_Parameter("AX")->asDouble(), pParameters->Get_Parameter("AY")->asDouble(), pParameters->Get_Parameter("BX")->asDouble(), pParameters->Get_Parameter("BY")->asDouble() ); return( true ); } return( false ); }
//--------------------------------------------------------- void CWKSP_Shapes::Edit_Shape_Draw_Move(wxDC &dc, const CSG_Rect &rWorld, const wxPoint &Point, const TSG_Point &ptWorld) { double ClientToWorld = rWorld.Get_XRange() / (double)dc.GetSize().x; dc.DrawLine(Point.x, Point.y, (int)((ptWorld.x - rWorld.Get_XMin()) / ClientToWorld), (int)((rWorld.Get_YMax() - ptWorld.y) / ClientToWorld) ); }
//--------------------------------------------------------- bool CGCS_Graticule::Get_Extent(const CSG_Rect &Extent, CSG_Rect &r) { if( m_Projector.Set_Inverse() ) { double x, y, d; CSG_Point p(Extent.Get_XMin(), Extent.Get_YMin()); m_Projector.Get_Projection(p); r.Assign(p, p); d = Extent.Get_XRange() / 10.0; for(y=Extent.Get_YMin(), x=Extent.Get_XMin(); x<=Extent.Get_XMax(); x+=d) { p.Assign(x, y); m_Projector.Get_Projection(p); r.Union(p); } for(y=Extent.Get_YMax(), x=Extent.Get_XMin(); x<=Extent.Get_XMax(); x+=d) { p.Assign(x, y); m_Projector.Get_Projection(p); r.Union(p); } d = Extent.Get_YRange() / 10.0; for(x=Extent.Get_XMin(), y=Extent.Get_YMin(); y<=Extent.Get_YMax(); y+=d) { p.Assign(x, y); m_Projector.Get_Projection(p); r.Union(p); } for(x=Extent.Get_XMax(), y=Extent.Get_YMin(); y<=Extent.Get_YMax(); y+=d) { p.Assign(x, y); m_Projector.Get_Projection(p); r.Union(p); } m_Projector.Set_Inverse(false); if( r.Get_XMin() < -180 ) r.m_rect.xMin = -180; else if( r.Get_XMax() > 180 ) r.m_rect.xMax = 180; if( r.Get_YMin() < -90 ) r.m_rect.yMin = -90; else if( r.Get_YMax() > 90 ) r.m_rect.yMax = 90; return( r.Get_XRange() > 0.0 && r.Get_YRange() > 0.0 ); } return( false ); }
//--------------------------------------------------------- bool CWKSP_Shapes::Edit_On_Mouse_Move(wxWindow *pMap, CSG_Rect rWorld, wxPoint pt, wxPoint ptLast, int Key) { switch( m_Edit_Mode ) { case EDIT_SHAPE_MODE_Split: case EDIT_SHAPE_MODE_Move: { CSG_Shape *pShape = m_Edit_Shapes.Get_Shape(1); if( pShape && pShape->Get_Point_Count() > 0 && (pt.x != ptLast.x || pt.y != ptLast.y) ) { wxClientDC dc(pMap); dc.SetLogicalFunction(wxINVERT); Edit_Shape_Draw_Move(dc, rWorld, ptLast, pShape->Get_Point(0, 0, false)); Edit_Shape_Draw_Move(dc, rWorld, pt , pShape->Get_Point(0, 0, false)); } return( true ); } //----------------------------------------------------- case EDIT_SHAPE_MODE_Normal: default: if( m_Edit_pShape ) { //--------------------------------------------- if( m_Edit_iPart >= 0 && (m_Edit_iPoint < 0 || Key & MODULE_INTERACTIVE_KEY_LEFT) && (pt.x != ptLast.x || pt.y != ptLast.y) ) { wxClientDC dc(pMap); dc.SetLogicalFunction(wxINVERT); Edit_Shape_Draw_Move(dc, rWorld, ptLast); Edit_Shape_Draw_Move(dc, rWorld, pt); return( true ); } //--------------------------------------------- else { int iPart, iPoint; double ClientToWorld = rWorld.Get_XRange() / (double)pMap->GetClientSize().x; CSG_Point Point(rWorld.Get_XMin() + pt.x * ClientToWorld, rWorld.Get_YMax() - pt.y * ClientToWorld); switch( Edit_Shape_HitTest(Point, EDIT_TICKMARK_SIZE * ClientToWorld, iPart, iPoint) ) { default: pMap->SetCursor(IMG_Get_Cursor(ID_IMG_CRS_SELECT )); break; case 1: pMap->SetCursor(IMG_Get_Cursor(ID_IMG_CRS_EDIT_POINT_MOVE)); break; case 2: pMap->SetCursor(IMG_Get_Cursor(ID_IMG_CRS_EDIT_POINT_ADD )); break; } return( true ); } } } return( false ); }
//--------------------------------------------------------- double CGCS_Graticule::Get_Interval(const CSG_Rect &Extent) { if( Parameters("INTERVAL")->asInt() == 0 ) { return( Parameters("FIXED")->asDouble() ); } double Interval = Extent.Get_XRange() > Extent.Get_YRange() ? Extent.Get_XRange() : Extent.Get_YRange(); if( Interval > 360 ) { Interval = 360; } Interval = Interval / Parameters("FITTED")->asInt(); double d = pow(10.0, (int)(log10(Interval)) - (Interval < 1.0 ? 1.0 : 0.0)); Interval = (int)(Interval / d) * d; return( Interval ); }
//--------------------------------------------------------- inline void CGeoref_Grid::Add_Target_Extent(CSG_Rect &Extent, double x, double y) { if( m_Engine.Get_Converted(x, y) ) { if( Extent.Get_XRange() >= 0.0 && Extent.Get_YRange() >= 0.0 ) { Extent.Union(CSG_Point(x, y)); } else { Extent.Assign(x, y, x, y); } } }
//--------------------------------------------------------- bool CGeoref_Grid::Get_Target_Extent(CSG_Rect &Extent, bool bEdge) { if( Parameters("METHOD")->asInt() == GEOREF_Triangulation ) // triangulation { return( m_Engine.Get_Reference_Extent(Extent) ); } //----------------------------------------------------- CSG_Grid *pGrid = Parameters("GRID")->asGrid(); Extent.m_rect.xMin = Extent.m_rect.yMin = 1.0; Extent.m_rect.xMax = Extent.m_rect.yMax = 0.0; //----------------------------------------------------- if( bEdge ) { for(int y=0; y<pGrid->Get_NY(); y++) { Add_Target_Extent(Extent, pGrid->Get_XMin(), pGrid->Get_System().Get_yGrid_to_World(y)); Add_Target_Extent(Extent, pGrid->Get_XMax(), pGrid->Get_System().Get_yGrid_to_World(y)); } for(int x=0; x<pGrid->Get_NX(); x++) { Add_Target_Extent(Extent, pGrid->Get_System().Get_xGrid_to_World(x), pGrid->Get_YMin()); Add_Target_Extent(Extent, pGrid->Get_System().Get_xGrid_to_World(x), pGrid->Get_YMax()); } } //----------------------------------------------------- else { for(int y=0; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++) { for(int x=0; x<pGrid->Get_NX(); x++) { if( !pGrid->is_NoData(x, y) ) { TSG_Point p = pGrid->Get_System().Get_Grid_to_World(x, y); Add_Target_Extent(Extent, p.x, p.y); } } } } return( is_Progress() && Extent.Get_XRange() > 0.0 && Extent.Get_YRange() > 0.0 ); }
//--------------------------------------------------------- bool CShapes_Cut::Get_Extent(CSG_Rect &r) { m_pPolygons = NULL; switch( Parameters("TARGET")->asInt() ) { //----------------------------------------------------- case 0: // user defined Get_Parameters("CUT")->Get_Parameter("AX")->Set_Value(r.Get_XMin()); Get_Parameters("CUT")->Get_Parameter("AY")->Set_Value(r.Get_YMin()); Get_Parameters("CUT")->Get_Parameter("BX")->Set_Value(r.Get_XMax()); Get_Parameters("CUT")->Get_Parameter("BY")->Set_Value(r.Get_YMax()); Get_Parameters("CUT")->Get_Parameter("DX")->Set_Value(r.Get_XRange()); Get_Parameters("CUT")->Get_Parameter("DY")->Set_Value(r.Get_YRange()); if( Dlg_Parameters("CUT") ) { r.Assign( Get_Parameters("CUT")->Get_Parameter("AX")->asDouble(), Get_Parameters("CUT")->Get_Parameter("AY")->asDouble(), Get_Parameters("CUT")->Get_Parameter("BX")->asDouble(), Get_Parameters("CUT")->Get_Parameter("BY")->asDouble() ); return( true ); } break; //----------------------------------------------------- case 1: // grid project if( Dlg_Parameters("GRID") ) { r.Assign(Get_Parameters("GRID")->Get_Parameter("GRID")->asGrid_System()->Get_Extent()); return( true ); } break; //----------------------------------------------------- case 2: // shapes extent if( Dlg_Parameters("SHAPES") ) { r.Assign(Get_Parameters("SHAPES")->Get_Parameter("SHAPES")->asShapes()->Get_Extent()); return( true ); } break; //----------------------------------------------------- case 3: // polygons if( Dlg_Parameters("POLYGONS") ) { r.Assign(Get_Parameters("POLYGONS")->Get_Parameter("POLYGONS")->asShapes()->Get_Extent()); m_pPolygons = Get_Parameters("POLYGONS")->Get_Parameter("POLYGONS")->asShapes(); return( true ); } break; } return( false ); }
//--------------------------------------------------------- bool CSTL_Import::On_Execute(void) { int Method; DWORD iFacette, nFacettes; TSTL_Point p[3]; CSG_String sFile, sHeader; CSG_File Stream; //----------------------------------------------------- sFile = Parameters("FILE") ->asString(); Method = Parameters("METHOD") ->asInt(); r_sin_x = sin(Parameters("ROT_X")->asDouble() * M_DEG_TO_RAD); r_sin_y = sin(Parameters("ROT_Y")->asDouble() * M_DEG_TO_RAD); r_sin_z = sin(Parameters("ROT_Z")->asDouble() * M_DEG_TO_RAD); r_cos_x = cos(Parameters("ROT_X")->asDouble() * M_DEG_TO_RAD); r_cos_y = cos(Parameters("ROT_Y")->asDouble() * M_DEG_TO_RAD); r_cos_z = cos(Parameters("ROT_Z")->asDouble() * M_DEG_TO_RAD); //----------------------------------------------------- if( !Stream.Open(sFile) ) { return( false ); } if( !Stream.Read(sHeader, 80) ) { return( false ); } Message_Add(sHeader); if( !Stream.Read(&nFacettes, sizeof(nFacettes)) ) { return( false ); } Message_Add(CSG_String::Format(SG_T("%s: %d"), _TL("Number of Facettes"), nFacettes)); //----------------------------------------------------- switch( Method ) { //----------------------------------------------------- case 0: { // Point Cloud CSG_Rect Extent; if( Get_Extent(Stream, Extent, nFacettes) ) { CSG_PRQuadTree Points(Extent); CSG_PointCloud *pPoints = SG_Create_PointCloud(); Parameters("POINTS")->Set_Value(pPoints); pPoints->Set_Name(SG_File_Get_Name(sFile, false)); pPoints->Add_Field((const char *)NULL, SG_DATATYPE_Undefined); for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++) { if( Read_Facette(Stream, p) ) { for(int i=0; i<3; i++) { if( Points.Add_Point(p[i].x, p[i].y, p[i].z) ) { pPoints->Add_Point(p[i].x, p[i].y, p[i].z); } } } } } break; } //----------------------------------------------------- case 1: { // Point Cloud (centered) CSG_PointCloud *pPoints = SG_Create_PointCloud(); Parameters("POINTS")->Set_Value(pPoints); pPoints->Set_Name(SG_File_Get_Name(sFile, false)); pPoints->Add_Field((const char *)NULL, SG_DATATYPE_Undefined); for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++) { if( Read_Facette(Stream, p) ) { pPoints->Add_Point( (p[0].x + p[1].x + p[2].x) / 3.0, (p[0].y + p[1].y + p[2].y) / 3.0, (p[0].z + p[1].z + p[2].z) / 3.0 ); } } break; } //----------------------------------------------------- case 2: { // Points CSG_Shapes *pPoints = SG_Create_Shapes(SHAPE_TYPE_Point, SG_File_Get_Name(sFile, false)); pPoints->Add_Field(SG_T("Z"), SG_DATATYPE_Float); Parameters("SHAPES")->Set_Value(pPoints); for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++) { if( Read_Facette(Stream, p) ) { CSG_Shape *pPoint = pPoints->Add_Shape(); pPoint->Add_Point( (p[0].x + p[1].x + p[2].x) / 3.0, (p[0].y + p[1].y + p[2].y) / 3.0 ); pPoint->Set_Value(0, (p[0].z + p[1].z + p[2].z) / 3.0 ); } } break; } //----------------------------------------------------- case 3: { // Raster CSG_Rect Extent; if( Get_Extent(Stream, Extent, nFacettes) ) { int nx, ny; double d; nx = Parameters("GRID_RES")->asInt(); d = Extent.Get_XRange() / nx; ny = 1 + (int)(Extent.Get_YRange() / d); m_pGrid = SG_Create_Grid(SG_DATATYPE_Float, nx, ny, d, Extent.Get_XMin(), Extent.Get_YMin()); m_pGrid->Set_Name(SG_File_Get_Name(sFile, false)); m_pGrid->Set_NoData_Value(-99999); m_pGrid->Assign_NoData(); Parameters("GRID")->Set_Value(m_pGrid); //--------------------------------------------- for(iFacette=0; iFacette<nFacettes && !Stream.is_EOF() && Set_Progress(iFacette, nFacettes); iFacette++) { if( Read_Facette(Stream, p) ) { TSG_Point_Z Point[3]; for(int i=0; i<3; i++) { Point[i].x = (p[i].x - m_pGrid->Get_XMin()) / m_pGrid->Get_Cellsize(); Point[i].y = (p[i].y - m_pGrid->Get_YMin()) / m_pGrid->Get_Cellsize(); Point[i].z = p[i].z; } Set_Triangle(Point); } } } break; } } //----------------------------------------------------- return( true ); }