Пример #1
0
 public void Trasladar(VertexSLT T)
 {
     for (int i = 0; i < _Loops.Count; i++)
     {
         _Loops[i].Trasladar(T);
     }
 }
Пример #2
0
        private VertexSLT ProductoVectorialUnitario(VertexSLT V1, VertexSLT V2, VertexSLT V3, bool Unitario = true)
        {
            double V2x = V2.X - V1.X;
            double V2y = V2.Y - V1.Y;
            double V2z = V2.Z - V1.Z;

            double V3x = V3.X - V1.X;
            double V3y = V3.Y - V1.Y;
            double V3z = V3.Z - V1.Z;

            double X = (V2.Y * V3.Z) - (V2.Z * V3.Y);
            double Y = (V2.Z * V3.X) - (V2.X * V3.Z);
            double Z = (V2.X * V3.Y) - (V2.Y * V3.X);

            VertexSLT Res = new VertexSLT();

            if (Unitario)
            {
                double ModuloRes = Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2));

                Res = new VertexSLT(Convert.ToSingle(X / ModuloRes), Convert.ToSingle(Y / ModuloRes), Convert.ToSingle(Z / ModuloRes));
            }
            else
            {
                Res = new VertexSLT(Convert.ToSingle(X), Convert.ToSingle(Y), Convert.ToSingle(Z));
            }

            return(Res);
        }
Пример #3
0
        private IList <VertexSLT> Intersection(LoopSLT Loop)
        {
            IList <VertexSLT> Res = new List <VertexSLT>();

            VertexSLT TempVertex = new VertexSLT();
            bool      IntInterna = false;

            for (int i = 1; i < Loop.Vertices.Count; i++)
            {
                TempVertex = new VertexSLT();
                IntInterna = false;
                if (Intersection(Loop.Vertices[i - 1], Loop.Vertices[i], out TempVertex, out IntInterna))
                {
                    if (IntInterna)
                    {
                        Res.Add(TempVertex);
                    }
                }
            }

            TempVertex = new VertexSLT();
            IntInterna = false;
            if (Intersection(Loop.Vertices[0], Loop.Vertices[Loop.Vertices.Count - 1], out TempVertex, out IntInterna))
            {
                if (IntInterna)
                {
                    Res.Add(TempVertex);
                }
            }

            return(Res);
        }
Пример #4
0
 public StrokeSLT(Modes mode, VertexSLT destino, bool pendiente, double e)
 {
     Mode      = mode;
     Destino   = destino;
     Pendiente = pendiente;
     E         = e;
 }
Пример #5
0
 public StrokeSLT()
 {
     Mode      = Modes.ModeTraslation;
     Destino   = new VertexSLT(0.0, 0.0, 0.0);
     Pendiente = true;
     E         = 0.0;
 }
Пример #6
0
 public void Trasladar(VertexSLT T)
 {
     for (int i = 0; i < Vertices.Count; i++)
     {
         Vertices[i].Trasladar(T);
     }
 }
Пример #7
0
        public bool EsIgual(VertexSLT Valor)
        {
            bool         Res    = false;
            const double Margen = 0.00001;

            if (Math.Abs(X - Valor.X) < Margen)
            {
                if (Math.Abs(Y - Valor.Y) < Margen)
                {
                    if (Math.Abs(Z - Valor.Z) < Margen)
                    {
                        Res = true;
                    }
                }
            }

            return(Res);
        }
Пример #8
0
        private void _Inicializa()
        {
            //Inicializa las variables
            Nombre       = "";
            Fallos       = new List <string>();
            _Facets      = new List <FacetSLT>();
            _IzqFrontInf = new VertexSLT();
            _DerPostSup  = new VertexSLT();
            PassTest     = false;

            _Centro = new VertexSLT();
            _Ancho  = double.NaN;
            _Largo  = double.NaN;
            _Alto   = double.NaN;

            _Tx = 0.0;
            _Ty = 0.0;
            _Tz = 0.0;
        }
Пример #9
0
        private bool Intersection(VertexSLT V1, VertexSLT V2, out VertexSLT Interseccion, out bool Interna)
        {
            bool Res = false;

            try
            {
                Interseccion = new VertexSLT();
                Interna      = false;

                VertexSLT Direccion = new VertexSLT(V2.X - V1.X, V2.Y - V1.Y, V2.Z - V1.Z);

                VertexSLT NormalPlanoZ = new VertexSLT(0.0, 0.0, 1.0);
                double    D            = -ZCalculo;

                double t = ((NormalPlanoZ.X * V1.X) + (NormalPlanoZ.Y * V1.Y) + (NormalPlanoZ.Z * V1.Z) + D)
                           / (-(NormalPlanoZ.X * Direccion.X) - (NormalPlanoZ.Y * Direccion.Y) - (NormalPlanoZ.Z * Direccion.Z));

                Interseccion = new VertexSLT(V1.X + t * Direccion.X, V1.Y + t * Direccion.Y, V1.Z + t * Direccion.Z);

                Res = true;

                if (0.0 <= t && t <= 1.0)
                {
                    Interna = true;
                }
            }
            catch (System.Exception sysEx)
            {
                sysEx.Data.Clear();
                Res          = false;
                Interseccion = new VertexSLT();
                Interna      = false;
            }

            return(Res);
        }
Пример #10
0
 public FacetSLT()
 {
     _Normal    = new VertexSLT();
     _Attribute = 0;
     _Loops     = new List <LoopSLT>();
 }
Пример #11
0
        public bool TestSLT()
        {
            bool Res = true;

            //http://www.ennex.com/~fabbers/StL.asp

            //Verifica la Orientación de cada faceta.
            foreach (FacetSLT F in _Facets)
            {
                foreach (LoopSLT L in F._Loops)
                {
                    if (L.Vertices.Count() >= 3)
                    {
                        VertexSLT TempV = ProductoVectorialUnitario(L.Vertices[0], L.Vertices[1], L.Vertices[2], true);
                        if (F._Normal.EsIgual(TempV))
                        {
                            //OK
                        }
                        else
                        {
                            //Redefino el vector normal
                            F._Normal = TempV;
                        }
                    }
                    else
                    {
                        //Fallo, cara con menos de tres vértices
                        Res = false;
                        Fallos.Add("Test SLT: Loop con menos de 3 vértices");
                    }
                }
            }

            //Verifica la Regla vértice a vértice.
            //Cada vértice tiene que existir por lo menos 3 veces
            IList <KeyValuePair <VertexSLT, byte> > ConteoVertices = new List <KeyValuePair <VertexSLT, byte> >();

            //Cargo el resumen de vértices verificando que no se dupliquen
            foreach (FacetSLT F in _Facets)
            {
                foreach (LoopSLT L in F._Loops)
                {
                    foreach (VertexSLT V in L.Vertices)
                    {
                        bool      Ex        = false;
                        VertexSLT TempV     = new VertexSLT();
                        byte      TempCount = 0;

                        for (int iV = 0; iV < ConteoVertices.Count(); iV++)
                        {
                            if (ConteoVertices[iV].Key.EsIgual(V))
                            {
                                Ex = true;

                                TempV     = ConteoVertices[iV].Key;
                                TempCount = ConteoVertices[iV].Value;

                                ConteoVertices.RemoveAt(iV);

                                TempCount++;
                                ConteoVertices.Add(new KeyValuePair <VertexSLT, byte>(TempV, TempCount));
                                break;
                            }
                        }

                        if (!Ex)
                        {
                            ConteoVertices.Add(new KeyValuePair <VertexSLT, byte>(V, 1));
                        }
                    }
                }
            }

            //Verifico el resumen de vértices
            for (int i = 0; i < ConteoVertices.Count(); i++)
            {
                if (ConteoVertices[i].Value < 3)
                {
                    Res = false;
                    Fallos.Add("Test SLT: Fallo en la Regla vértice a vértice");
                }
            }

            PassTest = Res;

            return(Res);
        }
Пример #12
0
        private bool _LeeSLTASCII(String FicheroSLT)
        {
            /*****ASCII STL
             *
             * An ASCII STL file begins with the line:
             *
             *  solid name
             *
             * Where name is an optional string (though if name is omitted there must still be a space after solid). The file continues with any number of triangles, each represented as follows:
             *
             *  facet normal ni nj nk
             *      outer loop
             *          vertex v1x v1y v1z
             *          vertex v2x v2y v2z
             *          vertex v3x v3y v3z
             *      endloop
             *  endfacet
             *
             * Where each n or v is a doubleing-point number in sign-mantissa-"e"-sign-exponent format, e.g., "2.648000e-002" (noting that each v must be non-negative). The file concludes with:
             *
             *  endsolid name
             *
             * The structure of the format suggests that other possibilities exist (e.g., facets with more than one "loop", or loops with more than three vertices). In practice, however, all facets are simple triangles.
             *
             * White space (spaces, tabs, newlines) may be used anywhere in the file except within numbers or words. The spaces between "facet" and "normal" and between "outer" and "loop" are required.*/

            bool Res = true;

            System.IO.StreamReader SR = new System.IO.StreamReader(FicheroSLT, Encoding.ASCII);
            //Evalua si es binario o ASCII
            string LineaSLT = SR.ReadLine();

            LineaSLT = LineaSLT.TrimStart(new char[2] {
                ' ', '\t'
            });

            if (LineaSLT.StartsWith("solid "))
            {
                Nombre = LineaSLT.Substring(5);

                bool FinSolido   = false;
                bool EnFacet     = false;
                bool EnOuterLoop = false;

                VertexSLT TempVertex = new VertexSLT();
                LoopSLT   TempLoop   = new LoopSLT();
                FacetSLT  TempFacet  = new FacetSLT();

                do
                {
                    LineaSLT = SR.ReadLine();

                    LineaSLT = LineaSLT.TrimStart(new char[2] {
                        ' ', '\t'
                    });

                    if (LineaSLT.StartsWith("facet normal "))
                    {
                        //facet normal ni nj nk
                        if (EnOuterLoop)
                        {
                            Fallos.Add("Lectura SLT ASCII: Nueva Faceta sin cierre correcto de Vértices");
                            Res = false;
                        }
                        else
                        {
                            //Obtengo el Vertex Normal y lo almaceno
                            LineaSLT = LineaSLT.Substring(12);
                            string[] TempStr = LineaSLT.Split(' ');
                            if (TempStr.Length == 3)
                            {
                                TempFacet._Normal = new VertexSLT(Convert.ToSingle(TempStr[0]), Convert.ToSingle(TempStr[1]), Convert.ToSingle(TempStr[2]));
                            }
                            else
                            {
                                Fallos.Add("Lectura SLT ASCII: El Vector Normal de la Faceta no tiene 3 domensiones");
                                Res = false;
                            }
                        }

                        EnFacet = true;
                    }
                    else if (LineaSLT == "outer loop")
                    {
                        if (EnOuterLoop)
                        {
                            Fallos.Add("Lectura SLT ASCII: Inicio de Loop sin cierre del anterior");
                            Res = false;
                        }
                        else
                        {
                            EnOuterLoop = true;
                        }
                    }
                    else if (LineaSLT.StartsWith("vertex "))
                    {
                        if (EnOuterLoop && EnFacet)
                        {
                            //vertex v1x v1y v1z
                            LineaSLT = LineaSLT.Substring(6);
                            string[] TempStr = LineaSLT.Split(' ');
                            if (TempStr.Length == 3)
                            {
                                TempLoop.Vertices.Add(new VertexSLT(Convert.ToSingle(TempStr[0]), Convert.ToSingle(TempStr[1]), Convert.ToSingle(TempStr[2])));
                            }
                            else
                            {
                                Fallos.Add("Lectura SLT ASCII: Un Vértice de la Faceta no tiene 3 domensiones");
                                Res = false;
                            }
                        }
                        else
                        {
                            Fallos.Add("Lectura SLT ASCII: Vértice fuera de un Loop o una Faceta");
                            Res = false;
                        }
                    }
                    else if (LineaSLT == "endloop" || LineaSLT == "end loop")
                    {
                        if (EnOuterLoop)
                        {
                            TempLoop.ActualizaBoundingZ();
                            TempFacet._Loops.Add(TempLoop);
                        }
                        else
                        {
                            Fallos.Add("Lectura SLT ASCII: Cierre de Loop incorrecto");
                            Res = false;
                        }

                        TempLoop    = new LoopSLT();
                        EnOuterLoop = false;
                    }
                    else if (LineaSLT == "endfacet" || LineaSLT == "end facet")
                    {
                        if (EnFacet)
                        {
                            if (TempFacet.EsValido())
                            {
                                _Facets.Add(TempFacet);
                            }
                            else
                            {
                                Fallos.Add("Lectura SLT ASCII: Faceta no válida");
                                Res = false;
                            }
                        }
                        else
                        {
                            Fallos.Add("Lectura SLT ASCII: Fin de Faceta no válida");
                            Res = false;
                        }

                        TempFacet = new FacetSLT();
                        EnFacet   = false;
                    }
                    else if (LineaSLT == "endsolid " + Nombre)
                    {
                        //Fin de sólido
                        if (!EnFacet && !EnOuterLoop)
                        {
                            FinSolido = true;
                        }
                        else
                        {
                            Fallos.Add("Lectura SLT ASCII: Fin de solido sin cierre correcto de Facetas o Vértices");
                            Res = false;
                        }
                    }
                    else
                    {
                        //No contemplado
                    }
                }while (!SR.EndOfStream || !FinSolido);
            }
            else
            {
                Res = false;
                Fallos.Add("Lectura SLT ASCII: El Fichero no comienza por 'solid '");
            }
            SR.Close();
            SR.Dispose();

            return(Res);
        }
Пример #13
0
        public bool LeeSLT(String FicheroSLT)
        {
            bool Res = false;

            OnReading(EventArgs.Empty);

            _Inicializa();

            System.IO.StreamReader SR = new System.IO.StreamReader(FicheroSLT, Encoding.ASCII);
            //Evalua si es binario o ASCII
            string PrimeraLineaSLT = SR.ReadLine();

            SR.Close();
            SR.Dispose();

            if (PrimeraLineaSLT.StartsWith("solid "))
            {
                //ASCII
                Res = _LeeSLTASCII(FicheroSLT);
            }
            else
            {
                //Binario
                Res = _LeeSLTBinario(FicheroSLT);
            }

            //Obtiene las esquinas del BowndingBox
            if (_Facets.Count > 0)
            {
                foreach (FacetSLT F in _Facets)
                {
                    foreach (LoopSLT L in F._Loops)
                    {
                        foreach (VertexSLT V in L.Vertices)
                        {
                            //compara mínimos con _Izq
                            if (double.IsNaN(_IzqFrontInf.X) || V.X < _IzqFrontInf.X)
                            {
                                _IzqFrontInf = new VertexSLT(V.X, _IzqFrontInf.Y, _IzqFrontInf.Z);
                            }
                            if (double.IsNaN(_IzqFrontInf.Y) || V.Y < _IzqFrontInf.Y)
                            {
                                _IzqFrontInf = new VertexSLT(_IzqFrontInf.X, V.Y, _IzqFrontInf.Z);
                            }
                            if (double.IsNaN(_IzqFrontInf.Z) || V.Z < _IzqFrontInf.Z)
                            {
                                _IzqFrontInf = new VertexSLT(_IzqFrontInf.X, _IzqFrontInf.Y, V.Z);
                            }

                            //compara máximos con _Der
                            if (double.IsNaN(_DerPostSup.X) || V.X > _DerPostSup.X)
                            {
                                _DerPostSup = new VertexSLT(V.X, _DerPostSup.Y, _DerPostSup.Z);
                            }
                            if (double.IsNaN(_DerPostSup.Y) || V.Y > _DerPostSup.Y)
                            {
                                _DerPostSup = new VertexSLT(_DerPostSup.X, V.Y, _DerPostSup.Z);
                            }
                            if (double.IsNaN(_DerPostSup.Z) || V.Z > _DerPostSup.Z)
                            {
                                _DerPostSup = new VertexSLT(_DerPostSup.X, _DerPostSup.Y, V.Z);
                            }
                        }
                    }
                }
            }
            else
            {
                _IzqFrontInf = new VertexSLT();
                _DerPostSup  = new VertexSLT();
            }

            return(Res);
        }
Пример #14
0
 public void Trasladar(VertexSLT T)
 {
     X  += T.X;
     Y  += T.Y;
     _Z += T.Z;
 }