public BeamInfo(Beam beam, BeamGeometry beamGeometry, List <DoseReductionFactor> doseReductionFactors) { BeamEsapi = beam; BeamGeometry = beamGeometry; DoseReductionFactors = doseReductionFactors; IscFluence = new Esapi.IscFluence.IscFluence(beam); }
private void A_DrawEraseEvent(ActionEventArgs gs) { BeamGeometry line = this.action.Geometry as BeamGeometry; sublineGeometry.Start = line.Start; sublineGeometry.End = line.End; sublineGeometry.Update(); this.Tip.SetText(sublineGeometry.TextValue, sublineGeometry.TextPosition, sublineGeometry.TextAngle); }
public IscFluenceOptimizer(PlanSetup planSetup, double doseThresholdPc = 10.0) { DoseThresholdPc = doseThresholdPc; PrescribedDosePerFraction = planSetup.UniqueFractionation.PrescribedDosePerFraction.Dose; DoseThresholdAbs = (doseThresholdPc / 100.0) * PrescribedDosePerFraction; NumberOfBeams = planSetup.Beams.Count(); Dose doseEsapi = planSetup.Dose; int xDose3dSize = doseEsapi.XSize; int yDose3dSize = doseEsapi.YSize; int zDose3dSize = doseEsapi.ZSize; double xDose3dRes = doseEsapi.XRes; double yDose3dRes = doseEsapi.YRes; double zDose3dRes = doseEsapi.ZRes; double xDose3dOrigin = doseEsapi.Origin.x; double yDose3dOrigin = doseEsapi.Origin.y; double zDose3dOrigin = doseEsapi.Origin.z; double[,,] dose3dArray = Helpers.EsapiDoseToDose3dArray(doseEsapi); var beamDoseArrays = new List <double[, , ]>(); var beamMus = new List <double>(); var beamMuPerGys = new List <double>(); double planNormalizationValue = planSetup.PlanNormalizationValue; for (int m = 0; m < NumberOfBeams; m++) { Beam beam = planSetup.Beams.ElementAt(m); beamDoseArrays.Add(Helpers.EsapiDoseToDose3dArray(beam.Dose)); beamMus.Add(beam.Meterset.Value); beamMuPerGys.Add(beam.MetersetPerGy); } for (int i = 0; i < zDose3dSize; i++) { for (int j = 0; j < yDose3dSize; j++) { for (int k = 0; k < xDose3dSize; k++) { double dosePc = dose3dArray[i, j, k]; if (dosePc > doseThresholdPc) { double z = zDose3dOrigin + i * zDose3dRes; double y = yDose3dOrigin + j * yDose3dRes; double x = xDose3dOrigin + k * xDose3dRes; VVector p = new VVector(x, y, z); List <double> beamDoses = new List <double>(); double doseSum = 0.0; for (int m = 0; m < NumberOfBeams; m++) { var dose = beamDoseArrays[m][i, j, k]; var mu = beamMus[m]; var muPerGy = beamMuPerGys[m]; double beamDose = Helpers.BeamPointDose(dose, muPerGy, mu); beamDose *= PrescribedDosePerFraction; beamDose /= planNormalizationValue; doseSum += beamDose; beamDoses.Add(beamDose); } double totalDose = (PrescribedDosePerFraction * dosePc) / 100.0; //Console.WriteLine($"doseSum: {doseSum:f}, totalDose {totalDose:f}, diff {doseSum - totalDose:g}, ratio {doseSum/totalDose:g}"); //if(Math.Abs(doseSum-totalDose) > 1.0E-2) //{ // throw new InvalidOperationException("Total doses does not coincide"); //} //this.PointsAboveThreshold.Add(new PointDoseBreakdown(x, y, z, totalDose, beamDoses)); this.PointsAboveThreshold.Add(new PointDoseBreakdown(x, y, z, doseSum, beamDoses)); } } } } var beams = planSetup.Beams; for (int i = 0; i < beams.Count(); i++) { Beam beam = beams.ElementAt(i); ControlPoint controlPoint0 = beam.ControlPoints.First(); double gantryAngle = controlPoint0.GantryAngle; double collimatorAngle = controlPoint0.CollimatorAngle; double couchAngle = controlPoint0.PatientSupportAngle; double[] isocenter = { beam.IsocenterPosition.x, beam.IsocenterPosition.y, beam.IsocenterPosition.z }; BeamGeometry beamGeometry = new BeamGeometry(gantryAngle, collimatorAngle, couchAngle, isocenter); List <DoseReductionFactor> doseReductionFactors = new List <DoseReductionFactor>(); foreach (PointDoseBreakdown p in PointsAboveThreshold) { double x = p.X; double y = p.Y; double z = p.Z; double totalDose = p.TotalDose; double totalSqauaredDose = p.TotalSquaredDose; double beamDose = p.BeamDoses[i]; double doseRed = totalDose - DoseThresholdAbs; double doseReductionFactor = 1.0 - (beamDose * doseRed) / totalSqauaredDose; double[] pPCS = new double[3] { x, y, z }; double[] projectedPoint = beamGeometry.ProjectedPointAtIsocenterPlaneInUCS(pPCS); doseReductionFactors.Add(new DoseReductionFactor { X = projectedPoint[0], Y = projectedPoint[2], BeamDose = beamDose, TotalDose = totalDose, DoseThreshold = DoseThresholdAbs, Value = doseReductionFactor }); } BeamInfos.Add(new BeamInfo(beam, beamGeometry, doseReductionFactors)); } }
/// <summary> /// Adds section data ( Beam, Prestressed Beam, Column, Hollow Core and Prestressed Slab ) to the ModelBuilderData instance. /// </summary> /// <param name="database"> /// </param> /// <param name="modelBuilderData"> /// </param> /// <param name="elementDictionary"> /// </param> void AddSectionData( ImpactDatabase database, ref ModelBuilderData modelBuilderData, ref Dictionary<ElementType.KnownValue, List<Element>> elementDictionary ) { if( null == modelBuilderData ) { throw new ArgumentNullException( "data" ); } if( null == elementDictionary ) { throw new ArgumentNullException( "elementDictionary" ); } // No need to continue if the list is empty. if( 0 == elementDictionary.Count ) { return; } List<Element> tempList = null; List<Element> beamList = new List<Element>( 500 ); List<Element> columnList = new List<Element>( 500 ); List<Element> hollowCoreList = new List<Element>( 500 ); List<Element> slabList = new List<Element>( 500 ); List<Element> allList = new List<Element>( 1000 ); bool proceed = false; if( elementDictionary.TryGetValue( ElementType.KnownValue.Beam, out tempList ) ) { beamList.AddRange( tempList ); allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.Beam ); proceed = true; } if( elementDictionary.TryGetValue( ElementType.KnownValue.PrestressedBeam, out tempList ) ) { beamList.AddRange( tempList ); allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.PrestressedBeam ); proceed = true; } if( elementDictionary.TryGetValue( ElementType.KnownValue.Column, out tempList ) ) { columnList.AddRange( tempList ); allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.Column ); proceed = true; } if( elementDictionary.TryGetValue( ElementType.KnownValue.HollowCore, out tempList ) ) { hollowCoreList.AddRange( tempList ); allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.HollowCore ); proceed = true; } if( elementDictionary.TryGetValue( ElementType.KnownValue.PrestressedSlab, out tempList ) ) { slabList.AddRange( tempList ); allList.AddRange( tempList ); elementDictionary.Remove( ElementType.KnownValue.PrestressedSlab ); proceed = true; } // No need to query the database if there are no elements. if( false == proceed ) { return; } // Section Parameters. var sectionParameterArgs = new ImpactDatabase.ProfacomArgs<ImpSectionStyleParameterStd>( this._factory, this._project, GetSectionParameterQuery( this._factory, this._project ), ImpSectionStyleParameterStd.ElementType, ImpSectionStyleParameterStd.Name, ImpSectionStyleParameterStd.ParameterId ); var sectionParameterList = database.Profacom( sectionParameterArgs, column => new { ElementType = ( (ElementType) column[0].Cast<string>() ). EnumValue, Name = column[1].Cast<string>(), Parameter = new SectionParameter( DataConverter.Cast <SectionStyleParameter>( column[2] ), column[3].Cast<double>() ) } ); // Section Geometry. var sectionGeometryArgs = new ImpactDatabase.ProfacomArgs<ImpSectionGeometryStd>( this._factory, this._project, GetSectionGeometryQuery( this._factory, this._project ), ImpSectionGeometryStd.ElementType, ImpSectionGeometryStd.Section, ImpSectionGeometryStd.PointId ); var sectionGeometryList = database.Profacom( sectionGeometryArgs, column => new { ElementType = ( (ElementType) column[0].Cast<string>() ). EnumValue, Name = column[1].Cast<string>(), Id = column[2].Cast<int>(), Point = new GeometryPoint { X = column[3].Cast <double>(), Y = column[4].Cast <double>(), Bulge = column[5].Cast <double>() } } ); // Section Core Geometry. var sectionCoreGeometryArgs = new ImpactDatabase.ProfacomArgs<ImpSectionCoreGeometryStd>( this._factory, this._project, GetSectionCoreGeometryQuery( this._factory, this._project ), ImpSectionCoreGeometryStd.ElementType, ImpSectionCoreGeometryStd.Section, ImpSectionCoreGeometryStd.CoreId, ImpSectionCoreGeometryStd.CorePointId ); var sectionCoreGeometryList = database.Profacom( sectionCoreGeometryArgs, column => new { ElementType = ( (ElementType) column[0].Cast<string>() ) .EnumValue, Name = column[1].Cast<string>(), Id = column[2].Cast<int>(), PointId = column[3].Cast<int>(), Point = new GeometryPoint { X = column[4]. Cast <double>(), Y = column[5]. Cast <double>(), Bulge = column[6]. Cast <double>() } } ).GroupBy( item => new { item.ElementType, item.Name, item.Id } ); // Section style and material. var sectionArgs = new ImpactDatabase.ProfacomArgs<ImpSectionStyleStd>( this._factory, this._project, GetSectionStyleQuery( this._company, this._factory, this._project ), ImpSectionStyleStd.ElementType, ImpSectionStyleStd.Name ); var sectionStyleList = database.Profacom( sectionArgs, column => new { ElementType = ( (ElementType)column[0].Cast<string>() ). EnumValue, Name = column[1].Cast<string>(), SectionType = column[2].Cast<string>(), Width = column[3].Cast<double>(), Height = column[4].Cast<double>(), CutType = column[5].Cast<CutType>(), // It is possible that no material was found, in that case // the resulting columns will contain 'null' values. // If the material is missing, we'll set the RGB value // to black ( 0, 0, 0 ). Material = column[6].Cast<string>(), } ); // End Beam angles. var endBeamList = database.GetAll( GetEndBeamQuery( this._factory, this._project ).ToString(), column => new { ElementMark = column [0]. Cast < string >(). Trim(), Side = column [ 1 ] . Cast < int > () == 3 ? Side . KnownValue . Left : Side . KnownValue . Right, Angle = column [2]. Cast < double >(), } ); var sectionList = new List<SectionGeometry>(); foreach( var element in allList ) { var style = sectionStyleList.Find( x => x.ElementType == element.Geometry.ElementType && x.Name == element.Style ); if( null != style ) { var section = new SectionGeometry( element.Geometry ) { SectionType = ( (SectionType)style.SectionType ).EnumValue, CutType = style.CutType, SectionWidth = style.Width, SectionHeight = style.Height, MaterialName = element.Geometry.MaterialName, Parameters = ( from item in sectionParameterList where item.ElementType == style.ElementType && item.Name == style.Name select item.Parameter ).ToDictionary( param => param.Key, param => param.Value ), SectionPoints = ( from item in sectionGeometryList where item.ElementType == style.ElementType && item.Name == style.Name orderby item.Id ascending select item.Point ).ToList(), Cores = ( from item in sectionCoreGeometryList where item.Key.ElementType == style.ElementType && item.Key.Name == style.Name let points = from n in item orderby n.PointId ascending select n.Point orderby item.Key.Id ascending select new CoreGeometry( points.ToList() ) ).ToList() }; sectionList.Add( section ); } else { // If we don't have a style, then we have to create the section as a bounding box. var section = new SectionGeometry( element.Geometry ) { SectionType = SectionType.KnownValue.Invalid, CutType = CutType.Symmetrical, SectionWidth = element.Geometry.Width, SectionHeight = element.Geometry.Height, MaterialName = element.Geometry.MaterialName, }; sectionList.Add( section ); } } // var sectionList = ( from element in allList // let style = sectionStyleList.Find( x => x.ElementType == element.Geometry.ElementType && x.Name == element.Style ) // where null != style // let section = new SectionGeometry( element.Geometry ) // { // SectionType = ( (SectionType)style.SectionType ).EnumValue, // CutType = style.CutType, // SectionWidth = style.Width, // SectionHeight = style.Height, // MaterialName = style.Material, // Parameters = ( from item in sectionParameterList // where item.ElementType == style.ElementType // && item.Name == style.Name // select item.Parameter ).ToDictionary( param => param.Key, param => param.Value ), // SectionPoints = ( from item in sectionGeometryList // where item.ElementType == style.ElementType // && item.Name == style.Name // orderby item.Id ascending // select item.Point ).ToList(), // Cores = ( from item in sectionCoreGeometryList // where item.Key.ElementType == style.ElementType // && item.Key.Name == style.Name // let points = ( from n in item orderby n.PointId ascending select n.Point ) // orderby item.Key.Id ascending // select new CoreGeometry( points.ToList() ) ).ToList() // } // select section ).ToList(); foreach( var item in sectionList ) { switch( item.ElementType ) { case ElementType.KnownValue.Beam: case ElementType.KnownValue.PrestressedBeam: { // Because the height parameter might be missing in the database, // we add it explicitly here. item.Parameters[SectionStyleParameter.H] = item.Height; var beam = new BeamGeometry( item ); // Check if the beam has an left vertical angle. var endBeamItem = endBeamList.Find( endBeam => endBeam.ElementMark == beam.ElementMark && endBeam.Side == Side.KnownValue.Left ); // Set the left vertical angle. if( null != endBeamItem ) { beam.VerticalAngleLeft = endBeamItem.Angle; } // Check if the beam has an right vertical angle. endBeamItem = endBeamList.Find( endBeam => endBeam.ElementMark == beam.ElementMark && endBeam.Side == Side.KnownValue.Right ); // Set the right vertical angle. if( null != endBeamItem ) { beam.VerticalAngleRight = endBeamItem.Angle; } modelBuilderData.Beams.Add( beam ); break; } case ElementType.KnownValue.Column: { // Because the height parameter might be missing in the database, // we add it explicitly here. item.Parameters[SectionStyleParameter.H] = item.Height; modelBuilderData.Columns.Add( item ); break; } case ElementType.KnownValue.HollowCore: { modelBuilderData.HollowCores.Add( item ); break; } case ElementType.KnownValue.PrestressedSlab: { modelBuilderData.PrestressedSlabs.Add( item ); break; } default: break; } } }
/// <summary> /// 解析指定的XML对象 /// </summary> /// <param name="messageXML"></param> private void ParseXML(XmlReader xmlReader) { Geometry2D shape = null; switch (xmlReader.Name) { case "ArcGeometry": shape = new ArcGeometry(); break; case "BeamGeometry": shape = new BeamGeometry(); break; case "CircleGeometry": shape = new CircleGeometry(); break; case "CSectionGeometry": shape = new CSectionGeometry(); break; case "EllipseGeometry": shape = new EllipseGeometry(); break; case "FloorGeometry": shape = new FloorGeometry(); break; case "LineGeometry": shape = new LineGeometry(); break; case "MeasureGeometry": shape = new MeasureGeometry(); break; case "MemberGeometry": shape = new MemberGeometry(); break; case "OSBGeometry": shape = new OSBGeometry(); break; case "PointGeometry": shape = new PointGeometry(); break; case "PolygonGeometry": shape = new PolygonGeometry(); break; case "PolylineGeometry": shape = new PolylineGeometry(); break; case "RectangleGeometry": shape = new RectangleGeometry(); break; case "SteelBeamGeometry": shape = new SteelBeamGeometry(); break; case "TextGeometry": shape = new TextGeometry(); break; case "WallGeometry": shape = new WallGeometry(); break; } if (shape != null) { //将信息写入数据流中 shape.ReadXML(xmlReader); //将图形添加都界面上 this.drawingKernel.AddShape(shape); } }