Ejemplo n.º 1
0
        public static CameraProperties SmoothBilateral(CameraProperties[] cams, int t0, float sigmatime, float sigmax)
        {
            int   l         = cams.Length;
            float wsumt     = 0;
            float wsumr     = 0;
            float wsumd     = 0;
            float sigtimesq = sigmatime * sigmatime;
            float sigxsq    = sigmax * sigmax;

            Vec3f tar0 = cams[t0].GetTarget();
            Quatf rot0 = cams[t0].qrot;
            float dis0 = cams[t0].dist;

            Vec3f t = new Vec3f();
            Quatf r = new Quatf(0, 0, 0, 0);
            float d = 0;

            // window to ~99%
            float siglg = Math.Max(sigmatime, sigmax);
            int   s     = Math.Max(0, (int)((float)t0 - siglg * 3.0f));
            int   e     = Math.Min(l - 1, (int)((float)t0 + siglg * 3.0f));

            for (int ti = s; ti <= e; ti++)
            {
                CameraProperties cam = cams[ti];

                float dtim = (ti - t0);
                float dtar = (cam.GetTarget() - tar0).Length;
                float drot = (cam.qrot - rot0).Length;
                float ddis = (cam.dist - dis0);

                float wg = (float)Math.Exp(-dtim * dtim / sigtimesq);
                float wt = wg * (float)Math.Exp(-dtar * dtar / sigxsq);
                float wr = wg * (float)Math.Exp(-drot * drot / sigxsq);
                float wd = wg * (float)Math.Exp(-ddis * ddis / sigxsq);

                wsumt += wt;
                wsumr += wr;
                wsumd += wd;

                t += cam.Target.Val * wt;
                r += cam.qrot * wr;
                d += cam.dist * wd;
            }

            t *= 1.0f / wsumt;
            r *= 1.0f / wsumr;
            d *= 1.0f / wsumd;

            return(new CameraProperties(t, r, d, cams[t0].Ortho.Val));
        }
Ejemplo n.º 2
0
        public CameraProperties[] GetCameras()
        {
            ModelingHistory history = ModelingHistory.history;

            CameraProperties artist   = null;
            CameraProperties bestview = null;

            Vec3f tar   = new Vec3f();
            Quatf rot   = new Quatf();
            float dist  = 0.0f;
            float ortho = 0.0f;

            List <Vec3f> selverts = new List <Vec3f>();
            Vec3f        anorm    = new Vec3f();

            foreach (int isnapshot in snapshots)
            {
                SnapshotScene    scene = history[isnapshot];
                CameraProperties cam   = scene.GetCamera();

                tar   += cam.GetTarget();
                rot   += cam.GetRotation();
                dist  += cam.GetDistance();
                ortho += (cam.GetOrtho() ? 1.0f : 0.0f);

                foreach (SnapshotModel model in scene.GetSelectedModels())
                {
                    Vec3f[] verts  = model.GetVerts();
                    Vec3f[] vnorms = model.GetVertNormals();
                    foreach (int ind in model.selinds)
                    {
                        selverts.Add(verts[ind]); anorm += vnorms[ind];
                    }
                }
            }

            int nsnapshots = snapshots.Count;

            if (nsnapshots == 0)
            {
                rot  = new Quatf(0.5f, -0.5f, -0.5f, -0.5f);
                dist = 10.0f;
                System.Console.WriteLine("Cluster with no snapshots " + start + ":" + end);
            }
            else
            {
                tar   /= (float)nsnapshots;
                rot   /= (float)nsnapshots;
                dist  /= (float)nsnapshots;
                ortho /= (float)nsnapshots;
            }

            artist = new CameraProperties(tar, rot, dist, (ortho >= 0.5f))
            {
                Name = "Artist"
            };

            bestview = artist;

            return(new CameraProperties[] { artist, bestview });
        }
Ejemplo n.º 3
0
 public void Set(CameraProperties camera)
 {
     Set(camera.GetTarget(), camera.GetRotation(), camera.GetDistance(), camera.GetOrtho());
 }