Polyligne

Polyligne

par Alexandre Aubry,
Nombre de réponses : 1

Bonjour à tous,

Dans la fonction my_mouse_down, j'ai du mal à comprendre comment doit on définir les points de la polyligne ?

Faut il mettre les variables x et y dans la matrice "points", ou bien dans les matrices Cp et Ip ? Cp et Ip sont ils des points qui doivent être défini dans la matrice "points" ? Y a t'il une bibliothèque particulière à utiliser ?

Merci d'avance pour vos éclaircissements,

Bonne soirée,

Alexandre

En réponse à Alexandre Aubry

Re: Polyligne

par Eric Paquette,
Explications supplémentaires pour les différentes variables :
  // Vertices and faces of the plane onto which the user will click to define the polyline.
  const Eigen::MatrixXd V= (Eigen::MatrixXd(4,3)<<
    0.0,-0.5,-0.01, 
    0.0, 0.5,-0.01, 
    1.0,-0.5,-0.01, 
    1.0, 0.5,-0.01).finished(); 
  const Eigen::MatrixXi F = (Eigen::MatrixXi(2,3)<<
    1,3,4,
    1,4,2).finished().array()-1;
  // We begin with 2 initial points on the polyline
  int nbPoints = 2;
  // Edges of the polyline as pairs of indices to the points matrix.
  Eigen::MatrixXi edges;
  // Matrix of RGB colors for the edges (one color per edge).
  Eigen::MatrixXd edgeColors;
  
  // XYZ coordinates of the polyline vertices
  Eigen::MatrixXd points = Eigen::MatrixXd(nbPoints,3);
  // RGB colors, one color for each vertex of the polyline
  Eigen::MatrixXd Cp; 
  // Need to hold down the shift key to add vertices to the polyline
  const int ShiftModifier = 1;
  // Matrices for the surface of revolution vertices and faces.
  Eigen::MatrixXd RV;
  Eigen::MatrixXi RF;
  // Number of strips of faces around the axis. 
  // If nbSubdiv = 4, then the vertices in the plane are rotated 
  // every 360 / 4 = 90 degrees. 
  // nbSubdiv must be greater or equal to 3.
  // The user can change the number of subdivisions by pressing keys from 3 to 9
  int nbSubdiv = 4;
  // Initially, we can add points. We will set this to false later.
  bool addingPoints = true;
Explications supplémentaires pour les my_mouse_down :
    if(igl::unproject_onto_mesh(Eigen::Vector2f(x,y), viewer.core().view,
viewer.core().proj, viewer.core().viewport,
V, F, fid, bc))
    {
      // Increase the matrix size to make room fo the new point.
      // Resize the matrix while keeping the data.
      points.conservativeResize(points.rows()+1, 3);
     
      // Add your code here. 
      // You need to make sure to move the former last point to the last position in points. 
      // Insert the XYZ position of the new point at the second to last position in points. 
      // Adjust Cp (size and contained colors). Adjust the colors with the jet function.
      // Adjust the edges (size and contained indices) given the new point 
      // inserted before the last point. 
      // Adjust the edgeColors (size and contained colors). Adjust the colors with 
      // the jet function.
      // Offset the new point with respect to the plane by setting its
      // Z value to 0.0.
      points(points.rows() - 2,2) = 0.0;
      // Color the vertices and edges from blue to red using the jet fonction.
      viewer.data().set_points(points, Cp);
      viewer.data().set_edges(points, edges, edgeColors);
      
      return true;
    }

N'hésitez pas à poser d'autres questions si ça n'est pas clair. Nous pourrons également en discuter au cours.