CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
TrVisIval.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// Interval definition
24
25#ifndef ODTRVISIVAL
26#define ODTRVISIVAL
27
28#include "TD_PackPush.h"
29
34template <typename DataType>
36{
37 // Min/max interval bounds.
39
40 // Set from actual values.
41 OdTrVisIvalImpl &set(DataType minBound, DataType maxBound)
42 {
45 return *this;
46 }
47 // Set from linear array.
48 OdTrVisIvalImpl &set(const DataType *pBounds)
49 {
50 m_minBound = pBounds[0];
51 m_maxBound = pBounds[1];
52 return *this;
53 }
54 // Set to identity.
56 {
57 m_minBound = m_maxBound = 0.0f;
58 return *this;
59 }
60
61 // Adapt from another DataType.
62 template <typename AltClass>
63 OdTrVisIvalImpl &adapt(const AltClass &altSet)
64 {
65 m_minBound = (DataType)altSet.m_minBound;
66 m_maxBound = (DataType)altSet.m_maxBound;
67 return *this;
68 }
69
70 // Linear getters.
71 const DataType *getArray() const { return &m_minBound; }
72 DataType *getArray() { return &m_minBound; }
73 // Accessors.
74 DataType minBound() const { return m_minBound; }
75 OdTrVisIvalImpl &setMinBound(DataType minBound) { m_minBound = minBound; return *this; }
76 DataType maxBound() const { return m_maxBound; }
77 OdTrVisIvalImpl &setMaxBound(DataType maxBound) { m_maxBound = maxBound; return *this; }
78
79 // Validate interval.
81 {
83 {
84 DataType tmpReg = m_minBound;
86 m_maxBound = tmpReg;
87 }
88 return *this;
89 }
90
91 bool isValid() const { return m_maxBound >= m_minBound; }
92
93 // Check identity.
94 bool isIdentity() const
95 {
96 return (m_maxBound == 0.0) && (m_minBound == m_maxBound);
97 }
98
99 // Interval length.
100 DataType length() const
101 {
102 return m_maxBound - m_minBound;
103 }
104
105 // Intervals comparision.
106 bool operator ==(const OdTrVisIvalImpl &ival) const
107 {
108 return (m_minBound == ival.m_minBound) && (m_maxBound == ival.m_maxBound);
109 }
110 bool operator !=(const OdTrVisIvalImpl &ival) const
111 {
112 return (m_minBound != ival.m_minBound) || (m_maxBound != ival.m_maxBound);
113 }
114
115 // Intervals intersection.
117 {
119 }
121 {
123 }
124
125 // Intervals unionizing.
127 {
129 }
131 {
133 }
134
135 void extend(DataType percents)
136 {
137 const DataType incVal = length() * 0.5f * percents;
138 m_minBound -= incVal; m_maxBound += incVal;
139 }
140
141 // Transformation to fit bounds interval in current interval.
143 { // Current interval is physical range for values mapping. "bounds" argument provides big interval of exist values space.
144 // For example, if we need to map "bounds" interval in { 0, 17 } range into physical interval in { 4, 5 } range for example.
145 const DataType bounds_length = bounds.length();
146 if (bounds_length > 0.0)
147 {
148 const DataType xform_scale = length() / bounds_length;
149 return OdTrVisIvalImpl().set(xform_scale, m_minBound - bounds.m_minBound * xform_scale);
150 }
151 return OdTrVisIvalImpl().set(0.0, m_minBound);
152 }
153 // Xform point by interval.
154 DataType xform(DataType value) const
155 {
156 return value * m_minBound + m_maxBound;
157 }
158 // Xform bounds by interval.
160 {
161 return OdTrVisIvalImpl().set(xform(bounds.m_minBound), xform(bounds.m_maxBound));
162 }
163
164 // Fit segments in bounds.
165 OdTrVisIvalImpl fit(const OdTrVisIvalImpl &bounds, const OdTrVisIvalImpl &segment) const
166 { // Current interval is xform. Return transform for nested bounds segment.
167 const OdTrVisIvalImpl fitSegment = xform(segment);
168 return fitSegment.fitTransform(bounds);
169 }
170};
171
172// Type definitions.
173
176
177#include "TD_PackPop.h"
178
179#endif // ODTRVISIVAL
#define odmin(X, Y)
Definition: OdPlatform.h:34
#define odmax(X, Y)
Definition: OdPlatform.h:35
OdTrVisIvalImpl< double > OdTrVisIvald
Definition: TrVisIval.h:175
OdTrVisIvalImpl< float > OdTrVisIvalf
Definition: TrVisIval.h:174
GLsizei const GLfloat * value
Definition: gles2_ext.h:302
DataType m_maxBound
Definition: TrVisIval.h:38
OdTrVisIvalImpl operator&(const OdTrVisIvalImpl &ival) const
Definition: TrVisIval.h:116
OdTrVisIvalImpl & setMaxBound(DataType maxBound)
Definition: TrVisIval.h:77
OdTrVisIvalImpl & operator*=(const OdTrVisIvalImpl &ival)
Definition: TrVisIval.h:120
OdTrVisIvalImpl fit(const OdTrVisIvalImpl &bounds, const OdTrVisIvalImpl &segment) const
Definition: TrVisIval.h:165
DataType maxBound() const
Definition: TrVisIval.h:76
DataType xform(DataType value) const
Definition: TrVisIval.h:154
OdTrVisIvalImpl & set(DataType minBound, DataType maxBound)
Definition: TrVisIval.h:41
OdTrVisIvalImpl & adapt(const AltClass &altSet)
Definition: TrVisIval.h:63
bool isValid() const
Definition: TrVisIval.h:91
OdTrVisIvalImpl operator|(const OdTrVisIvalImpl &ival) const
Definition: TrVisIval.h:126
OdTrVisIvalImpl & set(const DataType *pBounds)
Definition: TrVisIval.h:48
OdTrVisIvalImpl xform(const OdTrVisIvalImpl &bounds) const
Definition: TrVisIval.h:159
OdTrVisIvalImpl & setMinBound(DataType minBound)
Definition: TrVisIval.h:75
bool operator!=(const OdTrVisIvalImpl &ival) const
Definition: TrVisIval.h:110
bool isIdentity() const
Definition: TrVisIval.h:94
DataType minBound() const
Definition: TrVisIval.h:74
DataType * getArray()
Definition: TrVisIval.h:72
OdTrVisIvalImpl fitTransform(const OdTrVisIvalImpl &bounds) const
Definition: TrVisIval.h:142
bool operator==(const OdTrVisIvalImpl &ival) const
Definition: TrVisIval.h:106
OdTrVisIvalImpl & validate()
Definition: TrVisIval.h:80
OdTrVisIvalImpl & setIdentity()
Definition: TrVisIval.h:55
DataType m_minBound
Definition: TrVisIval.h:38
void extend(DataType percents)
Definition: TrVisIval.h:135
DataType length() const
Definition: TrVisIval.h:100
OdTrVisIvalImpl & operator|=(const OdTrVisIvalImpl &ival)
Definition: TrVisIval.h:130
const DataType * getArray() const
Definition: TrVisIval.h:71