CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
SiShapeRay.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24#ifndef _SiShapeRay_h_Included_
25#define _SiShapeRay_h_Included_
26
27#include "Ge/GeExtents3d.h"
28#include "Ge/GeBoundBlock3d.h"
29#include "Ge/GeRay3d.h"
30#include "Si/SiSpatialIndex.h"
31
32#include "TD_PackPush.h"
33
40struct OdSiShapeRay : public OdSiShape
41{
44
47
54 OdSiShapeRay( const OdGePoint3d& pointStart, const OdGeVector3d& vecDir )
55 {
56 m_pointStart = pointStart;
57 m_vecDir = vecDir;
58 }
59
66 {
67 OdGePoint3d startPt;
68 ray.hasStartPoint(startPt);
69 m_pointStart = startPt;
70
71 m_vecDir = ray.direction();
72 }
73
83 bool contains(const OdGeExtents3d& extents, bool planar, const OdGeTol& tol) const {
84 return false;
85 }
86
96 bool intersects(const OdGeExtents3d& extents, bool planar, const OdGeTol& tol) const
97 {
98 // fast ray box intersection
99 // Graphics Gems, 1990, pp. 395-396
100 const int sz = 3;
101 bool inside = true;
102
103 //-1 - LEFT
104 // 0 - MIDDLE
105 // 1 - RIGHT
106 int quadrant[sz];
107 int whichPlane;
108 double maxT[sz];
109 double candidatePlane[sz];
110
111 OdGeVector3d tolEqPt(tol.equalPoint(), tol.equalPoint(), tol.equalPoint());
112 OdGePoint3d minPt = extents.minPoint() - tolEqPt;
113 OdGePoint3d maxPt = extents.maxPoint() + tolEqPt;
114
115 for (int i = 0; i != sz; i++)
116 {
117 if (m_pointStart[i] < minPt[i])
118 {
119 quadrant[i] = -1;
120 candidatePlane[i] = minPt[i];
121 inside = false;
122 }
123 else if (m_pointStart[i] > maxPt[i])
124 {
125 quadrant[i] = 1;
126 candidatePlane[i] = maxPt[i];
127 inside = false;
128 }
129 else
130 {
131 quadrant[i] = 0;
132 }
133 }
134
135 OdGePoint3d coord;
136 if (inside)
137 {
138 coord = m_pointStart;
139 return true;
140 }
141
142 for (int i = 0; i != sz; i++)
143 {
144 if (quadrant[i] != 0 && m_vecDir[i] != 0.)
145 maxT[i] = (candidatePlane[i] - m_pointStart[i]) / m_vecDir[i];
146 else
147 maxT[i] = -1.;
148 }
149
150 whichPlane = 0;
151 for (int i = 1; i != sz; i++)
152 {
153 if (maxT[whichPlane] < maxT[i])
154 whichPlane = i;
155 }
156
157 if (maxT[whichPlane] < 0.)
158 {
159 return false;
160 }
161
162 for (int i = 0; i != sz; i++)
163 {
164 if (whichPlane != i)
165 {
166 coord[i] = m_pointStart[i] + maxT[whichPlane] * m_vecDir[i];
167 if (coord[i] < minPt[i] || coord[i] > maxPt[i])
168 {
169 return false;
170 }
171 }
172 else
173 {
174 coord[i] = candidatePlane[i];
175 }
176 }
177 return true;
178 }
179
185 virtual OdSiShape* clone() const { return new OdSiShapeRay(m_pointStart, m_vecDir); }
186
192 virtual void transform(const OdGeMatrix3d& tf)
193 {
196 }
197};
198
199#include "TD_PackPop.h"
200
201#endif
tol
Definition: DimVarDefs.h:2287
bool hasStartPoint(OdGePoint3d &startPoint) const
const OdGePoint3d & maxPoint() const
Definition: GeExtents3d.h:443
const OdGePoint3d & minPoint() const
Definition: GeExtents3d.h:438
OdGeVector3d direction() const
OdGePoint3d & transformBy(const OdGeMatrix3d &xfm)
Definition: GeTol.h:49
OdGeVector3d & transformBy(const OdGeMatrix3d &xfm)
OdSiShapeRay(const OdGePoint3d &pointStart, const OdGeVector3d &vecDir)
Definition: SiShapeRay.h:54
virtual void transform(const OdGeMatrix3d &tf)
Definition: SiShapeRay.h:192
bool contains(const OdGeExtents3d &extents, bool planar, const OdGeTol &tol) const
Definition: SiShapeRay.h:83
virtual OdSiShape * clone() const
Definition: SiShapeRay.h:185
OdGeVector3d m_vecDir
Definition: SiShapeRay.h:46
OdSiShapeRay(const OdGeRay3d &ray)
Definition: SiShapeRay.h:65
OdGePoint3d m_pointStart
Definition: SiShapeRay.h:43
bool intersects(const OdGeExtents3d &extents, bool planar, const OdGeTol &tol) const
Definition: SiShapeRay.h:96