//CALCULATE ORIENTATION FROM PATIENTORIENTATION TAG private string GetPatientOrientationString(double[] orientations) { string orientation = null; if (orientations != null) { var rowDirection = new Dicom.Imaging.Mathematics.Vector3D(orientations, 0); // take 3 values starting from index 0 var colDirection = new Dicom.Imaging.Mathematics.Vector3D(orientations, 3); // take 3 values starting from index 3 var normalvector = colDirection.CrossProduct(rowDirection); var nearestAxis = normalvector.NearestAxis(); var nearestAxisString = nearestAxis.ToString().Replace(" ", ""); switch (nearestAxisString) { case ("(0,1,0)"): orientation = "Coronal AP"; break; case ("(0,-1,0)"): orientation = "Coronal PA"; break; case ("(0,0,1)"): orientation = "Axial SI"; break; case ("(0,0,-1)"): orientation = "Axial IS"; break; case ("(1,0,0)"): orientation = "Saggital LR"; break; case ("(-1,0,0)"): orientation = "Saggital RL"; break; default: orientation = "N/A"; break; } } else { orientation = "N/A"; } return(orientation); }
public Vector3D(Vector3D v) { _x = v.X; _y = v.Y; _z = v.Z; }
public Vector3D Reflect(Vector3D normal) { double dot = DotProduct(normal); return new Vector3D( X - ((dot * 2.0f) * normal.X), Y - ((dot * 2.0f) * normal.Y), Z - ((dot * 2.0f) * normal.Z)); }
public Orientation3D(Vector3D forward, Vector3D down) { _forward = forward; _down = down; }
public Slice3D(Vector3D normal, Point3D topLeft, double width, double height) { Vector3D right = normal.Rotate(Vector3D.AxisY, -90.0); Vector3D down = normal.Rotate(Vector3D.AxisX, -90.0); _topLeft = topLeft; _topRight = _topLeft + (right * width); _bottomLeft = _topLeft + (down * height); _bottomRight = _bottomLeft + (right * width); _normal = normal; _width = width; _height = height; _plane = new Plane3D(normal, _topLeft); }
public Plane3D(Point3D a, Point3D b, Point3D c) { Vector3D av = a.ToVector(); Vector3D bv = b.ToVector(); Vector3D cv = c.ToVector(); _normal = (bv - av).CrossProduct(cv - av).Normalize(); _point = a; }
public bool ClosestPoints(Line3D b, out Point3D pa, out Point3D pb) { pa = null; pb = null; if (Vector == b.Vector || Vector == -b.Vector) return false; Vector3D p0 = Point.ToVector(); Vector3D p1 = b.Point.ToVector(); Vector3D d0 = Vector; Vector3D d1 = b.Vector; Vector3D d0n = d0.Normalize(); Vector3D c = new Vector3D(); Vector3D d = new Vector3D(); d.X = d1.X - d0n.X * (d0.X * d1.X + d0.Y * d1.Y + d0.Z * d1.Z); c.X = p1.X - p0.X + d0n.X * (d0.X * p0.X + d0.Y * p0.Y + d0.Z * p0.Z); d.Y = d1.Y - d0n.Y * (d0.X * d1.X + d0.Y * d1.Y + d0.Z * d1.Z); c.Y = p1.Y - p0.Y + d0n.Y * (d0.X * p0.X + d0.Y * p0.Y + d0.Z * p0.Z); d.Z = d1.Z - d0n.Z * (d0.X * d1.X + d0.Y * d1.Y + d0.Z * d1.Z); c.Z = p1.Z - p0.Z + d0n.Z * (d0.X * p0.X + d0.Y * p0.Y + d0.Z * p0.Z); double t = -(c.X * d.X + c.Y * d.Y + c.Z * d.Z) / (d.X * d.X + d.Y * d.Y + d.Z * d.Z); pb = b.Point + (b.Vector * t); pa = ClosestPoint(pb); return true; }
public Line3D(Point3D p, Vector3D v) { _point = p.Clone(); _vector = v.Clone(); }
public Vector3D CrossProduct(Vector3D b) { return new Vector3D((Y * b.Z) - (Z * b.Y), (Z * b.X) - (X * b.Z), (X * b.Y) - (Y * b.X)); }
public double DotProduct(Vector3D b) { return (X * b.X) + (Y * b.Y) + (Z * b.Z); }
public void Yaw(double angle) { _forward = _forward.Rotate(_down, angle); }
public void Roll(double angle) { _down = _down.Rotate(_forward, angle); }
public void Pitch(double angle) { Vector3D right = Right; _forward = _forward.Rotate(right, angle); _down = _down.Rotate(right, angle); }
public Orientation3D(Orientation3D orientation) { _forward = orientation.Forward.Clone(); _down = orientation.Down.Clone(); }
public Point3D Move(Vector3D axis, double distance) { return this + (axis.Normalize() * distance); }
public Line3D() { _point = Point3D.Zero.Clone(); _vector = Vector3D.Zero.Clone(); }
public double Distance(Vector3D b) { return Math.Sqrt((X - b.X) * (X - b.X) + (Y - b.Y) * (Y - b.Y) + (Z - b.Z) * (Z - b.Z)); }
public Line3D(Line3D line) { _point = line.Point.Clone(); _vector = line.Vector.Clone(); }
public bool IsPerpendicular(Vector3D b) { return DotProduct(b) == 0; }
public Plane3D(Vector3D normal, Point3D point) { _normal = normal; _point = point; }
public static Vector3D Max(Vector3D a, Vector3D b) { return (a >= b) ? a : b; }
public bool Intersect(Plane3D b, out Line3D intersection) { intersection = null; if (IsParallel(b)) return false; Point3D p; Vector3D v1 = Normal.CrossProduct(b.Normal); Vector3D v2 = new Vector3D(v1.X * v1.X, v1.Y * v1.Y, v1.Z * v1.Z); double w1 = -Distance; double w2 = -b.Distance; double id; if ((v2.Z > v2.Y) && (v2.Z > v2.X) && (v2.Z > Double.Epsilon)) { // point on XY plane id = 1.0 / v1.Z; p = new Point3D(Normal.Y * w2 - b.Normal.Y * w1, b.Normal.X * w1 - Normal.X * w2, 0.0); } else if ((v2.Y > v2.X) && (v2.Y > Double.Epsilon)) { // point on XZ plane id = -1.0 / v1.Y; p = new Point3D(Normal.Z * w2 - b.Normal.Z * w1, 0.0, b.Normal.Y * w1 - Normal.Y * w2); } else if (v2.X > Double.Epsilon) { // point on YZ plane id = 1.0 / v1.X; p = new Point3D(0.0, Normal.Z * w2 - b.Normal.Z * w1, b.Normal.Y * w1 - Normal.Y * w2); } else return false; p = (p.ToVector() * id).ToPoint(); id = 1.0 / Math.Sqrt(v2.X + v2.Y + v2.Z); v1 *= id; intersection = new Line3D(p, p.ToVector() + v1); return true; }
public static Vector3D Min(Vector3D a, Vector3D b) { return (a <= b) ? a : b; }
public Vector3D Rotate(Vector3D axis, double angle) { axis = axis.Normalize(); Vector3D parallel = axis * DotProduct(axis); Vector3D perpendicular = this - parallel; Vector3D mutualPerpendicular = axis.CrossProduct(perpendicular); Vector3D rotatePerpendicular = (perpendicular * Math.Cos(angle)) + (mutualPerpendicular * Math.Sin(angle)); return rotatePerpendicular + parallel; }
public Orientation3D() { _forward = new Vector3D(1.0, 0.0, 0.0); _down = new Vector3D(0.0, 0.0, 1.0); }