Пример #1
0
 public bool Equals(FPoint3 other)
 {
     return
         (x == other.x &&
          y == other.y &&
          z == other.z);
 }
Пример #2
0
 public Point3 apply(FPoint3 p)
 {
     return(new Point3(
                (p.x * m[0, 0] + p.y * m[1, 0] + p.z * m[2, 0]),
                (p.x * m[0, 1] + p.y * m[1, 1] + p.z * m[2, 1]),
                (p.x * m[0, 2] + p.y * m[1, 2] + p.z * m[2, 2])));
 }
Пример #3
0
 public Point3 apply(FPoint3 p)
 {
     return new Point3(
         (p.x * m[0, 0] + p.y * m[1, 0] + p.z * m[2, 0]),
         (p.x * m[0, 1] + p.y * m[1, 1] + p.z * m[2, 1]),
         (p.x * m[0, 2] + p.y * m[1, 2] + p.z * m[2, 2]));
 }
Пример #4
0
 public FPoint3 Cross(FPoint3 p)
 {
     return(new FPoint3(
                y * p.z - z * p.y,
                z * p.x - x * p.z,
                x * p.y - y * p.x));
 }
Пример #5
0
        public static bool loadModelSTL_ascii(SimpleModel simpleModel, string filename, FMatrix3x3 matrix)
        {
            SimpleVolume vol = new SimpleVolume();

            using (StreamReader f = new StreamReader(filename))
            {
                // check for "SOLID"

                FPoint3 vertex           = new FPoint3();
                int     n                = 0;
                Point3  v0               = new Point3(0, 0, 0);
                Point3  v1               = new Point3(0, 0, 0);
                Point3  v2               = new Point3(0, 0, 0);
                string  line             = f.ReadLine();
                Regex   onlySingleSpaces = new Regex("\\s+", RegexOptions.Compiled);
                while (line != null)
                {
                    line = onlySingleSpaces.Replace(line, " ");
                    var parts = line.Trim().Split(' ');
                    if (parts[0].Trim() == "vertex")
                    {
                        vertex.x = Convert.ToDouble(parts[1]);
                        vertex.y = Convert.ToDouble(parts[2]);
                        vertex.z = Convert.ToDouble(parts[3]);

                        // change the scale from mm to micrometers
                        vertex *= 1000.0;

                        n++;
                        switch (n)
                        {
                        case 1:
                            v0 = matrix.apply(vertex);
                            break;

                        case 2:
                            v1 = matrix.apply(vertex);
                            break;

                        case 3:
                            v2 = matrix.apply(vertex);
                            vol.addFaceTriangle(v0, v1, v2);
                            n = 0;
                            break;
                        }
                    }
                    line = f.ReadLine();
                }
            }

            if (vol.faceTriangles.Count > 3)
            {
                simpleModel.volumes.Add(vol);
                return(true);
            }

            return(false);
        }
Пример #6
0
        public static bool loadModelSTL_ascii(SimpleModel simpleModel, string filename, FMatrix3x3 matrix)
        {
            SimpleVolume vol = new SimpleVolume();
            using (StreamReader f = new StreamReader(filename))
            {
                // check for "SOLID"

                FPoint3 vertex = new FPoint3();
                int n = 0;
                Point3 v0 = new Point3(0, 0, 0);
                Point3 v1 = new Point3(0, 0, 0);
                Point3 v2 = new Point3(0, 0, 0);
                string line = f.ReadLine();
                Regex onlySingleSpaces = new Regex("\\s+", RegexOptions.Compiled);
                while (line != null)
                {
                    line = onlySingleSpaces.Replace(line, " ");
                    var parts = line.Trim().Split(' ');
                    if (parts[0].Trim() == "vertex")
                    {
                        vertex.x = Convert.ToDouble(parts[1]);
                        vertex.y = Convert.ToDouble(parts[2]);
                        vertex.z = Convert.ToDouble(parts[3]);

                        // change the scale from mm to micrometers
                        vertex *= 1000.0;

                        n++;
                        switch (n)
                        {
                            case 1:
                                v0 = matrix.apply(vertex);
                                break;

                            case 2:
                                v1 = matrix.apply(vertex);
                                break;

                            case 3:
                                v2 = matrix.apply(vertex);
                                vol.addFaceTriangle(v0, v1, v2);
                                n = 0;
                                break;
                        }
                    }
                    line = f.ReadLine();
                }
            }

            if (vol.faceTriangles.Count > 3)
            {
                simpleModel.volumes.Add(vol);
                return true;
            }

            return false;
        }
Пример #7
0
        public void GenerateSupportGrid(OptimizedModel model, ConfigSettings config)
        {
            this.generated = false;
            if (config.supportEndAngle < 0)
            {
                return;
            }

            this.generated = true;

            this.gridOffset.X = model.minXYZ_um.x;
            this.gridOffset.Y = model.minXYZ_um.y;
            this.gridScale    = 200;
            this.gridWidth    = (model.size_um.x / this.gridScale) + 1;
            this.gridHeight   = (model.size_um.y / this.gridScale) + 1;
            int gridSize = this.gridWidth * this.gridHeight;

            this.xYGridOfSupportPoints = new List <List <SupportPoint> >(gridSize);
            for (int i = 0; i < gridSize; i++)
            {
                this.xYGridOfSupportPoints.Add(new List <SupportPoint>());
            }

            this.endAngleDegrees         = config.supportEndAngle;
            this.generateInternalSupport = config.generateInternalSupport;
            this.supportXYDistance_um    = config.supportXYDistance_um;
            this.supportLayerHeight_um   = config.layerThickness_um;
            this.supportZGapLayers       = config.supportNumberOfLayersToSkipInZ;
            this.supportInterfaceLayers  = config.supportInterfaceLayers;

            // This should really be a ray intersection as later code is going to count on it being an even odd list of bottoms and tops.
            // As it is we are finding the hit on the plane but not checking for good intersection with the triangle.
            for (int volumeIndex = 0; volumeIndex < model.volumes.Count; volumeIndex++)
            {
                OptimizedVolume vol = model.volumes[volumeIndex];
                for (int faceIndex = 0; faceIndex < vol.facesTriangle.Count; faceIndex++)
                {
                    OptimizedFace faceTriangle = vol.facesTriangle[faceIndex];
                    Point3        v0           = vol.vertices[faceTriangle.vertexIndex[0]].position;
                    Point3        v1           = vol.vertices[faceTriangle.vertexIndex[1]].position;
                    Point3        v2           = vol.vertices[faceTriangle.vertexIndex[2]].position;

                    // get the angle of this polygon
                    double angleFromHorizon;
                    {
                        FPoint3 v0f    = new FPoint3(v0);
                        FPoint3 v1f    = new FPoint3(v1);
                        FPoint3 v2f    = new FPoint3(v2);
                        FPoint3 normal = (v1f - v0f).Cross(v2f - v0f);
                        normal.z = Math.Abs(normal.z);

                        angleFromHorizon = (Math.PI / 2) - FPoint3.CalculateAngle(normal, FPoint3.Up);
                    }

                    v0.x = (int)((v0.x - this.gridOffset.X) / (double)this.gridScale + .5);
                    v0.y = (int)((v0.y - this.gridOffset.Y) / (double)this.gridScale + .5);
                    v1.x = (int)((v1.x - this.gridOffset.X) / (double)this.gridScale + .5);
                    v1.y = (int)((v1.y - this.gridOffset.Y) / (double)this.gridScale + .5);
                    v2.x = (int)((v2.x - this.gridOffset.X) / (double)this.gridScale + .5);
                    v2.y = (int)((v2.y - this.gridOffset.Y) / (double)this.gridScale + .5);

                    if (v0.x > v1.x)
                    {
                        swap(ref v0, ref v1);
                    }
                    if (v1.x > v2.x)
                    {
                        swap(ref v1, ref v2);
                    }
                    if (v0.x > v1.x)
                    {
                        swap(ref v0, ref v1);
                    }
                    for (long x = v0.x; x < v1.x; x++)
                    {
                        long y0 = (long)(v0.y + (v1.y - v0.y) * (x - v0.x) / (double)(v1.x - v0.x) + .5);
                        long y1 = (long)(v0.y + (v2.y - v0.y) * (x - v0.x) / (double)(v2.x - v0.x) + .5);
                        long z0 = (long)(v0.z + (v1.z - v0.z) * (x - v0.x) / (double)(v1.x - v0.x) + .5);
                        long z1 = (long)(v0.z + (v2.z - v0.z) * (x - v0.x) / (double)(v2.x - v0.x) + .5);

                        if (y0 > y1)
                        {
                            swap(ref y0, ref y1);
                            swap(ref z0, ref z1);
                        }

                        for (long y = y0; y < y1; y++)
                        {
                            SupportPoint newSupportPoint = new SupportPoint((int)(z0 + (z1 - z0) * (y - y0) / (double)(y1 - y0) + .5), angleFromHorizon);
                            this.xYGridOfSupportPoints[(int)(x + y * this.gridWidth)].Add(newSupportPoint);
                        }
                    }

                    for (int x = v1.x; x < v2.x; x++)
                    {
                        long y0 = (long)(v1.y + (v2.y - v1.y) * (x - v1.x) / (double)(v2.x - v1.x) + .5);
                        long y1 = (long)(v0.y + (v2.y - v0.y) * (x - v0.x) / (double)(v2.x - v0.x) + .5);
                        long z0 = (long)(v1.z + (v2.z - v1.z) * (x - v1.x) / (double)(v2.x - v1.x) + .5);
                        long z1 = (long)(v0.z + (v2.z - v0.z) * (x - v0.x) / (double)(v2.x - v0.x) + .5);

                        if (y0 > y1)
                        {
                            swap(ref y0, ref y1);
                            swap(ref z0, ref z1);
                        }

                        for (int y = (int)y0; y < y1; y++)
                        {
                            this.xYGridOfSupportPoints[x + y * this.gridWidth].Add(new SupportPoint((int)(z0 + (z1 - z0) * (double)(y - y0) / (double)(y1 - y0) + .5), angleFromHorizon));
                        }
                    }
                }
            }

            for (int x = 0; x < this.gridWidth; x++)
            {
                for (int y = 0; y < this.gridHeight; y++)
                {
                    int gridIndex = x + y * this.gridWidth;
                    List <SupportPoint> currentList = this.xYGridOfSupportPoints[gridIndex];
                    currentList.Sort(SortSupportsOnZ);

                    if (currentList.Count > 1)
                    {
                        // now remove duplicates (try to make it a better bottom and top list)
                        for (int i = currentList.Count - 1; i >= 1; i--)
                        {
                            if (currentList[i].z == currentList[i - 1].z)
                            {
                                currentList.RemoveAt(i);
                            }
                        }
                    }
                }
            }
            this.gridOffset.X += this.gridScale / 2;
            this.gridOffset.Y += this.gridScale / 2;
        }
Пример #8
0
 public static double Dot(FPoint3 left, FPoint3 right)
 {
     return(left.x * right.x + left.y * right.y + left.z * right.z);
 }
Пример #9
0
 public static double CalculateAngle(FPoint3 first, FPoint3 second)
 {
     return(Math.Acos((FPoint3.Dot(first, second)) / (first.Length * second.Length)));
 }
Пример #10
0
 public bool Equals(FPoint3 other)
 {
     return
         x == other.x &&
         y == other.y &&
         z == other.z;
 }
Пример #11
0
 public FPoint3 Cross(FPoint3 p)
 {
     return new FPoint3(
         y * p.z - z * p.y,
         z * p.x - x * p.z,
         x * p.y - y * p.x);
 }
Пример #12
0
 public static double Dot(FPoint3 left, FPoint3 right)
 {
     return left.x * right.x + left.y * right.y + left.z * right.z;
 }
Пример #13
0
 public static double CalculateAngle(FPoint3 first, FPoint3 second)
 {
     return Math.Acos((FPoint3.Dot(first, second)) / (first.Length * second.Length));
 }
Пример #14
0
        public void GenerateSupportGrid(OptimizedModel model, ConfigSettings config)
        {
            this.generated = false;
            if (config.supportEndAngle < 0)
            {
                return;
            }

            this.generated = true;

            this.gridOffset.X = model.minXYZ_um.x;
            this.gridOffset.Y = model.minXYZ_um.y;
            this.gridScale = 200;
            this.gridWidth = (model.size_um.x / this.gridScale) + 1;
            this.gridHeight = (model.size_um.y / this.gridScale) + 1;
            int gridSize = this.gridWidth * this.gridHeight;
            this.xYGridOfSupportPoints = new List<List<SupportPoint>>(gridSize);
            for (int i = 0; i < gridSize; i++)
            {
                this.xYGridOfSupportPoints.Add(new List<SupportPoint>());
            }

            this.endAngleDegrees = config.supportEndAngle;
            this.generateInternalSupport = config.generateInternalSupport;
            this.supportXYDistance_um = config.supportXYDistance_um;
            this.supportLayerHeight_um = config.layerThickness_um;
            this.supportZGapLayers = config.supportNumberOfLayersToSkipInZ;
            this.supportInterfaceLayers = config.supportInterfaceLayers;

            // This should really be a ray intersection as later code is going to count on it being an even odd list of bottoms and tops.
            // As it is we are finding the hit on the plane but not checking for good intersection with the triangle.
            for (int volumeIndex = 0; volumeIndex < model.volumes.Count; volumeIndex++)
            {
                OptimizedVolume vol = model.volumes[volumeIndex];
                for (int faceIndex = 0; faceIndex < vol.facesTriangle.Count; faceIndex++)
                {
                    OptimizedFace faceTriangle = vol.facesTriangle[faceIndex];
                    Point3 v0 = vol.vertices[faceTriangle.vertexIndex[0]].position;
                    Point3 v1 = vol.vertices[faceTriangle.vertexIndex[1]].position;
                    Point3 v2 = vol.vertices[faceTriangle.vertexIndex[2]].position;

                    // get the angle of this polygon
                    double angleFromHorizon;
                    {
                        FPoint3 v0f = new FPoint3(v0);
                        FPoint3 v1f = new FPoint3(v1);
                        FPoint3 v2f = new FPoint3(v2);
                        FPoint3 normal = (v1f - v0f).Cross(v2f - v0f);
                        normal.z = Math.Abs(normal.z);

                        angleFromHorizon = (Math.PI / 2) - FPoint3.CalculateAngle(normal, FPoint3.Up);
                    }

                    v0.x = (int)((v0.x - this.gridOffset.X) / (double)this.gridScale + .5);
                    v0.y = (int)((v0.y - this.gridOffset.Y) / (double)this.gridScale + .5);
                    v1.x = (int)((v1.x - this.gridOffset.X) / (double)this.gridScale + .5);
                    v1.y = (int)((v1.y - this.gridOffset.Y) / (double)this.gridScale + .5);
                    v2.x = (int)((v2.x - this.gridOffset.X) / (double)this.gridScale + .5);
                    v2.y = (int)((v2.y - this.gridOffset.Y) / (double)this.gridScale + .5);

                    if (v0.x > v1.x) swap(ref v0, ref v1);
                    if (v1.x > v2.x) swap(ref v1, ref v2);
                    if (v0.x > v1.x) swap(ref v0, ref v1);
                    for (long x = v0.x; x < v1.x; x++)
                    {
                        long y0 = (long)(v0.y + (v1.y - v0.y) * (x - v0.x) / (double)(v1.x - v0.x) + .5);
                        long y1 = (long)(v0.y + (v2.y - v0.y) * (x - v0.x) / (double)(v2.x - v0.x) + .5);
                        long z0 = (long)(v0.z + (v1.z - v0.z) * (x - v0.x) / (double)(v1.x - v0.x) + .5);
                        long z1 = (long)(v0.z + (v2.z - v0.z) * (x - v0.x) / (double)(v2.x - v0.x) + .5);

                        if (y0 > y1)
                        {
                            swap(ref y0, ref y1);
                            swap(ref z0, ref z1);
                        }

                        for (long y = y0; y < y1; y++)
                        {
                            SupportPoint newSupportPoint = new SupportPoint((int)(z0 + (z1 - z0) * (y - y0) / (double)(y1 - y0) + .5), angleFromHorizon);
                            this.xYGridOfSupportPoints[(int)(x + y * this.gridWidth)].Add(newSupportPoint);
                        }
                    }

                    for (int x = v1.x; x < v2.x; x++)
                    {
                        long y0 = (long)(v1.y + (v2.y - v1.y) * (x - v1.x) / (double)(v2.x - v1.x) + .5);
                        long y1 = (long)(v0.y + (v2.y - v0.y) * (x - v0.x) / (double)(v2.x - v0.x) + .5);
                        long z0 = (long)(v1.z + (v2.z - v1.z) * (x - v1.x) / (double)(v2.x - v1.x) + .5);
                        long z1 = (long)(v0.z + (v2.z - v0.z) * (x - v0.x) / (double)(v2.x - v0.x) + .5);

                        if (y0 > y1)
                        {
                            swap(ref y0, ref y1);
                            swap(ref z0, ref z1);
                        }

                        for (int y = (int)y0; y < y1; y++)
                        {
                            this.xYGridOfSupportPoints[x + y * this.gridWidth].Add(new SupportPoint((int)(z0 + (z1 - z0) * (double)(y - y0) / (double)(y1 - y0) + .5), angleFromHorizon));
                        }
                    }
                }
            }

            for (int x = 0; x < this.gridWidth; x++)
            {
                for (int y = 0; y < this.gridHeight; y++)
                {
                    int gridIndex = x + y * this.gridWidth;
                    List<SupportPoint> currentList = this.xYGridOfSupportPoints[gridIndex];
                    currentList.Sort(SortSupportsOnZ);

                    if (currentList.Count > 1)
                    {
                        // now remove duplicates (try to make it a better bottom and top list)
                        for (int i = currentList.Count - 1; i >= 1; i--)
                        {
                            if (currentList[i].z == currentList[i - 1].z)
                            {
                                currentList.RemoveAt(i);
                            }
                        }
                    }
                }
            }
            this.gridOffset.X += this.gridScale / 2;
            this.gridOffset.Y += this.gridScale / 2;
        }