Exemplo n.º 1
0
 public void BasicTest()
 {
     Utilities.Math.Vector3 TestObject = new Utilities.Math.Vector3(2.5, 4.1, 1.3);
     Assert.InRange(TestObject.Magnitude, 4.97, 4.98);
     TestObject.Normalize();
     Assert.InRange(TestObject.X, .5, .6);
     Assert.InRange(TestObject.Y, .82, .83);
     Assert.InRange(TestObject.Z, .26, .27);
 }
Exemplo n.º 2
0
 public void BasicTest()
 {
     Utilities.Math.Vector3 TestObject = new Utilities.Math.Vector3(2.5, 4.1, 1.3);
     Assert.InRange(TestObject.Magnitude, 4.97, 4.98);
     TestObject.Normalize();
     Assert.InRange(TestObject.X, .5, .6);
     Assert.InRange(TestObject.Y, .82, .83);
     Assert.InRange(TestObject.Z, .26, .27);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates the bump map
 /// </summary>
 public virtual Bitmap Create(Bitmap ImageUsing)
 {
     if (ImageUsing == null)
     {
         throw new ArgumentNullException("ImageUsing");
     }
     CreateFilter();
     using (Bitmap TempImageX = FilterX.Create(ImageUsing))
     {
         using (Bitmap TempImageY = FilterY.Create(ImageUsing))
         {
             Bitmap       ReturnImage          = new Bitmap(TempImageX.Width, TempImageX.Height);
             Math.Vector3 TempVector           = new Utilities.Math.Vector3(0.0, 0.0, 0.0);
             BitmapData   TempImageXData       = TempImageX.LockImage();
             BitmapData   TempImageYData       = TempImageY.LockImage();
             BitmapData   ReturnImageData      = ReturnImage.LockImage();
             int          TempImageXPixelSize  = TempImageXData.GetPixelSize();
             int          TempImageYPixelSize  = TempImageYData.GetPixelSize();
             int          ReturnImagePixelSize = ReturnImageData.GetPixelSize();
             for (int y = 0; y < TempImageX.Height; ++y)
             {
                 for (int x = 0; x < TempImageX.Width; ++x)
                 {
                     Color TempPixelX = TempImageXData.GetPixel(x, y, TempImageXPixelSize);
                     Color TempPixelY = TempImageYData.GetPixel(x, y, TempImageYPixelSize);
                     TempVector.X = (double)(TempPixelX.R) / 255.0;
                     TempVector.Y = (double)(TempPixelY.R) / 255.0;
                     TempVector.Z = 1.0;
                     TempVector.Normalize();
                     TempVector.X = ((TempVector.X + 1.0) / 2.0) * 255.0;
                     TempVector.Y = ((TempVector.Y + 1.0) / 2.0) * 255.0;
                     TempVector.Z = ((TempVector.Z + 1.0) / 2.0) * 255.0;
                     ReturnImageData.SetPixel(x, y,
                                              Color.FromArgb((int)TempVector.X,
                                                             (int)TempVector.Y,
                                                             (int)TempVector.Z),
                                              ReturnImagePixelSize);
                 }
             }
             TempImageX.UnlockImage(TempImageXData);
             TempImageY.UnlockImage(TempImageYData);
             ReturnImage.UnlockImage(ReturnImageData);
             return(ReturnImage);
         }
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Creates the bump map
 /// </summary>
 public virtual Bitmap Create(Bitmap ImageUsing)
 {
     ImageUsing.ThrowIfNull("ImageUsing");
     CreateFilter();
     using (Bitmap TempImageX = FilterX.Create(ImageUsing))
     {
         using (Bitmap TempImageY = FilterY.Create(ImageUsing))
         {
             Bitmap     ReturnImage          = new Bitmap(TempImageX.Width, TempImageX.Height);
             BitmapData TempImageXData       = TempImageX.LockImage();
             BitmapData TempImageYData       = TempImageY.LockImage();
             BitmapData ReturnImageData      = ReturnImage.LockImage();
             int        TempImageXPixelSize  = TempImageXData.GetPixelSize();
             int        TempImageYPixelSize  = TempImageYData.GetPixelSize();
             int        ReturnImagePixelSize = ReturnImageData.GetPixelSize();
             int        Width  = TempImageX.Width;
             int        Height = TempImageX.Height;
             Parallel.For(0, Height, y =>
             {
                 Math.Vector3 TempVector = new Utilities.Math.Vector3(0.0, 0.0, 0.0);
                 for (int x = 0; x < Width; ++x)
                 {
                     Color TempPixelX = TempImageXData.GetPixel(x, y, TempImageXPixelSize);
                     Color TempPixelY = TempImageYData.GetPixel(x, y, TempImageYPixelSize);
                     TempVector.X     = (double)(TempPixelX.R) / 255.0;
                     TempVector.Y     = (double)(TempPixelY.R) / 255.0;
                     TempVector.Z     = 1.0;
                     TempVector.Normalize();
                     TempVector.X = ((TempVector.X + 1.0) / 2.0) * 255.0;
                     TempVector.Y = ((TempVector.Y + 1.0) / 2.0) * 255.0;
                     TempVector.Z = ((TempVector.Z + 1.0) / 2.0) * 255.0;
                     ReturnImageData.SetPixel(x, y,
                                              Color.FromArgb((int)TempVector.X,
                                                             (int)TempVector.Y,
                                                             (int)TempVector.Z),
                                              ReturnImagePixelSize);
                 }
             });
             TempImageX.UnlockImage(TempImageXData);
             TempImageY.UnlockImage(TempImageYData);
             ReturnImage.UnlockImage(ReturnImageData);
             return(ReturnImage);
         }
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates the bump map
 /// </summary>
 public Bitmap Create(Bitmap ImageUsing)
 {
     CreateFilter();
     using (Bitmap TempImageX = FilterX.Create(ImageUsing))
     {
         using (Bitmap TempImageY = FilterY.Create(ImageUsing))
         {
             Bitmap ReturnImage = new Bitmap(TempImageX.Width, TempImageX.Height);
             Math.Vector3 TempVector = new Utilities.Math.Vector3(0.0, 0.0, 0.0);
             BitmapData TempImageXData = Image.LockImage(TempImageX);
             BitmapData TempImageYData = Image.LockImage(TempImageY);
             BitmapData ReturnImageData = Image.LockImage(ReturnImage);
             int TempImageXPixelSize = Image.GetPixelSize(TempImageXData);
             int TempImageYPixelSize = Image.GetPixelSize(TempImageYData);
             int ReturnImagePixelSize = Image.GetPixelSize(ReturnImageData);
             for (int y = 0; y < TempImageX.Height; ++y)
             {
                 for (int x = 0; x < TempImageX.Width; ++x)
                 {
                     Color TempPixelX = Image.GetPixel(TempImageXData, x, y, TempImageXPixelSize);
                     Color TempPixelY = Image.GetPixel(TempImageYData, x, y, TempImageYPixelSize);
                     TempVector.X = (double)(TempPixelX.R) / 255.0;
                     TempVector.Y = (double)(TempPixelY.R) / 255.0;
                     TempVector.Z = 1.0;
                     TempVector.Normalize();
                     TempVector.X = ((TempVector.X + 1.0) / 2.0) * 255.0;
                     TempVector.Y = ((TempVector.Y + 1.0) / 2.0) * 255.0;
                     TempVector.Z = ((TempVector.Z + 1.0) / 2.0) * 255.0;
                     Image.SetPixel(ReturnImageData, x, y,
                         Color.FromArgb((int)TempVector.X,
                             (int)TempVector.Y,
                             (int)TempVector.Z),
                         ReturnImagePixelSize);
                 }
             }
             Image.UnlockImage(TempImageX, TempImageXData);
             Image.UnlockImage(TempImageY, TempImageYData);
             Image.UnlockImage(ReturnImage, ReturnImageData);
             return ReturnImage;
         }
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates the bump map
 /// </summary>
 public virtual Bitmap Create(Bitmap ImageUsing)
 {
     if (ImageUsing == null)
         throw new ArgumentNullException("ImageUsing");
     CreateFilter();
     using (Bitmap TempImageX = FilterX.Create(ImageUsing))
     {
         using (Bitmap TempImageY = FilterY.Create(ImageUsing))
         {
             Bitmap ReturnImage = new Bitmap(TempImageX.Width, TempImageX.Height);
             Math.Vector3 TempVector = new Utilities.Math.Vector3(0.0, 0.0, 0.0);
             BitmapData TempImageXData = TempImageX.LockImage();
             BitmapData TempImageYData = TempImageY.LockImage();
             BitmapData ReturnImageData = ReturnImage.LockImage();
             int TempImageXPixelSize = TempImageXData.GetPixelSize();
             int TempImageYPixelSize = TempImageYData.GetPixelSize();
             int ReturnImagePixelSize = ReturnImageData.GetPixelSize();
             for (int y = 0; y < TempImageX.Height; ++y)
             {
                 for (int x = 0; x < TempImageX.Width; ++x)
                 {
                     Color TempPixelX = TempImageXData.GetPixel(x, y, TempImageXPixelSize);
                     Color TempPixelY = TempImageYData.GetPixel(x, y, TempImageYPixelSize);
                     TempVector.X = (double)(TempPixelX.R) / 255.0;
                     TempVector.Y = (double)(TempPixelY.R) / 255.0;
                     TempVector.Z = 1.0;
                     TempVector.Normalize();
                     TempVector.X = ((TempVector.X + 1.0) / 2.0) * 255.0;
                     TempVector.Y = ((TempVector.Y + 1.0) / 2.0) * 255.0;
                     TempVector.Z = ((TempVector.Z + 1.0) / 2.0) * 255.0;
                     ReturnImageData.SetPixel(x, y,
                         Color.FromArgb((int)TempVector.X,
                             (int)TempVector.Y,
                             (int)TempVector.Z),
                         ReturnImagePixelSize);
                 }
             }
             TempImageX.UnlockImage(TempImageXData);
             TempImageY.UnlockImage(TempImageYData);
             ReturnImage.UnlockImage(ReturnImageData);
             return ReturnImage;
         }
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Creates the bump map
 /// </summary>
 private void CreateNormalMap()
 {
     try
     {
         Bitmap TempImageX = _FilterX.Image;
         Bitmap TempImageY = _FilterY.Image;
         _Image.Dispose();
         _Image = new Bitmap(TempImageX.Width, TempImageX.Height);
         Math.Vector3 TempVector = new Utilities.Math.Vector3(0.0, 0.0, 0.0);
         for (int y = 0; y < TempImageX.Height; ++y)
         {
             for (int x = 0; x < TempImageX.Width; ++x)
             {
                 Color TempPixelX = TempImageX.GetPixel(x, y);
                 Color TempPixelY = TempImageY.GetPixel(x, y);
                 TempVector.X = (double)(TempPixelX.R) / 255.0;
                 TempVector.Y = (double)(TempPixelY.R) / 255.0;
                 TempVector.Z = 1.0;
                 TempVector.Normalize();
                 TempVector.X = ((TempVector.X + 1.0) / 2.0) * 255.0;
                 TempVector.Y = ((TempVector.Y + 1.0) / 2.0) * 255.0;
                 TempVector.Z = ((TempVector.Z + 1.0) / 2.0) * 255.0;
                 _Image.SetPixel(x, y, Color.FromArgb((int)TempVector.X, (int)TempVector.Y, (int)TempVector.Z));
             }
         }
     }
     catch (Exception e) { throw e; }
 }
 /// <summary>
 /// Creates the bump map
 /// </summary>
 public virtual Bitmap Create(Bitmap ImageUsing)
 {
     ImageUsing.ThrowIfNull("ImageUsing");
     CreateFilter();
     using (Bitmap TempImageX = FilterX.Create(ImageUsing))
     {
         using (Bitmap TempImageY = FilterY.Create(ImageUsing))
         {
             Bitmap ReturnImage = new Bitmap(TempImageX.Width, TempImageX.Height);
             BitmapData TempImageXData = TempImageX.LockImage();
             BitmapData TempImageYData = TempImageY.LockImage();
             BitmapData ReturnImageData = ReturnImage.LockImage();
             int TempImageXPixelSize = TempImageXData.GetPixelSize();
             int TempImageYPixelSize = TempImageYData.GetPixelSize();
             int ReturnImagePixelSize = ReturnImageData.GetPixelSize();
             int Width = TempImageX.Width;
             int Height = TempImageX.Height;
             Parallel.For(0, Height, y =>
             {
                 Math.Vector3 TempVector = new Utilities.Math.Vector3(0.0, 0.0, 0.0);
                 for (int x = 0; x < Width; ++x)
                 {
                     Color TempPixelX = TempImageXData.GetPixel(x, y, TempImageXPixelSize);
                     Color TempPixelY = TempImageYData.GetPixel(x, y, TempImageYPixelSize);
                     TempVector.X = (double)(TempPixelX.R) / 255.0;
                     TempVector.Y = (double)(TempPixelY.R) / 255.0;
                     TempVector.Z = 1.0;
                     TempVector.Normalize();
                     TempVector.X = ((TempVector.X + 1.0) / 2.0) * 255.0;
                     TempVector.Y = ((TempVector.Y + 1.0) / 2.0) * 255.0;
                     TempVector.Z = ((TempVector.Z + 1.0) / 2.0) * 255.0;
                     ReturnImageData.SetPixel(x, y,
                         Color.FromArgb((int)TempVector.X,
                             (int)TempVector.Y,
                             (int)TempVector.Z),
                         ReturnImagePixelSize);
                 }
             });
             TempImageX.UnlockImage(TempImageXData);
             TempImageY.UnlockImage(TempImageYData);
             ReturnImage.UnlockImage(ReturnImageData);
             return ReturnImage;
         }
     }
 }
 public static Bitmap NormalMap(this Bitmap ImageUsing,bool InvertX=false,bool InvertY=false)
 {
     ImageUsing.ThrowIfNull("ImageUsing");
     using (Bitmap TempImageX = ImageUsing.BumpMap(Direction.LeftRight,InvertX))
     {
         using (Bitmap TempImageY = ImageUsing.BumpMap(Direction.TopBottom, InvertY))
         {
             Bitmap ReturnImage = new Bitmap(TempImageX.Width, TempImageX.Height);
             BitmapData TempImageXData = TempImageX.LockImage();
             BitmapData TempImageYData = TempImageY.LockImage();
             BitmapData ReturnImageData = ReturnImage.LockImage();
             int TempImageXPixelSize = TempImageXData.GetPixelSize();
             int TempImageYPixelSize = TempImageYData.GetPixelSize();
             int ReturnImagePixelSize = ReturnImageData.GetPixelSize();
             int Width = TempImageX.Width;
             int Height = TempImageX.Height;
             Parallel.For(0, Height, y =>
             {
                 Math.Vector3 TempVector = new Utilities.Math.Vector3(0.0, 0.0, 0.0);
                 for (int x = 0; x < Width; ++x)
                 {
                     Color TempPixelX = TempImageXData.GetPixel(x, y, TempImageXPixelSize);
                     Color TempPixelY = TempImageYData.GetPixel(x, y, TempImageYPixelSize);
                     TempVector.X = (double)(TempPixelX.R) / 255.0;
                     TempVector.Y = (double)(TempPixelY.R) / 255.0;
                     TempVector.Z = 1.0;
                     TempVector.Normalize();
                     TempVector.X = ((TempVector.X + 1.0) / 2.0) * 255.0;
                     TempVector.Y = ((TempVector.Y + 1.0) / 2.0) * 255.0;
                     TempVector.Z = ((TempVector.Z + 1.0) / 2.0) * 255.0;
                     ReturnImageData.SetPixel(x, y,
                         Color.FromArgb((int)TempVector.X,
                             (int)TempVector.Y,
                             (int)TempVector.Z),
                         ReturnImagePixelSize);
                 }
             });
             TempImageX.UnlockImage(TempImageXData);
             TempImageY.UnlockImage(TempImageYData);
             ReturnImage.UnlockImage(ReturnImageData);
             return ReturnImage;
         }
     }
 }