1 | ///
|
---|
2 | /// This file is part of ILNumerics Community Edition.
|
---|
3 | ///
|
---|
4 | /// ILNumerics Community Edition - high performance computing for applications.
|
---|
5 | /// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
|
---|
6 | ///
|
---|
7 | /// ILNumerics Community Edition is free software: you can redistribute it and/or modify
|
---|
8 | /// it under the terms of the GNU General Public License version 3 as published by
|
---|
9 | /// the Free Software Foundation.
|
---|
10 | ///
|
---|
11 | /// ILNumerics Community Edition is distributed in the hope that it will be useful,
|
---|
12 | /// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | /// GNU General Public License for more details.
|
---|
15 | ///
|
---|
16 | /// You should have received a copy of the GNU General Public License
|
---|
17 | /// along with ILNumerics Community Edition. See the file License.txt in the root
|
---|
18 | /// of your distribution package. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | ///
|
---|
20 | /// In addition this software uses the following components and/or licenses:
|
---|
21 | ///
|
---|
22 | /// =================================================================================
|
---|
23 | /// The Open Toolkit Library License
|
---|
24 | ///
|
---|
25 | /// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
---|
26 | ///
|
---|
27 | /// Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
28 | /// of this software and associated documentation files (the "Software"), to deal
|
---|
29 | /// in the Software without restriction, including without limitation the rights to
|
---|
30 | /// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
---|
31 | /// the Software, and to permit persons to whom the Software is furnished to do
|
---|
32 | /// so, subject to the following conditions:
|
---|
33 | ///
|
---|
34 | /// The above copyright notice and this permission notice shall be included in all
|
---|
35 | /// copies or substantial portions of the Software.
|
---|
36 | ///
|
---|
37 | /// =================================================================================
|
---|
38 | ///
|
---|
39 |
|
---|
40 | using System;
|
---|
41 | using System.Collections.Generic;
|
---|
42 | using System.Text;
|
---|
43 | using ILNumerics.Drawing.Misc;
|
---|
44 |
|
---|
45 | namespace ILNumerics.Drawing {
|
---|
46 | /// <summary>
|
---|
47 | /// Class holding and managing limits for a 3 dimensional cube
|
---|
48 | /// </summary>
|
---|
49 | public sealed class ILClippingData {
|
---|
50 |
|
---|
51 | #region eventing
|
---|
52 | /// <summary>
|
---|
53 | /// fires if the data range have changed
|
---|
54 | /// </summary>
|
---|
55 | public event ILClippingDataChangedEvent Changed;
|
---|
56 | /// <summary>
|
---|
57 | /// called if the limits have changed
|
---|
58 | /// </summary>
|
---|
59 | private void OnChange() {
|
---|
60 | if (m_eventingActive && Changed != null) {
|
---|
61 | Changed ( this, new ClippingChangedEventArgs(this));
|
---|
62 | }
|
---|
63 | m_isDirty = false;
|
---|
64 | }
|
---|
65 | #endregion
|
---|
66 |
|
---|
67 | #region attributes
|
---|
68 | private bool m_eventingActive = true;
|
---|
69 | private float m_xMin = float.MaxValue;
|
---|
70 | private float m_yMin = float.MaxValue;
|
---|
71 | private float m_zMin = float.MaxValue;
|
---|
72 | private float m_xMax = float.MinValue;
|
---|
73 | private float m_yMax = float.MinValue;
|
---|
74 | private float m_zMax = float.MinValue;
|
---|
75 | private float m_sphereRadius;
|
---|
76 | private bool m_isDirty = false;
|
---|
77 | private bool m_allowZeroVolume = true;
|
---|
78 | #endregion
|
---|
79 |
|
---|
80 | #region properties
|
---|
81 |
|
---|
82 | /// <summary>
|
---|
83 | /// the radius of a sphere tightly enclosing the box determined by this clipping data limits (readonly)
|
---|
84 | /// </summary>
|
---|
85 | public float SphereRadius {
|
---|
86 | get {
|
---|
87 | return m_sphereRadius;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | /// <summary>
|
---|
91 | /// minimum value for x axis
|
---|
92 | /// </summary>
|
---|
93 | public float XMin {
|
---|
94 | get {
|
---|
95 | return m_xMin;
|
---|
96 | }
|
---|
97 | set {
|
---|
98 | if (m_xMin != value) {
|
---|
99 | m_isDirty = true;
|
---|
100 | m_xMin = value;
|
---|
101 | if (!m_allowZeroVolume) ensureVolumeNotZero();
|
---|
102 | m_sphereRadius = getSphereRadius();
|
---|
103 | if (m_eventingActive && Changed != null)
|
---|
104 | OnChange();
|
---|
105 | }
|
---|
106 | }
|
---|
107 | }
|
---|
108 | /// <summary>
|
---|
109 | /// minimum value for y axis
|
---|
110 | /// </summary>
|
---|
111 | public float YMin {
|
---|
112 | get {
|
---|
113 | return m_yMin;
|
---|
114 | }
|
---|
115 | set {
|
---|
116 | if (m_yMin != value) {
|
---|
117 | m_isDirty = true;
|
---|
118 | m_yMin = value;
|
---|
119 | if (!m_allowZeroVolume) ensureVolumeNotZero();
|
---|
120 | m_sphereRadius = getSphereRadius();
|
---|
121 | if (m_eventingActive && Changed != null)
|
---|
122 | OnChange();
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|
126 | /// <summary>
|
---|
127 | /// minimum value for z axis
|
---|
128 | /// </summary>
|
---|
129 | public float ZMin {
|
---|
130 | get {
|
---|
131 | return m_zMin;
|
---|
132 | }
|
---|
133 | set {
|
---|
134 | if (m_zMin != value) {
|
---|
135 | m_isDirty = true;
|
---|
136 | m_zMin = value;
|
---|
137 | if (!m_allowZeroVolume) ensureVolumeNotZero();
|
---|
138 | m_sphereRadius = getSphereRadius();
|
---|
139 | if (m_eventingActive && Changed != null)
|
---|
140 | OnChange();
|
---|
141 | }
|
---|
142 | }
|
---|
143 | }
|
---|
144 | /// <summary>
|
---|
145 | /// maximum value for x axis
|
---|
146 | /// </summary>
|
---|
147 | public float XMax {
|
---|
148 | get {
|
---|
149 | return m_xMax;
|
---|
150 | }
|
---|
151 | set {
|
---|
152 | if (m_xMax != value) {
|
---|
153 | m_isDirty = true;
|
---|
154 | m_xMax = value;
|
---|
155 | if (!m_allowZeroVolume) ensureVolumeNotZero();
|
---|
156 | m_sphereRadius = getSphereRadius();
|
---|
157 | if (m_eventingActive && Changed != null)
|
---|
158 | OnChange();
|
---|
159 | }
|
---|
160 | }
|
---|
161 | }
|
---|
162 | /// <summary>
|
---|
163 | /// maximum value for y axis
|
---|
164 | /// </summary>
|
---|
165 | public float YMax {
|
---|
166 | get {
|
---|
167 | return m_yMax;
|
---|
168 | }
|
---|
169 | set {
|
---|
170 | if (m_yMax != value) {
|
---|
171 | m_isDirty = true;
|
---|
172 | m_yMax = value;
|
---|
173 | if (!m_allowZeroVolume) ensureVolumeNotZero();
|
---|
174 | m_sphereRadius = getSphereRadius();
|
---|
175 | if (m_eventingActive && Changed != null)
|
---|
176 | OnChange();
|
---|
177 | }
|
---|
178 | }
|
---|
179 | }
|
---|
180 | /// <summary>
|
---|
181 | /// maximum value for z axis
|
---|
182 | /// </summary>
|
---|
183 | public float ZMax {
|
---|
184 | get {
|
---|
185 | return m_zMax;
|
---|
186 | }
|
---|
187 | set {
|
---|
188 | if (m_zMax != value) {
|
---|
189 | m_isDirty = true;
|
---|
190 | m_zMax = value;
|
---|
191 | if (!m_allowZeroVolume) ensureVolumeNotZero();
|
---|
192 | m_sphereRadius = getSphereRadius();
|
---|
193 | if (m_eventingActive && Changed != null)
|
---|
194 | OnChange();
|
---|
195 | }
|
---|
196 | }
|
---|
197 | }
|
---|
198 | /// <summary>
|
---|
199 | /// minimum (coordinate)
|
---|
200 | /// </summary>
|
---|
201 | public ILPoint3Df Min {
|
---|
202 | get {
|
---|
203 | return new ILPoint3Df(XMin,YMin,ZMin);
|
---|
204 | }
|
---|
205 | }
|
---|
206 | /// <summary>
|
---|
207 | /// maximum (coordinate)
|
---|
208 | /// </summary>
|
---|
209 | public ILPoint3Df Max {
|
---|
210 | get {
|
---|
211 | return new ILPoint3Df(XMax,YMax,ZMax);
|
---|
212 | }
|
---|
213 | }
|
---|
214 | /// <summary>
|
---|
215 | /// get center of this clipping range
|
---|
216 | /// </summary>
|
---|
217 | public ILPoint3Df CenterF {
|
---|
218 | get {
|
---|
219 | ILPoint3Df ret;
|
---|
220 | ret.X = (XMax + XMin) / 2.0f;
|
---|
221 | ret.Y = (YMax + YMin) / 2.0f;
|
---|
222 | ret.Z = (ZMax + ZMin) / 2.0f;
|
---|
223 | return ret;
|
---|
224 | }
|
---|
225 | }
|
---|
226 | /// <summary>
|
---|
227 | /// get width (x-direction) of this clipping range
|
---|
228 | /// </summary>
|
---|
229 | public float WidthF {
|
---|
230 | get {
|
---|
231 | return (XMax - XMin);
|
---|
232 | }
|
---|
233 | }
|
---|
234 | /// <summary>
|
---|
235 | /// get height (y-direction) of this clipping range
|
---|
236 | /// </summary>
|
---|
237 | public float HeightF {
|
---|
238 | get {
|
---|
239 | return (YMax - YMin);
|
---|
240 | }
|
---|
241 | }
|
---|
242 | /// <summary>
|
---|
243 | /// get depth (z-direction) of this clipping range
|
---|
244 | /// </summary>
|
---|
245 | public float DepthF {
|
---|
246 | get {
|
---|
247 | return (ZMax - ZMin);
|
---|
248 | }
|
---|
249 | }
|
---|
250 | /// <summary>
|
---|
251 | /// marks the limits as altered, without having fired a changed event yet
|
---|
252 | /// </summary>
|
---|
253 | public bool IsDirty {
|
---|
254 | get {
|
---|
255 | return m_isDirty;
|
---|
256 | }
|
---|
257 | }
|
---|
258 | /// <summary>
|
---|
259 | /// true: this clipping data always ensures a non-zero volume
|
---|
260 | /// </summary>
|
---|
261 | /// <remarks>'NonZeroVolumne' means, non of Depth,Width nor Heigth are allowed to be zero. If some edge of the cube is set to zero, the class expands this edge by 1 in each direction.</remarks>
|
---|
262 | public bool AllowZeroVolume {
|
---|
263 | get {
|
---|
264 | return m_allowZeroVolume;
|
---|
265 | }
|
---|
266 | set {
|
---|
267 | m_allowZeroVolume = value;
|
---|
268 | }
|
---|
269 | }
|
---|
270 | #endregion
|
---|
271 |
|
---|
272 | #region public interface
|
---|
273 | /// <summary>
|
---|
274 | /// suspend the firing of events until EventingResume has been called
|
---|
275 | /// </summary>
|
---|
276 | public void EventingSuspend() {
|
---|
277 | m_eventingActive = false;
|
---|
278 | m_isDirty = false;
|
---|
279 | }
|
---|
280 | /// <summary>
|
---|
281 | /// Resume previously suspended eventing. Start sending events again.
|
---|
282 | /// </summary>
|
---|
283 | public void EventingResume() {
|
---|
284 | m_eventingActive = true;
|
---|
285 | if (m_isDirty && Changed != null) {
|
---|
286 | OnChange();
|
---|
287 | }
|
---|
288 | }
|
---|
289 | /// <summary>
|
---|
290 | /// enable eventing without sending pending events
|
---|
291 | /// </summary>
|
---|
292 | public void EventingStart() {
|
---|
293 | m_eventingActive = true;
|
---|
294 | m_isDirty = false;
|
---|
295 | }
|
---|
296 | /// <summary>
|
---|
297 | /// update ranges for this object with union of both ranges.
|
---|
298 | /// </summary>
|
---|
299 | /// <param name="clipData">clipping ranges to create union with</param>
|
---|
300 | public void Update (ILClippingData clipData) {
|
---|
301 | if (clipData.XMin < XMin) { m_isDirty = true; m_xMin = clipData.XMin; }
|
---|
302 | if (clipData.YMin < YMin) { m_isDirty = true; m_yMin = clipData.YMin; }
|
---|
303 | if (clipData.ZMin < ZMin) { m_isDirty = true; m_zMin = clipData.ZMin; }
|
---|
304 | if (clipData.XMax > XMax) { m_isDirty = true; m_xMax = clipData.XMax; }
|
---|
305 | if (clipData.YMax > YMax) { m_isDirty = true; m_yMax = clipData.YMax; }
|
---|
306 | if (clipData.ZMax > ZMax) { m_isDirty = true; m_zMax = clipData.ZMax; }
|
---|
307 | if (!m_allowZeroVolume) ensureVolumeNotZero();
|
---|
308 | m_sphereRadius = getSphereRadius();
|
---|
309 | if (m_isDirty && m_eventingActive && Changed != null)
|
---|
310 | OnChange();
|
---|
311 | }
|
---|
312 | /// <summary>
|
---|
313 | /// update ranges for this object with point coords for specific axes
|
---|
314 | /// </summary>
|
---|
315 | /// <param name="point">point with coords to update ranges with</param>
|
---|
316 | /// <param name="updateBitFlags">bitflag combination to specify axis to be recognized: 1,2,4 -> x,y,z</param>
|
---|
317 | public void Update (ILPoint3Df point, int updateBitFlags) {
|
---|
318 | if ((updateBitFlags & 1) != 0) {
|
---|
319 | if (point.X < XMin) { m_isDirty = true; m_xMin = point.X; }
|
---|
320 | if (point.X > XMax) { m_isDirty = true; m_xMax = point.X; }
|
---|
321 | }
|
---|
322 | if ((updateBitFlags & 2) != 0) {
|
---|
323 | if (point.Y < YMin) { m_isDirty = true; m_yMin = point.Y; }
|
---|
324 | if (point.Y > YMax) { m_isDirty = true; m_yMax = point.Y; }
|
---|
325 | }
|
---|
326 | if ((updateBitFlags & 4) != 0) {
|
---|
327 | if (point.Z < ZMin) { m_isDirty = true; m_zMin = point.Z; }
|
---|
328 | if (point.Z > ZMax) { m_isDirty = true; m_zMax = point.Z; }
|
---|
329 | }
|
---|
330 | if (!m_allowZeroVolume) ensureVolumeNotZero();
|
---|
331 | m_sphereRadius = getSphereRadius();
|
---|
332 | if (m_isDirty && m_eventingActive && Changed != null)
|
---|
333 | OnChange();
|
---|
334 | }
|
---|
335 | /// <summary>
|
---|
336 | /// update clipping data for this object with union of this and rectangle specified
|
---|
337 | /// </summary>
|
---|
338 | /// <param name="luCorner">left upper corner</param>
|
---|
339 | /// <param name="rbCorner">right lower corner</param>
|
---|
340 | public void Update (ILPoint3Df luCorner, ILPoint3Df rbCorner) {
|
---|
341 | bool oldeventState = m_eventingActive;
|
---|
342 | m_eventingActive = false;
|
---|
343 | Update(luCorner,7);
|
---|
344 | m_eventingActive = oldeventState;
|
---|
345 | Update(rbCorner,7);
|
---|
346 | }
|
---|
347 | public void Update (ILPoint3Df center, float zoomFactor) {
|
---|
348 | if (zoomFactor == 1.0f && center == CenterF) return;
|
---|
349 | m_isDirty = true;
|
---|
350 | float s = WidthF * zoomFactor / 2;
|
---|
351 | m_xMin = center.X - s;
|
---|
352 | m_xMax = center.X + s;
|
---|
353 | s = HeightF * zoomFactor / 2;
|
---|
354 | m_yMin = center.Y - s;
|
---|
355 | m_yMax = center.Y + s;
|
---|
356 | s = DepthF * zoomFactor / 2;
|
---|
357 | m_zMin = center.Z - s;
|
---|
358 | m_zMax = center.Z + s;
|
---|
359 | if (!m_allowZeroVolume) ensureVolumeNotZero();
|
---|
360 | m_sphereRadius = getSphereRadius();
|
---|
361 | if (m_eventingActive && Changed != null)
|
---|
362 | OnChange();
|
---|
363 | }
|
---|
364 | /// <summary>
|
---|
365 | /// Set clipping limits to volume inside the box specified
|
---|
366 | /// </summary>
|
---|
367 | /// <param name="lunCorner">left-upper-near corner of the volume box</param>
|
---|
368 | /// <param name="rbfCorner">right-bottom-far corner of the volume box</param>
|
---|
369 | public void Set(ILPoint3Df lunCorner, ILPoint3Df rbfCorner) {
|
---|
370 | m_isDirty = true;
|
---|
371 | m_xMin = Math.Min(lunCorner.X,rbfCorner.X);
|
---|
372 | m_xMax = Math.Max(lunCorner.X,rbfCorner.X);
|
---|
373 | m_yMin = Math.Min(lunCorner.Y,rbfCorner.Y);
|
---|
374 | m_yMax = Math.Max(lunCorner.Y,rbfCorner.Y);
|
---|
375 | m_zMin = Math.Min(lunCorner.Z,rbfCorner.Z);
|
---|
376 | m_zMax = Math.Max(lunCorner.Z,rbfCorner.Z);
|
---|
377 | if (!m_allowZeroVolume) ensureVolumeNotZero();
|
---|
378 | m_sphereRadius = getSphereRadius();
|
---|
379 | if (m_eventingActive && Changed != null)
|
---|
380 | OnChange();
|
---|
381 | }
|
---|
382 | /// <summary>
|
---|
383 | /// reset this clipping range to initial (all empty)
|
---|
384 | /// </summary>
|
---|
385 | public void Reset() {
|
---|
386 | m_xMin = float.MaxValue;
|
---|
387 | m_yMin = float.MaxValue;
|
---|
388 | m_zMin = float.MaxValue;
|
---|
389 | m_xMax = float.MinValue;
|
---|
390 | m_yMax = float.MinValue;
|
---|
391 | m_zMax = float.MinValue;
|
---|
392 | m_isDirty = true;
|
---|
393 | if (m_eventingActive && Changed != null)
|
---|
394 | OnChange();
|
---|
395 | }
|
---|
396 | /// <summary>
|
---|
397 | /// copy this from other clipping data
|
---|
398 | /// </summary>
|
---|
399 | /// <param name="m_clippingData"></param>
|
---|
400 | internal void CopyFrom(ILClippingData m_clippingData) {
|
---|
401 | m_xMin = m_clippingData.XMin;
|
---|
402 | m_yMin = m_clippingData.YMin;
|
---|
403 | m_zMin = m_clippingData.ZMin;
|
---|
404 | m_xMax = m_clippingData.XMax;
|
---|
405 | m_yMax = m_clippingData.YMax;
|
---|
406 | m_zMax = m_clippingData.ZMax;
|
---|
407 | if (!m_allowZeroVolume) ensureVolumeNotZero();
|
---|
408 | m_sphereRadius = getSphereRadius();
|
---|
409 | m_isDirty = true;
|
---|
410 | if (m_eventingActive && Changed != null)
|
---|
411 | OnChange();
|
---|
412 | }
|
---|
413 | /// <summary>
|
---|
414 | /// stretch clipping region to unit cube [0 1][0 1][0 1]
|
---|
415 | /// </summary>
|
---|
416 | /// <returns></returns>
|
---|
417 | public ILPoint3Df ScaleToUnitCube () {
|
---|
418 | ILPoint3Df ret = new ILPoint3Df();
|
---|
419 | float a = WidthF;
|
---|
420 | if (a != 0.0f) ret.X = 1 / a;
|
---|
421 | else ret.X = 0.0f;
|
---|
422 |
|
---|
423 | a = HeightF;
|
---|
424 | if (a != 0.0f) ret.Y = 1 / a;
|
---|
425 | else ret.Y = 0.0f;
|
---|
426 |
|
---|
427 | a = DepthF;
|
---|
428 | if (a != 0.0f) ret.Z = 1 / a;
|
---|
429 | else ret.Z = 0.0f;
|
---|
430 | return ret;
|
---|
431 | }
|
---|
432 | /// <summary>
|
---|
433 | /// offset centering scaled unit cube to zero: [-0.5 0.5][-0.5 0.5][-0.5 0.5]
|
---|
434 | /// </summary>
|
---|
435 | /// <returns></returns>
|
---|
436 | public ILPoint3Df CenterToUnitCube() {
|
---|
437 | ILPoint3Df a = ScaleToUnitCube();
|
---|
438 | ILPoint3Df b = new ILPoint3Df();
|
---|
439 | b.X = -0.5f - a.X * XMin;
|
---|
440 | b.Y = -0.5f - a.Y * YMin;
|
---|
441 | if (ZMin < ZMax)
|
---|
442 | b.Z = (-0.5f - a.Z * ZMin);
|
---|
443 | else b.Z = 0.0f;
|
---|
444 | return b;
|
---|
445 | }
|
---|
446 | /// <summary>
|
---|
447 | /// creates clone of this clipping data
|
---|
448 | /// </summary>
|
---|
449 | /// <returns>clone</returns>
|
---|
450 | public ILClippingData Clone() {
|
---|
451 | ILClippingData ret = new ILClippingData();
|
---|
452 | ret.Update(this);
|
---|
453 | return ret;
|
---|
454 | }
|
---|
455 | /// <summary>
|
---|
456 | /// Map coordinat from unit cube space [-0.5..0.5] into the space limited by this clipping data
|
---|
457 | /// </summary>
|
---|
458 | /// <param name="x">x coordinate (unit cube space: -0.5 ... 0.5)</param>
|
---|
459 | /// <param name="y">y coordinate (unit cube space: -0.5 ... 0.5)</param>
|
---|
460 | /// <param name="z">z coordinate (unit cube space: -0.5 ... 0.5)</param>
|
---|
461 | /// <returns></returns>
|
---|
462 | public ILPoint3Df Map(float x, float y, float z) {
|
---|
463 | ILPoint3Df ret;
|
---|
464 | ret.X = (x + 0.5f) * (m_xMax-m_xMin) + m_xMin;
|
---|
465 | ret.Y = (y + 0.5f) * (m_yMax-m_yMin) + m_yMin;
|
---|
466 | ret.Z = (z + 0.5f) * (m_zMax-m_zMin) + m_zMin;
|
---|
467 | //if (!m_allowZeroVolume) ensureVolumeNotZero();
|
---|
468 | return ret;
|
---|
469 | }
|
---|
470 |
|
---|
471 | public override string ToString() {
|
---|
472 | return String.Format("Min:{0} Max:{1}",Min,Max);
|
---|
473 | }
|
---|
474 | /// <summary>
|
---|
475 | /// Expand/shrink all those edges, not touched by the given line
|
---|
476 | /// </summary>
|
---|
477 | /// <param name="nearLineEnd">near line point</param>
|
---|
478 | /// <param name="farLineEnd">far line point</param>
|
---|
479 | /// <param name="offset">multiplicator, shrink-/expand value</param>
|
---|
480 | public void GetZoomParameter(ILPoint3Df nearLineEnd, ILPoint3Df farLineEnd, float offset,
|
---|
481 | out ILPoint3Df minCorner, out ILPoint3Df maxCorner) {
|
---|
482 | // we determine, if the side is touched by the line.
|
---|
483 | // if 'yes': the side is skipped (its limit/position are kept)
|
---|
484 | // if 'no': the side is moved towards/away from center
|
---|
485 | minCorner = this.Min;
|
---|
486 | maxCorner = this.Max;
|
---|
487 | float sX, sY, sZ;
|
---|
488 | float lamb;
|
---|
489 | float aX = nearLineEnd.X - farLineEnd.X;
|
---|
490 | float aY = nearLineEnd.Y - farLineEnd.Y;
|
---|
491 | float aZ = nearLineEnd.Z - farLineEnd.Z;
|
---|
492 | float offX = WidthF * (offset/2.0f);
|
---|
493 | float offY = HeightF * (offset/2.0f);
|
---|
494 | float offZ = DepthF * (offset/2.0f);
|
---|
495 | #region front side
|
---|
496 | lamb = (m_yMin - nearLineEnd.Y) / aY;
|
---|
497 | sX = nearLineEnd.X + lamb * aX;
|
---|
498 | sZ = nearLineEnd.Z + lamb * aZ;
|
---|
499 | if (sX > m_xMax || sX < m_xMin || sZ > m_zMax || sZ < m_zMin) {
|
---|
500 | minCorner.Y += offY;
|
---|
501 | }
|
---|
502 | #endregion
|
---|
503 | #region right side
|
---|
504 | lamb = (m_xMax - nearLineEnd.X) / aX;
|
---|
505 | sY = nearLineEnd.Y + lamb * aY;
|
---|
506 | sZ = nearLineEnd.Z + lamb * aZ;
|
---|
507 | if (sY > m_yMax || sY < m_yMin || sZ > m_zMax || sZ < m_zMin) {
|
---|
508 | maxCorner.X -= offX;
|
---|
509 | }
|
---|
510 | #endregion
|
---|
511 | #region back side
|
---|
512 | lamb = (m_yMax - nearLineEnd.Y) / aY;
|
---|
513 | sX = nearLineEnd.X + lamb * aX;
|
---|
514 | sZ = nearLineEnd.Z + lamb * aZ;
|
---|
515 | if (sX > m_xMax || sX < m_xMin || sZ > m_zMax || sZ < m_zMin) {
|
---|
516 | maxCorner.Y -= offY;
|
---|
517 | }
|
---|
518 | #endregion
|
---|
519 | #region left side
|
---|
520 | lamb = (m_xMin - nearLineEnd.X) / aX;
|
---|
521 | sY = nearLineEnd.Y + lamb * aY;
|
---|
522 | sZ = nearLineEnd.Z + lamb * aZ;
|
---|
523 | if (sY > m_yMax || sY < m_yMin || sZ > m_zMax || sZ < m_zMin) {
|
---|
524 | minCorner.X += offX;
|
---|
525 | }
|
---|
526 | #endregion
|
---|
527 | #region top side
|
---|
528 | lamb = (m_zMax - nearLineEnd.Z) / aZ;
|
---|
529 | sX = nearLineEnd.X + lamb * aX;
|
---|
530 | sY = nearLineEnd.Y + lamb * aY;
|
---|
531 | if (sY > m_yMax || sY < m_yMin || sX > m_xMax || sX < m_xMin) {
|
---|
532 | maxCorner.Z -= offZ;
|
---|
533 | }
|
---|
534 | #endregion
|
---|
535 | #region bottom side
|
---|
536 | lamb = (m_zMin - nearLineEnd.Z) / aZ;
|
---|
537 | sX = nearLineEnd.X + lamb * aX;
|
---|
538 | sY = nearLineEnd.Y + lamb * aY;
|
---|
539 | if (sY > m_yMax || sY < m_yMin || sX > m_xMax || sX < m_xMin) {
|
---|
540 | minCorner.Z += offZ;
|
---|
541 | }
|
---|
542 | #endregion
|
---|
543 | #region translate: move line to cross middle of view cube
|
---|
544 | ILPoint3Df rQ = CenterF;
|
---|
545 | sX = rQ.X - nearLineEnd.X;
|
---|
546 | sY = rQ.Y - nearLineEnd.Y;
|
---|
547 | sZ = rQ.Z - nearLineEnd.Z;
|
---|
548 | lamb = (aX * sX + aY * sY + aZ * sZ) / (aX * aX + aY * aY + aZ * aZ);
|
---|
549 | offX = rQ.X - (nearLineEnd.X + lamb * aX);
|
---|
550 | offY = rQ.Y - (nearLineEnd.Y + lamb * aY);
|
---|
551 | offZ = rQ.Z - (nearLineEnd.Z + lamb * aZ);
|
---|
552 | minCorner.X -= offX;
|
---|
553 | minCorner.Y -= offY;
|
---|
554 | minCorner.Z -= offZ;
|
---|
555 | maxCorner.X -= offX;
|
---|
556 | maxCorner.Y -= offY;
|
---|
557 | maxCorner.Z -= offZ;
|
---|
558 | #endregion
|
---|
559 | }
|
---|
560 |
|
---|
561 | #endregion
|
---|
562 |
|
---|
563 | #region private helper
|
---|
564 |
|
---|
565 | private float getSphereRadius() {
|
---|
566 | return ((Max - Min) / 2f).GetLength();
|
---|
567 | }
|
---|
568 |
|
---|
569 | /// <summary>
|
---|
570 | /// Ensure that this clipping data has valid length for all dimensions [deprecated]
|
---|
571 | /// </summary>
|
---|
572 | /// <remarks>If the length of the clipping cube is infinity for any dimension,
|
---|
573 | /// that dimension is set to a range of -0.5...0.5.
|
---|
574 | /// <para>This function is to be called by custom graphs which create their
|
---|
575 | /// size <b>relative</b> to the size of the clipping container. Those
|
---|
576 | /// graphs will need a valid container size and may call this function in the
|
---|
577 | /// constructor.</para></remarks>
|
---|
578 | /// <returns>true if the length in any dimension had to be corrected (set to 1.0), false otherwise.</returns>
|
---|
579 | private bool EnsureValidSize() {
|
---|
580 | bool change = false;
|
---|
581 | if (float.IsInfinity(WidthF)) {
|
---|
582 | change = true;
|
---|
583 | m_xMin = -0.5f;
|
---|
584 | m_xMax = 0.5f;
|
---|
585 | }
|
---|
586 | if (float.IsInfinity(HeightF)) {
|
---|
587 | change = true;
|
---|
588 | m_yMin = -0.5f;
|
---|
589 | m_yMax = 0.5f;
|
---|
590 | }
|
---|
591 | if (float.IsInfinity(DepthF)) {
|
---|
592 | change = true;
|
---|
593 | m_zMin = -0.5f;
|
---|
594 | m_zMax = 0.5f;
|
---|
595 | }
|
---|
596 | if (change && m_eventingActive && Changed != null) {
|
---|
597 | OnChange();
|
---|
598 | }
|
---|
599 | return change;
|
---|
600 | }
|
---|
601 |
|
---|
602 | private void ensureVolumeNotZero() {
|
---|
603 | if (HeightF == 0) {
|
---|
604 | m_isDirty = true;
|
---|
605 | m_yMin = m_yMin - 1f;
|
---|
606 | m_yMax = m_yMin + 2f;
|
---|
607 | }
|
---|
608 | if (WidthF == 0) {
|
---|
609 | m_isDirty = true;
|
---|
610 | m_xMin = m_xMin - 1f;
|
---|
611 | m_xMax = m_xMin + 2f;
|
---|
612 | }
|
---|
613 | if (DepthF == 0) {
|
---|
614 | m_isDirty = true;
|
---|
615 | m_zMin = m_zMin - 1f;
|
---|
616 | m_zMax = m_zMin + 2f;
|
---|
617 | }
|
---|
618 | }
|
---|
619 | #endregion
|
---|
620 |
|
---|
621 | #region operator overloads
|
---|
622 | /// <summary>
|
---|
623 | /// Equalty operator overload, true if both cubes span the same region in 3D space
|
---|
624 | /// </summary>
|
---|
625 | /// <param name="limit1">cube 1</param>
|
---|
626 | /// <param name="limit2">cube 2</param>
|
---|
627 | /// <returns>true if both cubes span the same 3D space, false otherwise</returns>
|
---|
628 | public static bool operator == (ILClippingData limit1, ILClippingData limit2) {
|
---|
629 | return (limit1.m_xMax == limit2.m_xMax &&
|
---|
630 | limit1.m_yMax == limit2.m_yMax &&
|
---|
631 | limit1.m_zMax == limit2.m_zMax &&
|
---|
632 | limit1.m_xMin == limit2.m_xMin &&
|
---|
633 | limit1.m_yMin == limit2.m_yMin &&
|
---|
634 | limit1.m_zMin == limit2.m_zMin);
|
---|
635 | }
|
---|
636 | /// <summary>
|
---|
637 | /// unequalty operator
|
---|
638 | /// </summary>
|
---|
639 | /// <param name="limit1">cube 1</param>
|
---|
640 | /// <param name="limit2">cube 2</param>
|
---|
641 | /// <returns>false if both cubes span the same 3D space, true otherwise</returns>
|
---|
642 | public static bool operator !=(ILClippingData limit1, ILClippingData limit2) {
|
---|
643 | return (limit1.m_xMax != limit2.m_xMax ||
|
---|
644 | limit1.m_yMax != limit2.m_yMax ||
|
---|
645 | limit1.m_zMax != limit2.m_zMax ||
|
---|
646 | limit1.m_xMin != limit2.m_xMin ||
|
---|
647 | limit1.m_yMin != limit2.m_yMin ||
|
---|
648 | limit1.m_zMin != limit2.m_zMin);
|
---|
649 | }
|
---|
650 | /// <summary>
|
---|
651 | /// Returns hash code for this ILClippingData
|
---|
652 | /// </summary>
|
---|
653 | /// <returns>hash code</returns>
|
---|
654 | public override int GetHashCode() {
|
---|
655 | return base.GetHashCode();
|
---|
656 | }
|
---|
657 | /// <summary>
|
---|
658 | /// Compares to cube objects
|
---|
659 | /// </summary>
|
---|
660 | /// <param name="obj"></param>
|
---|
661 | /// <returns>true if obj references this class instance, false otherwise</returns>
|
---|
662 | public override bool Equals(object obj) {
|
---|
663 | return base.Equals(obj);
|
---|
664 | }
|
---|
665 | #endregion
|
---|
666 |
|
---|
667 | }
|
---|
668 | }
|
---|