daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest Jun 19th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include "rply/rply.c"
  3.  
  4. typedef struct _HE_edge
  5. {
  6.  
  7.     struct HE_vert* vert;   // vertex at the end of the half-edge
  8.     struct HE_edge* pair;   // oppositely oriented adjacent half-edge
  9.     struct HE_face* face;   // face the half-edge borders
  10.     struct HE_edge* next;   // next half-edge around the face
  11.    
  12. }HE_edge;
  13.  
  14. typedef struct _HE_vert
  15. {
  16.  
  17.     float x;
  18.     float y;
  19.  
  20.     struct HE_edge* edge;  // one of the half-edges emantating from the vertex
  21.    
  22. }HE_vert;
  23.  
  24. typedef struct _HE_face
  25. {
  26.     int color;      // cor da face
  27.     struct HE_edge* edge;  // one of the half-edges bordering the face
  28.  
  29. }HE_face;
  30. HE_edge *HE;
  31. HE_vert *vertices;
  32.  
  33. int i = 0;
  34. long v0, v1, v2;
  35.  
  36. static int vertex_cb(p_ply_argument argument) {
  37.     long eol;
  38.     ply_get_argument_user_data(argument, NULL, &eol);
  39.     if (eol)
  40.        {
  41.                vertices[i].y = ply_get_argument_value(argument);
  42.                i++;
  43.        }
  44.    else
  45.        {
  46.                vertices[i].x = ply_get_argument_value(argument);
  47.        }
  48.    return 1;
  49. }
  50.  
  51. static int face_cb(p_ply_argument argument) {
  52.     long length, value_index;
  53.     ply_get_argument_property(argument, NULL, &length, &value_index);
  54.     switch (value_index) {
  55.         case 0:
  56.             v0 = ply_get_argument_value(argument);
  57.             break;
  58.         case 1:
  59.             v1 = ply_get_argument_value(argument);
  60.             break;
  61.         case 2:
  62.             v2 = ply_get_argument_value(argument);
  63.             break;
  64.         default:
  65.             break;
  66.     }
  67.     return 1;
  68. }
  69.  
  70. int main(void) {
  71.    
  72.     int arestas, nHEs;
  73.     long nvertices, ntriangles;
  74.    
  75.     p_ply ply = ply_open("rply/etc/input.ply", NULL);
  76.     if (!ply) return 1;
  77.     if (!ply_read_header(ply)) return 1;
  78.    
  79.     nvertices = ply_set_read_cb(ply, "vertex", "x", vertex_cb, NULL, 0);
  80.     ply_set_read_cb(ply, "vertex", "y", vertex_cb, NULL, 1);
  81.    
  82.     vertices = (HE_vert *) malloc (nvertices * sizeof(HE_vert));
  83.    
  84.     ntriangles = ply_set_read_cb(ply, "face", "vertex_indices", face_cb, NULL, 0);
  85.    
  86.     //calculando o numero de HEs;
  87.     arestas = nvertices + ntriangles - 2;
  88.     nHEs = arestas*2;
  89.    
  90.     HE = (HE_edge *) malloc (nHEs * sizeof(HE_edge));
  91.    
  92.     printf("%ld\n%ld\n", nvertices, ntriangles);
  93.     if (!ply_read(ply)) return 1;
  94.    
  95.     for(i = 0; i < nvertices; i++)
  96.     {
  97.         printf("X: %f, Y: %f \n", vertices[i].x, vertices[i].y);
  98.     }
  99.    
  100.     printf("Vertice 0 : %ld, Vertice 1: %ld, Vertice 2: %ld\n", v0, v1, v2);
  101.    
  102.     ply_close(ply);
  103.    
  104.     return 0;
  105. }
RAW Paste Data
Top