private void CheckJmp(JumpTypes jmp) { if (jmp != JumpTypes.Heaviside && jmp != JumpTypes.OneMinusHeaviside) { throw new NotSupportedException(); } }
/// <summary> /// Generates a quadrature rule factory for the cut edge integrals. /// </summary> public IQuadRuleFactory <QuadRule> GetEdgeRuleFactory(int levSetIndex, JumpTypes jmp, RefElement KrefVol) { var gdat = this.m_LevelSetDatas[levSetIndex].GridDat; if (!gdat.Grid.RefElements.Contains(KrefVol, (a, b) => object.ReferenceEquals(a, b))) { throw new ArgumentException(); } CheckJmp(jmp); if (jmp == JumpTypes.Heaviside) { var r = new EdgeRuleFromCellBoundaryFactory(gdat, GetCellFaceFactory(levSetIndex, KrefVol), m_LevelSetDatas[levSetIndex].Region.GetCutCellMask4LevSet(levSetIndex)); return(r); } else if (jmp == JumpTypes.OneMinusHeaviside) { return(new ComplementaryRuleFactory(GetEdgeRuleFactory(levSetIndex, JumpTypes.Heaviside, KrefVol))); } else { throw new ArgumentOutOfRangeException("unsupported jump type"); } }
/// <summary> /// Constructs a new factory /// </summary> /// <param name="tracker"> /// Tracker for the considered level set /// </param> /// <param name="Kref"> /// Reference element index /// </param> /// <param name="lsData"></param> /// <param name="rootFindingAlgorithm"> /// Selected root-finding algorithm for the line segments. Default is /// <see cref="LineSegment.DefaultRootFindingAlgorithm"/> /// </param> /// <param name="jumpType"> /// Determines the domain of integration, i.e. whether the rule should /// be valid for positive level set values, negative level set values, /// or even for both /// </param> /// <param name="tolerace"> /// Tolerance for the sign of the level set function. Using the example /// of <see cref="JumpTypes.Heaviside"/>, values phi with /// phi - Tolerance > 0 are considered 'positive'. /// </param> public CutLineQuadRuleFactory( LevelSetTracker.LevelSetData lsData, RefElement Kref, LineSegment.IRootFindingAlgorithm rootFindingAlgorithm = null, JumpTypes jumpType = JumpTypes.Heaviside, double tolerace = 1.0e-13) { this.RefElement = Kref; this.RootFindingAlgorithm = rootFindingAlgorithm ?? LineSegment.DefaultRootFindingAlgorithm; this.referenceLineSegments = GetReferenceLineSegments(); this.jumpType = jumpType; this.levelSetData = lsData; this.iKref = lsData.GridDat.Grid.RefElements.IndexOf(this.RefElement, (A, B) => object.ReferenceEquals(A, B)); if (this.iKref < 0) { throw new ArgumentException("Reference element cannot be found in the provided grid."); } this.levelSetIndex = lsData.LevelSetIndex; if (tolerace < 0.0) { throw new ArgumentOutOfRangeException(); } this.Tolerance = tolerace; emptyrule = CellBoundaryQuadRule.CreateEmpty(this.RefElement, 1, levelSetData.GridDat.SpatialDimension, referenceLineSegments.Length); // create a rule with just one node and weight zero; // this should avoid some special-case handling for empty rules emptyrule.NumbersOfNodesPerFace[0] = 1; emptyrule.Nodes.LockForever(); //tracker.Subscribe(this); }
void forceParameters() { switch( m_Prototype ) { case GameTypes.LARGE_FULL_COLLISION: m_TrackType = TrackTypes.ANALOGUE_JUMPS1; m_CollisionType = CollisionTypes.FULL_COLLISION; m_JumpType = JumpTypes.DIGITAL; m_viewDistance = 1.0f; break; case GameTypes.SMALL_FRONT_COLLISION: m_TrackType = TrackTypes.EASY_JUMPS1; m_CollisionType = CollisionTypes.FRONT_COLLISION; m_JumpType = JumpTypes.FAST_DIGITAL; m_viewDistance = 2.0f; break; case GameTypes.JOYRIDE_STYLE: m_TrackType = TrackTypes.ANALOGUE_JUMPS1; m_CollisionType = CollisionTypes.FULL_COLLISION; m_JumpType = JumpTypes.HIGH_ANALOGUE; m_viewDistance = 1.0f; break; case GameTypes.USER_CUSTOM: break; } }
/// <summary> /// Constructor /// </summary> /// <param name="lsData"></param> /// <param name="rootFindingAlgorithm"> /// One-dimensional root-finding algorithm for determining roots of the /// level set function on edges of the edges of the volume simplex. /// Default is <see cref="LineSegment.DefaultRootFindingAlgorithm"/> /// </param> /// <param name="jumpType"> /// Determines the level set region to be integrated over (negative /// level set values, positive level set values, or both) /// </param> public LevelSetEdgeVolumeQuadRuleFactory( LevelSetTracker.LevelSetData lsData, LineSegment.IRootFindingAlgorithm rootFindingAlgorithm = null, JumpTypes jumpType = JumpTypes.Heaviside) { if (lsData.GridDat.Cells.RefElements.Length > 1) { throw new NotImplementedException( "Multiple reference elements currently not supported"); } this.LevelSetData = lsData; this.jumpType = jumpType; this.levelSetIndex = lsData.LevelSetIndex; CoFaceQuadRuleFactory = new CutLineOnEdgeQuadRuleFactory(lsData, rootFindingAlgorithm, jumpType); edgeSurfaceRuleFactory = new LevelSetEdgeSurfaceQuadRuleFactory(lsData, CoFaceQuadRuleFactory, jumpType); // Use vertices; Since it is only used on edges that are considered // uncut, they _should_ all have the same sign RefElement simplex = LevelSetData.GridDat.Grid.RefElements[0]; RefElement edgeSimplex = simplex.FaceRefElement; QuadRule signEdgeRule = new QuadRule() { Nodes = edgeSimplex.Vertices, Weights = MultidimensionalArray.Create(edgeSimplex.NoOfVertices) }; signTestRule = new CellBoundaryFromEdgeRuleFactory <CellBoundaryQuadRule>( LevelSetData.GridDat, simplex, new FixedRuleFactory <QuadRule>(signEdgeRule)). GetQuadRuleSet(new CellMask(LevelSetData.GridDat, Chunk.GetSingleElementChunk(0)), -1). First().Rule; }
public JumpOperation(int ri, int offset, JumpTypes cond) : base(ri, 0, Opcodes.JMP) { if (offset > WORD_MAX) { throw new ArgumentOutOfRangeException("MemoryOffset", "Memory offset greater than maximum word size."); } Condition = cond; MemoryOffset = offset; }
/// <summary> /// Ctor /// </summary> public LevelSetEdgeSurfaceQuadRuleFactory(LevelSetTracker.LevelSetData lsData, IQuadRuleFactory <CellEdgeBoundaryQuadRule> edgeRuleFactory, JumpTypes jumpType) { //this.tracker = lsData.Tracker; this.levelSetIndex = lsData.LevelSetIndex; this.edgeRuleFactory = edgeRuleFactory; this.jumpType = jumpType; this.LevelSetData = lsData; if (lsData.GridDat.Cells.RefElements.Length > 1) { throw new NotSupportedException("Currently no support for mixed-type grids."); } }
/// <summary> /// constructor. /// </summary> /// <param name="lsData"> /// </param> /// <param name="edgeRuleFactory"> /// Some factory that provides quadrature rules for the integration /// over /// \f[ /// \partial K \cap \{ \vec{x}; \varphi(\vec{x}) {\leq \atop \geq} 0 \}. /// \f] /// Here, \f$ \partial K\f$ the boundary of /// some cell \f$ K\f$ and /// \f$ \varphi\f$ denotes the level set function /// </param> /// <param name="surfaceRuleFactory"> /// Some factory that provides quadrature rules for the integration /// over the zero level set, i.e. /// \f[ /// \{ \vec{x}; \varphi(\vec{x}) = 0 \} \cap K. /// \f] /// (ere, \f$ \partial K\f$ the boundary of some /// cell \f$ K\f$ and /// \f$ \varphi\f$ denotes the level set function /// </param> /// <param name="levSetIndex"> /// Index of the considered level set in <paramref name="tracker"/> /// </param> public LevelSetVolumeQuadRuleFactory( LevelSetTracker.LevelSetData lsData, IQuadRuleFactory <CellBoundaryQuadRule> edgeRuleFactory, IQuadRuleFactory <QuadRule> surfaceRuleFactory, JumpTypes jumpType = JumpTypes.Heaviside) { if (jumpType == JumpTypes.Implicit) { throw new NotSupportedException(); } this.levelSetIndex = lsData.LevelSetIndex; this.edgeRuleFactory = edgeRuleFactory; this.surfaceRuleFactory = surfaceRuleFactory; this.jumpType = jumpType; this.LevelSetData = lsData; }
/// <summary> /// Constructor /// </summary> /// <param name="tracker"></param> /// <param name="levelSetIndex"></param> /// <param name="rootFindingAlgorithm"></param> /// <param name="jumpType"></param> public CutLineOnEdgeQuadRuleFactory(LevelSetTracker.LevelSetData __lsData, LineSegment.IRootFindingAlgorithm rootFindingAlgorithm = null, JumpTypes jumpType = JumpTypes.Heaviside) { if (__lsData.GridDat.SpatialDimension < 3) { throw new ArgumentException("Only applicable in 3d", "tracker"); } if (__lsData.GridDat.Cells.RefElements.Length > 1) { throw new NotSupportedException(); } this.lsData = __lsData; this.RootFindingAlgorithm = rootFindingAlgorithm ?? LineSegment.DefaultRootFindingAlgorithm; this.jumpType = jumpType; this.levelSetIndex = lsData.LevelSetIndex; this.referenceLineSegments = GetReferenceLineSegments(); //tracker.Subscribe(this); }
/// <summary> /// Generates a quadrature rule factory for the cut volume integrals. /// </summary> public IQuadRuleFactory <QuadRule> GetVolRuleFactory(int levSetIndex, JumpTypes jmp, RefElement Kref) { CheckJmp(jmp); var ctx = this.m_LevelSetDatas[levSetIndex].GridDat; if (jmp == JumpTypes.Heaviside) { if (m_SurfaceFactory == null) { m_SurfaceFactory = new IQuadRuleFactory <QuadRule> [m_LevelSetDatas.Length]; } if (m_VolumeFactory == null) { m_VolumeFactory = new IQuadRuleFactory <QuadRule> [m_LevelSetDatas.Length]; } if (m_VolumeFactory[levSetIndex] == null) { switch (CutCellQuadratureType) { case MomentFittingVariants.Classic: m_VolumeFactory[levSetIndex] = new LevelSetVolumeQuadRuleFactory( this.m_LevelSetDatas[levSetIndex], GetCellFaceFactory(levSetIndex, Kref), GetSurfaceFactory(levSetIndex, Kref), jumpType: jmp); break; case MomentFittingVariants.OneStepGauss: case MomentFittingVariants.OneStepGaussAndStokes: { bool bStokes = CutCellQuadratureType == MomentFittingVariants.OneStepGaussAndStokes; LevelSetComboRuleFactory2 ComboRuleFactroy = new LevelSetComboRuleFactory2( this.m_LevelSetDatas[levSetIndex], this.GetCellFaceFactory(levSetIndex, Kref), bStokes ? this._GetSurfaceElement_BoundaryRuleFactory(levSetIndex, Kref) : null, _UseAlsoStokes: bStokes, _SurfaceNodesOnZeroLevset: false, _DoCheck: CheckQuadRules); m_VolumeFactory[levSetIndex] = ComboRuleFactroy.GetVolumeFactory(); m_SurfaceFactory[levSetIndex] = ComboRuleFactroy.GetSurfaceFactory(); break; } case MomentFittingVariants.TwoStepStokesAndGauss: case MomentFittingVariants.ExactCircle: { m_VolumeFactory[levSetIndex] = (new LevelSetVolumeQuadRuleFactory2b(Kref, this.m_LevelSetDatas[levSetIndex], GetCellFaceFactory(levSetIndex, Kref), GetSurfaceFactory(levSetIndex, Kref), jmp)); break; } case MomentFittingVariants.Saye: var comboFactory = Quadrature.SayeFactories.SayeGaussRule_Combo( this.m_LevelSetDatas[levSetIndex], new LineSegment.SafeGuardedNewtonMethod(1e-14)); m_VolumeFactory[levSetIndex] = comboFactory.GetVolumeFactory(); m_SurfaceFactory[levSetIndex] = comboFactory.GetSurfaceFactory(); break; default: throw new NotSupportedException(String.Format( "Variant {0} not implemented.", CutCellQuadratureType)); } } return(m_VolumeFactory[levSetIndex]); } else if (jmp == JumpTypes.OneMinusHeaviside) { return(new ComplementaryRuleFactory(GetVolRuleFactory(levSetIndex, JumpTypes.Heaviside, Kref))); } else { throw new ArgumentOutOfRangeException("unsupported jump type"); } }
public static void CreateJumps(IApplication app, JumpTypes jumpType, double jumpDistance) { IProgressDialog2 progressDialog = default(IProgressDialog2); IProgressDialogFactory progressDialogFactory = null; ITrackCancel trackCancel = null; IStepProgressor stepProgressor = null; ICursor lineCursor = null; IEditor editor = null; IFeature lineFeature = null; IMxDocument mxdoc = null; IMap map = null; UID geoFeatureLayerID = null; IEnumLayer enumLayer = null; IEditLayers eLayers = null; List<IFeatureLayer> lineLayers = null; ILayer layer = null; IFeatureLayer fLayer = null; IFeatureSelection fSel = null; try { //Get editor editor = Globals.getEditor(app); if (editor.EditState != esriEditState.esriStateEditing) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("MustBEditg"), A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_6")); return; } //ProgressBar progressDialogFactory = new ProgressDialogFactoryClass(); // Create a CancelTracker trackCancel = new CancelTrackerClass(); // Set the properties of the Step Progressor Int32 int32_hWnd = editor.Parent.hWnd; stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd); stepProgressor.MinRange = 0; // stepProgressor.MaxRange = itotal stepProgressor.StepValue = 1; stepProgressor.Message = ""; stepProgressor.Hide(); // Create the ProgressDialog. This automatically displays the dialog progressDialog = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast // Set the properties of the ProgressDialog progressDialog.CancelEnabled = false; progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_12") +"..."; progressDialog.Title = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_12"); progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe; mxdoc = (IMxDocument)app.Document; map = editor.Map; //Get enumeration of feature layers geoFeatureLayerID = new UIDClass(); geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; enumLayer = map.get_Layers(((ESRI.ArcGIS.esriSystem.UID)geoFeatureLayerID), true); //Get enumeration of editable layers eLayers = (IEditLayers)editor; // Create list of visible line layers with selected feature(s) lineLayers = new List<IFeatureLayer>(); enumLayer.Reset(); layer = enumLayer.Next(); while (layer != null) { fLayer = (IFeatureLayer)layer; stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeometryToolsMess_2") + fLayer.Name; if (fLayer.Valid && (fLayer.FeatureClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline) && (fLayer.Visible)) { if (eLayers.IsEditable(fLayer)) { fSel = fLayer as IFeatureSelection; if (fSel.SelectionSet.Count > 0) { stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeometryToolsMess_3") + fLayer.Name; lineLayers.Add(fLayer); } } } layer = enumLayer.Next(); } if (lineLayers.Count == 0) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsError_7")); return; } // Create an edit operation enabling undo/redo editor.StartOperation(); IPointCollection linePointCollection = null; ISpatialFilter spatialFilter = null; IFeatureCursor featureCursor = null; IFeature crossFeature = null; ITopologicalOperator topologicalOP = null; ITopologicalOperator topologicalOP2 = null; IPointCollection intersectPointCollection = null; IPoint intersectPoint = null; IPoint outPoint = null; IPoint beginPoint = null; IPoint endPoint = null; IActiveView activeView = null; IInvalidArea invalid = null; IEnvelope ext = null; ISegmentCollection testSegmentColl = null; ISegment testSegment = null; ISegmentCollection segmentColl = null; ISegmentCollection segmentCollNew = null; IConstructCircularArc constructCircArc = null; ISegment curveSegment = null; //IProximityOperator proximityOP = null; IPolycurve3 selCurve = null; IPolycurve3 selCurveB = null; IPolycurve3 crossCurve = null; IPolycurve3 crossCurveB = null; IPolycurve3 testSelCurve = null; IPolycurve3 testSelCurveB = null; object _missing = null; IFeatureSelection lineSel = null; ISelectionSet2 sel = null; IZAware pZAware = null; ISegmentCollection testSegmentColl2 = null; ISegment testSegment2 = null; IGeometryDef pGeometryDefTest = null; IFields pFieldsTest = null; IField pFieldTest = null; IGeoDataset pDS = null; try { activeView = map as IActiveView; invalid = new InvalidAreaClass(); invalid.Display = editor.Display; linePointCollection = (IPointCollection)new PolylineClass(); spatialFilter = new SpatialFilterClass(); intersectPoint = new PointClass(); outPoint = new PointClass(); //used for curve test on cross feature bool testProjectOnto; bool testCreatePart; bool testSplitHappened; int testNewPartIndex; int testNewSegmentIndex; //used for curve test on selected feature bool testProjectOnto2; bool testCreatePart2; bool testSplitHappened2; int testNewPartIndex2; int testNewSegmentIndex2; //ICurve lineCurve; double totalDistance; double distAlongCurve = 0; double distFromCurve = 0; bool boolRightSide = false; //test the amount of needed space for the inserted curve double remainderDistance = 0; double pointDistance = 0; bool projectOnto; bool createPart; bool splitHappenedBefore; bool splitHappenedAfter; int newPartIndexBegin; int newSegmentIndexBegin; int newPartIndexEnd; int newSegmentIndexEnd; _missing = Type.Missing; // Step through all line layers with selection sets foreach (IFeatureLayer lineLayer in lineLayers) { stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeometryToolsMess_4a") + lineLayer.Name; // Get cursor of selected lines lineSel = (IFeatureSelection)lineLayer; sel = lineSel.SelectionSet as ISelectionSet2; sel.Search(null, false, out lineCursor); // Process each selected line int idx = 0; while ((lineFeature = (IFeature)lineCursor.NextRow()) != null) { idx++; stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeometryToolsMess_4b") + idx + A4LGSharedFunctions.Localizer.GetString("GeometryToolsMess_4c") + lineLayer.Name; if (lineFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline) { selCurve = (IPolycurve3)lineFeature.ShapeCopy; pZAware = selCurve as IZAware; if (pZAware.ZAware) { pZAware.ZAware = false; } // Get cursor of crossing features spatialFilter.Geometry = selCurve; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses; featureCursor = lineLayer.Search(spatialFilter, false); // Process each crossing feature while ((crossFeature = (IFeature)featureCursor.NextFeature()) != null) { topologicalOP = (ITopologicalOperator)crossFeature.Shape; //topologicalOP2 = (ITopologicalOperator)polylinePointCollection; topologicalOP2 = (ITopologicalOperator)selCurve; topologicalOP2.Simplify(); topologicalOP.Simplify(); intersectPointCollection = (IPointCollection)topologicalOP.Intersect((IGeometry)selCurve, esriGeometryDimension.esriGeometry0Dimension); for (int i = 0; i < intersectPointCollection.PointCount; i++) { intersectPoint = intersectPointCollection.get_Point(i); //Determine if the crossing segement is an arc. //Continue if it is not. testProjectOnto = true; testCreatePart = false; crossCurve = (IPolycurve3)crossFeature.ShapeCopy; crossCurve.SplitAtPoint(intersectPoint, testProjectOnto, testCreatePart, out testSplitHappened, out testNewPartIndex, out testNewSegmentIndex); crossCurveB = (IPolycurve3)crossFeature.ShapeCopy; testSegmentColl = crossCurveB as ISegmentCollection; testSegment = testSegmentColl.get_Segment(testNewSegmentIndex - 1); if (testSegment.GeometryType != esriGeometryType.esriGeometryCircularArc) { //Determine if the current location of the selected line is an arc. //Continue if it is not. testProjectOnto2 = true; testCreatePart2 = false; testSelCurve = (IPolycurve3)lineFeature.ShapeCopy; testSelCurve.SplitAtPoint(intersectPoint, testProjectOnto2, testCreatePart2, out testSplitHappened2, out testNewPartIndex2, out testNewSegmentIndex2); testSelCurveB = (IPolycurve3)lineFeature.ShapeCopy; testSegmentColl2 = testSelCurveB as ISegmentCollection; testSegment2 = testSegmentColl2.get_Segment(testNewSegmentIndex2 - 1); if (testSegment2.GeometryType != esriGeometryType.esriGeometryCircularArc) { //Find distance along the original selected line //focusPolyline = (IPolyline)lineFeature.ShapeCopy; selCurveB = (IPolycurve3)lineFeature.ShapeCopy; selCurveB.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, intersectPoint, false, outPoint, ref distAlongCurve, ref distFromCurve, ref boolRightSide); remainderDistance = selCurveB.Length - distAlongCurve; totalDistance = distAlongCurve + jumpDistance; //Continue if there is enough room if ((selCurveB.Length >= (jumpDistance / 2)) && (remainderDistance >= (jumpDistance / 2))) { //find the points where the curve will begin and end beginPoint = new PointClass(); endPoint = new PointClass(); selCurveB.QueryPoint(esriSegmentExtension.esriNoExtension, (distAlongCurve - (jumpDistance / 2)), false, beginPoint); selCurveB.QueryPoint(esriSegmentExtension.esriNoExtension, (distAlongCurve + (jumpDistance / 2)), false, endPoint); //split the original line at the two points (vertices for begin and end of new curve) projectOnto = true; createPart = false; selCurveB.SplitAtPoint(beginPoint, projectOnto, createPart, out splitHappenedBefore, out newPartIndexBegin, out newSegmentIndexBegin); selCurveB.SplitAtPoint(endPoint, projectOnto, createPart, out splitHappenedAfter, out newPartIndexEnd, out newSegmentIndexEnd); if ((splitHappenedBefore = true) && (splitHappenedAfter = true)) { //Create the curve segment and add it to the polyline constructCircArc = new CircularArcClass(); // proximityOP = (IProximityOperator)intersectPoint; //pointDistance = proximityOP.ReturnDistance(beginPoint); pointDistance = jumpDistance; //check for direction of line to always make the jump on top if (jumpType == JumpTypes.Over) if (endPoint.X > beginPoint.X) { try { constructCircArc.ConstructChordDistance(intersectPoint, beginPoint, false, (pointDistance)); } catch { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsError_8")); continue; } } else { try { constructCircArc.ConstructChordDistance(intersectPoint, beginPoint, true, (pointDistance)); } catch { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsError_8")); continue; } } else { if (endPoint.X <= beginPoint.X) { try { constructCircArc.ConstructChordDistance(intersectPoint, beginPoint, false, (pointDistance)); } catch { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsError_8")); continue; } } else { try { constructCircArc.ConstructChordDistance(intersectPoint, beginPoint, true, (pointDistance)); } catch { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsError_8")); continue; } } } curveSegment = constructCircArc as ISegment; if (curveSegment != null & curveSegment.Length > 0) { segmentCollNew = (ISegmentCollection)new PolylineClass(); segmentCollNew.AddSegment(curveSegment, ref _missing, ref _missing); segmentColl = (ISegmentCollection)selCurveB; segmentColl.ReplaceSegmentCollection(newSegmentIndexBegin, 1, segmentCollNew); string sShpName = lineLayer.FeatureClass.ShapeFieldName; pFieldsTest = lineLayer.FeatureClass.Fields; int lGeomIndex = pFieldsTest.FindField(sShpName); pFieldTest = pFieldsTest.get_Field(lGeomIndex); pGeometryDefTest = pFieldTest.GeometryDef; bool bZAware; bool bMAware; //Determine if M or Z aware bZAware = pGeometryDefTest.HasZ; bMAware = pGeometryDefTest.HasM; if (bZAware) { // IGeometry pGeo = new PolylineClass(); pZAware = selCurveB as IZAware; if (pZAware.ZAware) { } else { pZAware.ZAware = true; //pZAware.DropZs(); } // pZAware.DropZs(); IZ pZ = selCurveB as IZ; pZ.SetConstantZ(0); } if (bMAware) { } pDS = lineLayer.FeatureClass as IGeoDataset; selCurveB.SpatialReference = pDS.SpatialReference; lineFeature.Shape = (IGeometry)selCurveB; lineFeature.Store(); //Prepare to redraw area around feature ext = curveSegment.Envelope; ext.Expand(2, 2, true); invalid.Add(ext); } } } else { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsError_9")); } } } } } } } } } catch (Exception ex) { editor.AbortOperation(); MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_6") + "\n" + ex.Message, ex.Source); } finally { // Refresh if (invalid!= null) invalid.Invalidate((short)esriScreenCache.esriAllScreenCaches); linePointCollection = null; spatialFilter = null; if (featureCursor != null) Marshal.ReleaseComObject(featureCursor); featureCursor = null; crossFeature = null; topologicalOP = null; topologicalOP2 = null; intersectPointCollection = null; intersectPoint = null; outPoint = null; beginPoint = null; endPoint = null; activeView = null; invalid = null; ext = null; testSegmentColl = null; testSegment = null; segmentColl = null; segmentCollNew = null; constructCircArc = null; curveSegment = null; //proximityOP = null; selCurve = null; selCurveB = null; crossCurve = null; crossCurveB = null; testSelCurve = null; testSelCurveB = null; _missing = null; lineSel = null; sel = null; pZAware = null; testSegmentColl2 = null; testSegment2 = null; pGeometryDefTest = null; pFieldsTest = null; pFieldTest = null; pDS = null; } // Stop the edit operation editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_6")); } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_6") + "\n" + ex.Message, ex.Source); return; } finally { if (lineCursor != null) { Marshal.ReleaseComObject(lineCursor); } // Cleanup if (progressDialog != null) { progressDialog.HideDialog(); //progressDialog = null; Marshal.ReleaseComObject(progressDialog); //progressDialogFactory = null; //Marshal.ReleaseComObject(progressDialogFactory); //trackCancel = null; //Marshal.ReleaseComObject(trackCancel); //stepProgressor = null; //Marshal.ReleaseComObject(stepProgressor); //appCursor = null; } progressDialog = null; progressDialogFactory = null; trackCancel = null; stepProgressor = null; lineCursor = null; editor = null; lineFeature = null; mxdoc = null; map = null; geoFeatureLayerID = null; enumLayer = null; eLayers = null; lineLayers = null; layer = null; fLayer = null; fSel = null; } }
public JumpInfo() { JumpType = JumpTypes.None; }
/// <summary> /// For some species <paramref name="sp"/>, /// this function computes on which side/wing /// of level-set no. <paramref name="levSetIdx"/>) /// the species is located. /// </summary> /// <remarks> /// Nur ein Provisorium, das ganze Konzept ist noch etwas unausgereift. (Habe einen Nachmittag lang darueber nachgedacht, keinen bessere Idee gehabt, /// und darum...). /// </remarks> public JumpTypes IdentifyWing(int levSetIdx, SpeciesId sp) { int NoOfLevSets = this.XDGSpaceMetrics.NoOfLevelSets; if (levSetIdx < 0 || levSetIdx > NoOfLevSets) { throw new ArgumentOutOfRangeException(); } if (NoOfLevSets == 1) { string[] speciesTable = (string[])(this.XDGSpaceMetrics.LevelSetRegions.SpeciesTable); Debug.Assert(speciesTable.Length == 2); string spN = this.XDGSpaceMetrics.LevelSetRegions.GetSpeciesName(sp); if (spN == speciesTable[0]) { return(JumpTypes.OneMinusHeaviside); } else if (spN == speciesTable[1]) { return(JumpTypes.Heaviside); } else { throw new Exception("should not happen."); } } else if (NoOfLevSets == 2) { string[,] speciesTable = (string[, ])(this.XDGSpaceMetrics.LevelSetRegions.SpeciesTable); Debug.Assert(speciesTable.GetLength(0) == 2); Debug.Assert(speciesTable.GetLength(1) == 2); string spN = this.XDGSpaceMetrics.LevelSetRegions.GetSpeciesName(sp); int cnt = 0; JumpTypes jmpRet = JumpTypes.Implicit; int[] _i = new int[2]; for (_i[0] = 0; _i[0] < 2; _i[0]++) // loop over signs of level-set 0 ... { for (_i[1] = 0; _i[1] < 2; _i[1]++) // loop over signs of level-set 1 ... { if (speciesTable[_i[0], _i[1]] == spN) { cnt++; if (_i[levSetIdx] == 0) { jmpRet = JumpTypes.OneMinusHeaviside; } else if (_i[levSetIdx] == 1) { jmpRet = JumpTypes.Heaviside; } else { throw new ApplicationException(); } } } } if (cnt != 1) { throw new NotImplementedException("unable to identify."); } return(jmpRet); } else { throw new NotImplementedException(); } }
private List <Operation> ParseCode(int startAddr = 0) { int addr = startAddr; List <ParsedInstruction> firstPassInstrs = new List <ParsedInstruction>(); for (int ln = 0; ln < code.Count; ln++) { List <Token> line = code[ln]; Token op = line[0]; if (op.Type == TokenType.OpCode) { if (mnemonicFormat.ContainsKey(op.Value)) { MnemonicFormat instrFormat = mnemonicFormat[op.Value]; // Check if the number of operands is correct, remembering to // account for the fact that the first token in the line was our // opcode token if (line.Count == instrFormat.OperandCount + 1) { ParsedInstruction parsedInstr = new ParsedInstruction(op.Value, op.LineNumber); for (int i = 0; i < instrFormat.OperandCount; i++) { Token operand = line[i + 1]; if ((instrFormat.OperandTypes[i] & operand.Type) == operand.Type) { Operand o = new Operand(operand.Value, EnumConv.TokenToOperandType(operand.Type)); parsedInstr.Operands.Add(o); } } firstPassInstrs.Add(parsedInstr); addr += instrFormat.IWCount; } else { throw new ParserException($"ERROR: Expected {instrFormat.OperandCount} parameters on line " + $"{op.LineNumber} for instruction {op.Value}. {line.Count - 1} parameters found.", op.LineNumber, line.Count); } } else { throw new ParserException($"ERROR: Unknown mnemonic {op.Value} on line {op.LineNumber}.", op.LineNumber, 0); } } else if (op.Type == TokenType.Label) { labelLocations.Add(op.Value, addr); } else if (op.Type == TokenType.Pragma) { // We'll hardcode this for now but come back and make it general later if (op.Value == "for" && line.Count == 5) { ParsedInstruction subInstr = new ParsedInstruction("sub", 0); Token loopReg = line[1]; if (loopReg.Type != TokenType.RegName) { // Throw an error throw new Exception("FOR loop token type mismatch - first argument not a register."); } // Subtract the register from itself to clear it subInstr.Operands.Add(new Operand(loopReg.Value, OperandType.Register)); subInstr.Operands.Add(new Operand(loopReg.Value, OperandType.Register)); addr++; // SUB is one word long ParsedInstruction addcInstr = new ParsedInstruction("addc", 0); Token startVal = line[2]; if (startVal.Type != TokenType.Label && startVal.Type != TokenType.Constant) { if (startVal.Type == TokenType.RegName) { addcInstr = new ParsedInstruction("add", 0); } else { throw new Exception("FOR loop token type mismatch - second argument not a constant or label."); } } addcInstr.Operands.Add(new Operand(loopReg.Value, OperandType.Register)); addcInstr.Operands.Add(new Operand(startVal.Value, EnumConv.TokenToOperandType(startVal.Type))); addr++; firstPassInstrs.Add(subInstr); firstPassInstrs.Add(addcInstr); int currentLoopNum = forLoopNum; labelLocations.Add($"@@@FOR_LOOP_NUM_{currentLoopNum}", addr); forLoopNum++; List <List <Token> > restOfLines = new List <List <Token> >(); restOfLines.AddRange(code.Skip(ln + 1)); ParsedPragma parsedFor = ParseFor(restOfLines, addr, currentLoopNum); firstPassInstrs.AddRange(parsedFor.ParsedInstructions); addr = parsedFor.NewAddrOffset; ln += parsedFor.LinesParsed; Operand regOp = new Operand(line[1].Value, EnumConv.TokenToOperandType(line[1].Type)); Operand startOp = new Operand(line[2].Value, EnumConv.TokenToOperandType(line[2].Type)); Operand loopOp = new Operand(line[3].Value, EnumConv.TokenToOperandType(line[3].Type)); Operand incOp = new Operand(line[4].Value, EnumConv.TokenToOperandType(line[4].Type)); List <ParsedInstruction> forInstrs = GenerateForCode(regOp, loopOp, incOp, currentLoopNum); firstPassInstrs.AddRange(forInstrs); addr += 10; labelLocations.Add($"@@@END_FOR_LOOP_NUM_{currentLoopNum}", addr); } else if (op.Value != "for") { throw new ParserException($"ERROR: Unsupported pragma {op.Value} on line {op.LineNumber}.", op.LineNumber, 0); } else { throw new ParserException($"ERROR: Invalid number of arguments for FOR loop on line " + $"{op.LineNumber}. Expected 4 arguments, received {line.Count - 1}.", op.LineNumber, 0); } } else { throw new ParserException($"ERROR: Unsupported token type {op.Type} on line {op.LineNumber}.", op.LineNumber, 0); } } List <Operation> parsedOps = new List <Operation>(); foreach (ParsedInstruction instr in firstPassInstrs) { Opcodes opName = EnumConv.StringToOpcode(instr.Name); if (Operation.ManipOpcodes.Contains(opName)) { int Ri = 0; int Rj = 0; // The Ri operand must always be a register, so we'll just // check that and assign Ri easily if (instr.Operands[0].Type != OperandType.Register) { throw new ParserException($"ERROR: Invalid Ri operand type {instr.Operands[0].Type} for instruction {instr.Name}.", instr.LineNumber, 1); } Ri = int.Parse(instr.Operands[0].Value); // Next we'll assign Rj, which can have a few types // If Rj doesn't exist, it's fine, we can just keep it as 0. // We have NOT which only takes one operand. if (instr.Operands.Count > 1) { if (instr.Operands[1].Type == OperandType.Register || instr.Operands[1].Type == OperandType.Constant) { Rj = int.Parse(instr.Operands[1].Value); } else if (instr.Operands[1].Type == OperandType.Label) { if (dirDict.ContainsKey(instr.Operands[1].Value)) { Rj = int.Parse(dirDict[instr.Operands[1].Value]); } else { throw new ParserException($"ERROR: Invalid label {instr.Operands[1].Value} on line {instr.LineNumber}.", instr.LineNumber, 2); } } else { throw new ParserException($"ERROR: Invalid Rj operand type {instr.Operands[1].Type} for instruction {instr.Name}.", instr.LineNumber, 2); } } parsedOps.Add(new ManipulationOperation(Ri, Rj, opName)); } else if (Operation.MemOpcodes.Contains(opName)) { int Ri = 0; int Rj = 0; int offset = 0; // Ri and Rj must be registers Ri = int.Parse(instr.Operands[0].Value); Rj = int.Parse(instr.Operands[1].Value); // Offset can be a hard-coded or labeled constant if (instr.Operands[2].Type == OperandType.Constant) { offset = int.Parse(instr.Operands[2].Value); } else if (instr.Operands[2].Type == OperandType.Label) { if (dirDict.ContainsKey(instr.Operands[2].Value)) { offset = int.Parse(dirDict[instr.Operands[2].Value]); } else { throw new ParserException($"ERROR: Invalid label {instr.Operands[2].Value} on line {instr.LineNumber}.", instr.LineNumber, 3); } } else { throw new ParserException($"ERROR: Invalid operand type {instr.Operands[2].Type} for instruction {instr.Name} on line {instr.LineNumber}.", instr.LineNumber, 3); } parsedOps.Add(new MemoryOperation(Ri, Rj, offset, opName)); } else if (Operation.MethodOpcodes.Contains(opName)) { int offset = 0; if (instr.Operands.Count > 0) { if (instr.Operands[0].Type == OperandType.Constant) { offset = int.Parse(instr.Operands[0].Value); } else if (instr.Operands[0].Type == OperandType.Label) { if (labelLocations.ContainsKey(instr.Operands[0].Value)) { offset = labelLocations[instr.Operands[0].Value]; } else { throw new ParserException($"ERROR: Invalid label {instr.Operands[0].Value} on line {instr.LineNumber}.", instr.LineNumber, 1); } } else { throw new ParserException($"ERROR: Invalid operand type {instr.Operands[0].Type} for instruction {instr.Name} on line {instr.LineNumber}.", instr.LineNumber, 1); } } parsedOps.Add(new MethodOperation(offset, opName)); } else if (Operation.StackOpcodes.Contains(opName)) { int Ri = int.Parse(instr.Operands[0].Value); parsedOps.Add(new StackOperation(Ri, opName)); } else if (opName == Opcodes.JMP) { JumpTypes jmpType = EnumConv.StringToJumpType(instr.Name); int offset = 0; // This assembler will only allow direct AM, so Ri=0 and // offset can be a constant or label if (instr.Operands[0].Type == OperandType.Constant) { offset = int.Parse(instr.Operands[0].Value); } else if (instr.Operands[0].Type == OperandType.Label) { if (labelLocations.ContainsKey(instr.Operands[0].Value)) { offset = labelLocations[instr.Operands[0].Value]; } else { throw new ParserException($"ERROR: Invalid label {instr.Operands[0].Value} on line {instr.LineNumber}.", instr.LineNumber, 1); } } else { throw new ParserException($"ERROR: Invalid operand type {instr.Operands[0].Type} for instruction {instr.Name} on line {instr.LineNumber}.", instr.LineNumber, 1); } parsedOps.Add(new JumpOperation(0, offset, jmpType)); } } return(parsedOps); }
/// <summary> /// For some species <paramref name="sp"/>, /// this function computes on which side/wing /// of level-set no. <paramref name="levSetIdx"/>) /// the species is located. /// </summary> /// <remarks> /// Nur ein Provisorium, das ganze Konzept ist noch etwas unausgereift. (Habe einen Nachmittag lang darueber nachgedacht, keinen bessere Idee gehabt, /// und darum...). /// </remarks> public JumpTypes IdentifyWing(int levSetIdx, SpeciesId sp) { int NoOfLevSets = this.XDGSpaceMetrics.NoOfLevelSets; if (levSetIdx < 0 || levSetIdx > NoOfLevSets) { throw new ArgumentOutOfRangeException(); } if (NoOfLevSets == 1) { string[] speciesTable = (string[])(this.XDGSpaceMetrics.LevelSetRegions.SpeciesTable); Debug.Assert(speciesTable.Length == 2); string spN = this.XDGSpaceMetrics.LevelSetRegions.GetSpeciesName(sp); if (spN == speciesTable[0]) { return(JumpTypes.OneMinusHeaviside); } else if (spN == speciesTable[1]) { return(JumpTypes.Heaviside); } else { throw new Exception("should not happen."); } } else if (NoOfLevSets == 2) { string[,] speciesTable = (string[, ])(this.XDGSpaceMetrics.LevelSetRegions.SpeciesTable); Debug.Assert(speciesTable.GetLength(0) == 2); Debug.Assert(speciesTable.GetLength(1) == 2); string spN = this.XDGSpaceMetrics.LevelSetRegions.GetSpeciesName(sp); int[] LevSetSigns; bool foundCell; { // we need the signs of other level sets to identify the wing // so we search for some cut cell of Level-Set #levSetIdx // which actually contains species 'sp' int J = this.XDGSpaceMetrics.GridDat.iLogicalCells.NoOfLocalUpdatedCells; int[] LenToNextchange = this.XDGSpaceMetrics.LevelSetRegions.m_LenToNextChange; LevSetSigns = new int[NoOfLevSets]; foundCell = false; for (int j = 0; j < J; j += LenToNextchange[j]) { ushort code = this.XDGSpaceMetrics.LevelSetRegions.m_LevSetRegions[j]; int dist = LevelSetTracker.DecodeLevelSetDist(code, levSetIdx); if (dist != 0) { continue; } // cut by Level-Set bool present = this.XDGSpaceMetrics.LevelSetRegions.IsSpeciesPresentInCell(sp, j); if (!present) { continue; } // contains species 'sp' var Signs = this.XDGSpaceMetrics.LevelSetRegions.GetCellSignCode(j); for (int iLs = 0; iLs < NoOfLevSets; iLs++) { if (iLs != levSetIdx) { var s = Signs.GetSign(iLs); if (s == LevelsetSign.Both) { continue; } else if (s == LevelsetSign.Negative) { foundCell = true; LevSetSigns[iLs] = 0; } else if (s == LevelsetSign.Positive) { foundCell = true; LevSetSigns[iLs] = 1; } else { throw new NotImplementedException(); } } } } } int cnt = 0; JumpTypes jmpRet = JumpTypes.Implicit; /* * int[] _i = new int[2]; * for (_i[0] = 0; _i[0] < 2; _i[0]++) { // loop over signs of level-set 0 ... * for (_i[1] = 0; _i[1] < 2; _i[1]++) { // loop over signs of level-set 1 ... * if (speciesTable[_i[0], _i[1]] == spN) { * cnt++; * * if (_i[levSetIdx] == 0) * jmpRet = JumpTypes.OneMinusHeaviside; * else if (_i[levSetIdx] == 1) * jmpRet = JumpTypes.Heaviside; * else * throw new ApplicationException(); * } * } * } */ if (foundCell == false) { return(JumpTypes.Heaviside); // no cell on this proc, so anyway pretty irrelevant } for (int i = 0; i < 2; i++) { LevSetSigns[levSetIdx] = i; if (speciesTable[LevSetSigns[0], LevSetSigns[1]] == spN) { cnt++; if (LevSetSigns[levSetIdx] == 0) { jmpRet = JumpTypes.OneMinusHeaviside; } else if (LevSetSigns[levSetIdx] == 1) { jmpRet = JumpTypes.Heaviside; } else { throw new ApplicationException(); } } } if (cnt != 1) { throw new NotImplementedException("unable to identify."); } return(jmpRet); } else { throw new NotImplementedException(); } }
/// <summary> /// Quadrature rule on cell boundaries /// </summary> public IQuadRuleFactory <CellBoundaryQuadRule> GetCellFaceFactory(int levSetIndex, RefElement Kref, JumpTypes jumpType) { int D = this.m_LevelSetDatas[0].GridDat.SpatialDimension; if (D == 2) { if (jumpType != JumpTypes.Heaviside && jumpType != JumpTypes.OneMinusHeaviside) { throw new NotSupportedException(); } Debug.Assert(CellFaceVolume_in3D == null); if (LineAndPoint_in2D == null) { LineAndPoint_in2D = new LineAndPointQuadratureFactory[this.m_LevelSetDatas.Length]; } if (LineAndPoint_in2D[levSetIndex] == null) { LineAndPoint_in2D[levSetIndex] = new LineAndPointQuadratureFactory(Kref, this.m_LevelSetDatas[levSetIndex], true); } return(LineAndPoint_in2D[levSetIndex].GetLineFactory(jumpType == JumpTypes.Heaviside ? true : false)); } else if (D == 3) { Debug.Assert(LineAndPoint_in2D == null); if (jumpType != JumpTypes.Heaviside) { throw new NotSupportedException(); } if (CellFaceVolume_in3D == null) { CellFaceVolume_in3D = new LevelSetEdgeVolumeQuadRuleFactory[this.m_LevelSetDatas.Length]; } var rootFindingAlgorithm = new LineSegment.SafeGuardedNewtonMethod(1e-14); CellFaceVolume_in3D[levSetIndex] = new LevelSetEdgeVolumeQuadRuleFactory( this.m_LevelSetDatas[levSetIndex], rootFindingAlgorithm, JumpTypes.Heaviside); return(CellFaceVolume_in3D[levSetIndex]); } else { throw new NotSupportedException(); } }