Debian Codegraph @

tools/physicalModeling/mesh2faust/vega/libraries/objMesh/octree.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 _OCTREE_H_
30 #define _OCTREE_H_
31
32 // An octree storing triangles. Can be intersected with a sphere or a line segment.
33 // Jernej Barbic, CMU
34
35 #include <vector>
36 #include "minivector.h"
37 #include "boundingBox.h"
38 #include "triangle.h"
39 #include "simpleSphere.h"
40
41 template<class TriangleClass>
42 class Octree
43 {
44 public:
45 // make empty octree
46 // maxDepth = maximum tree depth allowed
47 // depth = how deep in the hierarchy is this octree (for recursion) (you should use depth=0 when using this class; non-zero values are only passed internally)
48 Octree(int maxDepth=10, int depth=0);
49 ~Octree() { deallocate(); }
50
51 bool build(std::vector<TriangleClass> & triangleList, BoundingBox & parentCube, int maxNumTriangles);
52
53 // will construct a bounding box automatically:
54 bool build(std::vector<TriangleClass> & triangleList, int maxNumTriangles);
55 void setBuildPrintInfo(int info); // controls what gets printed out during construction: 0 = nothing, 1 = up to five warnings, 2 = all warnings
56 void getBuildInfo(int * numMaxDepthExceededCases, int * numMaxTriInDepthExceededCases);
57
58 // note: these two routines might return the same colliding triangle several times; call <TriangleClass>::makeUniqueList to make the list unique if needed
59 void buildCollisionList(std::vector<TriangleClass*> & triangleList, const SimpleSphere & simpleSphere);
60 void buildCollisionList(std::vector<TriangleClass*> & triangleList, const Vec3d & segmentStartPoint, const Vec3d & segmentEndPoint, std::vector<Vec3d> * intersectionList = NULL);
61
62 void render(); // openGL rendering
63 void render(int level); // only render leaf boxes at depth level 'level'
64 void render(int level, int boxIndex); // only render leaf boxes number "boxIndex" at depth level 'level'
65 void setRenderInfo(int info) { printRenderInfo = info; }
66
67 int getDepth(); // compute tree depth
68 BoundingBox getBoundingBox() { return boundingBox; }
69
70 protected:
71
72 void deallocate(); // free the memory
73 void createChildCubes(BoundingBox * childCubeBoxes);
74
75 BoundingBox boundingBox;
76 Octree * childrenNodes[8];
77
78 int maxDepth; // max depth allowed
79 int depth; // how deep in the hierarchy is this octree
80
81 void renderHelper(int level, int boxIndex); // only render leaf boxes number "boxIndex" at depth level 'level'
82 static int renderCounter; // for rendering
83 static int printRenderInfo;
84
85 std::vector<TriangleClass> triangles;
86
87 static int buildPrintInfo;
88 static int numMaxDepthExceededCases;
89 static int numMaxTriInDepthExceededCases;
90 };
91
92 template<class TriangleClass>
93 inline void Octree<TriangleClass>::getBuildInfo(int * numMaxDepthExceededCases, int * numMaxTriInDepthExceededCases)
94 {
95 *numMaxDepthExceededCases = this->numMaxDepthExceededCases;
96 *numMaxTriInDepthExceededCases = this->numMaxTriInDepthExceededCases;
97 }
98
99 template<class TriangleClass>
100 inline void Octree<TriangleClass>::setBuildPrintInfo(int info)
101 {
102 buildPrintInfo = info;
103 if (info == 1)
104 {
105 numMaxDepthExceededCases = 0;
106 numMaxTriInDepthExceededCases = 0;
107 }
108 }
109
110 #endif
111