1 #region
using statemens
4 using System.Reflection;
5 using System.Collections.Generic;
6 using System.ComponentModel;
12 using System.Windows.Forms;
13 using Microsoft.Xna.Framework;
19 using Point = System.Drawing.Point;
26 #region Tranfer function variables
27 bool tfPanelMouseDown =
false;
28 Point tfPanelMouseDownPos =
new Point();
31 #region XNA Viewport variables
32 bool xnaDrawSurface_MouseDownEvent =
false;
33 int mouseDownPosX, mouseDownPosY, mouseDownPosZ = 0;
37 #region other variables
38 string assemblyLocation = Assembly.GetExecutingAssembly().Location;
45 public bool XnaDrawSurface_MouseDownEvent
47 set { xnaDrawSurface_MouseDownEvent = value; }
48 get {
return xnaDrawSurface_MouseDownEvent; }
52 public int MouseDownPosX
54 set { mouseDownPosX = value; }
56 public int MouseDownPosY
58 set { mouseDownPosY = value; }
60 public Vector3 MouseMovePos
62 set { MouseMovePos = value; }
65 public bool SliceFormOpen
67 set { sliceFormOpen = value; }
68 get {
return sliceFormOpen; }
78 InitializeComponent();
79 SetStyle(ControlStyles.OptimizedDoubleBuffer |
80 ControlStyles.UserPaint |
81 ControlStyles.AllPaintingInWmPaint,
true);
83 #region init child controls
85 sliceFormOpen =
false;
86 this.transferfunctionCheckBox.Checked =
GameProperties.Instance.enableTransferFunction;
87 this.transferfunctionCheckBox1.Checked =
GameProperties.Instance.enableTransferAlphaValues;
88 this.transferfunctionCheckBox2.Checked =
GameProperties.Instance.showDensityValue;
89 this.enableCVDCheckBox.Checked =
GameProperties.Instance.enableCVDView;
90 this.cvdViewCheckBox1.Checked =
GameProperties.Instance.originalView;
91 this.cvdViewCheckBox2.Checked =
GameProperties.Instance.recoloredView;
99 this.cvdRadioButton1.Checked =
true;
100 this.cvdRadioButton2.Checked =
false;
101 this.cvdRadioButton3.Checked =
false;
104 this.cvdRadioButton1.Checked =
false;
105 this.cvdRadioButton2.Checked =
true;
106 this.cvdRadioButton3.Checked =
false;
109 this.cvdRadioButton1.Checked =
false;
110 this.cvdRadioButton2.Checked =
false;
111 this.cvdRadioButton3.Checked =
true;
114 this.cvdRadioButton1.Checked =
true;
115 this.cvdRadioButton2.Checked =
false;
116 this.cvdRadioButton3.Checked =
false;
122 this.cvdViewCheckBox1.Enabled =
true;
123 this.cvdViewCheckBox2.Enabled =
true;
124 this.cvdViewCheckBox3.Enabled =
true;
127 this.cvdRadioButton1.Enabled =
true;
128 this.cvdRadioButton2.Enabled =
true;
129 this.cvdRadioButton3.Enabled =
true;
133 this.cvdViewCheckBox1.Enabled =
false;
134 this.cvdViewCheckBox2.Enabled =
false;
135 this.cvdViewCheckBox3.Enabled =
false;
138 this.cvdRadioButton1.Enabled =
false;
139 this.cvdRadioButton2.Enabled =
false;
140 this.cvdRadioButton3.Enabled =
false;
146 volViewToolStripMenuItem.Checked =
true;
149 topViewToolStripMenuItem.Checked =
true;
152 sideViewToolStripMenuItem.Checked =
true;
155 frontViewToolStripMenuItem.Checked =
true;
158 volViewToolStripMenuItem.Checked =
true;
162 this.PerspProjRadio.Checked =
GameProperties.Instance.perspectiveProjection;
163 this.OrthProjRadio.Checked = !
GameProperties.Instance.perspectiveProjection;
164 this.BlendRadioButt1.Checked =
GameProperties.Instance.enableFrontToBackBlend;
165 this.BlendRadioButt2.Checked = !
GameProperties.Instance.enableFrontToBackBlend;
166 this.ShadingCheckBox.Checked =
GameProperties.Instance.enableShading;
171 #region update controls
172 public void updateSliceControls(
int xRange,
int yRange,
int zRange)
181 Decimal xIncrement = Decimal.Divide(XSliceNumericUpDown.Maximum,
new Decimal(xRange));
184 int xDecimalPlaces = 8;
185 XSliceNumericUpDown.Increment = xIncrement;
186 XSliceNumericUpDown.DecimalPlaces = xDecimalPlaces;
187 XSliceNumericUpDown.Value = Decimal.Divide(XSliceNumericUpDown.Maximum,
new Decimal(2));
188 XSlider.Maximum = xRange;
189 XSlider.Value = xRange / 2;
192 Decimal yIncrement = Decimal.Divide(YSliceNumericUpDown.Maximum,
new Decimal(yRange));
195 int yDecimalPlaces = 8;
196 YSliceNumericUpDown.Increment = yIncrement;
197 YSliceNumericUpDown.DecimalPlaces = yDecimalPlaces;
198 YSliceNumericUpDown.Value = Decimal.Divide(YSliceNumericUpDown.Maximum,
new Decimal(2));
199 YSlider.Maximum = yRange;
200 YSlider.Value = yRange / 2;
203 Decimal zIncrement = Decimal.Divide(ZSliceNumericUpDown.Maximum,
new Decimal(zRange));
206 int zDecimalPlaces = 8;
207 ZSliceNumericUpDown.Increment = zIncrement;
208 ZSliceNumericUpDown.DecimalPlaces = zDecimalPlaces;
209 ZSliceNumericUpDown.Value = Decimal.Divide(ZSliceNumericUpDown.Maximum,
new Decimal(2));
210 ZSlider.Maximum = zRange;
211 ZSlider.Value = zRange / 2;
213 XSliceGroup.Refresh();
214 YSliceGroup.Refresh();
215 ZSliceGroup.Refresh();
225 public void setSlicingGroups(
int slice, Decimal increment,
int decimalPlaces, Decimal value)
230 XSliceNumericUpDown.Increment = increment;
231 XSliceNumericUpDown.DecimalPlaces = decimalPlaces;
232 XSliceNumericUpDown.Value = value;
235 YSliceNumericUpDown.Increment = increment;
236 YSliceNumericUpDown.DecimalPlaces = decimalPlaces;
237 YSliceNumericUpDown.Value = value;
240 ZSliceNumericUpDown.Increment = increment;
241 ZSliceNumericUpDown.DecimalPlaces = decimalPlaces;
242 ZSliceNumericUpDown.Value = value;
262 XSlider.Maximum = maximum;
263 XSlider.Value = value;
266 YSlider.Maximum = maximum;
267 YSlider.Value = value;
270 ZSlider.Maximum = maximum;
271 ZSlider.Value = value;
280 public void updateSliceGroups()
282 XSliceGroup.Refresh();
283 YSliceGroup.Refresh();
284 ZSliceGroup.Refresh();
288 #region event handler
290 #region main menu handler
293 private void handleOpenFileMenu(
object sender, EventArgs e)
303 string relativePath = Path.Combine(assemblyLocation,
"../../../../Data");
304 string contentPath = Path.GetFullPath(relativePath);
306 this.openFileDialog.InitialDirectory = contentPath;
308 this.openFileDialog.Title =
"Load Data Set";
310 this.openFileDialog.Filter =
"Data Files (*.dat)|*.dat";
312 if (this.openFileDialog.ShowDialog() == DialogResult.OK)
314 #region set engine control
315 GameProperties.Instance.dataFilename = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf(
"\\") + 1);
316 updateXnaEngineState(
true,
true,
true,
true);
319 #region set tf control
320 TransferFunctionPanel.UpdateIsoValues =
true;
321 TransferFunctionPanel.DensityFunction = (
GameProperties.Instance.showDensityValue && this.transferfunctionCheckBox2.Checked);
322 TransferFunctionPanel.GetControlPoints =
true;
323 TransferFunctionPanel.Refresh();
333 private void handleSaveFileMenu(
object sender, EventArgs e)
335 string relativePath = Path.Combine(assemblyLocation,
"../../../../Data/Screenshots");
336 string contentPath = Path.GetFullPath(relativePath);
338 this.saveFileDialog.InitialDirectory = contentPath;
340 this.saveFileDialog.Title =
"Save Image as";
342 this.saveFileDialog.Filter =
"PNG Files (*.png)|*.png";
344 if (this.saveFileDialog.ShowDialog() == DialogResult.OK)
346 #region update engine state
347 GameProperties.Instance.saveFilename = saveFileDialog.FileName;
348 GameProperties.Instance.saveView =
true;
349 GameProperties.Instance.engineState.drawData =
true;
350 this.XNADrawSurface.Refresh();
360 private void handleExitMenu(
object sender, EventArgs e)
362 System.Windows.Forms.Application.Exit();
371 private void MainWindow_FormClosing(
object sender, FormClosingEventArgs e)
378 private void handleViewMenuOnClick(
object sender, EventArgs e)
385 if(sender == this.SingleToolStripMenuItem)
387 SingleToolStripMenuItem.Checked =
true;
388 SplitToolStripMenuItem.Checked =
false;
389 GameProperties.Instance.viewportMode =
ViewportMode.Single;
391 volViewToolStripMenuItem.Enabled =
true;
392 topViewToolStripMenuItem.Enabled =
true;
393 sideViewToolStripMenuItem.Enabled =
true;
394 frontViewToolStripMenuItem.Enabled =
true;
397 else if (sender == this.SplitToolStripMenuItem)
399 SingleToolStripMenuItem.Checked =
false;
400 SplitToolStripMenuItem.Checked =
true;
401 GameProperties.Instance.viewportMode =
ViewportMode.Split4;
403 volViewToolStripMenuItem.Enabled =
false;
404 topViewToolStripMenuItem.Enabled =
false;
405 sideViewToolStripMenuItem.Enabled =
false;
406 frontViewToolStripMenuItem.Enabled =
false;
409 else if (sender == this.volViewToolStripMenuItem)
411 volViewToolStripMenuItem.Checked =
true;
412 topViewToolStripMenuItem.Checked =
false;
413 sideViewToolStripMenuItem.Checked =
false;
414 frontViewToolStripMenuItem.Checked =
false;
415 GameProperties.Instance.viewMode =
ViewMode.VolView;
416 if (GameProperties.Instance.enableCVDView)
421 GameProperties.Instance.originalView = volViewToolStripMenuItem.Checked;
424 else if (sender == this.topViewToolStripMenuItem)
426 volViewToolStripMenuItem.Checked =
false;
427 topViewToolStripMenuItem.Checked =
true;
428 sideViewToolStripMenuItem.Checked =
false;
429 frontViewToolStripMenuItem.Checked =
false;
430 recoloredViewToolStripMenuItem.Checked =
false;
432 GameProperties.Instance.viewMode =
ViewMode.TopView;
434 else if (sender == this.sideViewToolStripMenuItem)
436 volViewToolStripMenuItem.Checked =
false;
437 topViewToolStripMenuItem.Checked =
false;
438 sideViewToolStripMenuItem.Checked =
true;
439 frontViewToolStripMenuItem.Checked =
false;
440 recoloredViewToolStripMenuItem.Checked =
false;
442 GameProperties.Instance.viewMode =
ViewMode.SideView;
444 else if (sender == this.frontViewToolStripMenuItem)
446 volViewToolStripMenuItem.Checked =
false;
447 topViewToolStripMenuItem.Checked =
false;
448 sideViewToolStripMenuItem.Checked =
false;
449 frontViewToolStripMenuItem.Checked =
true;
450 recoloredViewToolStripMenuItem.Checked =
false;
452 GameProperties.Instance.viewMode =
ViewMode.FrontView;
454 else if (sender == this.recoloredViewToolStripMenuItem)
457 topViewToolStripMenuItem.Checked =
false;
458 sideViewToolStripMenuItem.Checked =
false;
459 frontViewToolStripMenuItem.Checked =
false;
460 recoloredViewToolStripMenuItem.Checked = !recoloredViewToolStripMenuItem.Checked;
462 GameProperties.Instance.recoloredView = recoloredViewToolStripMenuItem.Checked;
463 if (GameProperties.Instance.enableCVDView)
465 cvdViewCheckBox2.Checked = recoloredViewToolStripMenuItem.Checked;
468 else if (sender == this.cvdViewToolStripMenuItem)
491 private void handleZoomMenuOnCLick(
object sender, EventArgs e)
502 #region functions menu
509 private void handleSlicingMenu(
object sender, EventArgs e)
512 sliceFormOpen =
true;
513 slicingDialog.MainForm =
this;
514 slicingDialog.setSlicingGroups(1, XSliceNumericUpDown.Increment, XSliceNumericUpDown.DecimalPlaces, XSliceNumericUpDown.Value);
515 slicingDialog.setSlicingGroups(2, YSliceNumericUpDown.Increment, YSliceNumericUpDown.DecimalPlaces, YSliceNumericUpDown.Value);
516 slicingDialog.setSlicingGroups(3, ZSliceNumericUpDown.Increment, YSliceNumericUpDown.DecimalPlaces, ZSliceNumericUpDown.Value);
517 slicingDialog.setSlicingGroups(1, XSlider.Maximum, XSlider.Value);
518 slicingDialog.setSlicingGroups(2, YSlider.Maximum, YSlider.Value);
519 slicingDialog.setSlicingGroups(3, ZSlider.Maximum, ZSlider.Value);
520 slicingDialog.Show();
531 private void handleMaxIntensityProjMenu(
object sender, EventArgs e)
533 if (maximumIntensityProjectionToolStripMenuItem.Checked)
535 maximumIntensityProjectionToolStripMenuItem.Checked =
false;
536 MaxIntensityProjCheckBox.Checked =
false;
540 maximumIntensityProjectionToolStripMenuItem.Checked =
true;
541 MaxIntensityProjCheckBox.Checked =
true;
544 GameProperties.Instance.maximumIntensityProjection = MaxIntensityProjCheckBox.Checked;
545 updateXnaEngineState(
true,
false,
true,
true);
553 private void handlePerspProjMenu(
object sender, EventArgs e)
555 if (perspectiveProjectionToolStripMenuItem.Checked)
557 perspectiveProjectionToolStripMenuItem.Checked =
false;
558 orthogonalProjectionToolStripMenuItem.Checked =
true;
559 PerspProjRadio.Checked =
false;
560 OrthProjRadio.Checked =
true;
564 perspectiveProjectionToolStripMenuItem.Checked =
true;
565 orthogonalProjectionToolStripMenuItem.Checked =
false;
566 PerspProjRadio.Checked =
true;
567 OrthProjRadio.Checked =
false;
570 GameProperties.Instance.perspectiveProjection = PerspProjRadio.Checked;
571 updateXnaEngineState(
true,
false,
true,
true);
579 private void handleOrthProjMenu(
object sender, EventArgs e)
581 if (orthogonalProjectionToolStripMenuItem.Checked)
583 perspectiveProjectionToolStripMenuItem.Checked =
true;
584 orthogonalProjectionToolStripMenuItem.Checked =
false;
585 PerspProjRadio.Checked =
true;
586 OrthProjRadio.Checked =
false;
590 perspectiveProjectionToolStripMenuItem.Checked =
false;
591 orthogonalProjectionToolStripMenuItem.Checked =
true;
592 PerspProjRadio.Checked =
false;
593 OrthProjRadio.Checked =
true;
595 GameProperties.Instance.perspectiveProjection = PerspProjRadio.Checked;
596 updateXnaEngineState(
true,
false,
true,
true);
604 private void handleBlendModeMenu(
object sender, EventArgs e)
606 if (sender == frontToBackBlendingToolStripMenuItem)
608 if (frontToBackBlendingToolStripMenuItem.Checked)
610 frontToBackBlendingToolStripMenuItem.Checked =
false;
611 backToFrontBlendingToolStripMenuItem.Checked =
true;
612 BlendRadioButt1.Checked =
false;
613 BlendRadioButt2.Checked =
true;
617 frontToBackBlendingToolStripMenuItem.Checked =
true;
618 backToFrontBlendingToolStripMenuItem.Checked =
false;
619 BlendRadioButt1.Checked =
true;
620 BlendRadioButt2.Checked =
false;
624 else if (sender == backToFrontBlendingToolStripMenuItem)
626 if (backToFrontBlendingToolStripMenuItem.Checked)
628 frontToBackBlendingToolStripMenuItem.Checked =
true;
629 backToFrontBlendingToolStripMenuItem.Checked =
false;
630 BlendRadioButt1.Checked =
true;
631 BlendRadioButt2.Checked =
false;
635 frontToBackBlendingToolStripMenuItem.Checked =
false;
636 backToFrontBlendingToolStripMenuItem.Checked =
true;
637 BlendRadioButt1.Checked =
false;
638 BlendRadioButt2.Checked =
true;
643 GameProperties.Instance.enableFrontToBackBlend = frontToBackBlendingToolStripMenuItem.Checked;
644 updateXnaEngineState(
true,
false,
true,
true);
652 private void handleShadingMenu(
object sender, EventArgs e)
654 if (shadingToolStripMenuItem.Checked)
656 shadingToolStripMenuItem.Checked =
false;
660 shadingToolStripMenuItem.Checked =
true;
662 ShadingCheckBox.Checked = shadingToolStripMenuItem.Checked;
663 GameProperties.Instance.enableShading = ShadingCheckBox.Checked;
664 updateXnaEngineState(
true,
false,
true,
true);
674 private void handleEnableTransferFunctionMenu(
object sender, EventArgs e)
676 if (enableTransferfunctionToolStripMenuItem.Checked)
678 enableTransferfunctionToolStripMenuItem.Checked =
false;
679 transferfunctionCheckBox1.Checked =
false;
681 else enableTransferfunctionToolStripMenuItem.Checked =
true;
682 transferfunctionCheckBox.Checked = enableTransferfunctionToolStripMenuItem.Checked;
684 #region update engine state
685 GameProperties.Instance.enableTransferFunction = enableTransferfunctionToolStripMenuItem.Checked;
686 GameProperties.Instance.enableTransferAlphaValues = transferfunctionCheckBox1.Checked;
687 updateXnaEngineState(
false,
false,
true,
true);
690 #region update tf control state
691 TransferFunctionPanel.EnableTransferFunction = enableTransferfunctionToolStripMenuItem.Checked;
692 TransferFunctionPanel.Refresh();
701 private void handleLoadTransferFunctionMenu(
object sender, EventArgs e)
703 string relativePath = Path.Combine(assemblyLocation,
"../../../../Data/Transferfunction");
704 string contentPath = Path.GetFullPath(relativePath);
706 this.openFileDialog.InitialDirectory = contentPath;
708 this.openFileDialog.Title =
"Load Transferfunction";
710 this.openFileDialog.Filter =
"XML Files (*.xml)|*.xml";
712 if (this.openFileDialog.ShowDialog() == DialogResult.OK)
714 loadTransferFunction(openFileDialog.FileName);
716 #region update engine state
717 updateXnaEngineState(
false,
false,
true,
true);
720 #region update transferfunction state
721 TransferFunctionPanel.GetControlPoints =
true;
722 TransferFunctionPanel.Refresh();
733 private void handleSaveTransferFunctionMenu(
object sender, EventArgs e)
735 string relativePath = Path.Combine(assemblyLocation,
"../../../../Data/Transferfunction");
736 string contentPath = Path.GetFullPath(relativePath);
738 this.saveFileDialog.InitialDirectory = contentPath;
740 this.saveFileDialog.Title =
"Save Transferfunction as";
742 this.saveFileDialog.Filter =
"XML Files (*.xml)|*.xml";
744 if (this.saveFileDialog.ShowDialog() == DialogResult.OK)
746 saveTransferFunction(saveFileDialog.FileName);
756 private void handleEditTransferFunctionMenu(
object sender, EventArgs e)
759 transferFunctionDialog.Show();
770 #region settings panel (right tab panel)
773 private void handleSliceNumericUpDown(
object sender, EventArgs e)
780 if (sender == XSliceNumericUpDown)
782 XSlider.Value = Decimal.ToInt32(Decimal.Multiply(XSliceNumericUpDown.Value,
new Decimal(XSlider.Maximum)));
783 GameProperties.Instance.xSliceValue = (float)XSliceNumericUpDown.Value;
786 else if (sender == YSliceNumericUpDown)
788 YSlider.Value = Decimal.ToInt32(Decimal.Multiply(YSliceNumericUpDown.Value,
new Decimal(YSlider.Maximum)));
789 GameProperties.Instance.ySliceValue = (float)YSliceNumericUpDown.Value;
792 else if (sender == ZSliceNumericUpDown)
794 ZSlider.Value = Decimal.ToInt32(Decimal.Multiply(ZSliceNumericUpDown.Value,
new Decimal(ZSlider.Maximum)));
795 GameProperties.Instance.zSliceValue = (float)ZSliceNumericUpDown.Value;
802 slicingDialog.setSlicingGroups(1, XSliceNumericUpDown.Increment, XSliceNumericUpDown.DecimalPlaces, XSliceNumericUpDown.Value);
803 slicingDialog.setSlicingGroups(2, YSliceNumericUpDown.Increment, YSliceNumericUpDown.DecimalPlaces, YSliceNumericUpDown.Value);
804 slicingDialog.setSlicingGroups(3, ZSliceNumericUpDown.Increment, YSliceNumericUpDown.DecimalPlaces, ZSliceNumericUpDown.Value);
805 slicingDialog.setSlicingGroups(1, XSlider.Maximum, XSlider.Value);
806 slicingDialog.setSlicingGroups(2, YSlider.Maximum, YSlider.Value);
807 slicingDialog.setSlicingGroups(3, ZSlider.Maximum, ZSlider.Value);
808 slicingDialog.Refresh();
811 if (!GameProperties.Instance.viewMode.Equals(
ViewMode.VolView))
813 updateXnaEngineState(
false,
false,
false,
true);
822 private void handleScrollSlider(
object sender, EventArgs e)
824 if (sender == XSlider)
826 Decimal newValue = Decimal.Divide(
new Decimal(XSlider.Value),
new Decimal(XSlider.Maximum));
827 XSliceNumericUpDown.Value = newValue;
828 GameProperties.Instance.xSliceValue = (float)newValue;
830 else if (sender == YSlider)
832 Decimal newValue = Decimal.Divide(
new Decimal(YSlider.Value),
new Decimal(YSlider.Maximum));
833 YSliceNumericUpDown.Value = newValue;
834 GameProperties.Instance.ySliceValue = (float)newValue;
837 else if (sender == ZSlider)
839 Decimal newValue = Decimal.Divide(
new Decimal(ZSlider.Value),
new Decimal(ZSlider.Maximum));
840 ZSliceNumericUpDown.Value = newValue;
841 GameProperties.Instance.zSliceValue = (float)newValue;
848 slicingDialog.setSlicingGroups(1, XSliceNumericUpDown.Increment, XSliceNumericUpDown.DecimalPlaces, XSliceNumericUpDown.Value);
849 slicingDialog.setSlicingGroups(2, YSliceNumericUpDown.Increment, YSliceNumericUpDown.DecimalPlaces, YSliceNumericUpDown.Value);
850 slicingDialog.setSlicingGroups(3, ZSliceNumericUpDown.Increment, YSliceNumericUpDown.DecimalPlaces, ZSliceNumericUpDown.Value);
851 slicingDialog.setSlicingGroups(1, XSlider.Maximum, XSlider.Value);
852 slicingDialog.setSlicingGroups(2, YSlider.Maximum, YSlider.Value);
853 slicingDialog.setSlicingGroups(3, ZSlider.Maximum, ZSlider.Value);
854 slicingDialog.Refresh();
857 if (!GameProperties.Instance.viewMode.Equals(
ViewMode.VolView))
859 updateXnaEngineState(
false,
false,
false,
true);
865 #region transfer function panel
866 private void handleTransferFunctionCheckbox(
object sender, EventArgs e)
874 if (!transferfunctionCheckBox.Checked) transferfunctionCheckBox1.Checked =
false;
875 enableTransferfunctionToolStripMenuItem.Checked = transferfunctionCheckBox.Checked;
877 #region set engine control
878 GameProperties.Instance.enableTransferFunction = transferfunctionCheckBox.Checked;
879 GameProperties.Instance.enableTransferAlphaValues = transferfunctionCheckBox1.Checked;
880 updateXnaEngineState(
false,
false,
true,
true);
883 #region set tf control
884 TransferFunctionPanel.EnableTransferFunction = transferfunctionCheckBox.Checked;
885 TransferFunctionPanel.Refresh();
894 private void handleTransferFunctionCheckbox1(
object sender, EventArgs e)
896 if (transferfunctionCheckBox1.Checked && !transferfunctionCheckBox.Checked) transferfunctionCheckBox1.Checked =
false;
898 #region set engine control
899 if (GameProperties.Instance.enableTransferAlphaValues == transferfunctionCheckBox1.Checked)
return;
900 GameProperties.Instance.enableTransferAlphaValues = transferfunctionCheckBox1.Checked;
901 updateXnaEngineState(
false,
false,
true,
true);
911 private void handleTransferFunctionCheckbox2(
object sender, EventArgs e)
913 GameProperties.Instance.showDensityValue = transferfunctionCheckBox2.Checked;
914 TransferFunctionPanel.DensityFunction = transferfunctionCheckBox2.Checked;
915 TransferFunctionPanel.Refresh();
926 private void TransferFunctionPanel_MouseDown(
object sender, MouseEventArgs e)
928 if (!transferfunctionCheckBox.Checked)
return;
930 Point newPos = clampToPanelDimensions(e.X, e.Y);
932 if (e.Button == MouseButtons.Left)
934 tfPanelMouseDown =
true;
935 tfPanelMouseDownPos = newPos;
938 #region create new control point or edit one
939 if (e.Button == MouseButtons.Right)
941 ColorDialog colorPicker =
new ColorDialog();
943 if (colorPicker.ShowDialog() == DialogResult.OK)
945 TransferFunctionPanel.setControlPoint(newPos, colorPicker.Color);
946 TransferFunctionPanel.SetControlPoints =
true;
947 TransferFunctionPanel.Refresh();
948 updateXnaEngineState(
false,
false,
true,
true);
961 private void TransferFunctionPanel_MouseMove(
object sender, MouseEventArgs e)
963 if (!transferfunctionCheckBox.Checked)
return;
967 if (tfPanelMouseDown)
970 Point newPos = clampToPanelDimensions(e.X, e.Y);
971 if (TransferFunctionPanel.changeControlPoint(tfPanelMouseDownPos, newPos))
973 TransferFunctionPanel.SetControlPoints =
true;
974 TransferFunctionPanel.Refresh();
976 tfPanelMouseDownPos = newPos;
988 private void TransferFunctionPanel_MouseUp(
object sender, MouseEventArgs e)
991 tfPanelMouseDown =
false;
992 updateXnaEngineState(
false,
false,
true,
true);
1000 private void TransferFunctionPanel_MouseDoubleClick(
object sender, MouseEventArgs e)
1002 if (!transferfunctionCheckBox.Checked)
return;
1004 Point cpPos = clampToPanelDimensions(e.X, e.Y);
1005 if(TransferFunctionPanel.removeControlPoint(cpPos))
1007 TransferFunctionPanel.SetControlPoints =
true;
1008 TransferFunctionPanel.Refresh();
1009 updateXnaEngineState(
false,
false,
true,
true);
1016 #region extended features
1017 private void handleEnableCVDCheckBox(
object sender, EventArgs e)
1024 if (enableCVDCheckBox.Checked)
1026 this.cvdViewCheckBox1.Checked = GameProperties.Instance.originalView;
1027 this.cvdViewCheckBox2.Checked = GameProperties.Instance.recoloredView;
1028 this.cvdViewCheckBox3.Checked = GameProperties.Instance.cvdView;
1029 this.cvdViewCheckBox4.Checked = GameProperties.Instance.simulate;
1030 this.cvdViewCheckBox1.Enabled =
true;
1031 this.cvdViewCheckBox2.Enabled =
true;
1032 this.cvdViewCheckBox3.Enabled =
true;
1033 this.cvdViewCheckBox4.Enabled =
true;
1034 this.cvdRadioButton1.Enabled =
true;
1035 this.cvdRadioButton2.Enabled =
true;
1036 this.cvdRadioButton3.Enabled =
true;
1042 this.cvdViewCheckBox1.Enabled =
false;
1043 this.cvdViewCheckBox2.Enabled =
false;
1044 this.cvdViewCheckBox3.Enabled =
false;
1045 this.cvdViewCheckBox4.Enabled =
false;
1046 this.cvdRadioButton1.Enabled =
false;
1047 this.cvdRadioButton2.Enabled =
false;
1048 this.cvdRadioButton3.Enabled =
false;
1052 GameProperties.Instance.enableCVDView = enableCVDCheckBox.Checked;
1053 updateXnaEngineState(
true,
false,
true,
true);
1062 private void handleEnableCVDViewCheckBox1(
object sender, EventArgs e)
1064 if (this.cvdViewCheckBox1.Checked)
1066 volViewToolStripMenuItem.Checked =
true;
1067 GameProperties.Instance.viewMode =
ViewMode.VolView;
1071 volViewToolStripMenuItem.Checked =
false;
1074 GameProperties.Instance.originalView = cvdViewCheckBox1.Checked;
1075 updateXnaEngineState(
true,
false,
true,
true);
1084 private void handleEnableCVDViewCheckBox2(
object sender, EventArgs e)
1086 if (this.cvdViewCheckBox2.Checked)
1089 this.recoloredViewToolStripMenuItem.Checked =
true;
1090 GameProperties.Instance.triggerRecolor =
true;
1094 this.recoloredViewToolStripMenuItem.Checked =
false;
1095 GameProperties.Instance.triggerRecolor =
false;
1098 GameProperties.Instance.recoloredView = cvdViewCheckBox2.Checked;
1099 updateXnaEngineState(
true,
false,
true,
true);
1108 private void handleEnableCVDViewCheckBox3(
object sender, EventArgs e)
1110 if (this.cvdViewCheckBox3.Checked)
1113 GameProperties.Instance.triggerOptimize =
true;
1114 GameProperties.Instance.CVDTFOptimized =
false;
1115 GameProperties.Instance.cvdView =
true;
1120 GameProperties.Instance.triggerOptimize =
false;
1121 GameProperties.Instance.cvdView =
false;
1125 updateXnaEngineState(
true,
false,
true,
true);
1135 private void handleEnableCVDViewCheckBox4(
object sender, EventArgs e)
1137 if (this.cvdViewCheckBox4.Checked ==
true)
1140 GameProperties.Instance.triggerSimulate =
true;
1144 GameProperties.Instance.triggerSimulate =
false;
1147 GameProperties.Instance.simulatedView = cvdViewCheckBox4.Checked;
1148 updateXnaEngineState(
true,
false,
true,
true);
1156 private void handleMaxIntensityProjCheckBox(
object sender, EventArgs e)
1158 if (MaxIntensityProjCheckBox.Checked)
1160 maximumIntensityProjectionToolStripMenuItem.Checked =
true;
1164 maximumIntensityProjectionToolStripMenuItem.Checked =
false;
1166 GameProperties.Instance.maximumIntensityProjection = MaxIntensityProjCheckBox.Checked;
1167 updateXnaEngineState(
true,
false,
true,
true);
1175 private void handlePerspProjRadioButt(
object sender, EventArgs e)
1177 perspectiveProjectionToolStripMenuItem.Checked =
true;
1178 orthogonalProjectionToolStripMenuItem.Checked =
false;
1179 GameProperties.Instance.perspectiveProjection =
true;
1180 updateXnaEngineState(
true,
false,
true,
true);
1189 private void handleCVDTypeRadioButtons(
object sender, EventArgs e)
1207 if (this.cvdRadioButton1.Checked)
1209 GameProperties.Instance.cvdType =
CVDType.Deuteranopy;
1210 GameProperties.Instance.CVD =
"deuteranopy";
1211 GameProperties.Instance.triggerRecolor =
true;
1212 GameProperties.Instance.triggerOptimize =
true;
1213 GameProperties.Instance.CVDTFOptimized =
false;
1215 else if (this.cvdRadioButton2.Checked)
1217 GameProperties.Instance.cvdType =
CVDType.Protanopy;
1218 GameProperties.Instance.CVD =
"protanopy";
1219 GameProperties.Instance.triggerRecolor =
true;
1220 GameProperties.Instance.triggerOptimize =
true;
1221 GameProperties.Instance.CVDTFOptimized =
false;
1223 else if (this.cvdRadioButton3.Checked)
1225 GameProperties.Instance.cvdType =
CVDType.Tritanopy;
1226 GameProperties.Instance.CVD =
"tritanopy";
1227 GameProperties.Instance.triggerRecolor =
true;
1228 GameProperties.Instance.triggerOptimize =
true;
1229 GameProperties.Instance.CVDTFOptimized =
false;
1232 updateXnaEngineState(
true,
false,
true,
true);
1241 private void handleOrthProjRadioButt(
object sender, EventArgs e)
1243 perspectiveProjectionToolStripMenuItem.Checked =
false;
1244 orthogonalProjectionToolStripMenuItem.Checked =
true;
1245 GameProperties.Instance.perspectiveProjection =
false;
1246 updateXnaEngineState(
true,
false,
true,
true);
1254 private void handleBlendRadioButt1(
object sender, EventArgs e)
1256 frontToBackBlendingToolStripMenuItem.Checked =
true;
1257 backToFrontBlendingToolStripMenuItem.Checked =
false;
1258 GameProperties.Instance.enableFrontToBackBlend =
true;
1259 updateXnaEngineState(
true,
false,
true,
true);
1267 private void handleBlendRadioButt2(
object sender, EventArgs e)
1269 frontToBackBlendingToolStripMenuItem.Checked =
false;
1270 backToFrontBlendingToolStripMenuItem.Checked =
true;
1271 GameProperties.Instance.enableFrontToBackBlend =
false;
1272 updateXnaEngineState(
true,
false,
true,
true);
1280 private void handleShadingCheckBox(
object sender, EventArgs e)
1282 if (ShadingCheckBox.Checked)
1284 shadingToolStripMenuItem.Checked =
true;
1288 shadingToolStripMenuItem.Checked =
false;
1290 GameProperties.Instance.enableShading = ShadingCheckBox.Checked;
1291 updateXnaEngineState(
true,
false,
true,
true);
1300 #region handle xna draw surface events
1301 private void handleXNADrawSurface_MouseDoubleClick(
object sender, MouseEventArgs e)
1310 switch (GameProperties.Instance.viewMode)
1313 GameProperties.Instance.viewMode =
ViewMode.TopView;
1314 volViewToolStripMenuItem.Checked =
false;
1315 topViewToolStripMenuItem.Checked =
true;
1316 sideViewToolStripMenuItem.Checked =
false;
1317 frontViewToolStripMenuItem.Checked =
false;
1320 GameProperties.Instance.viewMode =
ViewMode.SideView;
1321 volViewToolStripMenuItem.Checked =
false;
1322 topViewToolStripMenuItem.Checked =
false;
1323 sideViewToolStripMenuItem.Checked =
true;
1324 frontViewToolStripMenuItem.Checked =
false;
1327 GameProperties.Instance.viewMode =
ViewMode.FrontView;
1328 volViewToolStripMenuItem.Checked =
false;
1329 topViewToolStripMenuItem.Checked =
false;
1330 sideViewToolStripMenuItem.Checked =
false;
1331 frontViewToolStripMenuItem.Checked =
true;
1334 GameProperties.Instance.viewMode =
ViewMode.VolView;
1335 volViewToolStripMenuItem.Checked =
true;
1336 topViewToolStripMenuItem.Checked =
false;
1337 sideViewToolStripMenuItem.Checked =
false;
1338 frontViewToolStripMenuItem.Checked =
false;
1341 GameProperties.Instance.viewMode =
ViewMode.VolView;
1342 volViewToolStripMenuItem.Checked =
true;
1343 topViewToolStripMenuItem.Checked =
false;
1344 sideViewToolStripMenuItem.Checked =
false;
1345 frontViewToolStripMenuItem.Checked =
false;
1349 updateXnaEngineState(
true,
false,
true,
true);
1361 private void handleXNADrawSurface_MouseDown(
object sender, MouseEventArgs e)
1363 if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
1365 XnaDrawSurface_MouseDownEvent =
true;
1366 mouseDownPosX = (int)MathHelper.Clamp(e.X, 0, XNADrawSurface.Width-1);
1367 mouseDownPosY = (int)MathHelper.Clamp(e.Y, 0, XNADrawSurface.Height - 1);
1379 private void handleXNADrawSurface_MouseUp(
object sender, MouseEventArgs e)
1384 GameProperties.Instance.cameraInput = Vector3.Zero;
1385 XnaDrawSurface_MouseDownEvent =
false;
1394 private void handleXNADrawSurface_MouseMove(
object sender, MouseEventArgs e)
1396 if (XnaDrawSurface_MouseDownEvent)
1398 int nextPosX = (int)MathHelper.Clamp(e.X, 0, XNADrawSurface.Width - 1);
1399 int nextPosY = (int)MathHelper.Clamp(e.Y, 0, XNADrawSurface.Height - 1);
1401 int moveX = nextPosX - mouseDownPosX;
1402 int moveY = mouseDownPosY - nextPosY;
1405 if (e.Button == MouseButtons.Left)
1407 GameProperties.Instance.cameraInput.X = moveX;
1408 GameProperties.Instance.cameraInput.Y = moveY;
1410 else if (e.Button == MouseButtons.Right)
1412 GameProperties.Instance.cameraInput.Z = moveY;
1414 mouseDownPosX = nextPosX;
1415 mouseDownPosY = nextPosY;
1416 updateXnaEngineState(
true,
false,
true,
true);
1426 private void handleXNADrawSurface_MouseScroll(
object sender, MouseEventArgs e)
1428 if (XnaDrawSurface_MouseDownEvent)
1432 int numberLinesToMove = e.Delta * SystemInformation.MouseWheelScrollLines / 120;
1433 GameProperties.Instance.cameraInput.Z = numberLinesToMove;
1434 Console.WriteLine(
"Camera zoom: " + GameProperties.Instance.cameraInput.Z);
1435 updateXnaEngineState(
true,
false,
true,
true);
1445 private void XNADrawSurface_KeyPress(
object sender, KeyPressEventArgs e)
1494 #region add functions
1505 public void updateTFState(
bool enableTF,
bool drawDF,
bool setCP,
bool getCP,
bool updateDF)
1507 this.TransferFunctionPanel.EnableTransferFunction = enableTF;
1508 this.TransferFunctionPanel.DensityFunction = drawDF;
1509 if (setCP && getCP) { setCP =
false; getCP =
true; }
1510 this.TransferFunctionPanel.SetControlPoints = setCP;
1511 this.TransferFunctionPanel.GetControlPoints = getCP;
1512 this.TransferFunctionPanel.UpdateIsoValues = updateDF;
1513 if (enableTF || drawDF || setCP || getCP || updateDF) this.TransferFunctionPanel.Refresh();
1529 if (updateCam || load || update || draw) this.XNADrawSurface.Refresh();
1541 XmlTextReader xmlReader =
new XmlTextReader(fileName);
1542 xmlReader.MoveToElement();
1550 while (xmlReader.Read())
1552 if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name.Equals(
"ControlPoint"))
1554 while (!(xmlReader.NodeType == XmlNodeType.EndElement && xmlReader.Name.Equals(
"ControlPoint")))
1558 if (xmlReader.NodeType.Equals(XmlNodeType.Element))
1560 String elementName = xmlReader.Name;
1562 if (xmlReader.NodeType.Equals(XmlNodeType.Text))
1564 switch (elementName)
1567 r =
float.Parse(xmlReader.Value);
1571 g =
float.Parse(xmlReader.Value);
1575 b =
float.Parse(xmlReader.Value);
1579 a =
float.Parse(xmlReader.Value);
1583 isoValue =
int.Parse(xmlReader.Value);
1602 XmlTextWriter xmlWriter =
new XmlTextWriter(fileName, null);
1604 xmlWriter.WriteStartDocument();
1605 xmlWriter.WriteStartElement(
"TransferFunction");
1607 for (
int i = 0; i <
GameProperties.Instance.colorControlPoints.Count(); i++)
1609 xmlWriter.WriteStartElement(
"ControlPoint");
1611 xmlWriter.WriteStartElement(
"ColorR");
1612 xmlWriter.WriteString(
GameProperties.Instance.colorControlPoints[i].color.X.ToString());
1613 xmlWriter.WriteEndElement();
1615 xmlWriter.WriteStartElement(
"ColorG");
1616 xmlWriter.WriteString(
GameProperties.Instance.colorControlPoints[i].color.Y.ToString());
1617 xmlWriter.WriteEndElement();
1619 xmlWriter.WriteStartElement(
"ColorB");
1620 xmlWriter.WriteString(
GameProperties.Instance.colorControlPoints[i].color.Z.ToString());
1621 xmlWriter.WriteEndElement();
1623 xmlWriter.WriteStartElement(
"ColorA");
1624 xmlWriter.WriteString(
GameProperties.Instance.alphaControlPoints[i].color.W.ToString());
1625 xmlWriter.WriteEndElement();
1627 xmlWriter.WriteStartElement(
"IsoValue");
1628 xmlWriter.WriteString(
GameProperties.Instance.colorControlPoints[i].isoValue.ToString());
1629 xmlWriter.WriteEndElement();
1631 xmlWriter.WriteEndElement();
1634 xmlWriter.WriteEndElement();
1635 xmlWriter.WriteEndDocument();
1639 private Point clampToPanelDimensions(
int posX,
int posY)
1641 Point p =
new Point(posX, posY);
1642 if (p.X < 0) { p.X = 0; }
1643 else if (p.X >
this.TransferFunctionPanel.Width - 1)
1644 { p.X = this.TransferFunctionPanel.Width - 1; }
1645 if (p.Y < 0) { p.Y = 0; }
1646 else if (p.Y >
this.TransferFunctionPanel.Height - 1)
1647 { p.Y = this.TransferFunctionPanel.Height - 1; }
1654 protected override void WndProc(ref Message m)
1658 if (m.Msg == 0x0112)
1660 if (m.WParam ==
new IntPtr(0xF030)
1661 || m.WParam ==
new IntPtr(0xF120))
1664 updateXnaEngineState(
true,
false,
true,
true);
1669 base.WndProc(ref m);
1672 private void toolStripMenuItem3_Click(
object sender, EventArgs e)