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

BOP_Splitter.cpp « intern « boolop « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7dd3884e9deac9cffaf9e95a5cafbd033cc26a78 (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
/**
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 * All rights reserved.
 *
 * The Original Code is: all of this file.
 *
 * Contributor(s): none yet.
 *
 * ***** END GPL LICENSE BLOCK *****
 */
 
#include "BOP_Splitter.h"
#include "BOP_Tag.h"

#include <iostream>
using namespace std;

/**
 * Returns the split point resulting from intersect a plane and a mesh face  
 * according to its specified relative edge.
 * @param plane split plane
 * @param m mesh
 * @param f face
 * @param e relative edge index
 * @return intersection point
 */
MT_Point3 BOP_splitEdge(MT_Plane3 plane, BOP_Mesh *m, BOP_Face *f, unsigned int e)
{
	int v1 = -1, v2 = -1;
  
	switch(e) {
	case 1:
		v1 = f->getVertex(0);
		v2 = f->getVertex(1);
		break;
	case 2:
		v1 = f->getVertex(1);
		v2 = f->getVertex(2);
		break;
	case 3:
		v1 = f->getVertex(2);
		v2 = f->getVertex(0);
		break;
	default:
		// wrong relative edge index!
		break;
	}
  
	MT_Point3 p1 = m->getVertex(v1)->getPoint();
	MT_Point3 p2 = m->getVertex(v2)->getPoint();
	return BOP_intersectPlane(plane,p1,p2);
}

/**
 * Returns the segment resulting from intersect a plane and a mesh face.
 * @param plane split plane
 * @param m mesh
 * @param f face
 * @return segment if there is intersection, NULL otherwise
 */
BOP_Segment BOP_splitFace(MT_Plane3 plane, BOP_Mesh *m, BOP_Face *f)
{    
	BOP_Vertex *v1 = m->getVertex(f->getVertex(0));
	BOP_Vertex *v2 = m->getVertex(f->getVertex(1));
	BOP_Vertex *v3 = m->getVertex(f->getVertex(2));

	// Classify face vertices
	BOP_TAG tag1 = BOP_createTAG(BOP_classify(v1->getPoint(),plane));
	BOP_TAG tag2 = BOP_createTAG(BOP_classify(v2->getPoint(),plane));
	BOP_TAG tag3 = BOP_createTAG(BOP_classify(v3->getPoint(),plane));
  
	// Classify face according to its vertices classification
	BOP_TAG tag = BOP_createTAG(tag1,tag2,tag3);
  
	BOP_Segment s;

	switch(tag) {
	case IN_IN_IN : 
	case OUT_OUT_OUT :
	case ON_ON_ON :
		s.m_cfg1 = s.m_cfg2 = BOP_Segment::createUndefinedCfg();        
		break;
    
	case ON_OUT_OUT :
	case ON_IN_IN :
		s.m_v1 = f->getVertex(0);
		s.m_cfg1 = BOP_Segment::createVertexCfg(1);
		s.m_cfg2 = BOP_Segment::createUndefinedCfg();
		break;
    
	case OUT_ON_OUT :
	case IN_ON_IN :
		s.m_v1 = f->getVertex(1); 
		s.m_cfg1 = BOP_Segment::createVertexCfg(2);
		s.m_cfg2 = BOP_Segment::createUndefinedCfg();
		break;
    
	case OUT_OUT_ON :      
	case IN_IN_ON :
		s.m_v1 = f->getVertex(2); 
		s.m_cfg1 = BOP_Segment::createVertexCfg(3);
		s.m_cfg2 = BOP_Segment::createUndefinedCfg();
		break;
    
	case ON_ON_IN :
	case ON_ON_OUT :
		s.m_v1 = f->getVertex(0); 
		s.m_v2 = f->getVertex(1);
		s.m_cfg1 = BOP_Segment::createVertexCfg(1);
		s.m_cfg2 = BOP_Segment::createVertexCfg(2);
		break;
    
	case ON_OUT_ON :        
	case ON_IN_ON :
		s.m_v1 = f->getVertex(0); 
		s.m_v2 = f->getVertex(2);
		s.m_cfg1 = BOP_Segment::createVertexCfg(1);
		s.m_cfg2 = BOP_Segment::createVertexCfg(3);
		break;
    
	case OUT_ON_ON :
	case IN_ON_ON :
		s.m_v1 = f->getVertex(1); 
		s.m_v2 = f->getVertex(2);
		s.m_cfg1 = BOP_Segment::createVertexCfg(2);
		s.m_cfg2 = BOP_Segment::createVertexCfg(3);
		break;
    
	case IN_OUT_ON :
	case OUT_IN_ON :
		s.m_v2 = f->getVertex(2);
		s.m_cfg1 = BOP_Segment::createEdgeCfg(1);
		s.m_cfg2 = BOP_Segment::createVertexCfg(3);
	    break;
    
	case IN_ON_OUT :
	case OUT_ON_IN :
		s.m_v1 = f->getVertex(1);
		s.m_cfg1 = BOP_Segment::createVertexCfg(2);
		s.m_cfg2 = BOP_Segment::createEdgeCfg(3);
		break;
    
	case ON_IN_OUT :
	case ON_OUT_IN :
		s.m_v1 = f->getVertex(0);
		s.m_cfg1 = BOP_Segment::createVertexCfg(1);
		s.m_cfg2 = BOP_Segment::createEdgeCfg(2);
		break;
    
	case OUT_IN_IN :
	case IN_OUT_OUT :
		s.m_cfg1 = BOP_Segment::createEdgeCfg(1);
		s.m_cfg2 = BOP_Segment::createEdgeCfg(3);
		break;
    
	case OUT_IN_OUT :
	case IN_OUT_IN :
		s.m_cfg1 = BOP_Segment::createEdgeCfg(1);
		s.m_cfg2 = BOP_Segment::createEdgeCfg(2);
		break;
    
	case OUT_OUT_IN :
	case IN_IN_OUT :
		s.m_cfg1 = BOP_Segment::createEdgeCfg(2);
		s.m_cfg2 = BOP_Segment::createEdgeCfg(3);
		break;
    
	default:
		// wrong TAG!
		break;
	}

	return s;
}