public Triangle(NormalVector vector, List <Vertex> vertex) { Vector = vector; Vertex = vertex; }
public static async Task <double> CalculateVolume(string path) { Model nowy = new Model(); string inputPath = path; string header = ""; UInt32 trianglesCount = 0; using (FileStream fs = File.OpenRead(inputPath)) { var bajt = 0; double dx, dy, dz; int x1, x2, x3, x4; for (int i = 0; i < 80; i++) { bajt = fs.ReadByte(); header += Convert.ToChar(bajt); } x1 = fs.ReadByte(); x2 = fs.ReadByte(); x3 = fs.ReadByte(); x4 = fs.ReadByte(); string bits = make8CharBinary(Convert.ToString(x4, 2)) + make8CharBinary(Convert.ToString(x3, 2)) + make8CharBinary(Convert.ToString(x2, 2)) + make8CharBinary(Convert.ToString(x1, 2)); trianglesCount = Convert.ToUInt32(bits, 2); for (UInt32 i = 0; i < trianglesCount; i++) { x1 = fs.ReadByte(); x2 = fs.ReadByte(); x3 = fs.ReadByte(); x4 = fs.ReadByte(); dx = Real32ToDouble(x1, x2, x3, x4); x1 = fs.ReadByte(); x2 = fs.ReadByte(); x3 = fs.ReadByte(); x4 = fs.ReadByte(); dy = Real32ToDouble(x1, x2, x3, x4); x1 = fs.ReadByte(); x2 = fs.ReadByte(); x3 = fs.ReadByte(); x4 = fs.ReadByte(); dz = Real32ToDouble(x1, x2, x3, x4); NormalVector vector = new NormalVector(dx, dy, dz); x1 = fs.ReadByte(); x2 = fs.ReadByte(); x3 = fs.ReadByte(); x4 = fs.ReadByte(); dx = Real32ToDouble(x1, x2, x3, x4); x1 = fs.ReadByte(); x2 = fs.ReadByte(); x3 = fs.ReadByte(); x4 = fs.ReadByte(); dy = Real32ToDouble(x1, x2, x3, x4); x1 = fs.ReadByte(); x2 = fs.ReadByte(); x3 = fs.ReadByte(); x4 = fs.ReadByte(); dz = Real32ToDouble(x1, x2, x3, x4); Vertex v1 = new Vertex(dx, dy, dz); x1 = fs.ReadByte(); x2 = fs.ReadByte(); x3 = fs.ReadByte(); x4 = fs.ReadByte(); dx = Real32ToDouble(x1, x2, x3, x4); x1 = fs.ReadByte(); x2 = fs.ReadByte(); x3 = fs.ReadByte(); x4 = fs.ReadByte(); dy = Real32ToDouble(x1, x2, x3, x4); x1 = fs.ReadByte(); x2 = fs.ReadByte(); x3 = fs.ReadByte(); x4 = fs.ReadByte(); dz = Real32ToDouble(x1, x2, x3, x4); Vertex v2 = new Vertex(dx, dy, dz); x1 = fs.ReadByte(); x2 = fs.ReadByte(); x3 = fs.ReadByte(); x4 = fs.ReadByte(); dx = Real32ToDouble(x1, x2, x3, x4); x1 = fs.ReadByte(); x2 = fs.ReadByte(); x3 = fs.ReadByte(); x4 = fs.ReadByte(); dy = Real32ToDouble(x1, x2, x3, x4); x1 = fs.ReadByte(); x2 = fs.ReadByte(); x3 = fs.ReadByte(); x4 = fs.ReadByte(); dz = Real32ToDouble(x1, x2, x3, x4); Vertex v3 = new Vertex(dx, dy, dz); List <Vertex> nowa = new List <Vertex>(); nowa.Add(v1); nowa.Add(v2); nowa.Add(v3); Triangle tri = new Triangle(vector, nowa); nowy.Triangles.Add(tri); fs.ReadByte(); fs.ReadByte(); } } double volume = 0; foreach (var tri in nowy.Triangles) { volume += calculate3x3Determinant(tri) / 6; } return(volume); }