/* * Updates the historic of a garbage with the new detection of it * */ void GarbageHistoric::updateHistoricWithGarbage(Garbage * movedGarbage){ std::vector<int> newCentroid (movedGarbage->getCentroid()); std::vector<int> previousCentroid (this->currentPos); //update stats (found) this->lastAppeareance=age; this->age++; this->appeareances++; //update position int deltax=newCentroid[0]-previousCentroid[0]; int deltay=newCentroid[1]-previousCentroid[1]; this->deltaPos[0]=deltax; this->deltaPos[1]=deltay; this->currentPos[0]=newCentroid[0]; this->currentPos[1]=newCentroid[1]; //update garbage delete this->garbage; this->garbage=movedGarbage; }
Garbage * GarbageHistoric::guessPosition(){ //assumes linear movement using last known delta/position std::vector<int> newCentroid (2,0); std::vector<int> centroid (this->garbage->getCentroid()); std::vector<int> delta (this->deltaPos); int factor=(this->age - this->lastAppeareance); if(factor<=1){ return this->garbage; } int deltax=(factor-1)*delta[0]; int deltay=(factor-1)*delta[1]; newCentroid[0]=centroid[0] +deltax; newCentroid[1]=centroid[1] +deltay; MinimalBoundingRectangle * oldMbr=this->garbage->boundingBox(); int x=oldMbr->x; int y=oldMbr->y; int h=oldMbr->getHeight(); int w=oldMbr->getWidth(); MinimalBoundingRectangle * mbr= new MinimalBoundingRectangle(x+deltax,y+deltay,w,h); Garbage * newGarbage=new Garbage(mbr,newCentroid); //benchmark purposes newGarbage->isFocused=this->garbage->isFocused; newGarbage->isPredicted=this->garbage->isPredicted; newGarbage->isVisualized=this->garbage->isVisualized; return newGarbage; }
bool GarbageHistoric::isSameObject(Garbage * foundGarbage){ //tells if a newGarbage is similar to that found in previous frames std::vector<int> newCentroid (foundGarbage->getCentroid()); std::vector<int> previousCentroid (this->currentPos); int factor=DELTA_MOVEMENT_FACTOR*(this->age - this->lastAppeareance); //garbage has to be in previous centroid +- deltaPos int deltax=newCentroid[0]-previousCentroid[0]; int deltay=newCentroid[1]-previousCentroid[1]; int toleranceX=factor*fabs(deltaPos[0]) < PREDICTION_DELTA ? PREDICTION_DELTA : factor*fabs(deltaPos[0]); int toleranceY=factor*fabs(deltaPos[1]) < PREDICTION_DELTA ? PREDICTION_DELTA : factor*fabs(deltaPos[1]); if(fabs(deltax)<toleranceX && fabs(deltay)<toleranceY){ if(compareContour(foundGarbage)) return true; } return false; }
void QgsGrassEdit::keyPress( QKeyEvent *e ) { QgsDebugMsg( "entered." ); // This does not work: //keyPressEvent(e); // TODO: this is not optimal switch ( e->key() ) { case Qt::Key_F1: newPoint(); break; case Qt::Key_F2: newLine(); break; case Qt::Key_F3: newBoundary(); break; case Qt::Key_F4: newCentroid(); break; case Qt::Key_F5: moveVertex(); break; case Qt::Key_F6: addVertex(); break; case Qt::Key_F7: deleteVertex(); break; case Qt::Key_F9: moveLine(); break; case Qt::Key_F10: splitLine(); break; case Qt::Key_F11: deleteLine(); break; default: break; } }
void QgsGrassEdit::init() { if ( !( mProvider->isGrassEditable() ) ) { QMessageBox::warning( 0, tr( "Warning" ), tr( "You are not owner of the mapset, cannot open the vector for editing." ) ); return; } if ( !( mProvider->startEdit() ) ) { QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open vector for update." ) ); return; } mRubberBandLine = new QgsRubberBand( mCanvas ); mRubberBandIcon = new QgsVertexMarker( mCanvas ); mRubberBandLine->setZValue( 20 ); mRubberBandIcon->setZValue( 20 ); connect( mCanvas, SIGNAL( keyPressed( QKeyEvent * ) ), this, SLOT( keyPress( QKeyEvent * ) ) ); mToolBar = addToolBar( tr( "Edit tools" ) ); mNewPointAction = new QAction( QgsGrassPlugin::getThemeIcon( "grass_new_point.png" ), tr( "New point" ), this ); mNewPointAction->setShortcut( QKeySequence( Qt::Key_F1 ) ); mToolBar->addAction( mNewPointAction ); connect( mNewPointAction, SIGNAL( triggered() ), this, SLOT( newPoint() ) ); mNewLineAction = new QAction( QgsGrassPlugin::getThemeIcon( "grass_new_line.png" ), tr( "New line" ), this ); mNewLineAction->setShortcut( QKeySequence( Qt::Key_F2 ) ); mToolBar->addAction( mNewLineAction ); connect( mNewLineAction, SIGNAL( triggered() ), this, SLOT( newLine() ) ); mNewBoundaryAction = new QAction( QgsGrassPlugin::getThemeIcon( "grass_new_boundary.png" ), tr( "New boundary" ), this ); mNewBoundaryAction->setShortcut( QKeySequence( Qt::Key_F3 ) ); mToolBar->addAction( mNewBoundaryAction ); connect( mNewBoundaryAction, SIGNAL( triggered() ), this, SLOT( newBoundary() ) ); mNewCentroidAction = new QAction( QgsGrassPlugin::getThemeIcon( "grass_new_centroid.png" ), tr( "New centroid" ), this ); mNewCentroidAction->setShortcut( QKeySequence( Qt::Key_F4 ) ); mToolBar->addAction( mNewCentroidAction ); connect( mNewCentroidAction, SIGNAL( triggered() ), this, SLOT( newCentroid() ) ); mMoveVertexAction = new QAction( QgsGrassPlugin::getThemeIcon( "grass_move_vertex.png" ), tr( "Move vertex" ), this ); mMoveVertexAction->setShortcut( QKeySequence( Qt::Key_F5 ) ); mToolBar->addAction( mMoveVertexAction ); connect( mMoveVertexAction, SIGNAL( triggered() ), this, SLOT( moveVertex() ) ); mAddVertexAction = new QAction( QgsGrassPlugin::getThemeIcon( "grass_add_vertex.png" ), tr( "Add vertex" ), this ); mAddVertexAction->setShortcut( QKeySequence( Qt::Key_F6 ) ); mToolBar->addAction( mAddVertexAction ); connect( mAddVertexAction, SIGNAL( triggered() ), this, SLOT( addVertex() ) ); mDeleteVertexAction = new QAction( QgsGrassPlugin::getThemeIcon( "grass_delete_vertex.png" ), tr( "Delete vertex" ), this ); mDeleteVertexAction->setShortcut( QKeySequence( Qt::Key_F7 ) ); mToolBar->addAction( mDeleteVertexAction ); connect( mDeleteVertexAction, SIGNAL( triggered() ), this, SLOT( deleteVertex() ) ); mMoveLineAction = new QAction( QgsGrassPlugin::getThemeIcon( "grass_move_line.png" ), tr( "Move element" ), this ); mMoveLineAction->setShortcut( QKeySequence( Qt::Key_F9 ) ); mToolBar->addAction( mMoveLineAction ); connect( mMoveLineAction, SIGNAL( triggered() ), this, SLOT( moveLine() ) ); mSplitLineAction = new QAction( QgsGrassPlugin::getThemeIcon( "grass_split_line.png" ), tr( "Split line" ), this ); mSplitLineAction->setShortcut( QKeySequence( Qt::Key_F10 ) ); mToolBar->addAction( mSplitLineAction ); connect( mSplitLineAction, SIGNAL( triggered() ), this, SLOT( splitLine() ) ); mDeleteLineAction = new QAction( QgsGrassPlugin::getThemeIcon( "grass_delete_line.png" ), tr( "Delete element" ), this ); mDeleteLineAction->setShortcut( QKeySequence( Qt::Key_F11 ) ); mToolBar->addAction( mDeleteLineAction ); connect( mDeleteLineAction, SIGNAL( triggered() ), this, SLOT( deleteLine() ) ); mEditAttributesAction = new QAction( QgsGrassPlugin::getThemeIcon( "grass_edit_attributes.png" ), tr( "Edit attributes" ), this ); mToolBar->addAction( mEditAttributesAction ); connect( mEditAttributesAction, SIGNAL( triggered() ), this, SLOT( editAttributes() ) ); mCloseEditAction = new QAction( QgsGrassPlugin::getThemeIcon( "grass_close_edit.png" ), tr( "Close" ), this ); mToolBar->addAction( mCloseEditAction ); connect( mCloseEditAction, SIGNAL( triggered() ), this, SLOT( closeEdit() ) ); mNewPointAction->setCheckable( true ); mNewLineAction->setCheckable( true ); mNewBoundaryAction->setCheckable( true ); mNewCentroidAction->setCheckable( true ); mMoveVertexAction->setCheckable( true ); mAddVertexAction->setCheckable( true ); mDeleteVertexAction->setCheckable( true ); mMoveLineAction->setCheckable( true ); mSplitLineAction->setCheckable( true ); mDeleteLineAction->setCheckable( true ); mEditAttributesAction->setCheckable( true ); QActionGroup *ag = new QActionGroup( this ); ag->addAction( mNewPointAction ); ag->addAction( mNewLineAction ); ag->addAction( mNewBoundaryAction ); ag->addAction( mNewCentroidAction ); ag->addAction( mMoveVertexAction ); ag->addAction( mAddVertexAction ); ag->addAction( mDeleteVertexAction ); ag->addAction( mMoveLineAction ); ag->addAction( mSplitLineAction ); ag->addAction( mDeleteLineAction ); ag->addAction( mEditAttributesAction ); mEditPoints = Vect_new_line_struct(); mPoints = Vect_new_line_struct(); mCats = Vect_new_cats_struct(); // Set lines symbology from map int nlines = mProvider->numLines(); mLineSymb.resize( nlines + 1000 ); for ( int line = 1; line <= nlines; line++ ) { mLineSymb[line] = lineSymbFromMap( line ); } // Set nodes symbology from map int nnodes = mProvider->numNodes(); mNodeSymb.resize( nnodes + 1000 ); for ( int node = 1; node <= nnodes; node++ ) { mNodeSymb[node] = nodeSymbFromMap( node ); } // Set default colors mSymb.resize( SYMB_COUNT ); mSymb[SYMB_BACKGROUND].setColor( QColor( 255, 255, 255 ) ); // white mSymb[SYMB_HIGHLIGHT].setColor( QColor( 255, 255, 0 ) ); // yellow mSymb[SYMB_DYNAMIC].setColor( QColor( 125, 125, 125 ) ); // grey mSymb[SYMB_POINT].setColor( QColor( 0, 0, 0 ) ); // black mSymb[SYMB_LINE].setColor( QColor( 0, 0, 0 ) ); // black mSymb[SYMB_BOUNDARY_0].setColor( QColor( 255, 0, 0 ) ); // red mSymb[SYMB_BOUNDARY_1].setColor( QColor( 255, 125, 0 ) ); // orange mSymb[SYMB_BOUNDARY_2].setColor( QColor( 0, 255, 0 ) ); // green mSymb[SYMB_CENTROID_IN].setColor( QColor( 0, 255, 0 ) ); // green mSymb[SYMB_CENTROID_OUT].setColor( QColor( 255, 0, 0 ) ); // red mSymb[SYMB_CENTROID_DUPL].setColor( QColor( 255, 0, 255 ) ); // magenta mSymb[SYMB_NODE_1].setColor( QColor( 255, 0, 0 ) ); // red mSymb[SYMB_NODE_2].setColor( QColor( 0, 255, 0 ) ); // green // Set mSymbDisplay mSymbDisplay.resize( SYMB_COUNT ); mSymbDisplay[SYMB_BACKGROUND] = true; mSymbDisplay[SYMB_HIGHLIGHT] = true; mSymbDisplay[SYMB_DYNAMIC] = true; mSymbDisplay[SYMB_POINT] = true; mSymbDisplay[SYMB_LINE] = true; mSymbDisplay[SYMB_BOUNDARY_0] = true; mSymbDisplay[SYMB_BOUNDARY_1] = true; mSymbDisplay[SYMB_BOUNDARY_2] = true; mSymbDisplay[SYMB_CENTROID_IN] = true; mSymbDisplay[SYMB_CENTROID_OUT] = true; mSymbDisplay[SYMB_CENTROID_DUPL] = true; mSymbDisplay[SYMB_NODE_1] = true; mSymbDisplay[SYMB_NODE_2] = true; // Set symbology names mSymbName.resize( SYMB_COUNT ); mSymbName[SYMB_BACKGROUND] = tr( "Background" ); mSymbName[SYMB_HIGHLIGHT] = tr( "Highlight" ); mSymbName[SYMB_DYNAMIC] = tr( "Dynamic" ); mSymbName[SYMB_POINT] = tr( "Point" ); mSymbName[SYMB_LINE] = tr( "Line" ); mSymbName[SYMB_BOUNDARY_0] = tr( "Boundary (no area)" ); mSymbName[SYMB_BOUNDARY_1] = tr( "Boundary (1 area)" ); mSymbName[SYMB_BOUNDARY_2] = tr( "Boundary (2 areas)" ); mSymbName[SYMB_CENTROID_IN] = tr( "Centroid (in area)" ); mSymbName[SYMB_CENTROID_OUT] = tr( "Centroid (outside area)" ); mSymbName[SYMB_CENTROID_DUPL] = tr( "Centroid (duplicate in area)" ); mSymbName[SYMB_NODE_1] = tr( "Node (1 line)" ); mSymbName[SYMB_NODE_2] = tr( "Node (2 lines)" ); // Restore symbology QString spath = "/GRASS/edit/symb/"; QSettings settings; mLineWidth = settings.value( spath + "lineWidth", 1 ).toInt(); mSize = settings.value( spath + "markerSize", 9 ).toInt(); mLineWidthSpinBox->setValue( mLineWidth ); mMarkerSizeSpinBox->setValue( mSize ); for ( int i = 0; i < SYMB_COUNT; i++ ) { bool ok = settings.contains( spath + "display/" + QString::number( i ) ); bool displ = settings.value( spath + "display/" + QString::number( i ), true ).toBool(); if ( ok ) { mSymbDisplay[i] = displ; } ok = settings.contains( spath + "color/" + QString::number( i ) ); QString colorName = settings.value( spath + "color/" + QString::number( i ), "" ).toString(); if ( ok ) { QColor color( colorName ); mSymb[i].setColor( color ); // Use the 'dynamic' color for mRubberBand if ( i == SYMB_DYNAMIC ) { mRubberBandLine->setColor( QColor( colorName ) ); } } mSymb[i].setWidth( mLineWidth ); } // Set Symbology in dialog symbologyList->setColumnWidth( 0, 40 ); symbologyList->setColumnWidth( 1, 50 ); symbologyList->setColumnWidth( 2, 200 ); for ( int i = 0; i < SYMB_COUNT; i++ ) { if ( i == SYMB_NODE_0 ) continue; QPixmap pm( 40, 15 ); pm.fill( mSymb[i].color() ); QString index; index.sprintf( "%d", i ); QTreeWidgetItem *item = new QTreeWidgetItem( symbologyList ); if ( !( i == SYMB_BACKGROUND || i == SYMB_HIGHLIGHT || i == SYMB_DYNAMIC ) ) { item->setCheckState( 0, mSymbDisplay[i] ? Qt::Checked : Qt::Unchecked ); } item->setIcon( 1, pm ); item->setText( 2, mSymbName[i] ); item->setText( 3, index ); } connect( symbologyList, SIGNAL( itemPressed( QTreeWidgetItem *, int ) ), this, SLOT( changeSymbology( QTreeWidgetItem *, int ) ) ); // Init table tab mAttributeTable->setItemDelegate( new QgsGrassEditAttributeTableItemDelegate( this ) ); mAttributeTable->verticalHeader()->hide(); int ndblinks = mProvider->numDbLinks(); if ( ndblinks > 0 ) { for ( int i = 0; i < ndblinks; i++ ) { int f = mProvider->dbLinkField( i ); QString str; str.sprintf( "%d", f ); mTableField->addItem( str ); mFieldBox->addItem( str ); if ( i == 0 ) { setAttributeTable( f ); } } mTableField->setCurrentIndex( 0 ); mFieldBox->setCurrentIndex( 0 ); } else { mTableField->addItem( "1" ); setAttributeTable( 1 ); mFieldBox->addItem( "1" ); } connect( mAttributeTable, SIGNAL( cellChanged( int, int ) ), this, SLOT( columnTypeChanged( int, int ) ) ); // Set variables mSelectedLine = 0; mAttributes = 0; // Read max cats for ( int i = 0; i < mProvider->cidxGetNumFields(); i++ ) { int field = mProvider->cidxGetFieldNumber( i ); if ( field > 0 ) { int cat = mProvider->cidxGetMaxCat( i ); MaxCat mc; mc.field = field; mc.maxCat = cat; mMaxCats.push_back( mc ); } } connect( mCanvas, SIGNAL( renderComplete( QPainter * ) ), this, SLOT( postRender( QPainter * ) ) ); mCanvasEdit = new QgsGrassEditLayer( mCanvas ); mPixmap = &mCanvasEdit->pixmap(); // Init GUI values mCatModeBox->addItem( tr( "Next not used" ), CAT_MODE_NEXT ); mCatModeBox->addItem( tr( "Manual entry" ), CAT_MODE_MANUAL ); mCatModeBox->addItem( tr( "No category" ), CAT_MODE_NOCAT ); catModeChanged( ); // TODO: how to get keyboard events from canvas (shortcuts) restorePosition(); mValid = true; mInited = true; }