Esempio n. 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);
        }
Esempio n. 2
0
        void computeSynthNeighborhoods()
        {
            ScopeTimer tm = new ScopeTimer("[computeSynthNeighborhoods]");

            m_SynthNeighborhoods = new NeighborhoodSynth[mNumLevels][];

            // foreach level
            for (int level = 0; level < mNumLevels; level++)
            {
                MultiDimFloatTexture recolored_level = null;

                if (Globals.isDefined("4D"))
                {
                    // . keep only 4 dimension from recolored exemplar
                    MultiDimFloatTexture level_4D = new MultiDimFloatTexture(mOwner.recoloredStack(level).width(), mOwner.recoloredStack(level).height(), mOwner.recoloredStack(level).numComp());
                    int w = level_4D.getWidth();
                    int h = level_4D.getHeight();
                    Globals.Assert(w == mOwner.stack(level).getWidth() && h == mOwner.stack(level).height());
                    Globals.Assert(level_4D.numComp() == Globals.NUM_RECOLORED_PCA_COMPONENTS);
                    for (int i = 0; i < w; i++)
                    {
                        for (int j = 0; j < h; j++)
                        {
                            // . copy first four channels
                            for (int c = 0; c < 4; c++)
                            {
                                level_4D.set(mOwner.recoloredStack(level).get(i, j, c), i, j, c);
                            }
                            // . zero out all channels above 4
                            for (int c = 4; c < level_4D.numComp(); c++)
                            {
                                level_4D.set(0, i, j, c);
                            }
                        }
                    }
                    recolored_level = level_4D;
                }
                else
                {
                    // . keep all dimensions
                    recolored_level = mOwner.recoloredStack(level);
                }

                m_SynthNeighborhoods[level] = new NeighborhoodSynth[recolored_level.width() * recolored_level.height()];

                stack_accessor_v2 access = new stack_accessor_v2(level);


                for (int j = 0; j < recolored_level.height(); j++)
                {
                    for (int i = 0; i < recolored_level.width(); i++)
                    {
                        int index = i + j * recolored_level.width();
                        m_SynthNeighborhoods[level][index] = new NeighborhoodSynth();
                        m_SynthNeighborhoods[level][index].construct(
                            recolored_level,
                            access,
                            (!mOwner.isToroidal()) && level < (mNumLevels - Globals.NUM_LEVELS_WITHOUT_BORDER),
                            //(!m_bToroidal) && l < FIRST_LEVEL_WITH_BORDER,
                            level, i, j);
                    }
                }
            }

            tm.destroy();
            tm = null;
        }