From: <hug...@li...> - 2011-08-10 21:52:17
|
branch: gsoc2011_onomou details: http://hugin.hg.sourceforge.net/hgweb/hugin/hugin/hgrepo/h/hu/hugin/hugin/rev/f0f1f7abd02d changeset: 5477:f0f1f7abd02d user: onomou <on...@gm...> date: Sun Jul 17 01:45:13 2011 -0700 description: New: add control points along lines when a new line pair is created diffstat: src/hugin1/hugin/CPEditorPanel.cpp | 71 +++++++++++++++++++++++++++++-------- src/hugin1/hugin/CPEditorPanel.h | 9 +++- src/hugin1/hugin/CPImageCtrl.cpp | 46 ++++++++++------------- src/hugin1/hugin/CPImageCtrl.h | 6 ++- src/hugin1/hugin/CPSharedStructs.h | 3 +- 5 files changed, 88 insertions(+), 47 deletions(-) diffs (277 lines): diff -r 6df666909a91 -r f0f1f7abd02d src/hugin1/hugin/CPEditorPanel.cpp --- a/src/hugin1/hugin/CPEditorPanel.cpp Fri Jul 15 19:51:08 2011 -0700 +++ b/src/hugin1/hugin/CPEditorPanel.cpp Sun Jul 17 01:45:13 2011 -0700 @@ -687,6 +687,39 @@ #endif } +void CPEditorPanel::AddLinePoints() +{ + // todo: add check for leftNr == rightNr + ControlPoint point; + point.mode = PT::ControlPoint::X_Y; + StraightLine line1 = m_leftImg->getNewLine(); + StraightLine line2 = m_rightImg->getNewLine(); + //changeState(NO_POINT); // ? + DEBUG_DEBUG("AddLinePoints(): " << line1.points.size() << " points from the new line pair"); + for (int i = 0; i < line1.points.size(); i++) { + point.image1Nr = m_leftImageNr; point.image2Nr = m_rightImageNr; + point.x1 = line1.points[i].x; point.x2 = line2.points[i].x; + point.y1 = line1.points[i].y; point.y2 = line2.points[i].y; + + // todo: track points added for later line editing + //PT::AddCtrlPointCmd(*m_pano, point); + GlobalCmdHist::getInstance().addCommand( + new PT::AddCtrlPointCmd(*m_pano, point) + ); + } + // todo: history + // GlobalCmdHist::getInstance().addCommand( + // new PT::AddCtrlPointCmd(*m_pano, point) + // ); + + changeState(NO_POINT); + MainFrame::Get()->SetStatusText(_("new control point added")); +#ifdef HUGIN_CP_IMG_CHOICE + m_leftChoice->CalcCPDistance(m_pano); + m_rightChoice->CalcCPDistance(m_pano); +#endif +} + const float CPEditorPanel::getVerticalCPBias() { @@ -1308,19 +1341,12 @@ //tempPair.img1Lines.clear(); //tempPair.img2Lines.clear(); UpdateDisplay(false); + + + AddLinePoints(); } } -void CPEditorPanel::SelectLine(unsigned int nr) -{ - m_leftImg->selectLine(nr); - m_rightImg->selectLine(nr); - m_selectedLine = nr; - m_lineList->SetItemState(m_selectedLine, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); - //m_lineList->SetItemState(nr, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); - m_lineList->EnsureVisible(nr); -} - void CPEditorPanel::panoramaChanged(PT::Panorama &pano) { int nGui = m_cpModeChoice->GetCount(); @@ -1918,19 +1944,15 @@ //OnCPListDeselect(ev); int t = ev.GetIndex(); DEBUG_DEBUG("Line selected: " << t); - if (t >=0) { - SelectLine((unsigned int) t); - } changeState(NO_POINT); + changeLineState(t); //UpdateDisplay(false); } void CPEditorPanel::OnLineListDeselect(wxListEvent & ev) { - // disable CP controls - m_lineList->SetItemState(m_selectedLine, 0, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);//wxLIST_STATE_SELECTED); - m_selectedLine = UINT_MAX; changeState(NO_POINT); + changeLineState(-1); UpdateDisplay(false); } @@ -2335,6 +2357,23 @@ cpCreationState = newState; } +void CPEditorPanel::changeLineState(int imgNr) +{ + if( imgNr < 0) { // unselect lines + m_leftImg->deselectLine(); + m_rightImg->deselectLine(); + m_selectedLine = UINT_MAX; + m_lineList->SetItemState(m_selectedLine, 0, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);//wxLIST_STATE_SELECTED) only? + } else { + m_leftImg->selectLine(imgNr); + m_rightImg->selectLine(imgNr); + m_selectedLine = imgNr; + m_lineList->SetItemState(m_selectedLine, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); + //m_lineList->SetItemState(imgNr, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); + m_lineList->EnsureVisible(imgNr); + } +} + void CPEditorPanel::OnPrevImg(wxCommandEvent & e) { if (m_pano->getNrOfImages() < 2) return; diff -r 6df666909a91 -r f0f1f7abd02d src/hugin1/hugin/CPEditorPanel.h --- a/src/hugin1/hugin/CPEditorPanel.h Fri Jul 15 19:51:08 2011 -0700 +++ b/src/hugin1/hugin/CPEditorPanel.h Sun Jul 17 01:45:13 2011 -0700 @@ -156,13 +156,13 @@ // function called when a new line is added void NewLineAdded(StraightLine l, bool left); - - // select a line - void SelectLine(unsigned int nr); /// this is used to finally create the point in the panorama model void CreateNewPoint(); + // adds the points along a line to the panorama model + // ? should this be using the StraightLine returned on the CPevent fire ? + void AddLinePoints(); /// search for region in destImg // bool FindTemplate(unsigned int tmplImgNr, const wxRect ®ion, unsigned int dstImgNr, vigra_ext::CorrelationResult & res); @@ -250,6 +250,9 @@ }; // used to change the point selection state void changeState(CPCreationState newState); + + // used to change the line selection state + void changeLineState(int imgNr); /** estimate and set point in other image */ void estimateAndAddOtherPoint(const hugin_utils::FDiff2D & p, diff -r 6df666909a91 -r f0f1f7abd02d src/hugin1/hugin/CPImageCtrl.cpp --- a/src/hugin1/hugin/CPImageCtrl.cpp Fri Jul 15 19:51:08 2011 -0700 +++ b/src/hugin1/hugin/CPImageCtrl.cpp Sun Jul 17 01:45:13 2011 -0700 @@ -561,30 +561,6 @@ void CPImageCtrl::drawLine(wxDC & dc, const StraightLine l, bool selected) { - /* - wxBrush brush; - wxColour color; - - const char* str = "RGB(0,0,255)"; // blue - const char* hlt = "RGB(128,0,128)"; // purple? - wxString wxstr(str,wxConvUTF8); - wxString hlstr(hlt,wxConvUTF8); - if( selected ) - color = hlstr; - else - color = wxstr; - brush.SetColour(color); - dc.SetBrush(brush); - //dc.SetBrush(*wxTRANSPARENT_BRUSH); - wxPen pen; - pen.SetColour(color); - pen.SetStyle(wxSOLID); - if( selected ) - pen.SetWidth(4); - else - pen.SetWidth(2); - dc.SetPen(pen); - */ wxString color; if( selected ) color = wxT("CYAN"); @@ -664,9 +640,13 @@ //dc.DrawCircle(roundP(center),(int)radius); drawPoint(dc, invScale(applyRotInv(dropPoint)), 4, false); + newLine.points.clear(); + newLine.points.push_back(dropPoint); for( int i = 0; i <= 10; i++ ) { + // todo: change circle color for selected CPs dropPoint.x = radius * cos( thetaStart + i*step ) + center.x; dropPoint.y = radius * sin( thetaStart + i*step ) + center.y; + newLine.points.push_back(applyRotInv(invScale(dropPoint))); //drawPoint(dc, invScale(applyRotInv(dropPoint)), 0, false); dc.DrawLine( hugin_utils::roundi(prevx), hugin_utils::roundi(prevy), hugin_utils::roundi(dropPoint.x), hugin_utils::roundi(dropPoint.y) ); @@ -734,7 +714,7 @@ { bool sel = false; DEBUG_DEBUG("Drawing all " << lines.size() << " lines"); - for( unsigned int i = 0; i < lines.size(); i++ ) { + for( int i = 0; i < (int)lines.size(); i++ ) { if( i == selectedLineNr ) sel = true; drawLine( dc, lines[i], sel ); @@ -1072,7 +1052,13 @@ void CPImageCtrl::selectLine(unsigned int nr) { - selectedLineNr = nr; + selectedLineNr = (int)nr; + update(); +} + +void CPImageCtrl::deselectLine() +{ + selectedLineNr = -1; update(); } @@ -1466,6 +1452,7 @@ newLine.end = mpos; //editState = NO_SELECTION; lineState = THREE_POINTS; + selectedLineNr = -1; DEBUG_DEBUG("Switch lineState to THREE_POINTS"); CPEvent e( this, newLine ); // emit newLine event emit(e); @@ -1822,6 +1809,13 @@ return newPoint; } +StraightLine CPImageCtrl::getNewLine() +{ + // only possible if a new line is actually selected + // are there two newLine things being returned? + // DEBUG_ASSERT(editState == NEW_LINE); + return newLine; +} void CPImageCtrl::setNewPoint(const FDiff2D & p) { DEBUG_DEBUG("setting new point " << p.x << "," << p.y); diff -r 6df666909a91 -r f0f1f7abd02d src/hugin1/hugin/CPImageCtrl.h --- a/src/hugin1/hugin/CPImageCtrl.h Fri Jul 15 19:51:08 2011 -0700 +++ b/src/hugin1/hugin/CPImageCtrl.h Sun Jul 17 01:45:13 2011 -0700 @@ -158,6 +158,7 @@ void startNewLine(); void cancelNewLine(); void selectLine(unsigned int); + void deselectLine(); /// select a point for usage void selectPoint(unsigned int); @@ -205,6 +206,9 @@ /// get the new point hugin_utils::FDiff2D getNewPoint(); + /// get the new line + StraightLine getNewLine(); + /// initiate redraw void update(); @@ -262,7 +266,7 @@ std::vector<StraightLine> lines; StraightLine newLine; bool dimOverlay; // not useful currently - unsigned int selectedLineNr; + int selectedLineNr; bool findCircle(double startx, double starty, double midx, double midy, double endx, double endy, hugin_utils::FDiff2D ¢er, double &radius); double determinant(double a, double b, double c, double d, double e, double f, double g, double h, double i); diff -r 6df666909a91 -r f0f1f7abd02d src/hugin1/hugin/CPSharedStructs.h --- a/src/hugin1/hugin/CPSharedStructs.h Fri Jul 15 19:51:08 2011 -0700 +++ b/src/hugin1/hugin/CPSharedStructs.h Sun Jul 17 01:45:13 2011 -0700 @@ -2,5 +2,6 @@ { hugin_utils::FDiff2D start, mid, end; bool startSet, midSet, endSet; - StraightLine(): startSet(false), midSet(false), endSet(false) { } // constructor + std::vector<hugin_utils::FDiff2D> points; + StraightLine(): startSet(false), midSet(false), endSet(false) { } // constructor: falsify booleans }; |