-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathopennurbs_linear_workflow.cpp
213 lines (175 loc) · 6.34 KB
/
opennurbs_linear_workflow.cpp
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
//
// Copyright (c) 1993-2022 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
#include "opennurbs.h"
#include "opennurbs_internal_defines.h"
#if !defined(ON_COMPILING_OPENNURBS)
// This check is included in all opennurbs source .c and .cpp files to insure
// ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled.
// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined
// and the opennurbs .h files alter what is declared and how it is declared.
#error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs
#endif
class ON_LinearWorkflow::CImpl : public ON_InternalXMLImpl
{
public:
CImpl() { }
CImpl(ON_XMLNode& n) : ON_InternalXMLImpl(&n) { }
};
static const wchar_t* XMLPath(void)
{
return ON_RDK_DOCUMENT ON_XML_SLASH ON_RDK_SETTINGS ON_XML_SLASH ON_RDK_RENDERING;
}
ON_LinearWorkflow::ON_LinearWorkflow()
{
_impl = new CImpl;
}
ON_LinearWorkflow::ON_LinearWorkflow(ON_XMLNode& model_node)
{
_impl = new CImpl(model_node);
}
ON_LinearWorkflow::ON_LinearWorkflow(const ON_LinearWorkflow& lw)
{
_impl = new CImpl;
operator = (lw);
}
ON_LinearWorkflow::~ON_LinearWorkflow()
{
delete _impl;
_impl = nullptr;
}
const ON_LinearWorkflow& ON_LinearWorkflow::operator = (const ON_LinearWorkflow& lw)
{
if (this != &lw)
{
// When copying the object, we need to directly copy the underlying XML. So we can't allow
// virtual overrides to execute because they might hide the real values we want to copy.
using LW = ON_LinearWorkflow;
LW::SetPreProcessTexturesOn (lw.LW::PreProcessTexturesOn());
LW::SetPreProcessColorsOn (lw.LW::PreProcessColorsOn());
LW::SetPostProcessFrameBufferOn(lw.LW::PostProcessFrameBufferOn());
LW::SetPreProcessGammaOn (lw.LW::PreProcessGammaOn());
LW::SetPostProcessGammaOn (lw.LW::PostProcessGammaOn());
LW::SetPreProcessGamma (lw.LW::PreProcessGamma());
LW::SetPostProcessGamma (lw.LW::PostProcessGamma());
}
return *this;
}
bool ON_LinearWorkflow::operator == (const ON_LinearWorkflow& lw) const
{
// When checking equality, we need to directly check the underlying storage. So we can't allow
// virtual overrides to execute because they might hide the real values we want to check.
using LW = ON_LinearWorkflow;
if (LW::PreProcessTexturesOn() != lw.LW::PreProcessTexturesOn()) return false;
if (LW::PreProcessColorsOn() != lw.LW::PreProcessColorsOn()) return false;
if (LW::PostProcessFrameBufferOn() != lw.LW::PostProcessFrameBufferOn()) return false;
if (LW::PreProcessGammaOn() != lw.LW::PreProcessGammaOn()) return false;
if (LW::PostProcessGammaOn() != lw.LW::PostProcessGammaOn()) return false;
if (!IsFloatEqual(LW::PreProcessGamma(), lw.LW::PreProcessGamma())) return false;
if (!IsFloatEqual(LW::PostProcessGamma(), lw.LW::PostProcessGamma())) return false;
return true;
}
bool ON_LinearWorkflow::operator != (const ON_LinearWorkflow& lw) const
{
return !(operator == (lw));
}
bool ON_LinearWorkflow::PreProcessTexturesOn(void) const
{
return _impl->GetParameter(XMLPath(), ON_RDK_PRE_PROCESS_GAMMA_ON, false);
}
void ON_LinearWorkflow::SetPreProcessTexturesOn(bool b)
{
_impl->SetParameter(XMLPath(), ON_RDK_PRE_PROCESS_GAMMA_ON, b);
}
bool ON_LinearWorkflow::PreProcessColorsOn(void) const
{
return _impl->GetParameter(XMLPath(), ON_RDK_PRE_PROCESS_GAMMA_ON, false);
}
void ON_LinearWorkflow::SetPreProcessColorsOn(bool b)
{
_impl->SetParameter(XMLPath(), ON_RDK_PRE_PROCESS_GAMMA_ON, b);
}
bool ON_LinearWorkflow::PreProcessGammaOn(void) const
{
return _impl->GetParameter(XMLPath(), ON_RDK_PRE_PROCESS_GAMMA_ON, true);
}
void ON_LinearWorkflow::SetPreProcessGammaOn(bool on)
{
_impl->SetParameter(XMLPath(), ON_RDK_PRE_PROCESS_GAMMA_ON, on);
}
bool ON_LinearWorkflow::PostProcessGammaOn(void) const
{
return _impl->GetParameter(XMLPath(), ON_RDK_POST_PROCESS_GAMMA_ON, true);
}
void ON_LinearWorkflow::SetPostProcessGammaOn(bool on)
{
_impl->SetParameter(XMLPath(), ON_RDK_POST_PROCESS_GAMMA_ON, on);
}
bool ON_LinearWorkflow::PostProcessFrameBufferOn(void) const
{
return true; // Always on. For possible future use.
}
void ON_LinearWorkflow::SetPostProcessFrameBufferOn(bool)
{
// Always on. Ignore the call.
}
static float ClampGamma(float f) { return std::min(5.0f, std::max(0.2f, f)); }
float ON_LinearWorkflow::PreProcessGamma(void) const
{
return ON_LinearWorkflow::PostProcessGamma();
}
void ON_LinearWorkflow::SetPreProcessGamma(float gamma)
{
ON_LinearWorkflow::SetPostProcessGamma(gamma);
}
float ON_LinearWorkflow::PostProcessGamma(void) const
{
return ClampGamma(_impl->GetParameter(XMLPath(), ON_RDK_POST_PROCESS_GAMMA, 2.2f));
}
void ON_LinearWorkflow::SetPostProcessGamma(float gamma)
{
_impl->SetParameter(XMLPath(), ON_RDK_POST_PROCESS_GAMMA, ClampGamma(gamma));
}
void ON_LinearWorkflow::ApplyPreProcessGamma(ON_4fColor& col, bool for_texture) const
{
const bool check = for_texture ? PreProcessTexturesOn() : PreProcessColorsOn();
if (!check)
return;
const float gamma = PreProcessGamma();
if (!IsFloatEqual(gamma, 1.0f))
{
float* f = col.FloatArray();
ON_ASSERT((f[0] >= 0.0) && (f[1] >= 0.0) && (f[2] >= 0.0));
if (f[0] > 0.0) f[0] = powf(f[0], gamma);
if (f[1] > 0.0) f[1] = powf(f[1], gamma);
if (f[2] > 0.0) f[2] = powf(f[2], gamma);
}
}
ON__UINT32 ON_LinearWorkflow::DataCRC(ON__UINT32 crc) const
{
bool b[] = { PreProcessTexturesOn(), PreProcessColorsOn(), PostProcessFrameBufferOn(), PostProcessGammaOn() };
crc = ON_CRC32(crc, sizeof(b), b);
ON__INT64 f[] = { Integerize(PreProcessGamma()), Integerize(PostProcessGamma()) };
crc = ON_CRC32(crc, sizeof(f), f);
return crc;
}
void ON_LinearWorkflow::SetXMLNode(ON_XMLNode& node) const
{
_impl->SetModelNode(node);
}
void* ON_LinearWorkflow::EVF(const wchar_t* func, void* data)
{
return nullptr;
}
void ON_LinearWorkflow::OnInternalXmlChanged(const ON_LinearWorkflow*)
{
}