예제 #1
0
파일: FaultSkin.cs 프로젝트: Veggie13/ipf
        /**
         * Smooths multiple values stored in the cells of this skin. The values
         * smoothed are those accessed by the specified getter and setter. Each
         * smoothed value is an average of the values in a cell and its cell nabors.
         */
        void smoothN(FaultCell.GetN getter, FaultCell.SetN setter)
        {
            int ncell = size();
            int nval  = getter(_seed).Length;

            float[][] vals = new float[ncell][];
            for (int xxx = 0; xxx < ncell; xxx++)
            {
                vals[xxx] = new float[nval];
            }
            float[]     cnts       = new float[ncell];
            FaultCell[] cellNabors = new FaultCell[4];
            for (int icell = 0; icell < ncell; ++icell)
            {
                FaultCell cell     = _cellList[icell];
                float[]   valsCell = getter(cell);
                cellNabors[0] = cell.ca;
                cellNabors[1] = cell.cb;
                cellNabors[2] = cell.cl;
                cellNabors[3] = cell.cr;
                foreach (FaultCell cellNabor in cellNabors)
                {
                    if (cellNabor != null)
                    {
                        float[] valsNabor = getter(cellNabor);
                        for (int ival = 0; ival < nval; ++ival)
                        {
                            vals[icell][ival] += valsCell[ival] + valsNabor[ival];
                        }
                        cnts[icell] += 2.0f;
                    }
                }
            }
            for (int icell = 0; icell < ncell; ++icell)
            {
                FaultCell cell = _cellList[icell];
                float     cnti = cnts[icell];
                float     scli = 1.0f / (cnti > 0.0f ? cnti : 1.0f);
                for (int ival = 0; ival < nval; ++ival)
                {
                    vals[icell][ival] *= scli;
                }
                setter(cell, vals[icell]);
            }
        }
예제 #2
0
파일: FaultSkin.cs 프로젝트: Veggie13/ipf
 /**
  * Smooths the normal vectors of cells in this skin.
  * @param nsmooth the number of smoothings.
  */
 public void smoothCellNormals(int nsmooth)
 {
     FaultCell.GetN getter = (FaultCell cell) => new float[] { cell.w1, cell.w2, cell.w3 };
     FaultCell.SetN setter = (FaultCell cell, float[] w) =>
     {
         float w1 = w[0];
         float w2 = w[1];
         float w3 = w[2];
         float ws = 1.0f / (float)Math.Sqrt(w1 * w1 + w2 * w2 + w3 * w3);
         w1 *= ws;
         w2 *= ws;
         w3 *= ws;
         cell.setNormalVector(w1, w2, w3);
     };
     for (int ismooth = 0; ismooth < nsmooth; ++ismooth)
     {
         smoothN(getter, setter);
     }
 }