Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Klasse zum erstellen von einer PointCloud
- Option Strict On
- Option Explicit On
- Imports System.IO
- Imports System.Numerics
- Imports System.Runtime.InteropServices
- Imports System.Runtime.Serialization.Formatters.Binary
- Namespace Quaternion2DPlane
- <Serializable()>
- Public Class KomplexPlane
- #Region "TopVariabel"
- ''' <summary>
- ''' Gibt die Formate zum bearbeiten der Ebne an
- ''' </summary>
- Public Enum PushFlag
- ''' <summary>
- ''' Zieht den Bereich Kugelförmig mit Angabe eines Radius in die Ebne ein. Überschneidende Bereiche werden mitberechnet.
- ''' </summary>
- PushRoundUp = 0
- ''' <summary>
- ''' Drück den Bereich Kugelförmig mit Angabe eines Radius in die Ebne ein. Überschneidende Bereiche werden mitberechnet.
- ''' </summary>
- PushRoundDown = 1
- ''' <summary>
- ''' Zieht den Bereich Kegelförmig mit Angabe eines Radius in die Ebne ein. Überschneidende Bereiche werden mitberechnet.
- ''' </summary>
- PushLinearUp = 2
- ''' <summary>
- ''' Drückt den Bereich Kegelförmig mit Angabe eines Radius in die Ebne ein. Überschneidende Bereiche werden mitberechnet.
- ''' </summary>
- PushLinearDown = 3
- End Enum
- ''' <summary>
- ''' Gibt das zu verwendende Format an
- ''' </summary>
- Public Enum MeshExportFormat
- ''' <summary>
- ''' Einfache Positionsdaten
- ''' </summary>
- X_Y_Z = 0
- ''' <summary>
- '''Positionsdaten gefolgt vom Reflexionsgrad
- ''' </summary>
- X_Y_Z_Reflectance = 1
- ''' <summary>
- ''' Positionsdaten gefolgt von RGB Werten
- ''' </summary>
- X_Y_Z_R_G_B = 2
- ''' <summary>
- ''' Positionsdaten gefolgt von RGB Werten und dem Reflexionsgrad
- ''' </summary>
- X_Y_Z_R_G_B_Reflectance = 3
- ''' <summary>
- ''' Definiert eine Vertex Position
- ''' </summary>
- X_Y_Z_NX_NY_NZ = 4
- End Enum
- ''' <summary>
- ''' Definiert die Eigentschaften zum ersten Erstellen/Füllen der Komplexen Ebne
- ''' </summary>
- Public Enum CreateFlag
- ''' <summary>
- ''' <code>Entspricht keiner Auswahl. Die Standartgenerierung wird stadessen verwendet.</code>
- ''' </summary>
- None = -1
- ''' <summary>
- ''' Die X und Y Ebene wird gleichmäßig zwischen den gespeicherten Min und Max Werten aufgeteilt. Z Werte erhalten den Standart Wert.
- '''</summary>
- XY_Between_Default = 0
- ''' <summary>
- ''' Die X,Y und Z Ebne wird auf die gespeicherten Werten gesetzt (Property SetFix_X,SetFix_Y und SetFix_Z
- ''' </summary>
- XYZ_Fixed = 1
- ''' <summary>
- ''' Die X und Y Ebne wird wie bei CreateFlag.0 erstellt. Die Z Ebene wird beginnend von der ersten Spalte Links
- ''' in Richtung Rechts zwischen zmin zu zmax aufgeteilt und gefüllt.
- ''' </summary>
- XY_Between_Default_Z_1 = 2
- ''' <summary>
- ''' Die X und Y Ebne wird wie bei CreateFlag.0 erstellt. Die Z Ebene wird beginnend von der letzten Spalte rechts
- ''' in Richtung Links zwischen zmin zu zmax aufgeteilt und gefüllt.
- ''' </summary>
- XY_Between_Default_Z_2 = 3
- ''' <summary>
- ''' Die X und Y Ebne wird wie bei CreateFlag.0 erstellt. Die Z Ebene wird beginnend von der ersten Zeile oben,
- ''' in Richtung unten zwischen zmin und zmax aufgeteilt und gefüllt.
- ''' </summary>
- XY_Between_Default_Z_3 = 4
- ''' <summary>
- ''' Die X und Y Ebne wird wie bei CreateFlag.0 erstellt. Die Z Ebene wird beginnend von der letzten Zeile unten
- ''' in Richtung oben zwischen zmin und zmax aufgeteilt und gefüllt.
- ''' </summary>
- XY_Between_Default_Z_4 = 5
- ''' <summary>
- ''' Die X und Y Ebne wird wie bei CreateFlag.0 erstellt.
- ''' Die Z Ebne beschreibt eine Pyramidenartige Struktur welche bei zmin beginnt. Und zmax aufhört
- ''' Der Mittelpunkt der Ebne entspricht am Ende dem zmax Wert.
- ''' </summary>
- XY_Between_Default_Z_Stair_To_Middle_Up = 6
- ''' <summary>
- ''' Die X und Y Ebne wird wie bei CreateFlag.0 erstellt.
- ''' Die Z Ebne beschreibt eine Pyramidenartige Struktur welche bei zmax beginnt. Und zmin aufhört
- ''' Der Mittelpunkt der Ebne entspricht am Ende dem zmin Wert.
- ''' </summary>
- XY_Between_Default_Z_Stair_To_Middle_Down = 7
- ''' <summary>
- ''' XY wird zwischen den min/max Werten aufgeteilt. Für den Faktor werden die Größenordnungen der Ebne verwendet.
- '''Für Z wird der Faktor aus dem Mittelwert der Bild-Breite/Höhe errechnet. Anschließend wie bei XY aufgeteilt
- ''' </summary>
- Random_Between = 8
- End Enum
- Private mParents As New List(Of ParentHolder) 'Private - Kein Zugriff durch Property z.Z.
- Private mPlane(,) As Quaternion 'Private - Kein Zugriff durch Property z.Z.
- Private mBreite As Integer 'Property ReadOnly
- Private mHöhe As Integer 'Property ReadOnly
- Private xmin_Default As Double = -2.0 'Property ReadOnly
- Private xmax_Default As Double = 2.0 'Property ReadOnly
- Private ymin_Default As Double = -1.0 'Property ReadOnly
- Private ymax_Default As Double = 1.0 'Property ReadOnly
- Private zmin_Default As Double = -2.0 'Property ReadOnly
- Private zmax_Default As Double = 2.0 'Property ReadOnly
- Private Fix_X_Default As Double = 1.0 'Property
- Private Fix_Y_Default As Double = 1.0 'Property
- Private Fix_Z_Default As Double = 0.0 'Property
- Private MeshGutterSeperator As Char = CChar(";") 'Property
- Private MeshBreite As Integer 'Property
- Private MeshHöhe As Integer 'Property
- Private MeshTiefe As Integer 'Property
- Private MeshReflectance As Integer = 50 'Property
- Private PushFaktor As Integer = 1 'Property
- #End Region
- #Region "Property"
- Public Property GetPushFaktor() As Integer
- Get
- Return PushFaktor
- End Get
- Set(value As Integer)
- PushFaktor = value
- End Set
- End Property
- Public Property GetMeshReflectance() As Integer
- Get
- Return MeshReflectance
- End Get
- Set(value As Integer)
- MeshReflectance = value
- End Set
- End Property
- Public Property GetMeshTiefe() As Integer
- Get
- Return MeshTiefe
- End Get
- Set(value As Integer)
- MeshTiefe = value
- End Set
- End Property
- Public Property GetMeshHöhe() As Integer
- Get
- Return MeshHöhe
- End Get
- Set(value As Integer)
- MeshHöhe = value
- End Set
- End Property
- Public Property GetMeshBreite() As Integer
- Get
- Return MeshBreite
- End Get
- Set(value As Integer)
- MeshBreite = value
- End Set
- End Property
- Public Property GetMeshSeperator() As Char
- Get
- Return MeshGutterSeperator
- End Get
- Set(value As Char)
- MeshGutterSeperator = value
- End Set
- End Property
- Public Property GetFix_Z() As Double
- Get
- Return Fix_Z_Default
- End Get
- Set(value As Double)
- Fix_Z_Default = value
- End Set
- End Property
- Public Property GetFix_Y() As Double
- Get
- Return Fix_Y_Default
- End Get
- Set(value As Double)
- Fix_Y_Default = value
- End Set
- End Property
- Public Property GetFix_X() As Double
- Get
- Return Fix_X_Default
- End Get
- Set(value As Double)
- Fix_X_Default = value
- End Set
- End Property
- Public ReadOnly Property Get_zmaxDefault() As Double
- Get
- Return zmax_Default
- End Get
- End Property
- Public ReadOnly Property Get_zminDefault() As Double
- Get
- Return zmin_Default
- End Get
- End Property
- Public ReadOnly Property Get_ymaxDefault() As Double
- Get
- Return ymax_Default
- End Get
- End Property
- Public ReadOnly Property Get_yminDefault() As Double
- Get
- Return ymin_Default
- End Get
- End Property
- Public ReadOnly Property Get_xmaxDefault() As Double
- Get
- Return xmax_Default
- End Get
- End Property
- Public ReadOnly Property Get_xminDefault() As Double
- Get
- Return xmin_Default
- End Get
- End Property
- Public ReadOnly Property GetBreite() As Integer
- Get
- Return mBreite
- End Get
- End Property
- Public ReadOnly Property GetHöhe() As Integer
- Get
- Return mHöhe
- End Get
- End Property
- #End Region
- #Region "New"
- Public Sub New(ByVal Breite As Integer, ByVal Höhe As Integer)
- mBreite = Breite
- mHöhe = Höhe
- MeshBreite = mBreite
- MeshHöhe = mHöhe
- MeshTiefe = CInt(Math.Sqrt(mBreite * mHöhe))
- ReDim mPlane(mBreite, mHöhe)
- End Sub
- Public Sub New(ByVal Breite As Integer, ByVal Höhe As Integer, ByVal CreFlag As CreateFlag)
- mBreite = Breite
- mHöhe = Höhe
- ReDim mPlane(mBreite, mHöhe)
- Select Case CreFlag
- Case CreateFlag.None
- Create_XYZ_Fixed()
- Case CreateFlag.Random_Between
- Create_Random_Between()
- Case CreateFlag.XYZ_Fixed
- Create_XYZ_Fixed()
- Case CreateFlag.XY_Between_Default
- Create_XY_Between_Default()
- Case CreateFlag.XY_Between_Default_Z_1
- Create_XY_Between_Default_Z_1()
- Case CreateFlag.XY_Between_Default_Z_2
- Create_XY_Between_Default_Z_2()
- Case CreateFlag.XY_Between_Default_Z_3
- Create_XY_Between_Default_Z_3()
- Case CreateFlag.XY_Between_Default_Z_4
- Create_XY_Between_Default_Z_4()
- Case CreateFlag.XY_Between_Default_Z_Stair_To_Middle_Down
- Create_XY_Between_Default_Z_Stair_To_Middle_Down()
- Case CreateFlag.XY_Between_Default_Z_Stair_To_Middle_Up
- Create_XY_Between_Default_Z_Stair_To_Middle_Up()
- Case Else
- Create_XYZ_Fixed()
- End Select
- End Sub
- #End Region
- #Region "Private Hilfsfunktionen"
- Private Function GetAbsolute(ByVal val1 As Double, ByVal val2 As Double) As Double
- Dim result As Double
- Dim big As Double = Math.Max(val1, val2)
- Dim small As Double = Math.Min(val1, val2)
- If big > 0 And small > 0 Then
- result = big - small
- ElseIf big > 0 And small < 0 Then
- result = Math.Abs(small) + big
- Else
- result = Math.Abs(Math.Abs(big) - Math.Abs(small))
- End If
- Return result
- End Function
- Private Function CreateRoundPoints(ByVal Durchmesser As Integer, ByVal startpoint As Point) As List(Of Point)
- Dim points As New List(Of Point)
- Dim xStart As Integer = startpoint.X - Durchmesser
- Dim xEnd As Integer = startpoint.X + Durchmesser
- Dim yStart As Integer = startpoint.Y - Durchmesser
- Dim yEnd As Integer = startpoint.Y + Durchmesser
- For x As Integer = xStart To xEnd
- For y As Integer = yStart To yEnd
- Dim pkt As New Point(x, y)
- If x >= 0 And x <= mBreite And
- y >= 0 And y <= mHöhe Then
- If GetLinearPosDist(pkt, startpoint) <= Durchmesser Then points.Add(pkt)
- End If
- Next
- Next
- Return points
- End Function
- Private Function GetLinearPosDist(ByVal P1 As PointF, ByVal P2 As PointF) As Double
- Return Math.Sqrt((Math.Pow((P2.X - P1.X), 2)) + Math.Pow((P2.Y - P1.Y), 2))
- End Function
- Private Function ToRadians(ByVal deg As Double) As Double
- Return Math.PI / 180 * deg
- End Function
- #End Region
- #Region "CreateEbne Sub"
- Public Sub ReFreshEbne(ByVal Flag As CreateFlag)
- Select Case Flag
- Case CreateFlag.None
- Create_XYZ_Fixed()
- Case CreateFlag.Random_Between
- Create_Random_Between()
- Case CreateFlag.XYZ_Fixed
- Create_XYZ_Fixed()
- Case CreateFlag.XY_Between_Default
- Create_XY_Between_Default()
- Case CreateFlag.XY_Between_Default_Z_1
- Create_XY_Between_Default_Z_1()
- Case CreateFlag.XY_Between_Default_Z_2
- Create_XY_Between_Default_Z_2()
- Case CreateFlag.XY_Between_Default_Z_3
- Create_XY_Between_Default_Z_3()
- Case CreateFlag.XY_Between_Default_Z_4
- Create_XY_Between_Default_Z_4()
- Case CreateFlag.XY_Between_Default_Z_Stair_To_Middle_Down
- Create_XY_Between_Default_Z_Stair_To_Middle_Down()
- Case CreateFlag.XY_Between_Default_Z_Stair_To_Middle_Up
- Create_XY_Between_Default_Z_Stair_To_Middle_Up()
- Case Else
- Create_XYZ_Fixed()
- End Select
- End Sub
- Private Sub Create_XY_Between_Default()
- Dim xStep As Double = GetAbsolute(xmin_Default, xmax_Default) / mBreite
- Dim yStep As Double = GetAbsolute(ymin_Default, ymax_Default) / mHöhe
- For x As Integer = 0 To mBreite
- For y As Integer = 0 To mHöhe
- mPlane(x, y) = New Quaternion(xmin_Default + (x * xStep), ymin_Default + (y * yStep), Fix_Z_Default, 0)
- Next
- Next
- End Sub
- Private Sub Create_XYZ_Fixed()
- 'Alle Werte werden auf die Standartparameter gesetzt
- For x As Integer = 0 To mBreite
- For y As Integer = 0 To mHöhe
- mPlane(x, y) = New Quaternion(Fix_X_Default, Fix_Y_Default, Fix_Z_Default, 0)
- Next
- Next
- End Sub
- Private Sub Create_XY_Between_Default_Z_1()
- ' Die X und Y Ebne wird wie bei CreateFlag.0 erstellt. Die Z Ebene wird beginnend von der ersten Spalte Links
- ' in Richtung Rechts zwischen zmin zu zmax aufgeteilt und gefüllt.
- Dim xStep As Double = GetAbsolute(xmin_Default, xmax_Default) / mBreite
- Dim yStep As Double = GetAbsolute(ymin_Default, ymax_Default) / mHöhe
- Dim zStep As Double = GetAbsolute(zmin_Default, zmax_Default) / mBreite
- For x As Integer = 0 To mBreite
- For y As Integer = 0 To mHöhe
- mPlane(x, y) = New Quaternion(xmin_Default + (x * xStep), ymin_Default + (y * yStep), zmin_Default + (x * zStep), 0)
- Next
- Next
- End Sub
- Private Sub Create_XY_Between_Default_Z_2()
- ' Die X und Y Ebne wird wie bei CreateFlag.0 erstellt. Die Z Ebene wird beginnend von der letzten Spalte rechts
- ' in Richtung Links zwischen zmin zu zmax aufgeteilt und gefüllt.
- Dim xStep As Double = GetAbsolute(xmin_Default, xmax_Default) / mBreite
- Dim yStep As Double = GetAbsolute(ymin_Default, ymax_Default) / mHöhe
- Dim zStep As Double = GetAbsolute(zmin_Default, zmax_Default) / mBreite
- For x As Integer = 0 To mBreite
- For y As Integer = 0 To mHöhe
- mPlane(x, y) = New Quaternion(xmin_Default + (x * xStep), ymin_Default + (y * yStep), zmax_Default - (x * zStep), 0)
- Next
- Next
- End Sub
- Private Sub Create_XY_Between_Default_Z_3()
- ' Die X und Y Ebne wird wie bei CreateFlag.0 erstellt. Die Z Ebene wird beginnend von der ersten Zeile oben,
- ' in Richtung unten zwischen zmin und zmax aufgeteilt und gefüllt.
- Dim xStep As Double = GetAbsolute(xmin_Default, xmax_Default) / mBreite
- Dim yStep As Double = GetAbsolute(ymin_Default, ymax_Default) / mHöhe
- Dim zStep As Double = GetAbsolute(zmin_Default, zmax_Default) / mBreite
- For y As Integer = 0 To mHöhe
- For x As Integer = 0 To mBreite
- mPlane(x, y) = New Quaternion(xmin_Default + (x * xStep), ymin_Default + (y * yStep), zmin_Default + (x * zStep), 0)
- Next
- Next
- End Sub
- Private Sub Create_XY_Between_Default_Z_4()
- 'Die X und Y Ebne wird wie bei CreateFlag.0 erstellt. Die Z Ebene wird beginnend von der letzten Zeile unten
- ' in Richtung oben zwischen zmin und zmax aufgeteilt und gefüllt.
- Dim xStep As Double = GetAbsolute(xmin_Default, xmax_Default) / mBreite
- Dim yStep As Double = GetAbsolute(ymin_Default, ymax_Default) / mHöhe
- Dim zStep As Double = GetAbsolute(zmin_Default, zmax_Default) / mBreite
- For y As Integer = 0 To mHöhe
- For x As Integer = 0 To mBreite
- mPlane(x, y) = New Quaternion(xmin_Default + (x * xStep), ymin_Default + (y * yStep), zmax_Default - (x * zStep), 0)
- Next
- Next
- End Sub
- Private Sub Create_XY_Between_Default_Z_Stair_To_Middle_Up()
- 'Die X und Y Ebne wird wie bei CreateFlag.0 erstellt.
- 'Die Z Ebne beschreibt eine Pyramidenartige Struktur welche bei zmin beginnt. Und zmax aufhört
- 'Der Mittelpunkt der Ebne entspricht am Ende dem zmax Wert.
- Dim xStep As Double = GetAbsolute(xmin_Default, xmax_Default) / mBreite
- Dim yStep As Double = GetAbsolute(ymin_Default, ymax_Default) / mHöhe
- Dim zAbsolutDiagonal As Double = GetLinearPosDist(Point.Empty, New PointF(CSng(mBreite / 2), CSng(mHöhe / 2)))
- Dim zStep As Double = GetAbsolute(zmin_Default, zmax_Default) / zAbsolutDiagonal
- For y As Integer = 0 To mHöhe
- For x As Integer = 0 To mBreite
- Dim zWay As Double = zAbsolutDiagonal - GetLinearPosDist(New Point(x, y), New PointF(CSng(mBreite / 2), CSng(mHöhe / 2)))
- Dim zValue As Double = zmin_Default + (zStep * zWay)
- mPlane(x, y) = New Quaternion(xmin_Default + (x * xStep), ymin_Default + (y * yStep), zValue, 0)
- Next
- Next
- End Sub
- Private Sub Create_XY_Between_Default_Z_Stair_To_Middle_Down()
- ' Die X und Y Ebne wird wie bei CreateFlag.0 erstellt.
- 'Die Z Ebne beschreibt eine Pyramidenartige Struktur welche bei zmax beginnt. Und zmin aufhört
- ' Der Mittelpunkt der Ebne entspricht am Ende dem zmin Wert.
- Dim xStep As Double = GetAbsolute(xmin_Default, xmax_Default) / mBreite
- Dim yStep As Double = GetAbsolute(ymin_Default, ymax_Default) / mHöhe
- Dim zAbsolutDiagonal As Double = GetLinearPosDist(Point.Empty, New PointF(CSng(mBreite / 2), CSng(mHöhe / 2)))
- Dim zStep As Double = GetAbsolute(zmin_Default, zmax_Default) / zAbsolutDiagonal
- For y As Integer = 0 To mHöhe
- For x As Integer = 0 To mBreite
- Dim zWay As Double = zAbsolutDiagonal - GetLinearPosDist(New Point(x, y), New PointF(CSng(mBreite / 2), CSng(mHöhe / 2)))
- Dim zValue As Double = zmax_Default - (zStep * zWay)
- mPlane(x, y) = New Quaternion(xmin_Default + (x * xStep), ymin_Default + (y * yStep), zValue, 0)
- Next
- Next
- End Sub
- Private Sub Create_Random_Between()
- ' XY wird zwischen den min/max Werten aufgeteilt. Für den Faktor werden die Größenordnungen der Ebne verwendet.
- 'Für Z wird der Faktor aus dem Mittelwert der Bild-Breite/Höhe errechnet. Anschließend wie bei XY aufgeteilt
- Dim xStep As Double = GetAbsolute(xmin_Default, xmax_Default) / mBreite
- Dim yStep As Double = GetAbsolute(ymin_Default, ymax_Default) / mHöhe
- Dim zMidRange As Integer = CInt(Math.Sqrt(mBreite * mHöhe)) 'Sowohl für Step als auch für rand zwischen 0 und <-
- Dim zStep As Double = GetAbsolute(zmin_Default, zmax_Default) / zMidRange
- Dim rnd As New System.Random(TimeOfDay.Second * TimeOfDay.Minute * TimeOfDay.Millisecond)
- For x As Integer = 0 To mBreite
- For y As Integer = 0 To mHöhe
- Dim zValue As Double = zmin_Default + (rnd.Next(0, zMidRange) * zStep)
- mPlane(x, y) = New Quaternion(xmin_Default + (x * xStep), ymin_Default + (y * yStep), zValue, 0)
- Next
- Next
- End Sub
- #End Region
- #Region "Export MeshFile"
- Public Function ExportMesh(ByVal sPfad As String, ByVal Format As MeshExportFormat, ByVal Overwrite As Boolean) As Boolean
- If Not Overwrite And My.Computer.FileSystem.FileExists(sPfad) Then Return False
- If My.Computer.FileSystem.FileExists(sPfad) And Overwrite Then My.Computer.FileSystem.DeleteFile(sPfad)
- Dim result As Boolean = False
- Select Case Format
- Case MeshExportFormat.X_Y_Z
- result = ExportMesh_X_Y_Z(sPfad)
- Case MeshExportFormat.X_Y_Z_NX_NY_NZ
- result = ExportMesh_X_Y_Z_NX_NY_NZ(sPfad)
- Case MeshExportFormat.X_Y_Z_Reflectance
- result = ExportMesh_X_Y_Z_Reflectance(sPfad)
- Case MeshExportFormat.X_Y_Z_R_G_B
- result = ExportMesh_X_Y_Z_R_G_B(sPfad)
- Case MeshExportFormat.X_Y_Z_R_G_B_Reflectance
- result = ExportMesh_X_Y_Z_R_G_B_Reflectance(sPfad)
- End Select
- Return result
- End Function
- Private Function ExportMesh_X_Y_Z(ByVal sPfad As String) As Boolean
- Try
- Dim s As New Text.StringBuilder
- Dim xStep As Double = MeshBreite / GetAbsolute(xmin_Default, xmax_Default)
- Dim yStep As Double = MeshHöhe / GetAbsolute(ymin_Default, ymax_Default)
- Dim zStep As Double = MeshTiefe / GetAbsolute(zmin_Default, zmax_Default)
- Dim xVal, yVal, zVal As Double
- For x As Integer = 0 To mBreite
- For y As Integer = 0 To mHöhe
- With mPlane(x, y)
- xVal = .GetX * xStep
- yVal = .GetY * yStep
- zVal = .GetZ * zStep
- End With
- s.AppendLine(xVal.ToString & MeshGutterSeperator &
- yVal.ToString & MeshGutterSeperator &
- zVal.ToString)
- Next
- System.IO.File.AppendAllText(sPfad, s.Replace(",", ".").ToString)
- s.Clear()
- Next
- s.Clear()
- Return True
- Catch ex As Exception
- Return False
- End Try
- End Function
- Private Function ExportMesh_X_Y_Z_Reflectance(ByVal sPfad As String) As Boolean
- Try
- Dim s As New Text.StringBuilder
- Dim xStep As Double = MeshBreite / GetAbsolute(xmin_Default, xmax_Default)
- Dim yStep As Double = MeshHöhe / GetAbsolute(ymin_Default, ymax_Default)
- Dim zStep As Double = MeshTiefe / GetAbsolute(zmin_Default, zmax_Default)
- Dim xVal, yVal, zVal As Double
- For x As Integer = 0 To mBreite
- For y As Integer = 0 To mHöhe
- With mPlane(x, y)
- xVal = .GetX * xStep
- yVal = .GetY * yStep
- zVal = .GetZ * zStep
- End With
- s.AppendLine(xVal.ToString & MeshGutterSeperator &
- yVal.ToString & MeshGutterSeperator &
- zVal.ToString & MeshGutterSeperator &
- MeshReflectance.ToString)
- Next
- System.IO.File.AppendAllText(sPfad, s.Replace(",", ".").ToString)
- s.Clear()
- Next
- s.Clear()
- Return True
- Catch ex As Exception
- Return False
- End Try
- End Function
- Private Function ExportMesh_X_Y_Z_R_G_B(ByVal sPfad As String) As Boolean
- Try
- Dim s As New Text.StringBuilder
- Dim xStep As Double = MeshBreite / GetAbsolute(xmin_Default, xmax_Default)
- Dim yStep As Double = MeshHöhe / GetAbsolute(ymin_Default, ymax_Default)
- Dim zStep As Double = MeshTiefe / GetAbsolute(zmin_Default, zmax_Default)
- Dim xVal, yVal, zVal As Double
- Dim redStep As Double = 254 / GetLinearPosDist(Point.Empty, New Point(CInt(MeshTiefe / 2), CInt(MeshTiefe / 2)))
- Dim greenStep As Double = 254 / GetLinearPosDist(Point.Empty, New Point(CInt(MeshHöhe / 2), CInt(MeshHöhe / 2)))
- Dim blueStep As Double = 254 / GetLinearPosDist(Point.Empty, New Point(CInt(MeshBreite / 2), CInt(MeshBreite / 2)))
- For x As Integer = 0 To mBreite
- For y As Integer = 0 To mHöhe
- With mPlane(x, y)
- xVal = .GetX * xStep
- yVal = .GetY * yStep
- zVal = .GetZ * zStep
- End With
- s.AppendLine(xVal.ToString & MeshGutterSeperator &
- yVal.ToString & MeshGutterSeperator &
- zVal.ToString & MeshGutterSeperator &
- (redStep * Math.Abs(zVal)).ToString & MeshGutterSeperator &
- (greenStep * Math.Abs(yVal)).ToString & MeshGutterSeperator &
- (blueStep * Math.Abs(xVal)).ToString)
- Next
- System.IO.File.AppendAllText(sPfad, s.Replace(",", ".").ToString)
- s.Clear()
- Next
- s.Clear()
- Return True
- Catch ex As Exception
- Return False
- End Try
- End Function
- Private Function ExportMesh_X_Y_Z_R_G_B_Reflectance(ByVal sPfad As String) As Boolean
- Try
- Dim s As New Text.StringBuilder
- Dim xStep As Double = MeshBreite / GetAbsolute(xmin_Default, xmax_Default)
- Dim yStep As Double = MeshHöhe / GetAbsolute(ymin_Default, ymax_Default)
- Dim zStep As Double = MeshTiefe / GetAbsolute(zmin_Default, zmax_Default)
- Dim xVal, yVal, zVal As Double
- Dim redStep As Double = 254 / GetLinearPosDist(Point.Empty, New Point(CInt(MeshTiefe / 2), CInt(MeshTiefe / 2)))
- Dim greenStep As Double = 254 / GetLinearPosDist(Point.Empty, New Point(CInt(MeshHöhe / 2), CInt(MeshHöhe / 2)))
- Dim blueStep As Double = 254 / GetLinearPosDist(Point.Empty, New Point(CInt(MeshBreite / 2), CInt(MeshBreite / 2)))
- For x As Integer = 0 To mBreite
- For y As Integer = 0 To mHöhe
- With mPlane(x, y)
- xVal = .GetX * xStep
- yVal = .GetY * yStep
- zVal = .GetZ * zStep
- End With
- s.AppendLine(xVal.ToString & MeshGutterSeperator &
- yVal.ToString & MeshGutterSeperator &
- zVal.ToString & MeshGutterSeperator &
- (redStep * Math.Abs(zVal)).ToString & MeshGutterSeperator &
- (greenStep * Math.Abs(yVal)).ToString & MeshGutterSeperator &
- (blueStep * Math.Abs(xVal)).ToString & MeshGutterSeperator &
- MeshReflectance.ToString)
- Next
- System.IO.File.AppendAllText(sPfad, s.Replace(",", ".").ToString)
- s.Clear()
- Next
- s.Clear()
- Return True
- Catch ex As Exception
- Return False
- End Try
- End Function
- Private Function ExportMesh_X_Y_Z_NX_NY_NZ(ByVal sPfad As String) As Boolean
- Try
- Dim s As New Text.StringBuilder
- Dim xStep As Double = MeshBreite / GetAbsolute(xmin_Default, xmax_Default)
- Dim yStep As Double = MeshHöhe / GetAbsolute(ymin_Default, ymax_Default)
- Dim zStep As Double = MeshTiefe / GetAbsolute(zmin_Default, zmax_Default)
- Dim xVal, yVal, zVal As Double
- For x As Integer = 0 To mBreite
- For y As Integer = 0 To mHöhe
- With mPlane(x, y)
- xVal = .GetX * xStep
- yVal = .GetY * yStep
- zVal = .GetZ * zStep
- End With
- s.AppendLine(xVal.ToString & MeshGutterSeperator &
- yVal.ToString & MeshGutterSeperator &
- zVal.ToString & MeshGutterSeperator &
- xVal.ToString & MeshGutterSeperator &
- yVal.ToString & MeshGutterSeperator &
- zVal.ToString)
- Next
- System.IO.File.AppendAllText(sPfad, s.Replace(",", ".").ToString)
- s.Clear()
- Next
- s.Clear()
- Return True
- Catch ex As Exception
- Return False
- End Try
- End Function
- #End Region
- #Region "Manipulation der Ebne"
- Public Sub PushManipulation(ByVal Durchmesser As Integer, ByVal Mittelpunkt As Point, ByVal Flag As PushFlag)
- Select Case Flag
- Case PushFlag.PushLinearDown
- PushEbneLinearDown(Durchmesser, Mittelpunkt)
- Case PushFlag.PushLinearUp
- PushEbneLinearUp(Durchmesser, Mittelpunkt)
- Case PushFlag.PushRoundDown
- PushEbneRoundDown(Durchmesser, Mittelpunkt)
- Case PushFlag.PushRoundUp
- PushEbneRoundUp(Durchmesser, Mittelpunkt)
- End Select
- End Sub
- Private Sub PushEbneLinearDown(ByVal Durchmesser As Integer, ByVal MidPoint As Point)
- 'Drückt die Ebne Linear/Kegelförmig nach unten
- 'Wir müssen uns von oben nach unten arbeiten. Somit fangen wir mit vollem Radius an
- 'I setzen wir auf 1. Da 0 Ebne beginn
- 'Wir benötigen nur den ZStepper
- Dim zAbsolutDiagonal As Double = Math.Sqrt(mBreite * mHöhe)
- Dim zStep As Double = GetAbsolute(zmin_Default, zmax_Default) / zAbsolutDiagonal
- For i As Integer = 1 To Durchmesser
- Dim SchnittPunkte As List(Of Point) = CreateRoundPoints(Durchmesser - i, MidPoint)
- For Each oSPoint As Point In SchnittPunkte
- 'Die Punkte sollten von der Funktion schon überpüft worden sein,
- 'ob sie innerhalb unserer Grenzen liegen. Falls nicht -> CreateRoundPoints
- With mPlane(oSPoint.X, oSPoint.Y)
- mPlane(oSPoint.X, oSPoint.Y) = New Quaternion(.GetX, .GetY, .GetZ - (zStep * PushFaktor), .GetW)
- End With
- Next
- Next
- End Sub
- Private Sub PushEbneLinearUp(ByVal Durchmesser As Integer, ByVal MidPoint As Point)
- 'Drückt die Ebne Linear/Kegelförmig nach oben
- 'Wir müssen uns von oben nach unten arbeiten. Somit fangen wir mit vollem Radius an
- 'I setzen wir auf 1. Da 0 Ebne beginn
- 'Wir benötigen nur den ZStepper
- Dim zAbsolutDiagonal As Double = Math.Sqrt(mBreite * mHöhe)
- Dim zStep As Double = GetAbsolute(zmin_Default, zmax_Default) / zAbsolutDiagonal
- For i As Integer = 1 To Durchmesser
- Dim SchnittPunkte As List(Of Point) = CreateRoundPoints(Durchmesser - i, MidPoint)
- For Each oSPoint As Point In SchnittPunkte
- 'Die Punkte sollten von der Funktion schon überpüft worden sein,
- 'ob sie innerhalb unserer Grenzen liegen. Falls nicht -> CreateRoundPoints
- With mPlane(oSPoint.X, oSPoint.Y)
- mPlane(oSPoint.X, oSPoint.Y) = New Quaternion(.GetX, .GetY, .GetZ + (zStep * PushFaktor), .GetW)
- End With
- Next
- Next
- End Sub
- Private Sub PushEbneRoundDown(ByVal Durchmesser As Integer, ByVal MidPoint As Point)
- Dim zAbsolutDiagonal As Double = Math.Sqrt(mBreite * mHöhe)
- Dim zStep As Double = GetAbsolute(zmin_Default, zmax_Default) / zAbsolutDiagonal
- Dim zAlpha As Double = 0
- For i As Integer = 1 To Durchmesser - 1
- Dim rad As Double = ToRadians(180 / (Durchmesser - i) * i)
- zAlpha = Math.Sin(rad) * zStep
- Dim SchnittPunkte As List(Of Point) = CreateRoundPoints(Durchmesser - i, MidPoint)
- For Each oSPoint As Point In SchnittPunkte
- 'Die Punkte sollten von der Funktion schon überpüft worden sein,
- 'ob sie innerhalb unserer Grenzen liegen. Falls nicht -> CreateRoundPoints
- With mPlane(oSPoint.X, oSPoint.Y)
- mPlane(oSPoint.X, oSPoint.Y) = New Quaternion(.GetX, .GetY, .GetZ - Math.Abs(zAlpha * PushFaktor), .GetW)
- End With
- Next
- Next
- End Sub
- Private Sub PushEbneRoundUp(ByVal Durchmesser As Integer, ByVal MidPoint As Point)
- Dim zAbsolutDiagonal As Double = Math.Sqrt(mBreite * mHöhe)
- Dim zStep As Double = GetAbsolute(zmin_Default, zmax_Default) / zAbsolutDiagonal
- Dim zAlpha As Double = 0
- For i As Integer = 1 To Durchmesser - 1
- Dim rad As Double = ToRadians(180 / (Durchmesser - i) * i)
- zAlpha = Math.Sin(rad) * zStep
- Dim SchnittPunkte As List(Of Point) = CreateRoundPoints(Durchmesser - i, MidPoint)
- For Each oSPoint As Point In SchnittPunkte
- 'Die Punkte sollten von der Funktion schon überpüft worden sein,
- 'ob sie innerhalb unserer Grenzen liegen. Falls nicht -> CreateRoundPoints
- With mPlane(oSPoint.X, oSPoint.Y)
- mPlane(oSPoint.X, oSPoint.Y) = New Quaternion(.GetX, .GetY, .GetZ + Math.Abs(zAlpha * PushFaktor), .GetW)
- End With
- Next
- Next
- End Sub
- Public Sub Blowup(ByVal MidPoint As Point, ByVal Masse As Double, ByVal Wiederstand As Double, ByVal Streuung As Double)
- Dim nMasse As Double = Masse
- Dim nWiederstand As Double = Wiederstand
- Dim nStreuung As Double = Streuung
- If nMasse > 100 Then nMasse = 100
- If nMasse <= 0 Then nMasse = 1
- Dim zL As Integer = CInt(Math.Sqrt(mBreite * mHöhe) / 100 * Masse)
- Dim zStep As Double = GetAbsolute(zmin_Default, zmax_Default) / Math.Sqrt(mBreite * mHöhe)
- Dim AbstandUrsprung As Double = 1
- Dim rnd As New System.Random(TimeOfDay.Second * TimeOfDay.Minute * TimeOfDay.Millisecond)
- Do While True
- Dim pkt As List(Of Point) = CreateRoundPoints(CInt(AbstandUrsprung), MidPoint)
- For Each pk As Point In pkt
- Dim mnKraft As Double = zStep - (6.6743 * (zStep * zL * zStep) / (GetLinearPosDist(pk, MidPoint) * 2))
- If pk = MidPoint Then
- mnKraft = zStep - (6.6743 * (zStep * zL * zStep) / (GetLinearPosDist(New Point(MidPoint.X, MidPoint.Y - CInt(AbstandUrsprung)), MidPoint) * 2))
- End If
- mnKraft -= (zStep / 100 * Wiederstand)
- If rnd.Next(0, 100) <= Streuung Then
- Dim st As Double = ((mnKraft / 100) * (100 - Wiederstand))
- mnKraft -= st
- End If
- mnKraft = Math.Abs(mnKraft)
- With mPlane(pk.X, pk.Y)
- mPlane(pk.X, pk.Y) = New Quaternion(.GetX, .GetY, .GetZ - mnKraft, .GetW)
- End With
- Next
- AbstandUrsprung += 1
- If AbstandUrsprung >= zL Then Exit Do
- Loop
- End Sub
- #End Region
- End Class
- <Serializable()>
- Public Class ParentHolder
- Private ReadOnly mChilds As List(Of ChildHolder)
- Public Sub New()
- mChilds = New List(Of ChildHolder)
- End Sub
- Public Sub New(ByVal _Child As ChildHolder)
- mChilds = New List(Of ChildHolder)
- mChilds.Add(_Child)
- End Sub
- ''' <summary>
- ''' <code>Gibt das Item am gewählten Index zurück.</code>
- ''' </summary>
- ''' <param name="Index">Der Index des Elementes.</param>
- ''' <returns></returns>
- Public Function Item(ByVal Index As Integer) As ChildHolder
- If Index < 0 Then Throw New IndexOutOfRangeException("Index auserhalb des Bereiches!")
- If Index > mChilds.Count Then Throw New IndexOutOfRangeException("Index auserhalb des Bereiches!")
- Return mChilds(Index)
- End Function
- ''' <summary>
- ''' <code>Fügt ein Element in den Speichern ein.</code>
- ''' </summary>
- ''' <param name="Item">Object zum ablegen.</param>
- Public Sub Add(ByVal Item As ChildHolder)
- mChilds.Add(Item)
- End Sub
- ''' <summary>
- ''' <code>Überprüft ob ein Element mit dem gesuchten übereinstimmt und existiert.</code>
- ''' </summary>
- ''' <param name="Item">Das zu suchende Element.</param>
- ''' <returns></returns>
- Public Function Exist(ByVal Item As ChildHolder) As Boolean
- Dim result As Boolean = False
- For Each ch As ChildHolder In mChilds
- If ch.Equals(Item) Then
- result = True
- Exit For
- End If
- Next
- Return result
- End Function
- ''' <summary>
- ''' <code>Gibt alle Elemente als Array zurück.</code>
- ''' </summary>
- ''' <returns></returns>
- Public Function ToArray() As ChildHolder()
- Return mChilds.ToArray()
- End Function
- ''' <summary>
- ''' <code>Entfernt ein Element am gewünschten Index.</code>
- ''' </summary>
- ''' <param name="Index">Der Index im Array</param>
- Public Sub Remove(ByVal Index As Integer)
- If Index < 0 Then Throw New IndexOutOfRangeException("Der Index kann nicht kleiner 0 sein!")
- If Index > mChilds.Count Then Throw New IndexOutOfRangeException("Der Wert kann nicht größer als die Anzahl der Elemente sein.")
- mChilds.RemoveAt(Index)
- End Sub
- ''' <summary>
- ''' <code>Entfernt das erste Element das mit dem gesuchten Übereinstimmt aus dem Speicher.</code>
- ''' </summary>
- ''' <param name="Item">Das zu entfernende Element</param>
- ''' <returns></returns>
- Public Function RemoveFirst(ByVal Item As ChildHolder) As Boolean
- Dim val As Integer = -1
- For i As Integer = 0 To mChilds.Count - 1
- If mChilds(i).Equals(Item) Then
- val = i
- Exit For
- End If
- Next
- If Not val = -1 Then
- mChilds.RemoveAt(val)
- Return True
- Else
- Return False
- End If
- End Function
- ''' <summary>
- ''' <code>Gibt die Anzahl der existierende Elemente, die mit dem gesuchten übereinstimmen zurück.</code>
- ''' </summary>
- ''' <param name="Item">Zu suchende Elemente</param>
- ''' <returns></returns>
- Public Function CountOf(ByVal Item As ChildHolder) As Integer
- Dim val As Integer = 0
- For Each child As ChildHolder In mChilds
- If child.Equals(Item) Then val += 1
- Next
- Return val
- End Function
- ''' <summary>
- ''' <code>Entfernt alle Elemente die mit dem gesuchten übereinstimmen aus dem Speicher.</code>
- ''' </summary>
- ''' <param name="Item">Die zu entfernenden Elemente</param>
- Public Sub RemoveAll(ByVal Item As ChildHolder)
- Do Until CountOf(Item) = 0
- RemoveFirst(Item)
- Loop
- End Sub
- Public Overrides Function ToString() As String
- Dim totalBytes As Integer
- Dim b As BinaryFormatter = New BinaryFormatter()
- Dim m As MemoryStream = New MemoryStream()
- b.Serialize(m, Me)
- totalBytes = CInt(m.Length)
- m.Close()
- m.Dispose()
- b = Nothing
- Return "{ParentHolder:[" & mChilds.Count & "];Byte[" & totalBytes & "]}"
- End Function
- End Class
- <Serializable()>
- Public Structure ChildHolder
- Public Shared Empty As New ChildHolder(0, 0, New Quaternion(0, 0, 0, 0))
- Public Sub New(ByVal x As Integer, ByVal y As Integer, ByVal quat As Quaternion)
- GetX = x
- GetY = y
- GetQuaternion = quat
- End Sub
- Public ReadOnly Property GetX() As Integer
- Public ReadOnly Property GetY() As Integer
- Public ReadOnly Property GetQuaternion() As Quaternion
- Public Shadows Function Equals(obj As ChildHolder) As Boolean
- Try
- Return obj.GetQuaternion = GetQuaternion AndAlso obj.GetX = GetX AndAlso obj.GetY = GetY
- Catch ex As Exception
- Throw New Exception(ex.Message)
- End Try
- End Function
- Public Overrides Function ToString() As String
- Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()
- sb.Append("{X:")
- sb.Append(GetX)
- sb.Append(" Y:")
- sb.Append(GetY & "}")
- sb.Append(GetQuaternion.ToString)
- Return sb.ToString()
- End Function
- End Structure
- End Namespace
Add Comment
Please, Sign In to add comment