📄 view_histogram.cpp
字号:
int iPixel, iStep, nSteps, Maximum, nClasses;
double dPixel, dPixelFont, dz;
wxFont Font;
//-----------------------------------------------------
Draw_Edge(dc, EDGE_STYLE_SIMPLE, r);
Maximum = m_bCumulative
? m_pLayer->Get_Classifier()->Histogram_Get_Total()
: m_pLayer->Get_Classifier()->Histogram_Get_Maximum();
if( Maximum > 0 )
{
Font = dc.GetFont();
Font.SetPointSize((int)(0.7 * dyFont));
dc.SetFont(Font);
//-------------------------------------------------
dPixelFont = dyFont;
if( (dPixel = r.GetHeight() / (double)Maximum) < dPixelFont )
{
dPixel = dPixel * (1 + (int)(dPixelFont / dPixel));
}
nSteps = (int)(r.GetHeight() / dPixel);
dz = Maximum * dPixel / (double)r.GetHeight();
for(iStep=0; iStep<=nSteps; iStep++)
{
iPixel = r.GetBottom() - (int)(dPixel * iStep);
dc.DrawLine(r.GetLeft(), iPixel, r.GetLeft() - 5, iPixel);
Draw_Text(dc, TEXTALIGN_CENTERRIGHT, r.GetLeft() - 7, iPixel,
wxString::Format(wxT("%d"), (int)(iStep * dz))
);
}
//-------------------------------------------------
nClasses = m_pLayer->Get_Classifier()->Get_Class_Count();
dPixelFont = dyFont + 5;
if( (dPixel = r.GetWidth() / (double)nClasses) < dPixelFont )
{
dPixel = dPixel * (1 + (int)(dPixelFont / dPixel));
}
nSteps = (int)(r.GetWidth() / dPixel);
dz = dPixel / (double)r.GetWidth();
if( m_pLayer->Get_Classifier()->Get_Mode() == CLASSIFY_LUT )
{
for(iStep=0; iStep<nSteps; iStep++)
{
iPixel = r.GetLeft() + (int)(dPixel * iStep);
dc.DrawLine(iPixel, r.GetBottom(), iPixel, r.GetBottom() + 5);
Draw_Text(dc, TEXTALIGN_TOPRIGHT, iPixel, r.GetBottom() + 7, 45.0,
m_pLayer->Get_Classifier()->Get_Class_Name((int)(nClasses * iStep * dz))
);
}
}
else
{
double zFactor = m_pLayer->Get_Type() == WKSP_ITEM_Grid ? ((CWKSP_Grid *)m_pLayer)->Get_Grid()->Get_ZFactor() : 1.0;
for(iStep=0; iStep<=nSteps; iStep++)
{
iPixel = r.GetLeft() + (int)(dPixel * iStep);
dc.DrawLine(iPixel, r.GetBottom(), iPixel, r.GetBottom() + 5);
Draw_Text(dc, TEXTALIGN_CENTERRIGHT, iPixel, r.GetBottom() + 7, 45.0,
wxString::Format(wxT("%.*f"), Precision, zFactor * m_pLayer->Get_Classifier()->Get_RelativeToMetric(iStep * dz))
);
}
}
}
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CVIEW_Histogram::On_Mouse_Motion(wxMouseEvent &event)
{
if( m_bMouse_Down )
{
wxClientDC dc(this);
wxRect r(_Draw_Get_rDiagram(wxRect(wxPoint(0, 0), GetClientSize())));
dc.SetLogicalFunction(wxINVERT);
dc.DrawRectangle(m_Mouse_Down.x, r.GetTop(), m_Mouse_Move.x - m_Mouse_Down.x, r.GetHeight());
m_Mouse_Move = event.GetPosition();
dc.DrawRectangle(m_Mouse_Down.x, r.GetTop(), m_Mouse_Move.x - m_Mouse_Down.x, r.GetHeight());
}
}
//---------------------------------------------------------
void CVIEW_Histogram::On_Mouse_LDown(wxMouseEvent &event)
{
if( m_pLayer->Get_Classifier()->Get_Mode() == CLASSIFY_METRIC
|| m_pLayer->Get_Classifier()->Get_Mode() == CLASSIFY_SHADE )
{
m_bMouse_Down = true;
m_Mouse_Move = m_Mouse_Down = event.GetPosition();
CaptureMouse();
}
}
//---------------------------------------------------------
void CVIEW_Histogram::On_Mouse_LUp(wxMouseEvent &event)
{
if( m_bMouse_Down )
{
ReleaseMouse();
m_bMouse_Down = false;
m_Mouse_Move = event.GetPosition();
wxRect r(_Draw_Get_rDiagram(wxRect(wxPoint(0, 0), GetClientSize())));
double zFactor = m_pLayer->Get_Type() == WKSP_ITEM_Grid ? ((CWKSP_Grid *)m_pLayer)->Get_Grid()->Get_ZFactor() : 1.0;
m_pLayer->Set_Color_Range(
zFactor * m_pLayer->Get_Classifier()->Get_RelativeToMetric(
(double)(m_Mouse_Down.x - r.GetLeft()) / (double)r.GetWidth()),
zFactor * m_pLayer->Get_Classifier()->Get_RelativeToMetric(
(double)(m_Mouse_Move.x - r.GetLeft()) / (double)r.GetWidth())
);
}
}
//---------------------------------------------------------
void CVIEW_Histogram::On_Mouse_RDown(wxMouseEvent &event)
{
double zMin, zMax;
if( m_pLayer->Get_Classifier()->Get_Mode() == CLASSIFY_METRIC
|| m_pLayer->Get_Classifier()->Get_Mode() == CLASSIFY_SHADE )
{
switch( m_pLayer->Get_Type() )
{
default:
break;
case WKSP_ITEM_Grid:
zMin = ((CWKSP_Grid *)m_pLayer)->Get_Grid()->Get_ZMin(true);
zMax = ((CWKSP_Grid *)m_pLayer)->Get_Grid()->Get_ZMax(true);
m_pLayer->Set_Color_Range(zMin, zMax);
break;
case WKSP_ITEM_Shapes:
break;
}
}
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CVIEW_Histogram::On_Command_UI(wxUpdateUIEvent &event)
{
switch( event.GetId() )
{
case ID_CMD_HISTOGRAM_CUMULATIVE:
On_Cumulative_UI(event);
break;
}
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CVIEW_Histogram::On_Cumulative(wxCommandEvent &event)
{
m_bCumulative = !m_bCumulative;
Refresh();
}
void CVIEW_Histogram::On_Cumulative_UI(wxUpdateUIEvent &event)
{
event.Check(m_bCumulative);
}
//---------------------------------------------------------
void CVIEW_Histogram::On_AsTable(wxCommandEvent &event)
{
int i, n;
CSG_Table *pTable;
CSG_Table_Record *pRecord;
if( (n = m_pLayer->Get_Classifier()->Get_Class_Count()) > 0 )
{
pTable = new CSG_Table;
pTable->Set_Name(wxString::Format(wxT("%s: %s"), LNG("[CAP] Histogram"), m_pLayer->Get_Name().c_str()));
pTable->Add_Field(LNG("CLASS") , TABLE_FIELDTYPE_Int);
pTable->Add_Field(LNG("COUNT") , TABLE_FIELDTYPE_Int);
pTable->Add_Field(LNG("NAME") , TABLE_FIELDTYPE_String);
for(i=0; i<n; i++)
{
pRecord = pTable->Add_Record();
pRecord->Set_Value(0, i + 1);
pRecord->Set_Value(1, m_pLayer->Get_Classifier()->Histogram_Get_Count(i, false));
pRecord->Set_Value(2, m_pLayer->Get_Classifier()->Get_Class_Name(i).c_str());
}
g_pData->Add(pTable);
}
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CVIEW_Histogram::Update_Histogram(void)
{
bool bResult = m_pLayer->Get_Classifier()->Histogram_Update();
Refresh();
return( bResult );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -