Esempio n. 1
0
    /*
     *  Create nested grid vorticity influence tree.
     *
     *  Each layer of this tree represents a simplified, aggregated version of
     *  all of the information in its "child" layer, where each
     *  "child" has higher resolution than its "parent".
     *
     *  Derivation:
     *
     *  Using conservation properties, I_0 = I_0' , I_1 = I_1' , I_2 = I_2'
     *
     *  I_0 : wx d = w1x d1 + w2x d2
     *      : wy d = w1y d1 + w2y d2
     *      : wz d = w1z d1 + w2z d2
     *
     *  These 3 are not linearly independent:
     *  I_1 : ( y wz - z wy ) d = ( y1 wz1 - z1 wy1 ) d1 + ( y2 wz2 - z2 wy2 ) d2
     *      : ( z wx - x wz ) d = ( z1 wx1 - x1 wz1 ) d1 + ( z2 wx2 - x2 wz2 ) d2
     *      : ( x wy - y wx ) d = ( x1 wy1 - y1 wx1 ) d1 + ( x2 wy2 - y2 wx2 ) d2
     *
     *  I_2 : ( x^2 + y^2 + z^2 ) wx d = (x1^2 + y1^2 + z1^2 ) wx1 d1 + ( x2^2 + y2^2 + z2^2 ) wx2 d2
     *      : ( x^2 + y^2 + z^2 ) wy d = (x1^2 + y1^2 + z1^2 ) wy1 d1 + ( x2^2 + y2^2 + z2^2 ) wy2 d2
     *      : ( x^2 + y^2 + z^2 ) wz d = (x1^2 + y1^2 + z1^2 ) wz1 d1 + ( x2^2 + y2^2 + z2^2 ) wz2 d2
     *
     *  Can replace I_2 with its magnitude:
     *        ( x^2  + y^2  + z^2  ) ( wx^2  + wy^2  + wz^2  )^(1/2) d
     *      = ( x1^2 + y1^2 + z1^2 ) ( wx1^2 + w1y^2 + w1z^2 )^(1/2) d1
     + ( x2^2 + y2^2 + z2^2 ) ( wx2^2 + w2y^2 + w2z^2 )^(1/2) d2
     */
    void CreateInfluenceTree()
    {
        FindBoundingBox(); // Find axis-aligned bounding box that encloses all vortons and tracers.

        // Create skeletal nested grid for influence tree.
        float numElements;

        int numVortons = mVortons.Count;

        numElements = numVortons; // Default approach. Loss of precission when adding tracers... but fast.

        //float boundingBoxVolume = (mMaxCorner - mMinCorner).x * (mMaxCorner - mMinCorner).y * (mMaxCorner - mMinCorner).z;
        //float vortonVolume = 4 * (1.0f / 3.0f) * Mathf.PI *
        //    (mVortons[0].radius * mVortons[0].radius * mVortons[0].radius);
        ////Accurate approach that maintains precission.Very Slow.
        //numElements = boundingBoxVolume / vortonVolume;

        {
            UniformGrid <Vorton> ugSkeleton = new UniformGrid <Vorton>(); ///< Uniform grid with the same size & shape as the one holding aggregated information about mVortons.
            ugSkeleton.DefineShape((uint)numElements, mMinCorner, mMaxCorner, true);
            mInfluenceTree.Initialize(ugSkeleton);                        // Create skeleton of influence tree.
        }

        MakeBaseVortonGrid();

        int numLayers = mInfluenceTree.GetDepth();

        for (uint uParentLayer = 1; uParentLayer < numLayers; ++uParentLayer)
        {   // For each layer in the influence tree...
            AggregateClusters(uParentLayer);
        }
    }