UnityMol  0.9.6-875
UnityMol viewer / In developement
DepthCueing.cs
Go to the documentation of this file.
1 
60 using UnityEngine;
61 using System.Collections;
62 using System.Collections.Generic;
63 using UI;
64 using Molecule.Model;
65 
66 
67 public class DepthCueing {
68  private ReadDX readDx;
69  private float[,,] depth;
70  private static Vector3 invDelta;
71  private static Vector3 origin = MoleculeModel.MinValue;
72  private BallUpdate[] balls;
73  private int xDim, yDim, zDim;
74  private float depthAmplitude;
75 
76  private static float OFFSET = 1.0f;
77  private static float MAX_DEPTH = -10.0f;
78  private static List<Color> originalColors;
79 
80  public static bool isEnabled = false;
81  public static bool reset = false;
82  public static float POWER = 2;
83 
84 
88  public DepthCueing() {
89  // We get the ReadDX object and from it, the values we need.
91  depth = readDx._grid;
92  xDim = depth.GetLength(0);
93  yDim = depth.GetLength(1);
94  zDim = depth.GetLength(2);
95 
96  Debug.Log("Dimensions:");
97  Debug.Log(xDim.ToString());
98  Debug.Log(yDim.ToString());
99  Debug.Log(zDim.ToString());
100 
101  Vector3 delta = readDx.GetDelta();
102  invDelta = delta;
103 
104  invDelta.x = 1f/delta.x;
105  invDelta.y = 1f/delta.y;
106  invDelta.z = 1f/delta.z;
107 
108  origin = readDx.GetOrigin();
109 
110  // This is needed to correctly localize things. Unity's convention is different from our input data.
111  origin.x = -origin.x;
112 
113  balls = GameObject.FindObjectsOfType(typeof(BallUpdate)) as BallUpdate[];
114 
115  BuildColorList();
116  DepthCueing.reset = false;
117  }
118 
122  private void BuildColorList() {
123  originalColors = new List<Color>(MoleculeModel.atomsColorList);
124  }
125 
126 
131  private bool InBounds(int x, int y, int z){
132  if(x<0 || y<0 || z<0)
133  return false;
134  else
135  return true;
136  }
137 
141  public void Darken() {
142  int x, y, z;
143  float pointDepth;
144  float depthPercentage;
145  float colorFactor;
146  Vector3 position = Vector3.zero;
147  Vector3 indices = Vector3.zero;
148  foreach(BallUpdate bu in balls) {
149  position = bu.transform.position;
150  indices = Vector3.Scale(invDelta, (position - origin));
151  x = (int)indices.x;
152  x = -x; // Again, the X axis must be flipped.
153  y = (int)indices.y;
154  z = (int)indices.z;
155 
156  pointDepth = depth[x,y,z];
157 
158  if(pointDepth>=0f)
159  continue; // The values that are inside the molecule are negative.
160 
161  pointDepth = pointDepth + OFFSET;
162 
163  if(pointDepth <= MAX_DEPTH)
164  bu.atomcolor = Color.black;
165  else {
166  depthPercentage = Mathf.Abs(pointDepth/MAX_DEPTH);
167  colorFactor = 1f - depthPercentage;
168  colorFactor = Mathf.Pow(colorFactor, 2);
169  //bu.atomcolor = bu.atomcolor * colorFactor * (1.25f + POWER/10f);
170  MoleculeModel.atomsColorList[(int)bu.number] *= colorFactor * (1.25f + POWER/10f);
171  }
172  }
173  BallUpdate.resetColors = true;
174  isEnabled = true;
175  }
176 
180  public void Revert() {
181  Debug.Log("DepthCueing: Reverting to original colors");
183  BallUpdate.resetColors = true;
184  isEnabled = false;
185  }
186 
187 }
static Vector3 origin
Definition: DepthCueing.cs:71
float[,,] depth
Definition: DepthCueing.cs:69
float[,,] _grid
Definition: ReadDX.cs:88
DepthCueing()
Initializes a new instance of the DepthCueing class.
Definition: DepthCueing.cs:88
Vector3 GetDelta()
Definition: ReadDX.cs:103
Definition: ReadDX.cs:77
static float MAX_DEPTH
Definition: DepthCueing.cs:77
float depthAmplitude
Definition: DepthCueing.cs:74
static float POWER
Definition: DepthCueing.cs:82
static bool resetColors
Definition: BallUpdate.cs:73
bool InBounds(int x, int y, int z)
This function is currently not used, but can be useful for debugging, to check whether the index comp...
Definition: DepthCueing.cs:131
Color atomcolor
Definition: BallUpdate.cs:86
void Revert()
Reverts the molecule to its original colors, that is before the Depth Cueing effect was applied...
Definition: DepthCueing.cs:180
long number
Definition: BallUpdate.cs:84
static bool reset
Definition: DepthCueing.cs:81
static bool isEnabled
Definition: DepthCueing.cs:80
Vector3 GetOrigin()
Definition: ReadDX.cs:108
ReadDX readDx
Definition: DepthCueing.cs:68
static List< Color > atomsColorList
The color of each atom.
static Vector3 MinValue
The "smallest" corner of the bounding box that encloses the molecule.
static float OFFSET
Definition: DepthCueing.cs:76
void Darken()
Darkens the molecule.
Definition: DepthCueing.cs:141
static Vector3 invDelta
Definition: DepthCueing.cs:70
static List< Color > originalColors
Definition: DepthCueing.cs:78
BallUpdate[] balls
Definition: DepthCueing.cs:72
void BuildColorList()
Builds the list of the original colors, that is before the Depth Cueing effect is applied...
Definition: DepthCueing.cs:122
Definition: GUIDisplay.cs:66