~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to intern/boolop/intern/BOP_BSPTree.cpp

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
/** \file boolop/intern/BOP_BSPTree.cpp
29
 
 *  \ingroup boolopintern
30
 
 */
31
 
 
32
 
 
33
 
#include "BOP_BSPTree.h"
34
 
#include <vector>
35
 
#include <iostream>
36
 
 
37
 
/**
38
 
 * Constructs a new BSP tree.
39
 
 */
40
 
BOP_BSPTree::BOP_BSPTree()
41
 
{
42
 
        m_root = NULL;
43
 
        m_bspBB = NULL;
44
 
}
45
 
 
46
 
/**
47
 
 * Destroys a BSP tree.
48
 
 */
49
 
BOP_BSPTree::~BOP_BSPTree()
50
 
{
51
 
        if (m_root!=NULL) delete m_root;
52
 
        if (m_bspBB!=NULL) delete m_bspBB;
53
 
}
54
 
 
55
 
/**
56
 
 * Adds all mesh faces to BSP tree.
57
 
 * @param mesh mesh to add.
58
 
 * @param facesList face list to add.
59
 
 */
60
 
void BOP_BSPTree::addMesh(BOP_Mesh* mesh, BOP_Faces& facesList)
61
 
{
62
 
        for (BOP_IT_Faces it = facesList.begin(); it != facesList.end(); ++it) {
63
 
                addFace( mesh, *it );
64
 
        }
65
 
        
66
 
}
67
 
 
68
 
/**
69
 
 * Adds a new face into bsp tree.
70
 
 * @param mesh Input data for BSP tree.
71
 
 * @param face index to mesh face.
72
 
 */
73
 
 
74
 
void BOP_BSPTree::addFace(BOP_Mesh* mesh, BOP_Face* face)
75
 
{
76
 
        addFace(mesh->getVertex(face->getVertex(0))->getPoint(),
77
 
                        mesh->getVertex(face->getVertex(1))->getPoint(),
78
 
                        mesh->getVertex(face->getVertex(2))->getPoint(),
79
 
                        face->getPlane());
80
 
}
81
 
 
82
 
/**
83
 
 * Adds new facee to the bsp-tree.
84
 
 * @param p1 first face point.
85
 
 * @param p2 second face point.
86
 
 * @param p3 third face point.
87
 
 * @param plane face plane.
88
 
 */
89
 
void BOP_BSPTree::addFace(const MT_Point3& p1, 
90
 
                                                  const MT_Point3& p2, 
91
 
                                                  const MT_Point3& p3, 
92
 
                                                  const MT_Plane3& plane)
93
 
{
94
 
        if (m_root == NULL)
95
 
                m_root = new BOP_BSPNode(plane);
96
 
        else {
97
 
                BOP_BSPPoints pts;
98
 
 
99
 
                pts.push_back(p1);
100
 
                pts.push_back(p2);
101
 
                pts.push_back(p3);
102
 
 
103
 
                m_root->addFace(pts,plane);
104
 
        }
105
 
 
106
 
        // update bounding box
107
 
        m_bbox.add(p1);
108
 
        m_bbox.add(p2);
109
 
        m_bbox.add(p3);
110
 
}
111
 
 
112
 
/**
113
 
 * Tests face vs bsp-tree (returns where is the face respect bsp planes).
114
 
 * @param p1 first face triangle point.
115
 
 * @param p2 secons face triangle point.
116
 
 * @param p3 third face triangle point.
117
 
 * @param plane face plane.
118
 
 * @return BSP_IN, BSP_OUT or BSP_IN_OUT
119
 
 */
120
 
BOP_TAG BOP_BSPTree::classifyFace(const MT_Point3& p1, 
121
 
                                                                  const MT_Point3& p2, 
122
 
                                                                  const MT_Point3& p3, 
123
 
                                                                  const MT_Plane3& plane) const
124
 
{
125
 
        if ( m_root != NULL )
126
 
          return m_root->classifyFace(p1, p2, p3, plane);
127
 
        else
128
 
          return OUT;
129
 
}
130
 
 
131
 
/**
132
 
 * Filters a face using the BSP bounding infomation.
133
 
 * @param p1 first face triangle point.
134
 
 * @param p2 secons face triangle point.
135
 
 * @param p3 third face triangle point.
136
 
 * @param face face to test.
137
 
 * @return UNCLASSIFIED, BSP_IN, BSP_OUT or BSP_IN_OUT
138
 
 */
139
 
BOP_TAG BOP_BSPTree::filterFace(const MT_Point3& p1, 
140
 
                                                                const MT_Point3& p2, 
141
 
                                                                const MT_Point3& p3, 
142
 
                                                                BOP_Face* face)
143
 
{
144
 
        if ( m_bspBB != NULL ) {
145
 
                return m_bspBB->classifyFace(p1,p2,p3,face->getPlane());
146
 
        }
147
 
        else
148
 
                return UNCLASSIFIED;
149
 
}
150
 
 
151
 
/**
152
 
 * Tests face vs bsp-tree (returns where is the face respect bsp planes).
153
 
 * @param p1 first face triangle point.
154
 
 * @param p2 secons face triangle point.
155
 
 * @param p3 third face triangle point.
156
 
 * @param plane face plane.
157
 
 * @return BSP_IN, BSP_OUT or BSP_IN_OUT
158
 
 */
159
 
BOP_TAG BOP_BSPTree::simplifiedClassifyFace(const MT_Point3& p1, 
160
 
                                                                                        const MT_Point3& p2, 
161
 
                                                                                        const MT_Point3& p3, 
162
 
                                                                                        const MT_Plane3& plane) const
163
 
{
164
 
        if ( m_root != NULL )
165
 
          return m_root->simplifiedClassifyFace(p1, p2, p3, plane);
166
 
        else
167
 
          return OUT;
168
 
}
169
 
 
170
 
/**
171
 
 * Returns the deep of this BSP tree.
172
 
 * @return tree deep
173
 
 */
174
 
unsigned int BOP_BSPTree::getDeep() const
175
 
{
176
 
        if ( m_root != NULL )
177
 
          return m_root->getDeep();
178
 
        else
179
 
          return 0;
180
 
}
181
 
 
182
 
/**
183
 
 * Prints debug information.
184
 
 */
185
 
void BOP_BSPTree::print()
186
 
{
187
 
        if ( m_root != NULL )
188
 
                m_root->print( 0 );
189
 
}
190