UnityMol  0.9.6-875
UnityMol viewer / In developement
VolumetricDepth.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using System.Collections;
3 using UI;
4 using Molecule.Model;
5 
6 public class VolumetricDepth : Volumetric {
7 // private float maxDepth = - float.MaxValue;
8  private float minDepth = float.MaxValue;
9  private float depthAmplitude;
10 
11  private ReadDX readDx;
12 
13 
14  public override void Init() {
15  // We get the ReadDX object and from it, the values we need.
17  density = readDx._grid;
18  delta = readDx.GetDelta();
19  origin = readDx.GetOrigin();
20 
21  // This is needed to correctly place the particles.
22  origin.x = -origin.x;
23 
24  // Getting the bounds and amplitude of the electrostatics field.
25  foreach(float f in density) {
26  //if(f > maxDepth)
27  // maxDepth = f;
28  if(f < minDepth)
29  minDepth = f;
30  }
31 
32  // DepthAmplitude = largest absolute value
33  //if ( (-minDepth) > maxDepth)
34  // depthAmplitude = -minDepth;
35  //else
36  // depthAmplitude = maxDepth;
37 
38  depthAmplitude = Mathf.Abs(minDepth);
39 
40  Debug.Log("Amplitude:");
41  Debug.Log(depthAmplitude.ToString());
42 
43  // Creating the dynamic particle list, building the static particle array,
44  // setting it to the particle system, and enabling the renderer.
46  } // End of Init
47 
48  public override void CreatePoints() {
49  // Getting the size of the density grid.
50  int dim0 = density.GetLength(0);
51  int dim1 = density.GetLength(1);
52  int dim2 = density.GetLength(2);
53 
54  Vector3 indices = Vector3.zero;
55 
56  for(int x=0; x<dim0; x++) {
57  for(int y=0; y<dim1; y++) {
58  for(int z=0; z<dim2; z++) {
59  indices.x = -x;
60  indices.y = y;
61  indices.z = z;
62 
63  float depth = density[x,y,z];
64  Color c = Color.red; // if we see a red particle, something is wrong, they should be discared.
65  if(depth < 0)
66  c = Color.black;
67  c.a = 2.5f * Mathf.Abs((depth / depthAmplitude)); // Somewhat arbitrary, but guarantees 0 <= c.a <= 1.
68  if(raise) {
69  c.a = c.a * ALPHA_FACTOR;
70  if (c.a > 1f)
71  c.a = 1f;
72  }
73 
74  // Here, we cull.
75  if ( (c.a > ALPHA_THRESHOLD) && (depth <0) ) {
76  ParticleSystem.Particle particle = new ParticleSystem.Particle();
77  Vector3 p = new Vector3(0f,0f,0f);
78  p = origin + Vector3.Scale(indices, delta);
79  particle.position = p;
80  particle.startColor = c;
81  //Debug.Log(particle.color);
82  //pSystem.renderer.material.color = c;
83  //particle.size = particleScale;
84  particle.startSize = delta.x * 2.8f;
85  dynPoints.Add(particle);
86  }
87  }
88  }
89  }
90  } // End of CreatePoints
91 }
float ALPHA_THRESHOLD
Definition: Volumetric.cs:72
float[,,] _grid
Definition: ReadDX.cs:88
Vector3 GetDelta()
Definition: ReadDX.cs:103
Definition: ReadDX.cs:77
List< ParticleSystem.Particle > dynPoints
Definition: Volumetric.cs:80
void SetParticleSystem()
Sets the particle system.
Definition: Volumetric.cs:140
override void Init()
Initializes this instance.
Vector3 GetOrigin()
Definition: ReadDX.cs:108
static Vector3 delta
Definition: Volumetric.cs:82
float[,,] density
Definition: Volumetric.cs:77
float ALPHA_FACTOR
Definition: Volumetric.cs:75
override void CreatePoints()
Creates the points for this particle system.
Definition: GUIDisplay.cs:66
static Vector3 origin
Definition: Volumetric.cs:83