public static Tuple <RadiotherapyStruct, string> LoadContours( string filePath, Transform3 dicomToData, string seriesUID = null, string studyUID = null, bool warningsAsErrors = true) { var file = DicomFile.Open(filePath); return(LoadContours(file.Dataset, dicomToData, seriesUID, studyUID, warningsAsErrors)); }
/// <summary> /// Map an array of doubles are read from DICOM into the coordinate space of the given volume3D /// </summary> /// <param name="dicomToData">The dicom to data transform.</param> /// <param name="contourData"></param> /// <returns></returns> private static Tuple <int, ContourPolygon> ToContour(Transform3 dicomToData, IReadOnlyList <double> contourData) { var array = new PointF[contourData.Count / 3]; var first3DPoint = new Point3D(contourData[0], contourData[1], contourData[2]); var firstPixel = dicomToData * first3DPoint; var z = Convert.ToInt32(firstPixel.Z); Parallel.For( 0, array.Length, i => { var j = i * 3; var physicalPoint = new Point3D( contourData[j], contourData[j + 1], contourData[j + 2]); var pixelPoint = dicomToData * physicalPoint; if (Convert.ToInt32(pixelPoint.Z) != z) { throw new ArgumentException( "Invalid data: this contour contains points that are not in the same plane"); } array[i] = new PointF((float)pixelPoint.X, (float)pixelPoint.Y); }); return(Tuple.Create(z, new ContourPolygon(array, 0))); }
/// <summary> /// Load a RadiotherapyStruct from the given dicom dataset and map into the coordinate of the given Volume3D /// </summary> /// <param name="ds">Dataset to read the structure set from</param> /// <param name="dicomToData">The transform from going between dicom and voxel points.</param> /// <param name="seriesUID">SeriesUID that must match the referenced seriesUID inside the structure set</param> /// <param name="studyUID">The structure set must belong to the same study</param> /// <param name="warningsAsErrors">true if warnings should be treated as errors and thrown from this method.</param> /// <returns>A new RadiotherapyStruct with any warnings collated into a string</returns> public static Tuple <RadiotherapyStruct, string> LoadContours( DicomDataset ds, Transform3 dicomToData, string seriesUID = null, string studyUID = null, bool warningsAsErrors = true) { RadiotherapyStruct rtStruct = RadiotherapyStruct.Read(ds); if (studyUID != null && studyUID != rtStruct.Study.StudyInstanceUid) { var warningText = $"The RT STRUCTURE Set does not belong to this Study"; if (warningsAsErrors) { throw new ArgumentException(warningText); } return(Tuple.Create <RadiotherapyStruct, string>(null, warningText)); } // ReferencedFramesOfRef must contain at least 1 study/series reference if (CheckUnreferencedSeries(rtStruct.StructureSet, seriesUID)) { var warningText = $"The RT STRUCTURE does not reference this Series"; if (warningsAsErrors) { throw new ArgumentException(warningText); } return(Tuple.Create <RadiotherapyStruct, string>(null, warningText)); } var contoursData = rtStruct.Contours; // Do not warn if all structures are empty if (contoursData.Count != 0 && !contoursData.Any(c => CanUseStructData(c.DicomRtContour))) { var warningText = $"The RT STRUCTURE does not contain CLOSED PLANAR contours"; if (warningsAsErrors) { throw new ArgumentException(warningText); } return(Tuple.Create <RadiotherapyStruct, string>(null, warningText)); } var warningTypeText = string.Empty; if (CheckUnsupportedData(rtStruct)) { var badTypes = UnsupportedTypes(rtStruct); warningTypeText = $"The RT STRUCTURE contains unsupported Contour Types: {string.Join(",",badTypes)}"; // remove the parent structures RemoveUnsupportedTypes(rtStruct); } Parallel.ForEach(contoursData, c => CreateStructureContoursBySlice(dicomToData, c)); return(Tuple.Create(rtStruct, warningTypeText)); }
public OpticalSurface(int id, Vector3Pair p, Transform3 transform, Curve curve, Shape shape, Medium left, Medium right) : base(id, p, transform, curve, shape) { _mat[0] = left; _mat[1] = right; }
public static Tuple <RadiotherapyStruct, string> LoadStruct(string rtfile, Transform3 dicomToData, string studyUId, string seriesUId) { try { var file = DicomFile.Open(rtfile); return(RtStructReader.LoadContours(file.Dataset, dicomToData, seriesUId, studyUId, true)); } catch (Exception ex) { throw new ArgumentException($"RT file {rtfile} cannot be loaded - {ex.Message}"); } }
public MainViewModel() { EffectsManager = new DefaultEffectsManager(); Title = "Material Demo"; this.Camera = new PerspectiveCamera { Position = new Point3D(-30, 30, -30), LookDirection = new Vector3D(30, -30, 30), UpDirection = new Vector3D(0, 1, 0) }; var builder = new MeshBuilder(); builder.AddBox(new Vector3(0, -6, 0), 200, 2, 100); Floor = builder.ToMesh(); builder = new MeshBuilder(); builder.AddSphere(Vector3.Zero, 2); LoadObj(@"shaderBall\shaderBall.obj"); EnvironmentMap = LoadFileToMemory("Cubemap_Grandcanyon.dds"); ColorStripeMaterial.ColorStripeX = GetGradients(new Color4(1, 0, 0, 1), new Color4(0, 1, 0, 1), new Color4(0, 0, 1, 1), 48).ToList(); ColorStripeMaterial.ColorStripeY = GetGradients(new Color4(1, 1, 0, 1), new Color4(0, 1, 1, 1), new Color4(1, 0, 1, 1), 48).ToList(); MeshTitles = new BillboardText3D(); MeshTitles.TextInfo.Add(new TextInfo("Blinn", Transform1.ToVector3()) { Scale = 0.08f, Background = new Color4(1, 1, 1, 1) }); MeshTitles.TextInfo.Add(new TextInfo("Normal", Transform2.ToVector3()) { Scale = 0.08f, Background = new Color4(1, 1, 1, 1) }); MeshTitles.TextInfo.Add(new TextInfo("Diffuse", Transform3.ToVector3()) { Scale = 0.08f, Background = new Color4(1, 1, 1, 1) }); MeshTitles.TextInfo.Add(new TextInfo("Position", Transform4.ToVector3()) { Scale = 0.08f, Background = new Color4(1, 1, 1, 1) }); MeshTitles.TextInfo.Add(new TextInfo("VertexColor", Transform5.ToVector3()) { Scale = 0.08f, Background = new Color4(1, 1, 1, 1) }); MeshTitles.TextInfo.Add(new TextInfo("ColorStripe", Transform6.ToVector3()) { Scale = 0.08f, Background = new Color4(1, 1, 1, 1) }); (FloorMaterial as PhongMaterial).RenderShadowMap = true; }
public List <byte> Write() { List <byte> bytes = new List <byte>(); bytes.AddRange(Transform1.Write()); bytes.AddRange(Transform2.Write()); bytes.AddRange(Transform3.Write()); bytes.AddRange(Transform4.Write()); bytes.AddRange(Transform5.Write()); if (bytes.Count != 320) { throw new InvalidDataException("FPF_SubEntry is an invalid size."); } return(bytes); }
/// <summary> /// Map the given structure into the coordinate space of the Volume3D specified creating the /// ContoursBySlice instance /// </summary> /// <param name="dicomToData">The dicom to data transform.</param> /// <param name="c"></param> private static void CreateStructureContoursBySlice(Transform3 dicomToData, RadiotherapyContour c) { var structContours = c.DicomRtContour.DicomRtContourItems; var contourPoints = new List <Tuple <int, ContourPolygon> >(); foreach (var contour in structContours) { var pointsOnSlice = ToContour(dicomToData, contour.Data); contourPoints.Add(pointsOnSlice); } var sliceDict = contourPoints.GroupBy(x => x.Item1). ToDictionary(x => x.Key, g => (IReadOnlyList <ContourPolygon>)g.Select(x => x.Item2). ToList()); c.Contours = new ContoursPerSlice(sliceDict); }
public Camera(Point3 pos, Point3 lookat, Vector3 up, int width, int height, double fov = 45.0) { this.campos = pos; Vector3 lookdir = (lookat - pos).Normalized; Vector3 camside = up.Normalized.Cross(lookdir); Vector3 camup = camside.Cross(lookdir); camtrans = new Transform3(camside, camup, lookdir); this.Width = width; this.Height = height; double fovx = Coral.MathUtil.DegToRad(fov); double fovy = ((double)height / (double)width) * fovx; tan_fovx = Math.Tan(fovx); tan_fovy = -Math.Tan(fovy); }
private double r; //tube radius public TrTorus(Point3 center, double majrad, double tuberad, Material mat) : base(Transform3.Scale(majrad), mat) { this.R = 1.0; this.r = tuberad / majrad; this.center = center; }
public static TexMat ToTexMat(this Transform3 transform) { return(new TexMat(transform.ToMatrixd())); }
public TracerObject(Transform3 pos, Material mat) { this.Position = pos; this.Material = mat; this.InvPosition = Position.Inverse; }
public Stop(int id, Vector3Pair p, Transform3 transform, Curve curve, Shape shape) : base(id, p, transform, curve, shape) { _external_radius = shape.max_radius() * 2.0; }
//x^4+5x^2+y^4-5y^2+z^4-5z^2+11.8=0 public TrTangleCube(Point3 center, double size, Material mat) : base(Transform3.Scale(100.0), mat) { }
public MirrorSurface(int id, Vector3Pair p, Transform3 transform, Curve curve, Shape shape, Medium left, Medium right) : base(id, p, transform, curve, shape, left, right) { }
internal TransformVolume(Volume root) { Root = root; transformStack = Transform3.NewTransformStack(); }
public TrSphere(Point3 center, double rad, Material mat) : base(Transform3.Translate(center.X, center.Y, center.Z), mat) { this.rad = rad; }
public Image(int id, Vector3Pair p, Transform3 transform, Curve curve, Shape shape) : base(id, p, transform, curve, shape) { }