Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ include_directories(${QWT_INCLUDE_DIR})

option(ENABLE_OpenMP on)
if(ENABLE_OpenMP)
add_definitions(-D ENABLE_OpenMP)
if(MSVC)
set(OpenMP_C_FLAGS "${OpenMP_C_FLAGS} -openmp:llvm")
set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS} -openmp:llvm")
endif(MSVC)
add_definitions(-D ENABLE_OPENMP)
find_package(OpenMP REQUIRED)
if(NOT OpenMP_FOUND)
message(FATAL_ERROR "OpenMP Not Found!")
Expand Down
2 changes: 1 addition & 1 deletion src/Model/gwmalgorithmmetavariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool GwmAlgorithmMetaVariable::validate(QString &error) const

if (weightType == Weight::WeightType::BandwidthWeight)
{
if (weightBandwidthSize == 0)
if (!weightBandwidthAutoselect && weightBandwidthSize == 0)
{
error = QTranslator::tr("Bandwidth size is too small.");
return false;
Expand Down
1 change: 1 addition & 0 deletions src/Model/gwmalgorithmmetavariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct GwmAlgorithmMetaVariable
gwm::Weight::WeightType weightType = gwm::Weight::BandwidthWeight;
double weightBandwidthSize = DBL_MAX;
bool weightBandwidthAdaptive = true;
bool weightBandwidthAutoselect = false;
gwm::BandwidthWeight::KernelFunctionType weightBandwidthKernel = gwm::BandwidthWeight::KernelFunctionType::Gaussian;
// Distance
gwm::Distance::DistanceType distanceType = gwm::Distance::DistanceType::CRSDistance;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/gwmlayerbasicgwritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GwmLayerBasicGWRItem::GwmLayerBasicGWRItem(GwmLayerItem* parent, QgsVectorLayer*
mDataPointsSize = taskThread->dataLayer()->featureCount();
mDepVar = taskThread->dependentVariable();
mIndepVars = taskThread->independentVariables();
mWeight = gwm::BandwidthWeight(*static_cast<gwm::BandwidthWeight*>(taskThread->spatialWeight().weight()));
mWeight = gwm::BandwidthWeight(taskThread->spatialWeight().weight<gwm::BandwidthWeight>());
mDiagnostic = taskThread->diagnostic();
mDiagnostic0 = taskThread->diagnostic0();
mBetas = mat(taskThread->betas());
Expand Down
2 changes: 1 addition & 1 deletion src/Model/gwmlayercollinearitygwritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GwmLayerCollinearityGWRItem::GwmLayerCollinearityGWRItem(GwmLayerItem* parent, Q
mDataPointsSize = taskThread->dataLayer()->featureCount();
mDepVar = taskThread->dependentVariable();
mIndepVars = taskThread->independentVariables();
mWeight = gwm::BandwidthWeight(*static_cast<gwm::BandwidthWeight*>(taskThread->spatialWeight().weight()));
mWeight = gwm::BandwidthWeight(taskThread->spatialWeight().weight<gwm::BandwidthWeight>());
mDiagnostic = taskThread->dialnostic();
mDiagnostic0 = taskThread->diagnostic0();
mBetas = mat(taskThread->betas());
Expand Down
2 changes: 1 addition & 1 deletion src/Model/gwmlayerggwritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GwmLayerGGWRItem::GwmLayerGGWRItem(GwmLayerItem* parent, QgsVectorLayer* vector,
mDataPointsSize = taskThread->dataLayer()->featureCount();
mDepVar = taskThread->dependentVariable();
mIndepVars = taskThread->independentVariables();
mWeight = gwm::BandwidthWeight(*static_cast<gwm::BandwidthWeight*>(taskThread->spatialWeight().weight()));
mWeight = gwm::BandwidthWeight(taskThread->spatialWeight().weight<gwm::BandwidthWeight>());
mBetas = mat(taskThread->betas());
isBandwidthOptimized = taskThread->autoselectBandwidth();
mBandwidthSelScores = taskThread->bandwidthSelectorCriterions();
Expand Down
22 changes: 12 additions & 10 deletions src/Model/gwmlayergtdritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ GwmLayerGTDRItem::GwmLayerGTDRItem(GwmLayerItem* parentItem, QgsVectorLayer* vec
// update mBandwidth
if (!sws.empty())
{
auto* optimizedBw = sws[0].weight<gwm::BandwidthWeight>();
if (optimizedBw)
const auto& coreW = sws[0].weight();
if (coreW)
{
auto& optimizedBw = sws[0].weight<gwm::BandwidthWeight>();
// 更新为优化后的带宽值
mBandwidth->setBandwidth(optimizedBw->bandwidth());
mBandwidth->setAdaptive(optimizedBw->adaptive());
mBandwidth->setKernel(static_cast<GwmBandwidthWeight::KernelFunctionType>(optimizedBw->kernel()));
mBandwidth->setBandwidth(optimizedBw.bandwidth());
mBandwidth->setAdaptive(optimizedBw.adaptive());
mBandwidth->setKernel(static_cast<GwmBandwidthWeight::KernelFunctionType>(optimizedBw.kernel()));
isBandwidthOptimized = true;
}
}
Expand All @@ -57,14 +58,15 @@ GwmLayerGTDRItem::GwmLayerGTDRItem(GwmLayerItem* parentItem, QgsVectorLayer* vec
mBandwidths.reserve(sws.size());
for(int i = 0; i < sws.size(); ++i){
// 从 taskMeta 获取初始值,或从优化后的 spatialWeight 获取
auto* libBw = sws[i].weight<gwm::BandwidthWeight>();
if (libBw)
const auto& coreW = sws[i].weight();
if (coreW)
{
auto& libBw = sws[i].weight<gwm::BandwidthWeight>();
// 创建应用层的带宽权重对象
auto* appBw = new GwmBandwidthWeight(
libBw->bandwidth(),
libBw->adaptive(),
static_cast<GwmBandwidthWeight::KernelFunctionType>(libBw->kernel())
libBw.bandwidth(),
libBw.adaptive(),
static_cast<GwmBandwidthWeight::KernelFunctionType>(libBw.kernel())
);
mBandwidths.append(appBw);
}
Expand Down
11 changes: 10 additions & 1 deletion src/Model/gwmlayergwaverageitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ GwmLayerGWAverageItem::GwmLayerGWAverageItem(GwmLayerItem* parentItem, QgsVector
auto taskMeta = taskThread->meta();
mDataPointsSize = taskMeta.layer->featureCount();
mVariables = taskMeta.variables;
mBandwidth = new gwm::BandwidthWeight(taskMeta.weightBandwidthSize, taskMeta.weightBandwidthAdaptive, gwm::BandwidthWeight::KernelFunctionType(taskMeta.weightBandwidthKernel));
// Use final bandwidth from taskThread (may be updated by autoselect), fallback to meta
gwm::BandwidthWeight finalBw = taskThread->finalBandwidth();
if (finalBw.bandwidth() != 0.0 || finalBw.adaptive())
{
mBandwidth = new gwm::BandwidthWeight(finalBw);
}
else
{
mBandwidth = new gwm::BandwidthWeight(taskMeta.weightBandwidthSize, taskMeta.weightBandwidthAdaptive, gwm::BandwidthWeight::KernelFunctionType(taskMeta.weightBandwidthKernel));
}
mQuantile = taskThread->quantile();
mResultList = taskThread->resultlist();

Expand Down
11 changes: 6 additions & 5 deletions src/Model/gwmlayergwpcaitem.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "gwmlayergwpcaitem.h"
#include "gwmlayergwpcaitem.h"
#include "gwmlayergroupitem.h"

#include <QDir>
Expand All @@ -16,14 +16,15 @@ GwmLayerGWPCAItem::GwmLayerGWPCAItem(GwmLayerItem* parent, QgsVectorLayer* vecto
mK = taskThread->k();

gwm::SpatialWeight sw = taskThread->spatialWeight();
gwm::BandwidthWeight* gwmBw = sw.weight<gwm::BandwidthWeight>();
if (gwmBw)
const auto& coreW = sw.weight();
if (coreW)
{
if(gwmBw->bandwidth() == 0)
gwm::BandwidthWeight& gwmBw = sw.weight<gwm::BandwidthWeight>();
if(gwmBw.bandwidth() == 0)
{
qDebug() << "[GwmLayerGWPCAItem] WARNING: Bandwidth is 0! This will cause display issues in property panel.";
}
mWeight = gwm::BandwidthWeight(*gwmBw);
mWeight = gwm::BandwidthWeight(gwmBw);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Model/gwmlayerscalablegwritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ GwmLayerScalableGWRItem::GwmLayerScalableGWRItem(GwmLayerItem* parent, QgsVector
mDataPointsSize = taskThread->dataLayer()->featureCount();
mDepVar = taskThread->dependentVariable();
mIndepVars = taskThread->independentVariables();
mWeight = gwm::BandwidthWeight(*static_cast<gwm::BandwidthWeight*>(taskThread->spatialWeight().weight()));
mWeight = gwm::BandwidthWeight(taskThread->spatialWeight().weight<gwm::BandwidthWeight>());
mDistanceType = taskThread->spatialWeight().distance()->type();
mDiagnostic = taskThread->diagnostic();
mDiagnostic0 = taskThread->diagnostic0();
Expand Down
6 changes: 6 additions & 0 deletions src/PropertyPanelTabs/gwmpropertygwaveragetab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ void GwmPropertyGWAverageTab::updateUI()
QString bwSizeString = QString("%1 (number of nearest neighbours)").arg(int(weight.bandwidth()));
ui->lblBandwidthSize->setText(bwSizeString);
}
else
{
// for fixed bandwidth show distance value
QString bwSizeString = QString("%1 (distance)").arg(weight.bandwidth(), 0, 'f', 3);
ui->lblBandwidthSize->setText(bwSizeString);
}
ui->lblNumberDataPoints->setText(QString("%1").arg(mLayerItem->dataPointsSize()));
if (true)
{
Expand Down
Loading