-
Notifications
You must be signed in to change notification settings - Fork 0
/
MitsubaOptions.cs
375 lines (355 loc) · 14.6 KB
/
MitsubaOptions.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Rhino;
namespace Mitsuba {
struct MitsubaSettings {
public enum Integrator {
EDirectIllumination = 0,
EPathTracer,
EAdjointParticleTracer,
EBidirectional,
EKelemenMLT,
EVeachMLT,
EERPT
};
public bool writeSerialized;
public string rendererDirectory;
public Integrator integrator;
public int xres, yres;
public int pathLength;
public int samplesPerPixel;
public void Load(PersistentSettings settings) {
writeSerialized = settings.GetBool("WriteSerialized", true);
rendererDirectory = settings.GetString("RendererDirectory", "");
xres = settings.GetInteger("XResolution", 1024);
yres = settings.GetInteger("YResolution", 768);
pathLength = settings.GetInteger("PathLength", 3);
samplesPerPixel = settings.GetInteger("SamplesPerPixel", 4);
integrator = (Integrator) settings.GetInteger("Integrator",
(int) Integrator.EDirectIllumination);
}
public void Store(PersistentSettings settings) {
settings.SetBool("WriteSerialized", writeSerialized);
settings.SetString("RendererDirectory", rendererDirectory);
settings.SetInteger("XResolution", xres);
settings.SetInteger("YResolution", yres);
settings.SetInteger("PathLength", pathLength);
settings.SetInteger("SamplesPerPixel", samplesPerPixel);
settings.SetInteger("Integrator", (int) integrator);
}
};
partial class MitsubaOptionsControl : UserControl {
private Button browseButton;
private Label label2;
private Label label3;
private TextBox rendererDirectory;
private Label label4;
private Label label5;
private Label label6;
private Label label8;
private Label label9;
private ComboBox integrator;
private NumericUpDown pathLength;
private ComboBox resolution;
private Label label7;
private NumericUpDown samplesPerPixel;
private FolderBrowserDialog folderBrowserDialog1;
private CheckBox writeSerializedBox;
private Label label10;
public MitsubaOptionsControl(ref MitsubaSettings settings) {
InitializeComponent();
writeSerializedBox.Checked = settings.writeSerialized;
integrator.SelectedIndex = (int) settings.integrator;
pathLength.Value = settings.pathLength;
samplesPerPixel.Value = settings.samplesPerPixel;
rendererDirectory.Text = settings.rendererDirectory;
resolution.Text = settings.xres + "x" + settings.yres;
pathLength.Enabled = integrator.SelectedIndex != (int) MitsubaSettings.Integrator.EDirectIllumination;
}
public void Apply(ref MitsubaSettings settings) {
settings.writeSerialized = writeSerializedBox.Checked;
settings.integrator = (MitsubaSettings.Integrator) integrator.SelectedIndex;
settings.rendererDirectory = rendererDirectory.Text;
settings.samplesPerPixel = (int) samplesPerPixel.Value;
settings.pathLength = (int) pathLength.Value;
string[] parts = resolution.Text.Split('x');
if (parts.Length != 2)
throw new Exception("Invalid resolution specification!");
settings.xres = Convert.ToInt32(parts[0]);
settings.yres = Convert.ToInt32(parts[1]);
}
private void InitializeComponent() {
this.browseButton = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.rendererDirectory = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.integrator = new System.Windows.Forms.ComboBox();
this.pathLength = new System.Windows.Forms.NumericUpDown();
this.resolution = new System.Windows.Forms.ComboBox();
this.label7 = new System.Windows.Forms.Label();
this.samplesPerPixel = new System.Windows.Forms.NumericUpDown();
this.label10 = new System.Windows.Forms.Label();
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.writeSerializedBox = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.pathLength)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.samplesPerPixel)).BeginInit();
this.SuspendLayout();
//
// browseButton
//
this.browseButton.Location = new System.Drawing.Point(345, 50);
this.browseButton.Name = "browseButton";
this.browseButton.Size = new System.Drawing.Size(28, 23);
this.browseButton.TabIndex = 2;
this.browseButton.Text = "..";
this.browseButton.UseVisualStyleBackColor = true;
this.browseButton.Click += new System.EventHandler(this.browseButton_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(16, 18);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(183, 25);
this.label2.TabIndex = 3;
this.label2.Text = "Mitsuba Renderer";
//
// label3
//
this.label3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label3.Location = new System.Drawing.Point(112, 24);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(280, 2);
this.label3.TabIndex = 4;
//
// rendererDirectory
//
this.rendererDirectory.Location = new System.Drawing.Point(168, 52);
this.rendererDirectory.Name = "rendererDirectory";
this.rendererDirectory.Size = new System.Drawing.Size(174, 31);
this.rendererDirectory.TabIndex = 5;
//
// label4
//
this.label4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label4.Location = new System.Drawing.Point(112, 141);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(280, 3);
this.label4.TabIndex = 7;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(16, 159);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(166, 25);
this.label5.TabIndex = 6;
this.label5.Text = "Render Settings";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(40, 55);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(202, 25);
this.label6.TabIndex = 8;
this.label6.Text = "Renderer directory :";
this.label6.Click += new System.EventHandler(this.label6_Click);
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(40, 230);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(115, 25);
this.label8.TabIndex = 10;
this.label8.Text = "Integrator :";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(40, 265);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(133, 25);
this.label9.TabIndex = 11;
this.label9.Text = "Path length :";
//
// integrator
//
this.integrator.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.integrator.FormattingEnabled = true;
this.integrator.Items.AddRange(new object[] {
"Direct Illumination",
"Path tracer",
"Adjoint Particle Tracer",
"Bidirectional Path Tracer",
"Primary Sample Space MLT",
"Path Space MLT",
"Energy Redistribution Path Tracing"});
this.integrator.Location = new System.Drawing.Point(168, 227);
this.integrator.Name = "integrator";
this.integrator.Size = new System.Drawing.Size(205, 33);
this.integrator.TabIndex = 12;
this.integrator.SelectedIndexChanged += new System.EventHandler(this.integrator_SelectedIndexChanged);
//
// pathLength
//
this.pathLength.Location = new System.Drawing.Point(168, 263);
this.pathLength.Minimum = new decimal(new int[] {
2,
0,
0,
0});
this.pathLength.Name = "pathLength";
this.pathLength.Size = new System.Drawing.Size(205, 31);
this.pathLength.TabIndex = 13;
this.pathLength.Value = new decimal(new int[] {
2,
0,
0,
0});
//
// resolution
//
this.resolution.FormattingEnabled = true;
this.resolution.Items.AddRange(new object[] {
"512x512",
"640x480",
"768x512",
"768x576",
"1024x768",
"1024x1024",
"1280x720",
"1280x1024",
"1920x1080"});
this.resolution.Location = new System.Drawing.Point(168, 192);
this.resolution.Name = "resolution";
this.resolution.Size = new System.Drawing.Size(205, 33);
this.resolution.TabIndex = 14;
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(40, 195);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(190, 25);
this.label7.TabIndex = 15;
this.label7.Text = "Image Resolution :";
//
// samplesPerPixel
//
this.samplesPerPixel.Location = new System.Drawing.Point(168, 300);
this.samplesPerPixel.Maximum = new decimal(new int[] {
1000000,
0,
0,
0});
this.samplesPerPixel.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.samplesPerPixel.Name = "samplesPerPixel";
this.samplesPerPixel.Size = new System.Drawing.Size(205, 31);
this.samplesPerPixel.TabIndex = 17;
this.samplesPerPixel.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(40, 302);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(195, 25);
this.label10.TabIndex = 16;
this.label10.Text = "Samples per pixel :";
//
// writeSerializedBox
//
this.writeSerializedBox.AutoSize = true;
this.writeSerializedBox.Location = new System.Drawing.Point(45, 99);
this.writeSerializedBox.Name = "writeSerializedBox";
this.writeSerializedBox.Size = new System.Drawing.Size(273, 29);
this.writeSerializedBox.TabIndex = 19;
this.writeSerializedBox.Text = "Write serialized meshes";
this.writeSerializedBox.UseVisualStyleBackColor = true;
//
// MitsubaOptionsControl
//
this.Controls.Add(this.writeSerializedBox);
this.Controls.Add(this.samplesPerPixel);
this.Controls.Add(this.label10);
this.Controls.Add(this.label7);
this.Controls.Add(this.resolution);
this.Controls.Add(this.pathLength);
this.Controls.Add(this.integrator);
this.Controls.Add(this.label9);
this.Controls.Add(this.label8);
this.Controls.Add(this.label6);
this.Controls.Add(this.label4);
this.Controls.Add(this.label5);
this.Controls.Add(this.rendererDirectory);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.browseButton);
this.Name = "MitsubaOptionsControl";
this.Size = new System.Drawing.Size(411, 361);
((System.ComponentModel.ISupportInitialize)(this.pathLength)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.samplesPerPixel)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
private void browseButton_Click(object sender, EventArgs e) {
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) {
rendererDirectory.Text = folderBrowserDialog1.SelectedPath;
}
}
private void integrator_SelectedIndexChanged(object sender, EventArgs e) {
pathLength.Enabled = integrator.SelectedIndex != (int) MitsubaSettings.Integrator.EDirectIllumination;
}
private void label6_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
}
class MitsubaOptionsPage : Rhino.UI.OptionsDialogPage {
MitsubaOptionsControl m_control;
PersistentSettings m_settings;
MitsubaSettings m_mitsubaSettings;
public MitsubaOptionsPage(Rhino.PersistentSettings settings)
: base("Mitsuba") {
m_settings = settings;
m_mitsubaSettings = new MitsubaSettings();
m_mitsubaSettings.Load(m_settings);
m_control = new MitsubaOptionsControl(ref m_mitsubaSettings);
}
public override Object PageControl {
get { return m_control; }
}
public override bool OnApply() {
try {
m_control.Apply(ref m_mitsubaSettings);
m_mitsubaSettings.Store(m_settings);
return true;
} catch (Exception e) {
RhinoApp.WriteLine(e.ToString());
return false;
}
}
}
}