vector<vector<int> > levelOrderBottom(TreeNode *root) { int depth = TreeDepth(root); vector<vector<int> > lot(depth); if(root == NULL) return lot; queue<TreeNode *> nodeQueue; nodeQueue.push(root); TreeNode *node; queue<int> levelQueue; int level = 0; levelQueue.push(level); while(!nodeQueue.empty()){ node = nodeQueue.front(); nodeQueue.pop(); level = levelQueue.front(); levelQueue.pop(); lot[depth - level -1].push_back(node->val); if(node->left){ nodeQueue.push(node->left); levelQueue.push(level+1); } if(node->right){ nodeQueue.push(node->right); levelQueue.push(level+1); } level++; } return lot; }
void DataFusionAltimeter::calculateHeight(const cv::Mat& depth_image, const sensor_msgs::CameraInfoConstPtr& camInfoMsg, const sensor_msgs::ImuConstPtr& imuMsg) { cv::Point2f c(camInfoMsg->K[2], camInfoMsg->K[5]); cv::Point2f f(camInfoMsg->K[0], camInfoMsg->K[4]); tf::Quaternion q; tf::quaternionMsgToTF (imuMsg->orientation, q); tf::Vector3 lot(0, 0, 1); tf::Vector3 rotated_lot = tf::quatRotate(q, lot); ROS_INFO("rotated_lot(%f, %f, %f)", rotated_lot.x(), rotated_lot.y(), rotated_lot.z()); double u = f.x*rotated_lot.x()/rotated_lot.z() + c.x; double v = f.y*rotated_lot.y()/rotated_lot.z() + c.y; ROS_INFO("uv(%f, %f)", u, v); cv::Mat tmp = depth_image.clone(); cv::circle(tmp, cv::Point((int)(u), (int)(v)), 12, cv::Scalar(255), 4); cv::circle(tmp, cv::Point((int)(u), (int)(v)), 8, cv::Scalar(0), 4); cv::circle(tmp, cv::Point((int)(u), (int)(v)), 4, cv::Scalar(255), 4); cv::imshow("lot_image", tmp); cv::waitKey(10); //double roll, pitch, yaw; //tf::Matrix3x3(q).getRPY(roll, pitch, yaw); //ROS_INFO("%f, %f, %f", roll, pitch, yaw); //ROS_INFO("rosq(%f, %f, %f, %f)", imuMsg->orientation.x, imuMsg->orientation.y, imuMsg->orientation.z, imuMsg->orientation.w); }
static void lot(int* ylo,int* yhi,int ivr,int slt,int hor) {int iv,/* sl, */ tn, tp, yl, yh, l; int flg; *ylo = 0; *yhi = 0; {edgeinvert *with1 = &diag.vertlist[ivr-1][slt-1]; if ((IN_PRTCL|OUT_PRTCL)&with1->prop) return; iv = with1->nextvert.vno; } tp = howin(iv); flg = 1; tn = diag.valence[iv-1]; if (tp == 0 && (tn == 4 || (hor && tn == 3 && (OUT_PRTCL&diag.vertlist[iv-1][1].prop) && (OUT_PRTCL&diag.vertlist[iv-1][2].prop)))) { lot(&yl,&yh,iv,tn,1); *ylo += yl + yh + 1; --(tn); } for (l = tn; l >= 2; l--) if (!(IN_PRTCL&diag.vertlist[iv-1][l-1].prop)) { lot(&yl,&yh,iv,l,flg); if (flg) { flg = 0; *ylo += yl; *yhi += yh; } else *yhi += yl + yh + 1; } } /* The end of Lot's body */
void DealHelp::UpdateDisplay() { SDL_FillRect(m_pScreen, NULL, SDL_MapRGB(m_pScreen->format, 153, 153, 255)); nSDL_DrawString(m_pScreen, m_pFont, 15, 20, "Deal or No Deal is a game.\n\ There are 26 cases each containing\n\ money from a lot ($1,000,000) to\n\ very little ($0.01).\n\ \n\ You want the high value case; however\n\ the banker wants you to take a deal\n\ for the lesser value.\n\ \n\ Your object is to get the highest\n\ amount you can!\n\ \n\ Good luck!\n\ \n\ Also have fun!"); SDL_UpdateRect(m_pScreen, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); }
static void painter(int xc,int yc,int ivr,int slt,int hor) {int tp, l, xcnt, ycnt, xx, yy, hh, ylo, yhi, start, ks, kk, pp; int flag; /* char buff[10]; for(l=0;l<deep;l++) buff[l]=' '; buff[l]=0; deep++; printf("New vertex vrt=%d slt=%d \n",ivr,slt); */ flag = 0; start = 2; xcnt = xc; ycnt = yc; tp = howin(ivr); ks = wherein(ivr); kk = ks == diag.valence[ivr-1] ? diag.valence[ivr-1] - 1 : diag.valence[ivr-1] ; lot(&ylo,&yhi,ivr,kk,hor); //printf("%s vert=%d kk=%d hor=%d ylo=%d yhi=%d\n",buff,ivr,kk,hor,ylo,yhi); pp = ks == kk - 1 ? kk - 2 : kk - 1; if (tp == 2) { if (ylo < 2) ycnt += ystep; else { ycnt += ylo * ystep; yc += (ylo - 1) * ystep; } mline(xstart,yc,xcnt,ycnt,ivr,slt,1); mline(xstart,ycnt,xcnt,ycnt,ivr,ks,1); } else if (tp == 1) { if (yc == ystart) ycnt += ylo * ystep; if (hor && diag.valence[ivr-1] == 4) { lot(&hh,&yy,ivr,pp,hor); //printf("%s tp=1, ivr=%d pp=%d hh=%d yy=%d\n",buff, ivr,pp,hh,yy); ycnt += (yhi + hh + 1) * ystep; start = 1; } mline(xstart,ycnt,xcnt,ycnt,ivr,ks,1); } else if (diag.valence[ivr-1] == 4) { start = 1; if (!hor) cr(1,xcnt++,ycnt,ivr,slt); } else if (hor && (OUT_PRTCL&diag.vertlist[ivr-1][1].prop) && (OUT_PRTCL&diag.vertlist[ivr-1][2].prop)) start = 1; //printf("%s first start=%d\n",buff,start); res->scr[xcnt-1][ycnt-1] = vertsign; if (xcnt > res->mhor) res->mhor = xcnt; for (l = kk; l >= 2; l--) {edgeinvert *with1 = &diag.vertlist[ivr-1][l-1]; if (!(IN_PRTCL & with1->prop)) { if (flag) { // lot(&ylo,&yhi,ivr,l,start != 3); lot(&ylo,&yhi,ivr,l,start==2); //printf("%s start=%d vrt=%d l=%d hor=%d ylo=%d yhi=%d\n",buff, start, ivr,l, start==2, ylo,yhi); } else flag = 1; xx = (OUT_PRTCL&with1->prop) ? xend : start == 3 ? xcnt : xcnt + xstep; {vertlink *with2 = &with1->nextvert; if (start == 1) { // lot(&hh,&yy,ivr,pp,1); lot(&hh,&yy,ivr,l-1,1); //printf("%s statr1 vrt=%d l-1=%d hh=%d yy=%d\n",buff, ivr, l-1,hh,yy); yy = ycnt - (hh +1) * ystep; mline(xcnt,ycnt,xx,yy,with2->vno,with2->edno,0); if (!(OUT_PRTCL & with1->prop)) painter(xx,yy,with2->vno,with2->edno,1); } else if (start == 2) { lot(&hh,&yhi,ivr,l,1); mline(xcnt,ycnt,xx,ycnt,with2->vno,with2->edno,1); if (!(OUT_PRTCL&with1->prop)) painter(xx,ycnt,with2->vno,with2->edno,1); yy = yhi; // yy=ylo; } else { //printf("%s start=? %d yy=%d ylo=%d\n",buff,start,yy,ylo); yy += ylo + 1; // yy+=yhi+1; //printf("%s down %d\n",buff,yy); yy = ycnt + yy * ystep; mline(xcnt,ycnt,xx,yy,with2->vno,with2->edno,0); if (!(OUT_PRTCL&with1->prop)) painter(xx,yy,with2->vno,with2->edno,0); } } ++(start); } } } /* The end of Painter's body */