| | | 1 | | using System.Linq; |
| | | 2 | | |
| | | 3 | | namespace MorphoGeometry |
| | | 4 | | { |
| | | 5 | | /// <summary> |
| | | 6 | | /// Boundary box class. |
| | | 7 | | /// </summary> |
| | | 8 | | public class BoundaryBox |
| | | 9 | | { |
| | | 10 | | private const int NUM_VERT = 3; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Lower left point. |
| | | 14 | | /// </summary> |
| | 0 | 15 | | public Vector MinPoint { get; } |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Upper right point. |
| | | 19 | | /// </summary> |
| | 0 | 20 | | public Vector MaxPoint { get; } |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Create a new boundary box. |
| | | 24 | | /// </summary> |
| | | 25 | | /// <param name="facegroup">Facegroup.</param> |
| | 0 | 26 | | public BoundaryBox(FaceGroup facegroup) |
| | 0 | 27 | | { |
| | 0 | 28 | | float[] coordinateX = new float[facegroup.Faces.Count * NUM_VERT]; |
| | 0 | 29 | | float[] coordinateY = new float[facegroup.Faces.Count * NUM_VERT]; |
| | 0 | 30 | | float[] coordinateZ = new float[facegroup.Faces.Count * NUM_VERT]; |
| | | 31 | | |
| | 0 | 32 | | for (int i = 0; i < facegroup.Faces.Count; i++) |
| | 0 | 33 | | { |
| | 0 | 34 | | coordinateX[i] = facegroup.Faces[i].A.x; |
| | 0 | 35 | | coordinateX[i] = facegroup.Faces[i].B.x; |
| | 0 | 36 | | coordinateX[i] = facegroup.Faces[i].C.x; |
| | | 37 | | |
| | 0 | 38 | | coordinateY[i] = facegroup.Faces[i].A.y; |
| | 0 | 39 | | coordinateY[i] = facegroup.Faces[i].B.y; |
| | 0 | 40 | | coordinateY[i] = facegroup.Faces[i].C.y; |
| | | 41 | | |
| | 0 | 42 | | coordinateZ[i] = facegroup.Faces[i].A.z; |
| | 0 | 43 | | coordinateZ[i] = facegroup.Faces[i].B.z; |
| | 0 | 44 | | coordinateZ[i] = facegroup.Faces[i].C.z; |
| | 0 | 45 | | } |
| | | 46 | | |
| | 0 | 47 | | float minX = coordinateX.Min(); |
| | 0 | 48 | | float minY = coordinateY.Min(); |
| | 0 | 49 | | float minZ = coordinateZ.Min(); |
| | | 50 | | |
| | 0 | 51 | | float maxX = coordinateX.Max(); |
| | 0 | 52 | | float maxY = coordinateY.Max(); |
| | 0 | 53 | | float maxZ = coordinateZ.Max(); |
| | | 54 | | |
| | 0 | 55 | | MinPoint = new Vector(minX, minY, minZ); |
| | 0 | 56 | | MaxPoint = new Vector(maxX, maxY, maxZ); |
| | 0 | 57 | | } |
| | | 58 | | } |
| | | 59 | | } |