void DrawableText::applySettings(ResourceDescriptor settings) { m_color.applySettings( settings.getSubResource("Color")); m_location.applySettings( settings.getSubResource("Location") ); m_orientation.applySettings( settings.getSubResource("Orientation") ); ResourceDescriptor sub = settings.getSubResource("Text"); if (isNotEmpty(sub.getKey())) { setText(sub.getValue()); } sub = settings.getSubResource("Font"); if (isNotEmpty(sub.getValue())) { setFont(sub.getValue()); } sub = settings.getSubResource("Width"); if (isNotEmpty(sub.getValue())) { m_width = toMeters(sub.getValue()); } sub = settings.getSubResource("Height"); if (isNotEmpty(sub.getValue())) { m_height = toMeters(sub.getValue()); } }
void Box2DMouseJoint::setTarget(const QPointF &target) { const b2Vec2 targetMeters = toMeters(target); if (mMouseJointDef.target == targetMeters) return; mMouseJointDef.target = targetMeters; if (mouseJoint()) mouseJoint()->SetTarget(targetMeters); emit targetChanged(); }
void Vector3D::applySettings(ResourceDescriptor settings) { std::vector<string> values = split(settings.getValue(), ','); if (values.size() == 3 || values.size() == 2) { m_x = toMeters(values[0]); m_y = toMeters(values[1]); } if (values.size() == 3) { m_z = toMeters(values[2]); } ResourceDescriptor sub = settings.getSubResource("X"); if (isNotEmpty(sub.getValue())) { m_x = toMeters(sub.getValue()); } sub = settings.getSubResource("Y"); if (isNotEmpty(sub.getValue())) { m_y = toMeters(sub.getValue()); } sub = settings.getSubResource("Z"); if (isNotEmpty(sub.getValue())) { m_z = toMeters(sub.getValue()); } }
//extract blobs, get there 3D position, check which point they correspond to in HashTable void GH::getModelPointsFromImage(const cv::Mat& img, std::vector<DetectionGH> &matches) const { //get blobs vector<KeyPoint> blobs; extractBlobs(img, blobs); //plot them //for(int p=0;p<blobs.size();p++) // cv::circle(img, blobs[p].pt, (blobs[p].size - 1) / 2 + 1, cv::Scalar(255, 0, 0), -1); //get list of points from blob (will have to be removed later as just a copy of blobs) vector<Point2f> mPoints; for(unsigned int p=0;p<blobs.size();p++)mPoints.push_back(toMeters(cameraCalibration.cameraMatrix,blobs[p].pt)); //empty output vectors matches.clear(); //loop through all points for(unsigned int p=0;p<mPoints.size();p++) { //for each point need to accumulate votes from HT float votesId[nbIds]; //init all votes to 0 for(int id=0;id<nbIds;id++) votesId[id]=0; //for each point have to find the nbPtBasis closest points vector<unsigned int> idNeigbors; getClosestNeigbors(p, mPoints, idNeigbors); //for each positively oriented possible triangle in closest neigbors //define basis and project all points on it to fill HT for(unsigned int tp2=0;tp2<idNeigbors.size();tp2++) { //get index of point 2 in mVerticesDes unsigned int p2=idNeigbors[tp2]; //define first basis vector Point2f basis1= mPoints[p2]-mPoints[p]; for(unsigned int tp3=0;tp3<idNeigbors.size();tp3++) if(p2!=idNeigbors[tp3]) { unsigned int p3=idNeigbors[tp3]; //define second basis Point2f basis2= mPoints[p3]-mPoints[p]; //check direction of triangle if(testDirectionBasis(basis1,basis2)) { //put basis in a 2x2 matrix to inverse it and express all other points i this basis Matx22f tBasis(basis1.x,basis2.x,basis1.y,basis2.y); Matx22f tBasisInv=tBasis.inv(); //good basis => project all points and fill HT for(unsigned int i=0;i<mPoints.size();i++) if(i!=p && i!=p2 && i!=p3) { //project in current basis Point2f relCoord=tBasisInv*(mPoints[i]-mPoints[p]); //get bin Point2i bin=toCell(relCoord); //read HT with vote for p if(bin.x>=0 && bin.x<nbBinPerDim.x && bin.y>=0 && bin.y<nbBinPerDim.y) for(int id=0;id<nbIds;id++) votesId[id]+=HashTable[bin.x*(nbBinPerDim.y*nbIds) + bin.y*nbIds + id]; } } } } //if had votes, then find the id with max value int idPointEstim=-1; int nbVotesForId=0; for(int id=0;id<nbIds;id++) if(votesId[id]>nbVotesForId) { idPointEstim=id; nbVotesForId=votesId[id]; } //find second best id to compute discriminative power int idPointSecondBest=-1; (void)idPointSecondBest; int nbVotesForSecondBest=0; for(int id=0;id<nbIds;id++) if(id!=idPointEstim && votesId[id]>nbVotesForSecondBest) { idPointSecondBest=id; nbVotesForSecondBest=votesId[id]; } //add the point&id pair to output if id not already in list; if it is then need to check which one has most votes if(nbVotesForId>0) { std::vector<DetectionGH>::iterator it; it = find_if (matches.begin(), matches.end(), findIdInDetections(idPointEstim)); if (it != matches.end())//point exist, check which one is the best { int posInList=it-matches.begin(); if(matches[posInList].nbVotes<nbVotesForId)//if new one better than existing one, then replace it { matches[posInList].position=blobs[p].pt; matches[posInList].id=idPointEstim; matches[posInList].nbVotes=nbVotesForId; matches[posInList].discriminativePower=nbVotesForId-nbVotesForSecondBest; } } else { DetectionGH newMatch(blobs[p].pt,idPointEstim,nbVotesForId,nbVotesForId-nbVotesForSecondBest); matches.push_back(newMatch); } } } }
void Box2DFrictionJoint::setLocalAnchorB(const QPointF &localAnchorB) { mFrictionJointDef.localAnchorB = toMeters(localAnchorB); mAnchorsAuto = false; emit localAnchorBChanged(); }