Example #1
0
void AISystem::initTanksInScene(std::vector<Vec2> _positions)
{
	for (auto pos : _positions)
	{
		addRobot(pos);
	}
}
bool ClientTest::init()
{
    ServerFrame::init();
    Client::initPBModule();

    JsonHelper help("conf/robot.json");
    if (!help.loadJson())
    {
        return false;
    }

    const Json::Value& Root = help.root();
    LAZY_JSON_GET_UINT(m_maxCount,		        "max_count",			    Root);			
    LAZY_JSON_GET_UINT(m_onceCount	,	        "once_count",	            Root);
    LAZY_JSON_GET_UINT(m_accountBegin	,	    "account_start",	        Root);
    LAZY_JSON_GET_UINT(m_info._port	,	        "port",	                Root);
    LAZY_JSON_GET_UINT(m_onceTime	,	        "once_time",	            Root);
    LAZY_JSON_GET_STRING(m_info._ip,            "ip",                   Root);

    if (m_onceTime < 10)
    {   m_onceTime = 100;}

    addRobot();
    gEventMgr.addEvent(this, &ClientTest::reConnetClient, EVENT_ADD_TEST_ACCOUNT, m_onceTime, 0, 0);
    //gEventMgr.addEvent(this, &ClientTest::reConnetClient, EVENT_RECONN_TEST_ACCOUNT, m_onceTime, 0, 0);
    return true;
}
int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QMainWindow::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: openDocument(); break;
        case 1: saveDocument(); break;
        case 2: closeDocument(); break;
        case 3: newDocument(); break;
        case 4: addShape(); break;
        case 5: removeShape(); break;
        case 6: setShapeColor(); break;
        case 7: addSnowman(); break;
        case 8: addRobot(); break;
        case 9: about(); break;
        case 10: aboutQt(); break;
        case 11: updateActions(); break;
        default: ;
        }
        _id -= 12;
    }
    return _id;
}
Example #4
0
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    setupUi(this);

    QWidget *w = documentTabs->widget(0);
    documentTabs->removeTab(0);
    delete w;

    connect(actionOpen, SIGNAL(triggered()), this, SLOT(openDocument()));
    connect(actionClose, SIGNAL(triggered()), this, SLOT(closeDocument()));
    connect(actionNew, SIGNAL(triggered()), this, SLOT(newDocument()));
    connect(actionSave, SIGNAL(triggered()), this, SLOT(saveDocument()));
    connect(actionExit, SIGNAL(triggered()), this, SLOT(close()));
    connect(actionRed, SIGNAL(triggered()), this, SLOT(setShapeColor()));
    connect(actionGreen, SIGNAL(triggered()), this, SLOT(setShapeColor()));
    connect(actionBlue, SIGNAL(triggered()), this, SLOT(setShapeColor()));
    connect(actionAddCircle, SIGNAL(triggered()), this, SLOT(addShape()));
    connect(actionAddRectangle, SIGNAL(triggered()), this, SLOT(addShape()));
    connect(actionAddTriangle, SIGNAL(triggered()), this, SLOT(addShape()));
    connect(actionRemoveShape, SIGNAL(triggered()), this, SLOT(removeShape()));
    connect(actionAddRobot, SIGNAL(triggered()), this, SLOT(addRobot()));
    connect(actionAddSnowman, SIGNAL(triggered()), this, SLOT(addSnowman()));
    connect(actionAbout, SIGNAL(triggered()), this, SLOT(about()));
    connect(actionAboutQt, SIGNAL(triggered()), this, SLOT(aboutQt()));

    connect(undoLimit, SIGNAL(valueChanged(int)), this, SLOT(updateActions()));
    connect(documentTabs, SIGNAL(currentChanged(int)), this, SLOT(updateActions()));

    actionOpen->setShortcut(QString("Ctrl+O"));
    actionClose->setShortcut(QString("Ctrl+W"));
    actionNew->setShortcut(QString("Ctrl+N"));
    actionSave->setShortcut(QString("Ctrl+S"));
    actionExit->setShortcut(QString("Ctrl+Q"));
    actionRemoveShape->setShortcut(QString("Del"));
    actionRed->setShortcut(QString("Alt+R"));
    actionGreen->setShortcut(QString("Alt+G"));
    actionBlue->setShortcut(QString("Alt+B"));
    actionAddCircle->setShortcut(QString("Alt+C"));
    actionAddRectangle->setShortcut(QString("Alt+L"));
    actionAddTriangle->setShortcut(QString("Alt+T"));

    m_undoGroup = new QUndoGroup(this);
    undoView->setGroup(m_undoGroup);
    undoView->setCleanIcon(QIcon(":/icons/ok.png"));

    QAction *undoAction = m_undoGroup->createUndoAction(this);
    QAction *redoAction = m_undoGroup->createRedoAction(this);
    undoAction->setIcon(QIcon(":/icons/undo.png"));
    redoAction->setIcon(QIcon(":/icons/redo.png"));
    menuShape->insertAction(menuShape->actions().at(0), undoAction);
    menuShape->insertAction(undoAction, redoAction);

    toolBar->addAction(undoAction);
    toolBar->addAction(redoAction);

    newDocument();
    updateActions();
};
void Physics::registBodies(){
    addFloor();

    addBall(2.5,btVector3(SIZE_WIDTH/1.5,0,SIZE_DEPTH/1.5),0.08);

    btVector3 posTeam1[] = {btVector3(15,4,SIZE_DEPTH- 55),btVector3(35,4,30),btVector3(55,4,45)};
    btVector3 posTeam2[] = {btVector3(SIZE_WIDTH-15,4,55),btVector3(SIZE_WIDTH-25,4,SIZE_DEPTH - SIZE_DEPTH/2.5 + 20),btVector3(SIZE_WIDTH-55,4,85)};
    //Create robots here
    //Team 1
    for(int i = 0;i < numRobotsTeam;i++){
        if(numTeams >= 1){
            addRobot(Color(0.3,0.3,0.3),posTeam1[i],btVector3(0,90,0),8,0.25,clrPlayers[i],clrTeams[0]);
        }
    }

    for(int i = 0;i < numRobotsTeam;i++){
        if(numTeams == 2){
            addRobot(Color(0.3,0.3,0.3),posTeam2[i],btVector3(0,-100,0),8,0.25,clrPlayers[i],clrTeams[1]);
        }
    }

    addWall(Color(0,0,0),btVector3(SIZE_WIDTH/2+1,7.5,-2.5),SIZE_WIDTH,15,5,0);
    addWall(Color(0,0,0),btVector3(SIZE_WIDTH/2+1,7.5,SIZE_DEPTH+2.5),SIZE_WIDTH,15,5,0);

    addWall(Color(0,0,0),btVector3(-1.6,7.5,SIZE_DEPTH/6),5,15,SIZE_DEPTH/3,0);
    addWall(Color(0,0,0),btVector3(-1.6,7.5,SIZE_DEPTH-SIZE_DEPTH/6),5,15,SIZE_DEPTH/3,0);
    addWall(Color(0,0,0),btVector3(-12.5,7.5, SIZE_DEPTH/2),5,15,SIZE_DEPTH/3,0);
    addWall(Color(0,0,0),btVector3(-7,7.5,SIZE_DEPTH/3),15,15,5,0);
    addWall(Color(0,0,0),btVector3(-7,7.5,2*SIZE_DEPTH/3+2.5),15,15,5,0);

    addWall(Color(0,0,0),btVector3(SIZE_WIDTH+3.5,7.5,SIZE_DEPTH/6),5,15,SIZE_DEPTH/3,0);
    addWall(Color(0,0,0),btVector3(SIZE_WIDTH+3.5,7.5,SIZE_DEPTH-SIZE_DEPTH/6),5,15,SIZE_DEPTH/3,0);
    addWall(Color(0,0,0),btVector3(SIZE_WIDTH+13.5,7.5, SIZE_DEPTH/2),5,15,SIZE_DEPTH/3,0);
    addWall(Color(0,0,0),btVector3(SIZE_WIDTH+8.5,7.5,SIZE_DEPTH/3),15,15,5,0);
    addWall(Color(0,0,0),btVector3(SIZE_WIDTH+8.5,7.5,2*SIZE_DEPTH/3+2.5),15,15,5,0);

    addCorner(Color(0,0,0),btVector3(10,7.5,10),30,15,btVector3(0,45,0));
    addCorner(Color(0,0,0),btVector3(SIZE_WIDTH-9,7.5,10),30,15,btVector3(0,-45,0));
    addCorner(Color(0,0,0),btVector3(SIZE_WIDTH-9,7.5,SIZE_DEPTH-10),30,15,btVector3(0,45,0));
    addCorner(Color(0,0,0),btVector3(10,7.5,SIZE_DEPTH-10),30,15,btVector3(0,-45,0));
}
void TeamDetector::findRobotsByModel(::google::protobuf::RepeatedPtrField< ::SSL_DetectionRobot >* robots, int team_color_id, const Image<raw8> * image, CMVision::ColorRegionList * colorlist, CMVision::RegionTree & reg_tree)
{

    (void)image;
    const int MaxDetections = _other_markers_max_detections;
    Marker cen; // center marker
    Marker markers[MaxDetections];
    const float marker_max_query_dist = _other_markers_max_query_distance;
    const float marker_max_dist = _pattern_max_dist;

    // partially forget old detections
    //decaySeen();

    filter_team.init( colorlist->getRegionList(team_color_id).getInitialElement());
    const CMVision::Region * reg=0;
    SSL_DetectionRobot * robot=0;

    MultiPatternModel::PatternDetectionResult res;
    // printf("finding robots...\n");
    while((reg = filter_team.getNext()) != 0) {
        vector2d reg_img_center(reg->cen_x,reg->cen_y);
        vector3d reg_center3d;
        _camera_params.image2field(reg_center3d,reg_img_center,_robot_height);
        vector2d reg_center(reg_center3d.x,reg_center3d.y);
        //TODO add masking:
        //if(det.mask.get(reg->cen_x,reg->cen_y) >= 0.5){
        // printf("if in field:\n");
        if (field_filter.isInFieldOrPlayableBoundary(reg_center)) {
            cen.set(reg,reg_center3d,getRegionArea(reg,_robot_height));
            int num_markers = 0;

            reg_tree.startQuery(*reg,marker_max_query_dist);
            double sd=0.0;
            CMVision::Region *mreg;
            while((mreg=reg_tree.getNextNearest(sd))!=0 && num_markers<MaxDetections) {
                //TODO: implement masking:
                // filter_other.check(*mreg) && det.mask.get(mreg->cen_x,mreg->cen_y)>=0.5

                if(filter_others.check(*mreg) && model.usesColor(mreg->color)) {
                    vector2d marker_img_center(mreg->cen_x,mreg->cen_y);
                    vector3d marker_center3d;
                    _camera_params.image2field(marker_center3d,marker_img_center,_robot_height);
                    Marker &m = markers[num_markers];

                    m.set(mreg,marker_center3d,getRegionArea(mreg,_robot_height));
                    vector2f ofs = m.loc - cen.loc;
                    m.dist = ofs.length();
                    m.angle = ofs.angle();

                    if(m.dist>0.0 && m.dist<marker_max_dist) {
                        num_markers++;
                    }
                }
            }
            reg_tree.endQuery();
            // printf("num markers = %d\n", num_markers);
            if(num_markers >= 2) {
                CMPattern::PatternProcessing::sortMarkersByAngle(markers,num_markers);
                for(int i=0; i<num_markers; i++) {
                    // DEBUG CODE:
                    // char colorchar='?';
                    // if (markers[i].id==color_id_green) colorchar='g';
                    // if (markers[i].id==color_id_pink) colorchar='p';
                    // if (markers[i].id==color_id_white) colorchar='w';
                    // if (markers[i].id==color_id_team) colorchar='t';
                    // if (markers[i].id==color_id_field_green) colorchar='f';
                    // if (markers[i].id==color_id_cyan) colorchar='c';
                    // printf("%c ",colorchar);
                    int j = (i + 1) % num_markers;
                    markers[i].next_dist = dist(markers[i].loc,markers[j].loc);
                    markers[i].next_angle_dist = angle_pos(angle_diff(markers[i].angle,markers[j].angle));
                }

                if (model.findPattern(res,markers,num_markers,_pattern_fit_params,_camera_params)) {
                    robot=addRobot(robots,res.conf,_max_robots*2);
                    if (robot!=0) {
                        //setup robot:
                        robot->set_x(cen.loc.x);
                        robot->set_y(cen.loc.y);
                        if (_have_angle) robot->set_orientation(res.angle);
                        robot->set_robot_id(res.id);
                        robot->set_pixel_x(reg->cen_x);
                        robot->set_pixel_y(reg->cen_y);
                        robot->set_height(cen.height);
                    }
                }
            }
        }
    }
    //remove items with 0-confidence:
    stripRobots(robots);

    //remove extra items:
    while(robots->size() > _max_robots) {
        robots->RemoveLast();
    }

}
void TeamDetector::findRobotsByTeamMarkerOnly(::google::protobuf::RepeatedPtrField< ::SSL_DetectionRobot >* robots, int team_color_id, const Image<raw8> * image, CMVision::ColorRegionList * colorlist)
{
    filter_team.init( colorlist->getRegionList(team_color_id).getInitialElement() );

    //TODO: change these to update on demand:
    //local variables
    const CMVision::Region * reg=0;
    SSL_DetectionRobot * robot=0;
    while((reg = filter_team.getNext()) != 0) {
        vector2d reg_img_center(reg->cen_x,reg->cen_y);
        vector3d reg_center3d;
        _camera_params.image2field(reg_center3d,reg_img_center,_robot_height);
        vector2d reg_center(reg_center3d.x,reg_center3d.y);

        //TODO: add confidence masking:
        //float conf = det.mask.get(reg->cen_x,reg->cen_y);
        double conf=1.0;
        if (field_filter.isInFieldOrPlayableBoundary(reg_center) &&  ((_histogram_enable==false) || checkHistogram(reg,image)==true)) {
            double area = getRegionArea(reg,_robot_height);
            double area_err = fabs(area - _center_marker_area_mean);

            conf *= GaussianVsUniform(area_err, sq(_center_marker_area_stddev), _center_marker_uniform);
            //printf("-------------\n");
            if (conf < 1e-6) conf=0.0;

            /*if(unlikely(verbose > 2)){
              printf("    area=%0.1f err=%4.1f conf=%0.6f\n",area,area_err,conf);
            }
            if(det.debug) det.color(reg,rc,conf);*/

            //allow twice as many robots for now...
            //duplicate filtering will take care of the rest below:
            robot=addRobot(robots,conf,_max_robots*2);

            if (robot!=0) {
                //setup robot:
                robot->set_x(reg_center.x);
                robot->set_y(reg_center.y);
                robot->set_pixel_x(reg->cen_x);
                robot->set_pixel_y(reg->cen_y);
                robot->set_height(_robot_height);
            }
        }
    }

    // remove duplicates ... keep the ones with higher confidence:
    int size=robots->size();
    for(int i=0; i<size; i++) {
        for(int j=i+1; j<size; j++) {
            if(sqdist(vector2d(robots->Get(i).x(),robots->Get(i).y()),vector2d(robots->Get(j).x(),robots->Get(j).y())) < sq(_center_marker_duplicate_distance)) {
                robots->Mutable(i)->set_confidence(0.0);
            }
        }
    }

    //remove items with 0-confidence:
    stripRobots(robots);

    //remove extra items:
    while(robots->size() > _max_robots) {
        robots->RemoveLast();
    }

}