• Main Page
  • Packages
  • Classes
  • Files
  • File List

trunk/visLU/Gui/InputManager.cs

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 visLU2.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             //zoom for all views???
00101             //zoom +/-
00102             if (GameProperties.Instance.viewMode == ViewMode.VolView )
00103             {
00104                 // : logic in the camera class
00105                 //int numberOfTextLinesToMove = e.Delta * SystemInformation.MouseWheelScrollLines / 120;
00106                 //scrollStep --> e.Delta, 120->max zoom value ex. 10
00107                 //if endvalue > 0 -> zoom + , < 0 zoom -, = 0 nothing
00108                 GameProperties.Instance.cameraPosition.Z = zoomStep;
00109                // mouseDownPosZ = scrollStep;
00110             }
00111         }
00112 
00113         #region arrow plot
00114         public void enableArrowPlot(bool enable)
00115         {
00116             GameProperties.Instance.enableArrowPlot = enable;
00117             updateXnaEngineState(false, false, true, true);
00118         }
00119 
00120         public void enableScaledArrowLength(bool enable)
00121         {
00122             GameProperties.Instance.scaleArrowLength = enable;
00123             updateXnaEngineState(false, false, true, true);
00124         }
00125 
00126         public void enableArrowPlotTransferFunction(bool enable)
00127         {
00128             GameProperties.Instance.enableArrowTransferFunction = enable;
00129             updateXnaEngineState(false, false, true, true);
00130         }
00131         #endregion
00132         
00133         #region channels
00134 
00135         public void enableChannels(bool enable)
00136         {
00137             GameProperties.Instance.enableChannels = enable;
00138             updateXnaEngineState(false, false, true, true);
00139         }
00140 
00141         public void enableComposeChannels(bool enable)
00142         {
00143             GameProperties.Instance.composeChannels = enable;
00144             updateXnaEngineState(false, false, true, true);
00145         }
00146         #endregion
00147 
00148 
00149 
00150 
00151 
00152 
00153         public void setSliceValue(decimal xValue, decimal yValue, decimal zValue)
00154         {
00155             GameProperties.Instance.xSliceValue = (float)xValue;
00156             GameProperties.Instance.ySliceValue = (float)yValue;
00157             GameProperties.Instance.zSliceValue = (float)zValue;
00158 
00159             if (!GameProperties.Instance.viewMode.Equals(ViewMode.VolView))
00160             {
00161                 updateXnaEngineState(false, false, false, true);
00162             }
00163         }
00164 
00170         public void setArrowPlotParam(int paramIdx, float paramValue)
00171         {
00172             switch (paramIdx)
00173             {
00174                 case 1:
00175                     GameProperties.Instance.apStepsize = paramValue;
00176                     break;
00177                 case 2:
00178                     GameProperties.Instance.apAlpha = paramValue;
00179                     break;
00180                 default:
00181                     break;
00182             }
00183            updateXnaEngineState(false, false, true, true);
00184            
00185         }
00186 
00192         public bool enableSliceGroup(int slice)
00193         {
00194             if (GameProperties.Instance.viewMode.Equals(ViewMode.VolView)) return false;
00195 
00196             switch (slice)
00197             {
00198                 case 1: //x slice -> side view
00199                     if (GameProperties.Instance.viewMode.Equals(ViewMode.SideView)) return true;
00200                     break;
00201                 case 2: //y slice -> top view
00202                     if (GameProperties.Instance.viewMode.Equals(ViewMode.TopView)) return true;
00203                     break;
00204                 case 3: //z slice -> front view
00205                     if (GameProperties.Instance.viewMode.Equals(ViewMode.FrontView)) return true;
00206                     break;
00207                 default: 
00208                     return false;
00209             }
00210 
00211             return false;
00212         }
00213 
00219         public void enableTransferFunction(bool enable)
00220         {
00221             GameProperties.Instance.enableTransferFunction = enable;
00222             updateXnaEngineState(false, false, true, true);
00223         }
00224 
00225         #region streamline tab
00226         public void setStreamlineParam(int paramIdx, bool enable)
00227         {
00228             bool update = true;
00229             bool draw = true;
00230 
00231             switch (paramIdx)
00232             {
00233                 
00234                 case 1: //runge kutta integration
00235                     GameProperties.Instance.enableRungeKutta = enable;
00236                     update = false;
00237                     break;
00238                 case 2: //tapering
00239                     GameProperties.Instance.enableTapering = enable;
00240                     break;
00241                 case 3: //glyph mapping
00242                     GameProperties.Instance.enableGlyphMapping = enable;
00243                     break;
00244                 case 4: //texture generation
00245                     GameProperties.Instance.enableTextureGeneration = enable;
00246                     break;
00247                 case 5: //style off -> normal style
00248                     
00249                     GameProperties.Instance.enableTapering = enable;
00250                     GameProperties.Instance.enableGlyphMapping = enable;
00251                     GameProperties.Instance.enableTextureGeneration = enable;
00252                     break;
00253                 default://euler and normal style
00254                     GameProperties.Instance.enableRungeKutta = false;
00255                     GameProperties.Instance.enableTapering = false;
00256                     GameProperties.Instance.enableGlyphMapping = false;
00257                     GameProperties.Instance.enableTextureGeneration = false;
00258                     break;
00259             }
00260             
00261             updateXnaEngineState(false, false, update, draw);
00262         }
00263         public void setStreamlineParam(int paramIdx, float paramValue)
00264         {
00265             switch (paramIdx)
00266             {
00267                 case 1:
00268                     GameProperties.Instance.Dt = paramValue;
00269                     break;
00270                 case 2:
00271                     GameProperties.Instance.Dsep = paramValue * GameProperties.Instance.maxDsep;
00272                     break;
00273                 case 3:
00274                     GameProperties.Instance.Dtest = paramValue * GameProperties.Instance.maxDsep;
00275                     break;
00276                 case 4:
00277                     GameProperties.Instance.lineLength = paramValue;
00278                     break;
00279                 case 5:
00280                     GameProperties.Instance.lineWidth = paramValue;
00281                     break;
00282             }
00283             updateXnaEngineState(false, false, true, true);
00284             
00285         }
00286         #endregion
00287 
00288         #region extended feature set
00289 
00290 
00291 
00292 
00293         public void enableClippingPlane(bool enable)
00294         {
00295             GameProperties.Instance.enableClippingPlane = enable;
00296             updateXnaEngineState(true, false, true, true);
00297         }
00298 
00303         public void enableMaxIntensityProjection(bool enable)
00304         {
00305             GameProperties.Instance.maximumIntensityProjection = enable;
00306             updateXnaEngineState(true, false, true, true);
00307         }
00308 
00313         public void enablePerspProjection(bool enable)
00314         {
00315             GameProperties.Instance.perspectiveProjection = enable;
00316             updateXnaEngineState(true, false, true, true);
00317         }
00318 
00323         public void enableFrontToBackBlending(bool enable)
00324         {
00325             GameProperties.Instance.enableFrontToBackBlend = enable;
00326             updateXnaEngineState(true, false, true, true);
00327         }
00328 
00333         public void enableShading(bool enable)
00334         {
00335             GameProperties.Instance.enableShading = enable;
00336             updateXnaEngineState(true, false, true, true);
00337         }
00338 
00339 
00344         public void enableFullscreenMode(bool enable)
00345         {
00346             GameProperties.Instance.fullscreen = enable;
00347             updateXnaEngineState(true, false, true, true);
00348         }
00349         #endregion
00350 
00356         public void updateMousePos(int posX, int posY)
00357         {
00358            //if (GameProperties.Instance.viewMode == ViewMode.VolView)
00359             //{
00360                 GameProperties.Instance.cameraPosition.X += (mouseDownPosX - posX) * (0.05f);
00361                 GameProperties.Instance.cameraPosition.Y += (mouseDownPosY - posY) * (0.05f);
00362                 mouseDownPosX = posX;
00363                 mouseDownPosY = posY;
00364             //}
00365         }
00366 
00367         public void resetMousePos()
00368         {
00369             GameProperties.Instance.cameraPosition.X = 0;
00370             GameProperties.Instance.cameraPosition.Y = 0;
00371             //GameProperties.Instance.cameraPosition.Z = 0;
00372             mouseDownPosX = 0;
00373             mouseDownPosY = 0;
00374             //mouseDownPosZ = 0;
00375         }
00376 
00381         public void updateMouseScroll(int scrollStep)
00382         {
00383            
00384 
00385             //zoom +/-
00386            
00387 
00388                 // : logic in the camera class
00389                 //int numberOfTextLinesToMove = e.Delta * SystemInformation.MouseWheelScrollLines / 120;
00390                 //scrollStep --> e.Delta, 120->max zoom value ex. 10
00391                 //if endvalue > 0 -> zoom + , < 0 zoom -, = 0 nothing
00392                 GameProperties.Instance.cameraPosition.Z += scrollStep;
00393                // mouseDownPosZ = scrollStep;
00394               
00395  
00396         }
00397         
00410         private int getMousePos(int posX, int posY)
00411         {
00412             /*if ((posX >= GameProperties.Instance.XNASingleViewport.X && posY >= GameProperties.Instance.XNASingleViewport.Y)
00413                 && (posX <= GameProperties.Instance.XNASingleViewport.X + GameProperties.Instance.XNASingleViewport.Width && posY <= GameProperties.Instance.XNASingleViewport.Y + GameProperties.Instance.XNASingleViewport.Height))
00414             {
00415 
00416                 for (int i = 0; i < 4; i++)
00417                 {
00418                     if ((posX >= GameProperties.Instance.XNAViewports[i].X && posY >= GameProperties.Instance.XNAViewports[i].Y)
00419                 && (posX <= GameProperties.Instance.XNAViewports[i].X + GameProperties.Instance.XNAViewports[i].Width && posY <= GameProperties.Instance.XNAViewports[i].Y + GameProperties.Instance.XNAViewports[i].Height))
00420                         return i;
00421                 }
00422                 return 1;
00423 
00424             }*/
00425 
00426             //mouse outside the viewports
00427             return -1;
00428         }
00429 
00430         public void loadTransferFunction(String fileName)
00431         {
00432             GameProperties.Instance.channelControlPoints[GameProperties.Instance.currentChannelIdx].Clear();
00433 
00434             XmlTextReader xmlReader = new XmlTextReader(fileName);
00435             xmlReader.MoveToElement();
00436 
00437             int r = 0;
00438             int g = 0;
00439             int b = 0;
00440             float a = 0; 
00441             int isoValue = 0;
00442 
00443             while (xmlReader.Read())
00444             {
00445                 if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name.Equals("ControlPoint"))
00446                 {
00447                     while (!(xmlReader.NodeType == XmlNodeType.EndElement && xmlReader.Name.Equals("ControlPoint")))
00448                     {
00449                         xmlReader.Read();
00450                         
00451                         if (xmlReader.NodeType.Equals(XmlNodeType.Element))
00452                         {
00453                             String elementName = xmlReader.Name;
00454                             xmlReader.Read();
00455                             if (xmlReader.NodeType.Equals(XmlNodeType.Text))
00456                             {
00457                                 switch (elementName)
00458                                 {
00459                                     case "ColorR":
00460                                         r = int.Parse(xmlReader.Value);
00461                                         break;
00462 
00463                                     case "ColorG":
00464                                         g = int.Parse(xmlReader.Value);
00465                                         break;
00466 
00467                                     case "ColorB":
00468                                         b = int.Parse(xmlReader.Value);
00469                                         break;
00470 
00471                                     case "ColorA":
00472                                         a = float.Parse(xmlReader.Value);
00473                                         break;
00474 
00475                                     case "IsoValue":
00476                                         isoValue = int.Parse(xmlReader.Value);
00477                                         break;
00478                                 }//end switch
00479                             }//end if
00480                         }
00481                     }//end while
00482 
00483                    //save new control point for current channel
00484                     TransferControlPoint cp = new TransferControlPoint(r, g, b, isoValue);
00485                     cp.color.W = a;
00486                     GameProperties.Instance.channelControlPoints[GameProperties.Instance.currentChannelIdx].Add(cp);
00487                    
00488                 }   
00489             }
00490             xmlReader.Close();
00491         }
00492 
00496         public void saveTransferFunction(string fileName)
00497         {
00498             XmlTextWriter xmlWriter = new XmlTextWriter(fileName, null);
00499 
00500             xmlWriter.WriteStartDocument();
00501             xmlWriter.WriteStartElement("TransferFunction");
00502 
00503             for (int i = 0; i < GameProperties.Instance.channelControlPoints[GameProperties.Instance.currentChannelIdx].Count(); i++)
00504             {
00505                 xmlWriter.WriteStartElement("ControlPoint");
00506 
00507                 xmlWriter.WriteStartElement("ColorR");
00508                 xmlWriter.WriteString(GameProperties.Instance.channelControlPoints[GameProperties.Instance.currentChannelIdx][i].color.X.ToString());
00509                 xmlWriter.WriteEndElement();
00510 
00511                 xmlWriter.WriteStartElement("ColorG");
00512                 xmlWriter.WriteString(GameProperties.Instance.channelControlPoints[GameProperties.Instance.currentChannelIdx][i].color.Y.ToString());
00513                 xmlWriter.WriteEndElement();
00514 
00515                 xmlWriter.WriteStartElement("ColorB");
00516                 xmlWriter.WriteString(GameProperties.Instance.channelControlPoints[GameProperties.Instance.currentChannelIdx][i].color.Z.ToString());
00517                 xmlWriter.WriteEndElement();
00518 
00519                 xmlWriter.WriteStartElement("ColorA");
00520                 xmlWriter.WriteString(GameProperties.Instance.channelControlPoints[GameProperties.Instance.currentChannelIdx][i].color.W.ToString());
00521                 xmlWriter.WriteEndElement();
00522 
00523                 xmlWriter.WriteStartElement("IsoValue");
00524                 xmlWriter.WriteString(GameProperties.Instance.channelControlPoints[GameProperties.Instance.currentChannelIdx][i].isoValue.ToString());
00525                 xmlWriter.WriteEndElement();
00526 
00527                 xmlWriter.WriteEndElement();
00528             }
00529 
00530             xmlWriter.WriteEndElement();
00531             xmlWriter.WriteEndDocument();
00532             xmlWriter.Close();
00533         }
00534 
00535         #region update game and engine state 
00536 
00537         
00538         public void updateXnaEngineState(bool updateCam, bool load, bool update, bool draw) 
00539         {
00540             GameProperties.Instance.engineState.updateCamera = updateCam;
00541             GameProperties.Instance.engineState.loadData = load;
00542             GameProperties.Instance.engineState.updateData = update;
00543             GameProperties.Instance.engineState.drawData = draw;
00544         }
00545 
00546         public void updateXnaTF(bool updateArrowColor, bool updateChannelColor)
00547         {
00548             GameProperties.Instance.updateArrowColor = updateArrowColor;
00549             GameProperties.Instance.updateChannelColor = updateChannelColor;
00550         }
00551         #endregion
00552     }
00553 }

Generated on Wed Jan 19 2011 21:59:17 for flowvis-2 by  doxygen 1.7.2