Blender V2.61 - r43446
|
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_Segment.h" 00034 00035 #define UNDEFINED 0 00036 00040 BOP_Segment::BOP_Segment(){ 00041 m_cfg1 = UNDEFINED; 00042 m_cfg2 = UNDEFINED; 00043 } 00044 00051 int BOP_Segment::getEdgeBetween(unsigned int v1, unsigned int v2) 00052 { 00053 if ((v1 == 1 && v2 == 2) || (v1 == 2 && v2 == 1)) return 1; 00054 if ((v1 == 3 && v2 == 2) || (v1 == 2 && v2 == 3)) return 2; 00055 if ((v1 == 1 && v2 == 3) || (v1 == 3 && v2 == 1)) return 3; 00056 return -1; 00057 } 00058 00066 bool BOP_Segment::isOnEdge(unsigned int v, unsigned int e) 00067 { 00068 if (v == 1 && (e == 1 || e == 3)) return true; 00069 if (v == 2 && (e == 1 || e == 2)) return true; 00070 if (v == 3 && (e == 2 || e == 3)) return true; 00071 return false; 00072 } 00073 00077 void BOP_Segment::invert() 00078 { 00079 BOP_Index aux = m_v1; 00080 m_v1 = m_v2; 00081 m_v2 = aux; 00082 aux = m_cfg1; 00083 m_cfg1 = m_cfg2; 00084 m_cfg2 = aux; 00085 } 00086 00100 void BOP_Segment::sort() 00101 { 00102 if (m_cfg1 < m_cfg2) invert(); 00103 } 00104 00109 bool BOP_Segment::isIn(unsigned int cfg) 00110 { 00111 return (cfg == 20); 00112 } 00113 00118 bool BOP_Segment::isEdge(unsigned int cfg) 00119 { 00120 return (cfg > 10) && (cfg < 20); 00121 } 00122 00127 bool BOP_Segment::isVertex(unsigned int cfg) 00128 { 00129 return (cfg!=UNDEFINED) && (cfg < 10); 00130 } 00131 00136 bool BOP_Segment::isDefined(unsigned int cfg) 00137 { 00138 return (cfg != UNDEFINED); 00139 } 00140 00145 bool BOP_Segment::isUndefined(unsigned int cfg) 00146 { 00147 return (cfg == UNDEFINED); 00148 } 00149 00154 unsigned int BOP_Segment::getEdge(unsigned int cfg) 00155 { 00156 return cfg-10; 00157 } 00158 00163 BOP_Index BOP_Segment::getVertex(unsigned int cfg) 00164 { 00165 return cfg; 00166 } 00167 00172 unsigned int BOP_Segment::createEdgeCfg(unsigned int edge) 00173 { 00174 return 10+edge; 00175 } 00176 00181 unsigned int BOP_Segment::createVertexCfg(BOP_Index vertex) 00182 { 00183 return vertex; 00184 } 00185 00190 unsigned int BOP_Segment::createInCfg() 00191 { 00192 return 20; 00193 } 00194 00199 unsigned int BOP_Segment::createUndefinedCfg() 00200 { 00201 return UNDEFINED; 00202 } 00203 00208 unsigned int BOP_Segment::getConfig() 00209 { 00210 if (isUndefined(m_cfg1)) return m_cfg2; 00211 else if (isUndefined(m_cfg2)) return m_cfg1; 00212 else if (isVertex(m_cfg1)) { 00213 // v1 is vertex 00214 if (isVertex(m_cfg2)) { 00215 // v2 is vertex 00216 return createEdgeCfg(getEdgeBetween(getVertex(m_cfg1),getVertex(m_cfg2))); 00217 } 00218 else if (isEdge(m_cfg2)) { 00219 // v2 is edge 00220 if (isOnEdge(m_cfg1,getEdge(m_cfg2))) return m_cfg2; 00221 else return createInCfg(); //IN 00222 } 00223 else return createInCfg(); //IN 00224 } 00225 else if (isEdge(m_cfg1)) { 00226 // v1 is edge 00227 if (isVertex(m_cfg2)) { 00228 // v2 is vertex 00229 if (isOnEdge(m_cfg2,getEdge(m_cfg1))) return m_cfg1; 00230 else return createInCfg(); //IN 00231 } 00232 else if (isEdge(m_cfg2)) { 00233 // v2 is edge 00234 if (m_cfg1 == m_cfg2) return m_cfg1; 00235 else return createInCfg(); // IN 00236 } 00237 else return createInCfg(); // IN 00238 } 00239 else return createInCfg(); // IN 00240 } 00241 00245 std::ostream &operator<<(std::ostream &stream, const BOP_Segment &c) 00246 { 00247 std::cout << "m_v1: " << c.m_v1 << "(" << c.m_cfg1 << ") m_v2: " << c.m_v2 << "(" << c.m_cfg2 << ")"; 00248 return stream; 00249 }