//Copy b to this
 public Vector3Df Copy(Vector3Df b)
 {
     this.x = b.x;
     this.y = b.y;
     this.z = b.z;
     return this;
 }
        public static Vector3Df PerpVectorToPlane(Plane plane)
        {
            //Vector to return
            Vector3Df perpVector = new Vector3Df(0.0f, 0.0f, 0.0f);

            switch (plane)
            {
            //Perpindicular Vector in Z direction
            case Plane.XY:
            {
                perpVector.Set(0.0f, 0.0f, 1.0f);
                break;
            }

            //Perp. Vector in Y dir.
            case Plane.XZ:
            {
                perpVector.Set(0.0f, 1.0f, 0.0f);
                break;
            }

            //Perp. Vector in X dir.
            case Plane.YZ:
            {
                perpVector.Set(1.0f, 0.0f, 0.0f);
                break;
            }
            }

            //Get it
            return(perpVector);
        }
 //Add 2 vectors
 public Vector3Df Add(Vector3Df b)
 {
     this.x += b.x;
     this.y += b.y;
     this.z += b.z;
     return this;
 }
 //Component-wise Multplication
 public Vector3Df Mult(Vector3Df b)
 {
     this.x *= b.x;
     this.y *= b.y;
     this.z *= b.z;
     return this;
 }
Exemple #5
0
        //Map 2D Pixel Coordinates into 3D Vertices
        private static Vector3Df MapPixCoordToVertex(Vector2Df pix, Plane plane)
        {
            //Vertex to be returned
            Vector3Df vertex = new Vector3Df(0.0f, 0.0f, 0.0f);

            switch (plane)
            {
            //Zero out Z for XY Plane
            case Plane.XY:
            {
                vertex.x = pix.x;
                vertex.y = pix.y;
                vertex.z = 0.0f;
                break;
            }

            //Zero out X for YZ Plane
            //Notice that pix.x, pix.y are assigned in order
            //AKA pix.y is always assigned last
            // pix. x is always assigned first
            case Plane.YZ:
            {
                vertex.x = 0.0f;
                vertex.y = pix.x;
                vertex.z = pix.y;
                break;
            }

            //Zero out Y for XZ Plane
            case Plane.XZ:
            {
                vertex.x = pix.x;
                vertex.y = 0.0f;
                vertex.z = pix.y;
                break;
            }
            }

            //Just return it
            return(vertex);
        }
 //Basic constructor
 public Line(Vector3Df _p0, Vector3Df _p1)
 {
     p0 = _p0;
     p1 = _p1;
 }
Exemple #7
0
        //Create a vertex list
        public static List <Vector3Df> PixelsToVertices(Bitmap image, Plane plane, bool connectFirstAndLast)
        {
            //This is where we will store the geometry
            List <Vector3Df> geometry = new List <Vector3Df>();

            //Null check
            if (image is null)
            {
                return(geometry);
            }

            //Obtain normalized pixel coordinates
            List <Vector2Df> normCoords = BitmapToNormPixCoords(image);

            //normalized pixel coordinates not found
            if (normCoords.Count < 2)
            {
                return(geometry);
            }

            //Used to sort 'normCoords'
            List <NormPixCoordSortStruct> sortedNormCoords = new List <NormPixCoordSortStruct>();

            //Sort the normalized coordinates
            //Transform the Cartesian coordinate space of 'normCoords' into polar coordinates
            //This allows us to sort the normCoords by their angle wrt. the origin
            //This is done so that when normCoords are converted to vertices and stitched,
            //they follow a clockwise direction. Otherwise the stitching would occur based on
            //the traversal of the BitmapToNormCoords() function, which is not meaningful
            //By sorting the normCoords according to their angle wrt. the origin, we can sort
            //in a clockwise / counterclockwise manner, which ensures that when the stitching occurs,
            //it will provide a meanginful model / vertex list

            foreach (Vector2Df normCoord in normCoords)
            {
                //Populate sorting List<>
                sortedNormCoords.Add(new NormPixCoordSortStruct
                {
                    //preserve the normal coordinates
                    coord = normCoord,
                    //compute the angle wrt. horizontal thru origin
                    angle = Math.Atan2(normCoord.y - 0.5, normCoord.x - 0.5),
                    //compute Euclidean Distance (not squared)
                    //may be used later
                    mag = Math.Pow(normCoord.y - 0.5, 2.0) + Math.Pow(normCoord.x - 0.5, 2.0)
                });
            }

            //Sort, then replace normCoords with it's sorted counterpart
            sortedNormCoords.Sort(delegate(NormPixCoordSortStruct a, NormPixCoordSortStruct b)
            {
                return(a.angle.CompareTo(b.angle));
            });

            //Replace
            for (int i = 0; i < sortedNormCoords.Count; i++)
            {
                normCoords[i] = sortedNormCoords[i].coord;
            }

            //Add to geometry
            foreach (Vector2Df currentPixCoord in normCoords)
            {
                //Map prev pixel coordinates (2D) to vertices (3D)
                Vector3Df v0 = MapPixCoordToVertex(currentPixCoord, plane);
                //Add 1.0f to the component perpindicular to 'plane'
                //This creates a line with one point represented by the norm. pixel coord
                //and the other 1.0f 'into' the image space.
                //Same idea as having a piece of paper that represents the XY plane. One point of the line is visible,
                //the other is into the page (z direction) behind the one we can see
                Vector3Df v1 = MapPixCoordToVertex(currentPixCoord, plane).AddPerpToPlane(plane);

                //Add them to geometry
                geometry.Add(v0);
                geometry.Add(v1);
            }

            //Give them back to me!
            return(geometry);
        }