00001 #region using statemens
00002 using System;
00003 using System.IO;
00004 using System.Reflection;
00005 using System.Collections.Generic;
00006 using System.ComponentModel;
00007 using System.Data;
00008 using System.Drawing;
00009 using System.Linq;
00010 using System.Text;
00011 using System.Windows.Forms;
00012 using visLU.Gui;
00013 #endregion
00014
00015 namespace visLU.Gui
00016 {
00017
00021 public partial class MainWindow : Form
00022 {
00023 #region interactive tranfer function variables
00024 Pen penGray = new Pen(Color.Gray);
00025 Pen penLightGray = new Pen(Color.LightSlateGray);
00026 Pen penBlack = new Pen(Color.Black);
00027 Pen penBlue = new Pen(Color.Blue);
00028 Size controlPointSize = new Size(9, 9);
00029 Size colorBarSize = new Size(1, 30);
00030
00031 float[] isoValues;
00032 int[] isoValuesFrequency;
00033 SortedDictionary<int, TransferControlPoint> controlPoints;
00034 Color[] colorArray;
00035
00036 int stepsize = 1;
00037
00038 bool updateIsoValues = true;
00039 bool updateControlPoints = true;
00040 bool updateColorArray = true;
00041 bool tfPanelMouseDown = false;
00042 Point tfPanelMouseDownPos = new Point();
00043 #endregion
00044
00045 #region other variables
00046 string assemblyLocation = Assembly.GetExecutingAssembly().Location;
00047 InputManager inputManager;
00048 #endregion
00049
00053 public MainWindow()
00054 {
00055 InitializeComponent();
00056 SetStyle(ControlStyles.OptimizedDoubleBuffer |
00057 ControlStyles.UserPaint |
00058 ControlStyles.AllPaintingInWmPaint, true);
00059
00060 inputManager = new InputManager();
00061
00062
00063 updateIsoValues = true;
00064 updateIsoValuesData();
00065
00066 controlPoints = new SortedDictionary<int, TransferControlPoint>();
00067 updateControlPoints = true;
00068 updateControlPointsData();
00069 colorArray = new Color[256];
00070 updateColorArray = true;
00071
00072 }
00073
00074 #region XNA drawing area
00075
00076
00077
00078
00079
00080 public IntPtr getDrawSurface()
00081 {
00082 return XNADrawSurface.Handle;
00083 }
00084
00088 public void setXNADrawSurfaceDimensions()
00089 {
00090 GameProperties.Instance.XNADrawSurfaceWidth = XNADrawSurface.Size.Width;
00091 GameProperties.Instance.XNADrawSurfaceHeight = XNADrawSurface.Size.Height;
00092 }
00093
00098 public int XNADrawWidth()
00099 {
00100 return XNADrawSurface.Size.Width;
00101 }
00102
00107 public int XNADrawHeight()
00108 {
00109 return XNADrawSurface.Size.Height;
00110 }
00111
00112 #endregion
00113
00114 #region update controls
00115
00116
00117
00118
00119
00120
00121 public void updateSliceControls(int xRange, int yRange, int zRange)
00122 {
00123
00124 Decimal xIncrement = Decimal.Divide(XSliceNumericUpDown.Maximum, new Decimal(xRange));
00125
00126
00127 int xDecimalPlaces = 8;
00128 XSliceNumericUpDown.Increment = xIncrement;
00129 XSliceNumericUpDown.DecimalPlaces = xDecimalPlaces;
00130 XSliceNumericUpDown.Value = Decimal.Divide(XSliceNumericUpDown.Maximum, new Decimal(2));
00131 XSlider.Maximum = xRange;
00132 XSlider.Value = xRange / 2;
00133
00134
00135 Decimal yIncrement = Decimal.Divide(YSliceNumericUpDown.Maximum, new Decimal(yRange));
00136
00137
00138 int yDecimalPlaces = 8;
00139 YSliceNumericUpDown.Increment = yIncrement;
00140 YSliceNumericUpDown.DecimalPlaces = yDecimalPlaces;
00141 YSliceNumericUpDown.Value = Decimal.Divide(YSliceNumericUpDown.Maximum, new Decimal(2));
00142 YSlider.Maximum = yRange;
00143 YSlider.Value = yRange / 2;
00144
00145
00146 Decimal zIncrement = Decimal.Divide(ZSliceNumericUpDown.Maximum, new Decimal(zRange));
00147
00148
00149 int zDecimalPlaces = 8;
00150 ZSliceNumericUpDown.Increment = zIncrement;
00151 ZSliceNumericUpDown.DecimalPlaces = zDecimalPlaces;
00152 ZSliceNumericUpDown.Value = Decimal.Divide(ZSliceNumericUpDown.Maximum, new Decimal(2));
00153 ZSlider.Maximum = zRange;
00154 ZSlider.Value = zRange / 2;
00155
00156 XSliceGroup.Enabled = inputManager.enableSliceGroup(1);
00157 YSliceGroup.Enabled = inputManager.enableSliceGroup(2);
00158 ZSliceGroup.Enabled = inputManager.enableSliceGroup(3);
00159 XSliceGroup.Refresh();
00160 YSliceGroup.Refresh();
00161 ZSliceGroup.Refresh();
00162 }
00163
00171 public void setSlicingGroups(int slice, Decimal increment, int decimalPlaces, Decimal value)
00172 {
00173 switch (slice)
00174 {
00175 case 1:
00176 XSliceNumericUpDown.Increment = increment;
00177 XSliceNumericUpDown.DecimalPlaces = decimalPlaces;
00178 XSliceNumericUpDown.Value = value;
00179 break;
00180 case 2:
00181 YSliceNumericUpDown.Increment = increment;
00182 YSliceNumericUpDown.DecimalPlaces = decimalPlaces;
00183 YSliceNumericUpDown.Value = value;
00184 break;
00185 case 3:
00186 ZSliceNumericUpDown.Increment = increment;
00187 ZSliceNumericUpDown.DecimalPlaces = decimalPlaces;
00188 ZSliceNumericUpDown.Value = value;
00189 break;
00190 default:
00191 break;
00192
00193 }
00194
00195 }
00196
00203 public void setSlicingGroups(int slice, int maximum, int value)
00204 {
00205 switch (slice)
00206 {
00207 case 1:
00208 XSlider.Maximum = maximum;
00209 XSlider.Value = value;
00210 break;
00211 case 2:
00212 YSlider.Maximum = maximum;
00213 YSlider.Value = value;
00214 break;
00215 case 3:
00216 ZSlider.Maximum = maximum;
00217 ZSlider.Value = value;
00218 break;
00219 default:
00220 break;
00221
00222 }
00223
00224 }
00225 #endregion
00226
00227 #region event handler
00228
00229 #region main menu handler
00230
00231 #region file menu
00232
00233
00234
00235
00236
00237 private void handleOpenFileMenu(object sender, EventArgs e)
00238 {
00239
00240
00241 string relativePath = Path.Combine(assemblyLocation, "../../../../Data");
00242 string contentPath = Path.GetFullPath(relativePath);
00243
00244 this.openFileDialog.InitialDirectory = contentPath;
00245
00246 this.openFileDialog.Title = "Load Data Set";
00247
00248 this.openFileDialog.Filter = "Data Files (*.dat)|*.dat";
00249
00250 if (this.openFileDialog.ShowDialog() == DialogResult.OK)
00251 {
00252 GameProperties.Instance.dataFilename = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf("\\") + 1);
00253 inputManager.updateXnaEngineState(true, true, true, true);
00254 updateIsoValues = true;
00255 TransferFunctionPanel.Invalidate();
00256 }
00257 }
00258
00264 private void handleSaveFileMenu(object sender, EventArgs e)
00265 {
00266 string relativePath = Path.Combine(assemblyLocation, "../../../../Data/Screenshots");
00267 string contentPath = Path.GetFullPath(relativePath);
00268
00269 this.saveFileDialog.InitialDirectory = contentPath;
00270
00271 this.saveFileDialog.Title = "Save Image as";
00272
00273 this.saveFileDialog.Filter = "JPG Files (*.jpg)|*.jpg";
00274
00275 if (this.saveFileDialog.ShowDialog() == DialogResult.OK)
00276 {
00277 GameProperties.Instance.saveFilename = saveFileDialog.FileName;
00278 GameProperties.Instance.saveView = true;
00279 GameProperties.Instance.engineState.drawData = true;
00280 }
00281 }
00282
00288 private void handleExitMenu(object sender, EventArgs e)
00289 {
00290 GameProperties.Instance.exitGame = true;
00291
00292 }
00293
00299 private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
00300 {
00301 GameProperties.Instance.exitGame = true;
00302 }
00303 #endregion
00304
00305 #region view menu
00306
00307
00308
00309
00310
00311 private void handleViewMenuOnClick(object sender, EventArgs e)
00312 {
00313
00314
00315
00316 if (sender == this.volViewToolStripMenuItem)
00317 {
00318 volViewToolStripMenuItem.Checked = true;
00319 topViewToolStripMenuItem.Checked = false;
00320 sideViewToolStripMenuItem.Checked = false;
00321 frontViewToolStripMenuItem.Checked = false;
00322 XSliceGroup.Enabled = false;
00323 YSliceGroup.Enabled = false;
00324 ZSliceGroup.Enabled = false;
00325 inputManager.setViewMode(ViewMode.VolView);
00326 }
00327 else if (sender == this.topViewToolStripMenuItem)
00328 {
00329 volViewToolStripMenuItem.Checked = false;
00330 topViewToolStripMenuItem.Checked = true;
00331 sideViewToolStripMenuItem.Checked = false;
00332 frontViewToolStripMenuItem.Checked = false;
00333 XSliceGroup.Enabled = false;
00334 YSliceGroup.Enabled = true;
00335 ZSliceGroup.Enabled = false;
00336 inputManager.setViewMode(ViewMode.TopView);
00337 }
00338 else if (sender == this.sideViewToolStripMenuItem)
00339 {
00340 volViewToolStripMenuItem.Checked = false;
00341 topViewToolStripMenuItem.Checked = false;
00342 sideViewToolStripMenuItem.Checked = true;
00343 frontViewToolStripMenuItem.Checked = false;
00344 XSliceGroup.Enabled = true;
00345 YSliceGroup.Enabled = false;
00346 ZSliceGroup.Enabled = false;
00347 inputManager.setViewMode(ViewMode.SideView);
00348 }
00349 else if (sender == this.frontViewToolStripMenuItem)
00350 {
00351 volViewToolStripMenuItem.Checked = false;
00352 topViewToolStripMenuItem.Checked = false;
00353 sideViewToolStripMenuItem.Checked = false;
00354 frontViewToolStripMenuItem.Checked = true;
00355 XSliceGroup.Enabled = false;
00356 YSliceGroup.Enabled = false;
00357 ZSliceGroup.Enabled = true;
00358 inputManager.setViewMode(ViewMode.FrontView);
00359 }
00360
00361 inputManager.updateXnaEngineState(true, false, true, true);
00362 }
00363
00369 private void handleZoomMenuOnCLick(object sender, EventArgs e)
00370 {
00371
00372 if (sender == this.zoomInToolStripMenuItem) inputManager.setZoom(1);
00373 if (sender == this.zoomOutToolStripMenuItem) inputManager.setZoom(-1);
00374
00375
00376 inputManager.updateXnaEngineState(true, false, true, true);
00377 }
00378 #endregion
00379
00380 #region functions menu
00381
00382 private void handleSlicingMenu(object sender, EventArgs e)
00383 {
00384 SlicingForm slicingDialog = new SlicingForm();
00385 slicingDialog.MainForm = this;
00386 slicingDialog.setSlicingGroups(1, XSliceNumericUpDown.Increment, XSliceNumericUpDown.DecimalPlaces, XSliceNumericUpDown.Value);
00387 slicingDialog.setSlicingGroups(2, YSliceNumericUpDown.Increment, YSliceNumericUpDown.DecimalPlaces, YSliceNumericUpDown.Value);
00388 slicingDialog.setSlicingGroups(3, ZSliceNumericUpDown.Increment, YSliceNumericUpDown.DecimalPlaces, ZSliceNumericUpDown.Value);
00389 slicingDialog.setSlicingGroups(1, XSlider.Maximum, XSlider.Value);
00390 slicingDialog.setSlicingGroups(2, YSlider.Maximum, YSlider.Value);
00391 slicingDialog.setSlicingGroups(3, ZSlider.Maximum, ZSlider.Value);
00392 slicingDialog.Show();
00393 }
00394
00395
00396
00397
00403 private void handleMaxIntensityProjMenu(object sender, EventArgs e)
00404 {
00405 if (maximumIntensityProjectionToolStripMenuItem.Checked)
00406 {
00407 maximumIntensityProjectionToolStripMenuItem.Checked = false;
00408 MaxIntensityProjCheckBox.Checked = false;
00409 }
00410 else
00411 {
00412 maximumIntensityProjectionToolStripMenuItem.Checked = true;
00413 MaxIntensityProjCheckBox.Checked = true;
00414 }
00415 inputManager.enableMaxIntensityProjection(MaxIntensityProjCheckBox.Checked);
00416
00417 }
00423 private void handlePerspProjMenu(object sender, EventArgs e)
00424 {
00425 if (perspectiveProjectionToolStripMenuItem.Checked)
00426 {
00427 perspectiveProjectionToolStripMenuItem.Checked = false;
00428 orthogonalProjectionToolStripMenuItem.Checked = true;
00429 PerspProjRadio.Checked = false;
00430 OrthProjRadio.Checked = true;
00431 }
00432 else
00433 {
00434 perspectiveProjectionToolStripMenuItem.Checked = true;
00435 orthogonalProjectionToolStripMenuItem.Checked = false;
00436 PerspProjRadio.Checked = true;
00437 OrthProjRadio.Checked = false;
00438 }
00439 inputManager.enablePerspProjection(PerspProjRadio.Checked);
00440 }
00441
00447 private void handleOrthProjMenu(object sender, EventArgs e)
00448 {
00449 if (orthogonalProjectionToolStripMenuItem.Checked)
00450 {
00451 perspectiveProjectionToolStripMenuItem.Checked = true;
00452 orthogonalProjectionToolStripMenuItem.Checked = false;
00453 PerspProjRadio.Checked = true;
00454 OrthProjRadio.Checked = false;
00455 }
00456 else
00457 {
00458 perspectiveProjectionToolStripMenuItem.Checked = false;
00459 orthogonalProjectionToolStripMenuItem.Checked = true;
00460 PerspProjRadio.Checked = false;
00461 OrthProjRadio.Checked = true;
00462 }
00463 inputManager.enablePerspProjection(PerspProjRadio.Checked);
00464 }
00465
00466
00467 private void handleBlendModeMenu(object sender, EventArgs e)
00468 {
00469 if (sender == frontToBackBlendingToolStripMenuItem)
00470 {
00471 if (frontToBackBlendingToolStripMenuItem.Checked)
00472 {
00473 frontToBackBlendingToolStripMenuItem.Checked = false;
00474 backToFrontBlendingToolStripMenuItem.Checked = true;
00475 }
00476 else
00477 {
00478 frontToBackBlendingToolStripMenuItem.Checked = true;
00479 backToFrontBlendingToolStripMenuItem.Checked = false;
00480 }
00481
00482 }
00483 else if (sender == backToFrontBlendingToolStripMenuItem)
00484 {
00485 if (backToFrontBlendingToolStripMenuItem.Checked)
00486 {
00487 frontToBackBlendingToolStripMenuItem.Checked = true;
00488 backToFrontBlendingToolStripMenuItem.Checked = false;
00489 }
00490 else
00491 {
00492 frontToBackBlendingToolStripMenuItem.Checked = false;
00493 backToFrontBlendingToolStripMenuItem.Checked = true;
00494 }
00495
00496 }
00497
00498 BlendRadioButt1.Checked = frontToBackBlendingToolStripMenuItem.Checked;
00499 BlendRadioButt2.Checked = backToFrontBlendingToolStripMenuItem.Checked;
00500 inputManager.enableFrontToBackBlending(frontToBackBlendingToolStripMenuItem.Checked);
00501 }
00502
00503
00504 private void handleShadingMenu(object sender, EventArgs e)
00505 {
00506 if (shadingToolStripMenuItem.Checked)
00507 {
00508 shadingToolStripMenuItem.Checked = false;
00509 }
00510 else
00511 {
00512 shadingToolStripMenuItem.Checked = true;
00513 }
00514 ShadingCheckBox.Checked = shadingToolStripMenuItem.Checked;
00515 inputManager.enableShading(ShadingCheckBox.Checked);
00516 }
00517
00518
00524 private void handleEnableTransferFunctionMenu(object sender, EventArgs e)
00525 {
00526 if (enableTransferfunctionToolStripMenuItem.Checked)
00527 {
00528 enableTransferfunctionToolStripMenuItem.Checked = false;
00529 transferfunctionCheckBox1.Checked = false;
00530 }
00531 else enableTransferfunctionToolStripMenuItem.Checked = true;
00532 transferfunctionCheckBox.Checked = enableTransferfunctionToolStripMenuItem.Checked;
00533 inputManager.enableTransferFunction(enableTransferfunctionToolStripMenuItem.Checked, transferfunctionCheckBox1.Checked);
00534 TransferFunctionPanel.Refresh();
00535 }
00536
00542 private void handleLoadTransferFunctionMenu(object sender, EventArgs e)
00543 {
00544 string relativePath = Path.Combine(assemblyLocation, "../../../../Data/Transferfunction");
00545 string contentPath = Path.GetFullPath(relativePath);
00546
00547 this.openFileDialog.InitialDirectory = contentPath;
00548
00549 this.openFileDialog.Title = "Load Transferfunction";
00550
00551 this.openFileDialog.Filter = "XML Files (*.xml)|*.xml";
00552
00553 if (this.openFileDialog.ShowDialog() == DialogResult.OK)
00554 {
00555 this.inputManager.loadTransferFunction(openFileDialog.FileName);
00556 this.inputManager.updateXnaEngineState(false, false, true, true);
00557 this.updateControlPoints = true;
00558 TransferFunctionPanel.Refresh();
00559 }
00560 }
00561
00567 private void handleSaveTransferFunctionMenu(object sender, EventArgs e)
00568 {
00569 string relativePath = Path.Combine(assemblyLocation, "../../../../Data/Transferfunction");
00570 string contentPath = Path.GetFullPath(relativePath);
00571
00572 this.saveFileDialog.InitialDirectory = contentPath;
00573
00574 this.saveFileDialog.Title = "Save Transferfunction as";
00575
00576 this.saveFileDialog.Filter = "XML Files (*.xml)|*.xml";
00577
00578 if (this.saveFileDialog.ShowDialog() == DialogResult.OK)
00579 {
00580 this.inputManager.saveTransferFunction(saveFileDialog.FileName);
00581 }
00582 }
00583
00584
00590 private void handleEditTransferFunctionMenu(object sender, EventArgs e)
00591 {
00592 TransferfunctionForm transferFunctionDialog = new TransferfunctionForm();
00593 transferFunctionDialog.Show();
00594 }
00595
00596
00597
00598 #endregion
00599
00600 #region help menu
00601
00602 #endregion
00603
00604 #endregion
00605
00606 #region settings panel (right tab panel)
00607
00608 #region slices
00609
00610
00611
00612
00613
00614 private void handleSliceNumericUpDown(object sender, EventArgs e)
00615 {
00616 if (sender == XSliceNumericUpDown)
00617 {
00618 XSlider.Value = Decimal.ToInt32(Decimal.Multiply(XSliceNumericUpDown.Value, new Decimal(XSlider.Maximum)));
00619 inputManager.setSliceValue(1, XSliceNumericUpDown.Value);
00620
00621 }
00622 else if (sender == YSliceNumericUpDown)
00623 {
00624 YSlider.Value = Decimal.ToInt32(Decimal.Multiply(YSliceNumericUpDown.Value, new Decimal(YSlider.Maximum)));
00625 inputManager.setSliceValue(2, YSliceNumericUpDown.Value);
00626
00627 }
00628 else if (sender == ZSliceNumericUpDown)
00629 {
00630 ZSlider.Value = Decimal.ToInt32(Decimal.Multiply(ZSliceNumericUpDown.Value, new Decimal(ZSlider.Maximum)));
00631 inputManager.setSliceValue(3, ZSliceNumericUpDown.Value);
00632
00633 }
00634 }
00635
00641 private void handleScrollSlider(object sender, EventArgs e)
00642 {
00643 if (sender == XSlider)
00644 {
00645 Decimal newValue = Decimal.Divide(new Decimal(XSlider.Value), new Decimal(XSlider.Maximum));
00646 XSliceNumericUpDown.Value = newValue;
00647 inputManager.setSliceValue(1, newValue);
00648
00649 }
00650 else if (sender == YSlider)
00651 {
00652 Decimal newValue = Decimal.Divide(new Decimal(YSlider.Value), new Decimal(YSlider.Maximum));
00653 YSliceNumericUpDown.Value = newValue;
00654 inputManager.setSliceValue(2, newValue);
00655
00656 }
00657 else if (sender == ZSlider)
00658 {
00659 Decimal newValue = Decimal.Divide(new Decimal(ZSlider.Value), new Decimal(ZSlider.Maximum));
00660 ZSliceNumericUpDown.Value = newValue;
00661 inputManager.setSliceValue(3, newValue);
00662
00663 }
00664
00665 }
00666 #endregion
00667
00668 #region transfer function panel
00669
00670
00671
00672
00673
00674 private void handleTransferFunctionCheckbox1(object sender, EventArgs e)
00675 {
00676 if (transferfunctionCheckBox1.Checked)
00677 {
00678 enableTransferfunctionToolStripMenuItem.Checked = true;
00679 transferfunctionCheckBox.Checked = true;
00680 }
00681 inputManager.enableTransferFunction(transferfunctionCheckBox.Checked, transferfunctionCheckBox1.Checked);
00682 TransferFunctionPanel.Refresh();
00683 }
00689 private void handleTransferFunctionCheckbox(object sender, EventArgs e)
00690 {
00691 if (!transferfunctionCheckBox.Checked) transferfunctionCheckBox1.Checked = false;
00692 enableTransferfunctionToolStripMenuItem.Checked = transferfunctionCheckBox.Checked;
00693 inputManager.enableTransferFunction(transferfunctionCheckBox.Checked, transferfunctionCheckBox1.Checked);
00694 TransferFunctionPanel.Refresh();
00695 }
00696
00702 private void TransferFunctionPanel_Paint(object sender, PaintEventArgs e)
00703 {
00704 Graphics grobj = e.Graphics;
00705
00706 grobj.PageUnit = GraphicsUnit.Pixel;
00707 grobj.PageScale = 1;
00708 grobj.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
00709
00710 if (!transferfunctionCheckBox.Checked) return;
00711
00712 int width = TransferFunctionPanel.Width;
00713 int height = TransferFunctionPanel.Height;
00714
00715
00716
00717
00718
00719
00720 if (updateIsoValues)
00721 {
00722 updateIsoValuesData();
00723 generateHistogramm(width, height);
00724 }
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752 if (updateControlPoints) updateControlPointsData();
00753 List<Point> pList = new List<Point>();
00754 Color c1 = XNAToWindowsFormsColor(controlPoints.First().Value.color);
00755 Point p1 = new Point(controlPoints.First().Key, 255 - c1.A);
00756 pList.Add(p1);
00757 p1.X -= controlPointSize.Width / 2;
00758 p1.Y -= controlPointSize.Height / 2;
00759
00760 Rectangle rect = new Rectangle(p1, controlPointSize);
00761 grobj.DrawRectangle(penBlack, rect);
00762 grobj.FillRectangle(new SolidBrush(c1), rect);
00763
00764 IEnumerable<KeyValuePair<int, TransferControlPoint>> controlPointsTmp = controlPoints.Skip(1);
00765 foreach (KeyValuePair<int, TransferControlPoint> cp in controlPointsTmp)
00766 {
00767
00768 Color c2 = XNAToWindowsFormsColor(cp.Value.color);
00769 Point p2 = new Point(cp.Key, 255 - c2.A);
00770 pList.Add(p2);
00771
00772 p2.X -= controlPointSize.Width / 2;
00773 p2.Y -= controlPointSize.Height / 2;
00774 rect = new Rectangle(p2, controlPointSize);
00775 grobj.DrawRectangle(penBlack, rect);
00776 grobj.FillRectangle(new SolidBrush(c2), rect);
00777
00778 p1 = p2;
00779
00780 }
00781 grobj.DrawLines(penBlack, pList.ToArray());
00782
00783
00784 if (updateColorArray && GameProperties.Instance.updateColorBar)
00785 {
00786 updateColorArrayData();
00787
00788 }
00789 Rectangle rect1; Color c3;
00790 colorBarSize.Width = stepsize;
00791 {
00792 for (int i = 0; i < colorArray.Length; i++)
00793 {
00794 rect1 = new Rectangle(new Point(i, height - colorBarSize.Height), colorBarSize);
00795 c3 = colorArray[i];
00796 grobj.FillRectangle(new SolidBrush(c3), rect1);
00797 }
00798 }
00799 #region depricated
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819 #endregion
00820 }
00821
00827 private void generateHistogramm(int width, int height)
00828 {
00829 Bitmap flag = new Bitmap(width, height);
00830 Graphics flagGraphics = Graphics.FromImage(flag);
00831
00832
00833 for (int i = 0; i < isoValues.Length; i++)
00834 {
00835 for (int j = 0; j < stepsize; j++)
00836 {
00837 Point lowerPoint = new Point((int)((isoValues[i]) * stepsize + j), height);
00838 Point upperPoint = new Point((int)((isoValues[i]) * stepsize + j), (int)(height - isoValuesFrequency[i]));
00839 flagGraphics.DrawLine(penLightGray, lowerPoint, upperPoint);
00840 }
00841 }
00842
00843 Image image = Image.FromHbitmap(flag.GetHbitmap());
00844 this.TransferFunctionPanel.BackgroundImage = image;
00845 this.TransferFunctionPanel.BackgroundImageLayout = ImageLayout.Center;
00846 }
00847
00848
00854 private void TransferFunctionPanel_MouseDown(object sender, MouseEventArgs e)
00855 {
00856 if (!transferfunctionCheckBox.Checked) return;
00857
00858 Point newPos = clampToPanelDimensions(e.X, e.Y);
00859
00860 if (e.Button == MouseButtons.Left)
00861 {
00862 tfPanelMouseDown = true;
00863 tfPanelMouseDownPos = newPos;
00864 }
00865
00866 #region create new control point or edit one
00867 if (e.Button == MouseButtons.Right)
00868 {
00869 ColorDialog colorPicker = new ColorDialog();
00870 colorPicker.Color = XNAToWindowsFormsColor(GameProperties.Instance.colorArray[newPos.X]);
00871
00872
00873
00874 if (colorPicker.ShowDialog() == DialogResult.OK)
00875 {
00876 Color color = colorPicker.Color;
00877
00878 float r = (float)(color.R / 255.0f);
00879 float g = (float)(color.G / 255.0f);
00880 float b = (float)(color.B / 255.0f);
00881 float a = (float)((255 - newPos.Y) / 255.0f);
00882
00883 int key = getControlPointKey(newPos);
00884
00885 if (key == -1)
00886 {
00887
00888
00889 GameProperties.Instance.colorControlPoints.Add(new TransferControlPoint(r, g, b, (int)(newPos.X / stepsize)));
00890 GameProperties.Instance.alphaControlPoints.Add(new TransferControlPoint(a, (int)(newPos.X / stepsize)));
00891 TransferControlPoint cpNew = new TransferControlPoint(r, g, b, (int)(newPos.X / stepsize));
00892 cpNew.color.W = a;
00893 controlPoints.Add(newPos.X, cpNew);
00894 }
00895 else
00896 {
00897 controlPoints[key].color.X = r;
00898 controlPoints[key].color.Y = g;
00899 controlPoints[key].color.Z = b;
00900 controlPoints[key].color.W = a;
00901
00902 int currIsoValue = controlPoints[key].isoValue;
00903
00904 for (int i = 0; i < GameProperties.Instance.colorControlPoints.Count(); i++)
00905 {
00906 if (GameProperties.Instance.colorControlPoints[i].isoValue == currIsoValue
00907 && GameProperties.Instance.alphaControlPoints[i].isoValue == currIsoValue)
00908 {
00909 GameProperties.Instance.colorControlPoints[i].color.X = r;
00910 GameProperties.Instance.colorControlPoints[i].color.Y = g;
00911 GameProperties.Instance.colorControlPoints[i].color.Z = b;
00912 GameProperties.Instance.alphaControlPoints[i].color.W = a;
00913 i = GameProperties.Instance.colorControlPoints.Count();
00914 }
00915 }
00916
00917 }
00918
00919
00920
00921
00922
00923 inputManager.updateXnaEngineState(false, false, true, true);
00924
00925
00926 updateColorArray = true;
00927 TransferFunctionPanel.Invalidate();
00928
00929 }
00930 }
00931 #endregion
00932
00933 }
00934
00940 private void TransferFunctionPanel_MouseMove(object sender, MouseEventArgs e)
00941 {
00942 if (!transferfunctionCheckBox.Checked) return;
00943
00944
00945
00946 if (tfPanelMouseDown)
00947 {
00948
00949 int key = getControlPointKey(tfPanelMouseDownPos);
00950 if (key != -1)
00951 {
00952 tfPanelMouseDownPos.X = key;
00953 Point newPos = clampToPanelDimensions(e.X, e.Y);
00954
00955 int oldIsoValue = (tfPanelMouseDownPos.X / stepsize);
00956 int newIsoValue = (newPos.X / stepsize);
00957 float newAlpaValue = (float)((255 - newPos.Y) / 255.0f);
00958
00959
00960
00961
00962 if (newIsoValue == oldIsoValue)
00963 {
00964 controlPoints[newPos.X].color.W = newAlpaValue;
00965 }
00966 else
00967 {
00968
00969
00970 TransferControlPoint cp = controlPoints[tfPanelMouseDownPos.X];
00971 cp.isoValue = newIsoValue;
00972 cp.color.W = newAlpaValue;
00973 controlPoints.Remove(tfPanelMouseDownPos.X);
00974 if (controlPoints.ContainsKey(newPos.X))
00975 controlPoints[newPos.X] = cp;
00976 else controlPoints.Add(newPos.X, cp);
00977
00978 }
00979
00980
00981
00982 for (int i = 0; i < GameProperties.Instance.colorControlPoints.Count(); i++)
00983 {
00984 if (GameProperties.Instance.colorControlPoints[i].isoValue == oldIsoValue
00985 && GameProperties.Instance.alphaControlPoints[i].isoValue == oldIsoValue)
00986 {
00987 GameProperties.Instance.colorControlPoints[i].isoValue = newIsoValue;
00988 GameProperties.Instance.alphaControlPoints[i].isoValue = newIsoValue;
00989 GameProperties.Instance.alphaControlPoints[i].color.W = newAlpaValue;
00990 i = GameProperties.Instance.colorControlPoints.Count();
00991 }
00992 }
00993
00994
00995
00996
00997
00998
00999 tfPanelMouseDownPos = newPos;
01000
01001
01002 inputManager.updateXnaEngineState(false, false, true, true);
01003
01004
01005 updateColorArray = true;
01006 TransferFunctionPanel.Invalidate();
01007 }
01008 }
01009
01010 }
01011
01012 private void TransferFunctionPanel_MouseUp(object sender, MouseEventArgs e)
01013 {
01014 tfPanelMouseDown = false;
01015 }
01016
01017 #endregion
01018
01019 #region extended features
01020
01021
01027 private void handleMaxIntensityProjCheckBox(object sender, EventArgs e)
01028 {
01029 if (MaxIntensityProjCheckBox.Checked)
01030 {
01031 maximumIntensityProjectionToolStripMenuItem.Checked = true;
01032 }
01033 else
01034 {
01035 maximumIntensityProjectionToolStripMenuItem.Checked = false;
01036 }
01037 inputManager.enableMaxIntensityProjection(MaxIntensityProjCheckBox.Checked);
01038 }
01039
01045 private void handlePerspProjRadioButt(object sender, EventArgs e)
01046 {
01047 perspectiveProjectionToolStripMenuItem.Checked = true;
01048 orthogonalProjectionToolStripMenuItem.Checked = false;
01049 inputManager.enablePerspProjection(true);
01050 }
01051
01057 private void handleOrthProjRadioButt(object sender, EventArgs e)
01058 {
01059 perspectiveProjectionToolStripMenuItem.Checked = false;
01060 orthogonalProjectionToolStripMenuItem.Checked = true;
01061 inputManager.enablePerspProjection(false);
01062 }
01063
01069 private void handleBlendRadioButt1(object sender, EventArgs e)
01070 {
01071 frontToBackBlendingToolStripMenuItem.Checked = true;
01072 backToFrontBlendingToolStripMenuItem.Checked = false;
01073 inputManager.enableFrontToBackBlending(true);
01074 }
01075
01081 private void handleBlendRadioButt2(object sender, EventArgs e)
01082 {
01083 frontToBackBlendingToolStripMenuItem.Checked = false;
01084 backToFrontBlendingToolStripMenuItem.Checked = true;
01085 inputManager.enableFrontToBackBlending(false);
01086 }
01087
01093 private void handleShadingCheckBox(object sender, EventArgs e)
01094 {
01095 if (ShadingCheckBox.Checked)
01096 {
01097 shadingToolStripMenuItem.Checked = true;
01098 }
01099 else
01100 {
01101 shadingToolStripMenuItem.Checked = false;
01102 }
01103 inputManager.enableShading(ShadingCheckBox.Checked);
01104 }
01105
01106 #endregion
01107
01108 #endregion
01109
01110 #endregion
01111
01112 #region helper functions
01113
01114
01118 private void updateIsoValuesData()
01119 {
01120 if (GameProperties.Instance.distinctDensityValues != null && GameProperties.Instance.distinctDensityValues.Length > 0)
01121 {
01122 isoValues = GameProperties.Instance.distinctDensityValues;
01123 isoValuesFrequency = GameProperties.Instance.countDensityValues;
01124 int width = this.TransferFunctionPanel.Width;
01125 int height = this.TransferFunctionPanel.Height;
01126
01127 float minIso = isoValues[0];
01128 float maxIso = isoValues[isoValues.Length - 1];
01129 stepsize = (int)(width / Math.Abs(maxIso - minIso));
01130 float maxFrequency = (float)Math.Log10(isoValuesFrequency.Max());
01131 for (int i = 0; i < isoValuesFrequency.Length; i++)
01132 {
01133 isoValuesFrequency[i] = (int)(((Math.Log10((float)isoValuesFrequency[i])) / maxFrequency) * (height));
01134 }
01135
01136 updateIsoValues = false;
01137 }
01138
01139 }
01140
01144 private void updateControlPointsData()
01145 {
01146
01147
01148 if (GameProperties.Instance.colorControlPoints != null && GameProperties.Instance.colorControlPoints.Count() > 0)
01149 {
01150 controlPoints.Clear();
01151 for (int i = 0; i < GameProperties.Instance.colorControlPoints.Count(); i++)
01152 {
01153 int cpValue = GameProperties.Instance.colorControlPoints[i].isoValue;
01154 TransferControlPoint cpNext = GameProperties.Instance.colorControlPoints[i];
01155 cpNext.color.W = GameProperties.Instance.alphaControlPoints[i].color.W;
01156 controlPoints.Add(cpValue, cpNext);
01157 }
01158
01159 }
01160 else
01161 {
01162 TransferControlPoint cp1 = new TransferControlPoint(0.0f, 0.0f, 0.0f, 0);
01163 TransferControlPoint cp2 = new TransferControlPoint(1.0f, 0.0f, 0.0f, 80);
01164 TransferControlPoint cp3 = new TransferControlPoint(0.0f, 1.0f, 0.0f, 128);
01165 TransferControlPoint cp4 = new TransferControlPoint(0.0f, 0.0f, 0.0f, 255);
01166
01167 GameProperties.Instance.colorControlPoints.Add(cp1);
01168 GameProperties.Instance.colorControlPoints.Add(cp2);
01169 GameProperties.Instance.colorControlPoints.Add(cp3);
01170 GameProperties.Instance.colorControlPoints.Add(cp4);
01171 GameProperties.Instance.alphaControlPoints.Add(new TransferControlPoint(0.0f, 0));
01172 GameProperties.Instance.alphaControlPoints.Add(new TransferControlPoint(0.5f, 80));
01173 GameProperties.Instance.alphaControlPoints.Add(new TransferControlPoint(0.5f, 128));
01174 GameProperties.Instance.alphaControlPoints.Add(new TransferControlPoint(0.0f, 255));
01175
01176 TransferControlPoint cp1_ = new TransferControlPoint(0.0f, 0.0f, 0.0f, 0);
01177 TransferControlPoint cp2_ = new TransferControlPoint(1.0f, 0.0f, 0.0f, 80);
01178 TransferControlPoint cp3_ = new TransferControlPoint(0.0f, 1.0f, 0.0f, 128);
01179 TransferControlPoint cp4_ = new TransferControlPoint(0.0f, 0.0f, 0.0f, 255);
01180 cp1_.color.W = 0.0f;
01181 cp2_.color.W = 0.5f;
01182 cp3_.color.W = 0.5f;
01183 cp4_.color.W = 0.0f;
01184
01185 controlPoints.Add(0, cp1_);
01186 controlPoints.Add(80, cp2_);
01187 controlPoints.Add(128, cp3_);
01188 controlPoints.Add(255, cp4_);
01189
01190 }
01191
01192 updateControlPoints = false;
01193 }
01194
01198 private void updateColorArrayData()
01199 {
01200 if (GameProperties.Instance.colorArray != null && GameProperties.Instance.colorArray.Count() > 0)
01201 {
01202 for (int i = 0; i < GameProperties.Instance.colorArray.Count(); i++)
01203 {
01204 colorArray[i] = XNAToWindowsFormsColor(GameProperties.Instance.colorArray[i]);
01205 colorArray[i] = Color.FromArgb((int)(GameProperties.Instance.alphaArray[i] * 255), colorArray[i]);
01206 }
01207
01208 updateColorArray = false;
01209 }
01210 }
01211
01217 private Color XNAToWindowsFormsColor(Microsoft.Xna.Framework.Vector4 xnaColor)
01218 {
01219 int r = (int)(xnaColor.X * 255);
01220 int g = (int)(xnaColor.Y * 255);
01221 int b = (int)(xnaColor.Z * 255);
01222 int a = (int)(xnaColor.W * 255);
01223
01224 Color color = Color.FromArgb(a, r, g, b);
01225 return color;
01226 }
01227
01233 private Color XNAToWindowsFormsColor(Microsoft.Xna.Framework.Graphics.Color xnaColor)
01234 {
01235 Color color = Color.FromArgb(xnaColor.A, xnaColor.R, xnaColor.G, xnaColor.B);
01236 return color;
01237 }
01238
01239
01247 private Color lerpColor(Color c1, Color c2, float amount)
01248 {
01249 int r = (int)(c1.R + amount * (c2.R - c1.R));
01250 int g = (int)(c1.G + amount * (c2.G - c1.G));
01251 int b = (int)(c1.B + amount * (c2.B - c1.B));
01252 int a = (int)(c1.A + amount * (c2.A - c1.A));
01253 Color lerpColor = Color.FromArgb(a, r, g, b);
01254 lerpColor = Color.FromArgb(255, lerpColor);
01255
01256 return lerpColor;
01257 }
01258
01264 private int getControlPointKey(Point mousePos)
01265 {
01266 if (controlPoints.ContainsKey(mousePos.X)) return mousePos.X;
01267 else
01268 {
01269 foreach (int key in controlPoints.Keys)
01270 {
01271 if (mousePos.X >= (key - (controlPointSize.Width / 2)) &&
01272 mousePos.X <= (key + (controlPointSize.Width / 2)))
01273 {
01274 return key;
01275 }
01276 }
01277 }
01278
01279
01280
01281
01282 return -1;
01283 }
01284
01285 private Point clampToPanelDimensions(int posX, int posY)
01286 {
01287 Point p = new Point(posX, posY);
01288 if (p.X < 0) { p.X = 0; }
01289 else if (p.X > this.TransferFunctionPanel.Width - 1)
01290 { p.X = this.TransferFunctionPanel.Width - 1; }
01291 if (p.Y < 0) { p.Y = 0; }
01292 else if (p.Y > this.TransferFunctionPanel.Height - 1)
01293 { p.Y = this.TransferFunctionPanel.Height - 1; }
01294 return p;
01295 }
01296 #endregion
01297
01298 #region handle xna draw surface events
01299
01305 private void handleXNADrawSurface_MouseDoubleClick(object sender, MouseEventArgs e)
01306 {
01307 inputManager.setViewMode();
01308 volViewToolStripMenuItem.Checked = false;
01309 topViewToolStripMenuItem.Checked = false;
01310 sideViewToolStripMenuItem.Checked = false;
01311 frontViewToolStripMenuItem.Checked = false;
01312 XSliceGroup.Enabled = false;
01313 YSliceGroup.Enabled = false;
01314 ZSliceGroup.Enabled = false;
01315 switch (inputManager.getViewMode())
01316 {
01317
01318 case 0:
01319 volViewToolStripMenuItem.Checked = true;
01320 break;
01321 case 1:
01322 topViewToolStripMenuItem.Checked = true;
01323 YSliceGroup.Enabled = true;
01324 break;
01325 case 2:
01326 sideViewToolStripMenuItem.Checked = true;
01327 XSliceGroup.Enabled = true;
01328 break;
01329 case 3:
01330 frontViewToolStripMenuItem.Checked = true;
01331 ZSliceGroup.Enabled = true;
01332 break;
01333 default:
01334 volViewToolStripMenuItem.Checked = true;
01335 break;
01336
01337 }
01338 inputManager.updateXnaEngineState(true, false, true, true);
01339 }
01340
01341
01342 private void handleXNADrawSurface_MouseDown(object sender, MouseEventArgs e)
01343 {
01344 inputManager.XnaDrawSurface_MouseDownEvent = true;
01345 inputManager.MouseDownPosX = e.X;
01346 inputManager.MouseDownPosY = e.Y;
01347
01348 }
01349
01350 private void handleXNADrawSurface_MouseUp(object sender, MouseEventArgs e)
01351 {
01352 inputManager.XnaDrawSurface_MouseDownEvent = false;
01353 inputManager.resetMousePos();
01354 }
01355
01356 private void handleXNADrawSurface_MouseMove(object sender, MouseEventArgs e)
01357 {
01358 if (inputManager.XnaDrawSurface_MouseDownEvent)
01359 {
01360 inputManager.updateMousePos(e.X, e.Y);
01361 inputManager.updateXnaEngineState(true, false, true, true);
01362 }
01363 }
01364
01365 private void handleXNADrawSurface_MouseScroll(object sender, MouseEventArgs e)
01366 {
01367 if (inputManager.XnaDrawSurface_MouseDownEvent)
01368 {
01369 inputManager.updateMouseScroll(e.Delta / SystemInformation.MouseWheelScrollDelta);
01370
01371 inputManager.updateXnaEngineState(true, false, true, true);
01372 }
01373 }
01374 #endregion
01375
01376
01377
01378 }
01379 }