summaryrefslogtreecommitdiff
path: root/src/BOP/BOP_SFSCorrector.cxx
blob: afad4753369080fb1c3e3ff500e50e29589a11fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// File:	BOP_SFSCorrector.cxx
// Created:	Thu Aug 2 10:47:47 2001
// Author:	Peter KURNEV
//		<pkv@irinox>
//

#include <BOP_SFSCorrector.ixx>

#include <TopTools_IndexedMapOfOrientedShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>

#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Edge.hxx>

#include <BRep_Builder.hxx>

#include <BOP_ConnexityBlock.hxx>
#include <BOP_ListIteratorOfListOfConnexityBlock.hxx>
#include <BOP_ShellSplitter.hxx>
#include <BOPTColStd_ListOfListOfShape.hxx>
#include <BOPTColStd_ListIteratorOfListOfListOfShape.hxx>


static
  void MakeShell (const TopTools_ListOfShape& aLE, 
		  TopoDS_Shell& newShell);

//=======================================================================
// function: BOP_SFSCorrector::BOP_SFSCorrector
// purpose: 
//=======================================================================
  BOP_SFSCorrector::BOP_SFSCorrector()
:
  myIsDone(Standard_False),
  myErrorStatus(1)
{}
//=======================================================================
// function: SetSFS
// purpose: 
//=======================================================================
  void BOP_SFSCorrector::SetSFS (const BOP_ShellFaceSet& aSFS)
{
  BOP_ShellFaceSet* pSFS=(BOP_ShellFaceSet*) &aSFS;
  mySFS=pSFS;
}
//=======================================================================
// function: SFS
// purpose: 
//=======================================================================
  BOP_ShellFaceSet& BOP_SFSCorrector::SFS () 
{
  return *mySFS;
}
//=======================================================================
// function: NewSFS
// purpose: 
//=======================================================================
  BOP_ShellFaceSet& BOP_SFSCorrector::NewSFS () 
{
  return myNewSFS;
}
//=======================================================================
// function: IsDone
// purpose: 
//=======================================================================
  Standard_Boolean BOP_SFSCorrector::IsDone () const 
{
  return myIsDone;
}
//=======================================================================
// function: ErrorStatus
// purpose: 
//=======================================================================
  Standard_Integer BOP_SFSCorrector::ErrorStatus () const 
{
  return myErrorStatus;
}
//=======================================================================
// function: Do
// purpose: 
//=======================================================================
  void BOP_SFSCorrector::Do()
{
  DoConnexityBlocks();
  DoCorrections();
  myIsDone=Standard_True;
}
//=======================================================================
// function: DoConnexityBlocks
// purpose: 
//=======================================================================
  void BOP_SFSCorrector::DoConnexityBlocks()
{
  Standard_Boolean EnewinM, aGoOn;
  Standard_Integer Mextent, IsRegular, aNbNeighbours, Eindex;
  TopTools_IndexedMapOfOrientedShape myOrientedShapeMap, aMap;
  //
  mySFS->InitStartElements();
  for (; mySFS->MoreStartElements(); mySFS->NextStartElement()) {
    const TopoDS_Shape& anE = mySFS->StartElement(); 
    Mextent = myOrientedShapeMap.Extent();

    Eindex  = myOrientedShapeMap.Add(anE); 

    EnewinM = (Eindex > Mextent);
    if (EnewinM) {
      //
      // make a new block starting at element Eindex
      IsRegular=Standard_True; 
      aNbNeighbours=0;
      Mextent = myOrientedShapeMap.Extent();
      //
      aMap.Clear();
      aMap.Add(anE);
      //
      aGoOn = (Eindex <= Mextent);
      while (aGoOn) {
	const TopoDS_Shape& anEE = myOrientedShapeMap(Eindex);
	aNbNeighbours = mySFS->MaxNumberSubShape(anEE);
	
	IsRegular = IsRegular && (aNbNeighbours == 2);
	//
	mySFS->InitNeighbours(anEE);
	for (; mySFS->MoreNeighbours(); mySFS->NextNeighbour()) {
	  const TopoDS_Shape& aNeignbE = mySFS->Neighbour();
	  myOrientedShapeMap.Add(aNeignbE);
	  //
	  aMap.Add(aNeignbE);
	}
	
	Eindex++;
	Mextent = myOrientedShapeMap.Extent();
	aGoOn = (Eindex <= Mextent);
      } // end of while aGoOn
      
      BOP_ConnexityBlock aConnexityBlock;
      aConnexityBlock.SetShapes(aMap);
      aConnexityBlock.SetRegularity(IsRegular);
      myConnexityBlocks.Append(aConnexityBlock);
    } // end of if (EnewinM)
  } // end of for (; mySFS->MoreStartElements();...
}

//=======================================================================
// function: DoCorrections
// purpose: 
//=======================================================================
  void BOP_SFSCorrector::DoCorrections()
{
  Standard_Boolean anIsRegular, anIsNothingToDo, anIsDone;
  TopoDS_Shell aShell;
  BOP_ListIteratorOfListOfConnexityBlock aCBIt;
  
  //myNewSFS.Initialize(mySFS->Face());
  anIsDone=Standard_False;
  anIsNothingToDo=Standard_True;

  aCBIt.Initialize(myConnexityBlocks);
  for (; aCBIt.More(); aCBIt.Next()) {
    const BOP_ConnexityBlock& aCB=aCBIt.Value();
    const TopTools_ListOfShape& aListOfEdges=aCB.Shapes();

    anIsRegular=aCB.IsRegular();

    if (anIsRegular) {
      MakeShell(aListOfEdges, aShell);
      myNewSFS.AddShape (aShell);
      continue;
    }
    //
    // Treatment of non regular Connexity Block
    BOP_ShellSplitter aShellSplitter;
    aShellSplitter.DoWithListOfEdges(aListOfEdges);
    
    anIsDone=aShellSplitter.IsDone();
    anIsNothingToDo=aShellSplitter.IsNothingToDo();
    
    if (!anIsDone || anIsNothingToDo) {
      MakeShell(aListOfEdges, aShell);
      myNewSFS.AddShape (aShell);
      continue;
    }

    //
    const BOPTColStd_ListOfListOfShape& aSSS=aShellSplitter.Shapes();
    
    BOPTColStd_ListIteratorOfListOfListOfShape aShellIt(aSSS);
    for (; aShellIt.More(); aShellIt.Next()) {
      const TopTools_ListOfShape& aListF=aShellIt.Value();
      //
      MakeShell(aListF, aShell);
      myNewSFS.AddShape (aShell);
    }
  }
}

//=======================================================================
// function: MakeShell
// purpose: 
//=======================================================================
  void MakeShell(const TopTools_ListOfShape& aLE, 
		 TopoDS_Shell& newShell)
{
  BRep_Builder aBB;
  aBB.MakeShell(newShell);

  TopTools_ListIteratorOfListOfShape anIt(aLE);
  for (; anIt.More(); anIt.Next()){
    const TopoDS_Face& aF=TopoDS::Face(anIt.Value());
    aBB.Add(newShell, aF);
  }
}
/////////////////////////////////////////////////////////////////
//
// myErrorStatus:
//
// 1 - Nothing is done because only constructor has been called
//
/////////////////////////////////////////////////////////////////