//---------------------------------------------------------
void CVariogram_Dialog::Set_Variogram(void)
{
	double	lagDist	= m_Settings("LAGDIST")->asDouble();
	double	maxDist	= m_Settings("MAXDIST")->asDouble();

	if( lagDist > 0.0 )
	{
		double	Diagonal	= SG_Get_Length(m_pPoints->Get_Extent().Get_XRange(), m_pPoints->Get_Extent().Get_YRange());	// bounding box's diagonal

		if( maxDist <= 0.0 || maxDist > Diagonal )
		{
			m_Settings("MAXDIST")->Set_Value(maxDist = Diagonal);
		}

		CSG_Variogram::Calculate(m_pPoints, m_Attribute, m_bLog, m_pVariogram,
			1 + (int)(0.5 + maxDist / lagDist), maxDist, m_Settings("SKIP")->asInt()
		);

		m_pDistance->Set_Range(0.0, m_pVariogram->Get_Maximum(CSG_Variogram::FIELD_DISTANCE));
		m_pDistance->Set_Value(m_pVariogram->Get_Maximum(CSG_Variogram::FIELD_DISTANCE));

		m_pDiagram->Set_Variogram();

		Set_Model();
	}
}
//---------------------------------------------------------
bool CVariogram_Dialog::Execute(CSG_Shapes *pPoints, int Attribute, bool bLog, CSG_Table *pVariogram, CSG_Trend *pModel)
{
	if( m_pPoints != pPoints || m_nPoints != pPoints->Get_Count() || !m_Extent.is_Equal(pPoints->Get_Extent()) )
	{
		m_pPoints	= pPoints;
		m_nPoints	= pPoints->Get_Count();
		m_Extent	= pPoints->Get_Extent();
		m_Distance	= -1;

		int	nSkip	= 1 + m_pPoints->Get_Count() / 10000;

		m_Settings("SKIP"   )->Set_Value(nSkip);
		m_Settings("LAGDIST")->Set_Value(CSG_Variogram::Get_Lag_Distance(m_pPoints, 0, nSkip));
		m_Settings("MAXDIST")->Set_Value(0.5 * sqrt(SG_Get_Square(m_pPoints->Get_Extent().Get_XRange()) + SG_Get_Square(m_pPoints->Get_Extent().Get_YRange())));
	}

	m_Attribute		= Attribute;
	m_bLog			= bLog;
	m_pVariogram	= pVariogram;
	m_pModel		= pModel;

	m_pDiagram->Initialize(m_pModel, m_pVariogram);

	//-----------------------------------------------------
	Set_Variogram();

	return( ShowModal() == wxID_OK && m_pModel && m_pModel->is_Okay() );
}
//---------------------------------------------------------
void CVariogram_Dialog::Set_Model(void)
{
	//-----------------------------------------------------
	if( m_Distance < 0 || m_Distance != m_pDistance->Get_Value() )
	{
		m_Distance	= m_pDistance->Get_Value();

		m_pModel->Clr_Data();

		for(int i=0; i<m_pVariogram->Get_Count(); i++)
		{
			CSG_Table_Record	*pRecord	= m_pVariogram->Get_Record(i);

			if( pRecord->asDouble(CSG_Variogram::FIELD_DISTANCE) <= m_Distance )
			{
				m_pModel->Add_Data(pRecord->asDouble(CSG_Variogram::FIELD_DISTANCE), pRecord->asDouble(CSG_Variogram::FIELD_VAR_EXP));
			}
		}

		m_pModel->Get_Trend();
	}

	//-----------------------------------------------------
	wxString	s;

	if(	!m_pModel->Set_Formula(m_pFormula->GetValue().c_str()) )
	{
		s	+= m_pModel->Get_Error().w_str();
	}
	else if( !m_pModel->Get_Trend() )
	{
		s	+= _TL("function fitting failed !");
	}
	else
	{
		s	+= m_pModel->Get_Formula(SG_TREND_STRING_Function).w_str();
		s	+= wxString::Format(wxT("\n%s:\t%.2f%%"), _TL("Determination")		, m_pModel->Get_R2() * 100.0);
		s	+= wxString::Format(wxT("\n%s:\t%.*f")	, _TL("Fitting range")		, SG_Get_Significant_Decimals(m_pDistance->Get_Value()), m_pDistance->Get_Value());
		s	+= wxString::Format(wxT("\n%s:\t%d")	, _TL("Samples in range")	, m_pModel->Get_Data_Count());
		s	+= wxString::Format(wxT("\n%s:\t%d")	, _TL("Lag Classes")		, m_pVariogram->Get_Count());
		s	+= wxString::Format(wxT("\n%s:\t%.2f")	, _TL("Lag Distance")		, m_Settings("LAGDIST")->asDouble());
		s	+= wxString::Format(wxT("\n%s:\t%.2f")	, _TL("Maximum Distance")	, m_Settings("MAXDIST")->asDouble());

		m_Settings("MODEL")->Set_Value(m_pModel->Get_Formula(SG_TREND_STRING_Formula));
	}

	m_pParameters->SetValue(s);

	m_pDiagram->m_bPairs	= m_pPairs->GetValue();

	m_pDiagram->Refresh(true);
}
//---------------------------------------------------------
void CVariogram_Dialog::On_Button(wxCommandEvent &event)
{
	if( event.GetEventObject() == m_pSettings )
	{
		if( SG_UI_Dlg_Parameters(&m_Settings, m_Settings.Get_Name()) )
		{
			m_pFormula ->SetValue (m_Settings("MODEL")  ->asString());

			Set_Variogram();
		}
	}
	else
	{
		event.Skip();
	}
}
Пример #5
0
//---------------------------------------------------------
void CPoints_View_Dialog::On_Update_Choices(wxCommandEvent &event)
{
	if( event.GetEventObject() == m_pField_Z )
	{
		m_pView		->m_zField	= m_pField_Z	->GetSelection();

		m_pView		->Update_View();
	}

	else if( event.GetEventObject() == m_pField_Color )
	{
		m_Settings("C_RANGE")->asRange()->Set_Range(0.0, 0.0);

		m_pExtent	->m_cField	= m_pField_Color->GetSelection();
		m_pView		->m_cField	= m_pField_Color->GetSelection();

		m_pExtent	->Update_View();
		m_pView		->Update_Extent(m_pExtent->Get_Extent());
	}
	else
	{
		return;
	}
}
//---------------------------------------------------------
bool CPoints_View_Extent::_Draw_Image(void)
{
	if( m_pPoints->Get_Count() <= 0 || m_pPoints->Get_Extent().Get_XRange() <= 0.0 || m_pPoints->Get_Extent().Get_YRange() <= 0.0
	||	m_cField < 0 || m_cField >= m_pPoints->Get_Field_Count() )
	{
		return( false );
	}

	//-------------------------------------------------
	wxSize		Size;
	double		dx, dy;

	Size		= GetClientSize();

	if (Size.x <= 0 || Size.y <= 0)	// temporary hack for wxGTK to suppress 'assert "isOK()" failed in Get_Height(): invalid image'
		return( false );			// when dlg.ShowModal() is called; during construction everything is fine, but the first call of
									// the On_Size() event returns a client size of 0

	m_Image			.Create(Size.x, Size.y);
	m_Image_Value	.Create(Size.x, Size.y);
	m_Image_Count	.Create(Size.x, Size.y);

	//-------------------------------------------------
	m_Extent	= m_pPoints->Get_Extent();

	if( (dx = Size.y / (double)Size.x) < (m_Extent.Get_YRange() / m_Extent.Get_XRange()) )
	{
		dx	= 0.5 * (m_Extent.Get_XRange() - m_Extent.Get_YRange() / dx);
		m_Extent.m_rect.xMin	+= dx;
		m_Extent.m_rect.xMax	-= dx;
	}
	else
	{
		dy	= 0.5 * (m_Extent.Get_YRange() - m_Extent.Get_XRange() * dx);
		m_Extent.m_rect.yMin	+= dy;
		m_Extent.m_rect.yMax	-= dy;
	}

	dx	= Size.x / m_Extent.Get_XRange();
	dy	= Size.y / m_Extent.Get_YRange();

	//-------------------------------------------------
	bool	bColorAsRGB	= m_Settings("C_AS_RGB")->asBool();

	for(int i=0; i<m_pPoints->Get_Count(); i++)
	{
		TSG_Point_Z	p	= m_pPoints->Get_Point(i);	p.z	= m_pPoints->Get_Value(i, m_cField);

		int	ix	= (p.x - m_Extent.Get_XMin()) * dx;
		int	iy	= (p.y - m_Extent.Get_YMin()) * dy;

		if( ix >= 0 && ix <= m_Image.GetWidth() && iy >= 0 && iy < m_Image.GetHeight() )
		{
			if( !bColorAsRGB )
			{
				m_Image_Value[iy][ix]	+= p.z;
			}
			else
			{
				m_Image_Value[iy][ix]	 = p.z;
			}

			m_Image_Count[iy][ix]++;
		}
	}

	//-------------------------------------------------
	double	zMin	= m_pPoints->Get_Mean(m_cField) - 1.5 * m_pPoints->Get_StdDev(m_cField);
	double	zRange	= m_pPoints->Get_Mean(m_cField) + 1.5 * m_pPoints->Get_StdDev(m_cField) - zMin;

	CSG_Colors	*pColors	= m_Settings("COLORS")->asColors();

	for(int iy=0; iy<m_Image.GetHeight(); iy++)
	{
		for(int ix=0; ix<m_Image.GetWidth(); ix++)
		{
			if( m_Image_Count[iy][ix] > 0 )
			{
				if( !bColorAsRGB )
				{
					int	ic	= (int)(pColors->Get_Count() * (m_Image_Value[iy][ix] / m_Image_Count[iy][ix] - zMin) / zRange);
					int	c	= pColors->Get_Color(ic < 0 ? 0 : ic >= pColors->Get_Count() ? pColors->Get_Count() - 1 : ic);

					_Draw_Pixel(ix, iy, c);
				}
				else
				{
					_Draw_Pixel(ix, iy, m_Image_Value[iy][ix]);
				}
			}
			else
			{
				_Draw_Pixel(ix, iy, 0);
			}
		}
	}

	return( true );
}