Go to the documentation of this file.00001 #region using statements
00002 using System;
00003 using System.Collections.Generic;
00004 using System.Linq;
00005 using System.Text;
00006 using System.Windows.Forms;
00007 using System.Xml;
00008 using Microsoft.Xna.Framework;
00009 #endregion
00010
00011 namespace visLU.Gui
00012 {
00016 public class InputManager
00017 {
00018
00019 bool xnaDrawSurface_MouseDownEvent = false;
00020 int mouseDownPosX, mouseDownPosY, mouseDownPosZ = 0;
00021 Vector3 mouseMovePos;
00022
00023 #region properties
00024 public bool XnaDrawSurface_MouseDownEvent
00025 {
00026 set { xnaDrawSurface_MouseDownEvent = value; }
00027 get { return xnaDrawSurface_MouseDownEvent; }
00028
00029 }
00030
00031 public int MouseDownPosX
00032 {
00033 set { mouseDownPosX = value; }
00034 }
00035 public int MouseDownPosY
00036 {
00037 set { mouseDownPosY = value; }
00038 }
00039 public Vector3 MouseMovePos
00040 {
00041 set { MouseMovePos = value; }
00042 }
00043 #endregion
00044
00049 public void setViewMode(ViewMode newViewMode)
00050 {
00051 GameProperties.Instance.viewMode = newViewMode;
00052 }
00053
00058 public int getViewMode()
00059 {
00060 return (int)GameProperties.Instance.viewMode;
00061 }
00062
00063
00069 public void setViewMode()
00070 {
00071
00072 ViewMode currentViewMode = GameProperties.Instance.viewMode;
00073 switch (currentViewMode)
00074 {
00075 case ViewMode.VolView:
00076 GameProperties.Instance.viewMode = ViewMode.TopView;
00077 break;
00078 case ViewMode.TopView:
00079 GameProperties.Instance.viewMode = ViewMode.SideView;
00080 break;
00081 case ViewMode.SideView:
00082 GameProperties.Instance.viewMode = ViewMode.FrontView;
00083 break;
00084 case ViewMode.FrontView:
00085 GameProperties.Instance.viewMode = ViewMode.VolView;
00086 break;
00087 default:
00088 GameProperties.Instance.viewMode = ViewMode.VolView;
00089 break;
00090 }
00091
00092 }
00093
00098 public void setZoom(int zoomStep)
00099 {
00100
00101
00102 if (GameProperties.Instance.viewMode == ViewMode.VolView )
00103 {
00104
00105
00106
00107
00108 GameProperties.Instance.position.Z = zoomStep;
00109
00110 }
00111 }
00112
00119 public void setSliceValue(decimal xValue, decimal yValue, decimal zValue)
00120 {
00121 GameProperties.Instance.xSliceValue = (float)xValue;
00122 GameProperties.Instance.ySliceValue = (float)yValue;
00123 GameProperties.Instance.zSliceValue = (float)zValue;
00124
00125 if (!GameProperties.Instance.viewMode.Equals(ViewMode.VolView))
00126 {
00127 updateXnaEngineState(false, false, false, true);
00128 }
00129 }
00130
00136 public void setSliceValue(int slice, decimal value)
00137 {
00138 switch (slice)
00139 {
00140 case 1:
00141 GameProperties.Instance.xSliceValue = (float) value;
00142 break;
00143 case 2:
00144 GameProperties.Instance.ySliceValue = (float) value;
00145 break;
00146 case 3:
00147 GameProperties.Instance.zSliceValue = (float) value;
00148 break;
00149 default:
00150 break;
00151 }
00152
00153 if (!GameProperties.Instance.viewMode.Equals(ViewMode.VolView))
00154 {
00155 updateXnaEngineState(false, false, false, true);
00156 }
00157
00158 }
00159
00165 public bool enableSliceGroup(int slice)
00166 {
00167 if (GameProperties.Instance.viewMode.Equals(ViewMode.VolView)) return false;
00168
00169 switch (slice)
00170 {
00171 case 1:
00172 if (GameProperties.Instance.viewMode.Equals(ViewMode.SideView)) return true;
00173 break;
00174 case 2:
00175 if (GameProperties.Instance.viewMode.Equals(ViewMode.TopView)) return true;
00176 break;
00177 case 3:
00178 if (GameProperties.Instance.viewMode.Equals(ViewMode.FrontView)) return true;
00179 break;
00180 default:
00181 return false;
00182 break;
00183 }
00184
00185 return false;
00186 }
00187
00193 public void enableTransferFunction(bool enable, bool enableAlpha)
00194 {
00195 GameProperties.Instance.enableTransferFunction = enable;
00196 GameProperties.Instance.enableTransferAlphaValues = enableAlpha;
00197 updateXnaEngineState(false, false, true, true);
00198 }
00199
00200 #region extended feature set
00201
00202
00203
00204
00205 public void enableClippingPlane(bool enable)
00206 {
00207 GameProperties.Instance.enableClippingPlane = enable;
00208 updateXnaEngineState(true, false, true, true);
00209 }
00210
00215 public void enableMaxIntensityProjection(bool enable)
00216 {
00217 GameProperties.Instance.maximumIntensityProjection = enable;
00218 updateXnaEngineState(true, false, true, true);
00219 }
00220
00225 public void enablePerspProjection(bool enable)
00226 {
00227 GameProperties.Instance.perspectiveProjection = enable;
00228 updateXnaEngineState(true, false, true, true);
00229 }
00230
00235 public void enableFrontToBackBlending(bool enable)
00236 {
00237 GameProperties.Instance.enableFrontToBackBlend = enable;
00238 updateXnaEngineState(true, false, true, true);
00239 }
00240
00245 public void enableShading(bool enable)
00246 {
00247 GameProperties.Instance.enableShading = enable;
00248 updateXnaEngineState(true, false, true, true);
00249 }
00250
00251
00256 public void enableFullscreenMode(bool enable)
00257 {
00258 GameProperties.Instance.fullscreen = enable;
00259 updateXnaEngineState(true, false, true, true);
00260 }
00261 #endregion
00262
00269 public void updateMousePos(int posX, int posY)
00270 {
00271 if (GameProperties.Instance.viewMode == ViewMode.VolView)
00272 {
00273 GameProperties.Instance.position.X = mouseDownPosX - posX;
00274 GameProperties.Instance.position.Y = mouseDownPosY - posY;
00275 mouseDownPosX = posX;
00276 mouseDownPosY = posY;
00277 }
00278 }
00279
00280 public void resetMousePos()
00281 {
00282 GameProperties.Instance.position.X = 0;
00283 GameProperties.Instance.position.Y = 0;
00284 GameProperties.Instance.position.Z = 0;
00285 mouseDownPosX = 0;
00286 mouseDownPosY = 0;
00287 mouseDownPosZ = 0;
00288 }
00289
00295 public void updateMouseScroll(int scrollStep)
00296 {
00297 int mousePos = getMousePos(mouseDownPosX, mouseDownPosY);
00298
00299
00300 if (GameProperties.Instance.viewMode == ViewMode.VolView )
00301 {
00302
00303
00304
00305
00306 GameProperties.Instance.position.Z = scrollStep;
00307
00308 }
00309
00310 else
00311 {
00312 if (GameProperties.Instance.viewMode == ViewMode.TopView)
00313 {
00314
00315 }
00316 else if (GameProperties.Instance.viewMode == ViewMode.SideView)
00317 {
00318
00319 }
00320 else if (GameProperties.Instance.viewMode == ViewMode.FrontView)
00321 {
00322
00323 }
00324
00325 }
00326
00327 }
00328
00341 private int getMousePos(int posX, int posY)
00342 {
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 return -1;
00359 }
00360
00361 public void loadTransferFunction(String fileName)
00362 {
00363 GameProperties.Instance.colorControlPoints.Clear();
00364 GameProperties.Instance.alphaControlPoints.Clear();
00365
00366 XmlTextReader xmlReader = new XmlTextReader(fileName);
00367 xmlReader.MoveToElement();
00368
00369 float r = 0.0f;
00370 float g = 0.0f;
00371 float b = 0.0f;
00372 float a = 0.0f;
00373 int isoValue = 0;
00374
00375 while (xmlReader.Read())
00376 {
00377 if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name.Equals("ControlPoint"))
00378 {
00379 while (!(xmlReader.NodeType == XmlNodeType.EndElement && xmlReader.Name.Equals("ControlPoint")))
00380 {
00381 xmlReader.Read();
00382
00383 if (xmlReader.NodeType.Equals(XmlNodeType.Element))
00384 {
00385 String elementName = xmlReader.Name;
00386 xmlReader.Read();
00387 if (xmlReader.NodeType.Equals(XmlNodeType.Text))
00388 {
00389 switch (elementName)
00390 {
00391 case "ColorR":
00392 r = float.Parse(xmlReader.Value);
00393 break;
00394
00395 case "ColorG":
00396 g = float.Parse(xmlReader.Value);
00397 break;
00398
00399 case "ColorB":
00400 b = float.Parse(xmlReader.Value);
00401 break;
00402
00403 case "ColorA":
00404 a = float.Parse(xmlReader.Value);
00405 break;
00406
00407 case "IsoValue":
00408 isoValue = int.Parse(xmlReader.Value);
00409 break;
00410 }
00411 }
00412 }
00413 }
00414
00415
00416 GameProperties.Instance.colorControlPoints.Add(new TransferControlPoint(r, g, b, isoValue));
00417 GameProperties.Instance.alphaControlPoints.Add(new TransferControlPoint(a, isoValue));
00418 }
00419 }
00420 }
00421
00425 public void saveTransferFunction(string fileName)
00426 {
00427 XmlTextWriter xmlWriter = new XmlTextWriter(fileName, null);
00428
00429 xmlWriter.WriteStartDocument();
00430 xmlWriter.WriteStartElement("TransferFunction");
00431
00432 for (int i = 0; i < GameProperties.Instance.colorControlPoints.Count(); i++)
00433 {
00434 xmlWriter.WriteStartElement("ControlPoint");
00435
00436 xmlWriter.WriteStartElement("ColorR");
00437 xmlWriter.WriteString(GameProperties.Instance.colorControlPoints[i].color.X.ToString());
00438 xmlWriter.WriteEndElement();
00439
00440 xmlWriter.WriteStartElement("ColorG");
00441 xmlWriter.WriteString(GameProperties.Instance.colorControlPoints[i].color.Y.ToString());
00442 xmlWriter.WriteEndElement();
00443
00444 xmlWriter.WriteStartElement("ColorB");
00445 xmlWriter.WriteString(GameProperties.Instance.colorControlPoints[i].color.Z.ToString());
00446 xmlWriter.WriteEndElement();
00447
00448 xmlWriter.WriteStartElement("ColorA");
00449 xmlWriter.WriteString(GameProperties.Instance.alphaControlPoints[i].color.W.ToString());
00450 xmlWriter.WriteEndElement();
00451
00452 xmlWriter.WriteStartElement("IsoValue");
00453 xmlWriter.WriteString(GameProperties.Instance.colorControlPoints[i].isoValue.ToString());
00454 xmlWriter.WriteEndElement();
00455
00456 xmlWriter.WriteEndElement();
00457 }
00458
00459 xmlWriter.WriteEndElement();
00460 xmlWriter.WriteEndDocument();
00461 xmlWriter.Close();
00462 }
00463
00464 #region update game and engine state
00465 public void updateXnaEngineState(bool updateCam, bool load, bool update, bool draw)
00466 {
00467 GameProperties.Instance.engineState.updateCamera = updateCam;
00468 GameProperties.Instance.engineState.loadData = load;
00469 GameProperties.Instance.engineState.updateData = update;
00470 GameProperties.Instance.engineState.drawData = draw;
00471 }
00472 #endregion
00473 }
00474 }