BRL-CAD
overlaps.c
Go to the documentation of this file.
1 /* O V E R L A P S . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2009-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 #include "common.h"
22 
23 #include <stdlib.h>
24 #include <string.h>
25 
26 #include "ged.h" /* need GED_SEM_LIST - may have to re-think how to handle SEMS here. */
27 #include "analyze.h"
28 
29 
30 struct region_pair *
31 add_unique_pair(struct region_pair *list, /* list to add into */
32  struct region *r1, /* first region involved */
33  struct region *r2, /* second region involved */
34  double dist, /* distance/thickness metric value */
35  point_t pt) /* location where this takes place */
36 {
37  struct region_pair *rp, *rpair;
38 
39  /* look for it in our list */
41  for (BU_LIST_FOR (rp, region_pair, &list->l)) {
42 
43  if ((r1 == rp->r.r1 && r2 == rp->r2) || (r1 == rp->r2 && r2 == rp->r.r1)) {
44  /* we already have an entry for this region pair, we
45  * increase the counter, check the depth and update
46  * thickness maximum and entry point if need be and
47  * return.
48  */
49  rp->count++;
50 
51  if (dist > rp->max_dist) {
52  rp->max_dist = dist;
53  VMOVE(rp->coord, pt);
54  }
55  rpair = rp;
56  goto found;
57  }
58  }
59  /* didn't find it in the list. Add it */
60  BU_ALLOC(rpair, struct region_pair);
61  rpair->r.r1 = r1;
62  rpair->r2 = r2;
63  rpair->count = 1;
64  rpair->max_dist = dist;
65  VMOVE(rpair->coord, pt);
66  list->max_dist ++; /* really a count */
67 
68  /* insert in the list at the "nice" place */
69  for (BU_LIST_FOR (rp, region_pair, &list->l)) {
70  if (bu_strcmp(rp->r.r1->reg_name, r1->reg_name) <= 0)
71  break;
72  }
73  BU_LIST_INSERT(&rp->l, &rpair->l);
74  found:
76  return rpair;
77 }
78 
79 
80 /*
81  * Local Variables:
82  * tab-width: 8
83  * mode: C
84  * indent-tabs-mode: t
85  * c-file-style: "stroustrup"
86  * End:
87  * ex: shiftwidth=4 tabstop=8
88  */
#define BU_LIST_FOR(p, structure, hp)
Definition: list.h:365
#define BU_LIST_INSERT(old, new)
Definition: list.h:183
unsigned long count
Definition: analyze.h:75
void bu_semaphore_acquire(unsigned int i)
Definition: semaphore.c:180
struct bu_list l
Definition: analyze.h:69
Header file for the BRL-CAD common definitions.
const char * reg_name
Identifying string.
Definition: raytrace.h:539
struct region * r2
Definition: analyze.h:74
struct region * r1
Definition: analyze.h:72
#define BU_ALLOC(_ptr, _type)
Definition: malloc.h:223
vect_t coord
Definition: analyze.h:77
void bu_semaphore_release(unsigned int i)
Definition: semaphore.c:218
int bu_strcmp(const char *string1, const char *string2)
Definition: str.c:171
union region_pair::@16 r
double max_dist
Definition: analyze.h:76
#define GED_SEM_LIST
Definition: ged.h:91
struct region_pair * add_unique_pair(struct region_pair *list, struct region *r1, struct region *r2, double dist, point_t pt)
Definition: overlaps.c:31