forked from PachydermAcoustic/Hare
/
Hare_Geometry_Topology.cs
665 lines (588 loc) · 26.5 KB
/
Hare_Geometry_Topology.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
//'Hare: Accelerated Multi-Resolution Ray Tracing (GPL)
//'
//'Copyright (c) 2008 - 2015, Arthur van der Harten
//'This program is free software; you can redistribute it and/or modify
//'it under the terms of the GNU General Public License as published
//'by the Free Software Foundation; either version 3 of the License, or
//'(at your option) any later version.
//'This program is distributed in the hope that it will be useful,
//'but WITHOUT ANY WARRANTY; without even the implied warranty of
//'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//'GNU General Public License for more details.
//'
//'You should have received a copy of the GNU General Public
//'License along with this program; if not, write to the Free Software
//'Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
namespace Hare
{
namespace Geometry
{
/// <summary>
/// A class describing a topological model.
/// </summary>
public class Topology
{
/// <summary>
/// A list of vertices.
/// </summary>
private System.Collections.Generic.SortedDictionary<ulong, System.Collections.Generic.SortedDictionary<ulong, Point>> Vertices;
private List<Point> Vertices_List = new List<Point>();
/// <summary>
/// A list of polygons.
/// </summary>
public List<Polygon> Polys = new List<Polygon>();
/// <summary>
/// A list of planes on which polygons lie.
/// </summary>
public List<plane> planeList = new List<plane>();
/// <summary>
/// The min point of the topology bounding box.
/// </summary>
public Point Min;
/// <summary>
/// A list of planes and their polygons.
/// </summary>
public List<int>[] Plane_Members = new List<int>[0];
/// <summary>
/// The max point of the topology bounding box.
/// </summary>
public Point Max;
/// <summary>
/// The number of significant digits to which all points are rounded.
/// </summary>
public int Prec;
public MS_AABB Modspace;
/// <summary>
/// A simple constructor which initializes the topology at maximum precision.
/// </summary>
private Topology() : this(15) { }
/// <summary>
/// A simple constructor which allows the user to choose the precision.
/// </summary>
/// <param name="Precision">The number of significant digits the vertices will be rounded to.</param>
private Topology(int Precision)
{
//Vertices = new List<Point>();
Max = new Point(double.MinValue, double.MinValue, double.MinValue);
Min = new Point(double.MaxValue, double.MaxValue, double.MaxValue);
Vertices = new SortedDictionary<ulong, SortedDictionary<ulong, Point>>();
Prec = Precision;
}
public Topology(Point Minpt, Point Maxpt)
:this()
{
this.Max = Maxpt;
this.Min = Minpt;
Modspace = new MS_AABB(Min, Max);
}
public Topology(Point[][] T, int Precision)
: this(Precision)
{
double Minx = double.MaxValue, Miny = double.MaxValue, Minz = double.MaxValue;
double Maxx = double.MinValue, Maxy = double.MinValue, Maxz = double.MinValue;
foreach (Point[] parr in T) foreach (Point p in parr)
{
if (Minx > p.x) Minx = p.x;
if (Miny > p.y) Miny = p.y;
if (Minz > p.z) Minz = p.z;
if (Maxx < p.x) Maxx = p.x;
if (Maxy < p.y) Maxy = p.y;
if (Maxz < p.z) Maxz = p.z;
}
Min = new Point(Minx, Miny, Minz);
Max = new Point(Maxx, Maxy, Maxz);
Modspace = new MS_AABB(Min, Max);
Build_Topology(T);
}
/// <summary>
/// Initializes the topology with an explicit list of polygons and vertices.
/// </summary>
/// <param name="T">An array of arrays of points. The points represent vertices. The arrays represent the vertices of a single polygon.</param>
public Topology(Point[][] T)
: this()
{
double Minx = double.MaxValue, Miny = double.MaxValue, Minz = double.MaxValue;
double Maxx = double.MinValue, Maxy = double.MinValue, Maxz = double.MinValue;
foreach (Point[] parr in T) foreach (Point p in parr)
{
if (Minx > p.x) Minx = p.x;
if (Miny > p.y) Miny = p.y;
if (Minz > p.z) Minz = p.z;
if (Maxx < p.x) Maxx = p.x;
if (Maxy < p.y) Maxy = p.y;
if (Maxz < p.z) Maxz = p.z;
}
Min = new Point(Minx, Miny, Minz);
Max = new Point(Maxx, Maxy, Maxz);
Modspace = new MS_AABB(Min, Max);
Build_Topology(T);
}
/// <summary>
/// Finalizes the topology by updating the axis-aligned bounding box of the model.
/// </summary>
public void Finish_Topology()
{
//double Minx;
//double Miny;
//double Minz;
//double Maxx;
//double Maxy;
//double Maxz;
//Minx = double.MaxValue;
//Miny = double.MaxValue;
//Minz = double.MaxValue;
//Maxx = double.MinValue;
//Maxy = double.MinValue;
//Maxz = double.MinValue;
//foreach (Point p in Vertices)
//{
// if (p.x < Minx) Minx = p.x;
// if (p.y < Miny) Miny = p.y;
// if (p.z < Minz) Minz = p.z;
// if (p.x > Maxx) Maxx = p.x;
// if (p.y > Maxy) Maxy = p.y;
// if (p.z > Maxz) Maxz = p.z;
//}
//Min = new Point(Minx, Miny, Minz);
//Max = new Point(Maxx, Maxy, Maxz);
}
/// <summary>
/// Finalizes the topology by updating the axis-aligned bounding box of the model.
/// </summary>
/// <param name="EXPTS">A list of points which are not part of the model but need to be included in the axis-aligned bounding box.</param>
public void Finish_Topology(List<Point> EXPTS)
{
double Minx = Modspace.Min.x;
double Miny = Modspace.Min.y;
double Minz = Modspace.Min.z;
double Maxx = Modspace.Max.x;
double Maxy = Modspace.Max.y;
double Maxz = Modspace.Max.z;
//Minx = double.MaxValue;
//Miny = double.MaxValue;
//Minz = double.MaxValue;
//Maxx = double.MinValue;
//Maxy = double.MinValue;
//Maxz = double.MinValue;
//for (int i = 0; i < Vertices.Count; i++) for (int j = 0; j < Vertices[i].Count; j++) foreach (Point p in Vertices[i][j])
//{
// if (p.x < Minx) Minx = p.x;
// if (p.y < Miny) Miny = p.y;
// if (p.z < Minz) Minz = p.z;
// if (p.x > Maxx) Maxx = p.x;
// if (p.y > Maxy) Maxy = p.y;
// if (p.z > Maxz) Maxz = p.z;
//}
foreach (Point p in EXPTS)
{
if (p.x < Minx) Minx = p.x;
if (p.y < Miny) Miny = p.y;
if (p.z < Minz) Minz = p.z;
if (p.x > Maxx) Maxx = p.x;
if (p.y > Maxy) Maxy = p.y;
if (p.z > Maxz) Maxz = p.z;
}
Min = new Point(Minx, Miny, Minz);
Max = new Point(Maxx, Maxy, Maxz);
}
public void Add_Polygon(Point[] P, int Plane_ID)
{
List<Point> VertexList = new List<Point>(P.Length);
if (Plane_ID > Plane_Members.Length-1)
{
Array.Resize<List<int>>(ref Plane_Members, Plane_ID+1);
for (int i = 0; i < Plane_ID+1; i++)
{
if (Plane_Members[Plane_ID] == null) Plane_Members[Plane_ID] = new List<int>();
}
}
Plane_Members[Plane_ID].Add(Polys.Count);
for (int p = 0; p < P.Length; p++)
{
VertexList.Add(this.AddGetIndex(P[p]));
}
//Array.Resize(ref Polys, Polys.Length + 1);
if (P.Length == 4)
{
lock (Top_Lock) Polys.Add(new Quadrilateral(ref VertexList, 0, Polys.Count - 1, Plane_ID));
//Polys[Polys.Count - 1] = new Quadrilateral(ref Vertices, VertexList, 0, Polys.Length - 1);
}
else if (P.Length == 3)
{
lock (Top_Lock) Polys.Add(new Triangle(ref VertexList, 0, Polys.Count - 1, Plane_ID));
//Polys[Polys.Count - 1] = new Triangle(ref Vertices, VertexList, 0, Polys.Length - 1);
}
else
{
throw new NotImplementedException("Hare Does not yet support polygons of more than 4 sides.");
}
}
/// <summary>
/// Adds a polygon to the topology. Can be used immediately after initializing the topology.
/// </summary>
/// <param name="P">An array of Points which make up the vertices of the polygon.</param>
public void Add_Polygon(Point[] P)
{
List<Point> VertexList = new List<Point>(P.Length);
for (int p = 0; p < P.Length; p++)
{
VertexList.Add(this.AddGetIndex(P[p]));
}
//Array.Resize(ref Polys, Polys.Length + 1);
if (P.Length == 4)
{
lock (Top_Lock) Polys.Add(new Quadrilateral(ref VertexList, 0, Polys.Count));
//Polys[Polys.Count - 1] = new Quadrilateral(ref Vertices, VertexList, 0, Polys.Length - 1);
}
else if (P.Length == 3)
{
lock(Top_Lock) Polys.Add(new Triangle(ref VertexList, 0, Polys.Count));
//Polys[Polys.Count - 1] = new Triangle(ref Vertices, VertexList, 0, Polys.Length - 1);
}
else
{
throw new NotImplementedException("Hare Does not yet support polygons of more than 4 sides.");
}
plane p1 = new plane(Polys[Polys.Count-1]);
for(int i = 0; i < planeList.Count; i++) if (p1.GetHashCode() == planeList[i].GetHashCode())
{
Polys[Polys.Count - 1].Plane_ID = i;
Plane_Members[i].Add(Polys.Count - 1);
return;
}
planeList.Add(p1);
Array.Resize<List<int>>(ref Plane_Members, Plane_Members.Length+1);
Plane_Members[Plane_Members.Length-1] = new List<int>();
Plane_Members[Plane_Members.Length-1].Add(Polys.Count-1);
Polys[Polys.Count - 1].Plane_ID = planeList.Count-1;
}
Object Top_Lock = new Object();
public void Build_Topology(Point[][] T)
{
Min = new Point(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity);
Max = new Point(double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity);
Vertices = new SortedDictionary<ulong,SortedDictionary<ulong,Point>>();
Polys = new List<Polygon>(T.Length);
//for (int i = 0; i < T.Length; i++)
System.Threading.Tasks.Parallel.For(0, T.Length, i =>
{
List<Point> VertexList = new List<Point>();
for (int p = 0; p < T[i].Length; p++)
{
VertexList.Add(this.AddGetIndex(T[i][p]));
}
if (VertexList.Count == 4)
{
lock (Top_Lock) Polys.Add(new Quadrilateral(ref VertexList, 0, Polys.Count));
}
else if (VertexList.Count == 3)
{
lock (Top_Lock) Polys.Add(new Triangle(ref VertexList, 0, Polys.Count));
}
else
{
throw new NotImplementedException("Hare Does not yet support polygons of more than 4 sides.");
}
});
}
/// <summary>
/// Checks to see if the topology has a given point. If it does, it returns the index of the point. If not, it adds it and returns the index of the new point.
/// </summary>
/// <param name="x">The point to be found or added.</param>
/// <returns>The index of the point.</returns>
//private int AddGetIndex(Point x)
//{
// x.Round(Prec);
// try
// {
// for (int q = 0; q < Vertices.Length; q++)
// {
// if (Vertices[q].x == x.x && Vertices[q].y == x.y && Vertices[q].z == x.z)
// {
// return q;
// }
// }
// Array.Resize(ref Vertices, Vertices.Length + 1);
// Vertices[Vertices.Length - 1] = x;
// return Vertices.Length - 1;
// }
// catch (NullReferenceException)
// {
// Vertices[0] = x;
// return 0;
// }
//}
private Point AddGetIndex(Point x)
{
//Identify which grid point the point is located in...
x.Round(Prec);
lock (Top_Lock)
{
SortedDictionary<ulong, Point> D;
Point p;
ulong Hash_1, Hash_2;
x.Hash2(this.Modspace, out Hash_1, out Hash_2);
if (Vertices.TryGetValue(Hash_1, out D))
{
if (D.TryGetValue(Hash_2, out p))
{
return p;//Vertices[q];
}
else
{
D.Add(Hash_2, x);
Vertices_List.Add(x);
}
}
else
{
D = new SortedDictionary<ulong,Point>();
D.Add(Hash_2, x);
Vertices.Add(Hash_1, D);
Vertices_List.Add(x);
}
}
//if (x.x < Min.x) Min.x = x.x;
//if (x.y < Min.y) Min.y = x.y;
//if (x.z < Min.z) Min.z = x.z;
//if (x.x > Max.x) Max.x = x.x;
//if (x.y > Max.y) Max.y = x.y;
//if (x.z > Max.z) Max.z = x.z;
return x;
}
/// <summary>
/// Returns a point referenced by a given index.
/// </summary>
/// <param name="index">The point index.</param>
/// <returns>The indexed point.</returns>
public Point this[int index]
{
get
{
return this.Vertices_List[index];
}
}
/// <summary>
/// Returns a point referenced by a given polygon and vertex index.
/// </summary>
/// <param name="Poly_ID">The index of the polygon.</param>
/// <param name="Corner_ID">The index of the vertex of a given polygon.</param>
/// <returns>The indexed point.</returns>
public Point this[int Poly_ID, int Corner_ID]
{
get
{
return Polys[Poly_ID].Points[Corner_ID];
}
}
/// <summary>
/// Checks a ray for an intersection with a given polygon.
/// </summary>
/// <param name="Poly_ID">The index of the polygon to be checked.</param>
/// <param name="R">The ray to be intersected with the polygon.</param>
/// <param name="X">An event describing the intersection of the ray with the polygon.</param>
/// <returns>true if ray intersects, false if not.</returns>
public bool intersect(int Poly_ID, Ray R, out X_Event X)
{
double u, v, t;
Point P;
Polys[Poly_ID].Intersect(R,this.Polygon_Vertices(Poly_ID), out P, out u, out v, out t, out Poly_ID);
X = new X_Event(P, u, v, t, Poly_ID);
return true;
}
/// <summary>
/// Checks a ray for an intersection with a given polygon.
/// </summary>
/// <param name="Poly_ID">The index of the polygon to be checked.</param>
/// <param name="R">The ray to be intersected with the polygon.</param>
/// <param name="X">An event describing the intersection of the ray with the polygon.</param>
/// <returns>true if ray intersects, false if not.</returns>
public bool intersect(int Poly_ID, Ray R, out Point P, out double u, out double v, out double t)
{
return Polys[Poly_ID].Intersect(R, this.Polygon_Vertices(Poly_ID), out P, out u, out v, out t, out Poly_ID);
}
/// <summary>
/// Gets the array of vertices that make up a polygon.
/// </summary>
/// <param name="Poly_ID">The index of the polygon.</param>
/// <returns>an array of points.</returns>
public Point[] Polygon_Vertices(int Poly_ID)
{
Point[] P = new Point[Polys[Poly_ID].VertexCount];
for (int i = 0; i < P.Length; i++)
{
P[i] = Polys[Poly_ID].Points[i];
}
return P;
}
/// <summary>
/// Gets the number of polygons in the topology.
/// </summary>
public int Polygon_Count
{
get
{
return Polys.Count;
}
}
/// <summary>
/// Gets the number of vertices in the topology.
/// </summary>
public int Vertex_Count
{
get
{
return Vertices_List.Count;
}
}
/// <summary>
/// Gets the normal of a referenced polygon.
/// </summary>
/// <param name="Poly_ID">The index of the polygon.</param>
/// <returns>the normal of the polygon.</returns>
public Vector Normal(int Poly_ID)
{
return Polys[Poly_ID].Normal;
}
/// <summary>
/// Gets the area of the polygon.
/// Adapted from http://www.softsurfer.com/Archive/algorithm_0101/algorithm_0101.htm, by Dan Sunday.
/// </summary>
/// <param name="Poly_ID">The index of the polygon.</param>
/// <returns>the area of the polygon.</returns>
public double Polygon_Area(int Poly_ID)
{
double area = 0;
for (int i = 1, j = 2, k = 0; j < Polys[Poly_ID].VertexCount; i++, j++)
{
area += .5 * Hare.Geometry.Hare_math.Cross(Polys[Poly_ID].Points[i] - Polys[Poly_ID].Points[k], Polys[Poly_ID].Points[i] - Polys[Poly_ID].Points[j]).Length();
}
return area;
}
/// <summary>
/// Gets the centroid of a referenced polygon.
/// </summary>
/// <param name="Poly_ID">The index of the polygon.</param>
/// <returns>the centroid of the polygon.</returns>
public Point Polygon_Centroid(int Poly_ID)
{
Point P = new Point();
for (int i = 0; i < Polys[Poly_ID].VertexCount; i++)
{
P += Polys[Poly_ID].Points[i];
}
return P / Polys[Poly_ID].VertexCount;
}
/// <summary>
/// Gets the distance from a point to the closest point on a plane.
/// </summary>
/// <param name="P">The point to reference.</param>
/// <param name="Poly_ID">The polygon from which the plane to be used will be taken.</param>
/// <returns>the distance from the point to the plane.</returns>
public double DistToPlane (Point P, int Poly_ID)
{
return Polys[Poly_ID].DistToPlane(P);
}
/// <summary>
/// Gets the closest point on a polygon to a given point.
/// </summary>
/// <param name="P">The point to reference.</param>
/// <param name="Poly_ID">The index of the polygon.</param>
/// <returns>The point on the polygon</returns>
public Point Closest_Point(Point P, int Poly_ID)
{
Point[] PT = new Point[Polys[Poly_ID].VertexCount -2];
for (int p = 0, i = 0, j = 1, k = 2; k < Polys[Poly_ID].VertexCount;p++, j++, k++)
{
PT[p] = TriangleClosestPt(P, Polys[Poly_ID].Points[i], Polys[Poly_ID].Points[j], Polys[Poly_ID].Points[k]);
}
double PS, AS;
Point A = PT[0];
AS = A.x * A.x + A.y * A.y + A.z * A.z;
for (int p = 1; p < PT.Length; p++)
{
PS = PT[p].x * PT[p].x + PT[p].y * PT[p].y + PT[p].z * PT[p].z;
if (AS < PS)
{
AS = PS;
A = PT[p];
}
}
return A;
}
/// <summary>
/// The closest point on a triangle to a given point.
/// </summary>
/// <param name="p">The referenced point.</param>
/// <param name="a">Vertex a</param>
/// <param name="b">Vertex b</param>
/// <param name="c">Vertex c</param>
/// <returns>The closest point.</returns>
protected Point TriangleClosestPt(Point p, Point a, Point b, Point c)
{
// Check if P in vertex region outside A
Vector ab = b - a;
Vector ac = c - a;
Vector ap = p - a;
double d1 = Hare_math.Dot(ab, ap);
double d2 = Hare_math.Dot(ac, ap);
if (d1 <= 0.0f && d2 <= 0.0f) return a; // barycentric coordinates (1,0,0)
// Check if P in vertex region outside B
Vector bp = p - b;
double d3 = Hare_math.Dot(ab, bp);
double d4 = Hare_math.Dot(ac, bp);
if (d3 >= 0.0f && d4 <= d3) return b; // barycentric coordinates (0,1,0)
// Check if P in edge region of AB, if so return projection of P onto AB
double vc = d1 * d4 - d3 * d2;
if (vc <= 0.0f && d1 >= 0.0f && d3 <= 0.0f)
{
double v = d1 / (d1 - d3);
return a + v * ab; // barycentric coordinates (1-v,v,0)
}
// Check if P in vertex region outside C
Vector cp = p - c;
double d5 = Hare_math.Dot(ab, cp);
double d6 = Hare_math.Dot(ac, cp);
if (d6 >= 0.0f && d5 <= d6) return c; // barycentric coordinates (0,0,1)
// Check if P in edge region of AC, if so return projection of P onto AC
double vb = d5 * d2 - d1 * d6;
if (vb <= 0.0f && d2 >= 0.0f && d6 <= 0.0f)
{
double w = d2 / (d2 - d6);
return a + w * ac; // barycentric coordinates (1-w,0,w)
}
// Check if P in edge region of BC, if so return projection of P onto BC
double va = d3 * d6 - d5 * d4;
if (va <= 0.0f && (d4 - d3) >= 0.0f && (d5 - d6) >= 0.0f)
{
double w = (d4 - d3) / ((d4 - d3) + (d5 - d6));
return b + w * (c - b); // barycentric coordinates (0,1-w,w)
}
// P inside face region. Compute Q through its barycentric coordinates (u,v,w)
double denom = 1.0f / (va + vb + vc);
double vl = vb * denom;
double wl = vc * denom;
return a + ab * vl + ac * wl; // = u*a + v*b + w*c, u = va * denom = 1.0f - v - w
}
public class MS_AABB : AABB
{
public int xdim, ydim, zdim, XYTot;
public MS_AABB(Point Point_Min_in, Point Point_Max_in)
:base(Point_Min_in, Point_Max_in)
{
double xl = this.X_Length(), yl = this.Y_Length(), zl = this.Z_Length();
int max = Math.Max((int)Math.Ceiling(xl), Math.Max((int)Math.Ceiling(yl), (int)Math.Ceiling(zl)));
xdim = ydim = zdim = max;
//double x_2 = ((double)xdim - xl) / 2, y_2 = ((double)ydim - yl) / 2, z_2 = ((double)zdim - zl) / 2;
//Min_PT.x -= x_2;
//Min_PT.y -= y_2;
//Min_PT.z -= z_2;
XYTot = xdim * ydim;
}
}
}
}
}