Remove obsolete squares (something wrong with areas calcualtion)

This commit is contained in:
Anton 2021-03-05 15:47:08 +01:00
parent 583bd274c7
commit 9b47f4e4d0
4 changed files with 105 additions and 29 deletions

View File

@ -3,6 +3,16 @@ Public Class AppForm
Public Shared fillMode As Boolean
Sub AppForm_Load() Handles MyBase.Load
Dim dir As New IO.DirectoryInfo("C:\Users\Anton\Documents\Exjobb")
If dir.Exists Then
Individual.filepath = "C:\Users\Anton\Documents\Exjobb"
Else
Individual.filepath = "C:\Users\xperd\Documents"
End If
Settings.filesFolder = Individual.filepath
Settings.HLCtFolder = Individual.filepath & "\X2021"
Me.Width = 1400
Me.Height = 800
Me.Top = 20

View File

@ -1,7 +1,7 @@

Public Class Individual
'Public Shared filepath As String = "C:\Users\Anton\Documents\Exjobb"
Public Shared filepath As String = "C:\Users\xperd\Documents"
Public Shared filepath As String '= "C:\Users\Anton\Documents\Exjobb"
'Public Shared filepath As String = "C:\Users\xperd\Documents"
Sub Load_GUI()
' Initialize GUI

View File

@ -1,7 +1,7 @@
Imports XCCLibrary
Public Class Settings
Public Shared filesFolder As String = Individual.filepath ' Hämta från settings
Public Shared HLCtFolder As String = Individual.filepath & "\X2021" ' Hämta från settings
Public Shared filesFolder As String '= Individual.filepath ' Hämta från settings
Public Shared HLCtFolder As String '= Individual.filepath & "\X2021" ' Hämta från settings
' --- Settings button clicked ---
Public Shared Sub ButtonClicked(sender As Object, e As EventArgs)

View File

@ -436,37 +436,38 @@ Public Class Model_3D_Fill
GP.Add(p3)
GP.Add(p4)
Dim cornerAngleCounter As Integer = 1
Dim cornerRectangleCounter As Integer = 1
Dim numOfSideRectangles As Integer = 0
For j = 0 To Data.recessData.Rows.Count - 1
If Data.recessData.Rows(j)("RECESS TYPE") = "ANGLE" Then
Dim RP As New List(Of Integer())
Dim rec1(1), rec2(1), rec3(1) As Integer
If Data.recessData.Rows(j)("CORNER") = 1 Then
rec1(0) = -origo(0)
rec1(1) = origo(1)
ElseIf Data.recessData.Rows(j)("CORNER") = 2 Then
rec1(0) = origo(0)
rec1(1) = origo(1)
rec1(0) = Data.grossAreaPoints.Rows(Data.recessData.Rows(j)("CORNER") - 1)("X") * 1000
rec1(1) = Data.grossAreaPoints.Rows(Data.recessData.Rows(j)("CORNER") - 1)("Y") * 1000
ElseIf Data.recessData.Rows(j)("CORNER") = 3 Then
rec1(0) = origo(0)
rec1(1) = -origo(1)
Else
rec1(0) = -origo(0)
rec1(1) = -origo(1)
End If
'If Data.recessData.Rows(j)("CORNER") = 1 Then
' rec1(0) = -origo(0)
' rec1(1) = origo(1)
'ElseIf Data.recessData.Rows(j)("CORNER") = 2 Then
' rec1(0) = origo(0)
' rec1(1) = origo(1)
'ElseIf Data.recessData.Rows(j)("CORNER") = 3 Then
' rec1(0) = origo(0)
' rec1(1) = -origo(1)
'Else
' rec1(0) = -origo(0)
' rec1(1) = -origo(1)
'End If
Dim rowIndex As Integer
For k = 0 To Data.gratingPoints.Rows.Count - 1
If Data.gratingPoints.Rows(k)("NAME") = "CA" & cornerAngleCounter & "_" & 1 Then
rowIndex = k
End If
Next
rec2(0) = Data.gratingPoints.Rows(rowIndex)("X") * 1000
rec2(1) = Data.gratingPoints.Rows(rowIndex)("Y") * 1000
@ -477,28 +478,74 @@ Public Class Model_3D_Fill
RP.Add(rec2)
RP.Add(rec3)
Dim gratingObsolete As Boolean = True
For k = 0 To 3
Dim pInTriangle As Boolean = Calculate_Triangle_Bool(GP(k), RP(0), RP(1), RP(2))
If pInTriangle = False Then
gratingObsolete = False
Exit For
End If
Next
If gratingObsolete = True Then
listOfObsolete.Add(i)
End If
cornerAngleCounter += 1
ElseIf Data.recessData.Rows(j)("RECESS TYPE") = "SQUARE" OrElse Data.recessData.Rows(j)("RECESS TYPE") = "SIDE SQUARE" Then
'Fyra punkter rektangalarna
Dim RP As New List(Of Integer())
Dim rec1(1), rec2(1), rec3(1), rec4(1) As Integer
Dim rowIndex As Integer
If Data.recessData.Rows(j)("RECESS TYPE") = "SQUARE" Then
For k = 0 To Data.gratingPoints.Rows.Count - 1
If Data.gratingPoints.Rows(k)("NAME") = "CR" & cornerRectangleCounter & "_" & 1 Then
rowIndex = k
End If
Next
cornerRectangleCounter += 1
Else
For k = 0 To Data.gratingPoints.Rows.Count - 1
If Data.gratingPoints.Rows(k)("NAME") = "CS" & numOfSideRectangles & "_" & 1 Then
rowIndex = k
End If
Next
numOfSideRectangles += 1
End If
rec1(0) = Data.gratingPoints.Rows(rowIndex)("X") * 1000
rec1(1) = Data.gratingPoints.Rows(rowIndex)("Y") * 1000
rec2(0) = Data.gratingPoints.Rows(rowIndex + 1)("X") * 1000
rec2(1) = Data.gratingPoints.Rows(rowIndex + 1)("Y") * 1000
rec3(0) = Data.gratingPoints.Rows(rowIndex + 2)("X") * 1000
rec3(1) = Data.gratingPoints.Rows(rowIndex + 2)("Y") * 1000
If Data.recessData.Rows(j)("RECESS TYPE") = "SQUARE" Then
rec4(0) = Data.grossAreaPoints.Rows(Data.recessData.Rows(j)("CORNER") - 1)("X") * 1000
rec4(1) = Data.grossAreaPoints.Rows(Data.recessData.Rows(j)("CORNER") - 1)("Y") * 1000
Else
rec4(0) = Data.gratingPoints.Rows(rowIndex + 3)("X") * 1000
rec4(1) = Data.gratingPoints.Rows(rowIndex + 3)("Y") * 1000
End If
RP.Add(rec1)
RP.Add(rec2)
RP.Add(rec3)
RP.Add(rec4)
Dim gratingObsolete As Boolean = True
For k = 0 To 3
Dim pInSquare As Boolean = Calculate_Square_Bool(GP(k), RP(0), RP(1), RP(2), RP(3))
If pInSquare = False Then
gratingObsolete = False
Exit For
End If
Next
If gratingObsolete = True Then
listOfObsolete.Add(i)
End If
End If
@ -533,4 +580,23 @@ Public Class Model_3D_Fill
End If
End If
End Function
Private Shared Function Calculate_Square_Bool(gp As Integer(), p0 As Integer(), p1 As Integer(), p2 As Integer(), p3 As Integer())
Dim squareArea As Double = Math.Abs(p0(0) - p1(0)) * Math.Abs(p1(1) - p2(1))
If squareArea = 0 Then
squareArea = Math.Abs(p0(1) - p1(1)) * Math.Abs(p1(0) - p2(0))
End If
Dim area1 As Double = gp(0) * p0(1) + gp(1) * p1(0) + p0(0) * p1(1) - p0(1) * p1(0) - gp(1) * p0(0) - gp(0) * p1(1)
Dim area2 As Double = gp(0) * p1(1) + gp(1) * p2(0) + p1(0) * p2(1) - p1(1) * p2(0) - gp(1) * p1(0) - gp(0) * p2(1)
Dim area3 As Double = gp(0) * p2(1) + gp(1) * p3(0) + p2(0) * p3(1) - p2(1) * p3(0) - gp(1) * p2(0) - gp(0) * p3(1)
Dim area4 As Double = gp(0) * p3(1) + gp(1) * p0(0) + p3(0) * p0(1) - p3(1) * p0(0) - gp(1) * p3(0) - gp(0) * p0(1)
Dim compArea As Double = area1 + area2 + area3 + area4
If compArea > squareArea Then
Return False
Else
Return True
End If
End Function
End Class