-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIsoSurface.java
140 lines (122 loc) · 4.39 KB
/
IsoSurface.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package com.wtv.processing;
import com.wtv.converter.CSVReader;
import com.wtv.converter.ObjConverter;
import com.wtv.structures.Point;
import java.io.IOException;
import java.util.*;
public class IsoSurface {
public static void main(String[] args) // Eingabe: Filepath, Spaltentrenner(ohne space)
{
try {
printIsoCubes("examples/sphere01.csv", 4);
} catch (Exception e){
e.printStackTrace();
}
}
public static void printIsoCubes(String fileName, int lineAmount) throws IOException {
double[][][] result = CSVReader.dateiLesen3D(fileName);
assert result != null;
double[] lineHeights = lineHeights(lineAmount, findMin(result), findMax(result));
int i = 0;
for(double h: lineHeights){
i++;
ObjConverter.objCreateCubes(findIso(result, h), fileName.split("\\.")[0] + "(" + i + ")");
}
}
public static void printIsoTetrahedrons(String fileName, int lineAmount) throws IOException {
double[][][] result = CSVReader.dateiLesen3D(fileName);
assert result != null;
double[] lineHeights = lineHeights(lineAmount, findMin(result), findMax(result));
int i = 0;
for(double h: lineHeights){
i++;
ObjConverter.objCreateTetrahedrons(findIso(result, h), fileName.split("\\.")[0] + "(" + i + ")");
}
}
public static double[] lineHeights(int amount, double min, double max) {
double[] result = new double[amount];
double interval = max - min;
for(int i = 0; i < amount; i++){
result[i] = min + (interval/(amount+1)) * (i+1);
}
return result;
}
/**
* Uebung 7 1b
* @param values a 3d array which may not be empty
* @return the lowest value in the whole array
*/
public static double findMin(double[][][] values){
double min = Double.MAX_VALUE;
for (double[][] arr2 : values) {
for (double[] arr1: arr2) {
for (double v: arr1) {
if(v < min) min = v;
}
}
}
return min;
}
/**
* Uebung 7 1b
* @param values a 3d array which may not be empty
* @return the highest value in the whole array
*/
public static double findMax(double[][][] values){
double max = Double.MIN_VALUE;
for (double[][] arr2 : values) {
for (double[] arr1: arr2) {
for (double v: arr1) {
if(v > max) max = v;
}
}
}
return max;
}
/**
* Uebung 7 1c
* @param values
* @param iso
* @return
*/
public static Set<Point> findIso(double[][][] values, double iso) {
Set<Point> result = new HashSet<>();
for (int z = 0; z < values[0][0].length-1; z++) {
for (int y = 0; y < values[0].length-1; y++) {
for (int x = 0; x < values.length-1; x++ ) {
Point a = new Point(x,y,z,values[x][y][z]);
Point b;
b = new Point(x+1,y,z,values[x+1][y][z]);
result.add(intersectionOfLine(a,b,iso));
b = new Point(x,y+1,z,values[x][y+1][z]);
result.add(intersectionOfLine(a,b,iso));
b = new Point(x,y,z+1,values[x][y][z+1]);
result.add(intersectionOfLine(a,b,iso));
}
}
}
result.remove(null);
return result;
}
/**
* This is a subroutine of findIso. Returns the Point at which a linear interpolation between input a and b
* reaches the value iso
* @param a first point
* @param b second point
* @param iso the value to which we want to interpolate
* @return Either returns the Point at which a linear interpolation between input a and b reaches the value iso,
* or null if such point does not exist
*/
public static Point intersectionOfLine(Point a, Point b, double iso) {
double factor = (iso - a.value) / (b.value - a.value); //=NaN when dividing by zero
Point p = null;
if(0 <= factor && factor <=1) {
p = new Point(
a.x + (factor * (b.x-a.x)),
a.y + (factor * (b.y-a.y)),
a.z + (factor * (b.z-a.z)),
iso);
}
return p;
}
}