~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Mod/Mesh/App/WildMagic4/Wm4DelTriangle.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Wild Magic Source Code
 
2
// David Eberly
 
3
// http://www.geometrictools.com
 
4
// Copyright (c) 1998-2007
 
5
//
 
6
// This library is free software; you can redistribute it and/or modify it
 
7
// under the terms of the GNU Lesser General Public License as published by
 
8
// the Free Software Foundation; either version 2.1 of the License, or (at
 
9
// your option) any later version.  The license is available for reading at
 
10
// either of the locations:
 
11
//     http://www.gnu.org/copyleft/lgpl.html
 
12
//     http://www.geometrictools.com/License/WildMagicLicense.pdf
 
13
// The license applies to versions 0 through 4 of Wild Magic.
 
14
//
 
15
// Version: 4.0.1 (2006/07/19)
 
16
 
 
17
#include "Wm4FoundationPCH.h"
 
18
#include "Wm4DelTriangle.h"
 
19
 
 
20
namespace Wm4
 
21
{
 
22
//----------------------------------------------------------------------------
 
23
template <class Real>
 
24
DelTriangle<Real>::DelTriangle (int iV0, int iV1, int iV2)
 
25
{
 
26
    V[0] = iV0;
 
27
    V[1] = iV1;
 
28
    V[2] = iV2;
 
29
    A[0] = 0;
 
30
    A[1] = 0;
 
31
    A[2] = 0;
 
32
    Time = -1;
 
33
    IsComponent = false;
 
34
    OnStack = false;
 
35
}
 
36
//----------------------------------------------------------------------------
 
37
template <class Real>
 
38
bool DelTriangle<Real>::IsInsertionComponent (int i, DelTriangle* pkAdj,
 
39
    const Query2<Real>* pkQuery, const int* aiSupervertex)
 
40
{
 
41
    if (i != Time)
 
42
    {
 
43
        Time = i;
 
44
 
 
45
        // Determine the number of vertices in common with the supertriangle.
 
46
        // The supertriangle vertices have indices VQ-3, VQ-2, and VQ-1, where
 
47
        // VQ is the quantity of input vertices.
 
48
        int iCommon = 0, iSVIndex = -1, j;
 
49
        for (j = 0; j < 3; j++)
 
50
        {
 
51
            for (int k = 0; k < 3; k++)
 
52
            {
 
53
                if (V[j] == aiSupervertex[k])
 
54
                {
 
55
                    iCommon++;
 
56
                    iSVIndex = j;
 
57
                }
 
58
            }
 
59
        }
 
60
 
 
61
        int iRelation;
 
62
        if (iCommon == 0)
 
63
        {
 
64
            // The classic case is that a point is in the mesh formed only by
 
65
            // the input vertices, in which case we only test for containment
 
66
            // in the circumcircle of the triangle.
 
67
            iRelation = pkQuery->ToCircumcircle(i,V[0],V[1],V[2]);
 
68
        }
 
69
        else
 
70
        {
 
71
            // The classic problem is that points outside the mesh formed
 
72
            // only by the input vertices must be handled from a visibility
 
73
            // perspective rather than using circumcircles (compare with
 
74
            // convex hull construction).  By not doing this, you can run into
 
75
            // the pitfall that has snared many folks--the boundary edges of
 
76
            // the final triangulation do not form a convex polygon.
 
77
            int iV0, iV1;
 
78
            if (iCommon == 1)
 
79
            {
 
80
                iV0 = V[(iSVIndex+1)%3];
 
81
                iV1 = V[(iSVIndex+2)%3];
 
82
            }
 
83
            else  // iCommon == 2
 
84
            {
 
85
                for (j = 0; j < 3; j++)
 
86
                {
 
87
                    if (A[j] != 0 && A[j] != pkAdj)
 
88
                    {
 
89
                        break;
 
90
                    }
 
91
                }
 
92
                iV0 = V[j];
 
93
                iV1 = V[(j+1)%3];
 
94
            }
 
95
            iRelation = pkQuery->ToLine(i,iV0,iV1);
 
96
        }
 
97
 
 
98
        IsComponent = (iRelation < 0 ? true : false);
 
99
    }
 
100
 
 
101
    return IsComponent;
 
102
}
 
103
//----------------------------------------------------------------------------
 
104
template <class Real>
 
105
int DelTriangle<Real>::DetachFrom (int iAdj, DelTriangle* pkAdj)
 
106
{
 
107
    assert(0 <= iAdj && iAdj < 3 && A[iAdj] == pkAdj);
 
108
    A[iAdj] = 0;
 
109
    for (int i = 0; i < 3; i++)
 
110
    {
 
111
        if (pkAdj->A[i] == this)
 
112
        {
 
113
            pkAdj->A[i] = 0;
 
114
            return i;
 
115
        }
 
116
    }
 
117
    return -1;
 
118
}
 
119
//----------------------------------------------------------------------------
 
120
 
 
121
//----------------------------------------------------------------------------
 
122
// explicit instantiation
 
123
//----------------------------------------------------------------------------
 
124
template WM4_FOUNDATION_ITEM
 
125
class DelTriangle<float>;
 
126
 
 
127
template WM4_FOUNDATION_ITEM
 
128
class DelTriangle<double>;
 
129
//----------------------------------------------------------------------------
 
130
}