Ejemplo n.º 1
0
    /// <summary>
    /// Initializes a new instance of the <see cref="DepthCueing"/> class.
    /// </summary>
    public DepthCueing()
    {
        // We get the ReadDX object and from it, the values we need.
        readDx = GUIMoleculeController.readdx;
        depth  = readDx._grid;
        xDim   = depth.GetLength(0);
        yDim   = depth.GetLength(1);
        zDim   = depth.GetLength(2);

        Debug.Log("Dimensions:");
        Debug.Log(xDim.ToString());
        Debug.Log(yDim.ToString());
        Debug.Log(zDim.ToString());

        Vector3 delta = readDx.GetDelta();

        invDelta = delta;

        invDelta.x = 1f / delta.x;
        invDelta.y = 1f / delta.y;
        invDelta.z = 1f / delta.z;

        origin = readDx.GetOrigin();

        // This is needed to correctly localize things. Unity's convention is different from our input data.
        origin.x = -origin.x;

        balls = GameObject.FindObjectsOfType(typeof(BallUpdate)) as BallUpdate[];

        BuildColorList();
        DepthCueing.reset = false;
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Creates the surface objects.
    /// </summary>
    /// <param name='voxels'>
    /// Voxels, i.e. the scalar field used to compute the surface.
    /// </param>
    /// <param name='threshold'>
    /// The threshold on which the isosurface is based.
    /// </param>
    /// <param name='delta'>
    /// Delta parameter from the grid, basically the size of each cell.
    /// </param>
    /// <param name='origin'>
    /// Origin of the grid.
    /// </param>
    /// <param name='colors'>
    /// Colors. Kept from previous implementation, but doesn't do anything here. I'm only
    /// keeping it because I'm not sure what it was used for. --- Alexandre
    /// </param>
    /// <param name='tag'>
    /// Tag for the objects to be created.
    /// </param>
    /// <param name='electro'>
    /// True if this is an electrostatic field isosurface.
    /// </param>
    public static void CreateSurfaceObjects(float[,,] voxels, float threshold, Vector3 delta, Vector3 origin,
                                            Color[] colors, string tag = "SurfaceManager", bool electro = false)
    {
        ELECTRO = electro;
        Debug.Log(ELECTRO.ToString());
        if (ELECTRO)
        {
            ReadDX readDX = UI.GUIMoleculeController.readdx;
            origin = readDX.GetOrigin();
            delta  = readDX.GetDelta();
        }

        InitGenMesh(voxels, threshold, delta, origin, tag);
        SetDims();

        float    bMCTime = Time.realtimeSinceStartup;
        MeshData mData   = MarchingCubes.CreateMesh(VOXELS, 0, XDIM, 0, YDIM, 0, ZDIM);

        Debug.Log("Entire surface contains " + mData.vertices.Length.ToString() + " vertices.");
        float elapsed = 10f * (Time.realtimeSinceStartup - bMCTime);

        Debug.Log("GenerateMesh::MarchingCubes time: " + elapsed.ToString());
        OffsetVertices(mData);

        float         bSmooth       = Time.realtimeSinceStartup;
        AdjacencySets adjacencySets = new AdjacencySets(mData.triangles.Length);

        adjacencySets.AddAllTriangles(mData.triangles);
        SmoothFilter.AdjSetsSmoother(mData, adjacencySets);
        elapsed = Time.realtimeSinceStartup - bSmooth;
        Debug.Log("Smoothing time: " + elapsed.ToString());

        ProperlyCalculateNormals(mData);

        // Necessary for electrostatic fields isosurfaces
        Debug.Log(threshold.ToString());
        if (threshold < 0)
        {
            FlipTriangles(mData);
        }

        Splitting   splitting = new Splitting();
        List <Mesh> meshes    = splitting.Split(mData);

        CreateSurfaceObjects(meshes);
    }
Ejemplo n.º 3
0
    public override void Init()
    {
        // We get the ReadDX object and from it, the values we need.
        readDx  = GUIMoleculeController.readdx;
        density = readDx._grid;
        delta   = readDx.GetDelta();
        origin  = readDx.GetOrigin();

        // This is needed to correctly place the particles.
        origin.x = -origin.x;

        // Getting the bounds and amplitude of the electrostatics field.
        foreach (float f in density)
        {
            if (f > maxCharge)
            {
                maxCharge = f;
            }
            if (f < minCharge)
            {
                minCharge = f;
            }
        }

        // ChargeAmplitude = largest absolute value
        if ((-minCharge) > maxCharge)
        {
            chargeAmplitude = -minCharge;
        }
        else
        {
            chargeAmplitude = maxCharge;
        }

        Debug.Log("Amplitude:");
        Debug.Log(chargeAmplitude.ToString());

        // We get the parent object and a reference to its particle system, so we can control it.
        parentObj = GameObject.FindGameObjectWithTag("Volumetric");
        pSystem   = parentObj.GetComponent <ParticleSystem>();

        // Creating the dynamic particle list, building the static particle array,
        // setting it to the particle system, and enabling the renderer.
        SetParticleSystem();
    }     // End of Init