'
'
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Matrox.MatroxImagingLibrary
Namespace MImPolar
Friend Class Program
Private Const IMAGE_FILE As String = MIL.M_IMAGE_PATH & "Polar.mim"
Private Const POINT1_X As Integer = 147
Private Const POINT1_Y As Integer = 359
Private Const POINT2_X As Integer = 246
Private Const POINT2_Y As Integer = 404
Private Const POINT3_X As Integer = 354
Private Const POINT3_Y As Integer = 368
Private Const DELTA_RADIUS As Integer = 25
Private Const START_ANGLE As Integer = 210
Private Const END_ANGLE As Integer = 330
Shared Sub Main(ByVal args() As String)
Dim MilApplication As MIL_ID = MIL.M_NULL
Dim MilSystem As MIL_ID = MIL.M_NULL
Dim MilDisplay As MIL_ID = MIL.M_NULL
Dim MilImage As MIL_ID = MIL.M_NULL
Dim MilPolarImage As MIL_ID = MIL.M_NULL
Dim SizeRadius As Double = 0.0
Dim SizeAngle As Double = 0.0
Dim CenterX As Double = 0.0
Dim CenterY As Double = 0.0
Dim Radius As Double = 0.0
Dim OffsetX As Integer = 0
Dim OffsetY As Integer = 0
Dim SizeX As Integer = 0
Dim SizeY As Integer = 0
MIL.MappAllocDefault(MIL.M_DEFAULT, MilApplication, MilSystem, MilDisplay, CType(MIL.M_NULL, IntPtr), CType(MIL.M_NULL, IntPtr))
MIL.MbufRestore(IMAGE_FILE, MilSystem, MilImage)
MIL.MdispSelect(MilDisplay, MilImage)
GenerateCircle(POINT1_X, POINT1_Y, POINT2_X, POINT2_Y, POINT3_X, POINT3_Y, CenterX, CenterY, Radius)
MIL.MimPolarTransform(MilImage, MIL.M_NULL, CenterX, CenterY, Radius + DELTA_RADIUS, Radius - DELTA_RADIUS, START_ANGLE, END_ANGLE, MIL.M_RECTANGULAR_TO_POLAR, MIL.M_NEAREST_NEIGHBOR + MIL.M_OVERSCAN_ENABLE, SizeAngle, SizeRadius)
OffsetX = CInt(Fix((MIL.MbufInquire(MilImage, MIL.M_SIZE_X, MIL.M_NULL) / 2) - CType((SizeAngle / 2), MIL_INT)))
OffsetY = 20
SizeX = CInt(Math.Ceiling(SizeAngle))
SizeY = CInt(Math.Ceiling(SizeRadius))
MIL.MbufChild2d(MilImage, OffsetX, OffsetY, SizeX, SizeY, MilPolarImage)
Console.Write(Constants.vbLf + "POLAR TRANSFORMATION:" + Constants.vbLf)
Console.Write("---------------------" + Constants.vbLf + Constants.vbLf)
Console.Write("A string will be unrolled using a polar-to-rectangular transformation." + Constants.vbLf)
Console.Write("Press <Enter> to continue." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MimPolarTransform(MilImage, MilPolarImage, CenterX, CenterY, Radius + DELTA_RADIUS, Radius - DELTA_RADIUS, START_ANGLE, END_ANGLE, MIL.M_RECTANGULAR_TO_POLAR, MIL.M_NEAREST_NEIGHBOR + MIL.M_OVERSCAN_ENABLE, SizeAngle, SizeRadius)
Console.Write("Press <Enter> to end." + Constants.vbLf)
Console.ReadKey()
MIL.MbufFree(MilPolarImage)
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MilImage)
End Sub
Private Shared Sub GenerateCircle(ByVal X1 As Double, ByVal Y1 As Double, ByVal X2 As Double, ByVal Y2 As Double, ByVal X3 As Double, ByVal Y3 As Double, ByRef CenterX As Double, ByRef CenterY As Double, ByRef Radius As Double)
Dim Slope1 As Double = 0.0
Dim Slope2 As Double = 0.0
Dim MidPoint1X As Double = 0.0
Dim MidPoint1Y As Double = 0.0
Dim MidPoint2X As Double = 0.0
Dim MidPoint2Y As Double = 0.0
Dim Offset1 As Double = 0.0
Dim Offset2 As Double = 0.0
MidPoint1X = (X1 + X2) / 2
MidPoint1Y = (Y1 + Y2) / 2
MidPoint2X = (X2 + X3) / 2
MidPoint2Y = (Y2 + Y3) / 2
If ((Y2 - Y1) <> 0.0) AndAlso ((Y3 - Y2) <> 0.0) Then
Slope1 = -(X2 - X1) / (Y2 - Y1)
Slope2 = -(X3 - X2) / (Y3 - Y2)
Offset1 = MidPoint1Y - Slope1 * MidPoint1X
Offset2 = MidPoint2Y - Slope2 * MidPoint2X
CenterX = (Offset2 - Offset1) / (Slope1 - Slope2)
CenterY = Slope1 * (CenterX) + Offset1
ElseIf ((Y2 - Y1) = 0.0) AndAlso ((Y3 - Y2) <> 0.0) Then
Slope2 = -(X3 - X2) / (Y3 - Y2)
Offset2 = MidPoint2Y - Slope2 * MidPoint2X
CenterX = MidPoint1X
CenterY = Slope2 * (CenterX) + Offset2
ElseIf ((Y2 - Y1) <> 0.0) AndAlso ((Y3 - Y2) = 0.0) Then
Slope1 = -(X2 - X1) / (Y2 - Y1)
Offset1 = MidPoint1Y - Slope1 * MidPoint1X
CenterX = MidPoint2X
CenterY = Slope1 * (CenterX) + Offset1
End If
Radius = Math.Sqrt(Math.Pow(CenterX - X1, 2) + Math.Pow(CenterY - Y1, 2))
End Sub
End Class
End Namespace