diff --git a/BuildTools/CommonDistFiles/GeoDa.ico b/BuildTools/CommonDistFiles/GeoDa.ico new file mode 100644 index 000000000..179da6325 Binary files /dev/null and b/BuildTools/CommonDistFiles/GeoDa.ico differ diff --git a/BuildTools/windows/installer/32bit/GeoDa.iss b/BuildTools/windows/installer/32bit/GeoDa.iss index 73b40b0b6..9ce83b733 100644 --- a/BuildTools/windows/installer/32bit/GeoDa.iss +++ b/BuildTools/windows/installer/32bit/GeoDa.iss @@ -21,11 +21,13 @@ OutputBaseFilename=geoda_setup ChangesAssociations=yes [dirs] +Name: "{app}"; Permissions: everyone-full; Check: InitializeSetup Name: "{app}\basemap_cache"; Permissions: everyone-full -Name: "{app}"; Permissions: everyone-full +Name: "{app}\Examples"; Permissions: everyone-full [Files] Source: "..\..\Release\GeoDa.exe"; DestDir: "{app}"; DestName: "GeoDa.exe" +Source: "..\..\..\CommonDistFiles\GeoDa.ico"; DestDir: "{app}" Source: "..\..\..\CommonDistFiles\copyright.txt"; DestDir: "{app}" Source: "..\..\..\CommonDistFiles\GPLv3.txt"; DestDir: "{app}" Source: "..\..\..\CommonDistFiles\cache.sqlite"; DestDir: "{app}" @@ -37,6 +39,7 @@ Source: "vcredist_x86.exe"; DestDir: "{app}" Source: "ogr_FileGDB.dll"; DestDir: "{app}" Source: "ogr_OCI.dll"; DestDir: "{app}" Source: "ogr_SDE.dll"; DestDir: "{app}" +Source: "..\..\run_geoda.bat"; DestDir: "{app}" Source: "..\..\Release\sqlite.dll"; DestDir: "{app}" Source: "..\..\temp\curl-7.30.0\builds\curlib\bin\libcurl.dll"; DestDir: "{app}" Source: "..\..\temp\expat-2.1.0\build\Release\expat.dll"; DestDir: "{app}" @@ -55,7 +58,7 @@ Source: "..\..\temp\boost_1_57_0\stage\lib\boost_chrono-vc100-mt-1_57.dll"; Dest Source: "..\..\temp\boost_1_57_0\stage\lib\boost_thread-vc100-mt-1_57.dll"; DestDir: "{app}" Source: "..\..\temp\boost_1_57_0\stage\lib\boost_system-vc100-mt-1_57.dll"; DestDir: "{app}" -Source: "..\..\..\..\SampleData\Examples\*"; DestDir: "{userdocs}\Examples"; Flags: recursesubdirs uninsneveruninstall +Source: "..\..\..\..\SampleData\Examples\*"; DestDir: "{app}\Examples"; Flags: recursesubdirs uninsneveruninstall Source: "..\..\temp\gdal\data\*"; DestDir: "{app}\data"; Flags: recursesubdirs @@ -64,15 +67,18 @@ Source: "..\..\temp\gdal\data\*"; DestDir: "{app}\data"; Flags: recursesubdirs [Icons] Name: "{group}\GeoDa"; Filename: "{app}\GeoDa.exe" +;Name: "{group}\GeoDa"; Filename: "{app}\run_geoda.bat"; IconFilename: "{app}\GeoDa.ico" Name: "{group}\Uninstall"; Filename: "{uninstallexe}" Name: "{commondesktop}\GeoDa"; Filename: "{app}\GeoDa.exe" +;Name: "{commondesktop}\GeoDa"; Filename: "{app}\run_geoda.bat"; IconFilename: "{app}\GeoDa.ico" + [Registry] ; set PATH ; set GEODA_GDAL_DATA -Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"GEODA_GDAL_DATA"; ValueData:"{pf}\GeoDa Software\data"; Flags: preservestringtype uninsdeletevalue +Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"GEODA_GDAL_DATA"; ValueData:"{app}\data"; Flags: preservestringtype uninsdeletevalue ; set GEODA_OGR_DRIVER_PATH -Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"GEODA_OGR_DRIVER_PATH"; ValueData:"{pf}\GeoDa Software"; Flags: preservestringtype uninsdeletevalue +Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"GEODA_OGR_DRIVER_PATH"; ValueData:"{app}"; Flags: preservestringtype uninsdeletevalue Root: HKCR; Subkey: ".gda"; ValueType: string; ValueName: ""; ValueData: "GeoDaProjectFile"; Flags: uninsdeletevalue Root: HKCR; Subkey: "GeoDaProjectFile"; ValueType: string; ValueName: ""; ValueData: "GeoDa Project File"; Flags: uninsdeletekey @@ -109,5 +115,46 @@ begin Result := not RegKeyExists(HKLM,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}'); end; +function GetUninstallString: string; +var + sUnInstPath: string; + sUnInstallString: String; +begin + Result := ''; + sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\GeoDa_is1'); //Your App GUID/ID + sUnInstallString := ''; + if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then + RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString); + Result := sUnInstallString; +end; + +function IsUpgrade: Boolean; +begin + Result := (GetUninstallString() <> ''); +end; + +function InitializeSetup: Boolean; +var + V: Integer; + iResultCode: Integer; + sUnInstallString: string; +begin + Result := True; // in case when no previous version is found + if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\GeoDa_is1', 'UninstallString') then //Your App GUID/ID + begin + V := MsgBox(ExpandConstant('An old version of GeoDa was detected. Please uninstall it before continuing.'), mbInformation, MB_YESNO); //Custom Message if App installed + if V = IDYES then + begin + sUnInstallString := GetUninstallString(); + sUnInstallString := RemoveQuotes(sUnInstallString); + Exec(ExpandConstant(sUnInstallString), '', '', SW_SHOW, ewWaitUntilTerminated, iResultCode); + Result := True; //if you want to proceed after uninstall + //Exit; //if you want to quit after uninstall + end + else + Result := False; //when older version present and not uninstalled + end; +end; + [Run] Filename: {app}\vcredist_x86.exe; StatusMsg: Installing Visual Studio 2010 SP1 C++ CRT Libraries...; Check: VCRedistNeedsInstall diff --git a/BuildTools/windows/installer/64bit/GeoDa.iss b/BuildTools/windows/installer/64bit/GeoDa.iss index 2d8f0b3a2..dce8f8309 100644 --- a/BuildTools/windows/installer/64bit/GeoDa.iss +++ b/BuildTools/windows/installer/64bit/GeoDa.iss @@ -33,12 +33,15 @@ ArchitecturesInstallIn64BitMode=x64 ChangesAssociations=yes [dirs] +Name: "{app}"; Permissions: everyone-full; Check: InitializeSetup +Name: "{app}\Examples"; Permissions: everyone-full Name: "{app}\basemap_cache"; Permissions: everyone-full -Name: "{app}"; Permissions: everyone-full + [Files] Source: "..\..\Release\GeoDa.exe"; DestDir: "{app}"; DestName: "GeoDa.exe"; Check: IsX64 +Source: "..\..\..\CommonDistFiles\GeoDa.ico"; DestDir: "{app}" Source: "..\..\..\CommonDistFiles\copyright.txt"; DestDir: "{app}" Source: "..\..\..\CommonDistFiles\GPLv3.txt"; DestDir: "{app}" Source: "..\..\..\CommonDistFiles\cache.sqlite"; DestDir: "{app}" @@ -50,6 +53,7 @@ Source: "vcredist_x64.exe"; DestDir: "{app}" Source: "ogr_FileGDB.dll"; DestDir: "{app}" Source: "ogr_OCI.dll"; DestDir: "{app}" Source: "ogr_SDE.dll"; DestDir: "{app}" +Source: "..\..\run_geoda.bat"; DestDir: "{app}" Source: "..\..\Release\sqlite.dll"; DestDir: "{app}" Source: "..\..\temp\curl-7.46.0\builds\curlib\bin\libcurl.dll"; DestDir: "{app}" Source: "..\..\temp\expat-2.1.0\build\Release\expat.dll"; DestDir: "{app}" @@ -68,24 +72,25 @@ Source: "..\..\temp\boost_1_57_0\stage\lib\boost_chrono-vc100-mt-1_57.dll"; Dest Source: "..\..\temp\boost_1_57_0\stage\lib\boost_thread-vc100-mt-1_57.dll"; DestDir: "{app}" Source: "..\..\temp\boost_1_57_0\stage\lib\boost_system-vc100-mt-1_57.dll"; DestDir: "{app}" -Source: "..\..\..\..\SampleData\Examples\*"; DestDir: "{userdocs}\Examples"; Flags: recursesubdirs uninsneveruninstall - - +Source: "..\..\..\..\SampleData\Examples\*"; DestDir: "{app}\Examples"; Flags: recursesubdirs Source: "..\..\temp\gdal\data\*"; DestDir: "{app}\data"; Flags: recursesubdirs ;Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme [Icons] Name: "{group}\GeoDa"; Filename: "{app}\GeoDa.exe" +;Name: "{group}\GeoDa"; Filename: "{app}\run_geoda.bat"; IconFilename: "{app}\GeoDa.ico" Name: "{group}\Uninstall"; Filename: "{uninstallexe}" Name: "{commondesktop}\GeoDa"; Filename: "{app}\GeoDa.exe" +;Name: "{commondesktop}\GeoDa"; Filename: "{app}\run_geoda.bat"; IconFilename: "{app}\GeoDa.ico" + [Registry] ; set PATH ; set GEODA_GDAL_DATA -Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"GEODA_GDAL_DATA"; ValueData:"{pf}\GeoDa Software\data"; Flags: preservestringtype uninsdeletevalue +Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"GEODA_GDAL_DATA"; ValueData:"{app}\data"; Flags: preservestringtype uninsdeletevalue ; set GEODA_OGR_DRIVER_PATH -Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"GEODA_OGR_DRIVER_PATH"; ValueData:"{pf}\GeoDa Software"; Flags: preservestringtype uninsdeletevalue +Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"GEODA_OGR_DRIVER_PATH"; ValueData:"{app}"; Flags: preservestringtype uninsdeletevalue Root: HKCR; Subkey: ".gda"; ValueType: string; ValueName: ""; ValueData: "GeoDaProjectFile"; Flags: uninsdeletevalue Root: HKCR; Subkey: "GeoDaProjectFile"; ValueType: string; ValueName: ""; ValueData: "GeoDa Project File"; Flags: uninsdeletekey @@ -124,5 +129,47 @@ begin Result := not RegKeyExists(HKLM,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1D8E6291-B0D5-35EC-8441-6616F567A0F7}'); end; +function GetUninstallString: string; +var + sUnInstPath: string; + sUnInstallString: String; +begin + Result := ''; + sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\GeoDa_is1'); //Your App GUID/ID + sUnInstallString := ''; + if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then + RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString); + Result := sUnInstallString; +end; + +function IsUpgrade: Boolean; +begin + Result := (GetUninstallString() <> ''); +end; + +function InitializeSetup: Boolean; +var + V: Integer; + iResultCode: Integer; + sUnInstallString: string; +begin + Result := True; // in case when no previous version is found + if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\GeoDa_is1', 'UninstallString') then //Your App GUID/ID + begin + V := MsgBox(ExpandConstant('An old version of GeoDa was detected. Please uninstall it before continuing.'), mbInformation, MB_YESNO); //Custom Message if App installed + if V = IDYES then + begin + sUnInstallString := GetUninstallString(); + sUnInstallString := RemoveQuotes(sUnInstallString); + Exec(ExpandConstant(sUnInstallString), '', '', SW_SHOW, ewWaitUntilTerminated, iResultCode); + Result := True; //if you want to proceed after uninstall + //Exit; //if you want to quit after uninstall + end + else + Result := False; //when older version present and not uninstalled + end; +end; + [Run] Filename: {app}\vcredist_x64.exe; StatusMsg: Installing Visual Studio 2010 SP1 C++ CRT Libraries...; Check: VCRedistNeedsInstall + diff --git a/BuildTools/windows/run_geoda.bat b/BuildTools/windows/run_geoda.bat new file mode 100644 index 000000000..9e95f4480 --- /dev/null +++ b/BuildTools/windows/run_geoda.bat @@ -0,0 +1,10 @@ +@echo OFF +SET geodapath=%cd% +SET GEODA_GDAL_DATA="%geodapath%\data" +SET GEODA_OGR_DRIVER_PATH="%geodapath%" + +@echo %geodapath% +@echo %GEODA_GDAL_DATA% +@echo %GEODA_GDAL_DRIVER_PATH% + +start GeoDa.exe diff --git a/DialogTools/CreatingWeightDlg.cpp b/DialogTools/CreatingWeightDlg.cpp index 88a7b9e1a..b8c8cd847 100644 --- a/DialogTools/CreatingWeightDlg.cpp +++ b/DialogTools/CreatingWeightDlg.cpp @@ -310,7 +310,7 @@ void CreatingWeightDlg::OnCreateClick( wxCommandEvent& event ) wmi.SetToThres(id, dist_metric, dist_units, dist_units_str,dist_values, t_val, dist_var_1, dist_tm_1, dist_var_2, dist_tm_2); if (m_is_arc && m_arc_in_km) { - t_val /= GenGeomAlgs::one_mi_in_km; // convert km to mi + //t_val /= GenGeomAlgs::one_mi_in_km; // convert km to mi } if (t_val > 0) { @@ -1219,6 +1219,7 @@ bool CreatingWeightDlg::WriteWeightFile(GalElement *gal, GwtElement *gwt, } //GdaFrame::GetGdaFrame()->ShowConnectivityMapView(uid); } + delete w; } else { success = false; } diff --git a/Explore/Basemap.cpp b/Explore/Basemap.cpp index 9cbe1185d..8f2aecd67 100644 --- a/Explore/Basemap.cpp +++ b/Explore/Basemap.cpp @@ -655,7 +655,11 @@ bool Basemap::Draw(wxBitmap* buffer) { // when tiles pngs are ready, draw them on a buffer wxMemoryDC dc(*buffer); + dc.SetBackground( *wxTRANSPARENT_BRUSH ); dc.Clear(); + wxGraphicsContext* gc = wxGraphicsContext::Create(dc); + if (!gc) + return false; int x0 = startX; int x1 = endX; @@ -683,11 +687,11 @@ bool Basemap::Draw(wxBitmap* buffer) bmp.LoadFile(wxFilePath, wxBITMAP_TYPE_JPEG); } bool bmpOK = bmp.IsOk(); - if (bmpOK) dc.DrawBitmap(bmp, pos_x, pos_y, true); + if (bmpOK) gc->DrawBitmap(bmp, pos_x, pos_y, 256,256); //dc.DrawRectangle((i-startX) * 256 - offsetX, (j-startY) * 256 - offsetY, 256, 256); } } - + delete gc; isTileDrawn = true; return isTileReady; } diff --git a/Explore/MapNewView.cpp b/Explore/MapNewView.cpp index 6581ea2a1..495d17297 100644 --- a/Explore/MapNewView.cpp +++ b/Explore/MapNewView.cpp @@ -110,8 +110,8 @@ void SliderDialog::OnSliderChange( wxScrollEvent & event ) IMPLEMENT_CLASS(MapCanvas, TemplateCanvas) BEGIN_EVENT_TABLE(MapCanvas, TemplateCanvas) -#ifdef __linux__ - // in Linux, using old paint function without transparency support +#ifndef __WXMAC__ + // in Linux, windows using old paint function without transparency support EVT_PAINT(TemplateCanvas::OnPaint) #else EVT_PAINT(MapCanvas::OnPaint) @@ -293,7 +293,7 @@ void MapCanvas::DrawLayers() DrawLayer1(); if (!layer2_valid) { - DrawLayer1(); + //DrawLayer1(); DrawLayer2(); } @@ -306,8 +306,9 @@ void MapCanvas::DrawLayerBase() { if (isDrawBasemap) { if (basemap != 0) { + basemap_bm->UseAlpha(); layerbase_valid = basemap->Draw(basemap_bm); -#ifdef __linux__ +#ifndef __WXMAC__ // trigger to draw again, since it's drawing on ONE bitmap, // not multilayer with transparency support layer0_valid = false; @@ -317,62 +318,17 @@ void MapCanvas::DrawLayerBase() } -#ifdef __linux__ -void MapCanvas::resizeLayerBms(int width, int height) -{ - deleteLayerBms(); - basemap_bm = new wxBitmap(width, height); - layer0_bm = new wxBitmap(width, height); - layer1_bm = new wxBitmap(width, height); - layer2_bm = new wxBitmap(width, height); - final_bm = new wxBitmap(width, height); - - layerbase_valid = false; - layer0_valid = false; - layer1_valid = false; - layer2_valid = false; -} - -void MapCanvas::DrawLayer0() -{ - //LOG_MSG("In TemplateCanvas::DrawLayer0"); - wxSize sz = GetVirtualSize(); - wxMemoryDC dc(*layer0_bm); - - dc.SetPen(canvas_background_color); - dc.SetBrush(canvas_background_color); - dc.DrawRectangle(wxPoint(0,0), sz); - if (isDrawBasemap) - dc.DrawBitmap(*basemap_bm, 0, 0); - - BOOST_FOREACH( GdaShape* shp, background_shps ) { - shp->paintSelf(dc); - } - if (draw_sel_shps_by_z_val) { - DrawSelectableShapesByZVal(dc); - } else { - DrawSelectableShapes(dc); - } - - layer0_valid = true; - layer1_valid = false; -} - -// in Linux, following 3 functions will be inherited from TemplateCanvas -//void MapCanvas::DrawLayer1() -//void MapCanvas::DrawLayer2() -//void MapCanvas::OnPaint(wxPaintEvent& event) - -#else +#ifdef __WXMAC__ void MapCanvas::resizeLayerBms(int width, int height) { deleteLayerBms(); - basemap_bm = new wxBitmap(width, height); + basemap_bm = new wxBitmap(width, height, 32); layer0_bm = new wxBitmap(width, height, 32); layer1_bm = new wxBitmap(width, height, 32); layer2_bm = new wxBitmap(width, height, 32); final_bm = new wxBitmap(width, height); + basemap_bm->UseAlpha(); layer0_bm->UseAlpha(); layer1_bm->UseAlpha(); layer2_bm->UseAlpha(); @@ -399,10 +355,16 @@ void MapCanvas::DrawLayer0() dc.SetBackground( *wxTRANSPARENT_BRUSH ); dc.Clear(); + wxGraphicsContext* gc = wxGraphicsContext::Create(dc); + if (!gc) + return; + BOOST_FOREACH( GdaShape* shp, background_shps ) { - shp->paintSelf(dc); + shp->paintSelf(gc); } + delete gc; + if (draw_sel_shps_by_z_val) { DrawSelectableShapesByZVal(dc); } else { @@ -452,10 +414,16 @@ void MapCanvas::DrawLayer2() wxMemoryDC dc(*layer2_bm); dc.SetBackground( *wxTRANSPARENT_BRUSH ); dc.Clear(); + + wxGraphicsContext* gc = wxGraphicsContext::Create(dc); + if (!gc) + return; BOOST_FOREACH( GdaShape* shp, foreground_shps ) { - shp->paintSelf(dc); + shp->paintSelf(gc); } + + delete gc; layer2_valid = true; } @@ -485,19 +453,57 @@ void MapCanvas::OnPaint(wxPaintEvent& event) // Draw the the selection region "the black selection box" if needed PaintSelectionOutline(paint_dc); - - // Draw optional control objects if needed, should be in memeory - // PaintControls(paint_dc); - - // The resize event will ruin the position of scroll bars, so we reset the - // position of scroll bars again. - //if (prev_scroll_pos_x > 0) SetScrollPos(wxHORIZONTAL, prev_scroll_pos_x); - //if (prev_scroll_pos_y > 0) SetScrollPos(wxVERTICAL, prev_scroll_pos_y); isRepaint = false; } event.Skip(); } +#else +void MapCanvas::resizeLayerBms(int width, int height) +{ + deleteLayerBms(); + basemap_bm = new wxBitmap(width, height); + layer0_bm = new wxBitmap(width, height); + layer1_bm = new wxBitmap(width, height); + layer2_bm = new wxBitmap(width, height); + final_bm = new wxBitmap(width, height); + + layerbase_valid = false; + layer0_valid = false; + layer1_valid = false; + layer2_valid = false; +} + +void MapCanvas::DrawLayer0() +{ + //LOG_MSG("In TemplateCanvas::DrawLayer0"); + wxSize sz = GetVirtualSize(); + wxMemoryDC dc(*layer0_bm); + + dc.SetPen(canvas_background_color); + dc.SetBrush(canvas_background_color); + dc.DrawRectangle(wxPoint(0,0), sz); + + if (isDrawBasemap) + dc.DrawBitmap(*basemap_bm, 0, 0); + + BOOST_FOREACH( GdaShape* shp, background_shps ) { + shp->paintSelf(dc); + } + if (draw_sel_shps_by_z_val) { + DrawSelectableShapesByZVal(dc); + } else { + DrawSelectableShapes(dc); + } + + layer0_valid = true; + layer1_valid = false; +} + +// in Linux, following 3 functions will be inherited from TemplateCanvas +//void MapCanvas::DrawLayer1() +//void MapCanvas::DrawLayer2() +//void MapCanvas::OnPaint(wxPaintEvent& event) #endif diff --git a/Explore/MapNewView.h b/Explore/MapNewView.h index 6b9a21906..71f59f683 100644 --- a/Explore/MapNewView.h +++ b/Explore/MapNewView.h @@ -119,8 +119,8 @@ class MapCanvas : public TemplateCanvas, public CatClassifStateObserver bool DrawBasemap(bool flag, int map_type); virtual void DrawLayerBase(); virtual void DrawLayers(); -#ifdef __linux__ - // in linux, use old style drawing without transparency support +#ifndef __WXMAC__ + // in linux, windows use old style drawing without transparency support // the commented out functions are inherited from TemplateCanvas class // TODO will be replace by wxImage drawing code virtual void resizeLayerBms(int width, int height); diff --git a/Regression/smile2.cpp b/Regression/smile2.cpp index 76df74fb7..2eda26a6a 100644 --- a/Regression/smile2.cpp +++ b/Regression/smile2.cpp @@ -48,7 +48,7 @@ void Compute_RSLmError(GalElement* g, double *resid, int dim, double* rst, - const std::vector< std::set >& g_lookup); + double t); void Compute_RSLmErrorRobust(GalElement* g, double** cov, @@ -59,7 +59,7 @@ void Compute_RSLmErrorRobust(GalElement* g, int dim, int expl, double* rst, - const std::vector< std::set >& g_lookup); + double t); void Compute_RSLmLag(GalElement* g, double** cov, @@ -70,7 +70,7 @@ void Compute_RSLmLag(GalElement* g, int dim, int expl, double* rst, - const std::vector< std::set >& g_lookup); + double t); void Compute_RSLmLagRobust(GalElement* g, double** cov, @@ -81,7 +81,7 @@ void Compute_RSLmLagRobust(GalElement* g, int dim, int expl, double* rst, - const std::vector< std::set >& g_lookup); + double t); void Compute_RSLmSarma(GalElement* g, double** cov, @@ -92,7 +92,7 @@ void Compute_RSLmSarma(GalElement* g, int dim, int expl, double* rst, - const std::vector< std::set >& g_lookup); + double t); bool ordinaryLS(DenseVector &y, @@ -129,10 +129,7 @@ void MakeFastLookupMat(GalElement *g, int dim, } } -// Note: it is expected that input g_lookup was initialized as follows: -// MakeFastLookupMat(g, dim, g_lookup); -double T(GalElement *g, int dim, - const std::vector< std::set >& g_lookup) +double T(GalElement *g, int dim) { // tr(W'W+WW) // = tr(W'W) + tr(WW) @@ -140,7 +137,8 @@ double T(GalElement *g, int dim, using namespace std; double sum = 0; - + + /* int i=0, j=0; for (i = 0; i < dim; ++i) { for (j = 0; j < dim; ++j) { @@ -157,7 +155,17 @@ double T(GalElement *g, int dim, sum += g[j].GetRW(i) * g[j].GetRW(i); } } + */ + for (int i = 0; i < dim; ++i) { + for (int j = 0; j < dim; ++j) { + double w_ij = g[i].GetRW(j); + double w_ji = g[j].GetRW(i); + sum += w_ij * w_ji; + sum += w_ji * w_ji; + + } + } /* // below is also incorrect when handling knn weights matrix int cnt = 0, cp = 0; @@ -209,7 +217,7 @@ void Compute_RSLmLag(GalElement* g, int dim, int expl, double *rst, - const std::vector< std::set >& g_lookup) + double t) // t = T(g, dim, g_lookup) { double *Y = y.getThis(); double const ee = norm(resid, dim); @@ -235,7 +243,7 @@ void Compute_RSLmLag(GalElement* g, z.squareTimesColumn( z2, cov ); // z2 = (X'X)^(-1)X'WXb const double xMx = z.product(z2); // (WXb)'X(X'X)^(-1)X'WXb // lag.norm : (WXb)'(WXb) - double v = (lag.norm() - xMx + T(g, dim, g_lookup) * sigma2) / sigma2; + double v = (lag.norm() - xMx + t * sigma2) / sigma2; RS /= v; double const RS_stat = gammp( 0.5, RS * 0.5); @@ -257,7 +265,7 @@ void Compute_RSLmLagRobust(GalElement* g, int dim, int expl, double *rst, - const std::vector< std::set >& g_lookup) + double T21) // T21 = T(g, dim, g_lookup) { double *Y = y.getThis(); double const ee = norm(resid, dim); @@ -292,7 +300,6 @@ void Compute_RSLmLagRobust(GalElement* g, // z.product(z2) : (WXb)'(X(X'X)^(-1)X')(WXb) const double T11 = Wy.norm() - z.product(z2); const double T1 = T11 / sigma2; - const double T21 = T(g, dim, g_lookup); const double T2 = 1.0 / (T1 + T21); RS /= (1.0 / T2 - T21); @@ -486,11 +493,10 @@ double Compute_MoranZ(GalElement* g, // // Performs spatial error test specification: computes RS statistic -// +// t = tr[(W'+W)*W] void Compute_RSLmError(GalElement* g, double *resid, - int dim, double *rst, - const std::vector< std::set >& g_lookup) + int dim, double *rst, double t) { double const ee = norm(resid, dim); double const sigma2 = ee / (dim); @@ -505,7 +511,6 @@ void Compute_RSLmError(GalElement* g, double RS = geoda_sqr(re.product( lag ) / sigma2); // [e'We/sigma2]^2 - double t = T(g, dim, g_lookup); // tr[(W'+W)*W] RS /= t; double const RS_stat = gammp( 0.5, RS * 0.5); @@ -523,7 +528,7 @@ void Compute_RSLmErrorRobust(GalElement* g, int dim, int expl, double *rst, - const std::vector< std::set >& g_lookup) + double T21) //T21 = T(g, dim, g_lookup) tr[(W'+W)*W] { double *Y = y.getThis(); double const ee = norm(resid, dim); @@ -556,7 +561,7 @@ void Compute_RSLmErrorRobust(GalElement* g, // z.product(z2) : (WXb)'(X(X'X)^(-1)X')(WXb) const double T11 = Wy.norm() - z.product(z2); const double T1 = T11 / sigma2; - const double T21 = T(g, dim, g_lookup); + const double T2 = 1.0 / (T1 + T21); const double RS = geoda_sqr(RS2 - (RS1 * T2 * T21)) / (T21-(T21*T21*T2)); @@ -576,7 +581,7 @@ void Compute_RSLmSarma(GalElement* g, int dim, int expl, double *rst, - const std::vector< std::set >& g_lookup) + double T21) { double *Y = y.getThis(); double const ee = norm(resid, dim); @@ -609,7 +614,7 @@ void Compute_RSLmSarma(GalElement* g, // z.product(z2) : (WXb)'(X(X'X)^(-1)X')(WXb) const double T11 = Wy.norm() - z.product(z2); const double T1 = T11 / sigma2; - const double T21 = T(g, dim, g_lookup); + const double T2 = 1.0 / (T1 + T21); const double RS = (geoda_sqr(RS1 - RS2)/ (1.0/T2 - T21)) + (RS2*RS2/T21); @@ -738,38 +743,35 @@ bool classicalRegression(GalElement *g, // diagnostics for spatial dependence if (g != NULL) { - std::vector< std::set > g_lookup; - MakeFastLookupMat(g, dim, g_lookup); - double *rst = new double[2]; + + double t = T(g, dim); // tr[(W'+W)*W] - Compute_RSLmError(g, resid, dim, rst, g_lookup); + Compute_RSLmError(g, resid, dim, rst, t); dr->SetLmError(0, 1.0); dr->SetLmError(1, rst[0]); dr->SetLmError(2, rst[1]); - Compute_RSLmErrorRobust(g, cov, y, x, ols, resid, dim, expl, rst, - g_lookup); + Compute_RSLmErrorRobust(g, cov, y, x, ols, resid, dim, expl, rst, t); dr->SetLmErrRobust(0, 1.0); dr->SetLmErrRobust(1, rst[0]); dr->SetLmErrRobust(2, rst[1]); - Compute_RSLmLag(g, cov, y, x, ols, resid, dim, expl, rst, g_lookup); + Compute_RSLmLag(g, cov, y, x, ols, resid, dim, expl, rst, t); dr->SetLmLag(0, 1.0); dr->SetLmLag(1, rst[0]); dr->SetLmLag(2, rst[1]); - Compute_RSLmLagRobust(g, cov, y, x, ols, resid, dim, expl, rst, - g_lookup); + Compute_RSLmLagRobust(g, cov, y, x, ols, resid, dim, expl, rst, t); dr->SetLmLagRobust(0, 1.0); dr->SetLmLagRobust(1, rst[0]); dr->SetLmLagRobust(2, rst[1]); - Compute_RSLmSarma(g, cov, y, x, ols, resid, dim, expl, rst, g_lookup); + Compute_RSLmSarma(g, cov, y, x, ols, resid, dim, expl, rst, t); dr->SetLmSarma(0, 2.0); dr->SetLmSarma(1, rst[0]); dr->SetLmSarma(2, rst[1]); diff --git a/ShapeOperations/GalWeight.cpp b/ShapeOperations/GalWeight.cpp index 76e0dc15d..c2e4ea5ff 100644 --- a/ShapeOperations/GalWeight.cpp +++ b/ShapeOperations/GalWeight.cpp @@ -36,6 +36,7 @@ GalElement::GalElement() { + is_nbrAvgW_empty = true; } bool GalElement::Check(long nbrIdx) @@ -48,7 +49,7 @@ bool GalElement::Check(long nbrIdx) // return row standardized weights value double GalElement::GetRW(int idx) { - if (nbrAvgW.empty()) { + if (is_nbrAvgW_empty) { size_t sz = nbr.size(); nbrAvgW.resize(sz); double sumW = 0.0; @@ -59,11 +60,12 @@ double GalElement::GetRW(int idx) for (size_t i=0; i & GalElement::GetNbrs() const diff --git a/ShapeOperations/GalWeight.h b/ShapeOperations/GalWeight.h index 0b303214a..34a93114f 100644 --- a/ShapeOperations/GalWeight.h +++ b/ShapeOperations/GalWeight.h @@ -46,12 +46,14 @@ class GalElement { double SpatialLag(const std::vector& x, const int* perm) const; double GetRW(int idx); bool Check(long nbrIdx); + + bool is_nbrAvgW_empty; + std::vector nbrAvgW; + std::map nbrLookup; // nbr_id, idx_in_nbrWeight private: - std::map nbrLookup; // nbr_id, idx_in_nbrWeight std::vector nbr; std::vector nbrWeight; - std::vector nbrAvgW; }; class GalWeight : public GeoDaWeight { diff --git a/TemplateCanvas.cpp b/TemplateCanvas.cpp index 51f0963f4..fedd23016 100644 --- a/TemplateCanvas.cpp +++ b/TemplateCanvas.cpp @@ -1102,7 +1102,7 @@ void TemplateCanvas::DrawSelectableShapes(wxMemoryDC &dc) #ifdef __WXMAC__ DrawSelectableShapes_gc(dc); #else - DrawSelectableShapes_gc(dc); + DrawSelectableShapes_dc(dc); #endif } else { for (int i=0, iend=selectable_shps.size(); iSetPen(wxPen(selectable_outline_color)); gc->SetBrush(wxBrush(selectable_fill_color)); + int cc_ts = cat_data.curr_canvas_tm_step; int num_cats=cat_data.GetNumCategories(cc_ts); int w = layer0_bm->GetWidth(); int h = layer0_bm->GetHeight(); + if (selectable_shps_type == points) { int dirty_cnt = 0; gc->SetAntialiasMode(wxANTIALIAS_NONE); wxDouble r = GdaConst::my_point_click_radius; - if (w < 150 || h < 150) r *= 0.66; - if (selectable_shps.size() > 100 && (w < 80 || h < 80)) r = 0.2; + if (w < 150 || h < 150) + r *= 0.66; + if (selectable_shps.size() > 100 && (w < 80 || h < 80)) + r = 0.2; + + int bnd = w*h; + std::vector dirty(bnd, false); + GdaPoint* p; for (int cat=0; catisNull()) continue; - path.AddCircle(p->center.x, p->center.y, r); - + //path.AddCircle(p->center.x, p->center.y, r); + int bnd_idx = p->center.x + p->center.y*w; + if (bnd_idx >= 0 && bnd_idx < bnd && !dirty[bnd_idx]) { + path.AddCircle(p->center.x, p->center.y, r); + dirty[bnd_idx] = true; + } } gc->StrokePath(path); @@ -1168,7 +1179,8 @@ void TemplateCanvas::DrawSelectableShapes_gc(wxMemoryDC &dc) for (int cat=0; catSetPen(cat_data.GetCategoryPen(cc_ts, cat)); wxBrush br = cat_data.GetCategoryBrush(cc_ts, cat); - if (br.IsOk() ) gc->SetBrush(br); + if (br.IsOk() ) + gc->SetBrush(br); if (isDrawBasemap) { wxColour brushClr = cat_data.GetCategoryBrush(cc_ts, cat).GetColour(); @@ -1330,7 +1342,8 @@ void TemplateCanvas::DrawSelectableShapes_gen_dc(wxDC &dc) int w = layer0_bm->GetWidth(); int h = layer0_bm->GetHeight(); if (selectable_shps_type == points) { - //std::vector dirty(w*h, false); + int bnd = w*h; + std::vector dirty(bnd, false); int dirty_cnt = 0; dc.SetBrush(*wxTRANSPARENT_BRUSH); wxDouble r = GdaConst::my_point_click_radius; @@ -1344,11 +1357,12 @@ void TemplateCanvas::DrawSelectableShapes_gen_dc(wxDC &dc) for (int i=0, iend=ids.size(); iisNull()) continue; - dc.DrawCircle(p->center.x, p->center.y, r); - //if (!dirty[p->center.x + p->center.y*w]) { - //dc.DrawCircle(p->center.x, p->center.y, r); - //dirty[p->center.x + p->center.y*w] = true; - //} + //dc.DrawCircle(p->center.x, p->center.y, r); + int bnd_idx = p->center.x + p->center.y*w; + if (bnd_idx >= 0 && bnd_idx < bnd && !dirty[bnd_idx]) { + dc.DrawCircle(p->center.x, p->center.y, r); + dirty[bnd_idx] = true; + } } } } else if (selectable_shps_type == polygons) { @@ -1426,7 +1440,7 @@ void TemplateCanvas::DrawHighlightedShapes(wxMemoryDC &dc) #ifdef __WXMAC__ DrawHighlightedShapes_gc(dc); #else - DrawHighlightedShapes_gc(dc); + DrawHighlightedShapes_dc(dc); #endif return; } @@ -1455,7 +1469,8 @@ void TemplateCanvas::DrawHighlightedShapes_gc(wxMemoryDC &dc) int h = layer0_bm->GetHeight(); if (selectable_shps_type == points) { - //std::vector dirty(w*h, false); + int bnd = w*h; + std::vector dirty(bnd, false); GdaPoint* p; gc->SetAntialiasMode(wxANTIALIAS_NONE); gc->SetPen(wxPen(highlight_color)); @@ -1467,11 +1482,12 @@ void TemplateCanvas::DrawHighlightedShapes_gc(wxMemoryDC &dc) if (hs[i]) { p = (GdaPoint*) selectable_shps[i]; if (p->isNull()) continue; - path.AddCircle(p->center.x, p->center.y, r); - //if (!dirty[p->center.x + p->center.y*w]) { - //path.AddCircle(p->center.x, p->center.y, r); - //dirty[p->center.x + p->center.y*w] = true; - //} + //path.AddCircle(p->center.x, p->center.y, r); + int bnd_idx = p->center.x + p->center.y*w; + if (bnd_idx >= 0 && bnd_idx < bnd && !dirty[bnd_idx]) { + path.AddCircle(p->center.x, p->center.y, r); + dirty[bnd_idx] = true; + } } } gc->StrokePath(path); @@ -1596,7 +1612,8 @@ void TemplateCanvas::DrawHighlightedShapes_gen_dc(wxDC &dc, int h = layer0_bm->GetHeight(); if (selectable_shps_type == points) { - //std::vector dirty(w*h, false); + int bnd = w*h; + std::vector dirty(bnd, false); GdaPoint* p; dc.SetPen(hc_pen); dc.SetBrush(*wxTRANSPARENT_BRUSH); @@ -1607,11 +1624,12 @@ void TemplateCanvas::DrawHighlightedShapes_gen_dc(wxDC &dc, if (hs[i]) { p = (GdaPoint*) selectable_shps[i]; if (p->isNull()) continue; - dc.DrawCircle(p->center.x, p->center.y, r); - //if (!dirty[p->center.x + p->center.y*w]) { - //dc.DrawCircle(p->center.x, p->center.y, r); - //dirty[p->center.x + p->center.y*w] = true; - //} + //c.DrawCircle(p->center.x, p->center.y, r); + int bnd_idx = p->center.x + p->center.y*w; + if (bnd_idx >= 0 && bnd_idx < bnd && !dirty[bnd_idx]) { + dc.DrawCircle(p->center.x, p->center.y, r); + dirty[bnd_idx] = true; + } } } } else if (selectable_shps_type == polygons) { @@ -1671,7 +1689,7 @@ void TemplateCanvas::DrawNewSelShapes(wxMemoryDC &dc) #ifdef __WXMAC__ DrawNewSelShapes_gc(dc); #else - DrawNewSelShapes_gc(dc); + DrawNewSelShapes_dc(dc); #endif return; } @@ -1704,7 +1722,8 @@ void TemplateCanvas::DrawNewSelShapes_gc(wxMemoryDC &dc) std::vector& nh = GetNewlySelList(); if (selectable_shps_type == points) { - //std::vector dirty(w*h, false); + int bnd = w*h; + std::vector dirty(bnd, false); GdaPoint* p; gc->SetAntialiasMode(wxANTIALIAS_NONE); gc->SetPen(hc_pen); @@ -1715,11 +1734,12 @@ void TemplateCanvas::DrawNewSelShapes_gc(wxMemoryDC &dc) for (int i=0; iisNull()) continue; - path.AddCircle(p->center.x, p->center.y, r); - //if (!dirty[p->center.x + p->center.y*w]) { - //path.AddCircle(p->center.x, p->center.y, r); - //dirty[p->center.x + p->center.y*w] = true; - //} + //path.AddCircle(p->center.x, p->center.y, r); + int bnd_idx = p->center.x + p->center.y*w; + if (bnd_idx >= 0 && bnd_idx < bnd && !dirty[bnd_idx]) { + path.AddCircle(p->center.x, p->center.y, r); + dirty[bnd_idx] = true; + } } gc->StrokePath(path); } else if (selectable_shps_type == polygons) { @@ -1832,7 +1852,8 @@ void TemplateCanvas::DrawNewSelShapes_dc(wxMemoryDC &dc) std::vector& nh = GetNewlySelList(); if (selectable_shps_type == points) { - //std::vector dirty(w*h, false); + int bnd = w*h; + std::vector dirty(bnd, false); dc.SetPen(hc_pen); dc.SetBrush(*wxTRANSPARENT_BRUSH); GdaPoint* p; @@ -1842,11 +1863,12 @@ void TemplateCanvas::DrawNewSelShapes_dc(wxMemoryDC &dc) for (int i=0; iisNull()) continue; - dc.DrawCircle(p->center.x, p->center.y, r); - //if (!dirty[p->center.x + p->center.y*w]) { - //dc.DrawCircle(p->center.x, p->center.y, r); - //dirty[p->center.x + p->center.y*w] = true; - //} + //dc.DrawCircle(p->center.x, p->center.y, r); + int bnd_idx = p->center.x + p->center.y*w; + if (bnd_idx >= 0 && bnd_idx < bnd && !dirty[bnd_idx]) { + dc.DrawCircle(p->center.x, p->center.y, r); + dirty[bnd_idx] = true; + } } } else if (selectable_shps_type == polygons) { GdaPolygon* p; @@ -2095,7 +2117,8 @@ void TemplateCanvas::EraseNewUnSelShapes_dc(wxMemoryDC &dc) if (selectable_shps_type == points) { dc.SetBrush(*wxTRANSPARENT_BRUSH); - //std::vector dirty(w*h, false); + int bnd = w*h; + std::vector dirty(bnd, false); GdaPoint* p; wxDouble r = GdaConst::my_point_click_radius; if (w < 150 || h < 150) r *= 0.66; @@ -2105,11 +2128,12 @@ void TemplateCanvas::EraseNewUnSelShapes_dc(wxMemoryDC &dc) for (int i=0, iend=total_in_cat[cat]; iisNull()) continue; - dc.DrawCircle(p->center.x, p->center.y, r); - //if (!dirty[p->center.x + p->center.y*w]) { - //dc.DrawCircle(p->center.x, p->center.y, r); - //dirty[p->center.x + p->center.y*w] = true; - //} + //dc.DrawCircle(p->center.x, p->center.y, r); + int bnd_idx = p->center.x + p->center.y*w; + if (bnd_idx >= 0 && bnd_idx < bnd&& !dirty[bnd_idx]) { + dc.DrawCircle(p->center.x, p->center.y, r); + dirty[bnd_idx] = true; + } } } } else if (selectable_shps_type == polygons) { diff --git a/version.h b/version.h index df50b044b..fa9f3bd51 100644 --- a/version.h +++ b/version.h @@ -1,11 +1,11 @@ namespace Gda { const int version_major = 1; const int version_minor = 8; - const int version_build = 12; + const int version_build = 14; const int version_subbuild = 0; const int version_year = 2016; - const int version_month = 9; - const int version_day = 1; + const int version_month = 11; + const int version_day = 8; const int version_night = 0; const int version_type = 2; // 0: alpha, 1: beta, 2: release }