//--------------------------------------------------------- void Poly3D::BuildTriangles() //--------------------------------------------------------- { // Calculate the center of the polygon umWARNING("Poly3D::BuildTriangles()", "TODO: Check from where this is called!"); int Nr=m_xyz.num_rows(), Nc=m_xyz.num_cols(); DMat t_xyz; t_xyz.borrow(Nr,Nc, m_xyz.data()); DVec cent = t_xyz.row_sums() / (double)m_N; //DVec cent = sum(poly.m_xyz,2) / (double)m_N; // Sort the points by angle where the angle is // measured from the center of the polygon SortPoints(cent); // now build triangles DVec a,b; double totalarea = 0.0; for (int i=1; i<=m_N; ++i) { a = t_xyz(All,i); //b = poly.m_xyz(All, mod(i,poly.m_N)+1); b = t_xyz(All, 1 + (i%m_N)); AddTriangle(cent, a, b); totalarea += m_areas(i); } // Clear the polygon if the total area // of the polygon is too small. double tol = 1e-6; if (totalarea < tol) { Clear(); } }
void Graphics::PlotTriangle(HDC hdc, const TriangleSelfContained& triangle) { ScreenPoint points[3] = { triangle[0], triangle[1], triangle[2] }; if ((Approximately(points[0].x, points[1].x) && Approximately(points[1].x, points[2].x)) || (Approximately(points[0].y, points[1].y) && Approximately(points[1].y, points[2].y))) return; SortPoints(points); if (Approximately(points[0].y, points[1].y)) { PlotFlatTopTriangle(hdc, points[0], points[1], points[2], triangle.GetTexture()); } else if (Approximately(points[1].y, points[2].y)) { PlotFlatBottomTriangle(hdc, points[1], points[2], points[0], triangle.GetTexture()); } else { float tx = points[0].x + (points[1].y - points[0].y) * (points[2].x - points[0].x) / float(points[2].y - points[0].y); Color color = (points[0].color + (points[2].color - points[0].color) * ((points[1].y - points[0].y) / float(points[2].y - points[0].y))); float tz = points[0].z + (points[1].y - points[0].y) * (points[2].z - points[0].z) / float(points[2].y - points[0].y); float tu = points[0].u + (points[1].y - points[0].y) * (points[2].u - points[0].u) / float(points[2].y - points[0].y); float tv = points[0].v + (points[1].y - points[0].y) * (points[2].v - points[0].v) / float(points[2].y - points[0].y); ScreenPoint tp(tx, points[1].y, tz, tu, tv, color); PlotFlatBottomTriangle(hdc, tp, points[1], points[0], triangle.GetTexture()); PlotFlatTopTriangle(hdc, points[1], tp, points[2], triangle.GetTexture()); } }
void THighscoreHolder::UpdatePoints() { if ( iPointArray[iNumberOfItems - 1] < iActivePoints ) { iPointArray[iNumberOfItems - 1] = iActivePoints; SortPoints(); iActivePoints = 0; } }
void THighscoreHolder::InternalizeL(RReadStream& aStream) { for ( TInt i = 0 ; i < iNumberOfItems ; i++ ) { TInt error; TRAP(error, RestorePointL(i, aStream)); if ( error ) { iPointArray[i] = 0; } } SortPoints(); }
void CPlotPoints::Plot(FILE *pO,const char *pTitle,int AutoScale) { ///---------------------------------------------------------------------------- /// Plot /// This function plots all of the axis. The first /// axis in the list is the x axis, and all of the /// following lists of points are the various functions /// of the x axis. The scale for each Y axis is /// printed reight below the title line. /// /// parameters: /// pO.........pointer to the file to write data to /// pTitle....pointer to the tile of plot /// AutoScale.Auto Scale Plots if true ///---------------------------------------------------------------------------- int TotalPoints; int j,k; char *lab = new char[256]; FPoints *pP = m_pH; ///fget pointer to X axis points TotalPoints = pP->GetTotalPoints(); ///print title if(pTitle) { int len = strlen(pTitle); int spaces = (m_Hieght - len)/2; int extra = (m_Hieght - len)%2; for(j=0;j<(spaces-3);++j) lab[j] = '*'; for(;j<spaces;++j) lab[j] = ' '; strcpy(&lab[j],pTitle); j += len; for(k=0;k<3;++j,++k) lab[j] = ' '; for(k=0;k<(spaces-3 + extra);++k,++j) lab[j] = '*'; lab[j] = 0; fprintf(pO,"%s\n",lab); } ///Scale Data int i=0; pP = pP->GetNext(); //get first Y axis ///----------------------------------------- /// If no hight has been specified use 80 /// as the default ///----------------------------------------- if(this->m_Hieght==0) m_Hieght = 80; ///----------------------------------------- /// Even if we are not going to auto scale /// we still do this loop because this is /// where we also count the number of axis /// to plot. ///----------------------------------------- while(pP) { if(AutoScale) pP->Scale(m_Hieght); pP = pP->GetNext(); ++i; ///count the number of axis } int TotalAxis = i; ///Axis lableling double *pAxisInc = new double[TotalAxis]; pP = m_pH; pP = pP->GetNext(); ///first Y axis i = 0; ///--------------------------------- /// Calculate the increment for /// each Y axis ///--------------------------------- while(pP) { pAxisInc[i++] = (pP->GetMax() - pP->GetMin())/(double(m_Hieght-1)/10.0); pP = pP->GetNext(); } pP = m_pH; pP = pP->GetNext(); ///first Y axis i = 0; int axis = 0; ///---------------------------------- /// Calculate the total number of /// Y axis labels. ///---------------------------------- int YaxisLabels = (m_Hieght/10) + 1; ///--------------------------------- /// Actually do the labeling for /// the Y axis ///--------------------------------- while(pP) { int j,k; for(j=0,i=0;j<YaxisLabels;++j) { i += sprintf(&lab[i],"%6.2lf",pP->GetMin() + pAxisInc[axis] * double(j)); if(j<YaxisLabels-1) for(k=i;k%10;++k) lab[i++] = ' '; } sprintf(&lab[i],"(%c)%s\n",pP->GetDispChar(),pP->GetName()); fprintf(pO,"%s",lab); ++axis; pP = pP->GetNext(); } ///---------------------------------------------------- /// Draw X Axis and plot points ///---------------------------------------------------- /// Create an array of pointer to the Point Pointers FPoints** axOrder = new FPoints*[TotalAxis]; pP = m_pH; ///get the head of the points list pP = pP->GetNext(); /// Get first Y axis for(i=0;i<TotalAxis;++i,pP=pP->GetNext() ) axOrder[i] = pP; ///fill up the array for(k=0;k<TotalPoints;++k) ///plot all points { SortPoints(axOrder,TotalAxis,k); ///sort points ///draw plot for this X point int flag = 1; for(i=0,j=0;(i<TotalAxis) && flag;++i) { for(;(j<int(axOrder[i]->GetScaledVal(k))) && (j<m_Hieght);++j) { lab[j] = PlotChar(k,j); } ///if we haven't run out of plot room ///plot the plot character for that point if(j<m_Hieght) lab[j++] = axOrder[i]->GetDispChar(); ///and if j is equal to the plot height ///we are done. if(j>= m_Hieght) flag = 0; } ///if there is still room, finish up for this /// x axis point for(;j<m_Hieght;++j) lab[j] = PlotChar(k,j); ///add X axis value sprintf(&lab[j]," %8.6e",m_pH->GetVal(k)); ///output to the print device fprintf(pO,"%s\n",lab); } delete[] axOrder; ///delete allocated variables delete[] lab; }
// // Function: FindCorners // Purpose : This function finds the corner points in the calibration images // using opencv functions cvFindChessBoardCornerGuesses and // cvFindCornerSubPix. After image pixel coordinates are found, their // respective world coordinates are assigned. (z coordinate is always // zero). When the function cannot find the specified number of // coordinates in the image, the image is discarded because of the // added complexity in assigning their world coordinates. // Output : uveff : coordinates of the chessborder in image plane. // XYZeff: coordinates of uveff w.r.t World Coordinate System // m_effective_image_no : number of images processed. //---------------------------------------------------------------------------- void camcal::FindCorners() { IplImage* img = 0; IplImage* img0 = 0; IplImage* img1 = 0; IplImage* greyimg = 0; CvFont dfont; cvInitFont (&dfont, CV_FONT_VECTOR0, 0.3, 0.3, 0.0f, 1); CvPoint onecorner; int numcorners = m_corner_no; CvPoint2D64d* uv = new CvPoint2D64d[m_image_number * m_corner_no]; CvPoint3D64d* XYZ = new CvPoint3D64d[m_image_number * m_corner_no]; CvPoint2D32f* corners = new CvPoint2D32f[m_corner_no]; CvMemStorage* storage = 0; m_effective_image_no=-1; for( int imgnum=0; imgnum<m_image_number; imgnum++ ) { numcorners = m_corner_no; img = m_input_images[imgnum]; imgsize.width = img->width; imgsize.height= img->height; img0 = cvCloneImage(img); img1 = cvCloneImage(img); greyimg = cvCreateImageHeader(imgsize,IPL_DEPTH_8U,1); cvCreateImageData(greyimg); cvCvtColor(img, greyimg, CV_RGB2GRAY); img0 = cvCloneImage(greyimg); cvFindChessBoardCornerGuesses(greyimg, img0, storage, cvSize(m_x_height,m_x_width), corners, &numcorners); if( numcorners != m_corner_no ) { cvReleaseImage( &img0 ); cvReleaseImage( &img1 ); cvReleaseImage( &greyimg ); continue; } else m_effective_image_no++; // draw a circle at each corner found for( int t = 0; t < numcorners; t++ ) { onecorner.x = (int)corners[t].x; onecorner.y = (int)corners[t].y; cvCircle(img1, onecorner, 8, CV_RGB(0,255,0),2); // image, center, radius, color, thickness } // Find sub-corners cvFindCornerSubPix(greyimg, corners, numcorners, cvSize (m_x_height,m_x_width), cvSize(-1, -1), cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 10, 0.1)); // correct order if( m_apply_ordering ){ CvPoint3D32f init = FindRectangleCorner( corners, numcorners ); if( init.z < m_x_height*m_x_width ) SortPoints(corners, numcorners, &init); else { cout<<"Sort Error"; cvReleaseImage( &img0 ); cvReleaseImage( &img1 ); cvReleaseImage( &greyimg ); m_effective_image_no--; continue; } } //draw a circle and put the corner number at each subcorner found for( int t = 0; t < numcorners; t++ ) { onecorner.x = (int)corners[t].x; onecorner.y = (int)corners[t].y; cvCircle(img1, onecorner, 3, CV_RGB(255,0,0),1); char buf[10]; sprintf( buf, "%d", t ); // cvPutText(img1,numbers[t], cvPoint(onecorner.x, onecorner.y + 20), &dfont, CV_RGB(255,0,0)); cvPutText(img1, buf, cvPoint(onecorner.x, onecorner.y + 20), &dfont, CV_RGB(255,0,0)); } // CAMERA CALIBRATION PART for( int currPoint=0; currPoint < numcorners; currPoint++ ) { uv[ m_effective_image_no*numcorners + currPoint].x = corners[currPoint].x; uv[ m_effective_image_no*numcorners + currPoint].y = corners[currPoint].y; } int index; for( int i = 0; i < m_x_width; i++ ) { for( int j = 0; j < m_x_height; j++ ) { index = m_effective_image_no*numcorners + i*m_x_height+j; XYZ[ index ].x = m_grid_width *(m_x_width -i); XYZ[ index ].y = m_grid_height*(m_x_height-j); XYZ[ index ].z = 0; } } if( m_display_corners ) { cvvNamedWindow( "image", 1 ); cvvShowImage("image",img1); cvvWaitKey(0); cvDestroyWindow( "image" ); } // cvReleaseImage( &img ); cvReleaseImage( &img0 ); cvReleaseImage( &img1 ); cvReleaseImage( &greyimg ); } //loop to next image free (corners); m_effective_image_no++; delete []uveff ; uveff =NULL; delete []XYZeff; XYZeff = NULL; if( m_image_number == m_effective_image_no ){ uveff = uv; uv = NULL; XYZeff = XYZ; XYZ = NULL; } else { int size = m_effective_image_no * m_corner_no; uveff = new CvPoint2D64d[size]; XYZeff = new CvPoint3D64d[size]; for(int ph=0; ph<size; ph++) { uveff [ph] = uv [ph]; XYZeff[ph] = XYZ[ph]; } delete []uv; uv = NULL; delete []XYZ; XYZ = NULL; } }