Commit 74526422 authored by Patrick's avatar Patrick
parents f67e10e2 11b6b7b8
......@@ -164,7 +164,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6ea514f390717be4996e41605363758e, type: 3}
m_Name:
m_EditorClassIdentifier:
PathToFolder: D:\Unity\Git Projekte\StarCCMToUnityVFX\Assets\Data\10percentCells
PathToFolder: D:\Unity\Git Projekte\StarCCMToUnityVFX\Assets\Data\vtk_files\101
GridStepSize: 0.2
ConvertVTKToVectorfield: 0
--- !u!1 &425404723
......
......@@ -20,7 +20,7 @@ namespace Teamproject {
_filename = filename;
}
public void WriteToVectorfield(Vector3[,,] direction) {
public void WriteToVectorfield(Vector3[,,] direction, bool squareGrid = false) {
_direction = direction;
int x, y, z;
......@@ -29,6 +29,9 @@ namespace Teamproject {
z = _direction.GetLength(2);
_gridsize = new Vector3(x, y, z);
if (squareGrid)
SquareGridVEC();
string fullPath = _targetPath + "/" + _filename + ".vf";
sr = File.Create(fullPath);
......@@ -37,7 +40,7 @@ namespace Teamproject {
sr.Close();
}
public void WriteToVectorfield(float[,,] info) {
public void WriteToVectorfield(float[,,] info, bool squareGrid = false) {
_info = info;
int x, y, z;
......@@ -46,6 +49,9 @@ namespace Teamproject {
z = _info.GetLength(2);
_gridsize = new Vector3(x, y, z);
if (squareGrid)
SquareGridFLOAT();
string fullPath = _targetPath + "/" + _filename + "_info.vf";
sr = File.Create(fullPath);
......@@ -55,6 +61,53 @@ namespace Teamproject {
}
#region vector
private void SquareGridVEC() {
//find highest dimension
int highestDim = 0;
if (_gridsize.x >= _gridsize.y && _gridsize.x >= _gridsize.z)
highestDim = (int)_gridsize.x;
if (_gridsize.y >= _gridsize.x && _gridsize.y >= _gridsize.z)
highestDim = (int)_gridsize.y;
if (_gridsize.z >= _gridsize.y && _gridsize.z >= _gridsize.x)
highestDim = (int)_gridsize.z;
//find next highest dimension count, that is a result of 2^n
int maxDimCount = 0;
for (int i = 0; i < 10; i++) {
if(Math.Pow(2, i) > highestDim) {
maxDimCount = (int)Math.Pow(2, i);
break;
}
}
//number of indices that have to be filled in each dimension
int xFill, yFill, zFill;
xFill = maxDimCount - (int)_gridsize.x;
yFill = maxDimCount - (int)_gridsize.y;
zFill = maxDimCount - (int)_gridsize.z;
//index where the padding ends/ grids values get inserted
int xFillStart = xFill / 2;
int yFillStart = yFill / 2;
int zFillStart = zFill / 2;
//fill new grid with zero
Vector3[,,] newGrid = new Vector3[maxDimCount, maxDimCount, maxDimCount];
for (int x = 0; x < maxDimCount; x++)
for (int y = 0; y < maxDimCount; y++)
for (int z = 0; z < maxDimCount; z++)
newGrid[x, y, z] = Vector3.zero;
//insert old grid centered in the new one
for (int x = 0; x < _gridsize.x; x++)
for (int y = 0; y < _gridsize.y; y++)
for (int z = 0; z < _gridsize.z; z++)
newGrid[x + xFillStart, y + yFillStart, z + zFillStart] = _direction[x, y, z];
_direction = newGrid;
_gridsize = new Vector3(maxDimCount, maxDimCount, maxDimCount);
}
private void WriteHeaderVEC() {
Debug.Log("Writing VF-Header");
......@@ -87,6 +140,53 @@ namespace Teamproject {
#endregion
#region float
private void SquareGridFLOAT() {
//find highest dimension
int highestDim = 0;
if (_gridsize.x >= _gridsize.y && _gridsize.x >= _gridsize.z)
highestDim = (int)_gridsize.x;
if (_gridsize.y >= _gridsize.x && _gridsize.y >= _gridsize.z)
highestDim = (int)_gridsize.y;
if (_gridsize.z >= _gridsize.y && _gridsize.z >= _gridsize.x)
highestDim = (int)_gridsize.z;
//find next highest dimension count, that is a result of 2^n
int maxDimCount = 0;
for (int i = 0; i < 10; i++) {
if (Math.Pow(2, i) > highestDim) {
maxDimCount = (int)Math.Pow(2, i);
break;
}
}
//number of indices that have to be filled in each dimension
int xFill, yFill, zFill;
xFill = maxDimCount - (int)_gridsize.x;
yFill = maxDimCount - (int)_gridsize.y;
zFill = maxDimCount - (int)_gridsize.z;
//index where the padding ends/ grids values get inserted
int xFillStart = xFill / 2;
int yFillStart = yFill / 2;
int zFillStart = zFill / 2;
//fill new grid with zero
float[,,] newGrid = new float[maxDimCount, maxDimCount, maxDimCount];
for (int x = 0; x < maxDimCount; x++)
for (int y = 0; y < maxDimCount; y++)
for (int z = 0; z < maxDimCount; z++)
newGrid[x, y, z] = 0;
//insert old grid centered in the new one
for (int x = 0; x < _gridsize.x; x++)
for (int y = 0; y < _gridsize.y; y++)
for (int z = 0; z < _gridsize.z; z++)
newGrid[x + xFillStart, y + yFillStart, z + zFillStart] = _info[x, y, z];
_info = newGrid;
_gridsize = new Vector3(maxDimCount, maxDimCount, maxDimCount);
}
private void WriteHeaderFLOAT() {
Debug.Log("Writing VF-Header");
......@@ -106,10 +206,10 @@ namespace Teamproject {
Debug.Log("Writing data to file");
// "Elements are packed as an array of struct, organized by X then Y then Z." -> loops order important
for (int z = 0; z < _gridsize.z; z++)
for (int y = 0; y < _gridsize.y; y++)
for (int x = 0; x < _gridsize.x; x++)
sr.Write(BitConverter.GetBytes(_info[x, y, z]), 0, 4);
for (int z = 0; z < _gridsize.z; z++)
for (int y = 0; y < _gridsize.y; y++)
for (int x = 0; x < _gridsize.x; x++)
sr.Write(BitConverter.GetBytes(_info[x, y, z]), 0, 4);
}
#endregion
}
......
......@@ -7,6 +7,7 @@ using UnityEngine;
namespace Teamproject {
public class VTKDataReader {
public Dictionary<int, PCachePoint> points { get; private set; }
public Dictionary<int, float> pressure { get; private set; }
private string _pathToFolder;
private string _filenames;
......@@ -128,12 +129,45 @@ namespace Teamproject {
currentLine = reader.ReadLine();
}
//TODO: rename to "read scalar data", change to reading multiple parameters
private void ReadPressure() {
currentLine = reader.ReadLine();
if (!currentLine.StartsWith("SCALARS"))
return;
string lookuptable = reader.ReadLine();
//go into the first line with scalar values
currentLine = reader.ReadLine();
int currentPointID = 0;
int maxPointID = points.Keys.Count - 1;
pressure = new Dictionary<int, float>();
while(currentPointID != maxPointID) {
if (currentLine.EndsWith(" "))
currentLine = currentLine.Remove(currentLine.Length - 1); //else we get an empty array entry at the end in the next line
string[] parts = currentLine.Split(' ');
foreach (string part in parts) {
float f;
if(float.TryParse(part.Split('.')[0], out f)) {
} else {
Debug.Log("Failed parsing value >" + part + "<");
f = 0;
}
pressure[currentPointID] = f;
currentPointID++;
}
currentLine = reader.ReadLine();
}
//TODO: read scalar info
}
......
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