home *** CD-ROM | disk | FTP | other *** search
/ Practical Algorithms for Image Analysis / Practical Algorithms for Image Analysis.iso / TARFILE.GZ / tarfile / ch_5.4 / fitcrit / linkfeats.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-11  |  3.4 KB  |  135 lines

  1. /* LINKFEATS:   contains functions for creating and adding to linked list
  2.  *            of WW features
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include "pcc2.h"
  8. #include <images.h>
  9.  
  10. extern struct featNode *featHead,  /* linked list of features for */
  11.  *featTail;                     /* beginning and current list pos */
  12. extern long nFeats;             /* number of ww features */
  13.  
  14. int featadd (int, char *, struct dpoint);
  15. int insertendfeat (struct featNode **, struct point);
  16.  
  17. /* LINKCORNER: */
  18.  
  19. int
  20. linkcorner (type, coord)
  21.      int type;
  22.      struct point coord;
  23. {
  24.   struct featK *featK;
  25.   struct dpoint intrsct;        /* corner intersection */
  26.  
  27.   featK = (struct featK *) malloc (sizeof (struct featK));
  28.   featK->coord = coord;
  29.   intrsct.x = (double) coord.x;
  30.   intrsct.y = (double) coord.y;
  31.   featadd (type, (char *) featK, intrsct);  /*, CURVELT180); */
  32.  
  33.   return (0);
  34. }
  35.  
  36. /* LINKCURVE: */
  37.  
  38. int
  39. linkcurve (intrsct, trans1, trans2, center, radiusC, curveDirn)
  40.      struct dpoint intrsct;     /* intersection of tangents to curve */
  41.      struct point trans1, trans2;  /* transition pts from lines to curve */
  42.      struct dpoint center;      /* center of curvature */
  43.      double radiusC;            /* radius of curvature */
  44.      short curveDirn;           /* direction of curve */
  45. {
  46.   struct featC *featC;
  47.  
  48.   featC = (struct featC *) malloc (sizeof (struct featC));
  49.   featC->trans1 = trans1;
  50.   featC->trans2 = trans2;
  51.   featC->center = center;
  52.   featC->radiusC = radiusC;
  53.   featC->dirn = curveDirn;
  54.   featadd (WWCURVE, (char *) featC, intrsct);
  55.  
  56.   return (0);
  57. }
  58.  
  59.  
  60.  
  61. /* FEATADD: */
  62.  
  63. int
  64. featadd (type, info, intrsct)
  65.      int type;
  66.      char *info;
  67.      struct dpoint intrsct;     /* corner, or tangent intersection */
  68. {
  69.   struct featNode *featNew;
  70.  
  71.   nFeats++;
  72.   featNew = (struct featNode *) malloc (sizeof (struct featNode));
  73.   featNew->type = type;
  74.   featNew->intrsct = intrsct;
  75.   featNew->info = info;
  76.   featNew->next = NULL;
  77.   if (featHead == NULL) {
  78.     featNew->previous = NULL;
  79.     featHead = featTail = featNew;
  80.   }
  81.   else {
  82.     featNew->previous = featTail;
  83.     featTail->next = featNew;
  84.     featTail = featNew;
  85.   }
  86.  
  87.   return (0);
  88. }
  89.  
  90.  
  91. /* INSERTENDFEAT: */
  92.  
  93. int
  94. insertendfeat (featEnd, endPt)
  95.      struct featNode **featEnd; /* ptr to end feature ptr */
  96.      struct point endPt;        /* new end point */
  97. {
  98.   struct featNode *featNew;     /* ptr to new feature */
  99.   struct dpoint intrsct;        /* (double) of <endPt> */
  100.   struct featK *featK;          /* information for new end feature */
  101.  
  102.   nFeats++;
  103.   featNew = (struct featNode *) malloc (sizeof (struct featNode));
  104.   featNew->type = (*featEnd)->type;
  105.   intrsct.x = (double) endPt.x;
  106.   intrsct.y = (double) endPt.y;
  107.   featNew->intrsct = intrsct;
  108.   featK = (struct featK *) malloc (sizeof (struct featK));
  109.   featK->coord = endPt;
  110.   featNew->info = (char *) featK;
  111.  
  112.   if (featNew->type == WWSTRT) {  /* start feature type */
  113.     featNew->previous = (*featEnd)->previous;
  114.     featNew->next = (*featEnd);
  115.     if ((*featEnd)->previous != NULL)
  116.       ((*featEnd)->previous)->next = featNew;
  117.     (*featEnd)->previous = featNew;
  118.     (*featEnd)->type = WWCORNER;
  119.     if ((*featEnd) == featHead)
  120.       featHead = featNew;
  121.   }
  122.   else {                        /* end feature type */
  123.     featNew->previous = (*featEnd);
  124.     featNew->next = (*featEnd)->next;
  125.     if ((*featEnd)->next != NULL)
  126.       ((*featEnd)->next)->previous = featNew;
  127.     (*featEnd)->next = featNew;
  128.     (*featEnd)->type = WWCORNER;
  129.   }
  130.  
  131.   (*featEnd) = featNew;
  132.  
  133.   return (0);
  134. }
  135.