VIS2 SS2013 CVD DVR
 All Classes Namespaces Functions Enumerations Properties
Engine.cs
1 #region Using Statements
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.IO;
6 using System.Windows.Forms;
7 using Microsoft.Xna.Framework;
8 using Microsoft.Xna.Framework.Graphics;
9 using Microsoft.Xna.Framework.Audio;
10 using Microsoft.Xna.Framework.Content;
11 using Microsoft.Xna.Framework.GamerServices;
12 using Microsoft.Xna.Framework.Graphics;
13 using Microsoft.Xna.Framework.Input;
14 using Microsoft.Xna.Framework.Media;
15 using Microsoft.Xna.Framework.Net;
16 using Microsoft.Xna.Framework.Storage;
17 using Microsoft.Xna.Framework.Graphics.PackedVector;
18 using visLU.Effects;
19 using visLU.CVD;
20 #endregion
21 
22 namespace visLU
23 {
29  {
30  #region Variables
31 
32  #region Render Targets
33  private RenderTarget2D frontTarget;
34  private RenderTarget2D backTarget;
35  private RenderTarget2D sceneTarget;
36  private RenderTarget2D dvrTarget;
37 
38  private Texture2D dvrTexture;
39 
40  private RenderTarget2D cvdTarget;
41  #endregion
42 
43  ContentManager content;
44  SpriteBatch spriteBatch;
45  SpriteFont spriteBatchFont;
46 
47  #region viewport
48  Camera[] cameras;
49  Camera cvdCamera;
50  Viewport defaultViewport;
51  Viewport[] viewports;
52  int currentView;
53  int currentCvdView;
54  #endregion
55 
56  Data input;
57  private Model cubeModel;
58 
59  #region shader
60 
61  //standad
62  public VolumeShader shader;
63 
64  // CVD
65  public VolumeShader CVDshader;
66  public TFWeightsShader tfWeightsShader;
67 
68  // recoloring
69  public RecolorShader rGBtoLab_Shader;
70  public RecolorShader contrastLoss_Shader;
71  public RecolorShader predominantComponent_Shader;
72  public RecolorShader eigenVector_Shader;
73  public RecolorShader projection_Shader;
74  public RecolorShader maxProjectionEffect_Shader;
75  public RecolorShader enhanceContrast_Shader;
76  public RecolorShader labToRGB_Shader;
77 
78  //simulation
79  public RecolorShader sim_RGBtoLab_Shader;
80  public RecolorShader lMSShader;
81  public RecolorShader sim_LabToRGB_Shader;
82 
83  #endregion
84 
85  Image recoloredImage;
86  Image simulatedImage;
87  CVDtf cvdtf;
88 
89 
90  //int texturesSaved = 0; // for debug
91  int render = 3; //0 = nothing, 1=frontfaces, 2= front and backfaces 3= + volume
92  bool debugOutput = GameProperties.Instance.debugOutput;
93  int drawcount = 0; //only for debug
94 
95  int[] lastSize;
96 
97  Texture2D frameworkInfo;
98 
99  private bool debugShader;
100  Texture2D rgbTestTex;
101 
102  #endregion
103 
104  #region Properties
105  public Data Input
106  {
107  set { input = value; }
108  get { return input; }
109  }
110  #endregion
111 
112  #region Constructor
113  public Engine()
119  {
120  #region create cameras
121  cameras = new Camera[4];
122  cameras[0] = new InteractiveCamera();
123  cameras[0].Initialize();
124  for (int i = 1; i < 4; i++)
125  {
126  cameras[i] = new Camera();
127  cameras[i].Initialize();
128  }
129  cvdCamera = new InteractiveCamera(); cvdCamera.Initialize();
130  currentCvdView = (int)GameProperties.Instance.viewMode;
131  currentCvdView = (int)GameProperties.Instance.cvdViewMode; //start view for the split screen
132  #endregion
133 
134  input = null;
135  lastSize = new int[] {this.Size.Width, this.Size.Height};
136 
137  debugShader = GameProperties.Instance.shaderDebugMode;
138 
139  if (debugOutput)
140  {
141  Console.WriteLine("ENGINE STARTED");
142  }
143 
144  }
145  #endregion
146 
147  #region Methods
148  //##########################################################################################
149 
150  #region Initialize()
151  //-----------------------------------INITIALIZE()-------------------------------------------
152 
158  protected override void Initialize()
159  {
160  //get the content manager
161  content = Services.GetService(typeof(ContentManager)) as ContentManager;
162  if (content == null)
163  {
164  content = new ContentManager(Services, "Content");
165  Services.AddService<ContentManager>(content);
166  }
167 
168  //init sprite batch
169  spriteBatch = new SpriteBatch(GraphicsDevice);
170  Services.AddService<SpriteBatch>(spriteBatch);
171 
172  #region set views
173 
174  //cameras[1] -> top slice view
175  cameras[1].CameraPosition = new Vector3(0.0f, 1.0f, 0.0f);
176  cameras[1].CameraTarget = GameProperties.Instance.dataOrigin;
177  cameras[1].CameraUpVector = Vector3.UnitZ;
178  cameras[1].SetPerspectiveProjecton = false;
179  cameras[1].Initialize();
180 
181  //cameras[2] -> side slice view
182  cameras[2].CameraPosition = new Vector3(1.0f, 0.0f, 0.0f);
183  cameras[2].CameraTarget = GameProperties.Instance.dataOrigin;
184  cameras[2].CameraUpVector = Vector3.Up;
185  cameras[2].SetPerspectiveProjecton = false;
186  cameras[2].Initialize();
187 
188  //cameras[3] -> front slice view
189  cameras[3].CameraPosition = new Vector3(0.0f, 0.0f, 1.0f);
190  cameras[3].CameraTarget = GameProperties.Instance.dataOrigin;
191  cameras[3].CameraUpVector = Vector3.Up;
192  cameras[3].SetPerspectiveProjecton = false;
193  cameras[3].Initialize();
194 
195  #endregion
196 
197  #region init control points
198  setInitialControlPoints();
199  #endregion
200  }
201  //__________________________________________________________________________________________
202  #endregion
203 
204  #region LoadContent()
205  //-----------------------------------LOAD_CONTENT()-----------------------------------------
210  protected override void LoadContent()
211  {
212  spriteBatchFont = content.Load<SpriteFont>("Fonts\\spriteFont1");
213 
214  frameworkInfo = content.Load<Texture2D>("Texture\\framework_info");
215 
216  if (debugShader)
217  {
218  //rgbTestTex = content.Load<Texture2D>("Texture\\rgb");
219  //rgbTestTex = content.Load<Texture2D>("Texture\\test1");
220  rgbTestTex = content.Load<Texture2D>("Texture\\schiff");
221  //rgbTestTex = content.Load<Texture2D>("Texture\\nebula");
222  //rgbTestTex = content.Load<Texture2D>("Texture\\lobster");
223  }
224 
225  #region viewports
226  //init viewports for split screen
227  defaultViewport = GraphicsDevice.Viewport;
228  defaultViewport.Width = this.Size.Width;
229  defaultViewport.Height = this.Size.Height;
230  setViewports();
231  #endregion
232 
233  #region create Render Targets
234 
235  PresentationParameters pp = GraphicsDevice.PresentationParameters;
236  SurfaceFormat format = pp.BackBufferFormat;
237  //format = SurfaceFormat.Rgba64;
238  int width = pp.BackBufferWidth;
239  int height = pp.BackBufferHeight;
240  DepthFormat depthStecilFormat = pp.DepthStencilFormat;
241  int multiSample = pp.MultiSampleCount;
242 
243 
244  frontTarget = new RenderTarget2D(GraphicsDevice, width, height, false, format,
245  depthStecilFormat, multiSample, RenderTargetUsage.DiscardContents);
246 
247  backTarget = new RenderTarget2D(GraphicsDevice, width, height, false, format,
248  depthStecilFormat, multiSample, RenderTargetUsage.DiscardContents);
249 
250  sceneTarget = new RenderTarget2D(GraphicsDevice, width, height, false, format,
251  depthStecilFormat, multiSample, RenderTargetUsage.DiscardContents);
252 
253  dvrTarget = new RenderTarget2D(GraphicsDevice, width, height, false, format, depthStecilFormat, multiSample, RenderTargetUsage.DiscardContents);
254 
255  cvdTarget = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.Rgba64, depthStecilFormat, multiSample, RenderTargetUsage.DiscardContents);
256 
257 
258 
259 
260  Console.WriteLine("RENDERTARGETS created!");
261  #endregion
262 
263  #region create all shader
264 
265  if (debugOutput)
266  {
267  Console.WriteLine("trying to create shader");
268  }
269 
270  // standard shader
271  shader = new VolumeShader(GraphicsDevice, content.Load<Effect>("Effects\\volumeShader"), false);
272 
273  #region CVD shader
274 
275  CVDshader = new VolumeShader(GraphicsDevice, content.Load<Effect>("Effects\\volumeCVDShader"), true);
276  tfWeightsShader = new TFWeightsShader(GraphicsDevice, content.Load<Effect>("Effects\\TFWeights"));
277 
278  #endregion
279 
280  #region recolor shader
281 
282  rGBtoLab_Shader = new RecolorShader(GraphicsDevice, content.Load<Effect>("Effects\\RGBtoLab"), "convertToLab");
283  contrastLoss_Shader = new RecolorShader(GraphicsDevice, content.Load<Effect>("Effects\\ContrastLoss"), "ContrastLoss");
284  predominantComponent_Shader = new RecolorShader(GraphicsDevice, content.Load<Effect>("Effects\\PredominantComponent"), "PredominantComponent");
285  eigenVector_Shader = new RecolorShader(GraphicsDevice, content.Load<Effect>("Effects\\EigenVector"), "EigenVector");
286  projection_Shader = new RecolorShader(GraphicsDevice, content.Load<Effect>("Effects\\Proj"), "Project");
287  maxProjectionEffect_Shader = new RecolorShader(GraphicsDevice, content.Load<Effect>("Effects\\MaxProjectionEffect"), "MaxProjectionEffect");
288  enhanceContrast_Shader = new RecolorShader(GraphicsDevice, content.Load<Effect>("Effects\\EnhanceContrast"), "EnhanceContrast");
289  labToRGB_Shader = new RecolorShader(GraphicsDevice, content.Load<Effect>("Effects\\LabtoRGB"), "convertToRGB");
290 
291  #endregion
292 
293  #region simulation shader
294 
295  sim_RGBtoLab_Shader = new RecolorShader(GraphicsDevice, content.Load<Effect>("Effects\\RGBtoLab"), "convertToLab");
296  lMSShader = new RecolorShader(GraphicsDevice, content.Load<Effect>("Effects\\LMS"), "LMS");
297  sim_LabToRGB_Shader = new RecolorShader(GraphicsDevice, content.Load<Effect>("Effects\\LabtoRGB"), "convertToRGB");
298 
299  #endregion
300 
301  #endregion
302 
303  cubeModel = content.Load<Model>("Models/box");
304 
305  }
306 
307 
308  //__________________________________________________________________________________________
309  #endregion
310 
311  #region UnloadContent()
312  //-----------------------------------UNLOAD_CONTENT()---------------------------------------
313 
318  /*protected override void UnloadContent() ->>> free resources???
319  {
320  // TODO: Unload any non ContentManager content here
321  base.UnloadContent();
322  }*/
323 
324  //__________________________________________________________________________________________
325  #endregion
326 
327  #region Update()
328  //-----------------------------------UPDATE()-----------------------------------------------
329 
334  protected override void Update()
335  {
336 
337  if (debugOutput)
338  {
339  Console.WriteLine("Engine Update Call number " + drawcount);
340  }
341 
342  #region load data
343 
344  if (GameProperties.Instance.engineState.loadData)
345  {
346 
347  if (input != null && this.Controls.Count > 0)
348  {
349  foreach (Control c in Controls)
350  {
351  if (c.GetType().Equals("Data"))
352  {
353  this.Controls.Remove(c);
354  input = null;
355  break;
356  }
357 
358  }
359  }
360  setInitialControlPoints();
361  input = new Data(GameProperties.Instance.dataDir + GameProperties.Instance.dataFilename);
362  this.Controls.Add(input);
363 
364  #region init camera for 3d view
365  //init camera
366  Vector4 factor = input.scaleFactor;
367  Vector3 scale = new Vector3(factor.X, factor.Y, factor.Z);
368  Vector3 target = new Vector3(0.5f, 0.5f, 0.5f) * scale;
369  target = Vector3.Transform(target, input.worldMatrix);
370  cameras[0] = new InteractiveCamera();
371  cameras[0].CameraPosition = new Vector3(target.X, target.Y, 2.0f);
372  cameras[0].CameraTarget = target;
373  cameras[0].Initialize();
374  cvdCamera = new InteractiveCamera();
375  cvdCamera.CameraPosition = new Vector3(target.X, target.Y, 2.0f);
376  cvdCamera.CameraTarget = target;
377  cvdCamera.Initialize();
378  #endregion
379 
380  shader.SetEffectParameter(input.VolumeData, input.volumeGradients, GameProperties.Instance.directLightPos, input.stepSize * input.scaleSteps, GameProperties.Instance.baseSampleDist, input.scaleSteps, input.iterations, 0, input.scaleFactor, new Vector2(input.DataDimensions.X, input.DataDimensions.Y), input.slice);
381  //shader.SetEffectParameter(input.VolumeData, input.volumeGradients, input.stepSize * input.scaleSteps, input.iterations, 0, input.scaleFactor, input.slice);
382  GameProperties.Instance.engineState.loadData = false;
383  GameProperties.Instance.showInfoText = false;
384 
385  if (debugOutput)
386  {
387  Console.WriteLine("load data done");
388  }
389 
390  } //end if load data
391  #endregion
392 
393  #region set view mode and camera
394 
395  //set view mode and camera for single screen
396  if (GameProperties.Instance.engineState.updateCamera)
397  {
398  #region set camera to current view
399  if (debugOutput)
400  {
401  Console.WriteLine("SETTING CAMERA");
402  }
403  if (GameProperties.Instance.viewportMode.Equals(ViewportMode.Single))
404  {
405  currentView = 0;
406  switch (GameProperties.Instance.viewMode)
407  {
408  case ViewMode.VolView: //single 3d view
409 
410  currentView = 0;
411  break;
412 
413  case ViewMode.TopView: //single top view
414  currentView = 1;
415  break;
416 
417  case ViewMode.SideView: //single side view
418  currentView = 2;
419  break;
420 
421  case ViewMode.FrontView: //single front view
422  currentView = 3;
423  break;
424 
425  default:
426  currentView = 0;
427  break;
428  }
429 
430  if (currentView == 0) //set camera for the 3d view
431  {
432  cameras[currentView].SetPerspectiveProjecton = GameProperties.Instance.perspectiveProjection;
433  }
434 
435  cameras[currentView].CameraInput = GameProperties.Instance.cameraInput;
436  cameras[currentView].Update();
437 
438 
439  #endregion
440 
441  //set parameters to draw the correct scene view
442  if (input != null)
443  {
444  input.Camera = cameras[currentView];
445  input.CurrentCamera = currentView;
446  }
447  }
448  else if (GameProperties.Instance.viewportMode.Equals(ViewportMode.Split4))//set view mode and camera vor split screen
449  {
450  //3d view camera
451  cameras[0].SetPerspectiveProjecton = GameProperties.Instance.perspectiveProjection;
452  cameras[0].CameraInput = GameProperties.Instance.cameraInput;
453  cameras[0].SetClientSize = new int[] { viewports[0].Width, viewports[0].Height };
454  cameras[0].Update();
455  cvdCamera.SetPerspectiveProjecton = GameProperties.Instance.perspectiveProjection;
456  cvdCamera.CameraInput = GameProperties.Instance.cameraInput;
457  cvdCamera.SetClientSize = new int[] { viewports[2].Width, viewports[2].Height };
458  cvdCamera.Update();
459 
460  if (GameProperties.Instance.enableCVDView == true) //priority!
461  {
462  cvdCamera.SetPerspectiveProjecton = GameProperties.Instance.perspectiveProjection;
463  cvdCamera.CameraInput = GameProperties.Instance.cameraInput;
464  cvdCamera.SetClientSize = new int[] { viewports[2].Width, viewports[2].Height };
465  cvdCamera.Update();
466  }
467  else //split screen with 3d and slices
468  {
469  for (int i = 1; i < cameras.Length; i++)
470  {
471  cameras[i].CameraInput = GameProperties.Instance.cameraInput;
472  cameras[i].SetClientSize = new int[] { viewports[i].Width, viewports[i].Height };
473  cameras[i].Update();
474  }
475 
476  }
477  }
478 
479  GameProperties.Instance.engineState.updateCamera = false;
480  if (debugOutput)
481  {
482  Console.WriteLine("CAMERA SET");
483  }
484  }
485  #endregion
486 
487  #region update data
488  if (GameProperties.Instance.engineState.updateData && input != null)
489  {
490  #region front and backfaces
491 
492  if (GameProperties.Instance.viewportMode.Equals(ViewportMode.Split4) || (GameProperties.Instance.viewportMode.Equals(ViewportMode.Single) && currentView == (int)ViewMode.VolView))
493  {
494  #region set shader parameters for rendering
495  GraphicsDevice.BlendState = BlendState.Additive;
496  shader.CurrentTechnique = shader.Techniques["RenderPosition"];
497  shader.SetEffectParameter(input.worldMatrix * cameras[(int)ViewMode.VolView].ViewProjection, input.worldMatrix);
498  shader.SetEffectParameter(cameras[(int)ViewMode.VolView].CameraPosition);
499  #endregion
500 
501  if (render == 0)
502  {
503  if (debugOutput)
504  {
505  Console.WriteLine("don't draw frontfaces or backfaces or volume");
506  }
507  }
508 
509  if (render > 0)
510  {
511  #region Draw Frontfaces
512  if (debugOutput)
513  {
514  Console.WriteLine("1 DRAWING FRONTFACES");
515  }
516  GraphicsDevice.SetRenderTarget(frontTarget);
517  GraphicsDevice.Clear(Color.Black);
518  GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
519  shader.FrontFacesTexture = null;
520 
521  DrawVolume(0);
522  GraphicsDevice.SetRenderTarget(null);
523  #endregion
524  }
525 
526  if (render > 1)
527  {
528  #region Draw Backfaces
529  if (debugOutput)
530  {
531  Console.WriteLine("2 DRAWING BACKFACES");
532  }
533  GraphicsDevice.SetRenderTarget(backTarget);
534  GraphicsDevice.Clear(Color.Black);
535  GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;
536  shader.BackFacesTexture = null;
537 
538  DrawVolume(0);
539  GraphicsDevice.SetRenderTarget(null);
540  #endregion
541  }
542 
543  #region pass textures to shader
544  shader.FrontFacesTexture = frontTarget;
545  shader.BackFacesTexture = backTarget;
546  #endregion
547 
548  input.setControlpoints();
549  shader.TransferTexture = input.transferTexture;
550  shader.TransferTextureAlpha = input.transferTextureAlpha;
551  }
552 
553 
554  #region pass textures to shader
555  shader.FrontFacesTexture = frontTarget;
556  CVDshader.FrontFacesTexture = frontTarget;
557  shader.BackFacesTexture = backTarget;
558  CVDshader.BackFacesTexture = backTarget;
559  #endregion
560 
561  input.setControlpoints();
562  shader.TransferTexture = input.transferTexture;
563  shader.TransferTextureAlpha = input.transferTextureAlpha;
564  CVDshader.TransferTextureAlpha = input.transferTextureAlpha;
565 
566  GameProperties.Instance.engineState.updateData = false;
567 
568  if (debugOutput)
569  {
570  Console.WriteLine("data updated");
571  }
572  }
573  #endregion
574  #endregion
575 
576  #region optimize tf for cvd
577  //process just once for a single tf
578  if (true) //just for debug
579  {
580  if (GameProperties.Instance.enableCVDView && input != null)
581  {
582 
583  #region recoloring
584 
585  #region calculate new?
586  // calculate new only when recoloredView is first activated
587  if (GameProperties.Instance.recoloredView == true && GameProperties.Instance.recolor == false && GameProperties.Instance.triggerRecolor)
588  {
589  GameProperties.Instance.recolor = true;
590  }
591  else
592  {
593  GameProperties.Instance.recolor = false;
594  }
595  #endregion
596 
597  if (GameProperties.Instance.recolor)
598  {
599  #region instanciate Image class
600  if (recoloredImage == null)
601  {
602  recoloredImage = new Image(GraphicsDevice, GameProperties.Instance.CVD);
603  }
604  #endregion
605 
606  #region assign shader
607  if (recoloredImage.RGBtoLab_Shader == null)
608  {
609  recoloredImage.RGBtoLab_Shader = rGBtoLab_Shader;
610  recoloredImage.ContrastLoss_Shader = contrastLoss_Shader;
611  recoloredImage.PredominantComponent_Shader = predominantComponent_Shader;
612  recoloredImage.EigenVector_Shader = eigenVector_Shader;
613  recoloredImage.Projection_Shader = projection_Shader;
614  recoloredImage.MaxProjectionEffect_Shader = maxProjectionEffect_Shader;
615  recoloredImage.EnhanceContrast_Shader = enhanceContrast_Shader;
616  recoloredImage.LabToRGB_Shader = labToRGB_Shader;
617  }
618  #endregion
619 
620  #region debug: set test image to recolor
621  if (debugShader)
622  {
623  recoloredImage.ReferenceImageRGB = rgbTestTex;
624  }
625  else
626  {
627  if (GameProperties.Instance.viewportMode.Equals(ViewportMode.Split4))
628  {
629  recoloredImage.ReferenceImageRGB = dvrTexture;
630  //saveScreenshot(dvrTarget, "dvrtest.png", "PNG");
631  }
632  else
633  {
634  recoloredImage.ReferenceImageRGB = sceneTarget;
635  }
636  }
637  #endregion
638 
639  // recolor image
640  recoloredImage.Recolor(GraphicsDevice);
641 
642  GameProperties.Instance.recolor = false;
643  GameProperties.Instance.triggerRecolor = false;
644 
645  }
646 
647  #endregion
648 
649  #region calculate cvd tf
650 
651  if (recoloredImage != null && GameProperties.Instance.cvdView && GameProperties.Instance.triggerOptimize)
652  {
653  cvdtf = new CVDtf(recoloredImage.RecoloredImage, GraphicsDevice);
654  cvdtf.selectRecoloredPixels();
655 
656  #region set shader
657  //set selected pixels to shader
658  tfWeightsShader.SetEffectParameter(cvdtf.RecoloredImageMask);
659  tfWeightsShader.FrontFacesTexture = shader.FrontFacesTexture;
660  tfWeightsShader.BackFacesTexture = shader.BackFacesTexture;
661  tfWeightsShader.TransferTexture = shader.TransferTexture;
662  tfWeightsShader.TransferTextureAlpha = shader.TransferTextureAlpha;
663  tfWeightsShader.SetEffectParameter(input.volumeData, GameProperties.Instance.directLightPos, input.stepSize * input.scaleSteps, GameProperties.Instance.baseSampleDist, input.scaleSteps, input.iterations, 0, input.scaleFactor, new Vector2(input.DataDimensions.X, input.DataDimensions.Y), input.slice);
664  tfWeightsShader.SetEffectParameter(input.worldMatrix * cameras[0].ViewProjection, input.worldMatrix);
665  tfWeightsShader.SetEffectParameter(cameras[0].CameraPosition);
666  tfWeightsShader.CurrentTechnique = tfWeightsShader.Techniques["CalculateColorWeights"];
667  #endregion
668 
669  #region set render graphics device
670  //GraphicsDevice.DepthStencilState = DepthStencilState.Default;
671  GraphicsDevice.BlendState = BlendState.AlphaBlend;
672  GraphicsDevice.RasterizerState = RasterizerState.CullNone;
673  #endregion
674 
675  #region calculate weights
676 
677  List<TransferControlPoint> cpList = GameProperties.Instance.colorControlPoints;
678  cpList.Sort(delegate(TransferControlPoint p1, TransferControlPoint p2) { return p1.isoValue.CompareTo(p2.isoValue); });
679 
680  //render for each control point
681  for (int i = 0; i < cpList.Count; i++)
682  {
683 
684  float currCp; float prevCp; float nextCp;
685  //set curr cp index to shader
686  if (i == 0)
687  {
688  currCp = (float)cpList[i].isoValue;
689  prevCp = 0.0f;//1. default cp
690  nextCp = (float)cpList[i + 1].isoValue;
691  }
692  else if (i == (cpList.Count - 1))
693  {
694  currCp = (float)cpList[i].isoValue;
695  prevCp = (float)cpList[i - 1].isoValue;
696  nextCp = 255.0f; //last default cp
697  }
698  else
699  {
700  currCp = (float)cpList[i].isoValue;
701  prevCp = (float)cpList[i - 1].isoValue;
702  nextCp = (float)cpList[i + 1].isoValue;
703  }
704  tfWeightsShader.SetEffectParameter(currCp, prevCp, nextCp);
705  #region draw
706  GraphicsDevice.SetRenderTarget(cvdTarget); //cvdTarget
707  GraphicsDevice.Clear(Color.Black);
708  if (GameProperties.Instance.debugOutput)
709  {
710  Console.WriteLine("GraphicsDevice Render Target set to cvd target");
711  }
712  //call draw with this shader, set all other parameteres needed by the ray casting
713  try
714  {
715  foreach (ModelMesh mesh in cubeModel.Meshes)
716  {
717  foreach (ModelMeshPart mmp in mesh.MeshParts)
718  {
719  mmp.Effect = tfWeightsShader;
720 
721  Console.WriteLine("drawing...side.." + currentView);
722  };
723  mesh.Draw();
724  }
725  }
726  catch (Exception e)
727  {
728  Console.WriteLine("ERROR: " + e);
729  throw;
730  }
731 
732  GraphicsDevice.SetRenderTarget(null);
733  #endregion
734  cvdtf.setTFWeights(cvdTarget, i); //cvdTarget for ith control point
735  if (debugOutput)
736  {
737  saveScreenshot(cvdTarget, "cpweights" + i, "png");
738  }
739  }//end for control points list
740 
741  #endregion
742 
743  #region calculate and set cvd transfer function
744  CVDshader.CVDTransferTexture = cvdtf.calculateCVDColors();
745  #endregion
746 
747  GameProperties.Instance.CVDTFOptimized = true;
748  GameProperties.Instance.triggerOptimize = false;
749 
750  }
751  #endregion
752 
753  #region simulate perception
754 
755  #region calculate new?
756  // calculate new only when simulatedView is first activated
757  if (GameProperties.Instance.simulatedView == true && GameProperties.Instance.simulate == false && GameProperties.Instance.triggerSimulate)
758  {
759  GameProperties.Instance.simulate = true;
760  }
761  else
762  {
763  GameProperties.Instance.simulate = false;
764  }
765  #endregion
766 
767  if (GameProperties.Instance.simulate)
768  {
769  if (GameProperties.Instance.simulatedView && GameProperties.Instance.triggerSimulate)
770  {
771  #region instanciate Image class
772  if (simulatedImage == null)
773  {
774  simulatedImage = new Image(GraphicsDevice, GameProperties.Instance.CVD);
775  }
776  #endregion
777 
778  #region assign shader
779  if (simulatedImage.RGBtoLab_Shader == null)
780  {
781  simulatedImage.RGBtoLab_Shader = sim_RGBtoLab_Shader;
782  simulatedImage.LMSShader = lMSShader;
783  simulatedImage.LabToRGB_Shader = sim_LabToRGB_Shader;
784  }
785  #endregion
786 
787  #region debug: set test image to simulate perception
788  if (debugShader)
789  {
790  //simulatedImage.ImageToSimulate = rgbTestTex;
791  if (GameProperties.Instance.viewportMode.Equals(ViewportMode.Split4))
792  {
793  simulatedImage.ImageToSimulate = dvrTexture;
794  }
795  else
796  {
797  simulatedImage.ImageToSimulate = sceneTarget;
798  }
799  }
800  else
801  {
802  if (GameProperties.Instance.viewportMode.Equals(ViewportMode.Split4))
803  {
804  simulatedImage.ImageToSimulate = dvrTexture;
805  //saveScreenshot(dvrTarget, "dvrtest.png", "PNG");
806  }
807  else
808  {
809  simulatedImage.ImageToSimulate = sceneTarget;
810  }
811  }
812  #endregion
813 
814  // simulate perception for image
815  simulatedImage.SimulatePerception(GraphicsDevice);
816 
817  GameProperties.Instance.simulate = false;
818  GameProperties.Instance.triggerSimulate = false; //process one for every check event
819  }
820 
821 
822  }
823  #endregion
824  }
825 
826  }
827  #endregion
828  }
829 
830  private void DrawSprite(Texture2D tex)
831  {
832  GraphicsDevice.Clear(Color.Black);
833  GraphicsDevice.BlendState = BlendState.Additive;
834 
835  spriteBatch.Begin(0, BlendState.Additive, null, null, null, null);
836 
837  spriteBatch.Draw(tex, new Rectangle(0, 0, tex.Width, tex.Height), Color.Black);
838 
839  spriteBatch.End();
840  }
841 
842  //__________________________________________________________________________________________
843  #endregion
844 
845  #region Draw stuff
846  //-----------------------------------DRAW()-------------------------------------------------
847 
848  protected override void Draw()
849  {
850  //debug
851  if (debugOutput)
852  {
853  Console.WriteLine("Engine Draw Call " + drawcount);
854  }
855  drawcount++;
856 
857  GraphicsDevice.SetRenderTarget(null);
858  GraphicsDevice.Viewport = defaultViewport;
859  GraphicsDevice.Clear(Color.Black);
860 
861  #region draw info text on start
862  if (GameProperties.Instance.showInfoText)
863  {
864  drawInfo();
865  }
866  #endregion
867 
868  #region draw data
869 
870  if (GameProperties.Instance.engineState.drawData && input != null)
871  {
872 
873  #region save screenshot or recolor or simulate perception: set render target
874  if (GameProperties.Instance.saveView || GameProperties.Instance.recolor || GameProperties.Instance.simulate)
875  {
876  GraphicsDevice.SetRenderTarget(sceneTarget);
877  if (debugOutput)
878  {
879  Console.WriteLine("GraphicsDevice Render Target set to scenetarget");
880  }
881  }
882  #endregion
883 
884  //GraphicsDevice.SetRenderTarget(null);
885  //GraphicsDevice.SetRenderTarget(sceneTarget);
886 
887  //split screen
888  if (GameProperties.Instance.viewportMode.Equals(ViewportMode.Split4))
889  {
890 
891  if (GameProperties.Instance.enableCVDView)
892  {
893 
894  #region top left->3d view
895  //process only if not recolored yet and recoloredView == false
896  if(!GameProperties.Instance.recoloredView){
897  GraphicsDevice.SetRenderTarget(dvrTarget);
898  GraphicsDevice.Viewport = defaultViewport;
899  if (render > 2)
900  {
901  #region set parameters for rendering
902  GraphicsDevice.Clear(Color.Black);
903  GraphicsDevice.BlendState = BlendState.Additive;
904  GraphicsDevice.RasterizerState = RasterizerState.CullNone;
905  #endregion
906 
907  if (GameProperties.Instance.maximumIntensityProjection == true)
908  {
909  shader.CurrentTechnique = shader.Techniques["MaximumIntensity"];
910  }
911  else
912  {
913  GraphicsDevice.BlendState = BlendState.AlphaBlend;
914  GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;
915  shader.CurrentTechnique = shader.Techniques["RayCastSimple"];
916  }
917  }
918 
919  DrawVolume(0);
920  GraphicsDevice.SetRenderTarget(null);
921  dvrTexture = dvrTarget;
922  }
923 
924  #region draw 3d sprite for the split screen
925 
926  GraphicsDevice.Clear(Color.Black);
927 
928  GraphicsDevice.Viewport = defaultViewport;
929  GraphicsDevice.DepthStencilState = DepthStencilState.None;
930  spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
931  spriteBatch.Draw(dvrTexture, new Rectangle(viewports[0].X, viewports[0].Y, viewports[0].Width, viewports[0].Height), Color.White);
932  spriteBatch.End();
933  GraphicsDevice.DepthStencilState = DepthStencilState.Default;
934 
935 
936  /*GraphicsDevice.Viewport = viewports[0];
937  if (render > 2)
938  {
939  #region set parameters for rendering
940 
941  GraphicsDevice.BlendState = BlendState.Additive;
942  GraphicsDevice.RasterizerState = RasterizerState.CullNone;
943  #endregion
944 
945  if (GameProperties.Instance.maximumIntensityProjection == true)
946  {
947  shader.CurrentTechnique = shader.Techniques["MaximumIntensity"];
948  }
949  else
950  {
951  GraphicsDevice.BlendState = BlendState.AlphaBlend;
952  GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;
953  shader.CurrentTechnique = shader.Techniques["RayCastSimple"];
954  }
955  }
956 
957  DrawVolume(0);
958  drawText(0);*/
959  #endregion
960 
961  #endregion
962 
963 
964  #region top right-> recolored
965 
966  if (GameProperties.Instance.recoloredView && recoloredImage.RecoloredImage != null)
967  {
968  GraphicsDevice.Viewport = defaultViewport;
969  GraphicsDevice.DepthStencilState = DepthStencilState.None;
970  spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
971  spriteBatch.Draw(recoloredImage.RecoloredImage, new Rectangle(viewports[1].X, viewports[1].Y, viewports[1].Width, viewports[1].Height), Color.White);
972  spriteBatch.End();
973  GraphicsDevice.DepthStencilState = DepthStencilState.Default;
974 
975  }
976 
977 
978  #endregion
979 
980 
981  #region bottom left-> cvd
982 
983  GraphicsDevice.Viewport = viewports[2];
984  if (GameProperties.Instance.cvdView && GameProperties.Instance.CVDTFOptimized)
985  {
986  GraphicsDevice.SetRenderTarget(null);
987  #region draw cvd friendly volume
988  GraphicsDevice.BlendState = BlendState.AlphaBlend;
989  GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;
990  try
991  {
992  foreach (ModelMesh mesh in cubeModel.Meshes)
993  {
994  foreach (ModelMeshPart mmp in mesh.MeshParts)
995  {
996  mmp.Effect = CVDshader;
997  CVDshader.SetEffectParameter_CVD(input.VolumeData,
998  input.volumeGradients,
999  input.stepSize * input.scaleSteps,
1000  input.iterations,
1001  input.scaleFactor,
1002  new Vector2(input.DataDimensions.X, input.DataDimensions.Y),
1003  recoloredImage.RotationToLMS,
1004  recoloredImage.RotationFromLMS);
1005  CVDshader.SetEffectParameter(input.worldMatrix * cameras[0].ViewProjection, input.worldMatrix);
1006  CVDshader.SetEffectParameter(cameras[0].CameraPosition);
1007 
1008  };
1009  initializeTextureFilter();
1010  mesh.Draw();
1011  }
1012  }
1013  catch (Exception e)
1014  {
1015  Console.WriteLine("ERROR: " + e);
1016  throw;
1017  }
1018  }
1019  #endregion
1020  #endregion
1021 
1022 
1023  #region bottom right-> simulated
1024 
1025  if (simulatedImage != null)
1026  {
1027  GraphicsDevice.Viewport = defaultViewport;
1028  GraphicsDevice.DepthStencilState = DepthStencilState.None;
1029  spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
1030  spriteBatch.Draw(simulatedImage.RecoloredImage, new Rectangle(viewports[3].X, viewports[3].Y, viewports[3].Width, viewports[3].Height), Color.White);
1031  spriteBatch.End();
1032  GraphicsDevice.DepthStencilState = DepthStencilState.Default;
1033  }
1034 
1035  #endregion
1036  GraphicsDevice.Viewport = viewports[0];
1037  drawText(0);
1038  GraphicsDevice.Viewport = viewports[1];
1039  drawText(4);
1040  GraphicsDevice.Viewport = viewports[2];
1041  drawText(5);
1042  GraphicsDevice.Viewport = viewports[3];
1043  drawText(6);
1044  GraphicsDevice.Viewport = defaultViewport;
1045 
1046 
1047 
1048  }
1049  else //render 3d view and slices in split screen
1050  {
1051  if (render > 2)
1052  {
1053  #region set parameters for rendering
1054  GraphicsDevice.Clear(Color.Black);
1055  GraphicsDevice.BlendState = BlendState.Additive;
1056  GraphicsDevice.RasterizerState = RasterizerState.CullNone;
1057  #endregion
1058 
1059  for (int current = 0; current < 4; current++)
1060  {
1061  GraphicsDevice.Viewport = viewports[current];
1062 
1063  #region set correct shader technique
1064  if (current == 1)
1065  {
1066  input.slice = GameProperties.Instance.ySliceValue;
1067  shader.CurrentTechnique = shader.Techniques["RenderSlice"];
1068  }
1069  else if (current == 2)
1070  {
1071  input.slice = GameProperties.Instance.xSliceValue;
1072  shader.CurrentTechnique = shader.Techniques["RenderSlice"];
1073  }
1074  else if (current == 3)
1075  {
1076  input.slice = GameProperties.Instance.zSliceValue;
1077  shader.CurrentTechnique = shader.Techniques["RenderSlice"];
1078  }
1079  else
1080  {
1081  if (GameProperties.Instance.maximumIntensityProjection == true)
1082  {
1083  shader.CurrentTechnique = shader.Techniques["MaximumIntensity"];
1084  }
1085  else
1086  {
1087  GraphicsDevice.BlendState = BlendState.AlphaBlend;
1088  GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;
1089  shader.CurrentTechnique = shader.Techniques["RayCastSimple"];
1090  }
1091  }
1092  #endregion
1093 
1094  DrawVolume(current);
1095 
1096 
1097  #region draw text
1098  drawText(current);
1099  #endregion
1100 
1101  }
1102 
1103  GraphicsDevice.Viewport = defaultViewport;
1104  }
1105  else
1106  {
1107  // swapBuffers = false;
1108  }
1109 
1110 
1111  }
1112 
1113 
1114  }
1115  //single screens
1116  else if(GameProperties.Instance.viewportMode.Equals(ViewportMode.Single))
1117  {
1118  //GraphicsDevice.SetRenderTarget(null);
1119  if (debugOutput)
1120  {
1121  Console.WriteLine("DRAWING DATA!");
1122  }
1123  if (render > 2)
1124  {
1125  #region Draw Volume
1126 
1127  #region set parameters for rendering
1128  GraphicsDevice.Clear(Color.Black);
1129  GraphicsDevice.BlendState = BlendState.Additive;
1130  GraphicsDevice.RasterizerState = RasterizerState.CullNone;
1131  //shader.SetEffectParameter(input.worldMatrix * cameras[currentView].ViewProjection, input.worldMatrix);
1132  //shader.SetEffectParameter(cameras[currentView].CameraPosition);
1133  #endregion
1134 
1135  #region set correct shader technique
1136  if (currentView == 1)
1137  {
1138  input.slice = GameProperties.Instance.ySliceValue;
1139  shader.CurrentTechnique = shader.Techniques["RenderSlice"];
1140  }
1141  else if (currentView == 2)
1142  {
1143  input.slice = GameProperties.Instance.xSliceValue;
1144  shader.CurrentTechnique = shader.Techniques["RenderSlice"];
1145  }
1146  else if (currentView == 3)
1147  {
1148  input.slice = GameProperties.Instance.zSliceValue;
1149  shader.CurrentTechnique = shader.Techniques["RenderSlice"];
1150  }
1151  else
1152  {
1153  if (GameProperties.Instance.maximumIntensityProjection == true)
1154  {
1155  shader.CurrentTechnique = shader.Techniques["MaximumIntensity"];
1156  }
1157  else
1158  {
1159  GraphicsDevice.BlendState = BlendState.AlphaBlend;
1160  GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;
1161  shader.CurrentTechnique = shader.Techniques["RayCastSimple"];
1162  }
1163  }
1164  #endregion
1165  if (debugOutput)
1166  {
1167  Console.WriteLine(shader.CurrentTechnique.Name);
1168 
1169  }
1170 
1171  DrawVolume(currentView);
1172 
1173  #endregion
1174 
1175  #region draw text
1176  if (!(GameProperties.Instance.recolor || GameProperties.Instance.simulate))
1177  {
1178  //draw view mode
1179  drawText();
1180  }
1181  #endregion
1182  }
1183  }
1184 
1185 
1186  #region save screenshot
1187  if (GameProperties.Instance.saveView)
1188  {
1189  if (string.IsNullOrEmpty(GameProperties.Instance.saveFilename))
1190  {
1191  throw new ArgumentNullException(GameProperties.Instance.saveFilename);
1192  }
1193  GraphicsDevice.SetRenderTarget(null);
1194  saveScreenshot(sceneTarget, GameProperties.Instance.saveFilename, "png");
1195  GameProperties.Instance.saveView = false;
1196  this.swapBuffers = false;
1197 
1198  }
1199  #endregion
1200 
1201  GameProperties.Instance.engineState.drawData = false;
1202 
1203  if (debugOutput)
1204  {
1205  Console.WriteLine("end of drawing");
1206  }
1207  }
1208  #endregion
1209 
1210  }
1211 
1212  #region DrawVolume()
1213  public void DrawVolume(int side)
1219  {
1220  // draw cubeModel
1221  if (debugOutput)
1222  {
1223  Console.WriteLine("DrawVolume()");
1224  }
1225 
1226 
1227 
1228  #region draw original volume
1229  try
1230  {
1231  foreach (ModelMesh mesh in cubeModel.Meshes)
1232  {
1233  foreach (ModelMeshPart mmp in mesh.MeshParts)
1234  {
1235  mmp.Effect = shader;
1236  shader.SetEffectParameter(input.VolumeData, input.volumeGradients, input.stepSize * input.scaleSteps, input.iterations, side, input.scaleFactor, input.slice);
1237  shader.SetEffectParameter(input.worldMatrix * cameras[side].ViewProjection, input.worldMatrix);
1238  shader.SetEffectParameter(cameras[side].CameraPosition);
1239  if (debugOutput)
1240  {
1241  //Console.WriteLine("Camera pos:" + cameras[currentView].CameraPosition.X + "," + cameras[currentView].CameraPosition.Y + "," + cameras[currentView].CameraPosition.Z);
1242  Console.WriteLine("drawing...side.." + side);
1243  }
1244  };
1245 
1246  mesh.Draw();
1247  }
1248  }
1249  catch (Exception e)
1250  {
1251  Console.WriteLine("ERROR: " + e);
1252  throw;
1253  }
1254  #endregion
1255 
1256  }
1257  #endregion
1258 
1259  #region save screenshot
1260  private void saveScreenshot(Texture2D texture, String name, String ext)
1266  {
1267  if (debugOutput)
1268  {
1269  Console.WriteLine("saving " + name);
1270  }
1271  try
1272  {
1273  if (!name.ElementAt(name.Length - 4).Equals(".")) name = name + "." + ext;
1274  FileStream stream = File.OpenWrite(name);
1275  switch (ext)
1276  {
1277  case "png":
1278  texture.SaveAsPng(stream, texture.Width, texture.Height);
1279  break;
1280  case "jpg":
1281  texture.SaveAsJpeg(stream, texture.Width, texture.Height);
1282  break;
1283  default:
1284  if (name.ElementAt(name.Length - 4).Equals(".")) name = name.Substring(0, name.Length - 4);
1285  name = name + ".png";
1286  texture.SaveAsPng(stream, texture.Width, texture.Height);
1287  break;
1288  }
1289 
1290  }
1291  catch (Exception e)
1292  {
1293  Console.WriteLine("Save Screenshot: ");
1294  Console.WriteLine(e);
1295  }
1296 
1297  }
1298  #endregion
1299 
1300  #region draw text
1301  private void drawText()
1302  {
1303  if (debugOutput)
1304  {
1305  Console.WriteLine("DRAWING TEXT!");
1306  }
1307  GraphicsDevice.DepthStencilState = DepthStencilState.None;
1308 
1309  spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
1310 
1311  switch ((int)GameProperties.Instance.viewMode)
1312  {
1313  case 0:
1314  spriteBatch.DrawString(spriteBatchFont, ("3D View"),
1315  new Vector2(50, 50), Color.Silver);
1316  break;
1317  case 1:
1318  spriteBatch.DrawString(spriteBatchFont, ("Top View"),
1319  new Vector2(50, 50), Color.Silver);
1320  break;
1321  case 2:
1322  spriteBatch.DrawString(spriteBatchFont, ("Side View"),
1323  new Vector2(50, 50), Color.Silver);
1324  break;
1325  case 3:
1326  spriteBatch.DrawString(spriteBatchFont, ("Front View"),
1327  new Vector2(50,50), Color.Silver);
1328  break;
1329  default:
1330  spriteBatch.DrawString(spriteBatchFont, ("3d View"),
1331  new Vector2(50, 50), Color.Silver);
1332  break;
1333  }
1334 
1335  spriteBatch.End();
1336  GraphicsDevice.DepthStencilState = DepthStencilState.Default;
1337  }
1338 
1339 
1340  private void drawText(int viewMode)
1341  {
1342  if (debugOutput)
1343  {
1344  Console.WriteLine("DRAWING TEXT!");
1345  }
1346  GraphicsDevice.DepthStencilState = DepthStencilState.None;
1347 
1348  spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
1349 
1350  switch (viewMode)
1351  {
1352  case 0:
1353  spriteBatch.DrawString(spriteBatchFont, ("3D View"),
1354  new Vector2(50, 50), Color.Silver);
1355  break;
1356  case 1:
1357  spriteBatch.DrawString(spriteBatchFont, ("Top View"),
1358  new Vector2(50, 50), Color.Silver);
1359  break;
1360  case 2:
1361  spriteBatch.DrawString(spriteBatchFont, ("Side View"),
1362  new Vector2(50, 50), Color.Silver);
1363  break;
1364  case 3:
1365  spriteBatch.DrawString(spriteBatchFont, ("Front View"),
1366  new Vector2(50, 50), Color.Silver);
1367  break;
1368  case 4:
1369  spriteBatch.DrawString(spriteBatchFont, ("Recolored Image"),
1370  new Vector2(50, 50), Color.Silver);
1371  break;
1372  case 5:
1373  spriteBatch.DrawString(spriteBatchFont, ("CVD View"),
1374  new Vector2(50, 50), Color.Silver);
1375  break;
1376  case 6:
1377  spriteBatch.DrawString(spriteBatchFont, ("Simulated Perception"),
1378  new Vector2(50, 50), Color.Silver);
1379  break;
1380  default:
1381  spriteBatch.DrawString(spriteBatchFont, ("3d View"),
1382  new Vector2(50, 50), Color.Silver);
1383  break;
1384  }
1385 
1386  spriteBatch.End();
1387  GraphicsDevice.DepthStencilState = DepthStencilState.Default;
1388  }
1389  #endregion
1390 
1391  #region draw framework info
1392  private void drawInfo()
1396  {
1397  if (debugOutput)
1398  {
1399  Console.WriteLine("DRAWING INFO!");
1400  }
1401 
1402  GraphicsDevice.Clear(Color.Black);
1403  GraphicsDevice.DepthStencilState = DepthStencilState.None;
1404 
1405  spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
1406 
1407  //if(GameProperties.Instance.viewportMode.Equals(ViewportMode.Single))
1408  //{
1409  spriteBatch.Draw(frameworkInfo, new Rectangle(0, 0, defaultViewport.Width, defaultViewport.Height), Color.White);
1410 
1411  //}else if(GameProperties.Instance.viewportMode.Equals(ViewportMode.Split4))
1412  //{
1413  // spriteBatch.Draw(frameworkInfo, new Rectangle(0, 0, viewports[0].Width, viewports[0].Height), Color.White);
1414  //}
1415 
1416  spriteBatch.DrawString(spriteBatchFont, ("Load model: File -> Open"),
1417  new Vector2(30, (Height * 0.5f)), Color.Black);
1418  spriteBatch.DrawString(spriteBatchFont, ("Save Screenshot: File -> Save"),
1419  new Vector2(30, (Height * 0.5f) + 30), Color.Black);
1420  spriteBatch.DrawString(spriteBatchFont, ("Load or Save TF: Functions -> Transferfunction->"),
1421  new Vector2(30, (Height * 0.5f) + 60), Color.Black);
1422  spriteBatch.DrawString(spriteBatchFont, ("CVD DVR: Extended Features -> CVD"),
1423  new Vector2(30, (Height * 0.5f) + 90), Color.Black);
1424  spriteBatch.DrawString(spriteBatchFont, ("3d View Camera: Left mouse button -> rotate, right mouse button->zoom"),
1425  new Vector2(30, (Height * 0.5f) + 120), Color.Black);
1426 
1427  spriteBatch.End();
1428  GraphicsDevice.DepthStencilState = DepthStencilState.Default;
1429 
1430  }
1431  //__________________________________________________________________________________________
1432  #endregion
1433 
1434  #endregion
1435 
1436  #region additional Methods
1437  //##########################################################################################
1438 
1439  #region set initial control points
1440  void setInitialControlPoints()
1441  {
1442  //set initial control points
1443  GameProperties.Instance.colorControlPoints.Clear();
1444  GameProperties.Instance.alphaControlPoints.Clear();
1445  GameProperties.Instance.colorControlPoints.Add(new TransferControlPoint(0.0f, 0.0f, 0.0f, 20));//bottom left
1446  GameProperties.Instance.colorControlPoints.Add(new TransferControlPoint(0.0f, 0.0f, 0.0f, 250));//bottom right
1447  GameProperties.Instance.colorControlPoints.Add(new TransferControlPoint(1.0f, 0.0f, 0.0f, 50));
1448  GameProperties.Instance.colorControlPoints.Add(new TransferControlPoint(0.0f, 1.0f, 0.0f, 150));
1449  GameProperties.Instance.colorControlPoints.Add(new TransferControlPoint(0.0f, 0.0f, 1.0f, 200));
1450  GameProperties.Instance.alphaControlPoints.Add(new TransferControlPoint(0.0f, 20));//bottom left
1451  GameProperties.Instance.alphaControlPoints.Add(new TransferControlPoint(0.0f, 250));//bottom right
1452  GameProperties.Instance.alphaControlPoints.Add(new TransferControlPoint(0.8f, 50));
1453  GameProperties.Instance.alphaControlPoints.Add(new TransferControlPoint(1.0f, 150));
1454  GameProperties.Instance.alphaControlPoints.Add(new TransferControlPoint(0.8f, 200));
1455  }
1456  #endregion
1457 
1458  #region Initialize Texture Filter -> NEED THIS???
1459  private void initializeTextureFilter()
1463  {
1464  if (debugOutput)
1465  {
1466  Console.WriteLine("INITIALIZING TEXTURE FILTER");
1467  }
1468  /*
1469 
1470  device.SamplerStates[0].MipFilter = TextureFilter.Linear;
1471  Console.WriteLine("using Linear MipFilter");
1472  device.SamplerStates[0].MinFilter = TextureFilter.Linear;
1473  Console.WriteLine("using Linear MinFilter");
1474  device.SamplerStates[0].MagFilter = TextureFilter.Linear;
1475  Console.WriteLine("using Linear MagFilter");
1476  */
1477  try //not sure it works like this
1478  {
1479  SamplerState stAnisotropic = new SamplerState();
1480  stAnisotropic.Filter = TextureFilter.Anisotropic;
1481  GraphicsDevice.SamplerStates[0] = stAnisotropic;
1482  GraphicsDevice.SamplerStates[1] = stAnisotropic;
1483  GraphicsDevice.SamplerStates[2] = stAnisotropic;
1484  GraphicsDevice.SamplerStates[3] = stAnisotropic;
1485  GraphicsDevice.SamplerStates[4] = stAnisotropic;
1486  /*SamplerState stPoint = new SamplerState();
1487  stPoint.Filter = TextureFilter.Point;
1488  device.SamplerStates[0] = stPoint;*/
1489  }
1490  catch (Exception e)
1491  {
1492  Console.WriteLine("-----------LOOK HERE:" + e);
1493  /*SamplerState stLinear = new SamplerState();
1494  stLinear.Filter = TextureFilter.Linear;
1495  device.SamplerStates[0] = stLinear;*/
1496  }
1497 
1498  }
1499 
1500  #endregion
1501 
1502  //__________________________________________________________________________________________
1503 
1504  #endregion
1505 
1506  #endregion
1507 
1508  #region Control Properties Events
1509  protected override void OnSizeChanged(EventArgs e)
1510  {
1511  if (this.Size.Width != lastSize[0] || this.Size.Height != lastSize[1])
1512  {
1513 
1514  for (int i = 0; i < cameras.Length; i++)
1515  {
1516  lastSize[0] = this.Size.Width;
1517  lastSize[1] = this.Size.Height;
1518  defaultViewport.Width = this.Size.Width;
1519  defaultViewport.Height= this.Size.Height;
1520  setViewports();
1521  cameras[i].SetClientSize = lastSize;
1522 
1523  }
1524  if (debugOutput)
1525  {
1526  Console.WriteLine("Size:" + Size);
1527  }
1528 
1529  }
1530 
1531  GameProperties.Instance.engineState.updateCamera = true;
1532  GameProperties.Instance.engineState.updateData = true;
1533  GameProperties.Instance.engineState.drawData = true;
1534  this.Refresh();
1535  base.OnSizeChanged(e);
1536  }
1537 
1541  private void setViewports()
1542  {
1543  viewports = new Viewport[4];
1544  //top left
1545  viewports[0] = defaultViewport;
1546  viewports[0].X = 0;
1547  viewports[0].Y = 0;
1548  viewports[0].Width = defaultViewport.Width / 2;
1549  viewports[0].Height = defaultViewport.Height / 2;
1550  //top right
1551  viewports[1] = defaultViewport;
1552  viewports[1].X = defaultViewport.Width / 2; ;
1553  viewports[1].Y = 0;
1554  viewports[1].Width = defaultViewport.Width / 2;
1555  viewports[1].Height = defaultViewport.Height / 2;
1556  //bottom left
1557  viewports[2] = defaultViewport;
1558  viewports[2].X = 0;
1559  viewports[2].Y = defaultViewport.Height / 2;
1560  viewports[2].Width = defaultViewport.Width / 2;
1561  viewports[2].Height = defaultViewport.Height / 2;
1562  //bottom right
1563  viewports[3] = defaultViewport;
1564  viewports[3].X = defaultViewport.Width / 2;
1565  viewports[3].Y = defaultViewport.Height / 2;
1566  viewports[3].Width = defaultViewport.Width / 2;
1567  viewports[3].Height = defaultViewport.Height / 2;
1568  }
1569  #endregion
1570  }
1571 }
1572 
1573