Commit dc7411b3 authored by Moritz's avatar Moritz

removed unused scripts and scenes

parent 9e13d05f
This diff is collapsed.
fileFormatVersion: 2
guid: fdff0ddf5052dc44f8139e657438c69f
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: f80aa710e28bfd94b8b57f9ca24b65ea
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 14a9f18f8934a1342acd51f49ebf8ee9
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 261bf969dbf9e484eb2216a01a95b0cc
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 092d840853a7b1b41a3b4143c4ca26f1
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 6fff8da36b67f9b45b362f466b15a9d8
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 79c7c114d245de74fa436564885106e8
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.IO;
using System.Globalization;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
namespace Teamproject {
public class CelDataReader {
private string _pathToFolder;
private string _filenames;
public Dictionary<int, Vector3> vertices { get; private set; }
public Dictionary<int, Cell> cells {get; private set;}
public CelDataReader(string pathToFolder, string filenames) {
_pathToFolder = pathToFolder;
_filenames = filenames;
}
public void ReadCellData() {
ReadVertices();
ReadCells();
AssignVelocitiesToCells();
}
private void ReadVertices() {
StreamReader reader = new StreamReader(_pathToFolder + @"\" + _filenames + ".vrt");
vertices = new Dictionary<int, Vector3>();
string line;
int counter = 0;
while ((line = reader.ReadLine()) != null) {
//skip first 2 lines
if (counter < 2) {
counter++;
continue;
}
//first number: vertex ID, following three numbers: position coordinates
line = RemoveMultipleSpaces(line);
line = RemoveStartSpace(line);
string[] parts = line.Split(' ');
int key = int.Parse(parts[0]);
Vector3 value = new Vector3(
float.Parse(parts[1], CultureInfo.InvariantCulture.NumberFormat),
float.Parse(parts[2], CultureInfo.InvariantCulture.NumberFormat),
float.Parse(parts[3], CultureInfo.InvariantCulture.NumberFormat));
vertices.Add(key, value);
}
reader.Close();
}
private void ReadCells() {
//each cell is defined by three/four vertex points and ID
StreamReader reader = new StreamReader(_pathToFolder + @"\" + _filenames + ".cel");
cells = new Dictionary<int, Cell>();
string line;
int counter = 0;
int celltype = -1;
while ((line = reader.ReadLine()) != null) {
//skip first 2 lines
if (counter < 2) {
counter++;
continue;
}
//every second line, starting with third, contains information about celltype, unkown encoding
//counter % 2 == 0 -> overwrite celltype, counter % 2 == 1 -> save celltype with corresponding cell
if (counter % 2 == 0) {
//remove spaces
line = line.Replace(" ", "");
//remove id
line = line.Remove(0, 1);
//remaining numbers form some type of ID
celltype = int.Parse(line);
}
else {
//first number: vertex ID, following three numbers: position coordinates
line = RemoveMultipleSpaces(line);
line = RemoveStartSpace(line);
var parts = line.Split(' ');
int id = int.Parse(parts[0]);
List<int> vert = new List<int>(){
int.Parse(parts[1]),
int.Parse(parts[2]),
int.Parse(parts[3])};
//walls have only triangles
if (parts.Length > 4)
vert.Add(int.Parse(parts[4]));
Cell c = new Cell(id, celltype, vert);
cells.Add(id, c);
}
counter++;
}
reader.Close();
}
private void AssignVelocitiesToCells() {
StreamReader reader = new StreamReader(_pathToFolder + @"\" + _filenames + ".daten");
string line;
int counter = 0;
while ((line = reader.ReadLine()) != null) {
//skip first 2 lines
if (counter < 1) {
counter++;
continue;
}
//first number: vertex ID, following three numbers: position coordinates
line = RemoveMultipleSpaces(line);
line = RemoveStartSpace(line);
var parts = line.Split(' ');
int id = int.Parse(parts[0]);
Vector3 velocity = new Vector3(
float.Parse(parts[1], CultureInfo.InvariantCulture.NumberFormat),
float.Parse(parts[2], CultureInfo.InvariantCulture.NumberFormat),
float.Parse(parts[3], CultureInfo.InvariantCulture.NumberFormat));
if (!cells.TryGetValue(id, out Cell c2)) {
Debug.Log("couldnt assign velocity to cell with id " + id);
}
else
cells[id].SetVelocity(velocity);
}
reader.Close();
}
/// <summary>
/// Removes multiple spaces and replaces the by one space
/// </summary>
/// <param name="s"> String with multiple spaces </param>
/// <returns> String with single spaces only between other characters </returns>
private string RemoveMultipleSpaces(string s) {
RegexOptions options = RegexOptions.None;
Regex regex = new Regex("[ ]{2,}", options);
return regex.Replace(s, " ");
}
/// <summary>
/// Removes a single initial space at the strings beginning
/// </summary>
/// <param name="s"> String with eventual space at start </param>
/// <returns> String without eventual space at start </returns>
private string RemoveStartSpace(string s) {
if (s.StartsWith(" "))
return s.Remove(0, 1);
return s;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: a57a0df9cc8355f46bfcb2c5d57c5ece
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Teamproject {
public class CelToVF : MonoBehaviour {
[Tooltip("Path to CEL Data files containing the extensions .cel, .daten and .vrt \n" +
"STAR-CCM+ export options should be: Export Data: all Regions, Velocity (only vector \"Lab Reference Frame\"," +
" not magnitude or i, j, k; Export Type: Mesh and Solution Data")]
public string PathToFolder = "";
[Tooltip("Distance between adjacent gridpoints on any axis, in Millimeter")]
public float GridStepSize = default;
public bool ConvertCelToVectorfield = default;
void Update() {
if (ConvertCelToVectorfield) {
ConvertCelToVectorfield = false;
StartCoroutine(StartConvert());
}
}
public IEnumerator StartConvert() {
var startingTime = DateTime.Now;
string filenames = FileNameFinder.GetName(PathToFolder, ".cel");
Debug.Log("<color=teal> Starting reading data </color>");
yield return new WaitForEndOfFrame();
CelDataReader reader = new CelDataReader(PathToFolder, filenames);
reader.ReadCellData();
Debug.Log("<color=teal> Reading complete, starting mapping to grid </color>");
yield return new WaitForEndOfFrame();
Dictionary<int, Cell> cells = reader.cells;
Dictionary<int, Vector3> vertices = reader.vertices;
var gridMapper = new PointcloudToGridMapper(cells, vertices, GridStepSize);
gridMapper.StartConvert();
Debug.Log("<color=teal> Mapping complete, starting writing to vectorfield </color>");
yield return new WaitForEndOfFrame();
var writer = new VectorFieldWriter(PathToFolder, filenames);
writer.WriteToVectorfield(gridMapper.directionGrid);
//writer.WriteToVectorfield(gridMapper.info);
Debug.Log("<color=teal> Writing to vectorfield complete </color>");
var calcTime = (DateTime.Now - startingTime);
Debug.Log("<color=teal> Everything done in " + (calcTime.Minutes * 60 + calcTime.Seconds) + " seconds. </color>");
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 4591081a534893840a918e42738fa734
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Teamproject {
public class PointcloudToGridMapperCELLSIZEBASED {
/// <summary>
/// Grid containing the directions for each grid point
/// </summary>
public Vector3[,,] directionGrid { get; private set; }
/// <summary>
/// Grid containing additional information for each grid point, like the point type (wall, inlet, outlet, ..)
/// </summary>
public float[,,] info { get; private set; }
Dictionary<int, Cell> _cells;
Dictionary<int, Vector3> _vertices;
//pcache
private List<PCachePoint> points;
private Vector3 gridSize;
private Vector3 offsetCorrection; //if the grid doesn't start at 0, 0, 0 -> vector to move all points, so that grid is aligned
private float gridStepSize;
public PointcloudToGridMapperCELLSIZEBASED(Dictionary<int, Cell> cells, Dictionary<int, Vector3> vertices) {
_cells = cells;
_vertices = vertices;
}
public void StartConvert() {
CreateGrid();
CalculatePointsFromCells();
IntegratePointsIntoGrid();
}
private void CreateGrid() {
//get min and max position values
float maxX = float.MinValue;
float maxY = float.MinValue;
float maxZ = float.MinValue;
float minX = float.MaxValue;
float minY = float.MaxValue;
float minZ = float.MaxValue;
//iterate through all vertices -> find min/max values
foreach (Vector3 vertex in _vertices.Values) {
if (vertex.x > maxX)
maxX = vertex.x;
if (vertex.y > maxY)
maxY = vertex.y;
if (vertex.z > maxZ)
maxZ = vertex.z;
if (vertex.x < minX)
minX = vertex.x;
if (vertex.y < minY)
minY = vertex.y;
if (vertex.z < minZ)
minZ = vertex.z;
}
Debug.Log("max bounding box values (x, y, z): " + maxX + " " + maxY + " " + maxZ);
Debug.Log("min bounding box values (x, y, z): " + minX + " " + minY + " " + minZ);
//to align grid at point 0, 0, 0: calculate offset from origin
float xOffset = 0 - minX;
float yOffset = 0 - minY;
float zOffset = 0 - minZ;
offsetCorrection = new Vector3(xOffset, yOffset, zOffset);
//how to determine grid sampling rate (step size)?
//take average cell size -> should be size of grid cells
//get average cell size
float volume = 0;
foreach (Cell cell in _cells.Values) {
if (cell.VertexIDs.Count > 3) { //dont count non-volumetric cells
//calculate volume for each cell, vertex 0 as start for 3 vectors
Vector3 a, b, c;
a = _vertices[cell.VertexIDs[1]] - _vertices[cell.VertexIDs[0]];
b = _vertices[cell.VertexIDs[2]] - _vertices[cell.VertexIDs[0]];
c = _vertices[cell.VertexIDs[3]] - _vertices[cell.VertexIDs[0]];
// https://de.wikipedia.org/wiki/Tetraeder#Allgemeines_Tetraeder_(dreidimensionales_Simplex)
volume += (Vector3.Dot(Vector3.Cross(a, b), c)) / 6;
}
}
volume /= _cells.Values.Count;
//volume -> cube length? cuberoot
gridStepSize = Mathf.Pow(volume, 1f / 3f);
//gridsize way to large -> downsample (experiment with factor)
//example: (with rough simulation) downsizefactor 30 -> 3GB vectorfield, respectively 1GB info
float downsizefactor = 30f;
gridStepSize *= downsizefactor;
//create grid
int gridXSize = (int)Mathf.Ceil(maxX / gridStepSize);
int gridYSize = (int)Mathf.Ceil(maxY / gridStepSize);
int gridZSize = (int)Mathf.Ceil(maxZ / gridStepSize);
gridSize = new Vector3(gridXSize - 1, gridYSize - 1, gridZSize - 1); // -1 because following array is 0 based
directionGrid = new Vector3[gridXSize, gridYSize, gridZSize];
info = new float[gridXSize, gridYSize, gridZSize];
Debug.Log("grid points: " + gridXSize * gridYSize * gridZSize);
Debug.Log("grid step size: " + gridStepSize);
}
private void CalculatePointsFromCells() {
//pcache point = middlepoint of cell
points = new List<PCachePoint>();
foreach (KeyValuePair<int, Cell> kvp in _cells) {
Cell cell = kvp.Value;
//calculate midpoint for each cell
Vector3 cellMid = Vector3.zero;
foreach (int vertexID in cell.VertexIDs)
cellMid += _vertices[vertexID];
cellMid /= cell.VertexIDs.Count;
//add point to list
points.Add(new PCachePoint(cell.CellType, cellMid, cell.Velocity));
}
}
private void IntegratePointsIntoGrid() {
//interpolation:
// nearest neighbor
// within factor*gridStepSize range
//naive approach: iterate for each grid point g through all points p -> complexity (count(g))^(count(p))
//inverted lists: iterate through all points -> save in which neighborhood they are -> iterate though grid with knowledge of neighborhoods -> complexity count(g)*count(p)
//adjust points by including offset
List<PCachePoint> adjPoints = new List<PCachePoint>();
foreach (PCachePoint pd in points)
adjPoints.Add(new PCachePoint(pd.Type, pd.Position + offsetCorrection, pd.Direction));
float neighborhoodRange = gridStepSize;
//save neighborhoods
List<PCachePoint>[,,] nei = new List<PCachePoint>[(int)gridSize.x, (int)gridSize.y, (int)gridSize.z];
foreach (PCachePoint pcpoint in adjPoints) {
Vector3 min = new Vector3(
getFloorGridPoint(pcpoint.Position.x),
getFloorGridPoint(pcpoint.Position.y),
getFloorGridPoint(pcpoint.Position.z));
Vector3 max = new Vector3(
getCeilGridPoint(pcpoint.Position.x, (int)gridSize.x),
getCeilGridPoint(pcpoint.Position.y, (int)gridSize.y),
getCeilGridPoint(pcpoint.Position.z, (int)gridSize.z));
//Debug.Log("gridsize: " + (int)gridSize.x + " " + (int)gridSize.y + " " + (int)gridSize.z + ", point count: " + points.Count);
//Debug.Log("point position: " + pcpoint.Position + " with step size: " + gridStepSize + " results in min neighbors " + min + " and max neighbors" + max);
//get higher nearest grid point wihtin neighborhood range
float getCeilGridPoint(float value, int gridDimensionMax) {
value += neighborhoodRange;
value = Mathf.Floor(value / gridStepSize);
return value > gridDimensionMax ? gridDimensionMax : value;
}
//get lower nearest grid point wihtin neighborhood range
float getFloorGridPoint(float value) {
value -= neighborhoodRange;
value = Mathf.Ceil(value / gridStepSize);
return value < 0 ? 0 : value;
}
//add pcache point to neighborhood gridpoints
for (int x = (int)min.x; x <= max.x; x++) {
for (int y = (int)min.y; y <= max.y; y++) {
for (int z = (int)min.z; z <= max.z; z++) {
Debug.Log("size: " + gridSize + " und koordinaten x: " + x + ", y: " + y + ", z: " + z);
if (nei[x, y, z] == null)
nei[x, y, z] = new List<PCachePoint>();
nei[x, y, z].Add(pcpoint);
}
}
}
}
//compute grid points
for (int x = 0; x < gridSize.x; x++) {
for (int y = 0; y < gridSize.y; y++) {
for (int z = 0; z < gridSize.z; z++) {
Vector3 pointPos = new Vector3(x * gridStepSize, y * gridStepSize, z * gridStepSize);
if (nei[x, y, z] != null) {
//find nearest neighbor
int nearestIndex = 0;
float nearestDist = Vector3.Distance(pointPos, nei[x, y, z][0].Position);
for (int i = 1; i < nei[x, y, z].Count; i++) {
var dist = Vector3.Distance(pointPos, nei[x, y, z][i].Position);
if (dist < nearestDist) {
dist = nearestDist;
nearestIndex = i;
}
}
directionGrid[x, y, z] = nei[x, y, z][nearestIndex].Direction;
info[x, y, z] = nei[x, y, z][nearestIndex].Type;
}
else {
directionGrid[x, y, z] = Vector3.zero;
info[x, y, z] = 0;
}
}
}
}
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 416f29c10b3b3da4d80d2cf210657dd6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.IO;
using System.Globalization;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
public class CelToPCache : MonoBehaviour {
[Tooltip("Path to CEL Data files containing the extensions .cel, .daten and .vrt \n" +
"STAR-CCM+ export options should be: Export Data: all Regions, Velocity (only vector \"Lab Reference Frame\"," +
" not magnitude or i, j, k; Export Type: Mesh and Solution Data")]
public string PathToFolder = "";
public bool ConvertCelToPCacheNow = default;
/// <summary>
/// All files share the same name, only distinged by the extensions ".cel", ".daten" and ".vrt"
/// </summary>
private string filenames = "";
/// <summary>
/// Key: ID, Value: Position
/// </summary>
Dictionary<int, Vector3> vertices;
Dictionary<int, Cell> cells;
List<PCachePoint> pcachePoints;
private void Update() {
if (ConvertCelToPCacheNow) {
ConvertCelToPCacheNow = false;
ConvertCelToPCache();
}
}
private void ConvertCelToPCache() {
FindFileNames();
ReadVertices();
ReadCells();