Commit 1153b69a authored by Moritz's avatar Moritz

VectorFieldWriter: added option to square the grid before writing (length of all dimensions equal)

parent 437f952c
......@@ -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,44 @@ namespace Teamproject {
}
#region vector
private void SquareGridVEC() {
//find dimension with highest count
int maxDimCount = 0;
if (_gridsize.x >= _gridsize.y && _gridsize.x >= _gridsize.z)
maxDimCount = (int)_gridsize.x;
if (_gridsize.y >= _gridsize.x && _gridsize.y >= _gridsize.z)
maxDimCount = (int)_gridsize.y;
if (_gridsize.z >= _gridsize.y && _gridsize.z >= _gridsize.x)
maxDimCount = (int)_gridsize.z;
//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 +131,44 @@ namespace Teamproject {
#endregion
#region float
private void SquareGridFLOAT() {
//find dimension with highest count
int maxDimCount = 0;
if (_gridsize.x >= _gridsize.y && _gridsize.x >= _gridsize.z)
maxDimCount = (int)_gridsize.x;
if (_gridsize.y >= _gridsize.x && _gridsize.y >= _gridsize.z)
maxDimCount = (int)_gridsize.y;
if (_gridsize.z >= _gridsize.y && _gridsize.z >= _gridsize.x)
maxDimCount = (int)_gridsize.z;
//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 +188,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
}
......
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