Esempio n. 1
0
 // Draw Graphics on the scene
 private void DrawPicture(Graphics gLeft, Graphics gRight, picCollection myP)
 {
     gLeft.DrawImage(myP.myImage, myP.myX, myP.myY, myP.myImage.Width * myP.myScale, myP.myImage.Height * myP.myScale);
     gRight.DrawImage(myP.myImage2, myP.myX - myP.myDepth, myP.myY, myP.myImage2.Width * myP.myScale, myP.myImage2.Height * myP.myScale);
 }
        private void startPaint()
        {
            if (startTimer) tmrAnimation.Enabled = true;

            myAllPicCollection = new List<picCollection>();

            LapCalculate();

            /*xv = xc/R2
            yv = yc/R2
            zv = zc/R2 (4)
            where xc, yc, zc denotes the coordinates of the objects
            in camera space, R denote the distance of the object from
            the camera system and xv, yv, zv is the virtual coordinate
            system on which all the regular image processing is done
            for the corresponding 2D image.

            [1]
             */
            setVirtualCoordinates();

            // Convert left image to bmp

            leftBitmap = new Bitmap(picLeft3D.Width, picLeft3D.Height);
            Graphics gLeft = Graphics.FromImage(leftBitmap);

            // set depths for each region based on previously calculated depth matrix
            setDepthHollimanMultiRegionAlgo(leftBitmap, depthMatrixX, depthMatrixY, depthMatrixZ);

            // Specifies whether smoothing (antialiasing) is applied to lines and curves and the edges of filled areas
            gLeft.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            // Convert right image to bmp
            rightBitmap = new Bitmap(picRight3D.Width, picRight3D.Height);

            // set depths for each region based on previously calculated depth matrix
            setDepthHollimanMultiRegionAlgo(rightBitmap, depthMatrixX, depthMatrixY, depthMatrixZ);

            Graphics gRight = Graphics.FromImage(rightBitmap); ;
            gRight.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            picLeft3D.BackgroundImage = null;

               // set left background image
                if (rdoBackgroundPic.Checked) picLeft3D.BackgroundImage = Properties.Resources.left;

            picLeft3D.BackColor = lblBackgroundColor.BackColor;

            int limitY = 0;

            #region  RUN : Scene depth to display depth

            double d1Temp = 0.03;

            // selecting objects (with 2 different pictures for left and right) for painting on the scene
            if (chk3dObjects.Checked)
            {
                if (pics3DLeft.Count > 0)
                {
                    for (int i = 1; i <= upd3dObjects.Value; i++)
                    {
                        try
                        {
                            myPicInfo = new picCollection();
                            int myImageNumber = myRandom.Next(pics3DLeft.Count);
                            myPicInfo.myImage = pics3DLeft[myImageNumber];
                            myPicInfo.myImage2 = pics3DRight[myImageNumber];

                            // Set d1 for eaach 3d image
                            myPicInfo.d1 = d1Temp;

                            // Increment depths(d1) of each image linearly
                            d1Temp = d1Temp + 1;

                            myPicInfo.myDepth = myPicInfo.setDepth();                                                                                                                                                                                        myPicInfo.myDepth = myRandom.Next(1, trbDepth3D.Value / 2); myPicInfo.myDepth = myRandom.Next(1, trbDepth3D.Value / 2);
                            myPicInfo.myScale = (float)(myRandom.NextDouble() * .7 + .4);
                            myPicInfo.myX = (myRandom.Next(myPicInfo.myDepth, picLeft3D.Width - myPicInfo.myImage.Width - myPicInfo.myDepth) % picLeft3D.Width) + myPicInfo.myDepth;
                            myPicInfo.myY = myRandom.Next(picLeft3D.Height - 100 - limitY);
                            myAllPicCollection.Add(myPicInfo);

                        }
                        catch (ArgumentOutOfRangeException)
                        {

                            continue;
                        }
                    }
                }
            }

            if (chkSimpleObjects.Checked)
            {
                frmBackgrounds frm = new frmBackgrounds();
                frm.Show();
            }
            #endregion

            // drawing all objects of the collection in order by depth on the scene
            for (int d = 0; d < 120; d++)
            {
                foreach (picCollection myP in myAllPicCollection)
                {
                    if (d == myP.myDepth) DrawPicture(gLeft, gRight, myP);
                }
              }

            // drawing vertical guid lines
            if (chkGuideLines.Checked)
            {
                for (int i = 0; i < 2; i++)
                {
                    gLeft.DrawLine(new Pen(lblGuideLine.BackColor, 5), i * picLeft3D.Width - 1, 0, i * (picLeft3D.Width - 1), picLeft3D.Height);
                    gRight.DrawLine(new Pen(lblGuideLine.BackColor, 5), i * picRight3D.Width - 1, 0, i * (picRight3D.Width - 1), picRight3D.Height);
                }
            }
            picLeft3D.Image = leftBitmap;
            picRight3D.Image = rightBitmap;
        }
Esempio n. 3
0
        private void startPaint()
        {
            if (startTimer)
            {
                tmrAnimation.Enabled = true;
            }

            myAllPicCollection = new List <picCollection>();

            LapCalculate();

            /*xv = xc/R2
             * yv = yc/R2
             * zv = zc/R2 (4)
             * where xc, yc, zc denotes the coordinates of the objects
             * in camera space, R denote the distance of the object from
             * the camera system and xv, yv, zv is the virtual coordinate
             * system on which all the regular image processing is done
             * for the corresponding 2D image.
             *
             * [1]
             */
            setVirtualCoordinates();

            // Convert left image to bmp

            leftBitmap = new Bitmap(picLeft3D.Width, picLeft3D.Height);
            Graphics gLeft = Graphics.FromImage(leftBitmap);

            // set depths for each region based on previously calculated depth matrix
            setDepthHollimanMultiRegionAlgo(leftBitmap, depthMatrixX, depthMatrixY, depthMatrixZ);

            // Specifies whether smoothing (antialiasing) is applied to lines and curves and the edges of filled areas
            gLeft.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            // Convert right image to bmp
            rightBitmap = new Bitmap(picRight3D.Width, picRight3D.Height);

            // set depths for each region based on previously calculated depth matrix
            setDepthHollimanMultiRegionAlgo(rightBitmap, depthMatrixX, depthMatrixY, depthMatrixZ);

            Graphics gRight = Graphics.FromImage(rightBitmap);;

            gRight.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            picLeft3D.BackgroundImage = null;

            // set left background image
            if (rdoBackgroundPic.Checked)
            {
                picLeft3D.BackgroundImage = Properties.Resources.left;
            }

            picLeft3D.BackColor = lblBackgroundColor.BackColor;


            int limitY = 0;

            #region  RUN : Scene depth to display depth

            double d1Temp = 0.03;

            // selecting objects (with 2 different pictures for left and right) for painting on the scene
            if (chk3dObjects.Checked)
            {
                if (pics3DLeft.Count > 0)
                {
                    for (int i = 1; i <= upd3dObjects.Value; i++)
                    {
                        try
                        {
                            myPicInfo = new picCollection();
                            int myImageNumber = myRandom.Next(pics3DLeft.Count);
                            myPicInfo.myImage  = pics3DLeft[myImageNumber];
                            myPicInfo.myImage2 = pics3DRight[myImageNumber];

                            // Set d1 for eaach 3d image
                            myPicInfo.d1 = d1Temp;

                            // Increment depths(d1) of each image linearly
                            d1Temp = d1Temp + 1;

                            myPicInfo.myDepth = myPicInfo.setDepth();                                                                                                                                                                                        myPicInfo.myDepth = myRandom.Next(1, trbDepth3D.Value / 2); myPicInfo.myDepth = myRandom.Next(1, trbDepth3D.Value / 2);
                            myPicInfo.myScale = (float)(myRandom.NextDouble() * .7 + .4);
                            myPicInfo.myX     = (myRandom.Next(myPicInfo.myDepth, picLeft3D.Width - myPicInfo.myImage.Width - myPicInfo.myDepth) % picLeft3D.Width) + myPicInfo.myDepth;
                            myPicInfo.myY     = myRandom.Next(picLeft3D.Height - 100 - limitY);
                            myAllPicCollection.Add(myPicInfo);
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                            continue;
                        }
                    }
                }
            }

            if (chkSimpleObjects.Checked)
            {
                frmBackgrounds frm = new frmBackgrounds();
                frm.Show();
            }
            #endregion

            // drawing all objects of the collection in order by depth on the scene
            for (int d = 0; d < 120; d++)
            {
                foreach (picCollection myP in myAllPicCollection)
                {
                    if (d == myP.myDepth)
                    {
                        DrawPicture(gLeft, gRight, myP);
                    }
                }
            }

            // drawing vertical guid lines
            if (chkGuideLines.Checked)
            {
                for (int i = 0; i < 2; i++)
                {
                    gLeft.DrawLine(new Pen(lblGuideLine.BackColor, 5), i * picLeft3D.Width - 1, 0, i * (picLeft3D.Width - 1), picLeft3D.Height);
                    gRight.DrawLine(new Pen(lblGuideLine.BackColor, 5), i * picRight3D.Width - 1, 0, i * (picRight3D.Width - 1), picRight3D.Height);
                }
            }
            picLeft3D.Image  = leftBitmap;
            picRight3D.Image = rightBitmap;
        }
 // Draw Graphics on the scene
 private void DrawPicture(Graphics gLeft, Graphics gRight, picCollection myP)
 {
     gLeft.DrawImage(myP.myImage, myP.myX, myP.myY, myP.myImage.Width * myP.myScale, myP.myImage.Height * myP.myScale);
     gRight.DrawImage(myP.myImage2, myP.myX - myP.myDepth, myP.myY, myP.myImage2.Width * myP.myScale, myP.myImage2.Height * myP.myScale);
 }