|
Blender
V2.59
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include "BOP_Splitter.h" 00034 #include "BOP_Tag.h" 00035 00036 #include <iostream> 00037 using namespace std; 00038 00048 MT_Point3 BOP_splitEdge(MT_Plane3 plane, BOP_Mesh *m, BOP_Face *f, unsigned int e) 00049 { 00050 int v1 = -1, v2 = -1; 00051 00052 switch(e) { 00053 case 1: 00054 v1 = f->getVertex(0); 00055 v2 = f->getVertex(1); 00056 break; 00057 case 2: 00058 v1 = f->getVertex(1); 00059 v2 = f->getVertex(2); 00060 break; 00061 case 3: 00062 v1 = f->getVertex(2); 00063 v2 = f->getVertex(0); 00064 break; 00065 default: 00066 // wrong relative edge index! 00067 break; 00068 } 00069 00070 MT_Point3 p1 = m->getVertex(v1)->getPoint(); 00071 MT_Point3 p2 = m->getVertex(v2)->getPoint(); 00072 return BOP_intersectPlane(plane,p1,p2); 00073 } 00074 00082 BOP_Segment BOP_splitFace(MT_Plane3 plane, BOP_Mesh *m, BOP_Face *f) 00083 { 00084 BOP_Vertex *v1 = m->getVertex(f->getVertex(0)); 00085 BOP_Vertex *v2 = m->getVertex(f->getVertex(1)); 00086 BOP_Vertex *v3 = m->getVertex(f->getVertex(2)); 00087 00088 // Classify face vertices 00089 BOP_TAG tag1 = BOP_createTAG(BOP_classify(v1->getPoint(),plane)); 00090 BOP_TAG tag2 = BOP_createTAG(BOP_classify(v2->getPoint(),plane)); 00091 BOP_TAG tag3 = BOP_createTAG(BOP_classify(v3->getPoint(),plane)); 00092 00093 // Classify face according to its vertices classification 00094 BOP_TAG tag = BOP_createTAG(tag1,tag2,tag3); 00095 00096 BOP_Segment s; 00097 00098 switch(tag) { 00099 case IN_IN_IN : 00100 case OUT_OUT_OUT : 00101 case ON_ON_ON : 00102 s.m_cfg1 = s.m_cfg2 = BOP_Segment::createUndefinedCfg(); 00103 break; 00104 00105 case ON_OUT_OUT : 00106 case ON_IN_IN : 00107 s.m_v1 = f->getVertex(0); 00108 s.m_cfg1 = BOP_Segment::createVertexCfg(1); 00109 s.m_cfg2 = BOP_Segment::createUndefinedCfg(); 00110 break; 00111 00112 case OUT_ON_OUT : 00113 case IN_ON_IN : 00114 s.m_v1 = f->getVertex(1); 00115 s.m_cfg1 = BOP_Segment::createVertexCfg(2); 00116 s.m_cfg2 = BOP_Segment::createUndefinedCfg(); 00117 break; 00118 00119 case OUT_OUT_ON : 00120 case IN_IN_ON : 00121 s.m_v1 = f->getVertex(2); 00122 s.m_cfg1 = BOP_Segment::createVertexCfg(3); 00123 s.m_cfg2 = BOP_Segment::createUndefinedCfg(); 00124 break; 00125 00126 case ON_ON_IN : 00127 case ON_ON_OUT : 00128 s.m_v1 = f->getVertex(0); 00129 s.m_v2 = f->getVertex(1); 00130 s.m_cfg1 = BOP_Segment::createVertexCfg(1); 00131 s.m_cfg2 = BOP_Segment::createVertexCfg(2); 00132 break; 00133 00134 case ON_OUT_ON : 00135 case ON_IN_ON : 00136 s.m_v1 = f->getVertex(0); 00137 s.m_v2 = f->getVertex(2); 00138 s.m_cfg1 = BOP_Segment::createVertexCfg(1); 00139 s.m_cfg2 = BOP_Segment::createVertexCfg(3); 00140 break; 00141 00142 case OUT_ON_ON : 00143 case IN_ON_ON : 00144 s.m_v1 = f->getVertex(1); 00145 s.m_v2 = f->getVertex(2); 00146 s.m_cfg1 = BOP_Segment::createVertexCfg(2); 00147 s.m_cfg2 = BOP_Segment::createVertexCfg(3); 00148 break; 00149 00150 case IN_OUT_ON : 00151 case OUT_IN_ON : 00152 s.m_v2 = f->getVertex(2); 00153 s.m_cfg1 = BOP_Segment::createEdgeCfg(1); 00154 s.m_cfg2 = BOP_Segment::createVertexCfg(3); 00155 break; 00156 00157 case IN_ON_OUT : 00158 case OUT_ON_IN : 00159 s.m_v1 = f->getVertex(1); 00160 s.m_cfg1 = BOP_Segment::createVertexCfg(2); 00161 s.m_cfg2 = BOP_Segment::createEdgeCfg(3); 00162 break; 00163 00164 case ON_IN_OUT : 00165 case ON_OUT_IN : 00166 s.m_v1 = f->getVertex(0); 00167 s.m_cfg1 = BOP_Segment::createVertexCfg(1); 00168 s.m_cfg2 = BOP_Segment::createEdgeCfg(2); 00169 break; 00170 00171 case OUT_IN_IN : 00172 case IN_OUT_OUT : 00173 s.m_cfg1 = BOP_Segment::createEdgeCfg(1); 00174 s.m_cfg2 = BOP_Segment::createEdgeCfg(3); 00175 break; 00176 00177 case OUT_IN_OUT : 00178 case IN_OUT_IN : 00179 s.m_cfg1 = BOP_Segment::createEdgeCfg(1); 00180 s.m_cfg2 = BOP_Segment::createEdgeCfg(2); 00181 break; 00182 00183 case OUT_OUT_IN : 00184 case IN_IN_OUT : 00185 s.m_cfg1 = BOP_Segment::createEdgeCfg(2); 00186 s.m_cfg2 = BOP_Segment::createEdgeCfg(3); 00187 break; 00188 00189 default: 00190 // wrong TAG! 00191 break; 00192 } 00193 00194 return s; 00195 }