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

« back to all changes in this revision

Viewing changes to src/Mod/Mesh/App/Core/Visitor.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
/***************************************************************************
 
2
 *   Copyright (c) 2005 Imetric 3D GmbH                                    *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
6
 *   This library is free software; you can redistribute it and/or         *
 
7
 *   modify it under the terms of the GNU Library General Public           *
 
8
 *   License as published by the Free Software Foundation; either          *
 
9
 *   version 2 of the License, or (at your option) any later version.      *
 
10
 *                                                                         *
 
11
 *   This library  is distributed in the hope that it will be useful,      *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU Library General Public License for more details.                  *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU Library General Public     *
 
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
 
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
#include "PreCompiled.h"
 
25
 
 
26
#include "MeshKernel.h"
 
27
#include "Visitor.h"
 
28
#include "Algorithm.h"
 
29
 
 
30
using namespace MeshCore;
 
31
 
 
32
 
 
33
unsigned long MeshKernel::VisitNeighbourFacets (MeshFacetVisitor &rclFVisitor, unsigned long ulStartFacet) const
 
34
{
 
35
  unsigned long ulVisited = 0, j, ulLevel = 0;
 
36
  unsigned long ulCount = _aclFacetArray.size();
 
37
  std::vector<unsigned long> clCurrentLevel, clNextLevel;
 
38
  std::vector<unsigned long>::iterator  clCurrIter;  
 
39
  MeshFacetArray::_TConstIterator clCurrFacet, clNBFacet;
 
40
 
 
41
  // Startpunke aufnehmen
 
42
  clCurrentLevel.push_back(ulStartFacet);
 
43
  _aclFacetArray[ulStartFacet].SetFlag(MeshFacet::VISIT);
 
44
 
 
45
  // solange noch freie Nachbarn
 
46
  while (clCurrentLevel.size() > 0)
 
47
  {
 
48
    // besuche alle Nachbarn des aktuellen Level
 
49
    for (clCurrIter = clCurrentLevel.begin(); clCurrIter < clCurrentLevel.end(); clCurrIter++)
 
50
    {
 
51
      clCurrFacet = _aclFacetArray.begin() + *clCurrIter;
 
52
 
 
53
      // alle Nachbarn des aktuellen Dreiecks besuchen wenn nicht schon besucht wurde
 
54
      for (unsigned short i = 0; i < 3; i++)
 
55
      {
 
56
        j = clCurrFacet->_aulNeighbours[i]; // Index Nachbar-Facet
 
57
        if (j == ULONG_MAX) 
 
58
          continue;      // kein Nachbarn-Facet vorhanden
 
59
 
 
60
        if (j >= ulCount) 
 
61
          continue;      // Fehler in der Datenstruktur
 
62
 
 
63
        clNBFacet = _aclFacetArray.begin() + j;
 
64
 
 
65
        if (!rclFVisitor.AllowVisit(*clNBFacet, *clCurrFacet, j, ulLevel, i))
 
66
          continue;
 
67
 
 
68
        if (clNBFacet->IsFlag(MeshFacet::VISIT) == true)
 
69
          continue; // Nachbar-Facet schon besucht
 
70
        else
 
71
        { // besuche und markiere
 
72
          ulVisited++;
 
73
          clNextLevel.push_back(j);
 
74
          clNBFacet->SetFlag(MeshFacet::VISIT);
 
75
 
 
76
          if (rclFVisitor.Visit(*clNBFacet, *clCurrFacet, j, ulLevel) == false)
 
77
            return ulVisited;
 
78
        }
 
79
      }
 
80
    }
 
81
    clCurrentLevel = clNextLevel;
 
82
    clNextLevel.clear();
 
83
    ulLevel++;
 
84
  }  
 
85
 
 
86
  return ulVisited;
 
87
}
 
88
 
 
89
unsigned long MeshKernel::VisitNeighbourFacetsOverCorners (MeshFacetVisitor &rclFVisitor, unsigned long ulStartFacet) const
 
90
{
 
91
  unsigned long ulVisited = 0, ulLevel = 0;
 
92
  MeshRefPointToFacets clRPF(*this);
 
93
  const MeshFacetArray& raclFAry = _aclFacetArray;
 
94
  MeshFacetArray::_TConstIterator pFBegin = raclFAry.begin();
 
95
  std::vector<unsigned long> aclCurrentLevel, aclNextLevel;
 
96
 
 
97
  aclCurrentLevel.push_back(ulStartFacet);
 
98
  raclFAry[ulStartFacet].SetFlag(MeshFacet::VISIT);
 
99
 
 
100
  while (aclCurrentLevel.size() > 0)
 
101
  {
 
102
    // besuche alle Nachbarn des aktuellen Level
 
103
    for (std::vector<unsigned long>::iterator pCurrFacet = aclCurrentLevel.begin(); pCurrFacet < aclCurrentLevel.end(); pCurrFacet++)
 
104
    {
 
105
      for (int i = 0; i < 3; i++)
 
106
      {
 
107
        const MeshFacet &rclFacet = raclFAry[*pCurrFacet];
 
108
        std::set<MeshFacetArray::_TConstIterator> raclNB = clRPF[rclFacet._aulPoints[i]];
 
109
        for (std::set<MeshFacetArray::_TConstIterator>::iterator pINb = raclNB.begin(); pINb != raclNB.end(); pINb++)
 
110
        {
 
111
          if ((*pINb)->IsFlag(MeshFacet::VISIT) == false)  // nur besuchen wenn VISIT Flag nicht gesetzt
 
112
          {          
 
113
            ulVisited++;
 
114
            unsigned long ulFInd = *pINb - pFBegin;
 
115
            aclNextLevel.push_back(ulFInd);
 
116
            (*pINb)->SetFlag(MeshFacet::VISIT);
 
117
            if (rclFVisitor.Visit(*(*pINb), raclFAry[*pCurrFacet], ulFInd, ulLevel) == false)
 
118
              return ulVisited;
 
119
          }
 
120
        }
 
121
      }
 
122
    }
 
123
    aclCurrentLevel = aclNextLevel;
 
124
    aclNextLevel.clear();
 
125
    ulLevel++;
 
126
  }
 
127
 
 
128
  return ulVisited;
 
129
}
 
130
 
 
131
unsigned long MeshKernel::VisitNeighbourPoints (MeshPointVisitor &rclPVisitor, unsigned long ulStartPoint) const
 
132
{
 
133
  unsigned long ulVisited = 0, ulLevel = 0;
 
134
  std::vector<unsigned long> aclCurrentLevel, aclNextLevel;
 
135
  std::vector<unsigned long>::iterator  clCurrIter;  
 
136
  MeshPointArray::_TConstIterator pPBegin = _aclPointArray.begin();
 
137
  MeshRefPointToPoints clNPs(*this);
 
138
 
 
139
  aclCurrentLevel.push_back(ulStartPoint);
 
140
  (pPBegin + ulStartPoint)->SetFlag(MeshPoint::VISIT);
 
141
 
 
142
  while (aclCurrentLevel.size() > 0)
 
143
  {
 
144
    // besuche alle Nachbarn des aktuellen Level
 
145
    for (clCurrIter = aclCurrentLevel.begin(); clCurrIter < aclCurrentLevel.end(); ++clCurrIter)
 
146
    {
 
147
      std::set<MeshPointArray::_TConstIterator> raclNB = clNPs[*clCurrIter];
 
148
      for (std::set<MeshPointArray::_TConstIterator>::iterator pINb = raclNB.begin(); pINb != raclNB.end(); ++pINb)
 
149
      {
 
150
        if ((*pINb)->IsFlag(MeshPoint::VISIT) == false)  // nur besuchen wenn VISIT Flag nicht gesetzt
 
151
        {          
 
152
          ulVisited++;
 
153
          unsigned long ulPInd = *pINb - pPBegin;
 
154
          aclNextLevel.push_back(ulPInd);
 
155
          (*pINb)->SetFlag(MeshPoint::VISIT);
 
156
          if (rclPVisitor.Visit(*(*pINb), *(pPBegin + (*clCurrIter)), ulPInd, ulLevel) == false)
 
157
            return ulVisited;
 
158
        }
 
159
      }
 
160
    }
 
161
    aclCurrentLevel = aclNextLevel;
 
162
    aclNextLevel.clear();
 
163
    ulLevel++;
 
164
  }
 
165
 
 
166
  return ulVisited;
 
167
}
 
168
 
 
169
// -------------------------------------------------------------------------
 
170
 
 
171
MeshSearchNeighbourFacetsVisitor::MeshSearchNeighbourFacetsVisitor (const MeshKernel &rclMesh, float fRadius, unsigned long ulStartFacetIdx)
 
172
: _rclMeshBase(rclMesh),
 
173
  _clCenter(rclMesh.GetFacet(ulStartFacetIdx).GetGravityPoint()),
 
174
  _fRadius(fRadius),
 
175
  _ulCurrentLevel(0),
 
176
  _bFacetsFoundInCurrentLevel(false)
 
177
{
 
178
}
 
179
 
 
180
std::vector<unsigned long> MeshSearchNeighbourFacetsVisitor::GetAndReset (void)
 
181
{
 
182
  MeshAlgorithm(_rclMeshBase).ResetFacetsFlag(_vecFacets, MeshFacet::VISIT);
 
183
  return _vecFacets;
 
184
}