Beispiel #1
0
        // ProjectiveCamera Public Methods
        protected ProjectiveCamera(
            AnimatedTransform cameraToWorld,
            Transform cameraToScreen,
            Bounds2D screenWindow,
            double shutterOpen,
            double shutterClose,
            double lensr,
            double focald,
            Film film,
            Medium medium)
            : base(cameraToWorld, shutterOpen, shutterClose, film, medium)
        {
            CameraToScreen = cameraToScreen;
            // Initialize depth of field parameters
            LensRadius    = lensr;
            FocalDistance = focald;

            // Compute projective camera transformations

            // Compute projective camera screen transformations
            ScreenToRaster = Transform.Scale(film.FullResolution.X, film.FullResolution.Y, 1) * Transform.Scale(
                1 / (screenWindow.MaxPoint.X - screenWindow.MinPoint.X),
                1 / (screenWindow.MinPoint.Y - screenWindow.MaxPoint.Y),
                1) * Transform.Translate(new Vector3D(-screenWindow.MinPoint.X, -screenWindow.MaxPoint.Y, 0));
            RasterToScreen = ScreenToRaster.Inverse();
            RasterToCamera = CameraToScreen.Inverse() * RasterToScreen;
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //Matrix4x4 m1 = new Matrix4x4(-0.0198209956f, -0.328598410f, -0.944261789f, 396.734772f, -0.999803603f, 0.00651442632f, 0.0187198818f, 54.7861862f, 0.000000000f, 0.944447339f, -0.328662962f, 30.0000000f, 0, 0, 0, 1);
            //Matrix4x4 m2 = new Matrix4x4(-0.0198209956f, -0.328598410f, -0.944261789f, 396.734772f, -0.999803603f, 0.00651442632f, 0.0187198818f, 54.7861862f, 0.000000000f, 0.944447339f, -0.328662962f, 30.0000000f, 0, 0, 0, 1);
            //Matrix4x4 m3 = LR.Multiply(m1, m2);
            //Transform t = new Transform(m1);
            //Transform t2 = LR.Multiply(LR.Scale(10, 10, 10), t);

            Transform         t11      = new Transform(new Matrix4x4(-0.0198209956f, -0.328598410f, -0.944261789f, 396.734772f, -0.999803603f, 0.00651442632f, 0.0187198818f, 54.7861862f, 0.000000000f, 0.944447339f, -0.328662962f, 30.0000000f, 0, 0, 0, 1));
            Transform         t22      = new Transform(new Matrix4x4(-0.0198209956f, -0.328598410f, -0.944261789f, 396.734772f, -0.999803603f, 0.00651442632f, 0.0187198818f, 54.7861862f, 0.000000000f, 0.944447339f, -0.328662962f, 30.0000000f, 0, 0, 0, 1));
            AnimatedTransform cam2word = new AnimatedTransform(t11, 0, t22, 1);

            float[] screen = new float[4] {
                -1, 1, -1, 1
            };
            Film film = new Film();

            film.xResolution = 700;
            film.yResolution = 700;
            OrthoCamera  orthoCamera  = new OrthoCamera(cam2word, screen, 0, 1, 0, 0, film);
            CameraSample cameraSample = new CameraSample(689.738220f, 678.709778f, 0.559352338f, 0.253510952f, 0.562246382f);

            //cameraSample.imageX = 689.738220f;
            RayDifferential rd;

            orthoCamera.GenerateRayDifferential(cameraSample, out rd);
        }
Beispiel #3
0
 protected Camera(AnimatedTransform cameraToWorld,
                  float shutterOpen, float shutterClose,
                  Film film)
 {
     _cameraToWorld = cameraToWorld;
     _shutterOpen   = shutterOpen;
     _shutterClose  = shutterClose;
     _film          = film;
 }
Beispiel #4
0
 public PerspectiveCamera(
     AnimatedTransform cameraToWorld, float[] screenWindow,
     float shutterOpen, float shutterClose,
     float lensRadius, float focalDistance,
     float fieldOfView,
     Film film)
     : base(cameraToWorld, Transform.Perspective(fieldOfView, 1e-2f, 1000.0f), screenWindow, shutterOpen, shutterClose, lensRadius, focalDistance, film)
 {
     // Compute differential changes in origin for perspective camera rays
     _dxCamera = RasterToCamera.TransformPoint(new Point(1, 0, 0)) - RasterToCamera.TransformPoint(new Point(0, 0, 0));
     _dyCamera = RasterToCamera.TransformPoint(new Point(0, 1, 0)) - RasterToCamera.TransformPoint(new Point(0, 0, 0));
 }
Beispiel #5
0
        public static Camera Create(ParamSet paramSet, AnimatedTransform cam2World, Film film, Medium medium)
        {
            // Extract common camera parameters from _ParamSet_
            double shutteropen  = paramSet.FindOneFloat("shutteropen", 0.0);
            double shutterclose = paramSet.FindOneFloat("shutterclose", 1.0);

            if (shutterclose < shutteropen)
            {
                //Warning("Shutter close time [%f] < shutter open [%f].  Swapping them.",
                //        shutterclose, shutteropen);

                PbrtMath.Swap(ref shutterclose, ref shutteropen);
            }
            double lensradius    = paramSet.FindOneFloat("lensradius", 0.0);
            double focaldistance = paramSet.FindOneFloat("focaldistance", 1e6);
            double frame         = paramSet.FindOneFloat(
                "frameaspectratio",
                Convert.ToDouble(film.FullResolution.X) / Convert.ToDouble(film.FullResolution.Y));
            Bounds2D screen;

            if (frame > 1.0)
            {
                screen = new Bounds2D(new Point2D(-frame, -1.0), new Point2D(frame, 1.0));
            }
            else
            {
                screen = new Bounds2D(new Point2D(-1.0, -1.0 / frame), new Point2D(1.0, 1.0 / frame));
            }
            double[] sw = paramSet.FindFloat("screenwindow");
            if (sw != null)
            {
                if (sw.Length == 4)
                {
                    screen = new Bounds2D(new Point2D(sw[0], sw[2]), new Point2D(sw[1], sw[3]));
                }
                else
                {
                    //Error("\"screenwindow\" should have four values");
                }
            }
            double fov     = paramSet.FindOneFloat("fov", 90.0);
            double halffov = paramSet.FindOneFloat("halffov", -1.0);

            if (halffov > 0.0)
            {
                // hack for structure synth, which exports half of the full fov
                fov = 2.0 * halffov;
            }

            return(new PerspectiveCamera(cam2World, screen, shutteropen, shutterclose,
                                         lensradius, focaldistance, fov, film, medium));
        }
Beispiel #6
0
        public static Camera MakeCamera(
            string name,
            ParamSet paramSet,
            TransformSet cam2worldSet,
            double transformStart,
            double transformEnd,
            Film film)
        {
            Camera          camera          = null;
            MediumInterface mediumInterface = new MediumInterface(); // todo: implement graphicsState graphicsState.CreateMediumInterface();

            //static_assert(MaxTransforms == 2,
            //              "TransformCache assumes only two transforms");
            Transform[] cam2world = new Transform[]
            {
                // todo: implement transform cache
                //transformCache.Lookup(cam2worldSet[0]),
                //transformCache.Lookup(cam2worldSet[1])
                cam2worldSet[0],
                cam2worldSet[1]
            };

            AnimatedTransform animatedCam2World = new AnimatedTransform(
                cam2world[0],
                transformStart,
                cam2world[1],
                transformEnd);

            switch (name)
            {
            case "perspective":
                camera = PerspectiveCamera.Create(paramSet, animatedCam2World, film, mediumInterface.Outside);
                break;

            //case "orthographic":
            //  camera = CreateOrthographicCamera(paramSet, animatedCam2World, film, mediumInterface.Outside);
            //  break;
            //case "realistic":
            //  camera = CreateRealisticCamera(paramSet, animatedCam2World, film, mediumInterface.Outside);
            //  break;
            //case "environment":
            //  camera = CreateEnvironmentCamera(paramSet, animatedCam2World, film, mediumInterface.Outside);
            //  break;
            default:
                //Warning("Camera \"%s\" unknown.", name.c_str());
                break;
            }

            paramSet.ReportUnused();
            return(camera);
        }
Beispiel #7
0
        protected ProjectiveCamera(AnimatedTransform cameraToWorld, Transform cameraToScreen,
                                   float[] screenWindow, float shutterOpen, float shutterClose,
                                   float lensRadius, float focalDistance, Film film)
            : base(cameraToWorld, shutterOpen, shutterClose, film)
        {
            _cameraToScreen = cameraToScreen;
            _lensRadius     = lensRadius;
            _focalDistance  = focalDistance;

            // Compute projective camera screen transformations
            _screenToRaster = Transform.Scale(film.XResolution, film.YResolution, 1.0f)
                              * Transform.Scale(1.0f / (screenWindow[1] - screenWindow[0]), 1.0f / (screenWindow[2] - screenWindow[3]), 1.0f)
                              * Transform.Translate(new Vector(-screenWindow[0], -screenWindow[3], 0.0f));
            _rasterToScreen = Transform.Invert(_screenToRaster);
            _rasterToCamera = Transform.Invert(_cameraToScreen) * _rasterToScreen;
        }
Beispiel #8
0
        /// <inheritdoc />
        public PerspectiveCamera(AnimatedTransform cameraToWorld, Bounds2D screenWindow, double shutterOpen, double shutterClose, double lensr, double focald, double fov, Film film, Medium medium)
            : base(cameraToWorld, Transform.Perspective(fov, 1e-2f, 1000.0), screenWindow, shutterOpen, shutterClose, lensr, focald, film, medium)
        {
            // Compute differential changes in origin for perspective camera rays
            _dxCamera =
                (RasterToCamera.AtPoint(new Point3D(1.0, 0.0, 0.0)) - RasterToCamera.AtPoint(new Point3D(0.0, 0.0, 0.0))).ToVector3D();
            _dyCamera =
                (RasterToCamera.AtPoint(new Point3D(0.0, 1.0, 0.0)) - RasterToCamera.AtPoint(new Point3D(0.0, 0.0, 0.0))).ToVector3D();

            // Compute image plane bounds at $z=1$ for _PerspectiveCamera_
            Point2I res      = film.FullResolution;
            Point3D MinPoint = RasterToCamera.AtPoint(new Point3D(0.0, 0.0, 0.0));
            Point3D MaxPoint = RasterToCamera.AtPoint(new Point3D(res.X, res.Y, 0.0));

            MinPoint /= MinPoint.Z;
            MaxPoint /= MaxPoint.Z;
            _a        = Math.Abs((MaxPoint.X - MinPoint.X) * (MaxPoint.Y - MinPoint.Y));
        }
Beispiel #9
0
        protected Camera(AnimatedTransform cameraToWorld, double shutterOpen, double shutterClose, Film film, Medium medium)
        {
            CameraToWorld = cameraToWorld;
            ShutterOpen   = shutterOpen;
            ShutterClose  = shutterClose;
            Film          = film;
            Medium        = medium;

            if (CameraToWorld.HasScale())
            {
                // todo:
                //Warning(
                //  "Scaling detected in world-to-camera transformation!\n"
                //"The system has numerous assumptions, implicit and explicit,\n"
                //"that this transform will have no scale factors in it.\n"
                //"Proceed at your own risk; your image may have errors or\n"
                //"the system may crash as a result of this.");
            }
        }
        public ProjectiveCamera(AnimatedTransform c2w, Transform proj, float [] screenWindow, float sopen, float sclose, float lensr, float focald, Film f) : base(c2w, sopen, sclose, f)
        {
            // Initialize depth of field parameters
            lensRadius    = lensr;
            focalDistance = focald;

            // Compute projective camera transformations
            CameraToScreen = //Perspective(fov, 1e-2f, 1000.f);
                             proj;

            // Compute projective camera screen transformations

            ScreenToRaster = LR.Multiply(LR.Scale(film.xResolution, film.yResolution, 1.0f),
                                         LR.Scale(1.0f / (screenWindow[1] - screenWindow[0]), 1.0f / (screenWindow[2] - screenWindow[3]), 1.0f),
                                         LR.Translate(new Vector(-screenWindow[0], -screenWindow[3], 0.0f))
                                         );

            RasterToScreen = LR.Inverse(ScreenToRaster);
            RasterToCamera = LR.Multiply(LR.Inverse(CameraToScreen), RasterToScreen);
        }
Beispiel #11
0
        public override void Process(SceneReaderContext context)
        {
            context.VerifyWorld("ObjectInstance");

            if (context.RenderOptions.CurrentInstance != null)
            {
                throw new InvalidOperationException("ObjectInstance can't be called inside instance definition.");
            }
            if (!context.RenderOptions.Instances.ContainsKey(Name))
            {
                throw new InvalidOperationException("Unable to find instance named '" + Name + "'.");
            }

            var instances = context.RenderOptions.Instances[Name];

            if (instances.Count == 0)
            {
                return;
            }

            if (instances.Count > 1 || !instances[0].CanIntersect)
            {
                // Refine instance primitives and create aggregate.
                var accelerator = Factories.MakeAccelerator(
                    context.RenderOptions.AcceleratorName,
                    context.RenderOptions.AcceleratorParams,
                    instances);
                instances.Clear();
                instances.Add(accelerator);
            }

            var worldToInstance0        = Transform.Invert(context.CurrentTransform[0]);
            var worldToInstance1        = Transform.Invert(context.CurrentTransform[1]);
            var animatedWorldToInstance = new AnimatedTransform(
                worldToInstance0, context.RenderOptions.TransformStartTime,
                worldToInstance1, context.RenderOptions.TransformEndTime);

            context.RenderOptions.Primitives.Add(new TransformedPrimitive(
                                                     instances[0], animatedWorldToInstance));
        }
Beispiel #12
0
        public static Camera MakeCamera(string name, ParamSet parameters,
                                        TransformSet cameraToWorldSet, float transformStart, float transformEnd,
                                        Film film)
        {
            var animatedCameraToWorld = new AnimatedTransform(
                cameraToWorldSet[0], transformStart,
                cameraToWorldSet[1], transformEnd);

            switch (name)
            {
            case "perspective":
            {
                var shutterOpen  = parameters.FindSingle("shutteropen", 0.0f);
                var shutterClose = parameters.FindSingle("shutterclose", 1.0f);
                if (shutterOpen < shutterClose)
                {
                    MathUtility.Swap(ref shutterOpen, ref shutterClose);
                }
                var lensRadius    = parameters.FindSingle("lensradius", 0.0f);
                var focalDistance = parameters.FindSingle("focaldistance", 1e30f);
                var frame         = parameters.FindSingle("frameaspectratio", film.XResolution / (float)film.YResolution);
                var screenWindow  = parameters.FindSingleList("screenwindow");
                if (screenWindow.Length != 4)
                {
                    screenWindow = (frame > 1.0f)
                            ? new[] { -frame, frame, -1, 1 }
                }
                : new[] { -1, 1, -1 / frame, 1 / frame };
                var fieldOfView = parameters.FindSingle("fov", 90.0f);

                return(new PerspectiveCamera(animatedCameraToWorld, screenWindow, shutterOpen, shutterClose,
                                             lensRadius, focalDistance, fieldOfView, film));
            }

            default:
                throw new ArgumentException("Unknown camera: " + name);
            }
        }
Beispiel #13
0
 /// <summary>
 /// PerspectiveCamera
 /// </summary>
 /// <param name="c2w">c2w</param>
 /// <param name="proj">camer2screen</param>
 /// <param name="f">film</param>
 /// <param name="lensr">lenser</param>
 /// <param name="focald">focald</param>
 /// <param name="screenWindow">float[4]</param>
 ///
 public PerspectiveCamera(AnimatedTransform c2w, float[] screenWindow, float sopen, float sclose, float lensr, float focald, float fov, Film f) : base(c2w, LR.Perspective(fov, 1e-2f, 1000f), screenWindow, sopen, sclose, lensr, focald, f)
 {
     dxCamera = RasterToCamera.Caculate(new Point3(1, 0, 0)) - RasterToCamera.Caculate(new Point3(0, 0, 0));
     dyCamera = RasterToCamera.Caculate(new Point3(0, 1, 0)) - RasterToCamera.Caculate(new Point3(0, 0, 0));
 }
Beispiel #14
0
 public TransformedPrimitive(Primitive primitive, AnimatedTransform worldToPrimitive)
 {
     _primitive        = primitive;
     _worldToPrimitive = worldToPrimitive;
 }
Beispiel #15
0
 public OrthoCamera(AnimatedTransform c2w, float[] screenWindow, float sopen, float sclose, float lensr, float focald, Film f) : base(c2w, LR.Orthographic(0, 1), screenWindow, sopen, sclose, lensr, focald, f)
 {
     dxCamera = RasterToCamera.Caculate(new Vector(1, 0, 0));
     dyCamera = RasterToCamera.Caculate(new  Vector(0, 1, 0));
 }
Beispiel #16
0
        private void ProcessShape(SceneReaderContext context)
        {
            Primitive prim = null;
            AreaLight area = null;

            if (!context.CurrentTransform.IsAnimated)
            {
                // Create primitive for static shape.

                var shape = Factories.MakeShape(ImplementationType,
                                                context.CurrentTransform[0], context.GraphicsState.ReverseOrientation,
                                                Parameters);
                var material = context.GraphicsState.CreateMaterial(
                    Parameters, context.CurrentTransform[0]);

                // Possibly create area light for shape.
                if (!string.IsNullOrEmpty(context.GraphicsState.AreaLight))
                {
                    area = Factories.MakeAreaLight(
                        context.GraphicsState.AreaLight,
                        context.CurrentTransform[0],
                        context.GraphicsState.AreaLightParams,
                        shape);
                }
                prim = new GeometricPrimitive(shape, material, area);
            }
            else
            {
                // Create primitive for animated shape.

                var shape = Factories.MakeShape(ImplementationType, new Transform(),
                                                context.GraphicsState.ReverseOrientation, Parameters);
                var material = context.GraphicsState.CreateMaterial(
                    Parameters, context.CurrentTransform[0]);

                // Get animatedWorldToObject transform for shape.
                var worldToObj0           = Transform.Invert(context.CurrentTransform[0]);
                var worldToObj1           = Transform.Invert(context.CurrentTransform[1]);
                var animatedWorldToObject = new AnimatedTransform(
                    worldToObj0, context.RenderOptions.TransformStartTime,
                    worldToObj1, context.RenderOptions.TransformEndTime);

                Primitive basePrim = new GeometricPrimitive(shape, material, null);
                if (!basePrim.CanIntersect)
                {
                    // Refine animated shape and create BVH if more than one shape created.
                    var refinedPrimitives = basePrim.FullyRefine();
                    if (refinedPrimitives.Count == 0)
                    {
                        return;
                    }
                    basePrim = (refinedPrimitives.Count > 1)
                        ? new BoundingVolumeHierarchyAccelerator(refinedPrimitives)
                        : refinedPrimitives[0];
                }
                prim = new TransformedPrimitive(basePrim, animatedWorldToObject);
            }

            // Add primitive to scene or current instance.
            if (context.RenderOptions.CurrentInstance != null)
            {
                context.RenderOptions.CurrentInstance.Add(prim);
            }
            else
            {
                context.RenderOptions.Primitives.Add(prim);
                if (area != null)
                {
                    context.RenderOptions.Lights.Add(area);
                }
            }
        }