Luxophia

Форк
0
/
LUX.Data.Octree.D3.pas 
340 строк · 10.5 Кб
1
unit LUX.Data.Octree.D3;
2

3
interface //#################################################################### ■
4

5
uses LUX, LUX.D3, LUX.M4,
6
     LUX.Data.Octree, LUX.Data.Octree.Atom,
7
     LUX.Geometry.D3;
8

9
type //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【型】
10

11
     IOcNode3D   = interface;
12
       IOcLeaf3D = interface;
13
       IOcKnot3D = interface;
14
       IOctree3D = interface;
15

16
     TOcLeaf3D = class;
17
     TOcKnot3D = class;
18
     TOctree3D = class;
19

20
     //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【レコード】
21

22
     //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【インタフェース】
23

24
     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% IOcNode3D
25

26
     IOcNode3D = interface( IOcNode )
27
     ['{828065B3-3378-4052-8ECA-FF2BD612970F}']
28
     {protected}
29
       ///// アクセス
30
       function GetRoot :IOctree3D;
31
       function GetParen :IOcNode3D;
32
       procedure SetParen( const Paren_:IOcNode3D );
33
       function GetChilds( const I_:Byte ) :IOcNode3D;
34
       procedure SetChilds( const I_:Byte; const Child_:IOcNode3D );
35
       function GetCubo :TSingleCubo3D;
36
     {public}
37
       ///// プロパティ
38
       property Root                    :IOctree3D     read GetRoot                  ;
39
       property Paren                   :IOcNode3D     read GetParen  write SetParen ;
40
       property Childs[ const I_:Byte ] :IOcNode3D     read GetChilds write SetChilds;
41
       property Cubo                    :TSingleCubo3D read GetCubo                  ;
42
       ///// メソッド
43
       function ForChilds( const Func_:TConstFunc<IOcNode3D,Boolean> ) :Boolean;
44
       procedure ForFamily( const Proc_:TConstProc<IOcNode3D> );
45
       function ForChildPairs( const Node_:IOcNode3D; const Func_:TConstFunc<IOcNode3D,IOcNode3D,Boolean> ) :Boolean;
46
       function Collision( const Node_:IOcNode3D ) :Boolean;
47
     end;
48

49
     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% IOcLeaf3D
50

51
     IOcLeaf3D = interface( IOcLeaf )
52
     ['{A362526F-11E9-4521-B64B-F565A261DD50}']
53
     {protected}
54
     {public}
55
     end;
56

57
     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% IOcKnot3D
58

59
     IOcKnot3D = interface( IOcKnot )
60
     ['{824043A9-14C2-4FD2-8C8E-06C2E0EA0E6C}']
61
     {protected}
62
     {public}
63
     end;
64

65
     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% IOctree3D
66

67
     IOctree3D = interface( IOctree )
68
     ['{E8A174D1-4F6F-4F03-9182-D8BE1A631541}']
69
     {protected}
70
     {public}
71
       ///// メソッド
72
       function GetCubo( const Lev_:Cardinal; const Ind_:TCardinal3D ) :TSingleCubo3D; overload;
73
     end;
74

75
     //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【クラス】
76

77
     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TOcLeaf3D
78

79
     TOcLeaf3D = class( TOcLeaf<IOcNode3D,IOctree3D>, IOcLeaf3D, IOcNode3D )
80
     private
81
     protected
82
       ///// アクセス
83
       function GetCubo :TSingleCubo3D;
84
     public
85
       class constructor Create;
86
       constructor Create;
87
       destructor Destroy; override;
88
       ///// プロパティ
89
       property Cubo :TSingleCubo3D read GetCubo;
90
       ///// メソッド
91
       function Collision( const Node_:IOcNode3D ) :Boolean;
92
     end;
93

94
     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TOcKnot3D
95

96
     TOcKnot3D = class( TOcKnot<IOcNode3D,IOctree3D>, IOcKnot3D, IOcNode3D )
97
     private
98
     protected
99
       ///// アクセス
100
       function GetCubo :TSingleCubo3D;
101
     public
102
       class constructor Create;
103
       constructor Create;
104
       destructor Destroy; override;
105
       ///// プロパティ
106
       property Cubo :TSingleCubo3D read GetCubo;
107
       ///// メソッド
108
       function Collision( const Node_:IOcNode3D ) :Boolean;
109
     end;
110

111
     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TOctree3D
112

113
     TOctree3D = class( TOctree<IOcNode3D,IOctree3D,TOcKnot3D,TOcLeaf3D>, IOctree3D, IOcNode3D )
114
     private
115
     protected
116
       _Area :TSingleArea3D;
117
       _Pose :TSingleM4;
118
       ///// アクセス
119
       function GetCubo :TSingleCubo3D; overload;
120
     public
121
       class constructor Create;
122
       constructor Create;
123
       destructor Destroy; override;
124
       ///// プロパティ
125
       property Cubo :TSingleCubo3D read GetCubo            ;
126
       property Area :TSingleArea3D read   _Area write _Area;
127
       property Pose :TSingleM4     read   _Pose write _Pose;
128
       ///// メソッド
129
       function GetCubo( const Lev_:Cardinal; const Ind_:TCardinal3D ) :TSingleCubo3D; overload;
130
       function Collision( const Node_:IOcNode3D ) :Boolean;
131
     end;
132

133
//const //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【定数】
134

135
//var //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【変数】
136

137
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【ルーチン】
138

139
implementation //############################################################### ■
140

141
uses System.SysUtils, System.Math;
142

143
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【レコード】
144

145
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【クラス】
146

147
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TOcNode3D
148

149
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TOcLeaf3D
150

151
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
152

153
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
154

155
/////////////////////////////////////////////////////////////////////// アクセス
156

157
function TOcLeaf3D.GetCubo :TSingleCubo3D;
158
begin
159
     Result := Root.GetCubo( Lev, Ind );
160
end;
161

162
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
163

164
class constructor TOcLeaf3D.Create;
165
begin
166
     inherited;
167

168
     _CastNode := function( const Node_:IOcNode ) :IOcNode3D
169
                  begin Result := Node_ as IOcNode3D; end;
170

171
     _CastRoot := function( const Root_:IOctree ) :IOctree3D
172
                  begin Result := Root_ as IOctree3D; end;
173
end;
174

175
constructor TOcLeaf3D.Create;
176
begin
177
     inherited;
178

179
end;
180

181
destructor TOcLeaf3D.Destroy;
182
begin
183

184
     inherited;
185
end;
186

187
/////////////////////////////////////////////////////////////////////// メソッド
188

189
function TOcLeaf3D.Collision( const Node_:IOcNode3D ) :Boolean;
190
begin
191
     Result := Cubo.Collision( Node_.Cubo )
192
           and ForChildPairs( Node_, function( const N0,N1:IOcNode3D ) :Boolean
193
               begin
194
                    Result := N0.Collision( N1 );
195
               end );
196
end;
197

198
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TOcKnot3D
199

200
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
201

202
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
203

204
/////////////////////////////////////////////////////////////////////// アクセス
205

206
function TOcKnot3D.GetCubo :TSingleCubo3D;
207
begin
208
     Result := Root.GetCubo( Lev, Ind );
209
end;
210

211
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
212

213
class constructor TOcKnot3D.Create;
214
begin
215
     inherited;
216

217
     _CastNode := function( const Node_:IOcNode ) :IOcNode3D
218
                  begin Result := Node_ as IOcNode3D; end;
219

220
     _CastRoot := function( const Root_:IOctree ) :IOctree3D
221
                  begin Result := Root_ as IOctree3D; end;
222
end;
223

224
constructor TOcKnot3D.Create;
225
begin
226
     inherited;
227

228
end;
229

230
destructor TOcKnot3D.Destroy;
231
begin
232

233
     inherited;
234
end;
235

236
/////////////////////////////////////////////////////////////////////// メソッド
237

238
function TOcKnot3D.Collision( const Node_:IOcNode3D ) :Boolean;
239
begin
240
     Result := Cubo.Collision( Node_.Cubo )
241
           and ForChildPairs( Node_, function( const N0,N1:IOcNode3D ) :Boolean
242
               begin
243
                    Result := N0.Collision( N1 );
244
               end );
245
end;
246

247
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TOctree3D
248

249
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
250

251
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
252

253
/////////////////////////////////////////////////////////////////////// アクセス
254

255
function TOctree3D.GetCubo :TSingleCubo3D;
256
begin
257
     Result := Root.GetCubo( Lev, Ind );
258
end;
259

260
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
261

262
class constructor TOctree3D.Create;
263
begin
264
     inherited;
265

266
     _CastNode := function( const Node_:IOcNode ) :IOcNode3D
267
                  begin Result := Node_ as IOcNode3D; end;
268

269
     _CastRoot := function( const Root_:IOctree ) :IOctree3D
270
                  begin Result := Root_ as IOctree3D; end;
271
end;
272

273
constructor TOctree3D.Create;
274
begin
275
     inherited;
276

277
end;
278

279
destructor TOctree3D.Destroy;
280
begin
281

282
     inherited;
283
end;
284

285
/////////////////////////////////////////////////////////////////////// メソッド
286

287
function TOctree3D.GetCubo( const Lev_:Cardinal; const Ind_:TCardinal3D ) :TSingleCubo3D;
288
var
289
   N :Cardinal;
290
   S :TSingleSiz3D;
291
begin
292
     N := TOctree3D.DivLtoN( Lev_ );
293

294
     S.X := _Area.SizeX / N;
295
     S.Y := _Area.SizeY / N;
296
     S.Z := _Area.SizeZ / N;
297

298
     with Result do
299
     begin
300
          with Area do
301
          begin
302
               with Min do
303
               begin
304
                    X := _Area.Min.X + S.X * Ind_.X;
305
                    Y := _Area.Min.Y + S.Y * Ind_.Y;
306
                    Z := _Area.Min.Z + S.Z * Ind_.Z;
307
               end;
308

309
               with Max do
310
               begin
311
                    X := Min.X + S.X;
312
                    Y := Min.Y + S.Y;
313
                    Z := Min.Z + S.Z;
314
               end;
315
          end;
316

317
          Pose := _Pose;
318
     end;
319
end;
320

321
//------------------------------------------------------------------------------
322

323
function TOctree3D.Collision( const Node_:IOcNode3D ) :Boolean;
324
begin
325
     Result := Cubo.Collision( Node_.Cubo )
326
           and ForChildPairs( Node_, function( const N0,N1:IOcNode3D ) :Boolean
327
               begin
328
                    Result := N0.Collision( N1 );
329
               end );
330
end;
331

332
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【ルーチン】
333

334
//############################################################################## □
335

336
initialization //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 初期化
337

338
finalization //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 最終化
339

340
end. //######################################################################### ■

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.