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

« back to all changes in this revision

Viewing changes to intern/boolop/intern/BOP_Splitter.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_Splitter.cpp
29
 
 *  \ingroup boolopintern
30
 
 */
31
 
 
32
 
 
33
 
#include "BOP_Splitter.h"
34
 
#include "BOP_Tag.h"
35
 
 
36
 
#include <iostream>
37
 
 
38
 
/**
39
 
 * Returns the split point resulting from intersect a plane and a mesh face  
40
 
 * according to its specified relative edge.
41
 
 * @param plane split plane
42
 
 * @param m mesh
43
 
 * @param f face
44
 
 * @param e relative edge index
45
 
 * @return intersection point
46
 
 */
47
 
MT_Point3 BOP_splitEdge(MT_Plane3 plane, BOP_Mesh *m, BOP_Face *f, unsigned int e)
48
 
{
49
 
        int v1 = -1, v2 = -1;
50
 
  
51
 
        switch(e) {
52
 
        case 1:
53
 
                v1 = f->getVertex(0);
54
 
                v2 = f->getVertex(1);
55
 
                break;
56
 
        case 2:
57
 
                v1 = f->getVertex(1);
58
 
                v2 = f->getVertex(2);
59
 
                break;
60
 
        case 3:
61
 
                v1 = f->getVertex(2);
62
 
                v2 = f->getVertex(0);
63
 
                break;
64
 
        default:
65
 
                // wrong relative edge index!
66
 
                break;
67
 
        }
68
 
  
69
 
        MT_Point3 p1 = m->getVertex(v1)->getPoint();
70
 
        MT_Point3 p2 = m->getVertex(v2)->getPoint();
71
 
        return BOP_intersectPlane(plane,p1,p2);
72
 
}
73
 
 
74
 
/**
75
 
 * Returns the segment resulting from intersect a plane and a mesh face.
76
 
 * @param plane split plane
77
 
 * @param m mesh
78
 
 * @param f face
79
 
 * @return segment if there is intersection, NULL otherwise
80
 
 */
81
 
BOP_Segment BOP_splitFace(MT_Plane3 plane, BOP_Mesh *m, BOP_Face *f)
82
 
{    
83
 
        BOP_Vertex *v1 = m->getVertex(f->getVertex(0));
84
 
        BOP_Vertex *v2 = m->getVertex(f->getVertex(1));
85
 
        BOP_Vertex *v3 = m->getVertex(f->getVertex(2));
86
 
 
87
 
        // Classify face vertices
88
 
        BOP_TAG tag1 = BOP_createTAG(BOP_classify(v1->getPoint(),plane));
89
 
        BOP_TAG tag2 = BOP_createTAG(BOP_classify(v2->getPoint(),plane));
90
 
        BOP_TAG tag3 = BOP_createTAG(BOP_classify(v3->getPoint(),plane));
91
 
  
92
 
        // Classify face according to its vertices classification
93
 
        BOP_TAG tag = BOP_createTAG(tag1,tag2,tag3);
94
 
  
95
 
        BOP_Segment s;
96
 
 
97
 
        switch(tag) {
98
 
        case IN_IN_IN : 
99
 
        case OUT_OUT_OUT :
100
 
        case ON_ON_ON :
101
 
                s.m_cfg1 = s.m_cfg2 = BOP_Segment::createUndefinedCfg();        
102
 
                break;
103
 
    
104
 
        case ON_OUT_OUT :
105
 
        case ON_IN_IN :
106
 
                s.m_v1 = f->getVertex(0);
107
 
                s.m_cfg1 = BOP_Segment::createVertexCfg(1);
108
 
                s.m_cfg2 = BOP_Segment::createUndefinedCfg();
109
 
                break;
110
 
    
111
 
        case OUT_ON_OUT :
112
 
        case IN_ON_IN :
113
 
                s.m_v1 = f->getVertex(1); 
114
 
                s.m_cfg1 = BOP_Segment::createVertexCfg(2);
115
 
                s.m_cfg2 = BOP_Segment::createUndefinedCfg();
116
 
                break;
117
 
    
118
 
        case OUT_OUT_ON :      
119
 
        case IN_IN_ON :
120
 
                s.m_v1 = f->getVertex(2); 
121
 
                s.m_cfg1 = BOP_Segment::createVertexCfg(3);
122
 
                s.m_cfg2 = BOP_Segment::createUndefinedCfg();
123
 
                break;
124
 
    
125
 
        case ON_ON_IN :
126
 
        case ON_ON_OUT :
127
 
                s.m_v1 = f->getVertex(0); 
128
 
                s.m_v2 = f->getVertex(1);
129
 
                s.m_cfg1 = BOP_Segment::createVertexCfg(1);
130
 
                s.m_cfg2 = BOP_Segment::createVertexCfg(2);
131
 
                break;
132
 
    
133
 
        case ON_OUT_ON :        
134
 
        case ON_IN_ON :
135
 
                s.m_v1 = f->getVertex(0); 
136
 
                s.m_v2 = f->getVertex(2);
137
 
                s.m_cfg1 = BOP_Segment::createVertexCfg(1);
138
 
                s.m_cfg2 = BOP_Segment::createVertexCfg(3);
139
 
                break;
140
 
    
141
 
        case OUT_ON_ON :
142
 
        case IN_ON_ON :
143
 
                s.m_v1 = f->getVertex(1); 
144
 
                s.m_v2 = f->getVertex(2);
145
 
                s.m_cfg1 = BOP_Segment::createVertexCfg(2);
146
 
                s.m_cfg2 = BOP_Segment::createVertexCfg(3);
147
 
                break;
148
 
    
149
 
        case IN_OUT_ON :
150
 
        case OUT_IN_ON :
151
 
                s.m_v2 = f->getVertex(2);
152
 
                s.m_cfg1 = BOP_Segment::createEdgeCfg(1);
153
 
                s.m_cfg2 = BOP_Segment::createVertexCfg(3);
154
 
            break;
155
 
    
156
 
        case IN_ON_OUT :
157
 
        case OUT_ON_IN :
158
 
                s.m_v1 = f->getVertex(1);
159
 
                s.m_cfg1 = BOP_Segment::createVertexCfg(2);
160
 
                s.m_cfg2 = BOP_Segment::createEdgeCfg(3);
161
 
                break;
162
 
    
163
 
        case ON_IN_OUT :
164
 
        case ON_OUT_IN :
165
 
                s.m_v1 = f->getVertex(0);
166
 
                s.m_cfg1 = BOP_Segment::createVertexCfg(1);
167
 
                s.m_cfg2 = BOP_Segment::createEdgeCfg(2);
168
 
                break;
169
 
    
170
 
        case OUT_IN_IN :
171
 
        case IN_OUT_OUT :
172
 
                s.m_cfg1 = BOP_Segment::createEdgeCfg(1);
173
 
                s.m_cfg2 = BOP_Segment::createEdgeCfg(3);
174
 
                break;
175
 
    
176
 
        case OUT_IN_OUT :
177
 
        case IN_OUT_IN :
178
 
                s.m_cfg1 = BOP_Segment::createEdgeCfg(1);
179
 
                s.m_cfg2 = BOP_Segment::createEdgeCfg(2);
180
 
                break;
181
 
    
182
 
        case OUT_OUT_IN :
183
 
        case IN_IN_OUT :
184
 
                s.m_cfg1 = BOP_Segment::createEdgeCfg(2);
185
 
                s.m_cfg2 = BOP_Segment::createEdgeCfg(3);
186
 
                break;
187
 
    
188
 
        default:
189
 
                // wrong TAG!
190
 
                break;
191
 
        }
192
 
 
193
 
        return s;
194
 
}