예제 #1
0
        public static void SolvePnP(Scene scene, PinholeCamera camera, List <Tuple <int, PointF> > detectedMarkers)
        {
            var markers = scene.getIE <Marker>().ToList();
            //detectedMarkers.OrderBy(x => x.Item1);
            int markersid = 0;
            List <MCvPoint3D32f> points3d    = new List <MCvPoint3D32f>();
            List <PointF>        imagepoints = new List <PointF>();


            foreach (var detectedMarker in detectedMarkers)
            {
                var scenemarker = markers.Find(x => x.ID == detectedMarker.Item1);
                if (scenemarker != null)
                {
                    points3d.Add(new MCvPoint3D32f((float)scenemarker.X, (float)scenemarker.Y,
                                                   (float)scenemarker.Z));
                    imagepoints.Add(detectedMarker.Item2);
                }
            }
            Matrix <double> outrot   = new Matrix <double>(3, 1);
            Matrix <double> outtrans = new Matrix <double>(3, 1);

            double[] rvec, tvec;

            Emgu.CV.CvInvoke.SolvePnP(
                points3d.ToArray(),
                imagepoints.ToArray(),
                new Emgu.CV.Matrix <double>(camera.Intrinsics.Mat),
                new Emgu.CV.Matrix <double>(camera.Cv_DistCoeffs5), outrot, outtrans
                );
        }
예제 #2
0
        public static ZhangSimulation CreateSimulation(PinholeCamera c, ChessBoard board, int pictureCount,
                                                       Func <int, double[]> distanceGenerator,
                                                       Func <int, double[]> Angles)
        {
            throw new NotImplementedException();

            /*
             * ZhangSimulation simulation = new ZhangSimulation();
             *
             * var distances = distanceGenerator(pictureCount);
             * var angles = Angles(pictureCount);
             * Random r = new Random();
             * var randomvec = new Vector3d(r.NextDouble(),r.NextDouble(),r.NextDouble()).Normalized(); //IS NIET RANDOM
             * for (int i = 0; i < pictureCount; i++) {
             *  var pos = c.Pos + c.Dir*distances[i];
             *  var q1 = Quaterniond.FromAxisAngle(Vector3d.Cross(c.Dir, randomvec), angles[i]);
             *  var q2 = Quaterniond.FromAxisAngle(c.Dir, r.NextDouble()*Math.PI*2);
             *  var q = q1 + q2;
             *  var b = new ChessBoard();
             *  b.ChessboardSize = board.ChessboardSize;
             *  b.SquareSizemm = board.SquareSizemm;
             *  b.Pos = pos;
             *  b.Orient(q);
             *  simulation.Chessboards.Add(b);
             * }
             *
             * simulation.Camera = c;
             *
             * return simulation;
             * */
        }
예제 #3
0
        public static Point2d[] ProjectPointd2D_Manually(this PinholeCamera cam, Vector3d[] points3d, out Vector3d[] visible)
        {
            var r   = new List <Point2d>();
            var vis = new List <Vector3d>();



            var transf = cam.worldMat.Inverted();

            foreach (var vector3D in points3d)
            {
                var camcoord = Vector3d.TransformPerspective(vector3D, transf);

                if (camcoord.Z < 0)
                {
                    continue;
                }


                var x = camcoord.X / camcoord.Z;
                var y = camcoord.Y / camcoord.Z;

                var r2      = x * x + y * y;
                var r4      = r2 * r2;
                var r6      = r4 * r2;
                var r_coeff = ((1) + cam.DistortionR1 * r2 + cam.DistortionR2 * r4 + cam.DistortionR3 * r6);
                var tdistx  = 2 * cam.DistortionT1 * x * y + cam.DistortionT2 * (r2 + 2 * x * x);
                var tdisty  = 2 * cam.DistortionT2 * x * y + cam.DistortionT1 * (r2 + 2 * y * y);
                var xd      = x * r_coeff + tdistx;
                var yd      = y * r_coeff + tdisty;

                var im_x = cam.Intrinsics.fx * xd + cam.Intrinsics.cx;
                var im_y = cam.Intrinsics.fy * yd + cam.Intrinsics.cy;

                if (im_x >= 0 && im_x <= cam.PictureSize.Width && im_y >= 0 && im_y <= cam.PictureSize.Height)
                {
                    vis.Add(vector3D);
                    r.Add(new Point2d(im_x, im_y));
                }

                /*
                 * var test = ceresdotnet.CeresCameraCollectionBundler.testProjectPoint(
                 * cam.toCeresCamera(),
                 * new CeresPointOrient() {
                 *     RT = new[] { axis.X, axis.Y, axis.Z, trans.X, trans.Y, trans .Z}
                 * },
                 *  new CeresMarker2() {
                 *      Location = new CeresPoint2() {
                 *          X = vector3D.X,
                 *          Y = vector3D.Y,
                 *          Z = vector3D.Z
                 *      },
                 *      x = im_x,
                 *      y = im_y
                 *  });*/
            }
            visible = vis.ToArray();
            return(r.ToArray());
        }
예제 #4
0
        public Matrix <double> CameraToMatrix(PinholeCamera c)
        {
            var r = new Matrix <double>(new[] {
                c.Intrinsics.fx, c.Intrinsics.fy, c.Intrinsics.cx, c.Intrinsics.cy, c.Intrinsics.DistortionR1,
                c.Intrinsics.DistortionR2, c.Intrinsics.DistortionR3, c.Intrinsics.DistortionT1,
                c.Intrinsics.DistortionT2
            });

            return(r);
        }
예제 #5
0
        public static void MappingTestRender()
        {
            Cube Cube(float rotY, float rotX, float tx, float ty)
            {
                var cube1 = new Cube
                {
                    Material = { Texture = CreateTestCubeMap(), Roughness = 1f, SpecularColor = new Color(0.3f, 0.3f, 0.3f) }
                };

                cube1.SetTransform(Transform.RotateY(rotY).RotateX(rotX).Translate(tx, ty, 0));
                return(cube1);
            }

            var g = new Group();

            g.AddChild(Cube(0.7854f, 0.7854f, -6, 2));
            g.AddChild(Cube(2.3562f, 0.7854f, -2, 2));
            g.AddChild(Cube(3.927f, 0.7854f, 2, 2));
            g.AddChild(Cube(5.4978f, 0.7854f, 6, 2));
            g.AddChild(Cube(0.7854f, -0.7854f, -6, -2));
            g.AddChild(Cube(2.3562f, -0.7854f, -2, -2));
            g.AddChild(Cube(3.927f, -0.7854f, 2, -2));
            g.AddChild(Cube(5.4978f, -0.7854f, 6, -2));

            g.Divide(1);

            var w = new World();

            w.SetLights(new PointLight(new Point(0, 2, -100), Colors.White));
            w.SetObjects(g);

            var width  = 800;
            var height = 400;
            var from   = new Point(0, 0, -20f);
            var to     = new Point(0, 0, 0);

            var canvas      = new Canvas(width, height);
            var pps         = new PerPixelSampler(16);
            var fov         = 0.8f;
            var aspectRatio = (float)width / height;
            var transform   = Transform.LookAt(from, to, new Vector(0, 1, 0));
            var camera      = new PinholeCamera(transform, fov, aspectRatio);
            var cws         = new PhongWorldShading(1, w);
            var ctx         = new RenderContext(canvas, new RenderPipeline(cws, camera, pps));

            Console.WriteLine("Rendering at {0}x{1}...", width, height);
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            ctx.Render();
            PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "mapping");
            stopwatch.Stop();
            Console.WriteLine("Done ({0})", stopwatch.Elapsed);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            var c = PinholeCamera.getTestCamera();
            var b = new ChessBoard(8, 6, 20);
            var s = ZhangSimulation.CreateSimulation(c, b, 5,
                                                     count => Util.gaussDistr(count, .5, .2, .20, 1),
                                                     count => Util.gaussDistr(count, 0, Math.PI / 4, -Math.PI / 2, Math.PI / 2)
                                                     );

            _simulations.Add(s);
        }
예제 #7
0
        public static void Pinhole( SceneBase Scene, RenderMethod Method, Framebuffer Fb, byte MaxDepth, float Epsilon,
                                    byte RouletteDepth, float MaximumTerminationProbability, bool UseMultithreading,
                                    float ImagePlaneDistance, float ImagePlaneHeight, float ImagePlaneWidth,
                                    Point PinholeLocation, Vector CameraDirection, Vector Up,
                                    UInt16 XSamplesPerPixel, UInt16 YSamplesPerPixel, bool Jitter )
        {
            PinholeCamera Camera = new PinholeCamera( ImagePlaneDistance, ImagePlaneHeight, ImagePlaneWidth,
                                                      PinholeLocation, CameraDirection, Up,
                                                      XSamplesPerPixel, YSamplesPerPixel, Jitter );

            Render( Camera, Scene, Method, MaxDepth, Epsilon, RouletteDepth, MaximumTerminationProbability, Fb, UseMultithreading );
        }
예제 #8
0
        public void Apply(PinholeCamera camera, CeresCamera cc)
        {
            PosRuis?.Apply(ref cc.External.t[0], ref cc.External.t[1], ref cc.External.t[2]);

            camera.Intrinsics.fx *= .95;
            camera.Intrinsics.fy *= .95;

            camera.Intrinsics.cx = camera.Intrinsics.PictureSize.Width / 2;
            camera.Intrinsics.cy = camera.Intrinsics.PictureSize.Height / 2;

            camera.Intrinsics.SetDistortionsZero();
            cc.Internal.ZeroDistortions();
        }
예제 #9
0
        public static PointF[] ProjectPointd2D_Manually(this PinholeCamera cam, MCvPoint3D32f[] points3d, out MCvPoint3D32f[] visible)
        {
            var r   = new List <PointF>();
            var vis = new List <MCvPoint3D32f>();


            var transftk = cam.worldMat.Inverted();
            var transf   = transftk.tocv();


            VectorOfPoint3D32F points3dvec       = new VectorOfPoint3D32F(points3d);
            VectorOfPoint3D32F points3dvectransf = new VectorOfPoint3D32F(points3dvec.Size);

            CvInvoke.Transform(points3dvec, points3dvectransf, transf);


            for (int i = 0; i < points3dvec.Size; i++)
            {
                var camcoord = points3dvectransf[i];

                if (camcoord.Z < 0)
                {
                    continue;
                }


                var x = camcoord.X / camcoord.Z;
                var y = camcoord.Y / camcoord.Z;

                var r2      = x * x + y * y;
                var r4      = r2 * r2;
                var r6      = r4 * r2;
                var r_coeff = ((1) + cam.DistortionR1 * r2 + cam.DistortionR2 * r4 + cam.DistortionR3 * r6);
                var tdistx  = 2 * cam.DistortionT1 * x * y + cam.DistortionT2 * (r2 + 2 * x * x);
                var tdisty  = 2 * cam.DistortionT2 * x * y + cam.DistortionT1 * (r2 + 2 * y * y);
                var xd      = x * r_coeff + tdistx;
                var yd      = y * r_coeff + tdisty;

                var im_x = cam.Intrinsics.fx * xd + cam.Intrinsics.cx;
                var im_y = cam.Intrinsics.fy * yd + cam.Intrinsics.cy;

                if (im_x >= 0 && im_x <= cam.PictureSize.Width && im_y >= 0 && im_y <= cam.PictureSize.Height)
                {
                    vis.Add(points3dvec[i]);
                    r.Add(new PointF((float)im_x, (float)im_y));
                }
            }
            visible = vis.ToArray();
            return(r.ToArray());
        }
예제 #10
0
        public static Scene bundleAdjustScene(int cameranumber, double featureafstand)
        {
            //scene bevat SObject. dit kunnen eender welke elementen zijn die hier van overerven
            var s = new Scene();

            //calibratieruimte 8x4x10m elke 1m een marker, returns List<CalibratieForms::Marker>

            var ptn3d = featureafstand == _lastboxafst ? lastBox : createBox(8, 4, 10, featureafstand);

            _lastboxafst = featureafstand;
            lastBox      = ptn3d;

            s.objects.AddRange(ptn3d); //markers toevoegen aan scene

            Random rnd     = new Random();
            int    index   = rnd.Next(ptn3d.Count);
            var    cameras = new List <PinholeCamera>();

            var intr = CameraIntrinsics.EOS5DMARKII;

            for (int i = 0; i < cameranumber; i++)   //10 foto's met Huawei camera
            //var c = PinholeCamera.getTestCameraHuawei();//Huawei bepaald via Zhang
            {
                var c = new PinholeCamera(intr);
                c.Name = "EOS5DMARKII";
                var pos           = new Matrix <double>(new double[] { rnd.Next(2, 6), 2, rnd.Next(3, 7) }); //camera staat op x: 2-6m, y=2m, z=3-7m random gekozen
                var target        = ptn3d[rnd.Next(ptn3d.Count)];                                            //camera richt naar een random gekozen marker
                var worldtocamera = MatrixExt.LookAt(pos, target.Pos, MatrixExt.UnitVectorY <double>());     //berekend de wereld->cameracoordinaten
                var worldmat      = worldtocamera.Inverted();
                c.WorldMat = worldmat;

                //camera->wereldcoordinaten.
                //Deze matrix bevat dus op kolom3 de Positie van de camera in wereldcoordinten,
                //hiernaast de rotatie in 3x3 ([R t])
                cameras.Add(c);
            }

            /*for (int i = 0; i < 5; i++) { //5 foto's met Casio camera
             *  var c = PinholeCamera.getTestCamera();//Casio bepaald via zhang
             *  c.Name = "casio";
             *  var Pos = new Vector3d(rnd.Next(2, 6), 2, rnd.Next(3, 7));
             *  var target = ptn3d[rnd.Next(ptn3d.Count)];
             *  var worldtocamera = Matrix4d.LookAt(Pos, target.Pos, Vector3d.UnitY);
             *  c.worldMat = worldtocamera.Inverted();
             *  cameras.Add(c);
             * }*/
            s.objects.AddRange(cameras);
            return(s);
        }
예제 #11
0
        public void RayAfterCameraTransform()
        {
            var width      = 201;
            var height     = 101;
            var transform  = Transform.RotateY(MathF.PI / 4f) * Transform.Translate(0, -2, 5);
            var c          = new PinholeCamera(transform, MathF.PI / 2f, (float)width / height);
            var coordinate = new PixelCoordinate(100, 50);

            var(r, _) =
                c.CameraRay(
                    new PixelSample(new PixelInformation(coordinate, width, height), new UVPoint(0.5f, 0.5f)),
                    new TestSampler(0f, 0f, 0.5f));
            r.Origin.Should().Be(new Point(0, 2, -5));
            r.Direction.Should().Be(new Vector(MathF.Sqrt(2f) / 2f, 0.0f, -MathF.Sqrt(2f) / 2f));
        }
예제 #12
0
 public static double[] toCeresIntrinsics9(this PinholeCamera c)
 {
     double[] intrinsics =
     {
         c.Intrinsics.fx,
         c.Intrinsics.fy,
         c.Intrinsics.cx,
         c.Intrinsics.cy,
         c.DistortionR1,
         c.DistortionR2,
         c.DistortionT1,
         c.DistortionT2,
         c.DistortionR3,
     };
     return(intrinsics);
 }
예제 #13
0
        public static Scene bundleAdjustSceneMultiCollection()
        {
            //scene bevat SObject. dit kunnen eender welke elementen zijn die hier van overerven
            var s = new Scene();

            //calibratieruimte 8x4x10m elke 1m een marker, returns List<CalibratieForms::Marker>
            var ptn3d = createBox(8, 4, 10, 0.2);

            s.objects.AddRange(ptn3d); //markers toevoegen aan scene

            Random rnd     = new Random();
            int    index   = rnd.Next(ptn3d.Count);
            var    cameras = new List <PinholeCamera>();

            for (int i = 0; i < 6; i++)                                                                       //7 foto's met Huawei camera
            {
                var c = PinholeCamera.getTestCameraHuawei();                                                  //Huawei bepaald via Zhang
                c.Name = "huaweip9";
                var pos           = new Matrix <double>(new double [] { rnd.Next(2, 6), 2, rnd.Next(3, 7) }); //camera staat op x: 2-6m, y=2m, z=3-7m random gekozen
                var target        = ptn3d[rnd.Next(ptn3d.Count)];                                             //camera richt naar een random gekozen marker
                var worldtocamera = MatrixExt.LookAt(pos, target.Pos, MatrixExt.UnitVectorY <double>());      //berekend de wereld->cameracoordinaten
                c.WorldMat = worldtocamera.Inverted();
                //camera->wereldcoordinaten.
                //Deze matrix bevat dus op kolom3 de Positie van de camera in wereldcoordinten,
                //hiernaast de rotatie in 3x3 ([R t])
                cameras.Add(c);
            }
            CameraCollection coll  = new CameraCollection(cameras);
            CameraCollection coll2 = new CameraCollection(cameras);

            //coll.SetCollectionCenter_MidCameras();

            /*for (int i = 0; i < 5; i++) { //5 foto's met Casio camera
             *  var c = PinholeCamera.getTestCamera();//Casio bepaald via zhang
             *  c.Name = "casio";
             *  var Pos = new Vector3d(rnd.Next(2, 6), 2, rnd.Next(3, 7));
             *  var target = ptn3d[rnd.Next(ptn3d.Count)];
             *  var worldtocamera = Matrix4d.LookAt(Pos, target.Pos, Vector3d.UnitY);
             *  c.worldMat = worldtocamera.Inverted();
             *  cameras.Add(c);
             * }*/
            //s.objects.AddRange(cameras);
            s.objects.Add(coll);
            s.objects.Add(coll2);
            return(s);
        }
예제 #14
0
        public static Marker CreateFeatureFromCamera(PinholeCamera c, double sensorx, double sensory, double dist, int markerid)
        {
            var fx = c.Intrinsics.fx;
            var fy = c.Intrinsics.fy;
            var x  = sensorx - c.Intrinsics.cx;
            var y  = sensory - c.Intrinsics.cy;

            var camZ = dist * fx * fy / Math.Sqrt(fx * fx + x * x) / Math.Sqrt(fy * fy + y * y);
            var camX = x / fx * camZ;
            var camY = y / fy * camZ;

            var camCoord = new Matrix <double>(new [] { camX, camY, camZ, 1 });

            var coord = c.WorldMat * camCoord;

            return(new Marker(markerid, coord[0, 0] / coord[3, 0], coord[1, 0] / coord[3, 0], coord[2, 0] / coord[3, 0]));
        }
예제 #15
0
        public static Scene testScene_featuressimulation(double distmean, double diststd, int features)
        {
            var r = new Scene();
            var c = new PinholeCamera(CameraIntrinsics.GOPROHERO3_BROWNR3_AFGEROND_EXTRADIST);

            r.Add(c);
            Random rand = new WH2006();

            for (int i = 0; i < features; i++)
            {
                var sensorx = rand.NextDouble() * c.Intrinsics.PictureSize.Width;
                var sensory = rand.NextDouble() * c.Intrinsics.PictureSize.Height;
                var dist    = Util.NextGaussian(distmean, diststd);
                r.Add(CreateFeatureFromCamera(c, sensorx, sensory, dist, i));
            }
            return(r);
        }
예제 #16
0
        public void CalibrateCV(ChessBoard cb, out PinholeCamera[] cameras)
        {
            var worldCoordinates = cb.boardLocalCoordinates_cv;

            List <List <Point3f> > worldpoints = new List <List <Point3f> >();

            for (int i = 0; i < images.Count; i++)
            {
                worldpoints.Add(cb.boardLocalCoordinates_cv.ToList());
            }

            double[,] cameraMat2 = new double[3, 3];

            var imagepoints = images.Select(x => x.ImagePoints);



            Matrix cameramat  = new Matrix(3, 3);
            Matrix distcoeffs = new Matrix(4, 1);

            Mat[] rvecs, tvecs;

            CVI.CalibrateCamera(worldpoints.Select(x => x.ToArray()).ToArray(), imagepoints.ToArray(), images.First().imageSize,
                                cameramat, distcoeffs, CalibType.Default, new MCvTermCriteria(),
                                out rvecs, out tvecs);

            cameras = new PinholeCamera[images.Count];
            for (int i = 0; i < rvecs.Length; i++)
            {
                var rvec = rvecs[i];
                var tvec = tvecs[i];
                cameras[i] = new PinholeCamera();
                var cam = cameras[i];
                var rot = new RotationVector3D();
                rvec.CopyTo(rot);

                var worldMat = new Matrix4d();
            }


            for (int i = 0; i < cameras.Length; i++)
            {
                worldpoints.Add(cb.boardLocalCoordinates_cv.ToList());
            }
        }
예제 #17
0
        public void CreateScene(int width, int height, FloatColor color, bool useAntialiasing)
        {
            var renderTarget = new Framebuffer(width, height);

            renderTarget.Clear(color);

            var objects = new List <IHittable>
            {
                new Plane(new Vector3(0, -2, 0), new Vector3(0, 1, 0),
                          new ReflectiveMaterial(FloatColor.White, 0.4f, 0, 1000, 0.6f, CheckerTexture.Create(FloatColor.Green, FloatColor.Black).ToInfo())),
                new Sphere(new Vector3(-3.5f, 0, 0), 2,
                           new ReflectiveMaterial(FloatColor.UnityYellow, 0.7f, 0.5f, 1000, 0.3f)),
                new Sphere(new Vector3(3.5f, 0, 0), 2,
                           new ReflectiveMaterial(Color.GreenYellow.ToFloatColor(), 0.7f, 0.5f, 1000, 0.3f)),
                new Sphere(new Vector3(0, 0, 3.5f), 2,
                           new ReflectiveMaterial(Color.DeepSkyBlue.ToFloatColor(), 0.7f, 0.5f, 1000, 0.3f)),
                new Sphere(new Vector3(0, 0, -3.5f), 2,
                           new TransparentMaterial(Color.Red.ToFloatColor(), 0.1f, 0, 0.3f, 1.05f, 0.9f)),
            };


            var sampler = new Sampler(new RegularGenerator(), new SquareDistributor(), 25, 1);
            var camera  = new PinholeCamera(renderTarget, new Vector3(6, 2, -15),
                                            new Vector3(0, 0.3f, 0), new Vector3(0, -1, 0),
                                            new Vector2(0.7f, 0.7f * height / width), 2)
            {
                Sampler  = sampler,
                MaxDepth = 5
            };

            Scene = new Scene(objects, camera,
                              new List <Light>
            {
                new PointLight
                {
                    Position  = new Vector3(-5, 5, -3),
                    Color     = FloatColor.White,
                    Intensity = 2
                },
            },
                              FloatColor.Black);
        }
예제 #18
0
        public Form1()
        {
            InitializeComponent();

            ZhangSimulationForm simfrm = new ZhangSimulationForm();

            simfrm.Show(dockPanel1);

            LogForm logform = new LogForm();

            logform.Show(simfrm.Pane, DockAlignment.Bottom, .2);

            CameraInfoWindow cifo = new CameraInfoWindow();

            cifo.Show(simfrm.Pane, DockAlignment.Right, .5);

            CameraSimulationFrm cfrm = new CameraSimulationFrm();

            cfrm.Show(cifo.Pane, DockAlignment.Bottom, .35);


            CameraInfoWindow cifo2 = new CameraInfoWindow();

            cifo2.Show(cifo.Pane, DockAlignment.Right, .5);


            PinholeCamera c = PinholeCamera.getTestCamera();

            cifo.Camera = c;

            simfrm.InitialCameraWindow    = cifo;
            simfrm.CalibratedCameraWindow = cifo2;
            simfrm.cameraFrm = cfrm;


            Log.AddReader(logform);
        }
예제 #19
0
        public RefractionScene()
        {
            FileName   = "Assignment1_Refraction.jpg";
            Integrator = (IIntegrator)Activator.CreateInstance(Constants.Integrator);
            Camera     = new PinholeCamera()
            {
                FieldOfViewX = 30f,
                FieldOfViewY = 30f,
                ScreenWidth  = 512,
                ScreenHeight = 512,
                Eye          = new Vector4(0, 0, 2, 1),
                Up           = new Vector4(0, 1, 0, 1),
                LookAt       = new Vector4(0, 0, 0, 1)
            };
            Camera.PreProcess();

            Film = new Film(Camera.ScreenWidth, Camera.ScreenHeight);

            //List of objects
            Sphere sphere1 = new Sphere(new RefractiveMaterial(1.5f), new Vector3(0f, 0f, 0f), 0.4f);
            Sphere sphere2 = new Sphere(new BlinnPhongMaterial(new Color(0.8f, 0f, 0f), new Color(0.8f, 0.8f, 0.8f), 30f), new Vector3(0.4f, 0.2f, -0.3f), 0.3f);
            Plane  p1      = new Plane(1f, new Vector3(0, 1, 0))
            {
                Name     = "P1",
                Material = new LambertMaterial(new Color(0f, 0.8f, 0.8f))
            };
            Plane p2 = new Plane(1f, new Vector3(0, 0, 1))
            {
                Name     = "P2",
                Material = new LambertMaterial(new Color(0.3f, 0.8f, 0.8f))
            };
            Plane p3 = new Plane(1f, new Vector3(-1, 0, 0))
            {
                Name     = "P3",
                Material = new LambertMaterial(new Color(1.0f, 0.8f, 0.8f))
            };
            Plane p4 = new Plane(1f, new Vector3(1, 0, 0))
            {
                Name     = "P4",
                Material = new LambertMaterial(new Color(0f, 0.8f, 0f))
            };
            Plane p5 = new Plane(1f, new Vector3(0, -1, 0))
            {
                Name     = "P5",
                Material = new LambertMaterial(new Color(0.8f, 0.8f, 0.8f))
            };

            Objects = new IntersectableList();

            Objects.Add(sphere1);
            Objects.Add(sphere2);
            Objects.Add(p1);
            Objects.Add(p2);
            Objects.Add(p3);
            Objects.Add(p4);
            Objects.Add(p5);

            Lights = new List <ILight>();

            ILight light1 = new PointLight(new Vector3(0.0f, 0.8f, 0.8f), new Color(0.7f, 0.7f, 0.7f));
            ILight light2 = new PointLight(new Vector3(-0.8f, 0.2f, 0f), new Color(0.5f, 0.5f, 0.5f));

            Lights.Add(light1);
            Lights.Add(light2);
        }
예제 #20
0
 public IObservation[] getObservations(PinholeCamera c)
 {
     throw new NotImplementedException();
 }
예제 #21
0
        public static void LowPolyTeapotTest()
        {
            var path         = Path.Combine(GetExecutionPath(), "teapot-low.obj");
            var data         = ObjFile.ParseFile(path);
            var triangulated = data.Groups[0];

            triangulated.SetTransform(Transform.Scale(0.1f).RotateX(-MathF.PI / 2f));

            var material = new Material
            {
                Texture    = new SolidColor(new Color(0.3f, 0.3f, 1f)),
                Reflective = 0.4f,
                Ambient    = 0.2f,
                Diffuse    = 0.3f
            };

            var floor = new Cube();

            floor.SetMaterial(material);
            var fg = new Group();

            fg.AddChild(floor);
            fg.SetTransform(Transform.TranslateY(-1).Scale(1f));

            var g = new Group(fg, triangulated);

            g.Divide(1);

            var w = new World();

            w.SetLights(new PointLight(new Point(-10, 10, -10), Colors.White));
            w.SetObjects(g);

            //var width = 300;
            //var height = 200;
            //var transform = Transforms.View(new Point(0, 1.5f, -5f), new Point(0, 1, 0), new Vector(0, 1, 0));
            //var c = new PinholeCamera(transform, MathF.PI / 3f, width, height);
            //var scene = new Scene(c, new PhongWorldShading(1, w));
            //var canvas = new Canvas(width, height);

            var width  = 300;
            var height = 200;
            var from   = new Point(0, 1.5f, -5f);
            var to     = new Point(0, 1, 0);

            var canvas      = new Canvas(width, height);
            var pps         = new PerPixelSampler(3);
            var fov         = MathF.PI / 3f;
            var aspectRatio = (float)width / height;
            var transform   = Transform.LookAt(from, to, new Vector(0, 1, 0));
            var camera      = new PinholeCamera(transform, fov, aspectRatio);
            var cws         = new PhongWorldShading(1, w);
            var ctx         = new RenderContext(canvas, new RenderPipeline(cws, camera, pps));

            Console.WriteLine("Rendering at {0}x{1}...", width, height);
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            //RenderContext.Render(canvas, scene);
            ctx.Render();
            PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "teapot");
            stopwatch.Stop();
            Console.WriteLine("Done ({0})", stopwatch.Elapsed);
        }
예제 #22
0
        public static PointF[] ProjectPointd2D_Manually <T>(this PinholeCamera cam, T[] points3d, out T[] visible) where T : SPoint
        {
            var r   = new List <PointF>();
            var vis = new List <T>();

            //var tt = cam.worldMat.Inverted();
            //var transf = tt.tocv();
            var transf      = cam.WorldMat.Inverted();
            var worldmatinv = cam.worldMat.Inverted();

            var mcvpoints3d = points3d.Select(x => x.toMCvPoint3D32f());

            VectorOfPoint3D32F points3dvec = new VectorOfPoint3D32F(mcvpoints3d.ToArray());
            //VectorOfPoint3D32F points3dvectransf = new VectorOfPoint3D32F(points3dvec.Size);


            var camcoords = new Matrix <double>(3, points3d.Length);

            var phm_mat        = new Mat();
            var camcoords_mat  = new Mat();
            var camcoords_mat2 = new VectorOfPoint3D32F();

            CvInvoke.ConvertPointsToHomogeneous(points3dvec, phm_mat);

            //var phm = new Matrix<float>(4, points3d.Length, phm_mat.DataPointer);
            //var camcoord = cam.WorldMat.Inverted() * phm;
            CvInvoke.Transform(phm_mat, camcoords_mat, transf);
            CvInvoke.ConvertPointsFromHomogeneous(camcoords_mat, camcoords_mat2);


            var cc = cam.toCeresCamera();

            for (int i = 0; i < camcoords_mat2.Size; i++)
            {
                var phmm = new Matrix <double>(3, 1);

                var camcoord = Vector3d.TransformPerspective(new Vector3d(points3d[i].X, points3d[i].Y, points3d[i].Z), worldmatinv);
                var x        = camcoord.X / camcoord.Z;
                var y        = camcoord.Y / camcoord.Z;

                var r2      = x * x + y * y;
                var r4      = r2 * r2;
                var r6      = r4 * r2;
                var r_coeff = ((1) + cam.DistortionR1 * r2 + cam.DistortionR2 * r4 + cam.DistortionR3 * r6);
                var tdistx  = 2 * cam.DistortionT1 * x * y + cam.DistortionT2 * (r2 + 2 * x * x);
                var tdisty  = 2 * cam.DistortionT2 * x * y + cam.DistortionT1 * (r2 + 2 * y * y);
                var xd      = x * r_coeff + tdistx;
                var yd      = y * r_coeff + tdisty;

                var im_x2 = cam.Intrinsics.fx * xd + cam.Intrinsics.cx;
                var im_y2 = cam.Intrinsics.fy * yd + cam.Intrinsics.cy;

                if (camcoord.Z < 0) //camcoords_mat2[i].Z < 0) {
                {
                    continue;
                }

                var pointf = ceresdotnet.CeresTestFunctions.ProjectPoint(cc.Internal, cc.External, points3d[i].Pos);

                var im_x = pointf.X;
                var im_y = pointf.Y;

                if (im_x >= 0 && im_x <= cam.PictureSize.Width && im_y >= 0 && im_y <= cam.PictureSize.Height)
                {
                    vis.Add(points3d[i]);
                    r.Add(pointf);
                }
                if (im_x2 >= 0 && im_x2 <= cam.PictureSize.Width && im_y2 >= 0 && im_y2 <= cam.PictureSize.Height)
                {
                    //vis.Add(points3d[i]);
                    //pointf.X = (float)im_x2;
                    //pointf.Y = (float)im_y2;
                    //r.Add(pointf);
                }
            }
            visible = vis.ToArray();
            return(r.ToArray());
        }
예제 #23
0
        public void SolveMultiCollection()
        {
            SetUniqueValues();
            var collections = scene.get <CameraCollection>();
            var markers3d   = scene.get <Marker>();
            var cameras     = scene.get <PinholeCamera>();



            var collec = new CameraCollection(cameras);

            collections = new[] { collec };


            var ccoll = new CeresCameraCollection();

            ccoll.Cameras = new List <CeresCamera>();
            ccoll.Cameras.AddRange(cameras.Select(x => {
                var cc = x.toCeresCamera();
                return(cc);
            }));
            // ccoll.CreateSecondPositionCopy();

            var bundler = new ceresdotnet.CeresCameraMultiCollectionBundler();



            Dictionary <CeresCameraCollection, Dictionary <CeresCamera, List <CeresMarker> > > observations =
                new Dictionary <CeresCameraCollection, Dictionary <CeresCamera, List <CeresMarker> > >();



            List <CeresCamera>           cerescameras           = new List <CeresCamera>();
            List <CeresCameraCollection> cerescameracollections = new List <CeresCameraCollection>();

            int cameraID = -1;

            var collectionobservations2 = new Dictionary <CeresCamera, List <CeresMarker> >();

            foreach (var camera in UniqueCameras)
            {
                //voor ruis kopie maken
                var cameracopy = new PinholeCamera();
                var cc         = camera.toCeresCamera();
                cameracopy.toCeresCamera();
                cameracopy.updateFromCeres(cc.Internal);
                cameracopy.updateFromCeres(cc.External);
                this.OriginalValues.Add(camera, cameracopy);
            }



            int totaalfotos = 0;

            foreach (var collection in collections)
            {
                var cerescollection        = new CeresCameraCollection();
                var collectionobservations = new Dictionary <CeresCamera, List <CeresMarker> >();

                foreach (var camera in collection)
                {
                    totaalfotos++;
                    List <CeresMarker> ceresmarkers = new List <CeresMarker>();
                    cameraID++;

                    var puntenCv =
                        markers3d.ToDictionary(m => new MCvPoint3D32f((float)m.X, (float)m.Y, (float)m.Z));

                    var cc = camera.toCeresCamera();


                    ceresdotnet.CeresTestFunctions.ProjectPoint(cc.Internal, cc.External, markers3d[0].Pos);



                    var visible_proj = camera.ProjectPointd2D_Manually(markers3d, out Marker[] visible3d);
                    GemFeaturesPerFoto += visible_proj.Length;

                    //Pixel ruis
                    for (int i = 0; i < visible_proj.Length; i++)
                    {
                        PixelRuisProvider?.Apply(ref visible_proj[i]);
                    }


                    //in een cerescamera worden interne parameters opgeslaan volgens array v doubles

                    //Per interne parameters kan men bepalen wat dient gebundeld te worden
                    //ook combinatie zijn mogelijk
                    //3D ruis
                    foreach (var marker in markers3d)
                    {
                        //WorldRuisProvider?.Apply(marker);
                    }

                    for (int i = 0; i < visible3d.Length; i++)
                    {
                        var proj = visible_proj[i];
                        ceresmarkers.Add(new CeresMarker()
                        {
                            id       = visible3d[i].ID,
                            Location = visible3d[i].toCeresParameter(),
                            x        = proj.X,
                            y        = proj.Y
                        });
                    }

                    cerescameras.Add(cc);
                    collectionobservations.Add(cc, ceresmarkers);

                    //gesimuleerde foto weergeven

                    /*var window2 = new CameraSimulationFrm(string.Format("Camera {0}: {1}", cameraID, camera.Name)) {
                     *  Camera = camera
                     * };
                     * window2.Show();
                     * window2.drawChessboard(visible_proj);*/
                }
                observations.Add(cerescollection, collectionobservations);
                collectionobservations2 = collectionobservations;
            }
            GemFeaturesPerFoto /= totaalfotos;
            foreach (var intr in UniqueIntr)
            {
                //Camera ruis/modifier
                CameraModifier?.Apply(intr);
                intr.toCeresParameter();
            }
            foreach (var marker in markers3d)
            {
                WorldRuisProvider?.Apply(marker);
                marker.toCeresParameter();
            }


            CeresCameraMultiCollectionBundler.MarkersFromCameraDelegate findObservationsFunc = (camera, coll) => {
                var    r             = collectionobservations2[camera];
                double Allreproj     = 0;
                double totalmrkrcout = 0;
                //foreach (var ceresCamera in bundler.StandaloneCameraList) {
                double reprojections = 0;
                foreach (var ceresMarker in r)
                {
                    var reproj = CeresTestFunctions.ReprojectPoint(camera.Internal, camera.External,
                                                                   ceresMarker.toPointF(), ceresMarker.Location.toMatrix());
                    reprojections += Math.Sqrt(reproj.X * reproj.X + reproj.Y * reproj.Y);
                }
                Allreproj     += reprojections;
                totalmrkrcout += r.Count;
                reprojections /= r.Count;
                //}

                return(r);
            };

            bundler.MarkersFromCamera    = findObservationsFunc;
            bundler.CollectionList       = cerescameracollections;
            bundler.StandaloneCameraList = cerescameras;

            bundler.bundleCollections(iterationCallbackHandler);

            CeresCameraMultiCollectionBundler b = bundler;

            double AllReprojections = 0;
            double totalmarkercount = 0;

            double meanPosX = 0;
            double meanPosY = 0;
            double meanPosZ = 0;

            foreach (var ceresCamera in b.StandaloneCameraList)
            {
                double reprojections = 0;
                var    markerlist    = b.MarkersFromCamera(ceresCamera, null);
                foreach (var ceresMarker in markerlist)
                {
                    var reproj = CeresTestFunctions.ReprojectPoint(ceresCamera.Internal, ceresCamera.External, ceresMarker.toPointF(), ceresMarker.Location.toMatrix());
                    reprojections += Math.Sqrt(reproj.X * reproj.X + reproj.Y * reproj.Y);
                }
                AllReprojections += reprojections;
                totalmarkercount += markerlist.Count;
                reprojections    /= markerlist.Count;

                //mean cam pos;
                var pos = ceresCamera.External.t;
                meanPosX += pos[0];
                meanPosY += pos[1];
                meanPosZ += pos[2];
            }
            meanPosX /= b.StandaloneCameraList.Count;
            meanPosY /= b.StandaloneCameraList.Count;
            meanPosZ /= b.StandaloneCameraList.Count;

            AllReprojections    /= totalmarkercount;
            reporjectionsstring += String.Format("({0}) Error: {1}", "final", AllReprojections) + Environment.NewLine;
            meancamereapos      += String.Format("({0}) pos: {1}  {2}  {3}", "final", AllReprojections, meanPosX, meanPosY, meanPosZ) + Environment.NewLine;
            Console.WriteLine("({0}) reprojerror: {1}   mean cam pos: x({2}) y({3}) z({4})", "final", AllReprojections, meanPosX, meanPosY, meanPosZ);

            lastReproj = AllReprojections;

            foreach (var collection in collections)
            {
                foreach (var camera in collection)
                {
                    camera.updateFromCeres();
                }
            }
        }
예제 #24
0
        public static unsafe void ceresSolveAruco()
        {
            var                phc          = PinholeCamera.getTestCameraHuawei();
            string             dir          = @"C:\Users\jens\Desktop\calibratie\Huawei p9\aruco\stereo test\";
            List <CeresMarker> ceresmarkers = new List <CeresMarker>();
            List <CeresCamera> cerescameras = new List <CeresCamera>();
            var                files        = Directory.GetFiles(dir).ToList();


            //8 punten nodig
            var markerDictionary = Aruco.findArucoMarkers(files, Path.Combine(dir, "aruco_detected\\"), 1);
            var pairs            = findImagePairsMinMarkers(markerDictionary, 8);

            Matrix K = new Matrix(phc.Intrinsics.Mat);

            var W = new Matrix(new double[] {
                0.0D, -1.0D, 0.0D,
                1.0D, 0.0D, 0.0D,
                0.0D, 0.0D, 1.0D
            });


            var Wt = new Matrix(new double[] {
                0.0D, 1.0D, 0.0D,
                -1.0D, 0.0D, 0.0D,
                0.0D, 0.0D, 1.0D
            });
            var Z = new Matrix(new double[] {
                0.0D, 1.0D, 0.0D,
                -1.0D, 0.0D, 0.0D,
                0.0D, 0.0D, 0D
            });

            var diag = new Matrix(new double[] {
                1.0D, 0.0D, 0.0D,
                0.0D, 1.0D, 0.0D,
                0.0D, 0.0D, 0.0D
            });


            foreach (var stereoPair in pairs)
            {
                var            points_count = stereoPair.intersection.Count;
                VectorOfPointF punten1px, punten2px;
                {
                    int           i  = 0;
                    List <PointF> p1 = new List <PointF>();
                    List <PointF> p2 = new List <PointF>();
                    foreach (KeyValuePair <ArucoMarker, ArucoMarker> kvp in stereoPair.intersection)
                    {
                        p1.Add(kvp.Key.Corner1);
                        p2.Add(kvp.Value.Corner1);
                        i++;
                    }
                    punten1px = new VectorOfPointF(p1.ToArray());
                    punten2px = new VectorOfPointF(p2.ToArray());
                }


                Matrix F      = new Matrix(3, 3);
                CVI.FindFundamentalMat(punten1px, punten2px, F);



                Matrix essential = K.Transpose() * F * K;
                var    decomp = new SVD <double>(essential);
                var    U      = decomp.U;
                var    Vt     = decomp.Vt;

                var R1 = U * W * Vt;
                var R2 = U * W.Transpose() * Vt;
                var T1 = U.GetCol(2);
                var T2 = -1 * U.GetCol(2);

                Matrix[] Ps = new Matrix[4];

                for (int i = 0; i < 4; i++)
                {
                    Ps[i] = new Matrix(3, 4);
                }

                CVI.HConcat(R1, T1, Ps[0]);
                CVI.HConcat(R1, T2, Ps[1]);
                CVI.HConcat(R2, T1, Ps[2]);
                CVI.HConcat(R2, T2, Ps[3]);

                var KPs = new Matrix[4];
                KPs[0] = K * Ps[0];
                KPs[1] = K * Ps[1];
                KPs[2] = K * Ps[2];
                KPs[3] = K * Ps[3];


                var KP0 = K * new Matrix(new double [, ] {
                    { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }
                });

                for (int i = 0; i < 4; i++)
                {
                    Matrix <float>     output_hom = new Matrix <float>(4, punten1px.Size);
                    VectorOfPoint3D32F output_3d  = new VectorOfPoint3D32F();

                    CVI.TriangulatePoints(KP0, KPs[i], punten1px, punten2px, output_hom);
                    CVI.ConvertPointsFromHomogeneous(output_hom, output_3d);
                }

                Matrix S = U * diag * W * U.Transpose();

                Matrix R = U * W * decomp.Vt;
            }
        }
예제 #25
0
        public static void Build14_21(World world)
        {
            world.ViewPlane           = new ViewPlane();
            world.ViewPlane.HRes      = 400;
            world.ViewPlane.VRes      = 400;
            world.ViewPlane.PixelSize = 1;
            world.ViewPlane.Gamma     = 1;
            //world.ViewPlane.SamplesCount = 25;
            world.ViewPlane.Sampler = new Hammersley(1, 16);
            world.BackgroundColor   = new RGBColor(0, 0, 0);
            world.Tracer            = new RayCast(world);
            world.AmbientLight      = new Ambient();

            PinholeCamera pinholeCamera = new PinholeCamera(850);

            pinholeCamera.SetUpCamera(
                new Vector3d(0, 0, 500),
                new Vector3d(5, 0, 0));
            world.Camera = pinholeCamera;

            Point pointLight = new Point();

            pointLight.Location   = new Vector3d(100, 50, 150);
            pointLight.LightScale = 3;
            world.AddLight(pointLight);

            //Sphere 1
            Matte matte1 = new Matte();

            matte1.KA    = 0.25;
            matte1.KD    = 0.65;
            matte1.Color = new RGBColor(1, 1, 0);

            Sphere sphere1 = new Sphere(new Point3d(10, 5, 0), 27);

            sphere1.Material = matte1;
            world.AddObject(sphere1);

            //Sphere 2
            Matte matte2 = new Matte();

            matte2.KA    = 0.15;
            matte2.KD    = 0.85;
            matte2.Color = new RGBColor(0.71, 0.40, 0.16);

            Sphere sphere2 = new Sphere(new Point3d(-25, 10, -35), 27);

            sphere2.Material = matte2;
            world.AddObject(sphere2);

            //Plane
            Matte matte3 = new Matte();

            matte3.KA    = 0.15;
            matte3.KD    = 0.5;
            matte3.Color = new RGBColor(0, 0.4, 0.2);

            Phong phong = new Phong();

            phong.KA    = 0;
            phong.KD    = 0;
            phong.KS    = 1;
            phong.Color = new RGBColor(0, 0.4, 0.2);

            Vector3d normal = new Vector3d(0, 1, 0);

            normal.Normalize();

            Plane plane = new Plane(new Point3d(0, -10, 0),
                                    normal);

            plane.Material = phong;
            world.AddObject(plane);
        }
예제 #26
0
        public static CeresCamera toCeresCamera(this PinholeCamera camera)
        {
            var cc = new CeresCamera(camera.Intrinsics.toCeresParameter(), camera.toCeresParameter());

            return(cc);
        }
예제 #27
0
        public static void SphereMappingTestRender()
        {
            Console.WriteLine("Loading file...");
            var filePath = Path.Combine(GetExecutionPath(), "winter_river_1k.ppm");

            Console.WriteLine("Parsing file...");
            var textureCanvas = PPM.ParseFile(filePath);
            var image         = new UVImage(textureCanvas);
            var map           = new TextureMap(image, UVMapping.Spherical);


            Sphere Sphere(float rotY, float rotX, float tx, float ty)
            {
                var s = new Sphere()
                {
                    Material = { Texture = map }
                };

                s.SetTransform(Transform.RotateY(rotY).RotateX(rotX).Translate(tx, ty, 0));
                return(s);
            }

            var g = new Group();

            g.AddChild(Sphere(0.7854f, 0.7854f, -6, 2));
            g.AddChild(Sphere(2.3562f, 0.7854f, -2, 2));
            g.AddChild(Sphere(3.927f, 0.7854f, 2, 2));
            g.AddChild(Sphere(5.4978f, 0.7854f, 6, 2));
            g.AddChild(Sphere(0.7854f, -0.7854f, -6, -2));
            g.AddChild(Sphere(2.3562f, -0.7854f, -2, -2));
            g.AddChild(Sphere(3.927f, -0.7854f, 2, -2));
            g.AddChild(Sphere(5.4978f, -0.7854f, 6, -2));

            g.Divide(1);

            var w = new World();

            w.SetLights(new PointLight(new Point(0, 2, -100), Colors.White));
            w.SetObjects(g);

            var width  = 800;
            var height = 400;
            var from   = new Point(0, 0, -20f);
            var to     = new Point(0, 0, 0);

            var canvas      = new Canvas(width, height);
            var pps         = new PerPixelSampler(16);
            var fov         = 0.8f;
            var aspectRatio = (float)width / height;
            var transform   = Transform.LookAt(from, to, new Vector(0, 1, 0));
            var camera      = new PinholeCamera(transform, fov, aspectRatio);
            var cws         = new PhongWorldShading(1, w);
            var ctx         = new RenderContext(canvas, new RenderPipeline(cws, camera, pps));

            Console.WriteLine("Rendering at {0}x{1}...", width, height);
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            ctx.Render();
            PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "mapping_spheres");
            stopwatch.Stop();
            Console.WriteLine("Done ({0})", stopwatch.Elapsed);
        }
예제 #28
0
 public static void VisualizeDistortions(PinholeCamera camera)
 {
     var          script = byteToString(Resources.visualize_distortions);
     const string fx     = "%fx%";
 }
예제 #29
0
        public MirrorScene()
        {
            FileName   = "Assignment1_Mirror.jpg";
            Integrator = (IIntegrator)Activator.CreateInstance(Constants.Integrator);
            Camera     = new PinholeCamera()
            {
                FieldOfViewX = 30f,
                FieldOfViewY = 30f,
                ScreenWidth  = 512,
                ScreenHeight = 512,
                Eye          = new Vector4(0, 0, 2, 1),
                Up           = new Vector4(0, 1, 0, 1),
                LookAt       = new Vector4(0, 0, 0, 1)
            };
            Camera.PreProcess();

            Film = new Film(Camera.ScreenWidth, Camera.ScreenHeight);

            //List of objects
            Sphere sphere = new Sphere(new BlinnPhongMaterial(new Color(0.8f, 0, 0), new Color(0.6f, 0.6f, 0.6f), 30f), new Vector3(0f, 0f, 0f), 0.2f);
            //Sphere sphere = new Sphere(new LambertMaterial(new Color(0.8f, 0.8f, 0.8f)), new Vector3(0f, 0f, 0f), 0.2f);

            Sphere sphere2 = new Sphere(new MirrorMaterial(0.8f), new Vector3(0.4f, 0.2f, -0.3f), .3f);
            Plane  p1      = new Plane(1f, new Vector3(0, 1, 0))
            {
                Name     = "P1",
                Material = new LambertMaterial(new Color(0f, 0.8f, 0.8f))
            };
            Plane p2 = new Plane(1f, new Vector3(0, 0, 1))
            {
                Name     = "P2",
                Material = new LambertMaterial(new Color(0.3f, 0.8f, 0.8f))
            };
            Plane p3 = new Plane(1f, new Vector3(-1, 0, 0))
            {
                Name     = "P3",
                Material = new LambertMaterial(new Color(1.0f, 0.8f, 0.8f))
            };
            Plane p4 = new Plane(1f, new Vector3(1, 0, 0))
            {
                Name     = "P4",
                Material = new LambertMaterial(new Color(0f, 0.8f, 0f))
            };
            Plane p5 = new Plane(1f, new Vector3(0, -1, 0))
            {
                Name     = "P5",
                Material = new LambertMaterial(new Color(0.8f, 0.8f, 0.8f))
            };

            /*int[] i = { 0, 1, 2, 2, 3, 0 };
             * Mesh rectangle = new Mesh(new LambertMaterial(new Color(0, 0, 1)), i,
             *      -.25f, .999998f, .25f,
             *      -.25f, .999999f, -.25f,
             *       .25f, .999999f, -.25f,
             *       .25f, .999998f, .25f);*/
            Rectangle rectangle = new Rectangle(new Vector3(-0.2f, .99f, 0f), new Vector3(.5f, 0, 0), new Vector3(0, 0, 0.5f))
            {
                Material = new LambertMaterial(new Color(0, 0, 1))
            };

            Objects = new IntersectableList();

            Objects.Add(rectangle);
            Objects.Add(sphere);
            Objects.Add(sphere2);
            Objects.Add(p1);
            Objects.Add(p2);
            Objects.Add(p3);
            Objects.Add(p4);
            Objects.Add(p5);

            Lights = new List <ILight>();
            ILight light  = new PointLight(new Vector3(0.0f, 0.8f, 0.8f), new Color(0.7f, 0.7f, 0.7f));
            ILight light2 = new PointLight(new Vector3(-0.8f, 0.2f, 0.0f), new Color(.5f, .5f, .5f));
            ILight light3 = new AreaLight(new Color(0.1f, 0.1f, 0.1f), rectangle);

            Lights.Add(light3);
            //Lights.Add(light2);
            //Lights.Add(light);
        }