コード例 #1
0
        //------------------------------------------------------------------------------
        void Segment(ref List <Surface> SC, ref List <ModelBase> m)
        {
            if (leafCount > SurfaceController._MINNODESURF)
            {
                int trails = 1;

                ModelBase[] candidateLst = new ModelBase[4];
                ModelBase   TopModel     = null;

                int    nm      = 0; // number of models under test
                int    topsz   = 0;
                int    topflag = 0;
                int[]  contiq;
                int    topValidCount = 0;
                double prob          = 0.0d;

                while (
                    (prob < SurfaceController._RANSACPROB) &&
                    (Surface.RansacPEqN(trails, leafCount) < SurfaceController._RANSACPROB) &&
                    (trails < SurfaceController._RANSACPNUM)
                    )
                {
                    Vectors[] pts  = new Vectors[SurfaceController._MSSETSIZE];
                    Vectors[] ptsN = new Vectors[SurfaceController._MSSETSIZE];
                    for (int i = 0; i < SurfaceController._MSSETSIZE; i++)
                    {
                        int k = C.CONST.iRANDOM(0, leafCount - 1);
                        pts[i]  = _leafs[k].Sigma;
                        ptsN[i] = _leafs[k].Norm;
                    }

                    candidateLst[0] = new ModelPlane(pts, ptsN);
                    //candidateLst[0].Initialize() ;
                    if (candidateLst[0].Initialize())
                    {
                        // plane could fit the  data
                        nm++;
                    }
                    if (nm == 0)
                    {
                        // create other canidates
                        candidateLst[nm] = new ModelCylinder(pts, ptsN);
                        if (candidateLst[nm].Initialize())
                        {
                            nm++;
                        }
                        candidateLst[nm] = new ModelCone(pts, ptsN);
                        if (candidateLst[nm].Initialize())
                        {
                            nm++;
                        }
                        candidateLst[nm] = new ModelSphere(pts, ptsN);
                        if (candidateLst[nm].Initialize())
                        {
                            nm++;
                        }
                    }

                    // test models
                    while (nm > 0)
                    {
                        nm--;
                        int ValidCount = candidateLst[nm].Eval(_leafs);
                        if (ValidCount > SurfaceController._MINNODESURF)
                        {
                            if (ValidCount > topsz)
                            {
                                candidateLst[nm].refine(_leafs, true);
                                ValidCount = candidateLst[nm].Eval(_leafs);
                                FlagSubset(out contiq, null);
                                if (contiq[contiq[0]] > topsz)
                                {
                                    topValidCount = ValidCount;
                                    TopModel      = candidateLst[nm];
                                    topflag       = contiq[0];
                                    topsz         = contiq[topflag];
                                }
                            } //if ValidCount>topsz
                        }
                    }         //while nm > 0



                    trails++;

                    if (TopModel != null)
                    {
                        prob = TopModel.probabillity4(trails, topsz, topValidCount, this._leafs.Count);
                    }
                }// while nm > 0

                if (TopModel != null)
                {
                    // recompute largest subset
                    TopModel.Eval(Leafs);

                    FlagSubset(out contiq, null);
                    int flag = contiq[0];

                    split(flag, ref SC);

                    TopModel.refine(Leafs, false);
                    m.Add(TopModel);
                } // if TopModel
            }     // if leafscount> minsurf
        }