Esempio n. 1
0
        public static CameraProperties ReadBinaryFile(BinaryReader br)
        {
            CameraProperties cam = new CameraProperties();

            cam.ReadBinary(br);
            return(cam);
        }
Esempio n. 2
0
 public static CameraProperties[] GetSmoothedCameras_Bilateral(CameraProperties[] original, float sigmat, float sigmax)
 {
     CameraProperties[] smoothedcams = new CameraProperties[original.Length];
     for (int i = 0; i < original.Length; i++)
     {
         smoothedcams[i] = SmoothBilateral(original, i, sigmat, sigmax);
     }
     return(smoothedcams);
 }
Esempio n. 3
0
 public static CameraProperties[] GetSmoothedCameras_Gaussian(CameraProperties[] original, float sigmat)
 {
     CameraProperties[] smoothedcams = new CameraProperties[original.Length];
     for (int i = 0; i < original.Length; i++)
     {
         smoothedcams[i] = SmoothGaussian(original, i, sigmat);
     }
     return(smoothedcams);
 }
Esempio n. 4
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));
        }
Esempio n. 5
0
        public void Desync()
        {
            CameraProperties that = SyncToCamera;

            if (that == null)
            {
                return;
            }

            that.Properties.PropertyChanged -= this.Synchronize;
            this.Properties.PropertyChanged -= that.Synchronize;

            that.SyncToCamera = null;
            this.SyncToCamera = null;
        }
Esempio n. 6
0
        public static CameraProperties SmoothGaussian(CameraProperties[] cams, int t0, float sigma)
        {
            int   l    = cams.Length;
            float wsum = 0;
            float ss   = sigma * sigma;

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

            t0 = Math.Max(0, Math.Min(cams.Length - 1, t0));

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

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

                float dtim = (ti - t0);
                float w    = (float)Math.Exp(-dtim * dtim / ss);
                wsum += w;

                t += cam.Target.Val * w;
                r += cam.qrot * w;
                d += cam.dist * w;
            }

            t *= 1.0f / wsum;
            r *= 1.0f / wsum;
            d *= 1.0f / wsum;

            if (t0 < 0 || t0 >= l)
            {
                System.Console.WriteLine("t0 = " + t0 + ", l = " + l);
            }

            return(new CameraProperties(t, r, d, cams[t0].Ortho.Val));
        }
Esempio n. 7
0
        public void Sync(CameraProperties cam)
        {
            if (cam == null || cam == this)
            {
                Desync(); return;
            }
            if (cam == this.SyncToCamera && cam.SyncToCamera == this)
            {
                return;
            }

            Desync();
            cam.Desync();

            this.SyncToCamera = cam;
            cam.SyncToCamera  = this;

            cam.Properties.PropertyChanged  += this.Synchronize;
            this.Properties.PropertyChanged += cam.Synchronize;

            Synchronize(null, null);
        }
Esempio n. 8
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 });
        }
Esempio n. 9
0
        public SnapshotScene(string sPLYFilename, int timeindex, string command, string opts, SnapshotScene prev, bool nochange, bool cmdobjlist)
        {
            this.file      = MiscFileIO.GetFileNameOnly(sPLYFilename);
            this.timeindex = timeindex;
            this.command   = command;
            this.opts      = opts;
            this.prevscene = prev;

            cselected = 0;
            cedited   = 0;

            string[] objnames;
            bool[]   objvisibles;
            bool[]   objselecteds;
            bool[]   objactives;
            bool[]   objedits;
            string[] objplyfilenames;

            using (Stream s = new FileStream(sPLYFilename, FileMode.Open))
            {
                string plyline = FileIOFunctions.ReadTextString(s);
                if (plyline != "ply")
                {
                    throw new ArgumentException("SnapshotScene: Specified file is not .ply file");
                }

                ncameras = 0;
                nmodels  = 0;
                bool header = true;
                while (header)
                {
                    string cmd = FileIOFunctions.ReadTextString(s);
                    switch (cmd)
                    {
                    case "format":
                    case "property":
                        while (s.ReadByte() != 10)
                        {
                            ;                            // ignore the rest of the line
                        }
                        break;

                    case "comment":
                        string str = FileIOFunctions.ReadTextLine(s);
                        if (str.StartsWith("Created"))
                        {
                            switch (str.Split(new char[] { ' ' })[2])
                            {
                            case "Blender": ApplicationType = ApplicationTypes.BLENDER; break;
                            }
                        }
                        break;

                    case "element":
                        string variable = FileIOFunctions.ReadTextString(s);
                        int    val      = FileIOFunctions.ReadTextInteger(s);
                        switch (variable)
                        {
                        case "views": ncameras = val; break;

                        case "objects": nmodels = val; break;

                        default: throw new Exception("SnapshotScene: Unhandled element type " + variable);
                        }
                        break;

                    case "end_header": header = false; break;

                    default: throw new Exception("SnapshotScene: Unhandled command type " + cmd);
                    }
                }

                if (ApplicationType == ApplicationTypes.UNKNOWN)
                {
                    throw new Exception("SnapshotScene: PLY was created by an unknown application");
                }

                cameras = new CameraProperties[ncameras];
                for (int i = 0; i < ncameras; i++)
                {
                    // read viewing info
                    Vec3f  loc = new Vec3f(FileIOFunctions.ReadTextFloat(s), FileIOFunctions.ReadTextFloat(s), FileIOFunctions.ReadTextFloat(s));
                    float  w   = FileIOFunctions.ReadTextFloat(s);
                    float  x   = FileIOFunctions.ReadTextFloat(s);
                    float  y   = FileIOFunctions.ReadTextFloat(s);
                    float  z   = FileIOFunctions.ReadTextFloat(s);
                    Quatf  qua = (new Quatf(w, x, y, z)).Normalize();
                    float  dis = FileIOFunctions.ReadTextFloat(s);
                    String per = FileIOFunctions.ReadTextString(s);
                    cameras[i] = new CameraProperties(loc, qua, dis, (per == "ORTHO"));
                }

                int istart = 0, iend = 0, iinc = 0;
                switch (ApplicationType)
                {
                case ApplicationTypes.BLENDER:              // blender writes list of objects "backwards"; new objects are at beginning of list!
                    istart = nmodels - 1;
                    iend   = 0;
                    iinc   = -1;
                    break;

                default: throw new Exception("SnapshotScene: Unimplemented ApplicationType");
                }

                objnames        = new string[nmodels];
                objvisibles     = new bool[nmodels];
                objselecteds    = new bool[nmodels];
                objactives      = new bool[nmodels];
                objedits        = new bool[nmodels];
                objplyfilenames = new string[nmodels];

                for (int i = istart; i != iend + iinc; i += iinc)
                {
                    objnames[i]        = FileIOFunctions.ReadTextQuotedString(s);
                    objvisibles[i]     = (FileIOFunctions.ReadTextInteger(s) == 1);
                    objselecteds[i]    = (FileIOFunctions.ReadTextInteger(s) == 1);
                    objactives[i]      = (FileIOFunctions.ReadTextInteger(s) == 1);
                    objedits[i]        = (FileIOFunctions.ReadTextInteger(s) == 1);
                    objplyfilenames[i] = FileIOFunctions.ReadTextString(s);

                    if (objselecteds[i])
                    {
                        cselected++;
                    }
                    if (objedits[i])
                    {
                        cedited++;
                    }
                }
            }

            if (cedited > 1)
            {
                throw new Exception("more than one object being edited");
            }

            bool loadall = (prev == null || cmdobjlist);                // need to load every object?

            models       = new SnapshotModel[nmodels];
            modelscached = new SnapshotModel[nmodels];
            SnapshotModel[] pmodels = null;
            if (prev != null)
            {
                pmodels = prev.Models;
            }
            for (int i = 0; i < nmodels; i++)
            {
                bool prevsel = !cmdobjlist && (pmodels != null && pmodels[i] != null && pmodels[i].objselected);
                if (loadall || (objselecteds[i] && !nochange) || objselecteds[i] != prevsel || pmodels == null || pmodels[i] == null)
                {
                    models[i]             = new SnapshotModel(objplyfilenames[i]);
                    models[i].objind      = i;
                    models[i].objname     = objnames[i];
                    models[i].objvisible  = objvisibles[i];
                    models[i].objselected = objselecteds[i];
                    models[i].objactive   = objactives[i];
                    models[i].objedit     = objedits[i];
                    modelscached[i]       = models[i];
                }
                else
                {
                    models[i]       = null;
                    modelscached[i] = pmodels[i];
                }
            }
        }
Esempio n. 10
0
 public void Set(CameraProperties camera)
 {
     Set(camera.GetTarget(), camera.GetRotation(), camera.GetDistance(), camera.GetOrtho());
 }