void FLIRTDemo::mousePressedGL(int button, int x, int y){ if(button & Qt::LeftButton){ GLdouble worldX, worldY, worldZ; m_rendererWidget->unprojectCoordinates(x, y, &worldX, &worldY, &worldZ); if(!m_points.size()) return; double minDistance = 10e16; unsigned int minIndex = 0; Point2D clickedPoint(worldX, worldY); for(unsigned int i = 0; i < m_points.size(); i ++){ Point2D difference = clickedPoint - m_points[i]->getPosition(); double distance = hypot(difference.x, difference.y); if(distance < minDistance){ minDistance = distance; minIndex = i; } } if(minDistance < 0.2){ m_currentPoint = m_points[minIndex]; m_supportRenderer->setLaserPoints(&m_currentPoint->getSupport()); m_supportRenderer->setColor(m_colors[minIndex]); m_polarRenderer->setColor(m_colors[minIndex]); } else { m_currentPoint = NULL; } } drawDescriptor(); }
bool AgentDetector::updateModule() { LockGuard lg(m); bool isRefreshed = client.getDepthAndPlayers(depth,players); client.getRgb(rgb); bool tracked; if (handleMultiplePlayers) tracked=client.getJoints(joints); else tracked=client.getJoints(joint, EFAA_KINECT_CLOSEST_PLAYER); //cout<<"Tracking value = "<<tracked<<endl; if (tracked) { if (handleMultiplePlayers) client.getSkeletonImage(joints,skeletonImage); else { client.getSkeletonImage(joint,skeletonImage); joints.clear(); joints.push_back(joint); } } client.getPlayersImage(players,playersImage); client.getDepthImage(depth,depthToDisplay); if (depthPort.getOutputCount()>0) { depthPort.prepare()=depthToDisplay; depthPort.write(); } if (imagePort.getOutputCount()>0) { imagePort.prepare()=rgb; imagePort.write(); } if (playersPort.getOutputCount()>0) { playersPort.prepare()=playersImage; playersPort.write(); } if (skeletonPort.getOutputCount()>0) { skeletonPort.prepare()=skeletonImage; skeletonPort.write(); } if (showImages) { cvConvertScale((IplImage*)depthToDisplay.getIplImage(),depthTmp,1.0/255); cvCvtColor((IplImage*)rgb.getIplImage(),rgbTmp,CV_BGR2RGB); string mode=showMode; string submode; while (!mode.empty()) { if (showImageParser(mode,submode)) { if (submode=="rgb") cvShowImage("rgb",rgbTmp); else if (submode=="depth") cvShowImage("depth",depthTmp); else if (submode=="skeleton") cvShowImage("skeleton",(IplImage*)skeletonImage.getIplImage()); else if (submode=="players") cvShowImage("players",(IplImage*)playersImage.getIplImage()); else yError("unrecognized show mode!"); } } cvWaitKey(1); } //Send the players information to the OPC //Allow click calibration if (!checkCalibration()) { if (AgentDetector::clicked==clicked_left) { AgentDetector::clicked=idle; //Get the clicked point coordinate in Kinect space Vector clickedPoint(3); cout<<"Processing a click on ("<<AgentDetector::clickX<<" "<<AgentDetector::clickY<<") --> "; client.get3DPoint((int)AgentDetector::clickX,(int)AgentDetector::clickY,clickedPoint); cout<<clickedPoint.toString(3,3)<<endl; Bottle bCond; Bottle bObject; Bottle bRTObject; bObject.addString(EFAA_OPC_ENTITY_TAG); bObject.addString("=="); bObject.addString(EFAA_OPC_ENTITY_OBJECT); bRTObject.addString(EFAA_OPC_ENTITY_TAG); bRTObject.addString("=="); bRTObject.addString(EFAA_OPC_ENTITY_RTOBJECT); Bottle bPresent; bPresent.addString(EFAA_OPC_OBJECT_PRESENT_TAG); bPresent.addString("=="); bPresent.addDouble(1.0); bCond.addList()=bObject; bCond.addString("&&"); bCond.addList()=bPresent; bCond.addString("||"); bCond.addList()=bRTObject; bCond.addString("&&"); bCond.addList()=bPresent; opc->checkout(); opc->isVerbose=true; list<Entity*> presentObjects=opc->Entities(bCond); opc->isVerbose=false; Object *o=nullptr; if (presentObjects.size()==1) { o=dynamic_cast<Object*>(presentObjects.front()); } else { for(auto& presentObject : presentObjects) { if(presentObject->name() == "target") { o=dynamic_cast<Object*>(presentObject); break; } } } if(o) { Bottle botRPH, botRPHRep; botRPH.addString("add"); botRPH.addString("kinect"); Bottle &cooKinect=botRPH.addList(); cooKinect.addDouble(clickedPoint[0]); cooKinect.addDouble(clickedPoint[1]); cooKinect.addDouble(clickedPoint[2]); Bottle &cooiCub=botRPH.addList(); cooiCub.addDouble(o->m_ego_position[0]); cooiCub.addDouble(o->m_ego_position[1]); cooiCub.addDouble(o->m_ego_position[2]); rfh.write(botRPH,botRPHRep); cout<<"Sent to RFH: "<<botRPH.toString().c_str()<<endl; cout<<"Got from RFH: "<<botRPHRep.toString().c_str()<<endl; pointsCnt++; } else { yWarning("There should be 1 and only 1 object on the table"); yWarning("If there is more than one object, the object you want"); yWarning("to calibrate must be called \"target\""); } } else if (AgentDetector::clicked==clicked_right) { AgentDetector::clicked=idle; if (pointsCnt>=3) { Bottle calibBottle,calibReply; calibBottle.addString("cal"); calibBottle.addString("kinect"); rfh.write(calibBottle,calibReply); cout<<"Calibrated ! "<<calibReply.toString().c_str()<<endl; calibBottle.clear(); calibBottle.addString("save"); rfh.write(calibBottle,calibReply); cout<<"Saved to file ! "<<calibReply.toString().c_str()<<endl; checkCalibration(); } else yWarning("Unable to calibrate with less than 3 points pairs collected"); } } if (isRefreshed) { // yInfo() << " refreshed"; ////////////////////////////////////////////////////////////////// //Clear the previous agents //for(map<int, Agent*>::iterator pA=identities.begin(); pA!=identities.end() ; pA++) //{ // pA->second->m_present = 0.0; //} //partner->m_present = 0.0; // check if last apparition was more than dThreshlodDisaparition ago if (tracked) { //Go through all skeletons for(deque<Player>::iterator p=joints.begin(); p!=joints.end(); p++) { //check if this skeletton is really tracked bool reallyTracked = false; for(map<string,Joint>::iterator jnt = p->skeleton.begin() ; jnt != p->skeleton.end() ; jnt++) { if (jnt->second.x != 0 && jnt->second.y != 0 && jnt->second.z != 0) { reallyTracked = true; break; } } if (reallyTracked) { dSince = (clock() - dTimingLastApparition) / (double) CLOCKS_PER_SEC; //yInfo() << " is REALLY tracked"; string playerName = partner_default_name; //If the skeleton is tracked we dont identify if (identities.find(p->ID) != identities.end()) { playerName = identities[p->ID]; } else { //Check if we should learn this face if (currentTrainingFace != "") { setIdentity(*p,currentTrainingFace); currentTrainingFace = ""; } //if (useFaceRecognition) playerName = getIdentity(*p); } //We interact with OPC only if the calibration is done if (isCalibrated) { //main bottle to be streamed with loc of all agent body part Bottle& bAgentLoc = agentLocOutPort.prepare(); bAgentLoc.clear(); //Retrieve this player in OPC or create if does not exist opc->checkout(); partner = opc->addOrRetrieveEntity<Agent>(partner_default_name); partner->m_present = 1.0; // reset the timing. dTimingLastApparition = clock(); if (identities.find(p->ID) == identities.end()) { cout<<"Assigning name "<<playerName<<" to skeleton "<<p->ID<<endl; //Agent* specificAgent = opc->addEntity<Agent>(playerName); Agent* specificAgent = opc->addOrRetrieveEntity<Agent>(playerName); if(specificAgent == nullptr) { yError() << "SHIT specificAgent"; } else { identities[p->ID] = specificAgent->name(); specificAgent->m_present = 1.0; yInfo() << " specific agent is commited"; opc->commit(specificAgent); yInfo() << " specific agent is commited done"; } } // Relation r(partner->name(),"named",playerName); // opc->addRelation(r,1.0); // cout<<"Commiting : "<<r.toString()<<endl; yarp::os::Bottle &skeleton = outputSkeletonPort.prepare(); skeleton.clear(); //Convert the skeleton into efaaHelpers body. We loose orientation in the process... for(map<string,Joint>::iterator jnt = p->skeleton.begin() ; jnt != p->skeleton.end() ; jnt++) { Bottle bBodyPartLoc; Vector kPosition(4); kPosition[0] = jnt->second.x; kPosition[1] = jnt->second.y; kPosition[2] = jnt->second.z; kPosition[3] = 1; Vector icubPos = kinect2icub * kPosition; Vector irPos = icubPos.subVector(0,2); if (isMounted) { irPos = transform2IR(irPos); Bottle jntBtl; jntBtl.clear(); jntBtl.addString(jnt->first); jntBtl.addDouble(jnt->second.x); jntBtl.addDouble(jnt->second.y); jntBtl.addDouble(jnt->second.z); skeleton.addList() = jntBtl; } if (jnt->first == EFAA_OPC_BODY_PART_TYPE_HEAD) { partner->m_ego_position = irPos; } partner->m_body.m_parts[jnt->first] = irPos; bBodyPartLoc.addString(jnt->first); bBodyPartLoc.addString(irPos.toString()); bAgentLoc.addList() = bBodyPartLoc; } agentLocOutPort.write(); opc->commit(partner); // cout << skeleton.toString()<< endl; outputSkeletonPort.write(); //opc->commit(agent); } // cout<<'1'<<endl; } } } else { if (dSince > dThresholdDisparition) { opc->checkout(); partner = opc->addOrRetrieveEntity<Agent>(partner_default_name); partner->m_present = 0.0; opc->commit(partner); } else { //yInfo() << " clock is: " << clock() << "\t last apparition: " << dTimingLastApparition << "\t dSince: " << dSince; //yInfo() << " agent dissapeared but not for too long."; } } } return true; }
void SkyMap::mousePressEvent( QMouseEvent *e ) { KStars* kstars = KStars::Instance(); if ( ( e->modifiers() & Qt::ControlModifier ) && (e->button() == Qt::LeftButton) ) { ZoomRect.moveCenter( e->pos() ); setZoomMouseCursor(); update(); //refresh without redrawing skymap return; } // if button is down and cursor is not moved set the move cursor after 500 ms QTimer::singleShot(500, this, SLOT (setMouseMoveCursor())); // break if point is unusable if ( projector()->unusablePoint( e->pos() ) ) return; if ( !midMouseButtonDown && e->button() == Qt::MidButton ) { y0 = 0.5*height() - e->y(); //record y pixel coordinate for middle-button zooming midMouseButtonDown = true; } if ( !mouseButtonDown ) { if ( e->button() == Qt::LeftButton ) { mouseButtonDown = true; } //determine RA, Dec of mouse pointer m_MousePoint = projector()->fromScreen( e->pos(), data->lst(), data->geo()->lat() ); setClickedPoint( &m_MousePoint ); //Find object nearest to clickedPoint() double maxrad = 1000.0/Options::zoomFactor(); SkyObject* obj = data->skyComposite()->objectNearest( clickedPoint(), maxrad ); setClickedObject( obj ); if( obj ) setClickedPoint( obj ); switch( e->button() ) { case Qt::LeftButton: if( kstars ) { QString name; if( clickedObject() ) name = clickedObject()->translatedLongName(); else name = i18n( "Empty sky" ); kstars->statusBar()->changeItem(name, 0 ); } break; case Qt::RightButton: if( rulerMode ) { // Compute angular distance. slotEndRulerMode(); } else { // Show popup menu if( clickedObject() ) { clickedObject()->showPopupMenu( pmenu, QCursor::pos() ); } else { pmenu->createEmptyMenu( clickedPoint() ); pmenu->popup( QCursor::pos() ); } } break; default: ; } } }
void SkyMap::mouseMoveEvent( QMouseEvent *e ) { if ( Options::useHoverLabel() ) { //Start a single-shot timer to monitor whether we are currently hovering. //The idea is that whenever a moveEvent occurs, the timer is reset. It //will only timeout if there are no move events for HOVER_INTERVAL ms m_HoverTimer.start( HOVER_INTERVAL ); QToolTip::hideText(); } //Are we defining a ZoomRect? if ( ZoomRect.center().x() > 0 && ZoomRect.center().y() > 0 ) { //cancel operation if the user let go of CTRL if ( !( e->modifiers() & Qt::ControlModifier ) ) { ZoomRect = QRect(); //invalidate ZoomRect update(); } else { //Resize the rectangle so that it passes through the cursor position QPoint pcenter = ZoomRect.center(); int dx = abs(e->x() - pcenter.x()); int dy = abs(e->y() - pcenter.y()); if ( dx == 0 || float(dy)/float(dx) > float(height())/float(width()) ) { //Size rect by height ZoomRect.setHeight( 2*dy ); ZoomRect.setWidth( 2*dy*width()/height() ); } else { //Size rect by height ZoomRect.setWidth( 2*dx ); ZoomRect.setHeight( 2*dx*height()/width() ); } ZoomRect.moveCenter( pcenter ); //reset center update(); return; } } if ( projector()->unusablePoint( e->pos() ) ) return; // break if point is unusable //determine RA, Dec of mouse pointer m_MousePoint = projector()->fromScreen( e->pos(), data->lst(), data->geo()->lat() ); double dyPix = 0.5*height() - e->y(); if ( midMouseButtonDown ) { //zoom according to y-offset float yoff = dyPix - y0; if (yoff > 10 ) { y0 = dyPix; slotZoomIn(); } if (yoff < -10 ) { y0 = dyPix; slotZoomOut(); } } if ( mouseButtonDown ) { // set the mouseMoveCursor and set slewing=true, if they are not set yet if( !mouseMoveCursor ) setMouseMoveCursor(); if( !slewing ) { slewing = true; stopTracking(); //toggle tracking off } //Update focus such that the sky coords at mouse cursor remain approximately constant if ( Options::useAltAz() ) { m_MousePoint.EquatorialToHorizontal( data->lst(), data->geo()->lat() ); clickedPoint()->EquatorialToHorizontal( data->lst(), data->geo()->lat() ); dms dAz = m_MousePoint.az() - clickedPoint()->az(); dms dAlt = m_MousePoint.alt() - clickedPoint()->alt(); focus()->setAz( focus()->az().Degrees() - dAz.Degrees() ); //move focus in opposite direction focus()->setAz( focus()->az().reduce() ); focus()->setAlt( KSUtils::clamp( focus()->alt().Degrees() - dAlt.Degrees() , -90.0 , 90.0 ) ); focus()->HorizontalToEquatorial( data->lst(), data->geo()->lat() ); } else { dms dRA = m_MousePoint.ra() - clickedPoint()->ra(); dms dDec = m_MousePoint.dec() - clickedPoint()->dec(); focus()->setRA( focus()->ra().Hours() - dRA.Hours() ); //move focus in opposite direction focus()->setRA( focus()->ra().reduce() ); focus()->setDec( KSUtils::clamp( focus()->dec().Degrees() - dDec.Degrees() , -90.0 , 90.0 ) ); focus()->EquatorialToHorizontal( data->lst(), data->geo()->lat() ); } showFocusCoords(); //redetermine RA, Dec of mouse pointer, using new focus m_MousePoint = projector()->fromScreen( e->pos(), data->lst(), data->geo()->lat() ); setClickedPoint( &m_MousePoint ); forceUpdate(); // must be new computed } else { //mouse button not down emit mousePointChanged( &m_MousePoint ); } }
void CCheckerCtrl::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default SetFocus(); DWORD dwPos = GetMessagePos(); CPoint clickedPoint((int)(short)LOWORD(dwPos), (int)(short)HIWORD(dwPos)); ScreenToClient(&clickedPoint); { CRect cRect; GetWindowRect(&cRect); ScreenToClient(&cRect); UINT nY = UINT(((float)clickedPoint.y / (float(cRect.Height())/float(m_nBlocksPerColumn)))+.3); UINT nX = UINT(((float)clickedPoint.x / (float(cRect.Width())/float(m_nBlocksPerRow)))+.3); UINT nIndex = nY * m_nBlocksPerRow + nX + m_nyPos * m_nBlocksPerRow; if(nIndex < m_nNumberofBlocks && nX < m_nBlocksPerRow) { CString strNumber; // strNumber.Format("%d", nIndex + m_nStartIndex+1); strNumber = (m_crText.GetAt(nIndex + m_nStartIndex)); if (strNumber.GetLength()) { SetCapture(); CreateSafeTooltipRect(clickedPoint.x, clickedPoint.y, strNumber); GetParent()->PostMessage(9876,(WPARAM)(nIndex+m_nStartIndex+1), 0); CClientDC dc(this); CBrush brush; brush.CreateSolidBrush(GetSysColor(COLOR_INFOBK)); dc.Rectangle(tooltipRect); tooltipRect.left++; tooltipRect.top++; tooltipRect.bottom--; tooltipRect.right--; dc.FillRect(tooltipRect, &brush); CFont font; LOGFONT logFont; strcpy(logFont.lfFaceName, "Verdana"); logFont.lfHeight = -MulDiv(12, GetDeviceCaps(dc.m_hDC, LOGPIXELSY), 72); logFont.lfWidth = 0; logFont.lfEscapement = 0; logFont.lfItalic = FALSE; logFont.lfStrikeOut = FALSE; logFont.lfUnderline = FALSE; logFont.lfWeight = FW_BOLD; font.CreateFontIndirect(&logFont); dc.SelectObject(font); dc.SetTextColor(GetSysColor(COLOR_INFOTEXT)); dc.SetBkColor(GetSysColor(COLOR_INFOBK)); dc.DrawText(strNumber, tooltipRect, DT_VCENTER | DT_CENTER | DT_SINGLELINE); tooltipRect.left--; tooltipRect.top--; tooltipRect.bottom++; tooltipRect.right++; m_bShouldUpdated = TRUE; } } } CWnd::OnLButtonDown(nFlags, point); }