Commit fc2de57b authored by Moritz's avatar Moritz

PointcloudToGridMapper.cs:

- removed calculation of the gridStepSize and all unneeded related parameters, this parameter now gets passed in the constructor
- improved comments in IntegratePointsToGrid()
- renamed min to minGridPoint and max to maxGridPoint in IntegratePointsToGrid()

CelToVF.cs:
- Passes now the grid stepo size instead of the storage size to the PointcloudToGridMapper
- Added display of the passed time

CelToVF.unity:
- Set initial parameter for GridStepSize that isn't too big/ small
parent 979fd095
......@@ -150,7 +150,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4591081a534893840a918e42738fa734, type: 3}
m_Name:
m_EditorClassIdentifier:
PathToFolder: D:\Unity\Projekte\PCacheTest\Assets\Data\cel2
PathToFolder: D:\Unity\Git Projekte\StarCCMToUnityVFX\Assets\Data\cel
GridStepSize: 0.03
ConvertCelToVectorfield: 0
--- !u!4 &367691295
Transform:
......
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
......@@ -9,17 +10,22 @@ namespace Teamproject {
" 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;
// Update is called once per frame
void Update() {
if(ConvertCelToVectorfield) {
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>");
......@@ -34,7 +40,7 @@ namespace Teamproject {
Dictionary<int, Cell> cells = reader.cells;
Dictionary<int, Vector3> vertices = reader.vertices;
var gridMapper = new PointcloudToGridMapper(cells, vertices, 1000000000); //1GB
var gridMapper = new PointcloudToGridMapper(cells, vertices, GridStepSize);
gridMapper.StartConvert();
Debug.Log("<color=teal> Mapping complete, starting writing to vectorfield </color>");
......@@ -45,7 +51,9 @@ namespace Teamproject {
//writer.WriteToVectorfield(gridMapper.info);
Debug.Log("<color=teal> Writing to vectorfield complete </color>");
Debug.Log("<color=teal> Everything done!!! </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
......@@ -16,11 +16,9 @@ namespace Teamproject {
/// </summary>
public float[,,] info { get; private set; }
int VECTORBYTESIZE = 12;
Dictionary<int, Cell> _cells;
Dictionary<int, Vector3> _vertices;
int _storageSize = -1;
float _inputGridStepSize = -1;
//pcache
private List<PCachePoint> points;
......@@ -34,12 +32,11 @@ namespace Teamproject {
/// </summary>
/// <param name="cells"></param>
/// <param name="vertices"></param>
/// <param name="storageSize"> Final file size in bytes </param>
public PointcloudToGridMapper(Dictionary<int, Cell> cells, Dictionary<int, Vector3> vertices, int storageSize) {
/// <param name="inputGridStepSize"> Distance of adjacent gridpoints, entered by the user, in Millimeter </param>
public PointcloudToGridMapper(Dictionary<int, Cell> cells, Dictionary<int, Vector3> vertices, float inputGridStepSize) {
_cells = cells;
_vertices = vertices;
_storageSize = storageSize;
Debug.Log("storage size: " + _storageSize);
_inputGridStepSize = inputGridStepSize;
}
public void StartConvert() {
......@@ -78,26 +75,14 @@ namespace Teamproject {
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 maximum storage size, dependent from bounding box size -> conclude to step size
float bbX, bbY, bbZ; //bounding box sizes
bbX = maxX - minX;
bbY = maxY - minY;
bbZ = maxZ - minZ;
//TODO: comment
gridStepSize = (bbX * bbY * bbZ) / (_storageSize / VECTORBYTESIZE);
gridStepSize = Mathf.Pow(gridStepSize, 1f / 2.7658f);
//conversion to millimeter
gridStepSize = (_inputGridStepSize * Mathf.Pow(10, -3));
//create grid
int gridXSize = (int)Mathf.Ceil(maxX / gridStepSize);
......@@ -128,14 +113,31 @@ namespace Teamproject {
}
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
/*
* To integrate the points (point = "free" point calculated from the simulation results, not bound to grid) into the grid,
* we need to know which free points influence which gridpoints. Free points influence a gridpoint if they are near enough,
* called the neighbourhood.
* There are several ways to compute the neighbourhood:
*
* Naive approach:
* Iterate for each gridpoint g through all free points f
* -> complexity = count(g) ^ count(f)
*
* Inverted Lists approach:
* The neighbourhood (near enough free points to a gridpoint) is saved as a List<Free Point> for each gridpoint
* 1. Iterate through all free points
* 2. Calculate which gridpoints are surrounding the current free point
* 3. Save current free point in the neighbourhood-list of each gridpoint
* 4. For grid calculation: neighbourhoods are saved and easily accessable
* Advantage: complexity = count(g) * count (f) (count(g) * count (f) << count(g) ^ count(f))
* Disadvantage: more memory needed (each point in ~8 lists saved)
*
*
* Zum Speicherplatz mit den Listen:
* Points by reference abgespeichert oder? dann sollten die Listen ja eh nicht so groß sein
*/
//adjust free 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));
......@@ -143,15 +145,22 @@ namespace Teamproject {
float neighborhoodRange = gridStepSize;
//save neighborhoods
//Inverted Lists: calculate neighbourhoods (lists)
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(
/*
* Find the grid points that surround the current point
* maxGridPoint: gridpoint (directly surrounding the current point) most distant from the grid origin
* minGridPoint: gridpoint (directly surrounding the current point) nearest to the grid origin
* Watch out: maxGridPoint and minGridPoint could contain indices that are out of the grids bounds
*/
Vector3 minGridPoint = new Vector3(
getFloorGridPoint(pcpoint.Position.x),
getFloorGridPoint(pcpoint.Position.y),
getFloorGridPoint(pcpoint.Position.z));
Vector3 maxGridPoint = new Vector3(
getCeilGridPoint(pcpoint.Position.x, (int)gridSize.x),
getCeilGridPoint(pcpoint.Position.y, (int)gridSize.y),
getCeilGridPoint(pcpoint.Position.z, (int)gridSize.z));
......@@ -159,27 +168,35 @@ namespace Teamproject {
//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
//get higher nearest gridpoint within neighborhood range (higher = most distant from the grid origin)
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
//get lower nearest gridpoint within neighborhood range (lower = nearest to the grid origin)
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++) {
/*
* Remember for all gridpoints surrounding the current point, that this point is in their neighbourhood
* -> add free point to gridpoints neighborhood-list
*
* All surrounding gridpoints: defined by minGridPoint and maxGridPoint
*/
for (int x = (int)minGridPoint.x; x <= maxGridPoint.x; x++) {
for (int y = (int)minGridPoint.y; y <= maxGridPoint.y; y++) {
for (int z = (int)minGridPoint.z; z <= maxGridPoint.z; z++) {
//Debug.Log("size: " + gridSize + " und koordinaten x: " + x + ", y: " + y + ", z: " + z);
if ((x >= gridSize.x) || (y >= gridSize.y) || (z >= gridSize.z) || //index positive out of grids bounds
x < 0 || y < 0 || z < 0) //index negative out of grids bounds
continue;
if (nei[x, y, z] == null)
nei[x, y, z] = new List<PCachePoint>();
......@@ -189,6 +206,16 @@ namespace Teamproject {
}
}
/*
* To calculate the direction vector on each gridpoint: take direction vectors of the neighbourhoods free points
* Different approaches to combine the Vectors:
* 1. Don't combine, just take nearest free point to the current gridpoint
* 2. Treat all direction vectors equally, calculate mean direction vector
* 3. Weight influence of each free point with the distance to the current gridpoint, less distance = high influence
*
* currently 1. is used
*/
//compute grid points
for (int x = 0; x < gridSize.x; x++) {
for (int y = 0; y < gridSize.y; y++) {
......@@ -221,4 +248,5 @@ namespace Teamproject {
}
}
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment