Example #1
0
        public static void SaveRectData(string filename, vtkPolyData polyData, Rectangle rect)
        {
            try
            {
                SimplePointFile.OpenWriteFile(filename);

                var color = polyData.GetPointData().GetScalars();

                for (var i = 0; i < rect.Height; i++)
                {
                    for (var j = 0; j < rect.Width; j++)
                    {
                        var data = polyData.GetPoint(i * rect.Width + j);
                        var c    = color.GetComponent(i * rect.Width + j, 0);

                        SimplePointFile.Writeline(new[] { data[0], data[1], data[2], c, c, c });
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                SimplePointFile.CloseWriteFile();
            }
        }
Example #2
0
        public static void SaveData(int ratio, string filename)
        {
            try
            {
                SimplePointFile.OpenWriteFile(filename);

                var color = PolyData.GetPointData().GetScalars();

                for (var i = 0; i < ImageHeight; i += ratio)
                {
                    for (var j = 0; j < ImageWidth; j += ratio)
                    {
                        var data = PolyData.GetPoint(i * ImageWidth + j);
                        var c    = color.GetComponent(i * ImageWidth + j, 0);
                        SimplePointFile.Writeline(new[] { data[0] / ratio, data[1] / ratio, data[2], c, c, c });
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                SimplePointFile.CloseWriteFile();
            }
        }
        public static void GetImageInfo(string filename)
        {
            ImageWidth  = 0;
            ImageHeight = 0;

            SimplePointFile.OpenReadFile(filename);

            int lines = 0;

            double[] pixels = { 0, 0 };
            double[] temp;
            while ((temp = SimplePointFile.ReadLine()) != null)
            {
                pixels = temp;
                lines++;
            }

            //Console.WriteLine("File Lines:" + lines);
            if (lines == ((int)pixels[0] + 1) * ((int)pixels[1] + 1))
            {
                ImageWidth  = (int)pixels[0] + 1;
                ImageHeight = (int)pixels[1] + 1;
            }
            else
            {
                throw new NotSupportedException("File Type Error!");
            }

            SimplePointFile.CloseReadFile();
        }
Example #4
0
        public static void ReadDataFromFile(string filename)
        {
            try
            {
                SimplePointFile.GetImageInfo(filename);

                ImageWidth  = SimplePointFile.ImageWidth;
                ImageHeight = SimplePointFile.ImageHeight;

                //Console.WriteLine("ImageWidth:" + ImageWidth);
                //Console.WriteLine("ImageHeight:" + ImageHeight);

                var points = vtkPoints.New();

                var colorArray = vtkUnsignedCharArray.New();
                colorArray.SetNumberOfComponents(3);

                ImageData = vtkImageData.New();
                ImageData.SetExtent(0, ImageWidth - 1, 0, ImageHeight - 1, 0, 0);
                ImageData.SetNumberOfScalarComponents(1);
                ImageData.SetScalarTypeToUnsignedChar();


                SimplePointFile.OpenReadFile(filename);
                double[] data;
                while ((data = SimplePointFile.ReadLine()) != null)
                {
                    points.InsertNextPoint(data[0], data[1], data[2]);
                    colorArray.InsertNextTuple3(data[3], data[4], data[5]);

                    ImageData.SetScalarComponentFromDouble((int)data[0], (int)data[1], 0, 0, data[3]);
                }

                PolyData = vtkPolyData.New();
                PolyData.SetPoints(points);
                PolyData.GetPointData().SetScalars(colorArray);
                PolyData.Update();

                //Console.WriteLine("PolyData & ImageData Load.");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            finally
            {
                SimplePointFile.CloseReadFile();
            }
        }
Example #5
0
        public static void UpdateDepthFormFile(string filename)
        {
            var points = vtkPoints.New();

            SimplePointFile.OpenReadFile(filename);
            double[] data;
            while ((data = SimplePointFile.ReadShortLine()) != null)
            {
                points.InsertNextPoint(data[0], data[1], data[2]);
            }

            PolyData.SetPoints(points);
            PolyData.Update();

            SimplePointFile.CloseReadFile();
        }