Wm4DelTriangle.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.1 (2006/07/19)
00016 
00017 #include "Wm4FoundationPCH.h"
00018 #include "Wm4DelTriangle.h"
00019 
00020 namespace Wm4
00021 {
00022 //----------------------------------------------------------------------------
00023 template <class Real>
00024 DelTriangle<Real>::DelTriangle (int iV0, int iV1, int iV2)
00025 {
00026     V[0] = iV0;
00027     V[1] = iV1;
00028     V[2] = iV2;
00029     A[0] = 0;
00030     A[1] = 0;
00031     A[2] = 0;
00032     Time = -1;
00033     IsComponent = false;
00034     OnStack = false;
00035 }
00036 //----------------------------------------------------------------------------
00037 template <class Real>
00038 bool DelTriangle<Real>::IsInsertionComponent (int i, DelTriangle* pkAdj,
00039     const Query2<Real>* pkQuery, const int* aiSupervertex)
00040 {
00041     if (i != Time)
00042     {
00043         Time = i;
00044 
00045         // Determine the number of vertices in common with the supertriangle.
00046         // The supertriangle vertices have indices VQ-3, VQ-2, and VQ-1, where
00047         // VQ is the quantity of input vertices.
00048         int iCommon = 0, iSVIndex = -1, j;
00049         for (j = 0; j < 3; j++)
00050         {
00051             for (int k = 0; k < 3; k++)
00052             {
00053                 if (V[j] == aiSupervertex[k])
00054                 {
00055                     iCommon++;
00056                     iSVIndex = j;
00057                 }
00058             }
00059         }
00060 
00061         int iRelation;
00062         if (iCommon == 0)
00063         {
00064             // The classic case is that a point is in the mesh formed only by
00065             // the input vertices, in which case we only test for containment
00066             // in the circumcircle of the triangle.
00067             iRelation = pkQuery->ToCircumcircle(i,V[0],V[1],V[2]);
00068         }
00069         else
00070         {
00071             // The classic problem is that points outside the mesh formed
00072             // only by the input vertices must be handled from a visibility
00073             // perspective rather than using circumcircles (compare with
00074             // convex hull construction).  By not doing this, you can run into
00075             // the pitfall that has snared many folks--the boundary edges of
00076             // the final triangulation do not form a convex polygon.
00077             int iV0, iV1;
00078             if (iCommon == 1)
00079             {
00080                 iV0 = V[(iSVIndex+1)%3];
00081                 iV1 = V[(iSVIndex+2)%3];
00082             }
00083             else  // iCommon == 2
00084             {
00085                 for (j = 0; j < 3; j++)
00086                 {
00087                     if (A[j] != 0 && A[j] != pkAdj)
00088                     {
00089                         break;
00090                     }
00091                 }
00092                 iV0 = V[j];
00093                 iV1 = V[(j+1)%3];
00094             }
00095             iRelation = pkQuery->ToLine(i,iV0,iV1);
00096         }
00097 
00098         IsComponent = (iRelation < 0 ? true : false);
00099     }
00100 
00101     return IsComponent;
00102 }
00103 //----------------------------------------------------------------------------
00104 template <class Real>
00105 int DelTriangle<Real>::DetachFrom (int iAdj, DelTriangle* pkAdj)
00106 {
00107     assert(0 <= iAdj && iAdj < 3 && A[iAdj] == pkAdj);
00108     A[iAdj] = 0;
00109     for (int i = 0; i < 3; i++)
00110     {
00111         if (pkAdj->A[i] == this)
00112         {
00113             pkAdj->A[i] = 0;
00114             return i;
00115         }
00116     }
00117     return -1;
00118 }
00119 //----------------------------------------------------------------------------
00120 
00121 //----------------------------------------------------------------------------
00122 // explicit instantiation
00123 //----------------------------------------------------------------------------
00124 template WM4_FOUNDATION_ITEM
00125 class DelTriangle<float>;
00126 
00127 template WM4_FOUNDATION_ITEM
00128 class DelTriangle<double>;
00129 //----------------------------------------------------------------------------
00130 }

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