pqp
 All Classes
PQP_Internal.h
1 /*************************************************************************\
2 
3  Copyright 1999 The University of North Carolina at Chapel Hill.
4  All Rights Reserved.
5 
6  Permission to use, copy, modify and distribute this software and its
7  documentation for educational, research and non-profit purposes, without
8  fee, and without a written agreement is hereby granted, provided that the
9  above copyright notice and the following three paragraphs appear in all
10  copies.
11 
12  IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE
13  LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
14  CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE
15  USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
16  OF NORTH CAROLINA HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
17  DAMAGES.
18 
19  THE UNIVERSITY OF NORTH CAROLINA SPECIFICALLY DISCLAIM ANY
20  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
22  PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
23  NORTH CAROLINA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
24  UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 
26  The authors may be contacted via:
27 
28  US Mail: S. Gottschalk, E. Larsen
29  Department of Computer Science
30  Sitterson Hall, CB #3175
31  University of N. Carolina
32  Chapel Hill, NC 27599-3175
33 
34  Phone: (919)962-1749
35 
36  EMail: geom@cs.unc.edu
37 
38 
39 \**************************************************************************/
40 
41 #include "Tri.h"
42 #include "BV.h"
43 
44 class PQP_Model
45 {
46 
47 public:
48 
49  int build_state;
50 
51  Tri *tris;
52  int num_tris;
53  int num_tris_alloced;
54 
55  BV *b;
56  int num_bvs;
57  int num_bvs_alloced;
58 
59  Tri *last_tri; // closest tri on this model in last distance test
60 
61  BV *child(int n) { return &b[n]; }
62 
63  PQP_Model();
64  ~PQP_Model();
65 
66  int BeginModel(int num_tris = 8); // preallocate for num_tris triangles;
67  // the parameter is optional, since
68  // arrays are reallocated as needed
69  int AddTri(const PQP_REAL *p1, const PQP_REAL *p2, const PQP_REAL *p3,
70  int id);
71  int EndModel();
72  int MemUsage(int msg); // returns model mem usage.
73  // prints message to stderr if msg == TRUE
74 };
75 
77 {
78  int id1;
79  int id2;
80 };
81 
83 {
84  // stats
85 
86  int num_bv_tests;
87  int num_tri_tests;
88  double query_time_secs;
89 
90  // xform from model 1 to model 2
91 
92  PQP_REAL R[3][3];
93  PQP_REAL T[3];
94 
95  int num_pairs_alloced;
96  int num_pairs;
97  CollisionPair *pairs;
98 
99  void SizeTo(int n);
100  void Add(int i1, int i2);
101 
104 
105  // statistics
106 
107  int NumBVTests() { return num_bv_tests; }
108  int NumTriTests() { return num_tri_tests; }
109  double QueryTimeSecs() { return query_time_secs; }
110 
111  // free the list of contact pairs; ordinarily this list is reused
112  // for each query, and only deleted in the destructor.
113 
114  void FreePairsList();
115 
116  // query results
117 
118  int Colliding() { return (num_pairs > 0); }
119  int NumPairs() { return num_pairs; }
120  int Id1(int k) { return pairs[k].id1; }
121  int Id2(int k) { return pairs[k].id2; }
122 };
123 
124 #if PQP_BV_TYPE & RSS_TYPE // distance/tolerance are only available with RSS
125 
127 {
128  // stats
129 
130  int num_bv_tests;
131  int num_tri_tests;
132  double query_time_secs;
133 
134  // xform from model 1 to model 2
135 
136  PQP_REAL R[3][3];
137  PQP_REAL T[3];
138 
139  PQP_REAL rel_err;
140  PQP_REAL abs_err;
141 
142  PQP_REAL distance;
143  PQP_REAL p1[3];
144  PQP_REAL p2[3];
145  int qsize;
146 
147  // statistics
148 
149  int NumBVTests() { return num_bv_tests; }
150  int NumTriTests() { return num_tri_tests; }
151  double QueryTimeSecs() { return query_time_secs; }
152 
153  // The following distance and points established the minimum distance
154  // for the models, within the relative and absolute error bounds
155  // specified.
156  // Points are defined: PQP_REAL p1[3], p2[3];
157 
158  PQP_REAL Distance() { return distance; }
159  const PQP_REAL *P1() { return p1; }
160  const PQP_REAL *P2() { return p2; }
161 };
162 
164 {
165  // stats
166 
167  int num_bv_tests;
168  int num_tri_tests;
169  double query_time_secs;
170 
171  // xform from model 1 to model 2
172 
173  PQP_REAL R[3][3];
174  PQP_REAL T[3];
175 
176  int closer_than_tolerance;
177  PQP_REAL tolerance;
178 
179  PQP_REAL distance;
180  PQP_REAL p1[3];
181  PQP_REAL p2[3];
182  int qsize;
183 
184  // statistics
185 
186  int NumBVTests() { return num_bv_tests; }
187  int NumTriTests() { return num_tri_tests; }
188  double QueryTimeSecs() { return query_time_secs; }
189 
190  // If the models are closer than ( <= ) tolerance, these points
191  // and distance were what established this. Otherwise,
192  // distance and point values are not meaningful.
193 
194  PQP_REAL Distance() { return distance; }
195  const PQP_REAL *P1() { return p1; }
196  const PQP_REAL *P2() { return p2; }
197 
198  // boolean says whether models are closer than tolerance distance
199 
200  int CloserThanTolerance() { return closer_than_tolerance; }
201 };
202 
203 #endif