Example #1
0
        public Tuple <float, float> convertFromTo(ObjFigure objFigureData, string[] vertecData,
                                                  float[] scaleData, float[] translateData)
        {
            StlWriter stlObjWriter = new StlWriter();

            float area   = 0;
            float volume = 0;

            List <int> elements = stringProcessing(vertecData);

            int triangleCount = elements.Count() - 2;

            for (int i = 0; i < triangleCount; i++)
            {
                StlFigure stlFigure = new StlFigure();

                StlFigure newStlFigure = new StlFigure();

                stlFigure.Verteces.Add(objFigureData.Verteces.ElementAt(elements.ElementAt(0) - 1));

                stlFigure.Verteces.Add(objFigureData.Verteces.ElementAt(elements.ElementAt(i + 1) - 1));

                stlFigure.Verteces.Add(objFigureData.Verteces.ElementAt(elements.ElementAt(i + 2) - 1));

                stlObjWriter.stlFormatWrite(stlFigure);

                area   += stlFigure.calculateFacetArea();
                volume += stlFigure.calculateFacetVolume();
            }

            return(Tuple.Create(area, volume));
        }
Example #2
0
        public void stlFormatWrite(StlFigure stlFigure)
        {
            string path          = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\figureBin.stl";
            UInt16 attributeByte = 0;

            using (BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Append))){
                writer.Write((float)0);
                writer.Write((float)0);
                writer.Write((float)0);

                writer.Write(stlFigure.Verteces.ElementAt(0).X);
                writer.Write(stlFigure.Verteces.ElementAt(0).Y);
                writer.Write(stlFigure.Verteces.ElementAt(0).Z);

                writer.Write(stlFigure.Verteces.ElementAt(1).X);
                writer.Write(stlFigure.Verteces.ElementAt(1).Y);
                writer.Write(stlFigure.Verteces.ElementAt(1).Z);

                writer.Write(stlFigure.Verteces.ElementAt(2).X);
                writer.Write(stlFigure.Verteces.ElementAt(2).Y);
                writer.Write(stlFigure.Verteces.ElementAt(2).Z);

                writer.Write(attributeByte);
            }
        }