📄 graphcutview.cpp
字号:
// GraphCutView.cpp : implementation of the CGraphCutView class
//
#include "stdafx.h"
#include "GraphCut.h"
#include "GraphCutDoc.h"
#include "GraphCutView.h"
#include "Energy.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGraphCutView
IMPLEMENT_DYNCREATE(CGraphCutView, CView)
BEGIN_MESSAGE_MAP(CGraphCutView, CView)
//{{AFX_MSG_MAP(CGraphCutView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGraphCutView construction/destruction
CGraphCutView::CGraphCutView()
{
// TODO: add construction code here
// Minimize the following function of 3 binary variables:
// E(x, y, z) = x - 2*y + 3*(1-z) - 4*x*y + 5*|y-z|
Energy::Var varx, vary, varz;
Energy *e = new Energy();
varx = e -> add_variable();
vary = e -> add_variable();
varz = e -> add_variable();
e -> add_term1(varx, 0, 1); // add term x
e -> add_term1(vary, 0, -2); // add term -2*y
e -> add_term1(varz, 3, 0); // add term 3*(1-z)
e -> add_term2(varx, vary, 0, 0, 0, -4); // add term -4*x*y
e -> add_term2(vary, varz, 0, 5, 5, 0); // add term 5*|y-z|
Energy::TotalValue Emin = e -> minimize();
printf("Minimum = %d\n", Emin);
printf("Optimal solution:\n");
printf("x = %d\n", e->get_var(varx));
printf("y = %d\n", e->get_var(vary));
printf("z = %d\n", e->get_var(varz));
delete e;
}
CGraphCutView::~CGraphCutView()
{
}
BOOL CGraphCutView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CGraphCutView drawing
void CGraphCutView::OnDraw(CDC* pDC)
{
CGraphCutDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CGraphCutView printing
BOOL CGraphCutView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CGraphCutView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CGraphCutView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CGraphCutView diagnostics
#ifdef _DEBUG
void CGraphCutView::AssertValid() const
{
CView::AssertValid();
}
void CGraphCutView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CGraphCutDoc* CGraphCutView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGraphCutDoc)));
return (CGraphCutDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGraphCutView message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -