void TimgFilterLogoaway::Tplane::createBorder(const TlogoawaySettings *cfg,int side,int bmode) { unsigned char *s,*e; switch (side) { case TlogoawaySettings::NORTH: selectPoints(cfg,bmode,&s,&e, TlogoawaySettings::NW,TlogoawaySettings::NE, TlogoawaySettings::SW,TlogoawaySettings::SE, cfg->pointnw,cfg->pointne); createBorderH(bordn,s,e,cfg->dx>>shiftX,bmode); break; case TlogoawaySettings::EAST: selectPoints(cfg,bmode,&s,&e, TlogoawaySettings::NE,TlogoawaySettings::SE, TlogoawaySettings::NW,TlogoawaySettings::SW, cfg->pointne,cfg->pointse); createBorderV(borde,s,e,cfg->dy>>shiftY,stride2,bmode); break; case TlogoawaySettings::SOUTH: selectPoints(cfg,bmode,&s,&e, TlogoawaySettings::SW,TlogoawaySettings::SE, TlogoawaySettings::NW,TlogoawaySettings::NE, cfg->pointsw,cfg->pointse); createBorderH(bords,s,e,cfg->dx>>shiftX,bmode); break; case TlogoawaySettings::WEST: selectPoints(cfg,bmode,&s,&e, TlogoawaySettings::NW,TlogoawaySettings::SW, TlogoawaySettings::NE,TlogoawaySettings::SE, cfg->pointnw,cfg->pointsw); createBorderV(bordw,s,e,cfg->dy>>shiftY,stride2,bmode); break; } }
unsigned int RigidPointICP::calcNextStep(AbstractMesh& source, AbstractMesh const& dest) { // Select points auto sourcePoints = selectPoints(source); auto nearestPoints = m_nearestNeighbor.getAllNearest(sourcePoints, source, dest); // Sort out edge points on dest if((m_selectionMethod & NO_EDGES)) { for (unsigned int i = 0; i < nearestPoints.size(); i++) { if (nearestPoints[i].isEdge) { nearestPoints.erase(nearestPoints.begin() + i); sourcePoints.erase(sourcePoints.begin() + i); } } } // Calc averages auto srcAvg = getAverage(sourcePoints); auto destAvg = getAverage(nearestPoints); auto amountOfPoints = sourcePoints.size(); Eigen::MatrixXd X(3, amountOfPoints); Eigen::MatrixXd Y(3, amountOfPoints); // Fill X and Y for(unsigned int i = 0; i < amountOfPoints; i++) { auto srcVertex = sourcePoints[i].coords; auto corSrcVertex = srcVertex - srcAvg; X(0,i) = corSrcVertex.x(); X(1,i) = corSrcVertex.y(); X(2,i) = corSrcVertex.z(); auto destVertex = nearestPoints[i].coords; auto corDestVertex = destVertex - destAvg; Y(0, i) = corDestVertex.x(); Y(1, i) = corDestVertex.y(); Y(2, i) = corDestVertex.z(); } // Calculate optimal rotation auto XYT = X * Y.transpose(); Eigen::JacobiSVD<Eigen::MatrixXd> svd(XYT, Eigen::ComputeThinU | Eigen::ComputeThinV); auto R = svd.matrixV() * svd.matrixU().transpose(); // Translation auto t = destAvg - R * srcAvg; // Apply values to all vertices of source for (unsigned int i = 0; i < source.getAmountOfVertices(); i++) { auto vertex = source.getVertex(i); auto coords = R * vertex.coords + t; // Should be okay to use the same R for normal since the inverse of a rotation matrix // is its transpose. Thus the correct matrix is transpose(transpose(R)) = R. auto normal = R * vertex.normal; source.setVertex(i, coords, normal); } // Clear nearest neighbor cache m_nearestNeighbor.clearCache(); return sourcePoints.size(); }
/*! \brief Fonction principale: on peut choisir le nombre de points * en utilisant l'option "-nX" où X est un entier strictement * positif. * \remark Mettre opterr a 0 equivaut a supprimer volontairement les messages d'erreur renvoyes par getopt * lors de la lecture d'options non prevus sur la ligne de commande. Dans ces cas, l'erreur est traitee grace au * fait que getopt retourne la valeur '?', qui est donc traitee a part * \remark "n:" signifie que l'option n s'accompagne de la lecture immediate d'une valeur. Il ne faut pas * laisser d'espace entre -n et le nombre tape. Exemple: two -n1000.\par * La lecture est effectuee par un sscanf (lecture d'une chaine supposee formattee) sur l'argument ad hoc, optarg, * declare dans les routines de lecture de la ligne de commande. */ int main(int argc, char **argv) { int c; opterr = 0; while ((c = getopt(argc, argv, "n:f:?h")) != EOF) { switch (c) { case 'n': if ((sscanf(optarg, "%d", &nbPoints) != 1) || nbPoints <= 0) nbPoints = 50; break; case 'f': if ((sscanf(optarg, "%d", &nbPoints) != 1) || nbPoints <= 0) nbPoints = 50; break; case 'h': case '?': printf("use option -nX or -fX (no space), with 0 < X.\n"); return EXIT_SUCCESS; break; default : printf("Shouldn't be here, really...\n"); break; } } assert(nbPoints > 0); T = (vertex *) malloc(sizeof(vertex)*nbPoints); assert(T != NULL); glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); glutInitWindowPosition(5,5); glutInitWindowSize(300,300); glutCreateWindow("fenetre"); lireFichier("coord2.txt"); winInit(); selectPoints(); positionPointsParRapportPolygone(); glutDisplayFunc(display); glutMainLoop(); return EXIT_SUCCESS; }
/*! Generations des sites */ void selectPoints (void) { int n = nbPoints; rectangleEnglobantPolygone(); while (--n >= 0) { T[n].coords[0] = myRandom(0, 400); T[n].coords[1] = myRandom(0, 400); } Orientation orient = orientationPolaire(T[0],T[1],T[2]); if( orient == ALIGNES) selectPoints(); else if(orient == DROITE) // réorganisation des points dans l'ordre trigo { vertex tampon = T[1]; T[1] = T[2]; T[2] = tampon; } }
int main(int argc, char **argv) { int c; int pol,conv; int option1 = 0, option2 = 0, option3 = 0, option4 = 0; int nbPoints = 50; vertex *v; opterr = 0; while ((c = getopt(argc, argv, "1i:2o:34n:")) != EOF) { switch (c) { case '1': option1 = 1; break; case '2': option2 = 1; break; case '3': option3 = 1; break; case '4': option4 = 1; break; case 'n': if ((sscanf(optarg, "%d", &nbPoints) != 1) || nbPoints <= 0) nbPoints = 50; break; case 'o': /*verifier non null*/ out = optarg; break; case 'i': /*verifier non null*/ in = optarg; break; case 'h': case '?': printf("-1 partie 1 du tp\n"); printf("-2 partie 2 du tp\n"); printf("-3 partie 3 du tp\n"); printf("-ichaine ouvre le fichier \"chaine\" en lecture \n"); printf("-ochaine ouvre le fichier \"chaine\" en écriture \n"); return EXIT_SUCCESS; break; default : printf("Shouldn't be here, really...\n"); break; } } glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); glutInitWindowPosition(5,5); glutInitWindowSize(500,500); glutCreateWindow("fenetre"); definitionFenetre(0, 500, 0, 500, 10); winInit(); if(option1 && out != NULL) { glutDisplayFunc(display); glutMouseFunc(coordonnesPoint); ecrireFichier(out, &P); } else if(option2 && in != NULL) { lireFichier(in, &P); assert(P.p != NULL); pol = controlePolygoneSimple(); printf("controlePolygoneSimple : %d\n", pol); //glutDisplayFunc(displayPolygone); } else if(option3 && in != NULL) { lireFichier(in, &P); assert(P.p != NULL); if(controlePolygoneSimple()) conv = estConvexe(); } else if(option4 && in != NULL) { lireFichier(in, &P); assert(P.p != NULL); ALLOUER(v,nbPoints); selectPoints (v, nbPoints); if(controlePolygoneSimple() && estConvexe()) positionPointsParRapportPolygone(v, nbPoints); free(v); } glutMainLoop(); clearFenetre(); return EXIT_SUCCESS; }