Wm4DelTetrahedron.cpp

Go to the documentation of this file.
00001 // Wild Magic Source Code
00002 // David Eberly
00003 // http://www.geometrictools.com
00004 // Copyright (c) 1998-2007
00005 //
00006 // This library is free software; you can redistribute it and/or modify it
00007 // under the terms of the GNU Lesser General Public License as published by
00008 // the Free Software Foundation; either version 2.1 of the License, or (at
00009 // your option) any later version.  The license is available for reading at
00010 // either of the locations:
00011 //     http://www.gnu.org/copyleft/lgpl.html
00012 //     http://www.geometrictools.com/License/WildMagicLicense.pdf
00013 // The license applies to versions 0 through 4 of Wild Magic.
00014 //
00015 // Version: 4.0.0 (2006/06/28)
00016 
00017 #include "Wm4FoundationPCH.h"
00018 #include "Wm4DelTetrahedron.h"
00019 
00020 namespace Wm4
00021 {
00022 //----------------------------------------------------------------------------
00023 template <class Real>
00024 DelTetrahedron<Real>::DelTetrahedron (int iV0, int iV1, int iV2, int iV3)
00025 {
00026     V[0] = iV0;
00027     V[1] = iV1;
00028     V[2] = iV2;
00029     V[3] = iV3;
00030     A[0] = 0;
00031     A[1] = 0;
00032     A[2] = 0;
00033     A[3] = 0;
00034     Time = -1;
00035     IsComponent = false;
00036     OnStack = false;
00037 }
00038 //----------------------------------------------------------------------------
00039 template <class Real>
00040 bool DelTetrahedron<Real>::IsInsertionComponent (int i, DelTetrahedron* pkAdj,
00041     const Query3<Real>* pkQuery, const int* aiSupervertex)
00042 {
00043     // Indexing for the vertices of the triangle opposite a vertex.  The
00044     // triangle opposite vertex j is
00045     //   <aaiIndex[j][0], aaiIndex[j][1], aaiIndex[j][2]>
00046     // and is listed in counterclockwise order when viewed from outside the
00047     // tetrahedron.
00048     const int aaiIndex[4][3] = { {1,2,3}, {0,3,2}, {0,1,3}, {0,2,1} };
00049 
00050     if (i != Time)
00051     {
00052         Time = i;
00053 
00054         // Determine if the circumsphere of the tetrahedron contains the
00055         // input point.
00056         int iRelation = pkQuery->ToCircumsphere(i,V[0],V[1],V[2],V[3]);
00057         IsComponent = (iRelation <= 0 ? true : false);
00058         if (IsComponent)
00059         {
00060             return true;
00061         }
00062 
00063         // It is possible that a tetrahedron that shares a supervertex does
00064         // not have the circumsphere-containing property, but all faces of
00065         // it (other than the shared one with the calling tetrahedron) are
00066         // visible.  These are also included in the insertion polyhedron.
00067         for (int j = 0; j < 4; j++)
00068         {
00069             for (int k = 0; k < 4; k++)
00070             {
00071                 if (V[j] == aiSupervertex[k])
00072                 {
00073                     // Tetrahedron shares a supervertex.  It is safe to reuse
00074                     // k as a loop index because we are returning from the
00075                     // function.
00076                     int iNumInvisible = 0;
00077                     for (k = 0; k < 4; k++)
00078                     {
00079                         if (A[k] != pkAdj)
00080                         {
00081                             int iV0 = V[aaiIndex[k][0]];
00082                             int iV1 = V[aaiIndex[k][1]];
00083                             int iV2 = V[aaiIndex[k][2]];
00084                             iRelation = pkQuery->ToPlane(i,iV0,iV1,iV2);
00085                             if (iRelation > 0)
00086                             {
00087                                 iNumInvisible++;
00088                             }
00089                         }
00090                     }
00091                     IsComponent = (iNumInvisible == 0 ? true : false);
00092                     return IsComponent;
00093                 }
00094             }
00095         }
00096     }
00097 
00098     return IsComponent;
00099 }
00100 //----------------------------------------------------------------------------
00101 template <class Real>
00102 int DelTetrahedron<Real>::DetachFrom (int iAdj, DelTetrahedron* pkAdj)
00103 {
00104     assert(0 <= iAdj && iAdj < 4 && A[iAdj] == pkAdj);
00105     A[iAdj] = 0;
00106     for (int i = 0; i < 4; i++)
00107     {
00108         if (pkAdj->A[i] == this)
00109         {
00110             pkAdj->A[i] = 0;
00111             return i;
00112         }
00113     }
00114     return -1;
00115 }
00116 //----------------------------------------------------------------------------
00117 
00118 //----------------------------------------------------------------------------
00119 // explicit instantiation
00120 //----------------------------------------------------------------------------
00121 template WM4_FOUNDATION_ITEM
00122 class DelTetrahedron<float>;
00123 
00124 template WM4_FOUNDATION_ITEM
00125 class DelTetrahedron<double>;
00126 //----------------------------------------------------------------------------
00127 }

Generated on Wed Nov 23 19:01:03 2011 for FreeCAD by  doxygen 1.6.1