[BACK]Return to hidden3d.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gnuplot

Diff for /OpenXM_contrib/gnuplot/Attic/hidden3d.c between version 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2000/01/22 14:15:58 version 1.1.1.3, 2003/09/15 07:09:25
Line 288  static t_hl_extent_y *ymin_hl, *ymax_hl;
Line 288  static t_hl_extent_y *ymin_hl, *ymax_hl;
    Each column is splitted into pairs of points (a,b).     Each column is splitted into pairs of points (a,b).
    Each pair describes a cross of one line with the column. */     Each pair describes a cross of one line with the column. */
   
   /* HBB 20000608: finally, someone found a serious bug in this code :-(
    * whenever the Cross_store array has to be reallocated, all the
    * pointers in hl_buffer, and the next pointers in struct Cross become
    * invalid. Use indices instead of pointers. */
   
 struct Cross {  struct Cross {
     int a, b;      int a, b;
     struct Cross GPHUGE *next;      unsigned int next;          /* (unsigned int) -1 means: no next */
       /* HBB 20000608: was struct Cross GPHUGE *next;*/
 };  };
   
   #if 0 /* HBB 20000608 */
 static struct Cross GPHUGE *GPHUGE * hl_buffer;  static struct Cross GPHUGE *GPHUGE * hl_buffer;
   #else
   static unsigned int GPHUGE * hl_buffer;
   #endif
   
 /* HBB 980303: added a global array of Cross structures, to save lots  /* HBB 980303: added a global array of Cross structures, to save lots
  * of gp_alloc() calls (3 millions in a run through all.dem!)  */   * of gp_alloc() calls (3 millions in a run through all.dem!)  */
   
 #define CROSS_STORE_INCREASE 500        /* number of Cross'es to alloc at a time */  #define CROSS_STORE_INCREASE 500        /* number of Cross'es to alloc at a time */
 static struct Cross *Cross_store = 0;  static struct Cross *Cross_store = 0;
 static int last_Cross_store = 0, free_Cross_store = 0;  static unsigned int last_Cross_store = 0, free_Cross_store = 0;
   
 struct Vertex {  struct Vertex {
     coordval x, y, z;      coordval x, y, z;
Line 454  static GP_INLINE int maybe_build_polygon __PROTO((stru
Line 464  static GP_INLINE int maybe_build_polygon __PROTO((stru
          int n, long *v, long line, int style, struct lp_style_type * lp,           int n, long *v, long line, int style, struct lp_style_type * lp,
                long next, long next_frag, int id, t_poly_tested tested));                 long next, long next_frag, int id, t_poly_tested tested));
 static void init_polygons __PROTO((struct surface_points * plots, int pcount));  static void init_polygons __PROTO((struct surface_points * plots, int pcount));
 static int compare_by_zmax __PROTO((const void *p1, const void *p2));  int compare_by_zmax __PROTO((SORTFUNC_ARGS p1, SORTFUNC_ARGS p2));
 static void sort_by_zmax __PROTO((void));  static void sort_by_zmax __PROTO((void));
 static int obscured __PROTO((struct Polygon GPHUGE * p));  static int obscured __PROTO((struct Polygon GPHUGE * p));
 static GP_INLINE int xy_overlap __PROTO((struct Polygon GPHUGE * a, struct Polygon GPHUGE * b));  static GP_INLINE int xy_overlap __PROTO((struct Polygon GPHUGE * a, struct Polygon GPHUGE * b));
Line 473  static long split_polygon_by_plane __PROTO((long P, do
Line 483  static long split_polygon_by_plane __PROTO((long P, do
 static int in_front __PROTO((long Last, long Test));  static int in_front __PROTO((long Last, long Test));
   
 /* HBB 980303: new, for the new back-buffer for *Cross structures: */  /* HBB 980303: new, for the new back-buffer for *Cross structures: */
 static GP_INLINE struct Cross *get_Cross_from_store __PROTO((void));  static GP_INLINE unsigned int get_Cross_from_store __PROTO((void));
 static GP_INLINE void init_Cross_store __PROTO((void));  static GP_INLINE void init_Cross_store __PROTO((void));
   
 static GP_INLINE TBOOLEAN hl_buffer_set __PROTO((int xv, int yv));  static GP_INLINE TBOOLEAN hl_buffer_set __PROTO((int xv, int yv));
Line 644  void init_hidden_line_removal()
Line 654  void init_hidden_line_removal()
         yfact = 1;          yfact = 1;
     if (pnt == 0) {      if (pnt == 0) {
         i = XREDUCE(xright) - XREDUCE(xleft) + 1;          i = XREDUCE(xright) - XREDUCE(xleft) + 1;
         pnt = (tp_pnt *) gp_alloc(          pnt = (tp_pnt *) gp_alloc(i * sizeof(tp_pnt), "hidden pnt");
                      (unsigned long) (i * sizeof(tp_pnt)), "hidden pnt");  
         while (--i >= 0)          while (--i >= 0)
             pnt[i] = (tp_pnt) 0;              pnt[i] = (tp_pnt) 0;
     }      }
Line 903  long *v, line, next, next_frag;
Line 912  long *v, line, next, next_frag;
     (v) = 0; /* flag this as undefined */ \      (v) = 0; /* flag this as undefined */ \
     (c) = (border) = 0; \      (c) = (border) = 0; \
   } else {\    } else {\
   (v) = (long *) gp_alloc ((unsigned long) sizeof (long) * (n), "hidden PREPARE_POLYGON"); \    (v) = (long *) gp_alloc (sizeof (long) * (n), "hidden PREPARE_POLYGON"); \
   (v)[0] = vert_free + (i0);\    (v)[0] = vert_free + (i0);\
   (v)[1] = vert_free + (i1);\    (v)[1] = vert_free + (i1);\
   (v)[2] = vert_free + (i2);\    (v)[2] = vert_free + (i2);\
Line 975  int pcount;
Line 984  int pcount;
         }          }
     }      }
     vlist = (struct Vertex GPHUGE *)      vlist = (struct Vertex GPHUGE *)
         gp_alloc((unsigned long) sizeof(struct Vertex) * nvert, "hidden vlist");          gp_alloc(sizeof(struct Vertex) * nvert, "hidden vlist");
     plist = (struct Polygon GPHUGE *)      plist = (struct Polygon GPHUGE *)
         gp_alloc((unsigned long) sizeof(struct Polygon) * npoly, "hidden plist");          gp_alloc(sizeof(struct Polygon) * npoly, "hidden plist");
   
     /* initialize vlist: */      /* initialize vlist: */
     for (vert_free = 0, this_plot = plots, surface = 0;      for (vert_free = 0, this_plot = plots, surface = 0;
Line 1243  int pcount;
Line 1252  int pcount;
                     vert_free++;                      vert_free++;
                     break;                      break;
                 case DOTS:                  case DOTS:
                     v1 = (long *) gp_alloc((unsigned long) sizeof(long) * 1,                      v1 = (long *) gp_alloc(sizeof(long) * 1,
                                            "hidden v1 for dots");                                             "hidden v1 for dots");
                     v1[0] = vert_free++;                      v1[0] = vert_free++;
                     CHECK_PLIST();                      CHECK_PLIST();
Line 1259  int pcount;
Line 1268  int pcount;
                 case FINANCEBARS:                  case FINANCEBARS:
                 case POINTSTYLE:                  case POINTSTYLE:
                 case VECTOR:                  case VECTOR:
                     v1 = (long *) gp_alloc((unsigned long) sizeof(long) * 1,                      v1 = (long *) gp_alloc(sizeof(long) * 1,
                                            "hidden v1 for point");                                             "hidden v1 for point");
                     v1[0] = vert_free++;                      v1[0] = vert_free++;
                     CHECK_PLIST();                      CHECK_PLIST();
Line 1269  int pcount;
Line 1278  int pcount;
                 case BOXES:     /* handle as IMPULSES */                  case BOXES:     /* handle as IMPULSES */
                 case IMPULSES:                  case IMPULSES:
                     n1 = 2;                      n1 = 2;
                     v1 = (long *) gp_alloc((unsigned long) sizeof(long) * n1,                      v1 = (long *) gp_alloc(sizeof(long) * n1,
                                            "hidden v1 for impulse");                                             "hidden v1 for impulse");
                     v1[0] = vert_free++;                      v1[0] = vert_free++;
                     v1[1] = vert_free++;                      v1[1] = vert_free++;
Line 1283  int pcount;
Line 1292  int pcount;
     }      }
 }  }
   
 static int compare_by_zmax(p1, p2)  int compare_by_zmax(p1, p2)
 const void *p1, *p2;      SORTFUNC_ARGS p1;
       SORTFUNC_ARGS p2;
 {  {
     return (SIGNOF(plist[*(const long *) p2].zmax - plist[*(const long *) p1].zmax));      return (SIGNOF(plist[*(const long *) p2].zmax
                      - plist[*(const long *) p1].zmax));
 }  }
   
 static void sort_by_zmax()  static void sort_by_zmax()
Line 1294  static void sort_by_zmax()
Line 1305  static void sort_by_zmax()
 {  {
     long *sortarray, i;      long *sortarray, i;
     struct Polygon GPHUGE *this;      struct Polygon GPHUGE *this;
     sortarray = (long *) gp_alloc((unsigned long) sizeof(long) * pfree, "hidden sortarray");      sortarray = (long *) gp_alloc(sizeof(long) * pfree, "hidden sortarray");
     for (i = 0; i < pfree; i++)      for (i = 0; i < pfree; i++)
         sortarray[i] = i;          sortarray[i] = i;
     qsort(sortarray, (size_t) pfree, sizeof(long), compare_by_zmax);      qsort(sortarray, (size_t) pfree, sizeof(long), compare_by_zmax);
Line 1935  TBOOLEAN f;   /* return value = Front(1) or Back(0) */
Line 1946  TBOOLEAN f;   /* return value = Front(1) or Back(0) */
     /* We need two new polygons instead of the old one: */      /* We need two new polygons instead of the old one: */
     n1 = p->n - cross2 + cross1 + 2;      n1 = p->n - cross2 + cross1 + 2;
     n2 = cross2 - cross1 + 2;      n2 = cross2 - cross1 + 2;
     v1 = (long *) gp_alloc((unsigned long) sizeof(long) * n1,      v1 = (long *) gp_alloc(sizeof(long) * n1, "hidden v1 for two new poly");
                            "hidden v1 for two new poly");      v2 = (long *) gp_alloc(sizeof(long) * n2, "hidden v2 for two new poly");
     v2 = (long *) gp_alloc((unsigned long) sizeof(long) * n2,  
                            "hidden v2 for two new poly");  
 #if SHOW_SPLITTING_EDGES  #if SHOW_SPLITTING_EDGES
     line1 = 1L << (n1 - 1);      line1 = 1L << (n1 - 1);
     line2 = 1L << (n2 - 1);      line2 = 1L << (n2 - 1);
Line 2140  long Last, Test;
Line 2149  long Last, Test;
             test->tested = is_moved_or_split;              test->tested = is_moved_or_split;
             SPLIT_TEST_BY_P;              SPLIT_TEST_BY_P;
         } else {          } else {
             if (loop && (p->tested == is_tested)) {              if (loop && (p->tested == is_in_loop)) {
                 /* Ouch, seems like we're in trouble, really */                  /* Ouch, seems like we're in trouble, really: no way to
                    * split one of them, and we're in a loop, so we can't
                    * move p to the front of the list, without risking an
                    * endless loop. Well, let's just output the darn thing,
                    * then, no matter what. :-( */
   #if DEBUG /* normally off */
                 fprintf(stderr, "\                  fprintf(stderr, "\
 #Failed: In loop, without intersections.\n\  #Failed: In loop, without intersections.\n\
 #Relations are %d, %d\n",  #Relations are %d, %d\n",
                         p_rel_tplane, t_rel_pplane);                          p_rel_tplane, t_rel_pplane);
                 print_polygon(test, "test");                  print_polygon(test, "test");
                 print_polygon(p, "p");                  print_polygon(p, "p");
   #endif
                 continue;       /* Keep quiet, maybe no-one will notice (;-) */                  continue;       /* Keep quiet, maybe no-one will notice (;-) */
             } else {              } else {
                 PUT_P_IN_FRONT_TEST(is_in_loop);                  PUT_P_IN_FRONT_TEST(is_in_loop);
Line 2210  static GP_INLINE void init_Cross_store()
Line 2225  static GP_INLINE void init_Cross_store()
     last_Cross_store = CROSS_STORE_INCREASE;      last_Cross_store = CROSS_STORE_INCREASE;
     free_Cross_store = 0;      free_Cross_store = 0;
     Cross_store = (struct Cross *)      Cross_store = (struct Cross *)
         gp_alloc((unsigned long) last_Cross_store * sizeof(struct Cross),          gp_alloc(last_Cross_store * sizeof(struct Cross), "hidden cross store");
                  "hidden cross store");  
 }  }
   
 static GP_INLINE struct Cross *get_Cross_from_store()  static GP_INLINE unsigned int
   get_Cross_from_store()
 {  {
     while (last_Cross_store <= free_Cross_store) {      while (last_Cross_store <= free_Cross_store) {
         last_Cross_store += CROSS_STORE_INCREASE;          last_Cross_store += CROSS_STORE_INCREASE;
Line 2223  static GP_INLINE struct Cross *get_Cross_from_store()
Line 2238  static GP_INLINE struct Cross *get_Cross_from_store()
                  (unsigned long) last_Cross_store * sizeof(struct Cross),                   (unsigned long) last_Cross_store * sizeof(struct Cross),
                        "hidden cross store");                         "hidden cross store");
     }      }
     return Cross_store + (free_Cross_store++);      return free_Cross_store++;
 }  }
   
 static GP_INLINE TBOOLEAN  static GP_INLINE TBOOLEAN
  hl_buffer_set(xv, yv)   hl_buffer_set(xv, yv)
 int xv, yv;  int xv, yv;
 {  {
     struct Cross GPHUGE *c;      unsigned int c;
   
     /*HBB 961110: lclint wanted this: */      /*HBB 961110: lclint wanted this: */
     assert(hl_buffer != 0);      assert(hl_buffer != 0);
     for (c = hl_buffer[xv]; c != NULL; c = c->next)      for (c = hl_buffer[xv];
         if (c->a <= yv && c->b >= yv) {           c < last_Cross_store;
            c = Cross_store[c].next)
           if (Cross_store[c].a <= yv && Cross_store[c].b >= yv) {
             return TRUE;              return TRUE;
         }          }
     return FALSE;      return FALSE;
Line 2248  static int hl_buff_xmin, hl_buff_xmax;
Line 2266  static int hl_buff_xmin, hl_buff_xmax;
 /* Store a line crossing the x interval around xv between y = ya and  /* Store a line crossing the x interval around xv between y = ya and
  * y = yb in the hl_buffer */   * y = yb in the hl_buffer */
 static GP_INLINE void update_hl_buffer_column(xv, ya, yb)  static GP_INLINE void update_hl_buffer_column(xv, ya, yb)
 int xv, ya, yb;      int xv, ya, yb;
 {  {
     struct Cross GPHUGE *GPHUGE * cross, GPHUGE * cross2;      unsigned int cross, cross2;
       TBOOLEAN still_in_hl_buffer = TRUE;
   
     /* First, ensure that ya <= yb */      /* First, ensure that ya <= yb */
     if (ya > yb) {      if (ya > yb) {
Line 2259  int xv, ya, yb;
Line 2278  int xv, ya, yb;
         ya = y_temp;          ya = y_temp;
     }      }
     /* loop over all previous crossings at this x-value */      /* loop over all previous crossings at this x-value */
     for (cross = hl_buffer + xv; 1; cross = &(*cross)->next) {      for (cross = hl_buffer[xv], still_in_hl_buffer = TRUE;
         if (*cross == NULL) {           1;
            cross = Cross_store[cross].next, still_in_hl_buffer = FALSE
            ) {
           if (cross > last_Cross_store) {
             /* first or new highest crossing at this x-value */              /* first or new highest crossing at this x-value */
   
             /* HBB 980303: new method to allocate Cross structures */              /* HBB 980303: new method to allocate Cross structures */
             *cross = get_Cross_from_store();              cross = get_Cross_from_store();
             (*cross)->a = ya;              if (still_in_hl_buffer)
             (*cross)->b = yb;                  hl_buffer[xv] = cross;
             (*cross)->next = NULL;              Cross_store[cross].a = ya;
               Cross_store[cross].b = yb;
               Cross_store[cross].next = (unsigned int) -1;
             /* HBB 961201: keep track of x-range of hl_buffer, to              /* HBB 961201: keep track of x-range of hl_buffer, to
              * speedup free()ing it */               * speedup free()ing it */
             if (xv < hl_buff_xmin)              if (xv < hl_buff_xmin)
Line 2276  int xv, ya, yb;
Line 2300  int xv, ya, yb;
                 hl_buff_xmax = xv;                  hl_buff_xmax = xv;
             break;              break;
         }          }
         if (yb < (*cross)->a - 1) {          if (yb < Cross_store[cross].a - 1) {
             /* crossing below 'cross', create new entry before 'cross' */              /* crossing below 'cross', create new entry before 'cross' */
             cross2 = *cross;              cross2 = cross;
             /* HBB 980303: new method to allocate Cross structures */              /* HBB 980303: new method to allocate Cross structures */
             *cross = get_Cross_from_store();              cross = get_Cross_from_store();
             (*cross)->a = ya;              if (still_in_hl_buffer)
             (*cross)->b = yb;                  hl_buffer[xv] = cross;
             (*cross)->next = cross2;              Cross_store[cross].a = ya;
               Cross_store[cross].b = yb;
               Cross_store[cross].next = cross2;
             break;              break;
         } else if (ya <= (*cross)->b + 1) {          } else if (ya <= Cross_store[cross].b + 1) {
             /* crossing overlaps or covers 'cross' */              /* crossing overlaps or covers 'cross' */
             if (ya < (*cross)->a)              if (ya < Cross_store[cross].a)
                 (*cross)->a = ya;                  Cross_store[cross].a = ya;
             if (yb > (*cross)->b) {              if (yb > Cross_store[cross].b) {
                 if ((*cross)->next && (*cross)->next->a <= yb) {                  if (Cross_store[cross].next < last_Cross_store
                       && Cross_store[Cross_store[cross].next].a <= yb
                       ) {
                     /* crossing spans all the way up to 'cross->next' so                      /* crossing spans all the way up to 'cross->next' so
                      * unite them */                       * unite them */
                     cross2 = (*cross)->next;                      cross2 = Cross_store[cross].next;
                     (*cross)->b = cross2->b;                      Cross_store[cross].b = Cross_store[cross2].b;
                     (*cross)->next = cross2->next;                      Cross_store[cross].next = Cross_store[cross2].next;
                 } else                  } else
                     (*cross)->b = yb;                      Cross_store[cross].b = yb;
             }              }
             break;              break;
         }          }
Line 2625  struct Polygon GPHUGE *p;
Line 2653  struct Polygon GPHUGE *p;
     for (i = hl_buff_xmin; i <= hl_buff_xmax; i++) {      for (i = hl_buff_xmin; i <= hl_buff_xmax; i++) {
         /* HBB 980303: one part was removed here. It isn't needed any more,          /* HBB 980303: one part was removed here. It isn't needed any more,
          * with the global store for Cross structs. */           * with the global store for Cross structs. */
         hl_buffer[i] = NULL;          hl_buffer[i] = (unsigned int) -1;
     }      }
     /* HBB 980303: instead, set back the free pointer of the Cross store: */      /* HBB 980303: instead, set back the free pointer of the Cross store: */
     free_Cross_store = 0;      free_Cross_store = 0;
Line 2644  struct Polygon GPHUGE *p;
Line 2672  struct Polygon GPHUGE *p;
             if (ymin_hl[i] == HL_EXTENT_Y_MAX)              if (ymin_hl[i] == HL_EXTENT_Y_MAX)
                 graph_error("Logic error #2 in hidden line");                  graph_error("Logic error #2 in hidden line");
             if (pnt[i] == 0) {              if (pnt[i] == 0) {
                 pnt[i] = (t_pnt *) gp_alloc((unsigned long) y_malloc, "hidden ymalloc");                  pnt[i] = (t_pnt *) gp_alloc(y_malloc, "hidden ymalloc");
                 memset(pnt[i], 0, (size_t) y_malloc);                  memset(pnt[i], 0, (size_t) y_malloc);
             }              }
             if (ymin_hl[i] < 0 || ymax_hl[i] > YREDUCE(ytop) - YREDUCE(ybot))              if (ymin_hl[i] < 0 || ymax_hl[i] > YREDUCE(ytop) - YREDUCE(ybot))
Line 2691  int pcount;
Line 2719  int pcount;
     y_malloc = (2 + (YREDUCE(ytop) >> 4) - (YREDUCE(ybot) >> 4)) * sizeof(t_pnt);      y_malloc = (2 + (YREDUCE(ytop) >> 4) - (YREDUCE(ybot) >> 4)) * sizeof(t_pnt);
     /* ymin_hl, ymax_hl: */      /* ymin_hl, ymax_hl: */
     i = sizeof(t_hl_extent_y) * (XREDUCE(xright) - XREDUCE(xleft) + 1);      i = sizeof(t_hl_extent_y) * (XREDUCE(xright) - XREDUCE(xleft) + 1);
     ymin_hl = (t_hl_extent_y *) gp_alloc((unsigned long) i, "hidden ymin_hl");      ymin_hl = (t_hl_extent_y *) gp_alloc(i, "hidden ymin_hl");
     ymax_hl = (t_hl_extent_y *) gp_alloc((unsigned long) i, "hidden ymax_hl");      ymax_hl = (t_hl_extent_y *) gp_alloc(i, "hidden ymax_hl");
     for (i = (XREDUCE(xright) - XREDUCE(xleft)); i >= 0; i--) {      for (i = (XREDUCE(xright) - XREDUCE(xleft)); i >= 0; i--) {
         ymin_hl[i] = HL_EXTENT_Y_MAX;          ymin_hl[i] = HL_EXTENT_Y_MAX;
         ymax_hl[i] = 0;          ymax_hl[i] = 0;
Line 2701  int pcount;
Line 2729  int pcount;
     /* HBB 980303 new: initialize the global store for Cross structs: */      /* HBB 980303 new: initialize the global store for Cross structs: */
     init_Cross_store();      init_Cross_store();
     i = XREDUCE(xright) - XREDUCE(xleft) + 1;      i = XREDUCE(xright) - XREDUCE(xleft) + 1;
     hl_buffer =      hl_buffer = (unsigned int GPHUGE *)
         (struct Cross GPHUGE * GPHUGE *) gp_alloc((unsigned long) (i * sizeof(struct Cross GPHUGE *)),          gp_alloc(i * sizeof(unsigned int), "hidden hl_buffer");
                                                   "hidden hl_buffer");  
     while (--i >= 0)      while (--i >= 0)
         hl_buffer[i] = (struct Cross *) 0;          hl_buffer[i] = (unsigned int) -1;
   
     init_polygons(plots, pcount);      init_polygons(plots, pcount);
   

Legend:
Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>