1 {
2 *****************************************************************************
3 *                                                                           *
4 *  This file is part of the ZCAD                                            *
5 *                                                                           *
6 *  See the file COPYING.modifiedLGPL.txt, included in this distribution,    *
7 *  for details about the copyright.                                         *
8 *                                                                           *
9 *  This program is distributed in the hope that it will be useful,          *
10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
12 *                                                                           *
13 *****************************************************************************
14 }
15 {
16 @author(Andrey Zubarev <zamtmn@yandex.ru>)
17 }
18 
19 unit uzgprimitives;
20 {$INCLUDE def.inc}
21 interface
22 uses uzgprimitivessarray,math,uzglgeomdata,uzgldrawcontext,uzgvertex3sarray,uzgldrawerabstract,
23      uzbtypesbase,sysutils,uzbtypes,uzbmemman,
24      gzctnrvectortypes,uzbgeomtypes,uzegeometry;
25 const
26      LLAttrNothing=0;
27      LLAttrNeedSolid=1;
28      LLAttrNeedSimtlify=2;
29 
30      {LLLineId=1;
31      LLPointId=2;
32      LLSymbolId=3;
33      LLSymbolEndId=4;
34      LLPolyLineId=5;
35      LLTriangleId=6;}
36 type
37 {Export+}
38 ZGLOptimizerData={$IFNDEF DELPHI}packed{$ENDIF}record
39                                                      ignoretriangles:boolean;
40                                                      ignorelines:boolean;
41                                                      symplify:boolean;
42                                                end;
43 TEntIndexesData={$IFNDEF DELPHI}packed{$ENDIF}record
44                                                     GeomIndexMin,GeomIndexMax:GDBInteger;
45                                                     IndexsIndexMin,IndexsIndexMax:GDBInteger;
46                                               end;
47 TEntIndexesOffsetData={$IFNDEF DELPHI}packed{$ENDIF}record
48                                                     GeomIndexOffset:GDBInteger;
49                                                     IndexsIndexOffset:GDBInteger;
50                                               end;
51 PTLLPrimitive=^TLLPrimitive;
52 TLLPrimitive={$IFNDEF DELPHI}packed{$ENDIF} object
getPrimitiveSizenull53                        function getPrimitiveSize:GDBInteger;virtual;
54                        procedure getEntIndexs(var GeomData:ZGLGeomData;out eid:TEntIndexesData);virtual;
55                        procedure CorrectIndexes(const offset:TEntIndexesOffsetData);virtual;
56                        constructor init;
57                        destructor done;
drawnull58                        function draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;virtual;
CalcTrueInFrustumnull59                        function CalcTrueInFrustum(frustum:ClipArray;var GeomData:ZGLGeomData;out InRect:TInBoundingVolume):GDBInteger;virtual;
60                    end;
61 PTLLLine=^TLLLine;
62 TLLLine={$IFNDEF DELPHI}packed{$ENDIF} object(TLLPrimitive)
63               P1Index:TLLVertexIndex;{P2Index=P1Index+1}
drawnull64               function draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;virtual;
CalcTrueInFrustumnull65               function CalcTrueInFrustum(frustum:ClipArray;var GeomData:ZGLGeomData;out InRect:TInBoundingVolume):GDBInteger;virtual;
66               procedure getEntIndexs(var GeomData:ZGLGeomData;out eid:TEntIndexesData);virtual;
67               procedure CorrectIndexes(const offset:TEntIndexesOffsetData);virtual;
68         end;
69 PTLLTriangle=^TLLTriangle;
70 TLLTriangle={$IFNDEF DELPHI}packed{$ENDIF} object(TLLPrimitive)
71               P1Index:TLLVertexIndex;
drawnull72               function draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;virtual;
73               procedure getEntIndexs(var GeomData:ZGLGeomData;out eid:TEntIndexesData);virtual;
74               procedure CorrectIndexes(const offset:TEntIndexesOffsetData);virtual;
75         end;
76 PTLLFreeTriangle=^TLLFreeTriangle;
77 TLLFreeTriangle={$IFNDEF DELPHI}packed{$ENDIF} object(TLLPrimitive)
78               P1IndexInIndexesArray:TLLVertexIndex;
drawnull79               function draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;virtual;
80               procedure getEntIndexs(var GeomData:ZGLGeomData;out eid:TEntIndexesData);virtual;
81               procedure CorrectIndexes(const offset:TEntIndexesOffsetData);virtual;
82         end;
83 PTLLTriangleStrip=^TLLTriangleStrip;
84 TLLTriangleStrip={$IFNDEF DELPHI}packed{$ENDIF} object(TLLPrimitive)
85               P1IndexInIndexesArray:TLLVertexIndex;
86               IndexInIndexesArraySize:TLLVertexIndex;
drawnull87               function draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;virtual;
88               procedure getEntIndexs(var GeomData:ZGLGeomData;out eid:TEntIndexesData);virtual;
89               procedure CorrectIndexes(const offset:TEntIndexesOffsetData);virtual;
90               procedure AddIndex(Index:TLLVertexIndex);virtual;
91               constructor init;
92         end;
93 PTLLTriangleFan=^TLLTriangleFan;
94 TLLTriangleFan={$IFNDEF DELPHI}packed{$ENDIF} object(TLLTriangleStrip)
drawnull95               function draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;virtual;
96         end;
97 PTLLPoint=^TLLPoint;
98 TLLPoint={$IFNDEF DELPHI}packed{$ENDIF} object(TLLPrimitive)
99               PIndex:TLLVertexIndex;
drawnull100               function draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;virtual;
101               procedure getEntIndexs(var GeomData:ZGLGeomData;out eid:TEntIndexesData);virtual;
102               procedure CorrectIndexes(const offset:TEntIndexesOffsetData);virtual;
103         end;
104 PTSymbolSParam=^TSymbolSParam;
105 TSymbolSParam=packed record
106                    FirstSymMatr:DMatrix4D;
107                    sx,Rotate,Oblique,NeededFontHeight{,offsety}:GDBFloat;
108                    pfont:pointer;
109                    IsCanSystemDraw:GDBBoolean;
110              end;
111 PTLLSymbol=^TLLSymbol;
112 TLLSymbol={$IFNDEF DELPHI}packed{$ENDIF} object(TLLPrimitive)
113               SymSize:GDBInteger;
114               LineIndex:TArrayIndex;
115               Attrib:TLLPrimitiveAttrib;
116               OutBoundIndex:TLLVertexIndex;
117               PExternalVectorObject:pointer;
118               ExternalLLPOffset:TArrayIndex;
119               ExternalLLPCount:TArrayIndex;
120               SymMatr:DMatrix4F;
121               SymCode:Integer;//unicode symbol code
drawnull122               function draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;virtual;
123               procedure drawSymbol(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData;const PSymbolsParam:PTSymbolSParam);virtual;
124               constructor init;
CalcTrueInFrustumnull125               function CalcTrueInFrustum(frustum:ClipArray;var GeomData:ZGLGeomData;out InRect:TInBoundingVolume):GDBInteger;virtual;
126         end;
127 PTLLSymbolLine=^TLLSymbolLine;
128 TLLSymbolLine={$IFNDEF DELPHI}packed{$ENDIF} object(TLLPrimitive)
129               SimplyDrawed:GDBBoolean;
130               MaxSqrSymH:GDBFloat;
131               SymbolsParam:TSymbolSParam;
132               FirstOutBoundIndex,LastOutBoundIndex:TLLVertexIndex;
drawnull133               function draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;virtual;
134               constructor init;
135         end;
136 PTLLSymbolEnd=^TLLSymbolEnd;
137 TLLSymbolEnd={$IFNDEF DELPHI}packed{$ENDIF} object(TLLPrimitive)
drawnull138               function draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;virtual;
139                    end;
140 PTLLPolyLine=^TLLPolyLine;
141 TLLPolyLine={$IFNDEF DELPHI}packed{$ENDIF} object(TLLPrimitive)
142               P1Index,Count,SimplifiedContourIndex,SimplifiedContourSize:TLLVertexIndex;
143               Closed:GDBBoolean;
drawnull144               function draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;virtual;
CalcTrueInFrustumnull145               function CalcTrueInFrustum(frustum:ClipArray;var GeomData:ZGLGeomData;out InRect:TInBoundingVolume):GDBInteger;virtual;
146               procedure getEntIndexs(var GeomData:ZGLGeomData;out eid:TEntIndexesData);virtual;
147               procedure AddSimplifiedIndex(Index:TLLVertexIndex);virtual;
148               procedure CorrectIndexes(const offset:TEntIndexesOffsetData);virtual;
149               constructor init;
150         end;
151 {Export-}
152 implementation
153 uses {log,}uzglvectorobject;
getPrimitiveSizenull154 function TLLPrimitive.getPrimitiveSize:GDBInteger;
155 begin
156      result:=sizeof(self);
157 end;
158 constructor TLLPrimitive.init;
159 begin
160 end;
161 destructor TLLPrimitive.done;
162 begin
163 end;
164 procedure TLLPrimitive.getEntIndexs(var GeomData:ZGLGeomData;out eid:TEntIndexesData);
165 begin
166      eid.GeomIndexMin:=-1;
167      eid.GeomIndexMax:=-1;
168      eid.IndexsIndexMax:=-1;
169      eid.IndexsIndexMax:=-1;
170 end;
171 procedure TLLPrimitive.CorrectIndexes(const offset:TEntIndexesOffsetData);
172 begin
173 end;
drawnull174 function TLLPrimitive.draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;
175 begin
176      result:=getPrimitiveSize;
177 end;
TLLPrimitive.CalcTrueInFrustumnull178 function TLLPrimitive.CalcTrueInFrustum(frustum:ClipArray;var GeomData:ZGLGeomData;out InRect:TInBoundingVolume):GDBInteger;
179 begin
180      InRect:=IREmpty;
181      result:=getPrimitiveSize;
182 end;
drawnull183 function TLLLine.draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;
184 begin
185      if not OptData.ignorelines then
186                                     Drawer.DrawLine(@geomdata.Vertex3S,P1Index,P1Index+1);
187      result:=inherited;
188 end;
TLLLine.CalcTrueInFrustumnull189 function TLLLine.CalcTrueInFrustum(frustum:ClipArray;var GeomData:ZGLGeomData;out InRect:TInBoundingVolume):GDBInteger;
190 begin
191      InRect:=uzegeometry.CalcTrueInFrustum(PGDBvertex3S(geomdata.Vertex3S.getDataMutable(self.P1Index))^,PGDBvertex3S(geomdata.Vertex3S.getDataMutable(self.P1Index+1))^,frustum);
192      result:=getPrimitiveSize;
193 end;
194 procedure TLLLine.getEntIndexs(var GeomData:ZGLGeomData;out eid:TEntIndexesData);
195 begin
196      eid.GeomIndexMin:=P1Index;
197      eid.GeomIndexMax:=P1Index+1;
198      eid.IndexsIndexMax:=-1;
199      eid.IndexsIndexMin:=-1;
200 end;
201 procedure TLLLine.CorrectIndexes(const offset:TEntIndexesOffsetData);
202 begin
203      P1Index:=P1Index+offset.GeomIndexOffset;
204 end;
TLLPoint.drawnull205 function TLLPoint.draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;
206 begin
207      Drawer.DrawPoint(@geomdata.Vertex3S,PIndex);
208      result:=inherited;
209 end;
210 procedure TLLPoint.getEntIndexs(var GeomData:ZGLGeomData;out eid:TEntIndexesData);
211 begin
212      eid.GeomIndexMin:=PIndex;
213      eid.GeomIndexMax:=PIndex;
214      eid.IndexsIndexMax:=-1;
215      eid.IndexsIndexMin:=-1
216 end;
217 procedure TLLPoint.CorrectIndexes(const offset:TEntIndexesOffsetData);
218 begin
219      PIndex:=PIndex+offset.GeomIndexOffset;
220 end;
TLLTriangle.drawnull221 function TLLTriangle.draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;
222 begin
223      if not OptData.ignoretriangles then
224                                         Drawer.DrawTriangle(@geomdata.Vertex3S,P1Index,P1Index+1,P1Index+2);
225      result:=inherited;
226 end;
227 procedure TLLTriangle.getEntIndexs(var GeomData:ZGLGeomData;out eid:TEntIndexesData);
228 begin
229      eid.GeomIndexMin:=P1Index;
230      eid.GeomIndexMax:=P1Index+2;
231      eid.IndexsIndexMax:=-1;
232      eid.IndexsIndexMin:=-1
233 end;
234 procedure TLLTriangle.CorrectIndexes(const offset:TEntIndexesOffsetData);
235 begin
236      P1Index:=P1Index+offset.GeomIndexOffset;
237 end;
drawnull238 function TLLFreeTriangle.draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;
239 var
240    P1Index,P2Index,P3Index:pinteger;
241 begin
242      if not OptData.ignoretriangles then
243                                         begin
244                                              P1Index:=GeomData.Indexes.getDataMutable(P1IndexInIndexesArray);
245                                              P2Index:=GeomData.Indexes.getDataMutable(P1IndexInIndexesArray+1);
246                                              P3Index:=GeomData.Indexes.getDataMutable(P1IndexInIndexesArray+2);
247                                              Drawer.DrawTriangle(@geomdata.Vertex3S,P1Index^,P2Index^,P3Index^);
248                                         end;
249      result:=inherited;
250 end;
251 procedure TLLFreeTriangle.getEntIndexs(var GeomData:ZGLGeomData;out eid:TEntIndexesData);
252 var
253    P1Index,P2Index,P3Index:pinteger;
254 begin
255      P1Index:=GeomData.Indexes.getDataMutable(P1IndexInIndexesArray);
256      P2Index:=GeomData.Indexes.getDataMutable(P1IndexInIndexesArray+1);
257      P3Index:=GeomData.Indexes.getDataMutable(P1IndexInIndexesArray+2);
258      eid.GeomIndexMin:=min(min(P1Index^,P2Index^),P3Index^);
259      eid.GeomIndexMax:=max(max(P1Index^,P2Index^),P3Index^);
260      eid.IndexsIndexMin:=P1IndexInIndexesArray;
261      eid.IndexsIndexMax:=P1IndexInIndexesArray+2;
262 end;
263 procedure TLLFreeTriangle.CorrectIndexes(const offset:TEntIndexesOffsetData);
264 begin
265      P1IndexInIndexesArray:=P1IndexInIndexesArray+offset.IndexsIndexOffset;
266 end;
drawnull267 function TLLTriangleFan.draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;
268 begin
269      if not OptData.ignoretriangles then
270                                         Drawer.DrawTrianglesFan(@geomdata.Vertex3S,@geomdata.Indexes,P1IndexInIndexesArray,IndexInIndexesArraySize);
271      result:=getPrimitiveSize;
272 end;
273 
drawnull274 function TLLTriangleStrip.draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;
275 begin
276      if not OptData.ignoretriangles then
277                                         Drawer.DrawTrianglesStrip(@geomdata.Vertex3S,@geomdata.Indexes,P1IndexInIndexesArray,IndexInIndexesArraySize);
278      result:=getPrimitiveSize;
279 end;
280 procedure TLLTriangleStrip.getEntIndexs(var GeomData:ZGLGeomData;out eid:TEntIndexesData);
281 var
282    PIndex:pinteger;
283    index:TLLVertexIndex;
284    i:integer;
285 begin
286      if P1IndexInIndexesArray<>-1 then
287      begin
288        index:=P1IndexInIndexesArray;
289        PIndex:=GeomData.Indexes.getDataMutable(index);
290        eid.GeomIndexMin:=PIndex^;
291        eid.GeomIndexMax:=PIndex^;
292        inc(index);
293        for i:=2 to IndexInIndexesArraySize do
294        begin
295          PIndex:=GeomData.Indexes.getDataMutable(index);
296          eid.GeomIndexMin:=min(eid.GeomIndexMin,PIndex^);
297          eid.GeomIndexMax:=max(eid.GeomIndexMax,PIndex^);
298          inc(index);
299        end;
300        eid.IndexsIndexMin:=P1IndexInIndexesArray;
301        eid.IndexsIndexMax:=P1IndexInIndexesArray+IndexInIndexesArraySize-1;
302      end
303      else
304      begin
305        eid.GeomIndexMin:=-1;
306        eid.GeomIndexMax:=-1;
307        eid.IndexsIndexMin:=-1;
308        eid.IndexsIndexMax:=-1;
309      end;
310 end;
311 procedure TLLTriangleStrip.CorrectIndexes(const offset:TEntIndexesOffsetData);
312 begin
313      P1IndexInIndexesArray:=P1IndexInIndexesArray+offset.IndexsIndexOffset;
314 end;
315 procedure TLLTriangleStrip.AddIndex(Index:TLLVertexIndex);
316 begin
317      if P1IndexInIndexesArray=-1 then
318                                      P1IndexInIndexesArray:=Index;
319      inc(IndexInIndexesArraySize);
320 end;
321 constructor TLLTriangleStrip.init;
322 begin
323      P1IndexInIndexesArray:=-1;
324      IndexInIndexesArraySize:=0;
325 end;
326 
327 procedure TLLPolyLine.AddSimplifiedIndex(Index:TLLVertexIndex);
328 begin
329      if SimplifiedContourIndex=-1 then
330                                       SimplifiedContourIndex:=Index;
331      inc(SimplifiedContourSize);
332 end;
333 constructor TLLPolyLine.init;
334 begin
335      P1Index:=-1;
336      Count:=0;
337      SimplifiedContourIndex:=-1;
338      SimplifiedContourSize:=0;
339      Closed:=false;
340 end;
341 
TLLPolyLine.drawnull342 function TLLPolyLine.draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;
343 var
344    i,index,oldindex,sindex:integer;
345 begin
346   if not OptData.ignorelines then
347   begin
348     if (OptData.symplify)and(SimplifiedContourIndex<>-1) then
349     begin
350       sindex:=SimplifiedContourIndex;
351       if sindex<0 then sindex:=0;
352       oldindex:=PTArrayIndex(GeomData.Indexes.getDataMutable(sindex))^;
353       inc(sindex);
354       for i:=1 to SimplifiedContourSize-1 do
355       begin
356          index:=PTArrayIndex(GeomData.Indexes.getDataMutable(sindex))^;
357          Drawer.DrawLine(@geomdata.Vertex3S,oldindex,index);
358          oldindex:=index;
359          inc(sindex);
360       end;
361     end
362     else
363     begin
364        index:=P1Index+1;
365        oldindex:=P1Index;
366          for i:=1 to Count-1 do
367          begin
368             Drawer.DrawLine(@geomdata.Vertex3S,oldindex,index);
369             oldindex:=index;
370             inc(index);
371          end;
372     end;
373   if closed then
374                        Drawer.DrawLine(@geomdata.Vertex3S,oldindex,P1Index);
375   end;
376   result:=inherited;
377 end;
378 procedure TLLPolyLine.getEntIndexs(var GeomData:ZGLGeomData;out eid:TEntIndexesData);
379 begin
380      eid.GeomIndexMin:=P1Index;
381      eid.GeomIndexMax:=P1Index+Count-1;
382      if self.SimplifiedContourIndex=-1 then
383      begin
384      eid.IndexsIndexMin:=-1;
385      eid.IndexsIndexMax:=-1;
386      end
387      else
388      begin
389      eid.IndexsIndexMin:=SimplifiedContourIndex;
390      eid.IndexsIndexMax:=SimplifiedContourIndex+SimplifiedContourSize-1;
391      end
392 
393 end;
394 procedure TLLPolyLine.CorrectIndexes(const offset:TEntIndexesOffsetData);
395 begin
396      P1Index:=P1Index+offset.GeomIndexOffset;
397      SimplifiedContourIndex:=SimplifiedContourIndex+offset.IndexsIndexOffset;
398 end;
TLLPolyLine.CalcTrueInFrustumnull399 function TLLPolyLine.CalcTrueInFrustum(frustum:ClipArray;var GeomData:ZGLGeomData;out InRect:TInBoundingVolume):GDBInteger;
400 var
401    i,index:integer;
402    SubRect:TInBoundingVolume;
403 begin
404      InRect:=uzegeometry.CalcTrueInFrustum(PGDBvertex3S(geomdata.Vertex3S.getDataMutable(P1Index))^,PGDBvertex3S(geomdata.Vertex3S.getDataMutable(P1Index+1))^,frustum);
405      result:=getPrimitiveSize;
406      if InRect=IRPartially then
407                                exit;
408      index:=P1Index+1;
409      for i:=2 to Count-1 do
410      begin
411         SubRect:=uzegeometry.CalcTrueInFrustum(PGDBvertex3S(geomdata.Vertex3S.getDataMutable(index))^,PGDBvertex3S(geomdata.Vertex3S.getDataMutable(index+1))^,frustum);
412         case SubRect of
413           IREmpty:if InRect=IRFully then
414                                          InRect:=IRPartially;
415           IRFully:if InRect<>IRFully then
416                                          InRect:=IRPartially;
417           IRPartially:
418                       InRect:=IRPartially;
419         end;
420         if InRect=IRPartially then
421                                   exit;
422         inc(index);
423      end;
424 end;
TLLSymbolEnd.drawnull425 function TLLSymbolEnd.draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;
426 begin
427      OptData.ignoretriangles:=false;
428      OptData.ignorelines:=false;
429      OptData.symplify:=false;
430      result:=inherited;
431 end;
432 constructor TLLSymbolLine.init;
433 begin
434      MaxSqrSymH:=0;
435      inherited;
436 end;
437 
drawnull438 function TLLSymbolLine.draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;
439 begin
440   if (MaxSqrSymH/(rc.DrawingContext.zoom*rc.DrawingContext.zoom)<3)and(not rc.maxdetail) then
441                                                 begin
442                                                   Drawer.DrawLine(@geomdata.Vertex3S,FirstOutBoundIndex,LastOutBoundIndex+3);
443                                                   //Drawer.DrawLine(FirstOutBoundIndex+1,LastOutBoundIndex+2);
444                                                   {Drawer.DrawQuad(FirstOutBoundIndex,FirstOutBoundIndex+1,LastOutBoundIndex+2,LastOutBoundIndex+3);
445                                                   Drawer.DrawLine(FirstOutBoundIndex,FirstOutBoundIndex+1);
446                                                   Drawer.DrawLine(FirstOutBoundIndex+1,LastOutBoundIndex+2);
447                                                   Drawer.DrawLine(FirstOutBoundIndex+2,LastOutBoundIndex+3);
448                                                   Drawer.DrawLine(FirstOutBoundIndex+3,FirstOutBoundIndex);}
449                                                   self.SimplyDrawed:=true;
450                                                 end
451                                             else
452                                                 self.SimplyDrawed:=false;
453   result:=inherited;
454 end;
455 constructor TLLSymbol.init;
456 begin
457   SymSize:=-1;
458   LineIndex:=-1;
459   Attrib:=0;
460   OutBoundIndex:=-1;
461   PExternalVectorObject:=nil;
462   ExternalLLPOffset:=-1;
463   ExternalLLPCount:=-1;
464 end;
TLLSymbol.CalcTrueInFrustumnull465 function TLLSymbol.CalcTrueInFrustum(frustum:ClipArray;var GeomData:ZGLGeomData;out InRect:TInBoundingVolume):GDBInteger;
466 var
467    //ir1,ir2,ir3,ir4:TInBoundingVolume;
468    myfrustum:ClipArray;
469    OutBound:OutBound4V;
470    p:PGDBvertex3S;
471 begin
472      p:=geomdata.Vertex3S.getDataMutable(OutBoundIndex);
473      OutBound[0].x:=p^.x;
474      OutBound[0].y:=p^.y;
475      OutBound[0].z:=p^.z;
476      p:=geomdata.Vertex3S.getDataMutable(OutBoundIndex+1);
477      OutBound[1].x:=p^.x;
478      OutBound[1].y:=p^.y;
479      OutBound[1].z:=p^.z;
480      p:=geomdata.Vertex3S.getDataMutable(OutBoundIndex+2);
481      OutBound[2].x:=p^.x;
482      OutBound[2].y:=p^.y;
483      OutBound[2].z:=p^.z;
484      p:=geomdata.Vertex3S.getDataMutable(OutBoundIndex+3);
485      OutBound[3].x:=p^.x;
486      OutBound[3].y:=p^.y;
487      OutBound[3].z:=p^.z;
488 
489      InRect:=CalcOutBound4VInFrustum(OutBound,frustum);
490 
491      result:=getPrimitiveSize;
492 
493      if InRect<>IRPartially then
494                                 exit;
495 
496      myfrustum:=FrustumTransform(frustum,SymMatr);
497      InRect:=PZGLVectorObject(PExternalVectorObject).CalcCountedTrueInFrustum(myfrustum,true,ExternalLLPOffset,ExternalLLPCount);
498 end;
499 
TLLSymbol.drawnull500 function TLLSymbol.draw(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData):GDBInteger;
501 {TODO: this need rewrite}
502 var
503    {i,}index,minsymbolsize:integer;
504    sqrparamsize:gdbdouble;
505    PLLSymbolLine:PTLLSymbolLine;
506    PSymbolsParam:PTSymbolSParam;
507 begin
508   result:=0;
509   if self.LineIndex<>-1 then
510   begin
511     PLLSymbolLine:=pointer(LLPArray.getDataMutable(self.LineIndex));
512     PSymbolsParam:=@PLLSymbolLine^.SymbolsParam;
513   if PLLSymbolLine^.SimplyDrawed then
514                                                                            begin
515                                                                              result:=SymSize;
516                                                                              exit;
517                                                                            end;
518   end
519   else
520   begin
521     PLLSymbolLine:=nil;
522     PSymbolsParam:=nil;
523   end;
524 
525   index:=OutBoundIndex;
526   result:=inherited;
527   if not drawer.CheckOutboundInDisplay(@geomdata.Vertex3S,index) then
528                                                   begin
529                                                     result:=SymSize;
530                                                   end
531 
532 else if (Attrib and LLAttrNeedSimtlify)>0 then
533   begin
534     if (Attrib and LLAttrNeedSolid)>0 then
535                                                                   begin
536                                                                    minsymbolsize:=30;
537                                                                    OptData.ignorelines:=true;
538                                                                   end
539                                                               else
540                                                                   minsymbolsize:=30;
541     sqrparamsize:=GeomData.Vertex3S.GetLength(index)/(rc.DrawingContext.zoom*rc.DrawingContext.zoom);
542     if (sqrparamsize<minsymbolsize)and(not rc.maxdetail) then
543     begin
544       //if (PTLLSymbol(PPrimitive)^.Attrib and LLAttrNeedSolid)>0 then
545                                                                     Drawer.DrawQuad(@GeomData.Vertex3S,index,index+1,index+2,index+3);
546                                                                 {else
547                                                                     for i:=1 to 3 do
548                                                                     begin
549                                                                        Drawer.DrawLine(index);
550                                                                        inc(index);
551                                                                     end;}
552       result:=SymSize;
553       exit;
554     end
555     else
556    {if (sqrparamsize<(300))and(not rc.maxdetail) then
557    begin
558      OptData.ignoretriangles:=true;
559      OptData.ignorelines:=false;
560      if (Attrib and LLAttrNeedSolid)>0 then
561                                            OptData.symplify:=true;
562    end
563      else}
564     if (sqrparamsize<{(minsymbolsize+1000)}400)and(not rc.maxdetail) then
565     begin
566       OptData.ignoretriangles:=true;
567       OptData.ignorelines:=false;
568       if (Attrib and LLAttrNeedSolid)>0 then
569                                            OptData.symplify:=true;
570     end;
571     //if result<>SymSize then
572     begin
573       result:=SymSize;
574       drawSymbol(drawer,rc,GeomData,LLPArray,OptData,PSymbolSParam);
575     end;
576   end
577    else
578      begin
579        drawSymbol(drawer,rc,GeomData,LLPArray,OptData,PSymbolSParam);
580      end;
581 
582 end;
583 
584 procedure TLLSymbol.drawSymbol(drawer:TZGLAbstractDrawer;var rc:TDrawContext;var GeomData:ZGLGeomData;var LLPArray:TLLPrimitivesArray;var OptData:ZGLOptimizerData;const PSymbolsParam:PTSymbolSParam);
585 begin
586      drawer.pushMatrixAndSetTransform(SymMatr);
587      PZGLVectorObject(PExternalVectorObject).DrawCountedLLPrimitives(rc,drawer,OptData,ExternalLLPOffset,ExternalLLPCount);
588      drawer.popMatrix;
589 end;
590 
591 begin
592 end.
593 
594