Esempio n. 1
0
        public Bitmap Render(IImageRaster <IRaster3DInteger, bool> source_image)
        {
            IRaster3DInteger source_raster = source_image.Raster;
            List <int>       elements_true = source_image.GetElementIndexesWithValue(true);

            float[,] coordinates_image   = new float[elements_true.Count, 3];
            float[,] elements_projection = new float[elements_true.Count, 3];
            int [] coordinates = new int [3];

            for (int element_index_index = 0; element_index_index < elements_true.Count; element_index_index++)
            {
                source_raster.GetElementCoordinatesRBA(elements_true[element_index_index], coordinates);
                coordinates_image[element_index_index, 0] = coordinates[0];
                coordinates_image[element_index_index, 1] = coordinates[1];
                coordinates_image[element_index_index, 2] = coordinates[2];
            }

            for (int element_index = 0; element_index < elements_true.Count; element_index++)
            {
                elements_projection[element_index, 0] = ((coordinates_image[element_index, 0] - image_focus[0]) * projection_vector_x[0]) +
                                                        ((coordinates_image[element_index, 1] - image_focus[1]) * projection_vector_x[1]) +
                                                        ((coordinates_image[element_index, 2] - image_focus[2]) * projection_vector_x[2]);

                elements_projection[element_index, 1] = ((coordinates_image[element_index, 0] - image_focus[0]) * projection_vector_y[0]) +
                                                        ((coordinates_image[element_index, 1] - image_focus[1]) * projection_vector_y[1]) +
                                                        ((coordinates_image[element_index, 2] - image_focus[2]) * projection_vector_y[2]);

                elements_projection[element_index, 2] = ((coordinates_image[element_index, 0] - image_focus[0]) * projection_vector_z[0]) +
                                                        ((coordinates_image[element_index, 1] - image_focus[1]) * projection_vector_z[1]) +
                                                        ((coordinates_image[element_index, 2] - image_focus[2]) * projection_vector_z[2]);
            }

            Raster2DInteger bitmap_raster     = new Raster2DInteger(bitmap_size_x, bitmap_size_y);
            Bitmap          destination_image = new Bitmap(bitmap_size_x, bitmap_size_y);

            for (int index_y = 0; index_y < bitmap_raster.Size1; index_y++)
            {
                for (int index_x = 0; index_x < bitmap_raster.Size0; index_x++)
                {
                    destination_image.SetPixel(index_x, index_y, Color.Black);
                }
            }

            for (int element_index = 0; element_index < elements_true.Count; element_index++)
            {
                int x_target = (int)elements_projection[element_index, 0] + (bitmap_raster.Size0 / 2);
                int y_target = (int)elements_projection[element_index, 1] + (bitmap_raster.Size1 / 2);

                if (bitmap_raster.ContainsCoordinates(x_target, y_target))
                {
                    destination_image.SetPixel(x_target, y_target, Color.White);
                }
            }
            return(destination_image);
        }
        public IImageRaster <IRaster2DInteger, bool> Render(Tuple <List <int>, IRaster3DInteger> render_source)
        {
            List <int>       elements_true = render_source.Item1;
            IRaster3DInteger source_raster = render_source.Item2;

            float[,] coordinates_image   = new float[elements_true.Count, 3];
            float[,] elements_projection = new float[elements_true.Count, 3];
            int [] coordinates = new int [3];

            for (int element_index_index = 0; element_index_index < elements_true.Count; element_index_index++)
            {
                source_raster.GetElementCoordinatesRBA(elements_true[element_index_index], coordinates);
                coordinates_image[element_index_index, 0] = coordinates[0];
                coordinates_image[element_index_index, 1] = coordinates[1];
                coordinates_image[element_index_index, 2] = coordinates[2];
            }

            for (int element_index = 0; element_index < elements_true.Count; element_index++)
            {
                elements_projection[element_index, 0] = ((coordinates_image[element_index, 0] - image_focus[0]) * projection_vector_x[0]) +
                                                        ((coordinates_image[element_index, 1] - image_focus[1]) * projection_vector_x[1]) +
                                                        ((coordinates_image[element_index, 2] - image_focus[2]) * projection_vector_x[2]);

                elements_projection[element_index, 1] = ((coordinates_image[element_index, 0] - image_focus[0]) * projection_vector_y[0]) +
                                                        ((coordinates_image[element_index, 1] - image_focus[1]) * projection_vector_y[1]) +
                                                        ((coordinates_image[element_index, 2] - image_focus[2]) * projection_vector_y[2]);

                elements_projection[element_index, 2] = ((coordinates_image[element_index, 0] - image_focus[0]) * projection_vector_z[0]) +
                                                        ((coordinates_image[element_index, 1] - image_focus[1]) * projection_vector_z[1]) +
                                                        ((coordinates_image[element_index, 2] - image_focus[2]) * projection_vector_z[2]);
            }

            Raster2DInteger      bitmap_raster     = new Raster2DInteger(bitmap_size_x, bitmap_size_y);
            ImageRaster2D <bool> destination_image = new ImageRaster2D <bool>(bitmap_size_x, bitmap_size_y);

            for (int element_index = 0; element_index < elements_true.Count; element_index++)
            {
                int x_target = (int)elements_projection[element_index, 0] + (bitmap_raster.Size0 / 2);
                int y_target = (int)elements_projection[element_index, 1] + (bitmap_raster.Size1 / 2);

                if (bitmap_raster.ContainsCoordinates(x_target, y_target))
                {
                    destination_image.SetElementValue(x_target, y_target, true);
                }
            }
            return(destination_image);
        }
Esempio n. 3
0
        public BitmapFast Render(Tuple <double[][], Color[]> render_image)
        {
            double[][]  points           = render_image.Item1;
            Color[]     colors           = render_image.Item2;
            double [][] projected_points = new double [points.Length][];
            int[]       coordinates      = new int[3];

            for (int point_index = 0; point_index < points.Length; point_index++)
            {
                projected_points[point_index] = (projection_matrix * (points[point_index] - offset_matrix)).ToArray1DFloat64();
            }



            Raster2DInteger bitmap_raster     = new Raster2DInteger(bitmap_size_x, bitmap_size_y);
            BitmapFast      destination_image = new BitmapFast(this.bitmap_size_x, this.bitmap_size_y);

            destination_image.Lock();
            for (int index_y = 0; index_y < bitmap_raster.Size1; index_y++)
            {
                for (int index_x = 0; index_x < bitmap_raster.Size0; index_x++)
                {
                    destination_image.SetPixel(index_x, index_y, Color.Black);
                }
            }


            for (int element_index = 0; element_index < points.Length; element_index++)
            {
                int x_target = (int)(projected_points[element_index][0] * this.scale) + (bitmap_raster.Size0 / 2);
                int y_target = (int)(projected_points[element_index][1] * this.scale) + (bitmap_raster.Size1 / 2);

                if (bitmap_raster.ContainsCoordinates(x_target, y_target))
                {
                    destination_image.SetPixel(x_target, y_target, colors[element_index]);
                }
            }

            destination_image.Unlock();
            return(destination_image);
        }