示例#1
0
        int computeStackLevels_Box(MultiDimFloatTexture tex, ref MultiDimFloatTexture[] _lvls)
        {
            List <MultiDimFloatTexture> tmplvls = new List <MultiDimFloatTexture>();

            // compute stack of averages on large texture
            // . add unmodifed finest level
            tmplvls.Clear();
            tmplvls.Add(tex);
            int l = 0;

            MultiDimFloatTexture lvl = tex;

            float [] lvlDat = lvl.getData();
            int      num    = (int)(0.01 + BMathLib.log2((float)lvl.getWidth()));

            do                                                       // TODO: speed this up - extremely unefficient !!! (not critical though)
            {
                stack_accessor_v2 access = new stack_accessor_v2(l); // l is destination level for children
                                                                     // (children *are* at level l)

                MultiDimFloatTexture stackl = new MultiDimFloatTexture(lvl.getWidth(), lvl.getHeight(), lvl.numComp());

                List <float> avg = new List <float>();
                for (int q = 0; q < lvl.numComp(); q++)
                {
                    avg.Add(0);
                }

                for (int i = 0; i < stackl.getWidth(); i++)
                {
                    for (int j = 0; j < stackl.getHeight(); j++)
                    {
                        for (int q = 0; q < avg.Count; q++)
                        {
                            avg[q] = 0;
                        }

                        for (int li = 0; li < 2; li++)
                        {
                            for (int lj = 0; lj < 2; lj++)
                            {
                                int ci = 0, cj = 0;
                                access.child_ij(i, j, li, lj, ref ci, ref cj);
                                //CLM large amount of modification here.. check back w/ origional if problems occur
                                if (ci < 0 || ci >= lvl.getWidth() ||
                                    cj < 0 || cj >= lvl.getHeight())
                                {
                                    continue;
                                }

                                int idx = lvl.getpixmodIndex(ci, cj);
                                for (int c = 0; c < stackl.numComp(); c++)
                                {
                                    avg[c] += lvlDat[idx + c];
                                }
                            }
                        }


                        int opix = stackl.getpixIndex(i, j);
                        for (int c = 0; c < stackl.numComp(); c++)
                        {
                            stackl.getData()[opix + c] = avg[c] / 4.0f;
                        }
                    }
                }

                lvl = stackl;
                tmplvls.Add(lvl);
                l++;
            }  while ((1 << l) <= lvl.getWidth());

            // clamp stack
            int w = tex.getWidth() / 2;
            int h = tex.getHeight() / 2;

            _lvls = new MultiDimFloatTexture[m_iNbLevels];

            l = 0;
            int sz = w;

            for (int i = 0; i < tmplvls.Count; i++)
            {
                MultiDimFloatTexture ktex    = tmplvls[i];
                MultiDimFloatTexture clamped = ktex.extract(w / 2, h / 2, w, h);
                _lvls[i] = clamped;

                l++;
                sz >>= 1;
                if (sz < 1)
                {
                    break;
                }
            }

            for (int i = 0; i < tmplvls.Count; i++)
            {
                tmplvls[i] = null;
            }

            tmplvls.Clear();

            return((int)_lvls.Length);
        }