Fix #24775: boolean modifier crash in rendering on Mac. Problem was that this
[blender.git] / intern / boolop / intern / BOP_BSPNode.h
1 /**
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27  
28 #ifndef BOP_BSPNODE_H
29 #define BOP_BSPNODE_H
30
31 #include "MT_Plane3.h"
32 #include "BOP_Tag.h"
33 #include "BOP_Face.h"
34
35 typedef vector<MT_Point3> BOP_BSPPoints;
36 typedef vector<MT_Point3>::const_iterator BOP_IT_BSPPoints;
37
38 class BOP_BSPNode
39 {
40 protected:
41         BOP_BSPNode* m_inChild;
42         BOP_BSPNode* m_outChild;
43         MT_Plane3    m_plane;
44         unsigned int m_deep;
45
46 public:
47         // Construction methods
48         BOP_BSPNode(const MT_Plane3& plane);
49         ~BOP_BSPNode();
50         unsigned int addFace(const BOP_BSPPoints& pts, 
51                                                  const MT_Plane3& plane);
52         BOP_TAG classifyFace(const MT_Point3& p1, 
53                                                  const MT_Point3& p2, 
54                                                  const MT_Point3& p3, 
55                                                  const MT_Plane3& plane) const;
56         BOP_TAG simplifiedClassifyFace(const MT_Point3& p1, 
57                                                                    const MT_Point3& p2, 
58                                                                    const MT_Point3& p3, 
59                                                                    const MT_Plane3& plane) const;
60         
61 protected:
62         BOP_TAG testPoint(const MT_Point3& p) const;
63         BOP_TAG classifyFaceIN(const MT_Point3& p1, 
64                                                    const MT_Point3& p2, 
65                                                    const MT_Point3& p3, 
66                                                    const MT_Plane3& plane) const;
67         BOP_TAG classifyFaceOUT(const MT_Point3& p1, 
68                                                         const MT_Point3& p2, 
69                                                         const MT_Point3& p3, 
70                                                         const MT_Plane3& plane) const;
71         BOP_TAG simplifiedClassifyFaceIN(const MT_Point3& p1, 
72                                                                          const MT_Point3& p2, 
73                                                                          const MT_Point3& p3, 
74                                                                          const MT_Plane3& plane) const;
75         BOP_TAG simplifiedClassifyFaceOUT(const MT_Point3& p1, 
76                                                                           const MT_Point3& p2, 
77                                                                           const MT_Point3& p3, 
78                                                                           const MT_Plane3& plane) const;
79         bool hasSameOrientation(const MT_Plane3& plane) const;
80         int compChildren() const;
81         int splitTriangle(MT_Point3* res, 
82                                           const MT_Plane3& plane, 
83                                           const MT_Point3& p1, 
84                                           const MT_Point3& p2, 
85                                           const MT_Point3& p3, 
86                                           const BOP_TAG tag) const;
87
88 public:
89         // Inline acces methods
90         inline void setInChild(BOP_BSPNode* inChild) { m_inChild=inChild; };
91         inline void setOutChild(BOP_BSPNode* outChild) { m_outChild=outChild; };
92         inline BOP_BSPNode* getInChild() { return m_inChild; };
93         inline BOP_BSPNode* getOutChild() { return m_outChild; };
94         inline bool isLeaf() const { return !m_inChild && !m_outChild; };
95         inline void setPlane(const MT_Plane3& plane) {m_plane=plane;};
96         inline MT_Plane3& getPlane() { return m_plane; };
97
98         inline unsigned int getDeep() const {return m_deep;};
99         void print(unsigned int deep);
100 };
101
102 #endif