zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
/////////////////////////////////////////////////////////////////////////////// 
// Copyright (C) 2002-2016, Open Design Alliance (the "Alliance"). 
// All rights reserved. 
// 
// This software and its documentation and related materials are owned by 
// the Alliance. The software may only be incorporated into application 
// programs owned by members of the Alliance, subject to a signed 
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable  
// trade secrets of the Alliance and its suppliers. The software is also 
// protected by copyright law and international treaty provisions. Application  
// programs incorporating this software must include the following statement 
// with their copyright notices:
//   
//   This application incorporates Teigha(R) software pursuant to a license 
//   agreement with Open Design Alliance.
//   Teigha(R) Copyright (C) 2002-2016 by Open Design Alliance. 
//   All rights reserved.
//
// By use of this software, its documentation or related materials, you 
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
 
#ifndef _ODGSCULLINGVOLUME_H_INCLUDED_
#define _ODGSCULLINGVOLUME_H_INCLUDED_
 
#include "OdaCommon.h"
#include "RxObject.h"
#include "Gs/GsExport.h"
#include "Ge/GeBoundBlock3d.h"
#include "Ge/GeExtents3d.h"
#include "Ge/GePoint3d.h"
#include "Ge/GeSphere.h"
#include "Ge/GeVector3d.h"
 
#include "TD_PackPush.h"
 
// Culling primitives:
// BBox (AABB - Axis Aligned Bounding Box)
// BSphere (Bounding Sphere)
// OBBox (OBB - Oriented Bounding Box)
 
/** \details
    Base class for culling primitives.
 
    Library: TD_Gs
 
    <group OdGs_Classes> 
*/
class GS_TOOLKIT_EXPORT OdGsCullingPrimitive
{
  public:
    /** \details
      Type of culling primitive.
 
      \remarks
      <table>
      Name               Value    Description
      kPrimBBox          0        Axis Alligned Bounding Box.
      kPrimBSphere       1        Bounding Sphere.
      kPrimOBBox         2        Oriented Bounding Box.
      </table>
    */
    enum PrimitiveType
    {
      kPrimBBox,
      kPrimBSphere,
      kPrimOBBox
    };
  public:
    OdGsCullingPrimitive()
    {
    }
 
    virtual ~OdGsCullingPrimitive()
    {
    }
 
    /** \details
      Returns culling primitive type.
      
      \remarks
      <table>
      Name               Value    Description
      kPrimBBox          0        Axis Alligned Bounding Box.
      kPrimBSphere       1        Bounding Sphere.
      kPrimOBBox         2        Oriented Bounding Box.
      </table>
    */
    virtual PrimitiveType primitiveType() const = 0;
};
 
/** \details
    Culling primitive: axis alligned bounding box.
 
    Library: TD_Gs
 
    <group OdGs_Classes> 
*/
class GS_TOOLKIT_EXPORT OdGsCullingBBox : public OdGsCullingPrimitive, public OdGeExtents3d
{
  public:
    OdGsCullingBBox()
      : OdGsCullingPrimitive()
      , OdGeExtents3d()
    {
    }
 
    OdGsCullingBBox(const OdGePoint3d &min, const OdGePoint3d &max)
      : OdGsCullingPrimitive()
      , OdGeExtents3d(min, max)
    {
    }
 
    OdGsCullingBBox(const OdGeExtents3d &ext)
      : OdGsCullingPrimitive()
      , OdGeExtents3d(ext.minPoint(), ext.maxPoint())
    {
    }
 
    OdGsCullingBBox(const OdGsCullingBBox &aabb)
      : OdGsCullingPrimitive()
      , OdGeExtents3d(aabb.minPoint(), aabb.maxPoint())
    {
    }
 
    ~OdGsCullingBBox()
    {
    }
 
    OdGsCullingBBox &operator =(const OdGeExtents3d &ext)
    {
      set(ext.minPoint(), ext.maxPoint());
      return *this;
    }
 
    OdGsCullingBBox &operator =(const OdGsCullingBBox &aabb)
    {
      set(aabb.minPoint(), aabb.maxPoint());
      return *this;
    }
 
    // OdGsCullingPrimitive overrides
 
    /** \details
      Returns culling primitive type.
    */
    PrimitiveType primitiveType() const
    {
      return kPrimBBox;
    }
};
 
/** \details
    Culling primitive: bounding sphere.
 
    Library: TD_Gs
 
    <group OdGs_Classes> 
*/
class GS_TOOLKIT_EXPORT OdGsCullingBSphere : public OdGsCullingPrimitive, public OdGeSphere // GeSphere has many unnecessary data for culling
{
  public:
    OdGsCullingBSphere()
      : OdGsCullingPrimitive()
      , OdGeSphere()
    {
    }
 
    OdGsCullingBSphere(double radius, const OdGePoint3d &center)
      : OdGsCullingPrimitive()
      , OdGeSphere(radius, center)
    {
    }
 
    OdGsCullingBSphere(const OdGeSphere &sphere)
      : OdGsCullingPrimitive()
      , OdGeSphere(sphere)
    {
    }
 
    OdGsCullingBSphere(const OdGsCullingBSphere &bsphere)
      : OdGsCullingPrimitive()
      , OdGeSphere(bsphere)
    {
    }
 
    ~OdGsCullingBSphere()
    {
    }
 
    OdGsCullingBSphere &operator =(const OdGeSphere &sphere)
    {
      set(sphere.radius(), sphere.center());
      return *this;
    }
 
    OdGsCullingBSphere &operator =(const OdGsCullingBSphere &bsphere)
    {
      set(bsphere.radius(), bsphere.center());
      return *this;
    }
 
    // OdGsCullingPrimitive overrides
 
    /** \details
      Returns culling volume type.
    */
    PrimitiveType primitiveType() const
    {
      return kPrimBSphere;
    }
};
 
/** \details
    Culling primitive: oriented bounding box.
 
    Library: TD_Gs
 
    <group OdGs_Classes> 
*/
class GS_TOOLKIT_EXPORT OdGsCullingOBBox : public OdGsCullingPrimitive, public OdGeBoundBlock3d
{
  public:
    OdGsCullingOBBox()
      : OdGsCullingPrimitive()
      , OdGeBoundBlock3d()
    {
    }
 
    OdGsCullingOBBox(const OdGePoint3d &base, const OdGeVector3d &xAxis, const OdGeVector3d &yAxis, const OdGeVector3d &zAxis)
      : OdGsCullingPrimitive()
      , OdGeBoundBlock3d(base, xAxis, yAxis, zAxis)
    {
    }
 
    OdGsCullingOBBox(const OdGeBoundBlock3d &bb)
      : OdGsCullingPrimitive()
      , OdGeBoundBlock3d(bb)
    {
    }
 
    OdGsCullingOBBox(const OdGsCullingOBBox &obb)
      : OdGsCullingPrimitive()
      , OdGeBoundBlock3d(obb)
    {
    }
 
    ~OdGsCullingOBBox()
    {
    }
 
    OdGsCullingOBBox &operator =(const OdGeBoundBlock3d &bb)
    {
      OdGePoint3d base; OdGeVector3d side1, side2, side3;
      bb.get(base, side1, side2, side3);
      set(base, side1, side2, side3);
      return *this;
    }
 
    OdGsCullingOBBox &operator =(const OdGsCullingOBBox &obb)
    {
      OdGePoint3d base; OdGeVector3d side1, side2, side3;
      obb.get(base, side1, side2, side3);
      set(base, side1, side2, side3);
      return *this;
    }
 
    // OdGsCullingPrimitive overrides
 
    /** \details
      Returns culling primitive type.
    */
    PrimitiveType primitiveType() const
    {
      return kPrimOBBox;
    }
};
 
// Projection culling primitives:
// Ortho (Orthogonal culling box merged with optimization for 2d mode)
// Frustum (Perspective culling box without near and far culling planes)
 
/** \details
    Base class for orthogonal and perspective culling volumes.
 
    Library: TD_Gs
 
    <group OdGs_Classes> 
*/
class GS_TOOLKIT_EXPORT OdGsCullingVolume : public OdRxObject
{
  public:
    enum ProjectionType
    {
      kProjOrtho,
      kProjPerspective
    };
    enum IntersectionStatus
    {
      kIntersectNot, // No intersection detected
      kIntersectOk, // Intersects with projection boundary
      kIntersectIn // Primitive completely inside projection boundary
    };
  public:
    ODRX_DECLARE_MEMBERS(OdGsCullingVolume);
 
    /** \details
        Returns type of projection for this culling volume object.
 
        \remarks
        <table>
        Name               Value    Description
        kProjOrtho         0        Orthogonal projection.
        kProjPerspective   1        Perspective projection.
        </table>
    */
    virtual ProjectionType projectionType() const = 0;
 
    /** \details
        Optimized intersection test between culling volume and culling primitive.
        \param prim [in]  Input primitive for culling detection.
    */
    virtual bool intersectWithOpt(const OdGsCullingPrimitive &prim) const = 0;
    /** \details
        Intersection test between culling volume and culling primitive (returns complete and incomplete
        intersection statuses).
 
        \remarks
        Return value intersection statuses:
        <table>
        Name               Value    Description
        kIntersectNot      0        No intersection detected.
        kIntersectOk       1        Intersects with culling volume boundary.
        kIntersectIn       2        Culling volume primitive is completely inside culling volume boundary.
        </table>
 
        \param prim [in]  Input primitive for culling detection.
    */
    virtual IntersectionStatus intersectWith(const OdGsCullingPrimitive &prim) const = 0;
 
    /** \details
        Transform culling volume by transformation matrix.
        \param xfm [in]  Xform matrix.
    */
    virtual void transformBy(const OdGeMatrix3d& xfm) = 0;
};
 
/** \details
    This template class is a specialization of the OdSmartPtr class for OdGsCullingVolume object pointers.
*/
typedef OdSmartPtr<OdGsCullingVolume> OdGsCullingVolumePtr;
 
/** \details
    Orthogonal culling volume.
 
    Library: TD_Gs
 
    <group OdGs_Classes> 
*/
class GS_TOOLKIT_EXPORT OdGsOrthoCullingVolume : public OdGsCullingVolume
{
  public:
    ODRX_DECLARE_MEMBERS(OdGsOrthoCullingVolume);
 
    /** \details
        Initialize frustum culling volume by new values.
        \param position [in]  View position.
        \param direction [in]  View direction.
        \param upVector [in]  View up vector.
        \param volumeWidth [in]  Horizontal field of view.
        \param volumeHeight [in]  Vertical field of view.
    */
    virtual void init(const OdGePoint3d &position, const OdGeVector3d &direction, const OdGeVector3d &upVector,
                      double volumeWidth, double volumeHeight) = 0;
};
 
/** \details
    This template class is a specialization of the OdSmartPtr class for OdGsOrthoCullingVolume object pointers.
*/
typedef OdSmartPtr<OdGsOrthoCullingVolume> OdGsOrthoCullingVolumePtr;
 
/** \details
    Perspective culling volume.
 
    Library: TD_Gs
 
    <group OdGs_Classes> 
*/
class GS_TOOLKIT_EXPORT OdGsFrustumCullingVolume : public OdGsCullingVolume
{
  public:
    ODRX_DECLARE_MEMBERS(OdGsFrustumCullingVolume);
 
    /** \details
        Initialize frustum culling volume by new values.
        \param position [in]  View position.
        \param direction [in]  View direction.
        \param upVector [in]  View up vector.
        \param fovY [in]  Horizontal field of view in radians.
        \param aspect [in]  Aspect ratio between horizontal and vertical field of view (aspect = h / v).
        \param nPlanes [in]  Number of culling planes to test intersection (1,2,3,4 - enable only side planes, 5 - enable nearZ plane, 6 - enable farZ plane).
        \param nearZ [in]  Near Z-axis culling plane (must be greater than zero).
        \param farZ [in]  Far Z-axis culling plane.
    */
    virtual void init(const OdGePoint3d &position, const OdGeVector3d &direction, const OdGeVector3d &upVector,
                      double fovY, double aspect, OdUInt32 nPlanes = 4, double nearZ = 1.0, double farZ = 1e20) = 0;
    /** \details
        Initialize frustum culling volume by new values.
        \param position [in]  View position.
        \param direction [in]  View direction.
        \param upVector [in]  View up vector.
        \param fovX [in]  Horizontal field of view in radians.
        \param aspect [in]  If enabled - then fovY is aspect ratio (fovY = h / v), elsewhere fovY is vertical field of view in radians.
        \param fovY [in]  Aspect ratio or vertical field of view in radians (see aspect argument description).
        \param nPlanes [in]  Number of culling planes to test intersection (1,2,3,4 - enable only side planes, 5 - enable nearZ plane, 6 - enable farZ plane).
        \param nearZ [in]  Near Z-axis culling plane (must be greater than zero).
        \param farZ [in]  Far Z-axis culling plane.
    */
    virtual void init(const OdGePoint3d &position, const OdGeVector3d &direction, const OdGeVector3d &upVector,
                      double fovX, bool aspect, double fovY, OdUInt32 nPlanes = 4, double nearZ = 1.0, double farZ = 1e20) = 0;
};
 
/** \details
    This template class is a specialization of the OdSmartPtr class for OdGsFrustumCullingVolume object pointers.
*/
typedef OdSmartPtr<OdGsFrustumCullingVolume> OdGsFrustumCullingVolumePtr;
 
#include "TD_PackPop.h"
 
#endif // _ODGSCULLINGVOLUME_H_INCLUDED_