Welcome to mirror list, hosted at ThFree Co, Russian Federation.

octree_decl.hpp « carve « include « carve « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 46d5d4a22fe279239b298a5853ba261cb8a81a1e (plain)
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
// Begin License:
// Copyright (C) 2006-2014 Tobias Sargeant (tobias.sargeant@gmail.com).
// All rights reserved.
//
// This file is part of the Carve CSG Library (http://carve-csg.com/)
//
// This file may be used under the terms of either the GNU General
// Public License version 2 or 3 (at your option) as published by the
// Free Software Foundation and appearing in the files LICENSE.GPL2
// and LICENSE.GPL3 included in the packaging of this file.
//
// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE.
// End:


#pragma once

#include <carve/carve.hpp>

#include <carve/geom3d.hpp>
#include <carve/aabb.hpp>

#include <carve/polyhedron_base.hpp>

namespace carve {

  namespace csg {

    const double SLACK_FACTOR=1.0009765625;
    const unsigned FACE_SPLIT_THRESHOLD=50U;
    const unsigned EDGE_SPLIT_THRESHOLD=50U;
    const unsigned POINT_SPLIT_THRESHOLD=20U;
    const unsigned MAX_SPLIT_DEPTH=32;

    class Octree {

    public:
      class Node {
      private:
        Node(const Node &node); // undefined.
        Node &operator=(const Node &node); // undefined.

      public:
        Node *parent;
        Node *children[8];
        bool is_leaf;

        carve::geom3d::Vector min;
        carve::geom3d::Vector max;

        std::vector<const carve::poly::Geometry<3>::face_t *> faces;
        std::vector<const carve::poly::Geometry<3>::edge_t *> edges;
        std::vector<const carve::poly::Geometry<3>::vertex_t *> vertices;

        carve::geom3d::AABB aabb;

        Node();

        Node(const carve::geom3d::Vector &newMin, const carve::geom3d::Vector &newMax);
        Node(Node *p, double x1, double y1, double z1, double x2, double y2, double z2);

        ~Node();

        bool mightContain(const carve::poly::Geometry<3>::face_t &face);
        bool mightContain(const carve::poly::Geometry<3>::edge_t &edge);
        bool mightContain(const carve::poly::Geometry<3>::vertex_t &p);
        bool hasChildren();
        bool hasGeometry();

        template <class T>
        void putInside(const T &input, Node *child, T &output);

        bool split();
      };



      Node *root;



      struct no_filter {
        bool operator()(const carve::poly::Geometry<3>::edge_t *) { return true; }
        bool operator()(const carve::poly::Geometry<3>::face_t *) { return true; }
      };



      Octree();

      ~Octree();



      void setBounds(const carve::geom3d::Vector &min, const carve::geom3d::Vector &max);
      void setBounds(carve::geom3d::AABB aabb);



      void addEdges(const std::vector<carve::poly::Geometry<3>::edge_t > &edges);
      void addFaces(const std::vector<carve::poly::Geometry<3>::face_t > &faces);
      void addVertices(const std::vector<const carve::poly::Geometry<3>::vertex_t *> &vertices);



      static carve::geom3d::AABB makeAABB(const Node *node);



      void doFindEdges(const carve::geom::aabb<3> &aabb,
                       Node *node,
                       std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
                       unsigned depth) const;
      void doFindEdges(const carve::geom3d::LineSegment &l,
                       Node *node,
                       std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
                       unsigned depth) const;
      void doFindEdges(const carve::geom3d::Vector &v,
                       Node *node,
                       std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
                       unsigned depth) const;
      void doFindFaces(const carve::geom::aabb<3> &aabb,
                       Node *node,
                       std::vector<const carve::poly::Geometry<3>::face_t *> &out,
                       unsigned depth) const;
      void doFindFaces(const carve::geom3d::LineSegment &l,
                       Node *node,
                       std::vector<const carve::poly::Geometry<3>::face_t *> &out,
                       unsigned depth) const;



      void doFindVerticesAllowDupes(const carve::geom3d::Vector &v,
                                    Node *node,
                                    std::vector<const carve::poly::Geometry<3>::vertex_t *> &out,
                                    unsigned depth) const;

      void findVerticesNearAllowDupes(const carve::geom3d::Vector &v,
                                      std::vector<const carve::poly::Geometry<3>::vertex_t *> &out) const;



      template<typename filter_t>
      void doFindEdges(const carve::poly::Geometry<3>::face_t &f, Node *node,
                       std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
                       unsigned depth,
                       filter_t filter) const;

      template<typename filter_t>
      void findEdgesNear(const carve::poly::Geometry<3>::face_t &f,
                         std::vector<const carve::poly::Geometry<3>::edge_t *> &out,
                         filter_t filter) const;

      void findEdgesNear(const carve::poly::Geometry<3>::face_t &f,
                         std::vector<const carve::poly::Geometry<3>::edge_t *> &out) const {
        return findEdgesNear(f, out, no_filter());
      }



      void findEdgesNear(const carve::geom::aabb<3> &aabb, std::vector<const carve::poly::Geometry<3>::edge_t *> &out) const;
      void findEdgesNear(const carve::geom3d::LineSegment &l, std::vector<const carve::poly::Geometry<3>::edge_t *> &out) const;
      void findEdgesNear(const carve::poly::Geometry<3>::edge_t &e, std::vector<const carve::poly::Geometry<3>::edge_t *> &out) const;
      void findEdgesNear(const carve::geom3d::Vector &v, std::vector<const carve::poly::Geometry<3>::edge_t *> &out) const;



      void findFacesNear(const carve::geom::aabb<3> &aabb, std::vector<const carve::poly::Geometry<3>::face_t *> &out) const;
      void findFacesNear(const carve::geom3d::LineSegment &l, std::vector<const carve::poly::Geometry<3>::face_t *> &out) const;
      void findFacesNear(const carve::poly::Geometry<3>::edge_t &e, std::vector<const carve::poly::Geometry<3>::face_t *> &out) const;



      static void doSplit(int maxSplit, Node *node);



      template <typename FUNC>
      void doIterate(int level, Node *node, const FUNC &f) const;

      template <typename FUNC>
      void iterateNodes(const FUNC &f) const;



      void splitTree();

    };

  }
}