void Player::mergeObjectList(ObjectList &orig, const ObjectList &newobjs, SelectionFlags_t flags) { if(flags == SelectionFlags::SET) { orig = newobjs; } else if(flags == SelectionFlags::ADD) { for(ObjectList::const_iterator it = newobjs.begin(); it != newobjs.end(); ++it) { ObjectList::const_iterator it2 = std::find(orig.begin(), orig.end(), *it); if(it2 == orig.end()) orig.addObject(*it); } } /* else if(flags == SelectionFlags::ADD) */ else if(flags == SelectionFlags::REMOVE) { for(ObjectList::const_iterator it = newobjs.begin(); it != newobjs.end(); ++it) { ObjectList::iterator it2 = std::find(orig.begin(), orig.end(), *it); if(it2 != orig.end()) orig.erase(it2); } } /* else if(flags == SelectionFlags::REMOVE) */ }
ObjectPtr Game::findObjectByRect(ObjectList &matched_objs, int left, int top, int right, int bottom, unsigned int flags) { ObjectList &objs = this->getObjectList(); matched_objs.clear(); for(ObjectList::const_iterator it = objs.begin(); it != objs.end(); ++it) { const ObjectPtr &obj = *it; if(obj->insideRect(left, top, right, bottom)) { //fprintf(stderr, "adding object %s\n", obj->getObjectName()); matched_objs.addObject(obj); } } if(matched_objs.empty()) return ObjectPtr(); else return *matched_objs.begin(); }
ObjectList PBImage::getAnnotations(int id) const { ObjectList annotations = ObjectList(); protobuf::CameraLocation location = protobuf::HEAD_LEFT; if (id == 0) { location = protobuf::HEAD_LEFT; } else if (id == 1) { location = protobuf::HEAD_RIGHT; } if (mLoadedFrame != NULL) { for (int i = 0; i < mLoadedFrame->camera_size(); i++) { const protobuf::ProtoBufFrame_Camera& cam = mLoadedFrame->camera(i); if (cam.type().location() == location) { for (int o = 0; o < cam.objects_size(); ++o) { const protobuf::ProtoBufFrame_Object obj = cam.objects(o); Object::ObjectType type; switch (obj.type()) { case protobuf::BALL: type = Object::BALL; break; case protobuf::GOAL_POLE_YELLOW: type = Object::GOAL_POLE_YELLOW; break; case protobuf::GOAL_YELLOW_CROSSBAR: type = Object::GOAL_YELLOW_CROSSBAR; break; case protobuf::ROBOT: type = Object::ROBOT; break; case protobuf::ROBOT_CYAN: type = Object::ROBOT_CYAN; break; case protobuf::ROBOT_MAGENTA: type = Object::ROBOT_MAGENTA; break; case protobuf::LINE: type = Object::LINE; break; case protobuf::LINE_POINT: type = Object::LINE_POINT; break; case protobuf::OBSTACLE: type = Object::OBSTACLE; break; case protobuf::FIELD_LINE: type = Object::FIELD_LINE; break; case protobuf::UNKNOWN: default: Debugger::DEBUG("PBImage","Unsupported ObjectType!"); type = Object::UNKNOWN; break; } Object ob = Object(obj.box().x1(), obj.box().y1(), obj.box().x2(), obj.box().y2(), type); annotations.addObject(ob); } } } } return annotations; }