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

« back to all changes in this revision

Viewing changes to src/Mod/Mesh/App/WildMagic4/Wm4DelTetrahedron.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.0 (2006/06/28)
 
16
 
 
17
#include "Wm4FoundationPCH.h"
 
18
#include "Wm4DelTetrahedron.h"
 
19
 
 
20
namespace Wm4
 
21
{
 
22
//----------------------------------------------------------------------------
 
23
template <class Real>
 
24
DelTetrahedron<Real>::DelTetrahedron (int iV0, int iV1, int iV2, int iV3)
 
25
{
 
26
    V[0] = iV0;
 
27
    V[1] = iV1;
 
28
    V[2] = iV2;
 
29
    V[3] = iV3;
 
30
    A[0] = 0;
 
31
    A[1] = 0;
 
32
    A[2] = 0;
 
33
    A[3] = 0;
 
34
    Time = -1;
 
35
    IsComponent = false;
 
36
    OnStack = false;
 
37
}
 
38
//----------------------------------------------------------------------------
 
39
template <class Real>
 
40
bool DelTetrahedron<Real>::IsInsertionComponent (int i, DelTetrahedron* pkAdj,
 
41
    const Query3<Real>* pkQuery, const int* aiSupervertex)
 
42
{
 
43
    // Indexing for the vertices of the triangle opposite a vertex.  The
 
44
    // triangle opposite vertex j is
 
45
    //   <aaiIndex[j][0], aaiIndex[j][1], aaiIndex[j][2]>
 
46
    // and is listed in counterclockwise order when viewed from outside the
 
47
    // tetrahedron.
 
48
    const int aaiIndex[4][3] = { {1,2,3}, {0,3,2}, {0,1,3}, {0,2,1} };
 
49
 
 
50
    if (i != Time)
 
51
    {
 
52
        Time = i;
 
53
 
 
54
        // Determine if the circumsphere of the tetrahedron contains the
 
55
        // input point.
 
56
        int iRelation = pkQuery->ToCircumsphere(i,V[0],V[1],V[2],V[3]);
 
57
        IsComponent = (iRelation <= 0 ? true : false);
 
58
        if (IsComponent)
 
59
        {
 
60
            return true;
 
61
        }
 
62
 
 
63
        // It is possible that a tetrahedron that shares a supervertex does
 
64
        // not have the circumsphere-containing property, but all faces of
 
65
        // it (other than the shared one with the calling tetrahedron) are
 
66
        // visible.  These are also included in the insertion polyhedron.
 
67
        for (int j = 0; j < 4; j++)
 
68
        {
 
69
            for (int k = 0; k < 4; k++)
 
70
            {
 
71
                if (V[j] == aiSupervertex[k])
 
72
                {
 
73
                    // Tetrahedron shares a supervertex.  It is safe to reuse
 
74
                    // k as a loop index because we are returning from the
 
75
                    // function.
 
76
                    int iNumInvisible = 0;
 
77
                    for (k = 0; k < 4; k++)
 
78
                    {
 
79
                        if (A[k] != pkAdj)
 
80
                        {
 
81
                            int iV0 = V[aaiIndex[k][0]];
 
82
                            int iV1 = V[aaiIndex[k][1]];
 
83
                            int iV2 = V[aaiIndex[k][2]];
 
84
                            iRelation = pkQuery->ToPlane(i,iV0,iV1,iV2);
 
85
                            if (iRelation > 0)
 
86
                            {
 
87
                                iNumInvisible++;
 
88
                            }
 
89
                        }
 
90
                    }
 
91
                    IsComponent = (iNumInvisible == 0 ? true : false);
 
92
                    return IsComponent;
 
93
                }
 
94
            }
 
95
        }
 
96
    }
 
97
 
 
98
    return IsComponent;
 
99
}
 
100
//----------------------------------------------------------------------------
 
101
template <class Real>
 
102
int DelTetrahedron<Real>::DetachFrom (int iAdj, DelTetrahedron* pkAdj)
 
103
{
 
104
    assert(0 <= iAdj && iAdj < 4 && A[iAdj] == pkAdj);
 
105
    A[iAdj] = 0;
 
106
    for (int i = 0; i < 4; i++)
 
107
    {
 
108
        if (pkAdj->A[i] == this)
 
109
        {
 
110
            pkAdj->A[i] = 0;
 
111
            return i;
 
112
        }
 
113
    }
 
114
    return -1;
 
115
}
 
116
//----------------------------------------------------------------------------
 
117
 
 
118
//----------------------------------------------------------------------------
 
119
// explicit instantiation
 
120
//----------------------------------------------------------------------------
 
121
template WM4_FOUNDATION_ITEM
 
122
class DelTetrahedron<float>;
 
123
 
 
124
template WM4_FOUNDATION_ITEM
 
125
class DelTetrahedron<double>;
 
126
//----------------------------------------------------------------------------
 
127
}