VIS2 SS2013 CVD DVR
 All Classes Namespaces Functions Enumerations Properties
MainWindow.cs
1 #region using statemens
2 using System;
3 using System.IO;
4 using System.Reflection;
5 using System.Collections.Generic;
6 using System.ComponentModel;
7 using System.Data;
8 using System.Drawing;
9 using System.Linq;
10 using System.Text;
11 using System.Xml;
12 using System.Windows.Forms;
13 using Microsoft.Xna.Framework;
14 using visLU.Gui;
15 #endregion
16 
17 namespace visLU.Gui
18 {
19  using Point = System.Drawing.Point;
20 
24  public partial class MainWindow : Form
25  {
26  #region Tranfer function variables
27  bool tfPanelMouseDown = false;
28  Point tfPanelMouseDownPos = new Point();
29  #endregion
30 
31  #region XNA Viewport variables
32  bool xnaDrawSurface_MouseDownEvent = false;
33  int mouseDownPosX, mouseDownPosY, mouseDownPosZ = 0;
34  Vector3 mouseMovePos;
35  #endregion
36 
37  #region other variables
38  string assemblyLocation = Assembly.GetExecutingAssembly().Location;
39 
40  SlicingForm slicingDialog;
41  bool sliceFormOpen;
42  #endregion
43 
44  #region Properties
45  public bool XnaDrawSurface_MouseDownEvent
46  {
47  set { xnaDrawSurface_MouseDownEvent = value; }
48  get { return xnaDrawSurface_MouseDownEvent; }
49 
50  }
51 
52  public int MouseDownPosX
53  {
54  set { mouseDownPosX = value; }
55  }
56  public int MouseDownPosY
57  {
58  set { mouseDownPosY = value; }
59  }
60  public Vector3 MouseMovePos
61  {
62  set { MouseMovePos = value; }
63  }
64 
65  public bool SliceFormOpen
66  {
67  set { sliceFormOpen = value; }
68  get { return sliceFormOpen; }
69  }
70 
71  #endregion
72 
76  public MainWindow()
77  {
78  InitializeComponent();
79  SetStyle(ControlStyles.OptimizedDoubleBuffer |
80  ControlStyles.UserPaint |
81  ControlStyles.AllPaintingInWmPaint, true);
82 
83  #region init child controls
84  slicingDialog = null;
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;
92  this.cvdViewCheckBox3.Checked = GameProperties.Instance.cvdView;
93  this.cvdViewCheckBox4.Checked = GameProperties.Instance.simulate;
94  //this.cvdViewToolStripMenuItem.Checked = GameProperties.Instance.cvdView;
95  //this.recoloredViewToolStripMenuItem.Checked = GameProperties.Instance.recoloredView;
96  switch (GameProperties.Instance.cvdType)
97  {
98  case CVDType.Deuteranopy:
99  this.cvdRadioButton1.Checked = true;
100  this.cvdRadioButton2.Checked = false;
101  this.cvdRadioButton3.Checked = false;
102  break;
103  case CVDType.Protanopy:
104  this.cvdRadioButton1.Checked = false;
105  this.cvdRadioButton2.Checked = true;
106  this.cvdRadioButton3.Checked = false;
107  break;
108  case CVDType.Tritanopy:
109  this.cvdRadioButton1.Checked = false;
110  this.cvdRadioButton2.Checked = false;
111  this.cvdRadioButton3.Checked = true;
112  break;
113  default:
114  this.cvdRadioButton1.Checked = true;
115  this.cvdRadioButton2.Checked = false;
116  this.cvdRadioButton3.Checked = false;
117  break;
118  }
119 
120  if (GameProperties.Instance.enableCVDView)
121  {
122  this.cvdViewCheckBox1.Enabled = true;
123  this.cvdViewCheckBox2.Enabled = true;
124  this.cvdViewCheckBox3.Enabled = true;
125  //this.cvdViewToolStripMenuItem.Enabled = true;
126  //this.recoloredViewToolStripMenuItem.Enabled = true;
127  this.cvdRadioButton1.Enabled = true;
128  this.cvdRadioButton2.Enabled = true;
129  this.cvdRadioButton3.Enabled = true;
130  }
131  else
132  {
133  this.cvdViewCheckBox1.Enabled = false;
134  this.cvdViewCheckBox2.Enabled = false;
135  this.cvdViewCheckBox3.Enabled = false;
136  //this.cvdViewToolStripMenuItem.Enabled = false;
137  //this.recoloredViewToolStripMenuItem.Enabled = false;
138  this.cvdRadioButton1.Enabled = false;
139  this.cvdRadioButton2.Enabled = false;
140  this.cvdRadioButton3.Enabled = false;
141  }
142 
143  switch (GameProperties.Instance.viewMode)
144  {
145  case ViewMode.VolView:
146  volViewToolStripMenuItem.Checked = true;
147  break;
148  case ViewMode.TopView:
149  topViewToolStripMenuItem.Checked = true;
150  break;
151  case ViewMode.SideView:
152  sideViewToolStripMenuItem.Checked = true;
153  break;
154  case ViewMode.FrontView:
155  frontViewToolStripMenuItem.Checked = true;
156  break;
157  default:
158  volViewToolStripMenuItem.Checked = true;
159  break;
160  }
161 
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;
167 
168  #endregion
169  }
170 
171  #region update controls
172  public void updateSliceControls(int xRange, int yRange, int zRange)
179  {
180  //x Slice / side view
181  Decimal xIncrement = Decimal.Divide(XSliceNumericUpDown.Maximum, new Decimal(xRange));
182  //string xString = xIncrement.ToString();
183  //int xDecimalPlaces = xString.Substring(xString.IndexOf(",") + 1).Length;
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;
190 
191  //y Slice / top view
192  Decimal yIncrement = Decimal.Divide(YSliceNumericUpDown.Maximum, new Decimal(yRange));
193  //string yString = yIncrement.ToString();
194  //int yDecimalPlaces = yString.Substring(yString.IndexOf(",") + 1).Length;
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;
201 
202  //z Slice / front
203  Decimal zIncrement = Decimal.Divide(ZSliceNumericUpDown.Maximum, new Decimal(zRange));
204  //string zString = zIncrement.ToString();
205  //int zDecimalPlaces = zString.Substring(zString.IndexOf(",") + 1).Length;
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;
212 
213  XSliceGroup.Refresh();
214  YSliceGroup.Refresh();
215  ZSliceGroup.Refresh();
216  }
217 
225  public void setSlicingGroups(int slice, Decimal increment, int decimalPlaces, Decimal value)
226  {
227  switch (slice)
228  {
229  case 1:
230  XSliceNumericUpDown.Increment = increment;
231  XSliceNumericUpDown.DecimalPlaces = decimalPlaces;
232  XSliceNumericUpDown.Value = value;
233  break;
234  case 2:
235  YSliceNumericUpDown.Increment = increment;
236  YSliceNumericUpDown.DecimalPlaces = decimalPlaces;
237  YSliceNumericUpDown.Value = value;
238  break;
239  case 3:
240  ZSliceNumericUpDown.Increment = increment;
241  ZSliceNumericUpDown.DecimalPlaces = decimalPlaces;
242  ZSliceNumericUpDown.Value = value;
243  break;
244  default:
245  break;
246 
247  }
248 
249  }
250 
257  public void setSlicingGroups(int slice, int maximum, int value)
258  {
259  switch (slice)
260  {
261  case 1:
262  XSlider.Maximum = maximum;
263  XSlider.Value = value;
264  break;
265  case 2:
266  YSlider.Maximum = maximum;
267  YSlider.Value = value;
268  break;
269  case 3:
270  ZSlider.Maximum = maximum;
271  ZSlider.Value = value;
272  break;
273  default:
274  break;
275 
276  }
277 
278  }
279 
280  public void updateSliceGroups()
281  {
282  XSliceGroup.Refresh();
283  YSliceGroup.Refresh();
284  ZSliceGroup.Refresh();
285  }
286  #endregion
287 
288  #region event handler
289 
290  #region main menu handler
291 
292  #region file menu
293  private void handleOpenFileMenu(object sender, EventArgs e)
300  {
301  // Default to the directory which contains our content files.
302  //string assemblyLocation = Assembly.GetExecutingAssembly().Location;
303  string relativePath = Path.Combine(assemblyLocation, "../../../../Data");
304  string contentPath = Path.GetFullPath(relativePath);
305 
306  this.openFileDialog.InitialDirectory = contentPath;
307 
308  this.openFileDialog.Title = "Load Data Set";
309 
310  this.openFileDialog.Filter = "Data Files (*.dat)|*.dat";
311 
312  if (this.openFileDialog.ShowDialog() == DialogResult.OK)
313  {
314  #region set engine control
315  GameProperties.Instance.dataFilename = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf("\\") + 1);
316  updateXnaEngineState(true, true, true, true);
317  #endregion
318 
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();
324  #endregion
325  }
326  }
327 
333  private void handleSaveFileMenu(object sender, EventArgs e)
334  {
335  string relativePath = Path.Combine(assemblyLocation, "../../../../Data/Screenshots");
336  string contentPath = Path.GetFullPath(relativePath);
337 
338  this.saveFileDialog.InitialDirectory = contentPath;
339 
340  this.saveFileDialog.Title = "Save Image as";
341 
342  this.saveFileDialog.Filter = "PNG Files (*.png)|*.png";
343 
344  if (this.saveFileDialog.ShowDialog() == DialogResult.OK)
345  {
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();
351  #endregion
352  }
353  }
354 
360  private void handleExitMenu(object sender, EventArgs e)
361  {
362  System.Windows.Forms.Application.Exit();
363 
364  }
365 
371  private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
372  {
373  //todo?
374  }
375  #endregion
376 
377  #region view menu
378  private void handleViewMenuOnClick(object sender, EventArgs e)
384  {
385  if(sender == this.SingleToolStripMenuItem)
386  {
387  SingleToolStripMenuItem.Checked = true;
388  SplitToolStripMenuItem.Checked = false;
389  GameProperties.Instance.viewportMode = ViewportMode.Single;
390 
391  volViewToolStripMenuItem.Enabled = true;
392  topViewToolStripMenuItem.Enabled = true;
393  sideViewToolStripMenuItem.Enabled = true;
394  frontViewToolStripMenuItem.Enabled = true;
395 
396  }
397  else if (sender == this.SplitToolStripMenuItem)
398  {
399  SingleToolStripMenuItem.Checked = false;
400  SplitToolStripMenuItem.Checked = true;
401  GameProperties.Instance.viewportMode = ViewportMode.Split4;
402 
403  volViewToolStripMenuItem.Enabled = false;
404  topViewToolStripMenuItem.Enabled = false;
405  sideViewToolStripMenuItem.Enabled = false;
406  frontViewToolStripMenuItem.Enabled = false;
407  }
408 
409  else if (sender == this.volViewToolStripMenuItem)
410  {
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)
417  {
418  //cvdViewCheckBox1.Checked = volViewToolStripMenuItem.Checked;
419  //recoloredViewToolStripMenuItem.Checked = GameProperties.Instance.recoloredView;
420  //cvdViewToolStripMenuItem.Checked = GameProperties.Instance.cvdView;
421  GameProperties.Instance.originalView = volViewToolStripMenuItem.Checked;
422  }
423  }
424  else if (sender == this.topViewToolStripMenuItem)
425  {
426  volViewToolStripMenuItem.Checked = false;
427  topViewToolStripMenuItem.Checked = true;
428  sideViewToolStripMenuItem.Checked = false;
429  frontViewToolStripMenuItem.Checked = false;
430  recoloredViewToolStripMenuItem.Checked = false;
431  //cvdViewToolStripMenuItem.Checked = false;
432  GameProperties.Instance.viewMode = ViewMode.TopView;
433  }
434  else if (sender == this.sideViewToolStripMenuItem)
435  {
436  volViewToolStripMenuItem.Checked = false;
437  topViewToolStripMenuItem.Checked = false;
438  sideViewToolStripMenuItem.Checked = true;
439  frontViewToolStripMenuItem.Checked = false;
440  recoloredViewToolStripMenuItem.Checked = false;
441  //cvdViewToolStripMenuItem.Checked = false;
442  GameProperties.Instance.viewMode = ViewMode.SideView;
443  }
444  else if (sender == this.frontViewToolStripMenuItem)
445  {
446  volViewToolStripMenuItem.Checked = false;
447  topViewToolStripMenuItem.Checked = false;
448  sideViewToolStripMenuItem.Checked = false;
449  frontViewToolStripMenuItem.Checked = true;
450  recoloredViewToolStripMenuItem.Checked = false;
451  // cvdViewToolStripMenuItem.Checked = false;
452  GameProperties.Instance.viewMode = ViewMode.FrontView;
453  }
454  else if (sender == this.recoloredViewToolStripMenuItem)
455  {
456  //volViewToolStripMenuItem.Checked = false;
457  topViewToolStripMenuItem.Checked = false;
458  sideViewToolStripMenuItem.Checked = false;
459  frontViewToolStripMenuItem.Checked = false;
460  recoloredViewToolStripMenuItem.Checked = !recoloredViewToolStripMenuItem.Checked;
461  //cvdViewToolStripMenuItem.Checked = false;
462  GameProperties.Instance.recoloredView = recoloredViewToolStripMenuItem.Checked;
463  if (GameProperties.Instance.enableCVDView)
464  {
465  cvdViewCheckBox2.Checked = recoloredViewToolStripMenuItem.Checked;
466  }
467  }
468  else if (sender == this.cvdViewToolStripMenuItem)
469  {
470  /*//volViewToolStripMenuItem.Checked = false;
471  topViewToolStripMenuItem.Checked = false;
472  sideViewToolStripMenuItem.Checked = false;
473  frontViewToolStripMenuItem.Checked = false;
474  //recoloredViewToolStripMenuItem.Checked = false;
475  cvdViewToolStripMenuItem.Checked = !cvdViewToolStripMenuItem.Checked;
476  GameProperties.Instance.cvdView = cvdViewToolStripMenuItem.Checked;
477  if (GameProperties.Instance.enableCVDView)
478  {
479  cvdViewCheckBox3.Checked = cvdViewToolStripMenuItem.Checked;
480  }*/
481  }
482 
483  // updateXnaEngineState(true, false, true, true);
484  }
485 
491  private void handleZoomMenuOnCLick(object sender, EventArgs e)
492  {
493 
494  /*if (sender == this.zoomInToolStripMenuItem) inputManager.setZoom(1);
495  if (sender == this.zoomOutToolStripMenuItem) inputManager.setZoom(-1);
496  //inputManager.setZoom(e.Delta / SystemInformation.MouseWheelScrollDelta);
497  //inputManager.setZoom(e.Delta);
498  inputManager.updateXnaEngineState(true, false, true, true);*/
499  }
500  #endregion
501 
502  #region functions menu
503  //slicing
509  private void handleSlicingMenu(object sender, EventArgs e)
510  {
511  slicingDialog = new SlicingForm();
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();
521  }
522 
523 
524 
525  //projection functions
531  private void handleMaxIntensityProjMenu(object sender, EventArgs e)
532  {
533  if (maximumIntensityProjectionToolStripMenuItem.Checked)
534  {
535  maximumIntensityProjectionToolStripMenuItem.Checked = false;
536  MaxIntensityProjCheckBox.Checked = false;
537  }
538  else
539  {
540  maximumIntensityProjectionToolStripMenuItem.Checked = true;
541  MaxIntensityProjCheckBox.Checked = true;
542  }
543 
544  GameProperties.Instance.maximumIntensityProjection = MaxIntensityProjCheckBox.Checked;
545  updateXnaEngineState(true, false, true, true);
546 
547  }
553  private void handlePerspProjMenu(object sender, EventArgs e)
554  {
555  if (perspectiveProjectionToolStripMenuItem.Checked)
556  {
557  perspectiveProjectionToolStripMenuItem.Checked = false;
558  orthogonalProjectionToolStripMenuItem.Checked = true;
559  PerspProjRadio.Checked = false;
560  OrthProjRadio.Checked = true;
561  }
562  else
563  {
564  perspectiveProjectionToolStripMenuItem.Checked = true;
565  orthogonalProjectionToolStripMenuItem.Checked = false;
566  PerspProjRadio.Checked = true;
567  OrthProjRadio.Checked = false;
568  }
569 
570  GameProperties.Instance.perspectiveProjection = PerspProjRadio.Checked;
571  updateXnaEngineState(true, false, true, true);
572  }
573 
579  private void handleOrthProjMenu(object sender, EventArgs e)
580  {
581  if (orthogonalProjectionToolStripMenuItem.Checked)
582  {
583  perspectiveProjectionToolStripMenuItem.Checked = true;
584  orthogonalProjectionToolStripMenuItem.Checked = false;
585  PerspProjRadio.Checked = true;
586  OrthProjRadio.Checked = false;
587  }
588  else
589  {
590  perspectiveProjectionToolStripMenuItem.Checked = false;
591  orthogonalProjectionToolStripMenuItem.Checked = true;
592  PerspProjRadio.Checked = false;
593  OrthProjRadio.Checked = true;
594  }
595  GameProperties.Instance.perspectiveProjection = PerspProjRadio.Checked;
596  updateXnaEngineState(true, false, true, true);
597  }
598 
604  private void handleBlendModeMenu(object sender, EventArgs e)
605  {
606  if (sender == frontToBackBlendingToolStripMenuItem)
607  {
608  if (frontToBackBlendingToolStripMenuItem.Checked)
609  {
610  frontToBackBlendingToolStripMenuItem.Checked = false;
611  backToFrontBlendingToolStripMenuItem.Checked = true;
612  BlendRadioButt1.Checked = false;
613  BlendRadioButt2.Checked = true;
614  }
615  else
616  {
617  frontToBackBlendingToolStripMenuItem.Checked = true;
618  backToFrontBlendingToolStripMenuItem.Checked = false;
619  BlendRadioButt1.Checked = true;
620  BlendRadioButt2.Checked = false;
621  }
622 
623  }
624  else if (sender == backToFrontBlendingToolStripMenuItem)
625  {
626  if (backToFrontBlendingToolStripMenuItem.Checked)
627  {
628  frontToBackBlendingToolStripMenuItem.Checked = true;
629  backToFrontBlendingToolStripMenuItem.Checked = false;
630  BlendRadioButt1.Checked = true;
631  BlendRadioButt2.Checked = false;
632  }
633  else
634  {
635  frontToBackBlendingToolStripMenuItem.Checked = false;
636  backToFrontBlendingToolStripMenuItem.Checked = true;
637  BlendRadioButt1.Checked = false;
638  BlendRadioButt2.Checked = true;
639  }
640 
641  }
642 
643  GameProperties.Instance.enableFrontToBackBlend = frontToBackBlendingToolStripMenuItem.Checked;
644  updateXnaEngineState(true, false, true, true);
645  }
646 
652  private void handleShadingMenu(object sender, EventArgs e)
653  {
654  if (shadingToolStripMenuItem.Checked)
655  {
656  shadingToolStripMenuItem.Checked = false;
657  }
658  else
659  {
660  shadingToolStripMenuItem.Checked = true;
661  }
662  ShadingCheckBox.Checked = shadingToolStripMenuItem.Checked;
663  GameProperties.Instance.enableShading = ShadingCheckBox.Checked;
664  updateXnaEngineState(true, false, true, true);
665 
666  }
667 
668  //transfer function
674  private void handleEnableTransferFunctionMenu(object sender, EventArgs e)
675  {
676  if (enableTransferfunctionToolStripMenuItem.Checked)
677  {
678  enableTransferfunctionToolStripMenuItem.Checked = false;
679  transferfunctionCheckBox1.Checked = false;
680  }
681  else enableTransferfunctionToolStripMenuItem.Checked = true;
682  transferfunctionCheckBox.Checked = enableTransferfunctionToolStripMenuItem.Checked;
683 
684  #region update engine state
685  GameProperties.Instance.enableTransferFunction = enableTransferfunctionToolStripMenuItem.Checked;
686  GameProperties.Instance.enableTransferAlphaValues = transferfunctionCheckBox1.Checked;
687  updateXnaEngineState(false, false, true, true);
688  #endregion
689 
690  #region update tf control state
691  TransferFunctionPanel.EnableTransferFunction = enableTransferfunctionToolStripMenuItem.Checked;
692  TransferFunctionPanel.Refresh();
693  #endregion
694  }
695 
701  private void handleLoadTransferFunctionMenu(object sender, EventArgs e)
702  {
703  string relativePath = Path.Combine(assemblyLocation, "../../../../Data/Transferfunction");
704  string contentPath = Path.GetFullPath(relativePath);
705 
706  this.openFileDialog.InitialDirectory = contentPath;
707 
708  this.openFileDialog.Title = "Load Transferfunction";
709 
710  this.openFileDialog.Filter = "XML Files (*.xml)|*.xml";
711 
712  if (this.openFileDialog.ShowDialog() == DialogResult.OK)
713  {
714  loadTransferFunction(openFileDialog.FileName);
715 
716  #region update engine state
717  updateXnaEngineState(false, false, true, true);
718  #endregion
719 
720  #region update transferfunction state
721  TransferFunctionPanel.GetControlPoints = true;
722  TransferFunctionPanel.Refresh();
723  #endregion
724 
725  }
726  }
727 
733  private void handleSaveTransferFunctionMenu(object sender, EventArgs e)
734  {
735  string relativePath = Path.Combine(assemblyLocation, "../../../../Data/Transferfunction");
736  string contentPath = Path.GetFullPath(relativePath);
737 
738  this.saveFileDialog.InitialDirectory = contentPath;
739 
740  this.saveFileDialog.Title = "Save Transferfunction as";
741 
742  this.saveFileDialog.Filter = "XML Files (*.xml)|*.xml";
743 
744  if (this.saveFileDialog.ShowDialog() == DialogResult.OK)
745  {
746  saveTransferFunction(saveFileDialog.FileName);
747  }
748  }
749 
750 
756  private void handleEditTransferFunctionMenu(object sender, EventArgs e)
757  {
758  TransferfunctionForm transferFunctionDialog = new TransferfunctionForm();
759  transferFunctionDialog.Show();
760  }
761 
762  #endregion
763 
764  #region help menu
765  // TODO????
766  #endregion
767 
768  #endregion
769 
770  #region settings panel (right tab panel)
771 
772  #region slices
773  private void handleSliceNumericUpDown(object sender, EventArgs e)
779  {
780  if (sender == XSliceNumericUpDown)
781  {
782  XSlider.Value = Decimal.ToInt32(Decimal.Multiply(XSliceNumericUpDown.Value, new Decimal(XSlider.Maximum)));
783  GameProperties.Instance.xSliceValue = (float)XSliceNumericUpDown.Value;
784 
785  }
786  else if (sender == YSliceNumericUpDown)
787  {
788  YSlider.Value = Decimal.ToInt32(Decimal.Multiply(YSliceNumericUpDown.Value, new Decimal(YSlider.Maximum)));
789  GameProperties.Instance.ySliceValue = (float)YSliceNumericUpDown.Value;
790 
791  }
792  else if (sender == ZSliceNumericUpDown)
793  {
794  ZSlider.Value = Decimal.ToInt32(Decimal.Multiply(ZSliceNumericUpDown.Value, new Decimal(ZSlider.Maximum)));
795  GameProperties.Instance.zSliceValue = (float)ZSliceNumericUpDown.Value;
796 
797  }
798  else { return; }
799 
800  if (sliceFormOpen)
801  {
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();
809  }
810 
811  if (!GameProperties.Instance.viewMode.Equals(ViewMode.VolView))
812  {
813  updateXnaEngineState(false, false, false, true);
814  }
815  }
816 
822  private void handleScrollSlider(object sender, EventArgs e)
823  {
824  if (sender == XSlider)
825  {
826  Decimal newValue = Decimal.Divide(new Decimal(XSlider.Value), new Decimal(XSlider.Maximum));
827  XSliceNumericUpDown.Value = newValue;
828  GameProperties.Instance.xSliceValue = (float)newValue;
829  }
830  else if (sender == YSlider)
831  {
832  Decimal newValue = Decimal.Divide(new Decimal(YSlider.Value), new Decimal(YSlider.Maximum));
833  YSliceNumericUpDown.Value = newValue;
834  GameProperties.Instance.ySliceValue = (float)newValue;
835 
836  }
837  else if (sender == ZSlider)
838  {
839  Decimal newValue = Decimal.Divide(new Decimal(ZSlider.Value), new Decimal(ZSlider.Maximum));
840  ZSliceNumericUpDown.Value = newValue;
841  GameProperties.Instance.zSliceValue = (float)newValue;
842 
843  }
844  else { return; }
845 
846  if (sliceFormOpen)
847  {
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();
855  }
856 
857  if (!GameProperties.Instance.viewMode.Equals(ViewMode.VolView))
858  {
859  updateXnaEngineState(false, false, false, true);
860  }
861 
862  }
863  #endregion
864 
865  #region transfer function panel
866  private void handleTransferFunctionCheckbox(object sender, EventArgs e)
872  {
873  //set gui
874  if (!transferfunctionCheckBox.Checked) transferfunctionCheckBox1.Checked = false;
875  enableTransferfunctionToolStripMenuItem.Checked = transferfunctionCheckBox.Checked;
876 
877  #region set engine control
878  GameProperties.Instance.enableTransferFunction = transferfunctionCheckBox.Checked;
879  GameProperties.Instance.enableTransferAlphaValues = transferfunctionCheckBox1.Checked;
880  updateXnaEngineState(false, false, true, true);
881  #endregion
882 
883  #region set tf control
884  TransferFunctionPanel.EnableTransferFunction = transferfunctionCheckBox.Checked;
885  TransferFunctionPanel.Refresh();
886  #endregion
887  }
888 
894  private void handleTransferFunctionCheckbox1(object sender, EventArgs e)
895  {
896  if (transferfunctionCheckBox1.Checked && !transferfunctionCheckBox.Checked) transferfunctionCheckBox1.Checked = false;
897 
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);
902  #endregion
903 
904  }
905 
911  private void handleTransferFunctionCheckbox2(object sender, EventArgs e)
912  {
913  GameProperties.Instance.showDensityValue = transferfunctionCheckBox2.Checked;
914  TransferFunctionPanel.DensityFunction = transferfunctionCheckBox2.Checked;
915  TransferFunctionPanel.Refresh();
916  }
917 
918 
926  private void TransferFunctionPanel_MouseDown(object sender, MouseEventArgs e)
927  {
928  if (!transferfunctionCheckBox.Checked) return;
929 
930  Point newPos = clampToPanelDimensions(e.X, e.Y);
931 
932  if (e.Button == MouseButtons.Left) //select control point to move
933  {
934  tfPanelMouseDown = true;
935  tfPanelMouseDownPos = newPos;
936  }
937 
938  #region create new control point or edit one
939  if (e.Button == MouseButtons.Right) //create new control point or edit one
940  {
941  ColorDialog colorPicker = new ColorDialog();
942  //if user pick new color
943  if (colorPicker.ShowDialog() == DialogResult.OK)
944  {
945  TransferFunctionPanel.setControlPoint(newPos, colorPicker.Color);
946  TransferFunctionPanel.SetControlPoints = true;
947  TransferFunctionPanel.Refresh();
948  updateXnaEngineState(false, false, true, true);
949  }//end if ok
950  } //end if right button
951  #endregion
952 
953  }
954 
961  private void TransferFunctionPanel_MouseMove(object sender, MouseEventArgs e)
962  {
963  if (!transferfunctionCheckBox.Checked) return;
964 
965  //Console.WriteLine("e.x " + e.X);
966  //Console.WriteLine("e.y " + e.Y);
967  if (tfPanelMouseDown)
968  {
969 
970  Point newPos = clampToPanelDimensions(e.X, e.Y);
971  if (TransferFunctionPanel.changeControlPoint(tfPanelMouseDownPos, newPos))
972  {
973  TransferFunctionPanel.SetControlPoints = true;
974  TransferFunctionPanel.Refresh();
975  //update start pos for this control point
976  tfPanelMouseDownPos = newPos;
977  }
978 
979  }//end if
980 
981  }
982 
988  private void TransferFunctionPanel_MouseUp(object sender, MouseEventArgs e)
989  {
990 
991  tfPanelMouseDown = false;
992  updateXnaEngineState(false, false, true, true);
993  }
994 
1000  private void TransferFunctionPanel_MouseDoubleClick(object sender, MouseEventArgs e)
1001  {
1002  if (!transferfunctionCheckBox.Checked) return;
1003 
1004  Point cpPos = clampToPanelDimensions(e.X, e.Y);
1005  if(TransferFunctionPanel.removeControlPoint(cpPos))
1006  {
1007  TransferFunctionPanel.SetControlPoints = true;
1008  TransferFunctionPanel.Refresh();
1009  updateXnaEngineState(false, false, true, true);
1010  }
1011 
1012  }
1013 
1014  #endregion
1015 
1016  #region extended features
1017  private void handleEnableCVDCheckBox(object sender, EventArgs e)
1023  {
1024  if (enableCVDCheckBox.Checked)
1025  {
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;
1037  //this.cvdViewToolStripMenuItem.Enabled = true;
1038  //this.recoloredViewToolStripMenuItem.Enabled = true;
1039  }
1040  else
1041  {
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;
1049  //this.cvdViewToolStripMenuItem.Enabled = false;
1050  //this.recoloredViewToolStripMenuItem.Enabled = false;
1051  }
1052  GameProperties.Instance.enableCVDView = enableCVDCheckBox.Checked;
1053  updateXnaEngineState(true, false, true, true);
1054  }
1055 
1062  private void handleEnableCVDViewCheckBox1(object sender, EventArgs e)
1063  {
1064  if (this.cvdViewCheckBox1.Checked)
1065  {
1066  volViewToolStripMenuItem.Checked = true;
1067  GameProperties.Instance.viewMode = ViewMode.VolView;
1068  }
1069  else
1070  {
1071  volViewToolStripMenuItem.Checked = false;
1072  }
1073 
1074  GameProperties.Instance.originalView = cvdViewCheckBox1.Checked;
1075  updateXnaEngineState(true, false, true, true);
1076  }
1077 
1084  private void handleEnableCVDViewCheckBox2(object sender, EventArgs e)
1085  {
1086  if (this.cvdViewCheckBox2.Checked)
1087  {
1088 
1089  this.recoloredViewToolStripMenuItem.Checked = true;
1090  GameProperties.Instance.triggerRecolor = true;
1091  }
1092  else
1093  {
1094  this.recoloredViewToolStripMenuItem.Checked = false;
1095  GameProperties.Instance.triggerRecolor = false;
1096  }
1097 
1098  GameProperties.Instance.recoloredView = cvdViewCheckBox2.Checked;
1099  updateXnaEngineState(true, false, true, true);
1100  }
1101 
1108  private void handleEnableCVDViewCheckBox3(object sender, EventArgs e)
1109  {
1110  if (this.cvdViewCheckBox3.Checked)
1111  {
1112  //this.cvdViewToolStripMenuItem.Checked = true;
1113  GameProperties.Instance.triggerOptimize = true;
1114  GameProperties.Instance.CVDTFOptimized = false;
1115  GameProperties.Instance.cvdView = true;
1116  }
1117  else
1118  {
1119  //this.cvdViewToolStripMenuItem.Checked = false;
1120  GameProperties.Instance.triggerOptimize = false;
1121  GameProperties.Instance.cvdView = false;
1122  }
1123 
1124  //GameProperties.Instance.cvdView = cvdViewCheckBox3.Checked;
1125  updateXnaEngineState(true, false, true, true);
1126  }
1127 
1128 
1135  private void handleEnableCVDViewCheckBox4(object sender, EventArgs e)
1136  {
1137  if (this.cvdViewCheckBox4.Checked == true)
1138  {
1139  //trigger simulate
1140  GameProperties.Instance.triggerSimulate = true;
1141  }
1142  else
1143  {
1144  GameProperties.Instance.triggerSimulate = false;
1145  }
1146 
1147  GameProperties.Instance.simulatedView = cvdViewCheckBox4.Checked;
1148  updateXnaEngineState(true, false, true, true);
1149  }
1150 
1156  private void handleMaxIntensityProjCheckBox(object sender, EventArgs e)
1157  {
1158  if (MaxIntensityProjCheckBox.Checked)
1159  {
1160  maximumIntensityProjectionToolStripMenuItem.Checked = true;
1161  }
1162  else
1163  {
1164  maximumIntensityProjectionToolStripMenuItem.Checked = false;
1165  }
1166  GameProperties.Instance.maximumIntensityProjection = MaxIntensityProjCheckBox.Checked;
1167  updateXnaEngineState(true, false, true, true);
1168  }
1169 
1175  private void handlePerspProjRadioButt(object sender, EventArgs e)
1176  {
1177  perspectiveProjectionToolStripMenuItem.Checked = true;
1178  orthogonalProjectionToolStripMenuItem.Checked = false;
1179  GameProperties.Instance.perspectiveProjection = true;
1180  updateXnaEngineState(true, false, true, true);
1181  }
1182 
1183 
1189  private void handleCVDTypeRadioButtons(object sender, EventArgs e)
1190  {
1191  /*if (sender == this.cvdRadioButton1)
1192  {
1193  this.cvdRadioButton2.Checked = !this.cvdRadioButton1.Checked;
1194  this.cvdRadioButton3.Checked = !this.cvdRadioButton1.Checked;
1195  }
1196  else if (sender == this.cvdRadioButton2)
1197  {
1198  this.cvdRadioButton1.Checked = !this.cvdRadioButton2.Checked;
1199  this.cvdRadioButton3.Checked = !this.cvdRadioButton3.Checked;
1200  }
1201  else if (sender == this.cvdRadioButton3)
1202  {
1203  this.cvdRadioButton1.Checked = !this.cvdRadioButton3.Checked;
1204  this.cvdRadioButton2.Checked = !this.cvdRadioButton3.Checked;
1205  }*/
1206 
1207  if (this.cvdRadioButton1.Checked)
1208  {
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;
1214  }
1215  else if (this.cvdRadioButton2.Checked)
1216  {
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;
1222  }
1223  else if (this.cvdRadioButton3.Checked)
1224  {
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;
1230  }
1231 
1232  updateXnaEngineState(true, false, true, true);
1233  }
1234 
1235 
1241  private void handleOrthProjRadioButt(object sender, EventArgs e)
1242  {
1243  perspectiveProjectionToolStripMenuItem.Checked = false;
1244  orthogonalProjectionToolStripMenuItem.Checked = true;
1245  GameProperties.Instance.perspectiveProjection = false;
1246  updateXnaEngineState(true, false, true, true);
1247  }
1248 
1254  private void handleBlendRadioButt1(object sender, EventArgs e)
1255  {
1256  frontToBackBlendingToolStripMenuItem.Checked = true;
1257  backToFrontBlendingToolStripMenuItem.Checked = false;
1258  GameProperties.Instance.enableFrontToBackBlend = true;
1259  updateXnaEngineState(true, false, true, true);
1260  }
1261 
1267  private void handleBlendRadioButt2(object sender, EventArgs e)
1268  {
1269  frontToBackBlendingToolStripMenuItem.Checked = false;
1270  backToFrontBlendingToolStripMenuItem.Checked = true;
1271  GameProperties.Instance.enableFrontToBackBlend = false;
1272  updateXnaEngineState(true, false, true, true);
1273  }
1274 
1280  private void handleShadingCheckBox(object sender, EventArgs e)
1281  {
1282  if (ShadingCheckBox.Checked)
1283  {
1284  shadingToolStripMenuItem.Checked = true;
1285  }
1286  else
1287  {
1288  shadingToolStripMenuItem.Checked = false;
1289  }
1290  GameProperties.Instance.enableShading = ShadingCheckBox.Checked;
1291  updateXnaEngineState(true, false, true, true);
1292  }
1293 
1294  #endregion
1295 
1296  #endregion
1297 
1298  #endregion
1299 
1300  #region handle xna draw surface events
1301  private void handleXNADrawSurface_MouseDoubleClick(object sender, MouseEventArgs e)
1308  {
1309 
1310  switch (GameProperties.Instance.viewMode)
1311  {
1312  case ViewMode.VolView:
1313  GameProperties.Instance.viewMode = ViewMode.TopView;
1314  volViewToolStripMenuItem.Checked = false;
1315  topViewToolStripMenuItem.Checked = true;
1316  sideViewToolStripMenuItem.Checked = false;
1317  frontViewToolStripMenuItem.Checked = false;
1318  break;
1319  case ViewMode.TopView:
1320  GameProperties.Instance.viewMode = ViewMode.SideView;
1321  volViewToolStripMenuItem.Checked = false;
1322  topViewToolStripMenuItem.Checked = false;
1323  sideViewToolStripMenuItem.Checked = true;
1324  frontViewToolStripMenuItem.Checked = false;
1325  break;
1326  case ViewMode.SideView:
1327  GameProperties.Instance.viewMode = ViewMode.FrontView;
1328  volViewToolStripMenuItem.Checked = false;
1329  topViewToolStripMenuItem.Checked = false;
1330  sideViewToolStripMenuItem.Checked = false;
1331  frontViewToolStripMenuItem.Checked = true;
1332  break;
1333  case ViewMode.FrontView:
1334  GameProperties.Instance.viewMode = ViewMode.VolView;
1335  volViewToolStripMenuItem.Checked = true;
1336  topViewToolStripMenuItem.Checked = false;
1337  sideViewToolStripMenuItem.Checked = false;
1338  frontViewToolStripMenuItem.Checked = false;
1339  break;
1340  default:
1341  GameProperties.Instance.viewMode = ViewMode.VolView;
1342  volViewToolStripMenuItem.Checked = true;
1343  topViewToolStripMenuItem.Checked = false;
1344  sideViewToolStripMenuItem.Checked = false;
1345  frontViewToolStripMenuItem.Checked = false;
1346  break;
1347  }
1348 
1349  updateXnaEngineState(true, false, true, true);
1350 
1351  }
1352 
1353 
1361  private void handleXNADrawSurface_MouseDown(object sender, MouseEventArgs e)
1362  {
1363  if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
1364  {
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);
1368  }
1369 
1370  }
1371 
1379  private void handleXNADrawSurface_MouseUp(object sender, MouseEventArgs e)
1380  {
1381  mouseDownPosX = 0;
1382  mouseDownPosY = 0;
1383  mouseDownPosZ = 0;
1384  GameProperties.Instance.cameraInput = Vector3.Zero;
1385  XnaDrawSurface_MouseDownEvent = false;
1386  }
1387 
1394  private void handleXNADrawSurface_MouseMove(object sender, MouseEventArgs e)
1395  {
1396  if (XnaDrawSurface_MouseDownEvent)
1397  {
1398  int nextPosX = (int)MathHelper.Clamp(e.X, 0, XNADrawSurface.Width - 1);
1399  int nextPosY = (int)MathHelper.Clamp(e.Y, 0, XNADrawSurface.Height - 1);
1400 
1401  int moveX = nextPosX - mouseDownPosX;
1402  int moveY = mouseDownPosY - nextPosY;
1403 
1404  //Console.WriteLine("Move X:" + moveX + "; Move Y:" + moveY);
1405  if (e.Button == MouseButtons.Left)
1406  {
1407  GameProperties.Instance.cameraInput.X = moveX;
1408  GameProperties.Instance.cameraInput.Y = moveY;
1409  }
1410  else if (e.Button == MouseButtons.Right)
1411  {
1412  GameProperties.Instance.cameraInput.Z = moveY;
1413  }
1414  mouseDownPosX = nextPosX;
1415  mouseDownPosY = nextPosY;
1416  updateXnaEngineState(true, false, true, true);
1417  }
1418  }
1419 
1426  private void handleXNADrawSurface_MouseScroll(object sender, MouseEventArgs e)
1427  {
1428  if (XnaDrawSurface_MouseDownEvent)
1429  {
1430  //Console.WriteLine("Delta: " + e.Delta);
1431  //Console.WriteLine("System info scroll data: " + SystemInformation.MouseWheelScrollDelta);
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);
1436  }
1437  }
1438 
1445  private void XNADrawSurface_KeyPress(object sender, KeyPressEventArgs e)
1446  {
1447  //TODO
1448  /*switch (e.KeyCode)
1449  {
1450  // http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress(v=vs.110).aspx
1451  }*/
1452  }
1453 
1459  public void updateMouseScroll(int scrollStep)
1460  {
1461  //int mousePos = getMousePos(mouseDownPosX, mouseDownPosY);
1462 
1463  //zoom +/-
1464  if (GameProperties.Instance.viewMode == ViewMode.VolView)
1465  {
1466  // : logic in the camera class
1467  //
1468  //scrollStep --> e.Delta, 120->max zoom value ex. 10
1469  //if endvalue > 0 -> zoom + , < 0 zoom -, = 0 nothing
1470  GameProperties.Instance.position.Z = scrollStep;
1471  // mouseDownPosZ = scrollStep;
1472  }
1473  //move slice
1474  else
1475  {
1476  if (GameProperties.Instance.viewMode == ViewMode.TopView)
1477  {
1478  //GameProperties.Instance.ySliceValue = -scrollStep/10;
1479  }
1480  else if (GameProperties.Instance.viewMode == ViewMode.SideView)
1481  {
1482  //GameProperties.Instance.xSliceValue = -scrollStep/10;
1483  }
1484  else if (GameProperties.Instance.viewMode == ViewMode.FrontView)
1485  {
1486  //GameProperties.Instance.zSliceValue = -scrollStep/10;
1487  }
1488 
1489  }
1490 
1491  }
1492  #endregion
1493 
1494  #region add functions
1495 
1505  public void updateTFState(bool enableTF, bool drawDF, bool setCP, bool getCP, bool updateDF)
1506  {
1507  this.TransferFunctionPanel.EnableTransferFunction = enableTF;
1508  this.TransferFunctionPanel.DensityFunction = drawDF;
1509  if (setCP && getCP) { setCP = false; getCP = true; } //if both true -> error -> load initial control points
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();
1514  }
1515 
1523  public void updateXnaEngineState(bool updateCam, bool load, bool update, bool draw)
1524  {
1525  GameProperties.Instance.engineState.updateCamera = updateCam;
1526  GameProperties.Instance.engineState.loadData = load;
1527  GameProperties.Instance.engineState.updateData = update;
1528  GameProperties.Instance.engineState.drawData = draw;
1529  if (updateCam || load || update || draw) this.XNADrawSurface.Refresh();
1530  }
1531 
1536  public void loadTransferFunction(String fileName)
1537  {
1538  GameProperties.Instance.colorControlPoints.Clear();
1539  GameProperties.Instance.alphaControlPoints.Clear();
1540 
1541  XmlTextReader xmlReader = new XmlTextReader(fileName);
1542  xmlReader.MoveToElement();
1543 
1544  float r = 0.0f;
1545  float g = 0.0f;
1546  float b = 0.0f;
1547  float a = 0.0f;
1548  int isoValue = 0;
1549 
1550  while (xmlReader.Read())
1551  {
1552  if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name.Equals("ControlPoint"))
1553  {
1554  while (!(xmlReader.NodeType == XmlNodeType.EndElement && xmlReader.Name.Equals("ControlPoint")))
1555  {
1556  xmlReader.Read();
1557 
1558  if (xmlReader.NodeType.Equals(XmlNodeType.Element))
1559  {
1560  String elementName = xmlReader.Name;
1561  xmlReader.Read();
1562  if (xmlReader.NodeType.Equals(XmlNodeType.Text))
1563  {
1564  switch (elementName)
1565  {
1566  case "ColorR":
1567  r = float.Parse(xmlReader.Value);
1568  break;
1569 
1570  case "ColorG":
1571  g = float.Parse(xmlReader.Value);
1572  break;
1573 
1574  case "ColorB":
1575  b = float.Parse(xmlReader.Value);
1576  break;
1577 
1578  case "ColorA":
1579  a = float.Parse(xmlReader.Value);
1580  break;
1581 
1582  case "IsoValue":
1583  isoValue = int.Parse(xmlReader.Value);
1584  break;
1585  }//end switch
1586  }//end if
1587  }
1588  }//end while
1589 
1590  //save new control point
1591  GameProperties.Instance.colorControlPoints.Add(new TransferControlPoint(r, g, b, isoValue));
1592  GameProperties.Instance.alphaControlPoints.Add(new TransferControlPoint(a, isoValue));
1593  }
1594  }
1595  }
1596 
1600  public void saveTransferFunction(string fileName)
1601  {
1602  XmlTextWriter xmlWriter = new XmlTextWriter(fileName, null);
1603 
1604  xmlWriter.WriteStartDocument();
1605  xmlWriter.WriteStartElement("TransferFunction");
1606 
1607  for (int i = 0; i < GameProperties.Instance.colorControlPoints.Count(); i++)
1608  {
1609  xmlWriter.WriteStartElement("ControlPoint");
1610 
1611  xmlWriter.WriteStartElement("ColorR");
1612  xmlWriter.WriteString(GameProperties.Instance.colorControlPoints[i].color.X.ToString());
1613  xmlWriter.WriteEndElement();
1614 
1615  xmlWriter.WriteStartElement("ColorG");
1616  xmlWriter.WriteString(GameProperties.Instance.colorControlPoints[i].color.Y.ToString());
1617  xmlWriter.WriteEndElement();
1618 
1619  xmlWriter.WriteStartElement("ColorB");
1620  xmlWriter.WriteString(GameProperties.Instance.colorControlPoints[i].color.Z.ToString());
1621  xmlWriter.WriteEndElement();
1622 
1623  xmlWriter.WriteStartElement("ColorA");
1624  xmlWriter.WriteString(GameProperties.Instance.alphaControlPoints[i].color.W.ToString());
1625  xmlWriter.WriteEndElement();
1626 
1627  xmlWriter.WriteStartElement("IsoValue");
1628  xmlWriter.WriteString(GameProperties.Instance.colorControlPoints[i].isoValue.ToString());
1629  xmlWriter.WriteEndElement();
1630 
1631  xmlWriter.WriteEndElement();
1632  }
1633 
1634  xmlWriter.WriteEndElement();
1635  xmlWriter.WriteEndDocument();
1636  xmlWriter.Close();
1637  }
1638 
1639  private Point clampToPanelDimensions(int posX, int posY)
1640  {
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; }
1648  return p;
1649  }
1650  #endregion
1651 
1652 
1653 
1654  protected override void WndProc(ref Message m)
1655  {
1656 
1657  // WM_SYSCOMMAND
1658  if (m.Msg == 0x0112)
1659  {
1660  if (m.WParam == new IntPtr(0xF030) // Maximize event - SC_MAXIMIZE from Winuser.h
1661  || m.WParam == new IntPtr(0xF120)) // Restore event - SC_RESTORE from Winuser.h
1662  {
1663 
1664  updateXnaEngineState(true, false, true, true);
1665  //Console.WriteLine("Size:" + Size);
1666  }
1667  }
1668 
1669  base.WndProc(ref m);
1670  }
1671 
1672  private void toolStripMenuItem3_Click(object sender, EventArgs e)
1673  {
1674 
1675  }
1676 
1677 
1678  }
1679  }