1
unit LUX.Brep.Cell.TetraFlip.D3;
8
System.RegularExpressions,
10
LUX, LUX.D3, LUX.Geometry.D3,
11
LUX.Graph, LUX.Graph.Tree, LUX.Brep,
12
LUX.Brep.Cell.TetraFlip;
17
TTetraModel3D = class;
19
TTetraPoin3D = class(TTetraPoin<TSingle3D>)
25
TTetraCell3D<_TPoin_: TTetraPoin3D; _TCell_: class> = class
26
(TTetraCell<_TPoin_, _TCell_>)
29
function GetVolum2: Single;
30
function GetVolume: Single;
31
function GetBarycenter: TSingle3D;
32
function GetInnerCenter: TSingle3D;
33
function GetInnerRadius: Single;
34
function GetInnerSphere: TSingleSphere;
35
function GetCircumCenter: TSingle3D;
36
function GetCircumSpher2: TSingleSpher2;
37
function GetCircumSphere: TSingleSphere;
38
function GetFaceArea(const I_: Byte): Single;
39
function GetFaceNorm(const I_: Byte): TSingle3D;
40
function GetVoroEdge(const I_: Byte): TSingle3D;
42
property Volum2: Single read GetVolum2;
43
property Volume: Single read GetVolume;
44
property Barycenter: TSingle3D read GetBarycenter;
45
property InnerCenter: TSingle3D read GetInnerCenter;
46
property InnerRadius: Single read GetInnerRadius;
47
property InnerSphere: TSingleSphere read GetInnerSphere;
48
property CircumCenter: TSingle3D read GetCircumCenter;
49
property CircumSpher2: TSingleSpher2 read GetCircumSpher2;
50
property CircumSphere: TSingleSphere read GetCircumSphere;
51
property FaceArea[const I_: Byte]: Single read GetFaceArea;
52
property FaceNorm[const I_: Byte]: TSingle3D read GetFaceNorm;
53
property VoroEdge[const I_: Byte]: TSingle3D read GetVoroEdge;
56
TTetraCell3D = class(TTetraCell3D<TTetraPoin3D, TTetraCell3D>)
62
TTetraModel3D<_TPoin_: class; _TCell_: class> = class
63
(TTetraModel<_TPoin_, _TCell_>)
65
function Get_Self: TTetraModel3D; inline;
67
property _Self: TTetraModel3D read Get_Self;
69
procedure LoadFromFile(const FileName_: String);
70
procedure SaveToFile(const FileName_: String);
73
TTetraModel3D = class(TTetraModel3D<TTetraPoin3D, TTetraCell3D>)
77
procedure LoadFromFile(const FileName_: String);
78
procedure SaveToFile(const FileName_: String);
83
function TTetraCell3D<_TPoin_, _TCell_>.GetVolum2: Single;
85
Result := HeronVolum2(TTetraPoin3D(_Poin[0]).Pos, { ToDo: 本来キャスト不要 }
86
TTetraPoin3D(_Poin[1]).Pos, TTetraPoin3D(_Poin[2]).Pos,
87
TTetraPoin3D(_Poin[3]).Pos);
90
function TTetraCell3D<_TPoin_, _TCell_>.GetVolume: Single;
92
Result := Roo2(GetVolum2);
95
// ------------------------------------------------------------------------------
97
function TTetraCell3D<_TPoin_, _TCell_>.GetBarycenter: TSingle3D;
99
Result := LUX.Geometry.D3.Barycenter(TTetraPoin3D(_Poin[0]).Pos,
100
{ ToDo: Originally no cast required }
101
TTetraPoin3D(_Poin[1]).Pos, TTetraPoin3D(_Poin[2]).Pos,
102
TTetraPoin3D(_Poin[3]).Pos);
105
// ------------------------------------------------------------------------------
107
function TTetraCell3D<_TPoin_, _TCell_>.GetInnerCenter: TSingle3D;
109
Result := LUX.Geometry.D3.InnerCenter(TTetraPoin3D(_Poin[0]).Pos,
110
{ ToDo: Originally no cast required }
111
TTetraPoin3D(_Poin[1]).Pos, TTetraPoin3D(_Poin[2]).Pos,
112
TTetraPoin3D(_Poin[3]).Pos);
115
function TTetraCell3D<_TPoin_, _TCell_>.GetInnerRadius: Single;
117
Result := LUX.Geometry.D3.InnerRadius(TTetraPoin3D(_Poin[0]).Pos,
118
{ ToDo: Originally no cast required }
119
TTetraPoin3D(_Poin[1]).Pos, TTetraPoin3D(_Poin[2]).Pos,
120
TTetraPoin3D(_Poin[3]).Pos);
123
function TTetraCell3D<_TPoin_, _TCell_>.GetInnerSphere: TSingleSphere;
125
Result := TSingleSphere.Inner(TTetraPoin3D(_Poin[0]).Pos, { ToDo: 本来キャスト不要 }
126
TTetraPoin3D(_Poin[1]).Pos, TTetraPoin3D(_Poin[2]).Pos,
127
TTetraPoin3D(_Poin[3]).Pos);
130
// ------------------------------------------------------------------------------
132
function TTetraCell3D<_TPoin_, _TCell_>.GetCircumCenter: TSingle3D;
134
Result := LUX.Geometry.D3.CircumCenter(TTetraPoin3D(_Poin[0]).Pos,
135
{ ToDo: Originally no cast required }
136
TTetraPoin3D(_Poin[1]).Pos, TTetraPoin3D(_Poin[2]).Pos,
137
TTetraPoin3D(_Poin[3]).Pos);
140
function TTetraCell3D<_TPoin_, _TCell_>.GetCircumSpher2: TSingleSpher2;
142
Result := TSingleSpher2.Create(TTetraPoin3D(_Poin[0]).Pos, { ToDo: 本来キャスト不要 }
143
TTetraPoin3D(_Poin[1]).Pos, TTetraPoin3D(_Poin[2]).Pos,
144
TTetraPoin3D(_Poin[3]).Pos);
147
function TTetraCell3D<_TPoin_, _TCell_>.GetCircumSphere: TSingleSphere;
149
Result := TSingleSphere.Create(TTetraPoin3D(_Poin[0]).Pos, { ToDo: 本来キャスト不要 }
150
TTetraPoin3D(_Poin[1]).Pos, TTetraPoin3D(_Poin[2]).Pos,
151
TTetraPoin3D(_Poin[3]).Pos);
154
// ------------------------------------------------------------------------------
156
function TTetraCell3D<_TPoin_, _TCell_>.GetFaceArea(const I_: Byte): Single;
158
with _VertTable[I_] do
160
Result := HeronArea(TTetraPoin3D(_Poin[_[1]]).Pos, { ToDo: 本来キャスト不要 }
161
TTetraPoin3D(_Poin[_[2]]).Pos, TTetraPoin3D(_Poin[_[3]]).Pos);
165
// ------------------------------------------------------------------------------
167
function TTetraCell3D<_TPoin_, _TCell_>.GetFaceNorm(const I_: Byte): TSingle3D;
169
with _VertTable[I_] do
171
Result := TriNormal(TTetraPoin3D(_Poin[_[1]]).Pos, { ToDo: 本来キャスト不要 }
172
TTetraPoin3D(_Poin[_[2]]).Pos, TTetraPoin3D(_Poin[_[3]]).Pos);
176
function TTetraCell3D<_TPoin_, _TCell_>.GetVoroEdge(const I_: Byte): TSingle3D;
180
C := TTetraCell3D(Cell[I_]);
182
if Assigned(C) and (C.Open = -1) then
183
Result := CircumCenter.VectorTo(C.CircumCenter)
185
Result := FaceNorm[I_];
188
function TTetraModel3D<_TPoin_, _TCell_>.Get_Self: TTetraModel3D;
190
Result := TTetraModel3D(Self);
193
procedure TTetraModel3D<_TPoin_, _TCell_>.LoadFromFile(const FileName_: String);
195
_Self.LoadFromFile(FileName_);
198
procedure TTetraModel3D<_TPoin_, _TCell_>.SaveToFile(const FileName_: String);
200
_Self.SaveToFile(FileName_);
203
procedure TTetraModel3D.LoadFromFile(const FileName_: String);
207
PoinN, CellN, I, J, PoinI, CellI, VertI, BondI: Integer;
209
RP := TRegEx.Create('PoinsN\s*=\s*(\d+)', [roCompiled]);
210
RC := TRegEx.Create('CellsN\s*=\s*(\d+)', [roCompiled]);
212
with TFileReader.Create(FileName_, TEncoding.UTF8) do
215
Assert(L = '#TetraFlip', L);
220
while not EndOfStream do
228
PoinN := Groups[1].Value.ToInteger;
233
CellN := Groups[1].Value.ToInteger;
236
Assert(not EndOfStream);
237
Assert(PoinN >= 0, PoinN.ToString);
238
Assert(CellN >= 0, CellN.ToString);
243
for I := 0 to PoinN - 1 do
245
with TTetraPoin3D.Create(_PoinModel) do
247
Pos := TSingle3D.Create(ReadSingle, ReadSingle, ReadSingle);
252
for I := 0 to CellN - 1 do
254
with TTetraCell3D.Create(Self) do
258
PoinI := ReadInteger;
261
Poin[J] := _PoinModel.Childs[PoinI];
271
for I := 0 to CellN - 1 do
277
CellI := ReadInteger;
283
Cell[J] := Self.Childs[CellI];
300
procedure TTetraModel3D.SaveToFile(const FileName_: String);
305
F := TFileStream.Create(FileName_, fmCreate);
307
with TStreamWriter.Create(F, TEncoding.UTF8) do
309
WriteLine('#TetraFlip');
310
WriteLine('PoinsN=' + _PoinModel.ChildsN.ToString);
311
WriteLine('CellsN=' + ChildsN.ToString);
316
with TBinaryWriter.Create(F) do
320
for I := 0 to ChildsN - 1 do
334
for I := 0 to ChildsN - 1 do
340
if Assigned(Poin[J]) then
348
for I := 0 to ChildsN - 1 do
354
if Assigned(Cell[J]) then
356
Write(Cell[J].Order);