Debian Codegraph @

tools/physicalModeling/mesh2faust/vega/libraries/include/boundingBox.h

raw symbols SCIP
1 /*************************************************************************
2 * *
3 * Vega FEM Simulation Library Version 3.1 *
4 * *
5 * "objMesh" library , Copyright (C) 2007 CMU, 2009 MIT, 2016 USC *
6 * All rights reserved. *
7 * *
8 * Code authors: Jernej Barbic, Christopher Twigg, Daniel Schroeder *
9 * http://www.jernejbarbic.com/code *
10 * *
11 * Research: Jernej Barbic, Fun Shing Sin, Daniel Schroeder, *
12 * Doug L. James, Jovan Popovic *
13 * *
14 * Funding: National Science Foundation, Link Foundation, *
15 * Singapore-MIT GAMBIT Game Lab, *
16 * Zumberge Research and Innovation Fund at USC *
17 * *
18 * This library is free software; you can redistribute it and/or *
19 * modify it under the terms of the BSD-style license that is *
20 * included with this library in the file LICENSE.txt *
21 * *
22 * This library is distributed in the hope that it will be useful, *
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file *
25 * LICENSE.TXT for more details. *
26 * *
27 *************************************************************************/
28
29 #ifndef __BOUNDINGBOX_H__
30 #define __BOUNDINGBOX_H__
31
32 // Bounding Box
33 // Author: Jernej Barbic, CMU
34
35 #include <vector>
36 #include "minivector.h"
37
38 class BoundingBox
39 {
40 public:
41
42 BoundingBox(Vec3d bmin_g=Vec3d(0,0,0), Vec3d bmax_g=Vec3d(1,1,1)): bmin_(bmin_g), bmax_(bmax_g) { updateData();}
43 BoundingBox(const std::vector<Vec3d> & vertices);
44 template<class Triangle> BoundingBox(const std::vector<Triangle> & tripool);
45
46 // accessors
47 const Vec3d & bmin() const { return bmin_;}
48 const Vec3d & bmax() const { return bmax_;}
49
50 const Vec3d & center() const { return center_;}
51 const Vec3d & halfSides() const { return halfSides_;}
52
53 double diameter() const { return len(bmax_-bmin_); }
54
55 // mutators
56 void setbmin(const Vec3d & bmin_g) { bmin_=bmin_g; updateData();}
57 void setbmin(double x, double y, double z) { bmin_=Vec3d(x,y,z); updateData();}
58 void setbmax(const Vec3d & bmax_g) { bmax_=bmax_g; updateData();}
59 void setbmax(double x, double y, double z) { bmax_=Vec3d(x,y,z); updateData();}
60
61 void render() const;
62
63 double distanceToPoint(const Vec3d & point) const;
64 bool checkInside(const Vec3d & point) const;
65
66 // sanity check bmin <= bmax
67 void verifyBox() const;
68
69 // expands from the center
70 // factor of 1.0 indicates no expansion
71 void expand(double expansionFactor);
72 void regularize(); // converts the box into one with all sides equal
73
74 bool lineSegmentIntersection(const Vec3d & segmentStart, const Vec3d & segmentEnd, Vec3d * intersection) const;
75
76 void print() const;
77
78 protected:
79
80 void updateData(); // updates center and half-sides
81 Vec3d center_, halfSides_;
82 Vec3d bmin_,bmax_;
83 };
84
85 #endif