Blender V2.61 - r43446

BOP_Face.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_Face.h"
00034 
00035 /******************************************************************************/
00036 /*** BOP_Face                                                               ***/
00037 /******************************************************************************/
00038 
00044 BOP_Face::BOP_Face(MT_Plane3 plane, BOP_Index originalFace)
00045 {
00046     m_plane        = plane;
00047     m_tag          = UNCLASSIFIED;
00048     m_originalFace = originalFace;
00049     m_split        = 0;
00050     m_bbox         = NULL;
00051 }
00052 
00056 void BOP_Face::invert()
00057 {
00058     getPlane().Invert();
00059     BOP_Index aux = m_indexs[0];
00060     m_indexs[0] = m_indexs[2];
00061     m_indexs[2] = aux;
00062 }
00063 
00064 /******************************************************************************/
00065 /*** BOP_Face                                                              ***/
00066 /******************************************************************************/
00067 
00076 BOP_Face3::BOP_Face3(BOP_Index v1, BOP_Index v2, BOP_Index v3, MT_Plane3 plane, BOP_Index originalFace): BOP_Face(plane,originalFace) 
00077 {
00078     m_indexs[0] = v1;
00079     m_indexs[1] = v2;
00080     m_indexs[2] = v3;   
00081     m_size = 3;
00082 }
00083 
00091 bool BOP_Face3::getEdgeIndex(BOP_Index v1, BOP_Index v2, unsigned int &e)
00092 {
00093     if (m_indexs[0] == v1) {
00094         if (m_indexs[1] == v2) {
00095             e = 1;
00096         }
00097         else if (m_indexs[2] == v2) {
00098             e = 3;
00099         }
00100         else
00101           return false;
00102     }
00103     else if (m_indexs[1] == v1) {
00104         if (m_indexs[0] == v2) {
00105             e = 1;
00106         }
00107         else if (m_indexs[2] == v2) {
00108             e = 2;
00109         }
00110         else
00111           return false;
00112     }
00113     else if (m_indexs[2] == v1) {
00114         if (m_indexs[0] == v2) {
00115             e = 3;
00116         }
00117         else if (m_indexs[1] == v2) {
00118             e = 2;
00119         }
00120         else
00121           return false;
00122     }else {
00123       return false;
00124     }
00125     
00126     return  true;
00127 } 
00128 
00134 bool BOP_Face3::containsVertex(BOP_Index v) 
00135 {
00136     return (m_indexs[0] == v || m_indexs[1] == v || m_indexs[2] == v);
00137 }
00138 
00146 bool BOP_Face3::getNeighbours(BOP_Index v, BOP_Index &prev, BOP_Index &next) 
00147 {
00148     if (m_indexs[0] == v) {
00149       prev = m_indexs[2];
00150       next = m_indexs[1];
00151     }
00152     else if (m_indexs[1] == v) {
00153       prev = m_indexs[0];
00154       next = m_indexs[2];
00155     }
00156         else if (m_indexs[2] == v) {
00157       prev = m_indexs[1];
00158       next = m_indexs[0];
00159     }
00160     else return false;
00161     
00162     return true;
00163 }
00164 
00171 bool BOP_Face3::getPreviousVertex(BOP_Index v, BOP_Index &w) 
00172 {
00173     if (m_indexs[0] == v) w = m_indexs[2];
00174     else if (m_indexs[1] == v) w = m_indexs[0];
00175     else if (m_indexs[2] == v) w = m_indexs[1];
00176     else return false;
00177     
00178     return true;
00179 }
00180 
00187 bool BOP_Face3::getNextVertex(BOP_Index v, BOP_Index &w) 
00188 {
00189     if (m_indexs[0] == v) w = m_indexs[1];
00190     else if (m_indexs[1] == v) w = m_indexs[2];
00191     else if (m_indexs[2] == v) w = m_indexs[0];
00192     else return false;
00193     
00194     return true;
00195 } 
00196 
00202 void BOP_Face3::replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex)
00203 {
00204     /* if the old index really exists, and new index also exists already,
00205      * don't create an edge with both vertices == newIndex */
00206 
00207     if( (m_indexs[0] == oldIndex || m_indexs[1] == oldIndex || m_indexs[2] == oldIndex) &&
00208             (m_indexs[0] == newIndex || m_indexs[1] == newIndex || m_indexs[2] == newIndex) ) {
00209         setTAG(BROKEN);
00210     }
00211 
00212     if (m_indexs[0] == oldIndex) m_indexs[0] = newIndex;
00213     else if (m_indexs[1] == oldIndex) m_indexs[1] = newIndex;
00214     else if (m_indexs[2] == oldIndex) m_indexs[2] = newIndex;
00215 }
00216 
00217 /******************************************************************************/
00218 /*** BOP_Face4                                                              ***/
00219 /******************************************************************************/
00220 
00230 BOP_Face4::BOP_Face4(BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index v4, MT_Plane3 plane, 
00231                      BOP_Index originalFace): 
00232                      BOP_Face(plane,originalFace) 
00233 {
00234     m_indexs[0] = v1;
00235     m_indexs[1] = v2;
00236     m_indexs[2] = v3;
00237     m_indexs[3] = v4;
00238     
00239     m_size = 4;
00240 }
00241 
00247 bool BOP_Face4::containsVertex(BOP_Index v) 
00248 {
00249     return (m_indexs[0] == v || m_indexs[1] == v || m_indexs[2] == v || m_indexs[3]==v);
00250 }
00251 
00260 bool BOP_Face4::getNeighbours(BOP_Index v, BOP_Index &prev, BOP_Index &next, BOP_Index &opp) 
00261 {
00262     if (m_indexs[0] == v) {
00263       prev = m_indexs[3];
00264       next = m_indexs[1];
00265       opp = m_indexs[2];
00266     }
00267     else if (m_indexs[1] == v) {
00268       prev = m_indexs[0];
00269       next = m_indexs[2];
00270       opp = m_indexs[3];
00271     }
00272     else if (m_indexs[2] == v) {
00273       prev = m_indexs[1];
00274       next = m_indexs[3];
00275       opp = m_indexs[0];
00276     }
00277     else if (m_indexs[3] == v) {
00278       prev = m_indexs[2];
00279       next = m_indexs[0];
00280       opp = m_indexs[1];
00281     }
00282     else return false;
00283 
00284     return true;
00285 }
00286 
00293 bool BOP_Face4::getPreviousVertex(BOP_Index v, BOP_Index &w) 
00294 {
00295     if (m_indexs[0] == v) w = m_indexs[3];
00296     else if (m_indexs[1] == v) w = m_indexs[0];
00297     else if (m_indexs[2] == v) w = m_indexs[1];
00298     else if (m_indexs[3] == v) w = m_indexs[2];
00299     else return false;
00300 
00301     return true;
00302 }
00303 
00310 bool BOP_Face4::getNextVertex(BOP_Index v, BOP_Index &w) 
00311 {
00312     if (m_indexs[0] == v) w = m_indexs[1];
00313     else if (m_indexs[1] == v) w = m_indexs[2];
00314     else if (m_indexs[2] == v) w = m_indexs[3];
00315     else if (m_indexs[3] == v) w = m_indexs[0];
00316     else return false;
00317 
00318     return true;
00319 } 
00320 
00327 bool BOP_Face4::getOppositeVertex(BOP_Index v, BOP_Index &w)
00328 {
00329     if (m_indexs[0] == v) 
00330         w = m_indexs[2];
00331     else if (m_indexs[1] == v) 
00332         w = m_indexs[3];
00333     else if (m_indexs[2] == v) 
00334         w = m_indexs[0];
00335     else if (m_indexs[3] == v) 
00336         w = m_indexs[1];
00337     else
00338       return false;
00339 
00340     return true;
00341 }
00342 
00348 void BOP_Face4::replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex)
00349 {
00350     if (m_indexs[0] == oldIndex) m_indexs[0] = newIndex;
00351     else if (m_indexs[1] == oldIndex) m_indexs[1] = newIndex;
00352     else if (m_indexs[2] == oldIndex) m_indexs[2] = newIndex;
00353     else if (m_indexs[3] == oldIndex) m_indexs[3] = newIndex;
00354 }
00355 
00363 bool BOP_Face4::getEdgeIndex(BOP_Index v1, BOP_Index v2, unsigned int &e)
00364 {
00365     if (m_indexs[0] == v1) {
00366         if (m_indexs[1] == v2) {
00367             e = 1;
00368         }
00369         else if (m_indexs[3] == v2) {
00370             e = 4;
00371         }
00372         else
00373           return false;
00374     }
00375     else if (m_indexs[1] == v1) {
00376         if (m_indexs[0] == v2) {
00377             e = 1;
00378         }
00379         else if (m_indexs[2] == v2) {
00380             e = 2;
00381         }
00382         else
00383           return false;
00384     }
00385     else if (m_indexs[2] == v1) {
00386         if (m_indexs[1] == v2) {
00387             e = 2;
00388         }
00389         else if (m_indexs[3] == v2) {
00390             e = 3;
00391         }
00392         else
00393           return false;
00394     }
00395     else if (m_indexs[3] == v1) {
00396         if (m_indexs[2] == v2) {
00397             e = 3;
00398         }
00399         else if (m_indexs[0] == v2) {
00400             e = 4;
00401         }
00402         else
00403           return false;
00404     }
00405     else return false;
00406     
00407     return  true;
00408 }  
00409 
00410 #ifdef BOP_DEBUG
00411 
00414 ostream &operator<<(ostream &stream, BOP_Face *f)
00415 {
00416     char aux[20];
00417     BOP_stringTAG(f->m_tag,aux);
00418     if (f->size()==3) {
00419         stream << "Face[" << f->getVertex(0) << "," << f->getVertex(1) << ",";
00420         stream << f->getVertex(2) << "] ("  <<  aux  <<  ") <-- " << f->m_originalFace;
00421     }
00422     else {
00423         stream << "Face[" << f->getVertex(0) << "," << f->getVertex(1) << ",";
00424         stream << f->getVertex(2) << "," << f->getVertex(3) << "] ("  <<  aux;
00425         stream <<  ") <-- " << f->m_originalFace;
00426     }
00427 
00428     return stream;
00429 }
00430 #endif