Blender V2.61 - r43446

BOP_Splitter.cpp

Go to the documentation of this file.
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 
00047 MT_Point3 BOP_splitEdge(MT_Plane3 plane, BOP_Mesh *m, BOP_Face *f, unsigned int e)
00048 {
00049     int v1 = -1, v2 = -1;
00050   
00051     switch(e) {
00052     case 1:
00053         v1 = f->getVertex(0);
00054         v2 = f->getVertex(1);
00055         break;
00056     case 2:
00057         v1 = f->getVertex(1);
00058         v2 = f->getVertex(2);
00059         break;
00060     case 3:
00061         v1 = f->getVertex(2);
00062         v2 = f->getVertex(0);
00063         break;
00064     default:
00065         // wrong relative edge index!
00066         break;
00067     }
00068   
00069     MT_Point3 p1 = m->getVertex(v1)->getPoint();
00070     MT_Point3 p2 = m->getVertex(v2)->getPoint();
00071     return BOP_intersectPlane(plane,p1,p2);
00072 }
00073 
00081 BOP_Segment BOP_splitFace(MT_Plane3 plane, BOP_Mesh *m, BOP_Face *f)
00082 {    
00083     BOP_Vertex *v1 = m->getVertex(f->getVertex(0));
00084     BOP_Vertex *v2 = m->getVertex(f->getVertex(1));
00085     BOP_Vertex *v3 = m->getVertex(f->getVertex(2));
00086 
00087     // Classify face vertices
00088     BOP_TAG tag1 = BOP_createTAG(BOP_classify(v1->getPoint(),plane));
00089     BOP_TAG tag2 = BOP_createTAG(BOP_classify(v2->getPoint(),plane));
00090     BOP_TAG tag3 = BOP_createTAG(BOP_classify(v3->getPoint(),plane));
00091   
00092     // Classify face according to its vertices classification
00093     BOP_TAG tag = BOP_createTAG(tag1,tag2,tag3);
00094   
00095     BOP_Segment s;
00096 
00097     switch(tag) {
00098     case IN_IN_IN : 
00099     case OUT_OUT_OUT :
00100     case ON_ON_ON :
00101         s.m_cfg1 = s.m_cfg2 = BOP_Segment::createUndefinedCfg();        
00102         break;
00103     
00104     case ON_OUT_OUT :
00105     case ON_IN_IN :
00106         s.m_v1 = f->getVertex(0);
00107         s.m_cfg1 = BOP_Segment::createVertexCfg(1);
00108         s.m_cfg2 = BOP_Segment::createUndefinedCfg();
00109         break;
00110     
00111     case OUT_ON_OUT :
00112     case IN_ON_IN :
00113         s.m_v1 = f->getVertex(1); 
00114         s.m_cfg1 = BOP_Segment::createVertexCfg(2);
00115         s.m_cfg2 = BOP_Segment::createUndefinedCfg();
00116         break;
00117     
00118     case OUT_OUT_ON :      
00119     case IN_IN_ON :
00120         s.m_v1 = f->getVertex(2); 
00121         s.m_cfg1 = BOP_Segment::createVertexCfg(3);
00122         s.m_cfg2 = BOP_Segment::createUndefinedCfg();
00123         break;
00124     
00125     case ON_ON_IN :
00126     case ON_ON_OUT :
00127         s.m_v1 = f->getVertex(0); 
00128         s.m_v2 = f->getVertex(1);
00129         s.m_cfg1 = BOP_Segment::createVertexCfg(1);
00130         s.m_cfg2 = BOP_Segment::createVertexCfg(2);
00131         break;
00132     
00133     case ON_OUT_ON :        
00134     case ON_IN_ON :
00135         s.m_v1 = f->getVertex(0); 
00136         s.m_v2 = f->getVertex(2);
00137         s.m_cfg1 = BOP_Segment::createVertexCfg(1);
00138         s.m_cfg2 = BOP_Segment::createVertexCfg(3);
00139         break;
00140     
00141     case OUT_ON_ON :
00142     case IN_ON_ON :
00143         s.m_v1 = f->getVertex(1); 
00144         s.m_v2 = f->getVertex(2);
00145         s.m_cfg1 = BOP_Segment::createVertexCfg(2);
00146         s.m_cfg2 = BOP_Segment::createVertexCfg(3);
00147         break;
00148     
00149     case IN_OUT_ON :
00150     case OUT_IN_ON :
00151         s.m_v2 = f->getVertex(2);
00152         s.m_cfg1 = BOP_Segment::createEdgeCfg(1);
00153         s.m_cfg2 = BOP_Segment::createVertexCfg(3);
00154         break;
00155     
00156     case IN_ON_OUT :
00157     case OUT_ON_IN :
00158         s.m_v1 = f->getVertex(1);
00159         s.m_cfg1 = BOP_Segment::createVertexCfg(2);
00160         s.m_cfg2 = BOP_Segment::createEdgeCfg(3);
00161         break;
00162     
00163     case ON_IN_OUT :
00164     case ON_OUT_IN :
00165         s.m_v1 = f->getVertex(0);
00166         s.m_cfg1 = BOP_Segment::createVertexCfg(1);
00167         s.m_cfg2 = BOP_Segment::createEdgeCfg(2);
00168         break;
00169     
00170     case OUT_IN_IN :
00171     case IN_OUT_OUT :
00172         s.m_cfg1 = BOP_Segment::createEdgeCfg(1);
00173         s.m_cfg2 = BOP_Segment::createEdgeCfg(3);
00174         break;
00175     
00176     case OUT_IN_OUT :
00177     case IN_OUT_IN :
00178         s.m_cfg1 = BOP_Segment::createEdgeCfg(1);
00179         s.m_cfg2 = BOP_Segment::createEdgeCfg(2);
00180         break;
00181     
00182     case OUT_OUT_IN :
00183     case IN_IN_OUT :
00184         s.m_cfg1 = BOP_Segment::createEdgeCfg(2);
00185         s.m_cfg2 = BOP_Segment::createEdgeCfg(3);
00186         break;
00187     
00188     default:
00189         // wrong TAG!
00190         break;
00191     }
00192 
00193     return s;
00194 }