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 visLU2.Gui;
00013 #endregion
00014
00015 namespace visLU2.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
00032 List<SortedDictionary<int, TransferControlPoint>> channelControlPoints;
00033 List<Color[]> channelColorArray;
00034 int tfStepsize = 1;
00035 public bool updateChannelControlPoints = false;
00036 int currChannelIdx;
00037
00038
00039 SortedDictionary<int, TransferControlPoint> arrowControlPoints;
00040 Color[] arrowColorArray;
00041
00042 bool updateArrowControlPoints = false;
00043
00044 bool dataLoaded = false;
00045 bool tfPanelMouseDown = false;
00046 Point tfPanelMouseDownPos = new Point();
00047 #endregion
00048
00049 #region other variables
00050 string assemblyLocation = Assembly.GetExecutingAssembly().Location;
00051 InputManager inputManager;
00052 #endregion
00053
00057 public MainWindow()
00058 {
00059 InitializeComponent();
00060 SetStyle(ControlStyles.OptimizedDoubleBuffer |
00061 ControlStyles.UserPaint |
00062 ControlStyles.AllPaintingInWmPaint, true);
00063
00064 inputManager = new InputManager();
00065
00066 channelControlPoints = new List<SortedDictionary<int, TransferControlPoint>>();
00067
00068 channelColorArray = new List<Color[]>();
00069
00070 arrowControlPoints = new SortedDictionary<int, TransferControlPoint>();
00071 arrowColorArray = new Color[256];
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 public void updateChannelControl(List<string> channelNames, int currChannelIdx)
00116 {
00117
00118 this.EnableChannelsCheckbox.Checked = GameProperties.Instance.enableChannels;
00119 this.ChannelsCompoBox.Items.Clear();
00120 foreach (string item in channelNames)
00121 {
00122 this.ChannelsCompoBox.Items.Add(item);
00123 }
00124
00125 this.ChannelsCompoBox.SelectedIndex = currChannelIdx;
00126 this.currChannelIdx = currChannelIdx;
00127 this.transferfunctionCheckBox.Checked = GameProperties.Instance.enableChannelTransferFunction;
00128 this.ComposeChannelsCheckBox.Checked = GameProperties.Instance.composeChannels;
00129 this.updateChannelControlPoints = true;
00130 this.dataLoaded = GameProperties.Instance.dataLoaded;
00131 TransferFunctionPanel.Invalidate();
00132
00133 }
00134
00135 public void updateArrowPlotControl()
00136 {
00137 this.EnableArrowPlotCheckBox.Checked = GameProperties.Instance.enableArrowPlot;
00138 if (GameProperties.Instance.scaleArrowLength)
00139 {
00140 this.UniformArrowRadio.Checked = false;
00141 this.ScaledArrowRadio.Checked = true;
00142 }
00143 else
00144 {
00145 this.UniformArrowRadio.Checked = true;
00146 this.ScaledArrowRadio.Checked = false;
00147 }
00148 this.ArrowStepsizeScrollbar.Value = (int)GameProperties.Instance.apStepsize;
00149 this.ArrowDensityLabel.Text = this.ArrowStepsizeScrollbar.Value.ToString();
00150 this.ArrowPlotEnableColor.Checked = GameProperties.Instance.enableArrowTransferFunction;
00151 this.ArrowAlphaScrollBar.Value = (int)(GameProperties.Instance.apAlpha * 255);
00152 this.ArrowAlphaLabel.Text = this.ArrowAlphaScrollBar.Value.ToString();
00153 this.updateArrowControlPoints = true;
00154 this.dataLoaded = GameProperties.Instance.dataLoaded;
00155 ArrowPlotColorPanel.Invalidate();
00156 }
00157
00158 public void updateStreamlineControl(float maxLineLength)
00159 {
00160 this.EnableStreamlinesCheckBox.Checked = GameProperties.Instance.enableStreamlines;
00161 if (GameProperties.Instance.enableRungeKutta)
00162 {
00163 this.EulerRadioButton.Checked = false;
00164 this.RungeKuttaRadioButton.Checked = true;
00165 }
00166 else
00167 {
00168 this.EulerRadioButton.Checked = true;
00169 this.RungeKuttaRadioButton.Checked = false;
00170 }
00171
00172 this.StreamlineDtNumUpDown.Value = (decimal)GameProperties.Instance.Dt;
00173
00174 float dsep = GameProperties.Instance.Dsep / GameProperties.Instance.maxDsep;
00175 this.StreamlineDsepSlider.Value = (int)(dsep * (this.StreamlineDsepSlider.Maximum - (this.StreamlineDsepSlider.LargeChange - 1)));
00176 this.StreamlineDsepLabel.Text = dsep.ToString();
00177
00178 float dtest = GameProperties.Instance.Dtest / GameProperties.Instance.Dsep;
00179 this.StreamlineDtestSlider.Value = (int)(dtest * (this.StreamlineDtestSlider.Maximum - (this.StreamlineDtestSlider.LargeChange - 1)));
00180 this.StreamlineDtestLabel.Text = dtest.ToString();
00181 this.StreamlineStyleRadio1.Checked = false;
00182 this.StreamlineStyleRadio2.Checked = false;
00183 this.StreamlineStyleRadio3.Checked = false;
00184 this.StreamlineStyleRadio4.Checked = false;
00185 if (GameProperties.Instance.enableTapering)
00186 {
00187 this.StreamlineStyleRadio2.Checked = true;
00188 }
00189 else if (GameProperties.Instance.enableGlyphMapping)
00190 {
00191 this.StreamlineStyleRadio3.Checked = true;
00192 }
00193 else if (GameProperties.Instance.enableTextureGeneration)
00194 {
00195 this.StreamlineStyleRadio4.Checked = true;
00196 }
00197 else
00198 {
00199 this.StreamlineStyleRadio1.Checked = true;
00200 }
00201 this.StreamlineLengthUpDown.Value = (decimal)GameProperties.Instance.lineLength;
00202 this.StreamlineLengthUpDown.Maximum = (decimal)maxLineLength;
00203 this.StreamlineWidthUpDown.Value = (decimal)(GameProperties.Instance.lineWidth / GameProperties.Instance.Dtest);
00204 }
00205
00206 #endregion
00207
00208 #region event handler
00209
00210 #region main menu handler
00211
00212 #region file menu
00213
00214
00215
00216
00217
00218 private void handleOpenFileMenu(object sender, EventArgs e)
00219 {
00220
00221
00222 string relativePath = Path.Combine(assemblyLocation, "../../../../Data");
00223 string contentPath = Path.GetFullPath(relativePath);
00224
00225 this.openFileDialog.InitialDirectory = contentPath;
00226
00227 this.openFileDialog.Title = "Load Data Set";
00228
00229 this.openFileDialog.Filter = "Data Files (*.gri)|*.gri";
00230
00231 if (this.openFileDialog.ShowDialog() == DialogResult.OK)
00232 {
00233 if (GameProperties.Instance.relativePath)
00234 {
00235 String[] splitName = openFileDialog.FileName.Split('\\');
00236 String dataFileName = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf(splitName[splitName.Length - 2]));
00237 GameProperties.Instance.dataDir = "Data\\";
00238 GameProperties.Instance.dataFilename = dataFileName;
00239 }
00240 else
00241 {
00242 GameProperties.Instance.dataDir = "";
00243 GameProperties.Instance.dataFilename = openFileDialog.FileName;
00244 }
00245
00246 inputManager.updateXnaEngineState(true, true, true, true);
00247 transferfunctionToolStripMenuItem.Enabled = true;
00248
00249 }
00250 }
00251
00257 private void handleSaveFileMenu(object sender, EventArgs e)
00258 {
00259 string relativePath = Path.Combine(assemblyLocation, "../../../../Data/Screenshots");
00260 string contentPath = Path.GetFullPath(relativePath);
00261
00262 this.saveFileDialog.InitialDirectory = contentPath;
00263
00264 this.saveFileDialog.Title = "Save Image as";
00265
00266 this.saveFileDialog.Filter = "JPG Files (*.jpg)|*.jpg";
00267
00268 if (this.saveFileDialog.ShowDialog() == DialogResult.OK)
00269 {
00270 GameProperties.Instance.saveFilename = saveFileDialog.FileName;
00271 GameProperties.Instance.saveView = true;
00272 GameProperties.Instance.engineState.drawData = true;
00273 }
00274 }
00275
00281 private void handleExitMenu(object sender, EventArgs e)
00282 {
00283 GameProperties.Instance.exitGame = true;
00284
00285 }
00286
00292 private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
00293 {
00294 GameProperties.Instance.exitGame = true;
00295 }
00296 #endregion
00297
00298 #region functions menu
00299
00305 private void handlePerspProjMenu(object sender, EventArgs e)
00306 {
00307 if (perspectiveProjectionToolStripMenuItem.Checked)
00308 {
00309 perspectiveProjectionToolStripMenuItem.Checked = false;
00310 orthogonalProjectionToolStripMenuItem.Checked = true;
00311 UniformArrowRadio.Checked = false;
00312 ScaledArrowRadio.Checked = true;
00313 }
00314 else
00315 {
00316 perspectiveProjectionToolStripMenuItem.Checked = true;
00317 orthogonalProjectionToolStripMenuItem.Checked = false;
00318 UniformArrowRadio.Checked = true;
00319 ScaledArrowRadio.Checked = false;
00320 }
00321 inputManager.enablePerspProjection(UniformArrowRadio.Checked);
00322 }
00323
00329 private void handleOrthProjMenu(object sender, EventArgs e)
00330 {
00331 if (orthogonalProjectionToolStripMenuItem.Checked)
00332 {
00333 perspectiveProjectionToolStripMenuItem.Checked = true;
00334 orthogonalProjectionToolStripMenuItem.Checked = false;
00335 UniformArrowRadio.Checked = true;
00336 ScaledArrowRadio.Checked = false;
00337 }
00338 else
00339 {
00340 perspectiveProjectionToolStripMenuItem.Checked = false;
00341 orthogonalProjectionToolStripMenuItem.Checked = true;
00342 UniformArrowRadio.Checked = false;
00343 ScaledArrowRadio.Checked = true;
00344 }
00345 inputManager.enablePerspProjection(UniformArrowRadio.Checked);
00346 }
00347
00348
00349 private void handleBlendModeMenu(object sender, EventArgs e)
00350 {
00351 if (sender == frontToBackBlendingToolStripMenuItem)
00352 {
00353 if (frontToBackBlendingToolStripMenuItem.Checked)
00354 {
00355 frontToBackBlendingToolStripMenuItem.Checked = false;
00356 backToFrontBlendingToolStripMenuItem.Checked = true;
00357 }
00358 else
00359 {
00360 frontToBackBlendingToolStripMenuItem.Checked = true;
00361 backToFrontBlendingToolStripMenuItem.Checked = false;
00362 }
00363
00364 }
00365 else if (sender == backToFrontBlendingToolStripMenuItem)
00366 {
00367 if (backToFrontBlendingToolStripMenuItem.Checked)
00368 {
00369 frontToBackBlendingToolStripMenuItem.Checked = true;
00370 backToFrontBlendingToolStripMenuItem.Checked = false;
00371 }
00372 else
00373 {
00374 frontToBackBlendingToolStripMenuItem.Checked = false;
00375 backToFrontBlendingToolStripMenuItem.Checked = true;
00376 }
00377
00378 }
00379 inputManager.enableFrontToBackBlending(frontToBackBlendingToolStripMenuItem.Checked);
00380 }
00381
00382
00383 private void handleShadingMenu(object sender, EventArgs e)
00384 {
00385 if (shadingToolStripMenuItem.Checked)
00386 {
00387 shadingToolStripMenuItem.Checked = false;
00388 }
00389 else
00390 {
00391 shadingToolStripMenuItem.Checked = true;
00392 }
00393
00394 inputManager.enableShading(shadingToolStripMenuItem.Checked);
00395 }
00396
00397
00398
00404 private void handleLoadTransferFunctionMenu(object sender, EventArgs e)
00405 {
00406 string relativePath = Path.Combine(assemblyLocation, "../../../../Data/Transferfunction");
00407 string contentPath = Path.GetFullPath(relativePath);
00408
00409 this.openFileDialog.InitialDirectory = contentPath;
00410
00411 this.openFileDialog.Title = "Load Transferfunction";
00412
00413 this.openFileDialog.Filter = "XML Files (*.xml)|*.xml";
00414
00415 if (this.openFileDialog.ShowDialog() == DialogResult.OK)
00416 {
00417 this.inputManager.loadTransferFunction(openFileDialog.FileName);
00418 this.inputManager.updateXnaEngineState(false, false, true, true);
00419 this.inputManager.updateXnaTF(false, true);
00420 updateGuiTF(false, false, true, true);
00421 }
00422 }
00423
00424
00425
00431 private void handleSaveTransferFunctionMenu(object sender, EventArgs e)
00432 {
00433 string relativePath = Path.Combine(assemblyLocation, "../../../../Data/Transferfunction");
00434 string contentPath = Path.GetFullPath(relativePath);
00435
00436 this.saveFileDialog.InitialDirectory = contentPath;
00437
00438 this.saveFileDialog.Title = "Save Transferfunction as";
00439
00440 this.saveFileDialog.Filter = "XML Files (*.xml)|*.xml";
00441
00442 if (this.saveFileDialog.ShowDialog() == DialogResult.OK)
00443 {
00444 this.inputManager.saveTransferFunction(saveFileDialog.FileName);
00445 }
00446 }
00447
00448
00454 private void handleEditTransferFunctionMenu(object sender, EventArgs e)
00455 {
00456 TransferfunctionForm transferFunctionDialog = new TransferfunctionForm();
00457 transferFunctionDialog.Show();
00458 }
00459
00460
00461
00462 #endregion
00463
00464 #region help menu
00465
00466 #endregion
00467
00468 #endregion
00469
00470 #region settings panel (right tab panel)
00471
00472 #region arrow plot tab
00473 private void handleArrowRadioButt(object sender, EventArgs e)
00474 {
00475 if (UniformArrowRadio.Checked)
00476 {
00477 inputManager.enableScaledArrowLength(false);
00478 }
00479 else
00480 {
00481 inputManager.enableScaledArrowLength(true);
00482 }
00483 }
00484
00485 private void handleArrowPlotScrollbar(object sender, EventArgs e)
00486 {
00487 if (sender == ArrowStepsizeScrollbar)
00488 {
00489 this.ArrowDensityLabel.Text = ArrowStepsizeScrollbar.Value.ToString();
00490 inputManager.setArrowPlotParam(1, (float)ArrowStepsizeScrollbar.Value);
00491
00492 }
00493 else if (sender == ArrowAlphaScrollBar)
00494 {
00495 this.ArrowAlphaLabel.Text = ArrowAlphaScrollBar.Value.ToString();
00496 inputManager.setArrowPlotParam(2, (float)((float)ArrowAlphaScrollBar.Value / 255));
00497
00498 }
00499
00500
00501 }
00502
00503 private void handleArrowPlotTransFunctionCheckbox(object sender, EventArgs e)
00504 {
00505 inputManager.enableArrowPlotTransferFunction(this.ArrowPlotEnableColor.Checked);
00506 }
00507
00508 private void handleArrowPlotCheckbox(object sender, EventArgs e)
00509 {
00510 inputManager.enableArrowPlot(this.EnableArrowPlotCheckBox.Checked);
00511 }
00512 #endregion
00513
00514 #region channel tab
00515
00516 private void handleEnableChannelsCheckBox(object sender, EventArgs e)
00517 {
00518 inputManager.enableChannels(EnableChannelsCheckbox.Checked);
00519 }
00520
00521 private void handleChannelComboBoxSelect(object sender, EventArgs e)
00522 {
00523 GameProperties.Instance.currentChannelIdx = this.ChannelsCompoBox.SelectedIndex;
00524 currChannelIdx = this.ChannelsCompoBox.SelectedIndex;
00525 if (GameProperties.Instance.enableChannelTransferFunction)
00526 {
00527 TransferFunctionPanel.Refresh();
00528 }
00529 this.inputManager.updateXnaEngineState(false, false, true, true);
00530 this.updateChannelControlPoints = true;
00531 TransferFunctionPanel.Refresh();
00532 }
00533
00534 private void handleComposeChannelsCheckBox(object sender, EventArgs e)
00535 {
00536 if (this.ComposeChannelsCheckBox.Checked)
00537 {
00538
00539
00540 }
00541 else
00542 {
00543
00544
00545 }
00546 inputManager.enableComposeChannels(this.ComposeChannelsCheckBox.Checked);
00547 }
00548 #endregion
00549
00550 #region transfer function panel
00551
00552
00553
00554
00555
00556 private void handleTransferFunctionCheckbox(object sender, EventArgs e)
00557 {
00558 if (!transferfunctionCheckBox.Checked)
00559 enableTransferfunctionToolStripMenuItem.Checked = transferfunctionCheckBox.Checked;
00560 inputManager.enableTransferFunction(transferfunctionCheckBox.Checked);
00561 TransferFunctionPanel.Refresh();
00562 }
00563
00569 private void TransferFunctionPanel_Paint(object sender, PaintEventArgs e)
00570 {
00571
00572 Graphics grobj = e.Graphics;
00573
00574 grobj.PageUnit = GraphicsUnit.Pixel;
00575 grobj.PageScale = 1;
00576 grobj.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
00577
00578 int width = TransferFunctionPanel.Width;
00579 int height = TransferFunctionPanel.Height;
00580 grobj.DrawRectangle(penGray, new Rectangle(0, 0, width - 1, height - 1));
00581
00582 if (!dataLoaded) return;
00583
00584 #region arrow plot
00585 if (sender == this.ArrowPlotColorPanel)
00586 {
00587 width = ArrowPlotColorPanel.Width;
00588 height = ArrowPlotColorPanel.Height;
00589
00590
00591 if (updateArrowControlPoints)
00592 {
00593 updateArrowControlPointsData();
00594 }
00595
00596
00597 if (arrowControlPoints.Count() > 0)
00598 {
00599
00600 List<Point> pList = new List<Point>();
00601 Color c1 = XNAToWindowsFormsColor(arrowControlPoints.First().Value.color);
00602 Point p1 = new Point(arrowControlPoints.First().Key, 255 - c1.A);
00603 pList.Add(p1);
00604 p1.X -= controlPointSize.Width / 2;
00605 p1.Y -= controlPointSize.Height / 2;
00606
00607 Rectangle rect = new Rectangle(p1, controlPointSize);
00608 grobj.DrawRectangle(penBlack, rect);
00609 grobj.FillRectangle(new SolidBrush(c1), rect);
00610
00611 IEnumerable<KeyValuePair<int, TransferControlPoint>> controlPointsTmp = arrowControlPoints.Skip(1);
00612 foreach (KeyValuePair<int, TransferControlPoint> cp in controlPointsTmp)
00613 {
00614
00615 Color c2 = XNAToWindowsFormsColor(cp.Value.color);
00616 Point p2 = new Point(cp.Key, 255 - c2.A);
00617 pList.Add(p2);
00618
00619 p2.X -= controlPointSize.Width / 2;
00620 p2.Y -= controlPointSize.Height / 2;
00621
00622 rect = new Rectangle(p2, controlPointSize);
00623 grobj.DrawRectangle(penBlack, rect);
00624 grobj.FillRectangle(new SolidBrush(c2), rect);
00625
00626 p1 = p2;
00627
00628 }
00629 grobj.DrawLines(penBlack, pList.ToArray());
00630
00631 }
00632
00633
00634 if (GameProperties.Instance.updateArrowColor)
00635 {
00636 updateArrowColorArrayData();
00637 }
00638
00639
00640 if (arrowColorArray.Length > 0)
00641 {
00642 Rectangle rect1;
00643 colorBarSize.Width = tfStepsize;
00644 {
00645 for (int i = 0; i < arrowColorArray.Length; i++)
00646 {
00647 grobj.FillRectangle(new SolidBrush(arrowColorArray[i]), new Rectangle(new Point(i, 0), new Size(1, height)));
00648 }
00649 }
00650 }
00651 }
00652 #endregion
00653
00654 #region channels
00655
00656 if (sender == this.TransferFunctionPanel)
00657 {
00658 width = TransferFunctionPanel.Width;
00659 height = TransferFunctionPanel.Height;
00660
00661
00662 if (updateChannelControlPoints)
00663 {
00664 updateChannelControlPointsData();
00665 }
00666
00667
00668 if (channelControlPoints.Count() > 0 && channelControlPoints[currChannelIdx].Count() > 0)
00669 {
00670
00671 List<Point> pList = new List<Point>();
00672 Color c1 = XNAToWindowsFormsColor(channelControlPoints[currChannelIdx].First().Value.color);
00673 Point p1 = new Point(channelControlPoints[currChannelIdx].First().Key, 255 - c1.A);
00674 pList.Add(p1);
00675 p1.X -= controlPointSize.Width / 2;
00676 p1.Y -= controlPointSize.Height / 2;
00677
00678 Rectangle rect = new Rectangle(p1, controlPointSize);
00679 grobj.DrawRectangle(penBlack, rect);
00680 grobj.FillRectangle(new SolidBrush(c1), rect);
00681
00682 IEnumerable<KeyValuePair<int, TransferControlPoint>> controlPointsTmp = channelControlPoints[currChannelIdx].Skip(1);
00683 foreach (KeyValuePair<int, TransferControlPoint> cp in controlPointsTmp)
00684 {
00685
00686 Color c2 = XNAToWindowsFormsColor(cp.Value.color);
00687 Point p2 = new Point(cp.Key, 255 - c2.A);
00688 pList.Add(p2);
00689
00690 p2.X -= controlPointSize.Width / 2;
00691 p2.Y -= controlPointSize.Height / 2;
00692
00693 rect = new Rectangle(p2, controlPointSize);
00694 grobj.DrawRectangle(penBlack, rect);
00695 grobj.FillRectangle(new SolidBrush(c2), rect);
00696
00697 p1 = p2;
00698
00699 }
00700 grobj.DrawLines(penBlack, pList.ToArray());
00701
00702 }
00703
00704
00705 if (GameProperties.Instance.updateChannelColor)
00706 {
00707 updateChannelColorArrayData();
00708 }
00709
00710
00711 if (channelColorArray.Count() > 0 && channelColorArray[currChannelIdx].Length > 0)
00712 {
00713 Rectangle rect1;
00714 colorBarSize.Width = tfStepsize;
00715 {
00716 for (int i = 0; i < channelColorArray[currChannelIdx].Length; i++)
00717 {
00718 grobj.FillRectangle(new SolidBrush(channelColorArray[currChannelIdx][i]), new Rectangle(new Point(i, 0), new Size(1, height)));
00719 }
00720 }
00721 }
00722
00723 }
00724 #endregion
00725
00726 }
00727
00728
00729
00735 private void TransferFunctionPanel_MouseDown(object sender, MouseEventArgs e)
00736 {
00737 if (!dataLoaded) return;
00738
00739 Point newPos = clampToPanelDimensions(e.X, e.Y, sender);
00740
00741 if (e.Button == MouseButtons.Left)
00742 {
00743 tfPanelMouseDown = true;
00744 tfPanelMouseDownPos = newPos;
00745 }
00746
00747 #region arrow plot control points
00748 if (sender == this.ArrowPlotColorPanel)
00749 {
00750
00751 #region create new control point or edit one
00752 if (e.Button == MouseButtons.Right)
00753 {
00754 ColorDialog colorPicker = new ColorDialog();
00755 colorPicker.Color = XNAToWindowsFormsColor(GameProperties.Instance.arrowColorArray[newPos.X]);
00756
00757
00758 if (colorPicker.ShowDialog() == DialogResult.OK)
00759 {
00760 Color color = colorPicker.Color;
00761
00762 int r = color.R;
00763 int g = color.G;
00764 int b = color.B;
00765 float a = (float)((255.0f - newPos.Y) / 255.0f);
00766
00767 int key = getControlPointKey(newPos, sender);
00768
00769 if (key == -1)
00770 {
00771 GameProperties.Instance.arrowControlPoints.Add(new TransferControlPoint(r, g, b, (int)(newPos.X / tfStepsize)));
00772 GameProperties.Instance.arrowControlPoints.Last().color.W = a;
00773 TransferControlPoint cpNew = new TransferControlPoint(r, g, b, (int)(newPos.X / tfStepsize));
00774 cpNew.color.W = a;
00775 arrowControlPoints.Add(newPos.X, cpNew);
00776 }
00777 else
00778 {
00779 arrowControlPoints[key].color.X = r;
00780 arrowControlPoints[key].color.Y = g;
00781 arrowControlPoints[key].color.Z = b;
00782 arrowControlPoints[key].color.W = a;
00783
00784 int currIsoValue = arrowControlPoints[key].isoValue;
00785
00786 for (int i = 0; i < GameProperties.Instance.arrowControlPoints.Count(); i++)
00787 {
00788 if (GameProperties.Instance.arrowControlPoints[i].isoValue == currIsoValue)
00789 {
00790 GameProperties.Instance.arrowControlPoints[i].color.X = r;
00791 GameProperties.Instance.arrowControlPoints[i].color.Y = g;
00792 GameProperties.Instance.arrowControlPoints[i].color.Z = b;
00793 GameProperties.Instance.arrowControlPoints[i].color.W = a;
00794 i = GameProperties.Instance.arrowControlPoints.Count();
00795 }
00796 }
00797
00798 }
00799
00800
00801
00802
00803
00804 inputManager.updateXnaEngineState(false, false, true, true);
00805
00806
00807 ArrowPlotColorPanel.Refresh();
00808
00809 }
00810 }
00811 #endregion
00812 }
00813 #endregion
00814
00815 #region channel control points
00816 if (sender == this.TransferFunctionPanel)
00817 {
00818
00819 #region create new control point or edit one
00820 if (e.Button == MouseButtons.Right)
00821 {
00822 ColorDialog colorPicker = new ColorDialog();
00823 colorPicker.Color = XNAToWindowsFormsColor(GameProperties.Instance.colorArray[currChannelIdx][newPos.X]);
00824
00825
00826 if (colorPicker.ShowDialog() == DialogResult.OK)
00827 {
00828 Color color = colorPicker.Color;
00829
00830 int r = color.R;
00831 int g = color.G;
00832 int b = color.B;
00833 float a = (float)((255.0f - newPos.Y) / 255.0f);
00834
00835 int key = getControlPointKey(newPos, sender);
00836
00837 if (key == -1)
00838 {
00839 GameProperties.Instance.channelControlPoints[currChannelIdx].Add(new TransferControlPoint(r, g, b, (int)(newPos.X / tfStepsize)));
00840 GameProperties.Instance.channelControlPoints[currChannelIdx].Last().color.W = a;
00841 TransferControlPoint cpNew = new TransferControlPoint(r, g, b, (int)(newPos.X / tfStepsize));
00842 cpNew.color.W = a;
00843 channelControlPoints[currChannelIdx].Add(newPos.X, cpNew);
00844 }
00845 else
00846 {
00847 channelControlPoints[currChannelIdx][key].color.X = r;
00848 channelControlPoints[currChannelIdx][key].color.Y = g;
00849 channelControlPoints[currChannelIdx][key].color.Z = b;
00850 channelControlPoints[currChannelIdx][key].color.W = a;
00851
00852 int currIsoValue = channelControlPoints[currChannelIdx][key].isoValue;
00853
00854 for (int i = 0; i < GameProperties.Instance.channelControlPoints[currChannelIdx].Count(); i++)
00855 {
00856 if (GameProperties.Instance.channelControlPoints[currChannelIdx][i].isoValue == currIsoValue)
00857 {
00858 GameProperties.Instance.channelControlPoints[currChannelIdx][i].color.X = r;
00859 GameProperties.Instance.channelControlPoints[currChannelIdx][i].color.Y = g;
00860 GameProperties.Instance.channelControlPoints[currChannelIdx][i].color.Z = b;
00861 GameProperties.Instance.channelControlPoints[currChannelIdx][i].color.W = a;
00862 i = GameProperties.Instance.channelControlPoints[currChannelIdx].Count();
00863 }
00864 }
00865
00866 }
00867
00868
00869
00870
00871
00872 inputManager.updateXnaEngineState(false, false, true, true);
00873
00874
00875 GameProperties.Instance.updateChannelColor = true;
00876 TransferFunctionPanel.Invalidate();
00877
00878 }
00879 }
00880 #endregion
00881
00882 }
00883 #endregion
00884
00885 }
00886
00892 private void TransferFunctionPanel_MouseMove(object sender, MouseEventArgs e)
00893 {
00894 if (!dataLoaded) return;
00895
00896 #region arrow plot control points
00897 if (sender == this.ArrowPlotColorPanel && tfPanelMouseDown)
00898 {
00899 int key = getControlPointKey(tfPanelMouseDownPos, sender);
00900 if (key != -1)
00901 {
00902 tfPanelMouseDownPos.X = key;
00903 Point newPos = clampToPanelDimensions(e.X, e.Y, sender);
00904
00905 int oldIsoValue = (tfPanelMouseDownPos.X / tfStepsize);
00906 int newIsoValue = (newPos.X / tfStepsize);
00907 float newAlpaValue = (float)((255 - newPos.Y) / 255.0f);
00908
00909 if (newIsoValue == oldIsoValue)
00910 {
00911 arrowControlPoints[newPos.X].color.W = newAlpaValue;
00912 }
00913 else
00914 {
00915
00916
00917 TransferControlPoint cp = arrowControlPoints[tfPanelMouseDownPos.X];
00918 cp.isoValue = newIsoValue;
00919 cp.color.W = newAlpaValue;
00920 arrowControlPoints.Remove(tfPanelMouseDownPos.X);
00921 if (arrowControlPoints.ContainsKey(newPos.X))
00922 arrowControlPoints[newPos.X] = cp;
00923 else arrowControlPoints.Add(newPos.X, cp);
00924
00925 }
00926
00927
00928
00929 for (int i = 0; i < GameProperties.Instance.arrowControlPoints.Count(); i++)
00930 {
00931 if (GameProperties.Instance.arrowControlPoints[i].isoValue == oldIsoValue)
00932 {
00933 GameProperties.Instance.arrowControlPoints[i].isoValue = newIsoValue;
00934 GameProperties.Instance.arrowControlPoints[i].color.W = newAlpaValue;
00935 i = GameProperties.Instance.arrowControlPoints.Count();
00936 }
00937 }
00938
00939
00940
00941 tfPanelMouseDownPos = newPos;
00942
00943
00944 inputManager.updateXnaEngineState(false, false, true, true);
00945
00946
00947
00948 ArrowPlotColorPanel.Refresh();
00949 }
00950 }
00951
00952 #endregion
00953
00954 #region channel control points
00955 if (sender == this.TransferFunctionPanel && tfPanelMouseDown)
00956 {
00957 int key = getControlPointKey(tfPanelMouseDownPos, sender);
00958 if (key != -1)
00959 {
00960 tfPanelMouseDownPos.X = key;
00961 Point newPos = clampToPanelDimensions(e.X, e.Y, sender);
00962
00963 int oldIsoValue = (tfPanelMouseDownPos.X / tfStepsize);
00964 int newIsoValue = (newPos.X / tfStepsize);
00965 float newAlpaValue = (float)((255 - newPos.Y) / 255.0f);
00966
00967 if (newIsoValue == oldIsoValue)
00968 {
00969 channelControlPoints[currChannelIdx][newPos.X].color.W = newAlpaValue;
00970 }
00971 else
00972 {
00973
00974
00975 TransferControlPoint cp = channelControlPoints[currChannelIdx][tfPanelMouseDownPos.X];
00976 cp.isoValue = newIsoValue;
00977 cp.color.W = newAlpaValue;
00978 channelControlPoints[currChannelIdx].Remove(tfPanelMouseDownPos.X);
00979 if (channelControlPoints[currChannelIdx].ContainsKey(newPos.X))
00980 channelControlPoints[currChannelIdx][newPos.X] = cp;
00981 else channelControlPoints[currChannelIdx].Add(newPos.X, cp);
00982
00983 }
00984
00985
00986
00987 for (int i = 0; i < GameProperties.Instance.channelControlPoints[currChannelIdx].Count(); i++)
00988 {
00989 if (GameProperties.Instance.channelControlPoints[currChannelIdx][i].isoValue == oldIsoValue)
00990 {
00991 GameProperties.Instance.channelControlPoints[currChannelIdx][i].isoValue = newIsoValue;
00992 GameProperties.Instance.channelControlPoints[currChannelIdx][i].color.W = newAlpaValue;
00993 i = GameProperties.Instance.channelControlPoints[currChannelIdx].Count();
00994 }
00995 }
00996
00997
00998
00999 tfPanelMouseDownPos = newPos;
01000
01001
01002 inputManager.updateXnaEngineState(false, false, true, true);
01003
01004
01005 GameProperties.Instance.updateChannelColor = true;
01006 TransferFunctionPanel.Invalidate();
01007 }
01008
01009 }
01010 #endregion
01011
01012 }
01013
01014 private void TransferFunctionPanel_MouseUp(object sender, MouseEventArgs e)
01015 {
01016 tfPanelMouseDown = false;
01017 }
01018
01019 #endregion
01020
01021 #region streamline tab
01022
01023 private void handleStreamlinesCheckBox(object sender, EventArgs e)
01024 {
01025 if (GameProperties.Instance.enableStreamlines == false)
01026 {
01027 GameProperties.Instance.enableStreamlines = true;
01028 }
01029 else
01030 {
01031 GameProperties.Instance.enableStreamlines = false;
01032 }
01033
01034 inputManager.updateXnaEngineState(false, false, true, true);
01035 }
01036
01037
01038 private void handleStreamlineTab(object sender, EventArgs e)
01039 {
01040 if (sender == this.StreamlineDtNumUpDown)
01041 {
01042 inputManager.setStreamlineParam(1,(float)StreamlineDtNumUpDown.Value);
01043 }
01044
01045 if (sender == this.StreamlineDsepSlider)
01046 {
01047 float newVal = ((float)StreamlineDsepSlider.Value )/ (StreamlineDsepSlider.Maximum - (StreamlineDsepSlider.LargeChange - 1));
01048 StreamlineDsepLabel.Text = newVal.ToString();
01049 inputManager.setStreamlineParam(2,newVal);
01050
01051 }
01052
01053 if (sender == this.StreamlineDtestSlider)
01054 {
01055 float newVal = ((float)StreamlineDtestSlider.Value) / (StreamlineDtestSlider.Maximum - (StreamlineDtestSlider.LargeChange - 1));
01056 StreamlineDtestLabel.Text = newVal.ToString();
01057
01058 newVal *= ((float)StreamlineDsepSlider.Value )/ (StreamlineDsepSlider.Maximum - (StreamlineDsepSlider.LargeChange - 1));
01059 inputManager.setStreamlineParam(3, newVal);
01060
01061 }
01062
01063 if (sender == StreamlineStyleRadio1 || sender == StreamlineStyleRadio2
01064 || sender == StreamlineStyleRadio3 || sender == StreamlineStyleRadio4)
01065 {
01066 if (StreamlineStyleRadio1.Checked)
01067 {
01068 inputManager.setStreamlineParam(5, false);
01069 }
01070 if (StreamlineStyleRadio2.Checked)
01071 {
01072 inputManager.setStreamlineParam(2, true);
01073 }
01074 if (StreamlineStyleRadio3.Checked)
01075 {
01076 inputManager.setStreamlineParam(3, true);
01077 }
01078 if (StreamlineStyleRadio4.Checked)
01079 {
01080 inputManager.setStreamlineParam(4, true);
01081 }
01082
01083 }
01084 if (sender == EulerRadioButton || sender == RungeKuttaRadioButton)
01085 {
01086 if (EulerRadioButton.Checked)
01087 inputManager.setStreamlineParam(1, false);
01088 else
01089 inputManager.setStreamlineParam(1, true);
01090 }
01091
01092 if (sender == StreamlineLengthUpDown)
01093 {
01094 inputManager.setStreamlineParam(4, (float)StreamlineLengthUpDown.Value);
01095 }
01096
01097 if (sender == StreamlineWidthUpDown)
01098 {
01099 inputManager.setStreamlineParam(5, (float)StreamlineWidthUpDown.Value * GameProperties.Instance.Dtest);
01100 }
01101
01102 }
01103 #endregion
01104
01105 #region extended features
01106 private void handleChangeActiveTab(object sender, TabControlCancelEventArgs e)
01107 {
01108 if (sender == SettingsPanel)
01109 {
01110 if(SettingsPanel.SelectedTab.Equals(ArrowPlotTab))
01111 {
01112 GameProperties.Instance.activeTab = ActiveTab.ArrowTab;
01113 }
01114 if (SettingsPanel.SelectedTab.Equals(ChannelsTab))
01115 {
01116 GameProperties.Instance.activeTab = ActiveTab.ChannelsTab;
01117 }
01118 if (SettingsPanel.SelectedTab.Equals(StreamlinesTab))
01119 {
01120 GameProperties.Instance.activeTab = ActiveTab.StreamlinesTab;
01121 }
01122 }
01123
01124 }
01125
01126 private void handleActiveTabChange(object sender, EventArgs e)
01127 {
01128 if (sender == this.XNADrawSurface)
01129 {
01130 GameProperties.Instance.activeTab = ActiveTab.XnaDrawSurface;
01131 }
01132 if (sender == this.MainMenu)
01133 {
01134 GameProperties.Instance.activeTab = ActiveTab.MainMenu;
01135 }
01136 if (sender == ArrowPlotTab)
01137 {
01138 GameProperties.Instance.activeTab = ActiveTab.ArrowTab;
01139 }
01140 if (sender == ChannelsTab)
01141 {
01142 GameProperties.Instance.activeTab = ActiveTab.ChannelsTab;
01143 }
01144 if (sender == StreamlinesTab)
01145 {
01146 GameProperties.Instance.activeTab = ActiveTab.StreamlinesTab;
01147 }
01148 }
01149
01150
01156 private void handlePerspProjRadioButt(object sender, EventArgs e)
01157 {
01158 perspectiveProjectionToolStripMenuItem.Checked = true;
01159 orthogonalProjectionToolStripMenuItem.Checked = false;
01160 inputManager.enablePerspProjection(true);
01161 }
01162
01168 private void handleOrthProjRadioButt(object sender, EventArgs e)
01169 {
01170 perspectiveProjectionToolStripMenuItem.Checked = false;
01171 orthogonalProjectionToolStripMenuItem.Checked = true;
01172 inputManager.enablePerspProjection(false);
01173 }
01174
01180 private void handleBlendRadioButt1(object sender, EventArgs e)
01181 {
01182 frontToBackBlendingToolStripMenuItem.Checked = true;
01183 backToFrontBlendingToolStripMenuItem.Checked = false;
01184 inputManager.enableFrontToBackBlending(true);
01185 }
01186
01192 private void handleBlendRadioButt2(object sender, EventArgs e)
01193 {
01194 frontToBackBlendingToolStripMenuItem.Checked = false;
01195 backToFrontBlendingToolStripMenuItem.Checked = true;
01196 inputManager.enableFrontToBackBlending(false);
01197 }
01198
01199 #endregion
01200
01201 #endregion
01202
01203 #endregion
01204
01205 #region helper functions
01206
01207 #region arrow plot
01208 private void updateArrowControlPointsData()
01209 {
01210
01211 if (GameProperties.Instance.arrowControlPoints != null && GameProperties.Instance.arrowControlPoints.Count() > 0)
01212 {
01213 arrowControlPoints.Clear();
01214 for (int i = 0; i < GameProperties.Instance.arrowControlPoints.Count(); i++)
01215 {
01216 int cpValue = GameProperties.Instance.arrowControlPoints[i].isoValue;
01217 TransferControlPoint cpNext = GameProperties.Instance.arrowControlPoints[i];
01218 arrowControlPoints.Add(cpValue, cpNext);
01219 }
01220
01221 }
01222 updateArrowControlPoints = false;
01223 }
01224
01225 private void updateArrowColorArrayData()
01226 {
01227 if (GameProperties.Instance.arrowColorArray != null && GameProperties.Instance.arrowColorArray.Count() > 0)
01228 {
01229
01230 for (int i = 0; i < GameProperties.Instance.arrowColorArray.Count(); i++)
01231 {
01232 this.arrowColorArray[i] = Color.FromArgb(GameProperties.Instance.arrowColorArray[i].A,
01233 GameProperties.Instance.arrowColorArray[i].R,
01234 GameProperties.Instance.arrowColorArray[i].G,
01235 GameProperties.Instance.arrowColorArray[i].B);
01236
01237 }
01238
01239
01240 GameProperties.Instance.updateArrowColor = false;
01241
01242 }
01243 }
01244 #endregion
01245
01246 #region channels
01247 private void updateChannelControlPointsData()
01248 {
01249
01250
01251 if (GameProperties.Instance.channelControlPoints != null && GameProperties.Instance.channelControlPoints.Count() > 0)
01252 {
01253 channelControlPoints.Clear();
01254 channelColorArray.Clear();
01255 for (int i = 0; i < GameProperties.Instance.channelControlPoints.Count(); i++)
01256 {
01257 SortedDictionary<int, TransferControlPoint> cpList = new SortedDictionary<int,TransferControlPoint>();
01258 for (int j = 0; j < GameProperties.Instance.channelControlPoints[i].Count(); j++)
01259 {
01260 int cpValue = GameProperties.Instance.channelControlPoints[i][j].isoValue;
01261 TransferControlPoint cpNext = GameProperties.Instance.channelControlPoints[i][j];
01262 cpList.Add(cpValue, cpNext);
01263 }
01264 channelControlPoints.Add(cpList);
01265 channelColorArray.Add(new Color[256]);
01266
01267 }
01268
01269 }
01270
01271
01272 updateChannelControlPoints = false;
01273 }
01274
01278 private void updateChannelColorArrayData()
01279 {
01280 if (GameProperties.Instance.colorArray != null && GameProperties.Instance.colorArray.Count() > 0)
01281 {
01282
01283 for (int i = 0; i < GameProperties.Instance.colorArray[currChannelIdx].Count(); i++)
01284 {
01285 this.channelColorArray[currChannelIdx][i] = Color.FromArgb(GameProperties.Instance.colorArray[currChannelIdx][i].A,
01286 GameProperties.Instance.colorArray[currChannelIdx][i].R,
01287 GameProperties.Instance.colorArray[currChannelIdx][i].G,
01288 GameProperties.Instance.colorArray[currChannelIdx][i].B);
01289
01290 }
01291
01292
01293 GameProperties.Instance.updateChannelColor = false;
01294 }
01295 }
01296 #endregion
01297
01298 private void updateGuiTF(bool updateArrowControlPoints, bool updateArrowColor, bool updateChannelControlPoints, bool updateChannelColor)
01299 {
01300 this.updateArrowControlPoints = updateArrowControlPoints;
01301
01302 this.updateChannelControlPoints = updateChannelControlPoints;
01303
01304 if (this.updateArrowControlPoints)
01305 {
01306 ArrowPlotColorPanel.Invalidate();
01307
01308 }
01309 if (this.updateChannelControlPoints)
01310 {
01311 TransferFunctionPanel.Invalidate();
01312
01313 }
01314
01315 }
01321 private Color XNAToWindowsFormsColor(Microsoft.Xna.Framework.Vector4 xnaColor)
01322 {
01323 int r = (int)(xnaColor.X);
01324 int g = (int)(xnaColor.Y);
01325 int b = (int)(xnaColor.Z);
01326 int a = (int)(xnaColor.W * 255);
01327
01328 Color color = Color.FromArgb(a, r, g, b);
01329 return color;
01330 }
01331
01337 private Color XNAToWindowsFormsColor(Microsoft.Xna.Framework.Graphics.Color xnaColor)
01338 {
01339 Color color = Color.FromArgb((int)xnaColor.A, (int)xnaColor.R, (int)xnaColor.G, (int)xnaColor.B);
01340 return color;
01341 }
01342
01343
01351 private Color lerpColor(Color c1, Color c2, float amount)
01352 {
01353 int r = (int)(c1.R + amount * (c2.R - c1.R));
01354 int g = (int)(c1.G + amount * (c2.G - c1.G));
01355 int b = (int)(c1.B + amount * (c2.B - c1.B));
01356 int a = (int)(c1.A + amount * (c2.A - c1.A));
01357 Color lerpColor = Color.FromArgb(a, r, g, b);
01358 lerpColor = Color.FromArgb(255, lerpColor);
01359
01360 return lerpColor;
01361 }
01362
01363
01364 private int getControlPointKey(Point mousePos, Object sender)
01365 {
01366 if (sender == this.ArrowPlotColorPanel)
01367 {
01368 if (arrowControlPoints.ContainsKey(mousePos.X)) return mousePos.X;
01369 else
01370 {
01371 foreach (int key in arrowControlPoints.Keys)
01372 {
01373 if (mousePos.X >= (key - (controlPointSize.Width / 2)) &&
01374 mousePos.X <= (key + (controlPointSize.Width / 2)))
01375 {
01376 return key;
01377 }
01378 }
01379 }
01380 }
01381
01382 if (sender == this.TransferFunctionPanel)
01383 {
01384 if (channelControlPoints[currChannelIdx].ContainsKey(mousePos.X)) return mousePos.X;
01385 else
01386 {
01387 foreach (int key in channelControlPoints[currChannelIdx].Keys)
01388 {
01389 if (mousePos.X >= (key - (controlPointSize.Width / 2)) &&
01390 mousePos.X <= (key + (controlPointSize.Width / 2)))
01391 {
01392 return key;
01393 }
01394 }
01395 }
01396 }
01397 return -1;
01398 }
01399
01400 private Point clampToPanelDimensions(int posX, int posY, Object sender)
01401 {
01402 int width = 256;
01403 int height = 256;
01404
01405 if (sender == this.TransferFunctionPanel)
01406 {
01407 width = this.TransferFunctionPanel.Width;
01408 height = this.TransferFunctionPanel.Height;
01409 }
01410
01411 if (sender == this.ArrowPlotColorPanel)
01412 {
01413 width = this.ArrowPlotColorPanel.Width;
01414 height = this.ArrowPlotColorPanel.Height;
01415 }
01416
01417 Point p = new Point(posX, posY);
01418 if (p.X < 0) { p.X = 0; }
01419 else if (p.X > width - 1)
01420 { p.X = width - 1; }
01421 if (p.Y < 0) { p.Y = 0; }
01422 else if (p.Y > height - 1)
01423 { p.Y = height - 1; }
01424
01425 return p;
01426 }
01427 #endregion
01428
01429 #region handle xna draw surface events
01430
01431
01432 private void handleXNADrawSurface_MouseDown(object sender, MouseEventArgs e)
01433 {
01434 inputManager.XnaDrawSurface_MouseDownEvent = true;
01435 inputManager.MouseDownPosX = e.X;
01436 inputManager.MouseDownPosY = e.Y;
01437
01438 }
01439
01440 private void handleXNADrawSurface_MouseUp(object sender, MouseEventArgs e)
01441 {
01442 inputManager.XnaDrawSurface_MouseDownEvent = false;
01443 }
01444
01445 private void handleXNADrawSurface_MouseMove(object sender, MouseEventArgs e)
01446 {
01447 if (inputManager.XnaDrawSurface_MouseDownEvent)
01448 {
01449 inputManager.updateMousePos(e.X, e.Y);
01450 inputManager.updateXnaEngineState(true, false, true, true);
01451 }
01452 }
01453
01454 private void handleXNADrawSurface_MouseScroll(object sender, MouseEventArgs e)
01455 {
01456 if (inputManager.XnaDrawSurface_MouseDownEvent)
01457 {
01458 inputManager.updateMouseScroll(e.Delta / SystemInformation.MouseWheelScrollDelta);
01459 inputManager.updateXnaEngineState(true, false, true, true);
01460 }
01461 }
01462 #endregion
01463
01464
01465
01466
01467
01468
01469
01470 }
01471 }