/// <summary>
    /// This method sets the properties of the STATIC overlay. This will ensure that the correct tiles are shown on the grid depending on the effect the spell has on different units.
    /// </summary>
    /// <param name="overlayType"></param>
    /// <param name="range"></param>
    /// <param name="op"></param>
    public static void DrawRangeOverlay(OverlayType overlayType, int range, Vector3Int currentMousePosition, OverlayProperties op, Unit unit = null)
    {
        overlayProperties = op;

        switch (overlayType)
        {
        case OverlayType.Cross:
            DrawCrossOverlay(currentMousePosition, range);
            break;

        case OverlayType.Diamond:
            DrawDiamondOverlay(currentMousePosition, range);
            break;

        case OverlayType.Square:
            DrawSquareOverlay(currentMousePosition, range);
            break;

        case OverlayType.Self:
            DrawSelfOverlay(currentMousePosition);
            break;

        default:
            break;
        }

        if (overlayType != OverlayType.Self && unit == null)
        {
            if (floorsTilemap.HasTile(currentMousePosition))
            {
                DrawRangeOverlay(currentMousePosition);
            }
        }
    }
Beispiel #2
0
        public void SetVisibility(OverlayType type, bool visible)
        {
            if (!_areaRenderer)
            {
                RestartOverlay();
            }

            switch (type)
            {
            case OverlayType.AREA:
                _areaRenderer.enabled = visible;
                break;

            case OverlayType.DERIV:
                _derivRenderer.enabled = visible;
                break;

            case OverlayType.COEFF:
                _coeffRenderer.enabled = visible;
                break;
            }

            bool anyVisible = AnyVisible();

            for (int i = 0; i < _markingRenderers.Count; i++)
            {
                _markingRenderers[i].enabled = anyVisible;
                if (i > _numGridLines)
                {
                    _markingRenderers[i].enabled = false;
                }
            }
        }
Beispiel #3
0
		public void UpdateVersion()
		{
			if (overlayType == UMACrowdRandomSet.OverlayType.Unknown)
			{
				if (useSkinColor)
				{
					overlayType = UMACrowdRandomSet.OverlayType.Skin;
				}
				else if (useHairColor)
				{
					overlayType = UMACrowdRandomSet.OverlayType.Hair;
				}
				else
				{
					if (minRGB == maxRGB)
					{
						if (minRGB == Color.white)
						{
							overlayType = UMACrowdRandomSet.OverlayType.Texture;
						}
						else
						{
							overlayType = UMACrowdRandomSet.OverlayType.Color;
						}
					}
					else
					{
						overlayType = UMACrowdRandomSet.OverlayType.Random;
					}
				}
			}
		}
Beispiel #4
0
		/// <summary> 
		/// This method will handle arguments of 
		/// LocationType.None correctly.
		/// </summary>
		/// <returns> true if the locations correspond to the opCode
		/// </returns>
		internal static bool IsResultOfOp(int loc0, int loc1, OverlayType opCode)
		{
			if (loc0 == LocationType.Boundary)
				loc0 = LocationType.Interior;
			if (loc1 == LocationType.Boundary)
				loc1 = LocationType.Interior;

			switch (opCode)
			{
				case OverlayType.Intersection: 
					return loc0 == LocationType.Interior && 
                        loc1 == LocationType.Interior;
				
				case OverlayType.Union: 
					return loc0 == LocationType.Interior || 
                        loc1 == LocationType.Interior;
				
				case OverlayType.Difference: 
					return loc0 == LocationType.Interior && 
                        loc1 != LocationType.Interior;
				
				case OverlayType.SymmetricDifference: 
					return (loc0 == LocationType.Interior && loc1 != LocationType.Interior) || 
                        (loc0 != LocationType.Interior && loc1 == LocationType.Interior);
			}

			return false;
		}
Beispiel #5
0
 public void UpdateVersion()
 {
     if (overlayType == UMACrowdRandomSet.OverlayType.Unknown)
     {
         if (useSkinColor)
         {
             overlayType = UMACrowdRandomSet.OverlayType.Skin;
         }
         else if (useHairColor)
         {
             overlayType = UMACrowdRandomSet.OverlayType.Hair;
         }
         else
         {
             if (minRGB == maxRGB)
             {
                 if (minRGB == Color.white)
                 {
                     overlayType = UMACrowdRandomSet.OverlayType.Texture;
                 }
                 else
                 {
                     overlayType = UMACrowdRandomSet.OverlayType.Color;
                 }
             }
             else
             {
                 overlayType = UMACrowdRandomSet.OverlayType.Random;
             }
         }
     }
 }
        private List <Vector3> GetOverlayPositions(OverlayType overlayType, int range)
        {
            List <Vector3>    positions = new List <Vector3>();
            IEnumerable <int> ranges    = Enumerable.Range(-range, range * 2 + 1);

            if (overlayType == OverlayType.Move)
            {
                foreach (int h in ranges)
                {
                    positions.Add(new Vector3(h, 0, transform.position.z));
                }

                foreach (int v in ranges)
                {
                    positions.Add(new Vector3(0, v, transform.position.z));
                }
            }

            if (overlayType == OverlayType.Attack)
            {
                foreach (int h in ranges)
                {
                    foreach (int v in ranges)
                    {
                        positions.Add(new Vector3(h, v, transform.position.z));
                    }
                }
            }

            return(positions);
        }
Beispiel #7
0
    public void Initialize()
    {
        int index = 0;

        overMan = GameManager.instance.overlayManager;
        foreach (KeyValuePair <OverlayType, OverlayManager.IOverlay> overPair in overMan.overlays)
        {
            OverlayType             overType = overPair.Key;
            OverlayManager.IOverlay over     = overPair.Value;

            GameObject overlayButton          = Instantiate(overlayButtonExample, transform);
            Button     overlayButtonComponent = overlayButton.GetComponent <Button>();

            int value = index;
            overlayButtonComponent.onClick.AddListener(delegate {
                overMan.SelectOverlay(overType);
                Select(value);
            });

            overlayButton.GetComponent <Tooltip>().AddLocalizedLine(
                new Localization.Line("overlay", over.codeName)
                );

            buttons.Add(overlayButton.GetComponents <Image>());

            overlayButton.transform.GetChild(0).gameObject.GetComponent <Image>().sprite = over.sprite;

            index++;
        }
        Destroy(overlayButtonExample);
        Reset();
    }
Beispiel #8
0
        /// <summary>
        /// Determines nodes which are in the result, and creates
        /// {@link Point}s for them.
        ///
        /// This method determines nodes which are candidates for the result via their
        /// labelling and their graph topology.
        ///
        /// </summary>
        /// <param name="opCode">the overlay operation
        /// </param>
        private void ExtractNonCoveredResultNodes(OverlayType opCode)
        {
            // Add nodes from edge intersections which have not already been included in the result
            for (IEnumerator nodeit = op.Graph.Nodes.GetEnumerator(); nodeit.MoveNext();)
            {
                Node n = (Node)nodeit.Current;

                // filter out nodes which are known to be in the result
                if (n.InResult)
                {
                    continue;
                }
                // if an incident edge is in the result, then the node coordinate is included already
                if (n.IsIncidentEdgeInResult)
                {
                    continue;
                }

                if (n.Edges.Degree == 0 ||
                    opCode == OverlayType.Intersection)
                {
                    // For nodes on edges, only INTERSECTION can result in
                    // edge nodes being included even
                    // if none of their incident edges are included
                    Label label = n.Label;
                    if (OverlayOp.IsResultOfOp(label, opCode))
                    {
                        FilterCoveredNodeToPoint(n);
                    }
                }
            }
        }
Beispiel #9
0
    public void RemoveOverlaysOfType(Vector3Int cellPosition, LayerType layerType, OverlayType overlayType, bool onlyIfCleanable = false)
    {
        cellPosition.z = 0;

        var overlayPos = metaTileMap.GetOverlayPosByType(cellPosition, layerType, overlayType);

        if (overlayPos == null || overlayPos.Count == 0)
        {
            return;
        }

        foreach (var overlay in overlayPos)
        {
            cellPosition = overlay;

            if (onlyIfCleanable)
            {
                //only remove it if it's a cleanable tile
                var tile = metaTileMap.GetTile(cellPosition, layerType) as OverlayTile;
                //it's not an overlay tile or it's not cleanable so don't remove it
                if (tile == null || !tile.IsCleanable)
                {
                    continue;
                }
            }

            InternalRemoveTile(cellPosition, layerType);

            SpawnSafeThread.RemoveTileMessageSend(networkMatrix.MatrixSync.netId, cellPosition, layerType);

            AddToChangeList(cellPosition, layerType);
        }
    }
Beispiel #10
0
        /// <summary>
        /// Collect edges from area inputs which should be in the result but
        /// which have not been included in a result area.
        /// </summary>
        /// <remarks>
        /// This happens ONLY:
        /// <list type="bullet">
        /// <item>
        /// <description>
        /// During an intersection when the boundaries of two areas touch
        /// in a line segment.
        /// </description>
        /// </item>
        /// <item>
        /// <description>OR as a result of a dimensional collapse.</description>
        /// </item>
        /// </list>
        /// </remarks>
        private void CollectBoundaryTouchEdge(DirectedEdge de,
                                              OverlayType opCode, ArrayList edges)
        {
            Label label = de.Label;

            if (de.LineEdge)
            {
                return;  // only interested in area edges
            }
            if (de.Visited)
            {
                return;  // already processed
            }
            if (de.InteriorAreaEdge)
            {
                return;  // added to handle dimensional collapses
            }
            if (de.Edge.InResult)
            {
                return;  // if the edge linework is already included, don't include it again
            }
            // sanity check for labelling of result edgerings
            Debug.Assert(!(de.InResult || de.Sym.InResult) || !de.Edge.InResult);

            // include the linework if it's in the result of the operation
            if (OverlayOp.IsResultOfOp(label, opCode) &&
                opCode == OverlayType.Intersection)
            {
                edges.Add(de.Edge);
                de.VisitedEdge = true;
            }
        }
Beispiel #11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="geom0"></param>
        /// <param name="geom1"></param>
        /// <param name="opCode"></param>
        /// <returns></returns>
		public static Geometry Overlay(Geometry geom0, Geometry geom1, 
            OverlayType opCode)
		{
			OverlayOp gov   = new OverlayOp(geom0, geom1);
			Geometry geomOv = gov.Overlay(opCode);

			return geomOv;
		}
        private void InstantiateOverlayTile(Vector3 position, OverlayType overlayType)
        {
            Sprite sprite = overlayType == OverlayType.Move ? moveRangeSpriteOverlay : attackRangeSpriteOverlay;

            GameObject go = Instantiate(overlayTilePrefab, overlay.transform.position + position, Quaternion.identity, overlay.transform);

            go.GetComponent <SpriteRenderer>().sprite = sprite;
        }
Beispiel #13
0
 /// <summary>
 /// Changes the DrawingManager's drawing mode, which defines the type of overlay to be added on the map.
 /// Accepted values are 'marker', 'polygon', 'polyline', 'rectangle', 'circle', or null.
 /// A drawing mode of null means that the user can interact with the map as normal, and clicks do not draw anything.
 /// </summary>
 /// <returns></returns>
 public Task SetDrawingMode(OverlayType drawingMode)
 {
     return(_jsRuntime.InvokeWithDefinedGuidAndMethodAsync <object>(
                "googleMapDrawingManagerJsFunctions.invoke",
                _guid.ToString(),
                "setDrawingMode",
                drawingMode));
 }
    /// <summary>
    /// This method sets the properties of the REALTIME overlay. This will ensure that the correct tiles are shown on the grid depending on the effect the spell has on different units.
    /// </summary>
    /// <param name="overlayType"></param>
    /// <param name="range"></param>
    /// <param name="op"></param>
    public static void DrawRealtimeOverlay(OverlayType overlayType, int range, OverlayProperties op)
    {
        overlayProperties = op;

        realtimeOverlay.isEnabled   = true;
        realtimeOverlay.overlayType = overlayType;
        realtimeOverlay.range       = range;
    }
Beispiel #15
0
        /// Does some synchronous work inside the compositor.
        /// Some mostly-faked progress will be displayed.
        public async Task <T> RunInCompositorAsync <T>(
            OverlayType overlayType,
            Func <T> action,
            float fadeDuration,
            bool showSuccessText = false)
        {
            SetOverlayFromType(overlayType);
            bool bFullProgress = false;

            UpdateProgress(bFullProgress ? 1.0f : 0.0f);

            App.VrSdk.SetOverlayAlpha(0);
            await Awaiters.NextFrame;

            try
            {
                // You can't rely on the SteamVR compositor fade being totally over in the time
                // you specified. You also can't rely on being able to get a sensible value for the fade
                // alpha, so you can't reliably wait for it to be done.
                // Therefore, we use the simple method of just waiting a bit longer than we should
                // need to, by passing slightly-too-wide bounds.
                await FadeCompositorAndOverlayAsync(0, 1.1f, fadeDuration);

                // Wait one additional frame for any transitions to complete (e.g. fade to black).
                App.VrSdk.PauseRendering(true);
                Progress.Report(0.25);
                await Awaiters.NextFrame;

                T result = default;
                try
                {
                    result = action();
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }

                Progress.Report(0.75);
                if (showSuccessText)
                {
                    SetText("Success!");
                    await Awaiters.Seconds(1f);
                }

                App.VrSdk.PauseRendering(false);
                await FadeCompositorAndOverlayAsync(1, 0, fadeDuration);

                return(result);
            }
            catch (Exception)
            {
                App.VrSdk.PauseRendering(false);
                App.VrSdk.FadeFromCompositor(0);
                SetOverlayTransitionRatio(0);
                throw;
            }
        }
Beispiel #16
0
 public bool IsVisible(OverlayType type)
 {
     return(type switch
     {
         OverlayType.AREA => (_areaRenderer != null && _areaRenderer.enabled),
         OverlayType.DERIV => (_derivRenderer != null && _derivRenderer.enabled),
         OverlayType.COEFF => (_coeffRenderer != null && _coeffRenderer.enabled),
         _ => false
     });
Beispiel #17
0
        /// <summary>
        /// Computes the Point geometries which will appear in the result,
        /// given the specified overlay operation.
        /// </summary>
        /// <returns>
        /// A list of the Points objects in the result.
        /// </returns>
        public IGeometryList Build(OverlayType opCode)
        {
            ExtractNonCoveredResultNodes(opCode);

            // It can happen that connected result nodes are still covered by
            // result geometries, so must perform this filter.
            // (For instance, this can happen during topology collapse).
            return(resultPointList);
        }
Beispiel #18
0
        public static bool OverlayOperate(DotSpatial.Data.IFeatureSet baseFeatureSet, DotSpatial.Data.IFeatureSet overlayFeatureSet,
                                          ref OSGeo.OGR.Layer resultLayer, OverlayType type, Ogr.GDALProgressFuncDelegate callback)
        {
            OSGeo.OGR.Layer baseLayer    = VectorConverter.DS2OrgLayer(baseFeatureSet);
            OSGeo.OGR.Layer overlayLayer = VectorConverter.DS2OrgLayer(overlayFeatureSet);
            bool            result       = OverlayOperate(baseLayer, overlayLayer, ref resultLayer, type, callback);

            return(result);
        }
Beispiel #19
0
        public static bool OverlayOperate(string baseLayerPath, string overlayLayerPath,
                                          ref OSGeo.OGR.Layer resultLayer, OverlayType type, Ogr.GDALProgressFuncDelegate callback)
        {
            OSGeo.OGR.Layer baseLayer    = VectorConverter.GetOgrLayer(baseLayerPath);
            OSGeo.OGR.Layer overlayLayer = VectorConverter.GetOgrLayer(overlayLayerPath);
            bool            result       = OverlayOperate(baseLayer, overlayLayer, ref resultLayer, type, callback);

            return(result);
        }
Beispiel #20
0
 private void CollectLines(OverlayType opCode)
 {
     for (IEnumerator it = op.Graph.EdgeEnds.GetEnumerator(); it.MoveNext();)
     {
         DirectedEdge de = (DirectedEdge)it.Current;
         CollectLineEdge(de, opCode, lineEdgesList);
         CollectBoundaryTouchEdge(de, opCode, lineEdgesList);
     }
 }
Beispiel #21
0
        /// <returns>
        /// a list of the LineStrings in the result of the specified overlay operation
        /// </returns>
        public GeometryList Build(OverlayType opCode)
        {
            FindCoveredLineEdges();
            CollectLines(opCode);
            //LabelIsolatedLines(lineEdgesList);
            BuildLines(opCode);

            return(resultLineList);
        }
 OverlayDrawer(Rect rectangle, Color backgroundColor)
 {
     m_Type                = OverlayType.BackgroundColor;
     m_Rect                = rectangle;
     m_Color               = backgroundColor;
     m_Text                = string.Empty;
     m_Texture             = null;
     m_BackgroundTextStyle = null;
     m_TextStyle           = null;
 }
 public Overlay(long start, long end, Size size, WatermarkPosition position, Point offset, OverlayType overlayType)
 {
     Id          = Guid.NewGuid();
     StartTicks  = start;
     EndTicks    = end;
     Size        = size;
     Position    = position;
     Offset      = offset;
     OverlayType = overlayType;
 }
 /// Like RunInCompositor but for non-coroutines
 public IEnumerator <Null> RunInCompositor(
     OverlayType overlayType,
     System.Action action,
     float fadeDuration,
     bool bFullProgress   = false,
     bool showSuccessText = false)
 {
     return(RunInCompositor(overlayType, AsCoroutine(action), fadeDuration,
                            bFullProgress, showSuccessText));
 }
Beispiel #25
0
 public Overlay(long start, long end, Size size, WatermarkPosition position, Point offset, OverlayType overlayType)
 {
     Id = Guid.NewGuid();
     StartTicks = start;
     EndTicks = end;
     Size = size;
     Position = position;
     Offset = offset;
     OverlayType = overlayType;
 }
 OverlayDrawer(Rect rectangle, Texture2D backTexture)
 {
     m_Type                = OverlayType.BackgroundTexture;
     m_Rect                = rectangle;
     m_Color               = Color.clear;
     m_Text                = string.Empty;
     m_Texture             = backTexture;
     m_BackgroundTextStyle = null;
     m_TextStyle           = null;
 }
Beispiel #27
0
    public Color?GetColourOfFirstTile(Vector3Int cellPosition, OverlayType overlayType, LayerType layerType)
    {
        var overlays = metaTileMap.GetOverlayPosByType(cellPosition, layerType, overlayType);

        if (overlays.Count == 0)
        {
            return(null);
        }

        return(metaTileMap.GetColour(overlays.First(), layerType));
    }
 /// Like RunInCompositor, but allows you to pass an IEnumerator(float).
 /// The float being yielded should be a progress value between 0 and 1.
 public IEnumerator <Null> RunInCompositorWithProgress(
     OverlayType overlayType,
     IEnumerator <float> coroutineWithProgress,
     float fadeDuration)
 {
     return(RunInCompositor(
                overlayType,
                ConsumeAsProgress(coroutineWithProgress),
                fadeDuration,
                false));
 }
Beispiel #29
0
        private void BuildLines(OverlayType opCode)
        {
            // need to simplify lines?
            for (IEnumerator it = lineEdgesList.GetEnumerator(); it.MoveNext();)
            {
                Edge e = (Edge)it.Current;

                LineString line = geometryFactory.CreateLineString(e.Coordinates);
                resultLineList.Add(line);
                e.InResult = true;
            }
        }
 OverlayDrawer(Rect rectangle, string msg, GUIStyle textStyle, Color textColor, Color bgTextColor, GUIStyle bgTextStyle)
 {
     m_Type      = OverlayType.TextBox;
     m_Rect      = rectangle;
     m_Text      = msg;
     m_TextStyle = textStyle;
     m_TextStyle.normal.textColor           = textColor;
     m_BackgroundTextStyle                  = bgTextStyle;
     m_BackgroundTextStyle.normal.textColor = bgTextColor;
     m_Texture = null;
     m_Color   = Color.clear;
 }
Beispiel #31
0
		private void ComputeOverlay(OverlayType opCode)
		{
			// copy points from input Geometries.
			// This ensures that any Point geometries
			// in the input are considered for inclusion in the result set
			CopyPoints(0);
			CopyPoints(1);
			
			// node the input Geometries
			arg[0].ComputeSelfNodes(li, false);
			arg[1].ComputeSelfNodes(li, false);
			
			// compute intersections between edges of the two input geometries
			arg[0].ComputeEdgeIntersections(arg[1], li, true);
			
			EdgeCollection baseSplitEdges = new EdgeCollection();
			arg[0].ComputeSplitEdges(baseSplitEdges);
			arg[1].ComputeSplitEdges(baseSplitEdges);
//			EdgeCollection splitEdges = baseSplitEdges;
			// Add the noded edges to this result graph
			InsertUniqueEdges(baseSplitEdges);
			
			ComputeLabelsFromDepths();
			ReplaceCollapsedEdges();
			
			graph.AddEdges(edgeList.Edges);
			ComputeLabelling();

            LabelIncompleteNodes();
			
			// The ordering of building the result Geometries is important.
			// Areas must be built before lines, which must be built before points.
			// This is so that lines which are covered by areas are not included
			// explicitly, and similarly for points.
			FindResultAreaEdges(opCode);
			CancelDuplicateResultEdges();
			PolygonBuilder polyBuilder = new PolygonBuilder(geomFact);
			polyBuilder.Add(graph);
			resultPolyList = polyBuilder.Build();
			
			LineBuilder lineBuilder = new LineBuilder(this, geomFact, ptLocator);
			resultLineList = lineBuilder.Build(opCode);
			
			PointBuilder pointBuilder = new PointBuilder(this, geomFact);
			resultPointList = pointBuilder.Build(opCode);
			
			// gather the results from all calculations into a single Geometry for the result set
			resultGeom = ComputeGeometry(resultPointList, resultLineList, resultPolyList);
		}
Beispiel #32
0
        public override void Run()
        {
            OverlayType   type      = OverlayType.Update;
            OverlayDialog frmUpdate = new OverlayDialog(type);

            frmUpdate.Text = StringParser.Parse("${res:Ribbon.SpatialAnalysis.Overlay.Update}");
            if (frmUpdate.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string baseLayerPath    = frmUpdate.baseLayerPath;
                string overlayLayerPath = frmUpdate.overlayLayerPath;
                string resultLayerPath  = frmUpdate.resultLayerPath;

                OverlayOperate.ProcessOverlay(baseLayerPath, overlayLayerPath, resultLayerPath, type);
            }
        }
Beispiel #33
0
	void Update()
	{
		if (Input.GetKey (KeyCode.Joystick1Button0))
		{
			currentOverlayType = OverlayType.None;
		}
		else if (Input.GetKey (KeyCode.Joystick1Button1))
		{
			currentOverlayType = OverlayType.OverlayShowLod;
		}
		else
		{
			currentOverlayType = OverlayType.Overlay;
		}
	}
Beispiel #34
0
	void Update()
    {
#if !UNITY_ANDROID || UNITY_EDITOR
        if (this.GetComponent<Renderer>().material.mainTexture != texture)
        {
            texId = this.GetComponent<Renderer>().material.mainTexture.GetNativeTexturePtr();
            texture = this.GetComponent<Renderer>().material.mainTexture;
        }
#endif

		if (Input.GetKey (KeyCode.Joystick1Button0))
		{
			currentOverlayType = OverlayType.None;
		}
		else if (Input.GetKey (KeyCode.Joystick1Button1))
		{
			currentOverlayType = OverlayType.OverlayShowLod;
		}
		else
		{
			currentOverlayType = OverlayType.Overlay;
		}
	}
Beispiel #35
0
        private void addPoints(PlanarGraph graph, OverlayType operation, Polygon p1, Polygon p2, Collection<IGeometry> collection)
        { 
            foreach (PlanarGraphNode node in graph.Nodes)
                node.Enabled = isNodeEnabled(node, operation, p1, p2);

            List<PointD> points = graph.BuildPoints();

            foreach (PointD p in points)
                collection.Add(p);
        }
Beispiel #36
0
	void Update()
    {
#if !UNITY_ANDROID || UNITY_EDITOR
		ApplyTexture();
#endif

		if (Input.GetKey (KeyCode.Joystick1Button0))
		{
			currentOverlayType = OverlayType.None;
		}
		else if (Input.GetKey (KeyCode.Joystick1Button1))
		{
			currentOverlayType = OverlayType.OverlayShowLod;
		}
		else
		{
			currentOverlayType = OverlayType.Overlay;
		}
    }
Beispiel #37
0
        private GeometryCollection calculateNonIntersectedObjectsOverlay(IGeometry geometry1, IGeometry geometry2, OverlayType operation, bool performSnapping)
        {
            GeometryCollection result = new GeometryCollection();

            // zero crossing
            if (operation == OverlayType.Intersection)
                return result;

            // difference is equal to the first object
            if (operation == OverlayType.Difference)
            {
                result.Add((IGeometry)geometry1.Clone());
                return result;
            }

            // symmetric difference and the union concatenating
            try
            {
                if (geometry1 is Polygon && geometry2 is Polygon)
                {
                    _polygon1Contours = SimplifyContours(((Polygon)geometry1).Contours);
                    _polygon2Contours = SimplifyContours(((Polygon)geometry2).Contours);

                    Polygon p = new Polygon();
                    foreach (Contour c in _polygon1Contours)
                        p.Contours.Add(c);

                    foreach (Contour c in _polygon2Contours)
                        p.Contours.Add(c);

                    result.Add(p);
                }
                else if (geometry1 is Polyline && geometry2 is Polyline)
                {
                    Polyline p = new Polyline();

                    foreach (LinePath path in ((Polyline)geometry1).Paths)
                        p.Paths.Add(path);

                    foreach (LinePath path in ((Polyline)geometry2).Paths)
                        p.Paths.Add(path);

                    result.Add(p);
                }
                else
                {
                    // If a figure is still a proving ground to normalize topology
                    if (geometry1 is Polygon)
                    {
                        geometry1 = (IGeometry)((Polygon)geometry1).Clone();
                        ((Polygon)geometry1).Simplify();
                    }

                    if (geometry2 is Polygon)
                    {
                        geometry2 = (IGeometry)((Polygon)geometry2).Clone();
                        ((Polygon)geometry2).Simplify();
                    }

                    result.Add(geometry1);
                    result.Add(geometry2);
                }

                return result;
            }
            finally
            {
                _polygon1Contours = null;
                _polygon2Contours = null;
            }
        }
Beispiel #38
0
		private static void SetOverlay(IDicomAttributeProvider dataset, int overlayIndex, bool[] overlayData, OverlayType type, Point origin, int rows, int columns, int? frames, int? frameOrigin, bool bigEndian, bool useOW)
		{
			DicomOverlayTestHelper.AddOverlayPlane(dataset, overlayIndex, overlayData, type, origin, rows, columns, frames, frameOrigin, bigEndian, useOW);
		}
		/// <summary>
		/// Sets an overlay plane module on the given dataset by embedding the overlay in an unused bit of the Pixel Data.
		/// </summary>
		/// <remarks>
		/// Call <see cref="SetImagePixels"/> before calling this method as it updates the current PixelData in the dataset.
		/// </remarks>
		/// <param name="dataset">The dataset.</param>
		/// <param name="overlayIndex">The index of the overlay plane.</param>
		/// <param name="overlayData">The overlay data.</param>
		/// <param name="type">The overlay type.</param>
		/// <param name="origin">The overlay origin per frame.</param>
		/// <param name="bitPosition">The position of the unused bit in the PixelData where the overlay should be stored.</param>
		/// <param name="bigEndian">Whether or not the dataset is big endian.</param>
		/// <exception cref="ArgumentException">Thrown if input values are inconsistent.</exception>
		public static void AddOverlayPlane(IDicomAttributeProvider dataset, int overlayIndex, bool[] overlayData, OverlayType type, Point origin, int bitPosition, bool bigEndian)
		{
			Platform.CheckForNullReference(dataset, "dataset");

			var rows = dataset[DicomTags.Rows].GetInt32(0, 0);
			var columns = dataset[DicomTags.Columns].GetInt32(0, 0);
			var frames = dataset[DicomTags.NumberOfFrames].GetInt32(0, 1);
			var bitsAllocated = dataset[DicomTags.BitsAllocated].GetInt32(0, 16);
			var bitsStored = dataset[DicomTags.BitsStored].GetInt32(0, 16);
			var highBit = dataset[DicomTags.HighBit].GetInt32(0, bitsStored - 1);
			var pixelData = (byte[]) dataset[DicomTags.PixelData].Values;

			// sanity check
			Platform.CheckForNullReference(overlayData, "overlayData");
			Platform.CheckArgumentRange(overlayIndex, 0, 15, "overlayIndex");
			Platform.CheckTrue(bitPosition >= 0 && bitPosition <= 15 && (bitPosition > highBit || bitPosition <= highBit - bitsStored), "bitPosition must specify an unused bit");
			Platform.CheckTrue(rows*columns*frames == overlayData.Length, "overlayData must have length equal to rows*columns*frames");
			Platform.CheckArgumentRange(bitsStored, 1, 16, "bitsStored");
			Platform.CheckTrue(highBit >= bitsStored - 1 && highBit <= 15, "highBit must be between bitsStored-1 and 15, inclusive");
			Platform.CheckTrue(bitsAllocated == 8 || bitsAllocated == 16, "bitsAllocated must be 8 or 16");
			Platform.CheckTrue(rows*columns*frames*(bitsAllocated/8) == pixelData.Length, "pixelData must have length equal to rows*columns*frames*bitsAllocated/8");

			uint tagOffset = ((uint) overlayIndex)*2*0x10000;

			// set basic attributes
			dataset[tagOffset + DicomTags.OverlayRows].SetInt32(0, rows);
			dataset[tagOffset + DicomTags.OverlayColumns].SetInt32(0, columns);
			dataset[tagOffset + DicomTags.OverlayType].SetString(0, type.ToString());
			dataset[tagOffset + DicomTags.OverlayOrigin].SetStringValue(string.Format(@"{0}\{1}", origin.X, origin.Y));
			dataset[tagOffset + DicomTags.OverlayBitsAllocated].SetInt32(0, bitsAllocated);
			dataset[tagOffset + DicomTags.OverlayBitPosition].SetInt32(0, bitPosition);

			// set multiframe attributes
			if (frames > 1)
				dataset[tagOffset + DicomTags.NumberOfFramesInOverlay].SetInt32(0, frames);
			else
				dataset[tagOffset + DicomTags.NumberOfFramesInOverlay].SetEmptyValue();
			dataset[tagOffset + DicomTags.ImageFrameOrigin].SetEmptyValue();

			// set overlay in unused bits of pixel data
			if (bitsAllocated == 16)
			{
				var highByte = bigEndian ? 0 : 1; // in a big endian word, the high byte is first
				var overlayBitMaskLow = (byte) (bitPosition <= 7 ? (1 << bitPosition) : 0);
				var overlayBitMaskHigh = (byte) (bitPosition > 7 ? (1 << (bitPosition - 8)) : 0);
				for (int i = 0; i < overlayData.Length; i++)
				{
					var cursor = i*2;
					pixelData[cursor + highByte] = (byte) ((pixelData[cursor + highByte] & ~overlayBitMaskHigh) | (overlayData[i] ? overlayBitMaskHigh : (byte) 0));
					pixelData[cursor + 1 - highByte] = (byte) ((pixelData[cursor + 1 - highByte] & ~overlayBitMaskLow) | (overlayData[i] ? overlayBitMaskLow : (byte) 0));
				}
			}
			else if (bitsAllocated == 8)
			{
				var overlayBitMask = (byte) (1 << bitPosition);
				for (int i = 0; i < overlayData.Length; i++)
				{
					pixelData[i] = (byte) ((pixelData[i] & ~overlayBitMask) | (overlayData[i] ? overlayBitMask : (byte) 0));
				}
			}
			dataset[DicomTags.PixelData].Values = pixelData;
		}
Beispiel #40
0
        private void getPointPolylineOverlay(MultiPoint mp, Polyline polyline, OverlayType operation, GeometryCollection result, bool performSnapping, bool inverseArgs)
        {
            try
            {
                _geometry1 = mp;
                _geometry2 = polyline;
                bool isValid = true;

                try
                {
                    init(performSnapping);

                    PlanarGraph graph = PlanarGraph.Build(_geometry1, _geometry2);

                    // classify edges and nodes
                    foreach (PlanarGraphEdge edge in graph.Edges)
                    {
                        edge.IsVisited = false;
                        switch (operation)
                        {
                            case OverlayType.Intersection:
                                edge.Enabled = false;
                                break;
                            case OverlayType.Union:
                                edge.Enabled = edge.Label.UsedByObject2;
                                break;
                            case OverlayType.Difference:
                                edge.Enabled = inverseArgs ? edge.Label.UsedByObject2 : false;
                                break;
                            case OverlayType.SymmetricDifference:
                                edge.Enabled = edge.Label.UsedByObject2;
                                break;
                        }
                    }

                    foreach (PlanarGraphNode node in graph.Nodes)
                    {
                        bool hasEnabledEdges = false;
                        foreach (PlanarGraphEdge edge in node.IncidentEdges)
                            if (edge.Enabled)
                            {
                                hasEnabledEdges = true;
                                break;
                            }
                        if (hasEnabledEdges)
                            node.Enabled = false;
                        else
                        {
                            switch (operation)
                            {
                                case OverlayType.Intersection:
                                    node.Enabled = node.Label.UsedByObject1 && node.Label.UsedByObject2;
                                    break;
                                case OverlayType.Union:
                                    node.Enabled = node.Label.UsedByObject1;
                                    break;
                                case OverlayType.Difference:
                                    node.Enabled = inverseArgs ? false : !node.Label.UsedByObject2;
                                    break;
                                case OverlayType.SymmetricDifference:
                                    node.Enabled = true;
                                    break;
                            }
                        }
                    }

                    // build results:
                    // point
                    List<PointD> points = graph.BuildPoints();

                    foreach (PointD p in points)
                        result.Add(p);

                    // polyline
                    Polyline pl = graph.BuildPolyline(false, false);

                    if (pl.CoordinateCount > 0)
                        result.Add(pl);

                    for (int i = 0; i < result.Count; i++)
                    {
                        IGeometry g = translateGeometry(result[i], _translationCenter.X, _translationCenter.Y);
                        if (g is PointD)
                            result[i] = g;
                    }
                }
                catch (TopologyException)
                {
                    if (!performSnapping)
                        isValid = false;
                    else
                        throw new InvalidOperationException("Unable to complete operation correctly with this value of tolerance (PlanimertyAlgorithms.Tolerance)");
                }

                if (isValid)
                    return;
                else
                {
                    // overlay has not been calculated.
                    // it may be possible to calculate the overlay aligned to the grid
                    getPointPolylineOverlay(mp, polyline, operation, result, true, inverseArgs);
                    return;
                }
            }
            finally
            {
                _geometry1 = null;
                _geometry2 = null;
            }
        }
Beispiel #41
0
        private void getPolylinePolygonOverlay(Polyline polyline, Polygon polygon, OverlayType operation, GeometryCollection result, bool performSnapping, bool inverseArgs)
        {
            try
            {
                _geometry1 = polyline;
                _geometry2 = polygon;
                bool isValid = true;

                try
                {
                    init(performSnapping);

                    PlanarGraph graph = PlanarGraph.Build(_geometry1, _geometry2);

                    //building polygon
                    foreach (PlanarGraphNode node in graph.Nodes)
                        node.Layout = PlanarGraphNode.NodeLayout.Unknown;

                    foreach (PlanarGraphEdge edge in graph.Edges)
                    {
                        edge.IsVisited = false;
                        edge.Enabled = edge.Label.UsedByObject2;
                    }
                    Polygon pg = graph.BuildPolygon(true, false);

                    // build results:
                    // point
                    foreach (PlanarGraphNode node in graph.Nodes)
                        node.Enabled = isNodeEnabled(node, operation, polyline, pg, inverseArgs);

                    List<PointD> points = graph.BuildPoints();

                    foreach (PointD p in points)
                        result.Add(p);

                    // polyline
                    foreach (PlanarGraphEdge edge in graph.Edges)
                    {
                        edge.IsVisited = false;
                        edge.Enabled = isLinearEdgeEnabled(edge, operation, pg, inverseArgs);
                    }

                    Polyline pl = graph.BuildPolyline(false, false);
                    if (pl.CoordinateCount > 0)
                        result.Add(pl);

                    // landfill has been constructed, it may be added to the result
                    if (operation == OverlayType.SymmetricDifference || operation == OverlayType.Union ||
                        (operation == OverlayType.Difference && inverseArgs))
                        if(pg.CoordinateCount > 0)
                            result.Add(pg);

                    for (int i = 0; i < result.Count; i++)
                    {
                        IGeometry g = translateGeometry(result[i], _translationCenter.X, _translationCenter.Y);
                        if (g is PointD)
                            result[i] = g;
                    }
                }
                catch (TopologyException)
                {
                    if (!performSnapping)
                        isValid = false;
                    else
                        throw new InvalidOperationException("Unable to complete operation correctly with this value of tolerance (PlanimertyAlgorithms.Tolerance)");
                }

                if (isValid)
                    return;
                else
                {
                    //overlay has not been calculated.
                    // it may be possible to calculate the overlay aligned to the grid
                    getPolylinePolygonOverlay(polyline, polygon, operation, result, true, inverseArgs);
                    return;
                }
            }
            finally
            {
                _geometry1 = null;
                _geometry2 = null;
            }
        }
Beispiel #42
0
 private void addPolyline(PlanarGraph graph, OverlayType operation, Polygon p1, Polygon p2, Collection<IGeometry> collection)
 {
     foreach (PlanarGraphEdge edge in graph.Edges)
     {
         edge.IsVisited = false;
         edge.Enabled = isLinearEdgeEnabled(edge, operation, p1, p2);
     }
     Polyline polyline = graph.BuildPolyline(false, false);
     if (polyline.CoordinateCount > 0)
         collection.Add(polyline);
 }
Beispiel #43
0
        //private void getPointPointOverlay(PointD p1, PointD p2, OverlayType operation, ICollection<IGeometry> result)
        //{
        //    bool isEqual = p1.Equals(p2);
        //    switch (operation)
        //    {
        //        case OverlayType.Intersection:
        //            if (isEqual)
        //                result.Add((IGeometry)p1.Clone());
        //            break;
        //        case OverlayType.Union:
        //            result.Add((IGeometry)p1.Clone());
        //            if (!isEqual)
        //                result.Add((IGeometry)p2.Clone());
        //            break;
        //        case OverlayType.Difference:
        //            if (!isEqual)
        //                result.Add((IGeometry)p1.Clone());
        //            break;
        //        case OverlayType.SymmetricDifference:
        //            if (!isEqual)
        //            {
        //                result.Add((IGeometry)p1.Clone());
        //                result.Add((IGeometry)p2.Clone());
        //            }
        //            break;
        //    }
        //}

        private void getPointPointOverlay(MultiPoint mp1, MultiPoint mp2, OverlayType operation, ICollection<IGeometry> result)
        {
            PlanarGraph graph = PlanarGraph.Build(mp1, mp2);

            switch (operation)
            {
                case OverlayType.Intersection:
                    foreach (PlanarGraphNode node in graph.Nodes)
                        if (node.Label.UsedByObject1 && node.Label.UsedByObject2)
                            result.Add(new PointD(node.Point));
                    break;
                case OverlayType.Union:
                    foreach (PlanarGraphNode node in graph.Nodes)
                        result.Add(new PointD(node.Point));
                    break;
                case OverlayType.Difference:
                    foreach (PlanarGraphNode node in graph.Nodes)
                        if (node.Label.UsedByObject1 && !node.Label.UsedByObject2)
                            result.Add(new PointD(node.Point));
                    break;
                case OverlayType.SymmetricDifference:
                    foreach (PlanarGraphNode node in graph.Nodes)
                        if (node.Label.UsedByObject1 ^ node.Label.UsedByObject2)
                            result.Add(new PointD(node.Point));
                    break;
            }
        }
Beispiel #44
0
 public BalloonStateUpdateMessage(string balloonID, OverlayType overlayType, Colour bgColor, int votes)
     : base(MessageType.BalloonStateUpdate, Tag, balloonID)
 {
     m_overlayType = overlayType;
     m_bgColor = bgColor;
     m_votes = votes;
 }
Beispiel #45
0
		private static void SetOverlay(IDicomAttributeProvider dataset, int overlayIndex, bool[] overlayData, OverlayType type, Point origin, int bitPosition, bool bigEndian)
		{
			DicomOverlayTestHelper.AddOverlayPlane(dataset, overlayIndex, overlayData, type, origin, bitPosition, bigEndian);
		}
        public void SetVisibility(OverlayType type, bool visible)
        {
            if (!_areaRenderer)
                RestartOverlay();

            switch (type)
            {
                case OverlayType.AREA:
                    _areaRenderer.enabled = visible;
                    break;
                case OverlayType.DERIV:
                    _derivRenderer.enabled = visible;
                    break;
                case OverlayType.COEFF:
                     _coeffRenderer.enabled = visible;
                    break;
            }

            bool anyVisible = AnyVisible();
            for (int i = 0; i < _markingRenderers.Count; i++)
            {
                _markingRenderers[i].enabled = anyVisible;
                if (i > _numGridLines)
                    _markingRenderers[i].enabled = false;
            }
        }
 public bool IsVisible(OverlayType type)
 {
     switch (type)
     {
         case OverlayType.AREA:
             return (_areaRenderer != null) ? _areaRenderer.enabled : false;
         case OverlayType.DERIV:
             return (_derivRenderer != null) ? _derivRenderer.enabled : false;
         case OverlayType.COEFF:
             return (_coeffRenderer != null) ? _coeffRenderer.enabled : false;
         default:
             return false;
     }
 }
Beispiel #48
0
		private OverlayPlaneType(OverlayType type, string description)
		{
			this.OverlayType = type;
			this.Description = description;
		}
Beispiel #49
0
 private void addPolygon(PlanarGraph graph, OverlayType operation, Polygon p1, Polygon p2, Collection<IGeometry> collection)
 {
     foreach (PlanarGraphEdge edge in graph.Edges)
     {
         edge.IsVisited = false;
         edge.Enabled = isAreaEdgeEnabled(edge, operation, p1, p2);
     }
     foreach (PlanarGraphNode node in graph.Nodes)
         node.Layout = PlanarGraphNode.NodeLayout.Unknown;
     Polygon polygon = graph.BuildPolygon(false, false);
     if (polygon.CoordinateCount > 0)
         collection.Add(polygon);
 }
Beispiel #50
0
        private bool isLinearEdgeEnabled(PlanarGraphEdge edge, OverlayType operation, Polygon p1, Polygon p2)
        {
            if (isAreaEdgeEnabled(edge, operation, p1, p2))
                return false;

            switch (operation)
            {
                case OverlayType.Intersection:
                    return edge.Label.UsedByObject1 && edge.Label.UsedByObject2;
                case OverlayType.Union:
                    return false;
                case OverlayType.Difference:
                    return false;
                case OverlayType.SymmetricDifference:
                    return false;
            }

            return false;
        }
Beispiel #51
0
        private void getPolygonPolygonOverlay(Polygon polygon1, Polygon polygon2, OverlayType operation, GeometryCollection result, bool performSnapping)
        {
            try
            {
                _geometry1 = polygon1;
                _geometry2 = polygon2;
                bool isValid = true;

                try
                {
                    init(performSnapping);

                    PlanarGraph graph = PlanarGraph.Build(_geometry1, _geometry2);

                    // build the first facility
                    foreach (PlanarGraphNode node in graph.Nodes)
                        node.Layout = PlanarGraphNode.NodeLayout.Unknown;

                    foreach (PlanarGraphEdge edge in graph.Edges)
                    {
                        edge.IsVisited = false;
                        edge.Enabled = edge.Label.UsedByObject1;
                    }
                    Polygon p1 = graph.BuildPolygon(true, false);

                    // building a second facility
                    foreach (PlanarGraphNode node in graph.Nodes)
                        node.Layout = PlanarGraphNode.NodeLayout.Unknown;

                    foreach (PlanarGraphEdge edge in graph.Edges)
                    {
                        edge.IsVisited = false;
                        edge.Enabled = edge.Label.UsedByObject2;
                    }
                    Polygon p2 = graph.BuildPolygon(false, true);

                    // build results:
                    // point
                    if (operation == OverlayType.Intersection)
                        addPoints(graph, operation, p1, p2, result);

                    // polyline
                    if (operation == OverlayType.Intersection)
                        addPolyline(graph, operation, p1, p2, result);

                    // ground
                    addPolygon(graph, operation, p1, p2, result);

                    for (int i = 0; i < result.Count; i++)
                    {
                        IGeometry g = translateGeometry(result[i], _translationCenter.X, _translationCenter.Y);
                        if (g is PointD)
                            result[i] = g;
                    }
                }
                catch (TopologyException)
                {
                    if (!performSnapping)
                        isValid = false;
                    else
                        throw new InvalidOperationException("Unable to complete operation correctly with this value of tolerance (PlanimertyAlgorithms.Tolerance)");
                }

                if (isValid)
                    return;
                else
                {
                    // overlay has not been calculated.
                    // it may be possible to calculate the overlay aligned to the grid
                    getPolygonPolygonOverlay(polygon1, polygon2, operation, result, true);
                    return;
                }
            }
            finally
            {
                _geometry1 = null;
                _geometry2 = null;
            }
        }
Beispiel #52
0
        private bool isAreaEdgeEnabled(PlanarGraphEdge edge, OverlayType operation, Polygon p1, Polygon p2)
        {
            bool usebyPolygon1 = edge.Label.UsedByObject1;
            bool usebyPolygon2 = edge.Label.UsedByObject2;

            switch (operation)
            {
                case OverlayType.Intersection:
                    if (usebyPolygon1 && usebyPolygon2 && edge.OrientationInObject1 == edge.OrientationInObject2)
                        return true;

                    if ((usebyPolygon1 ^ usebyPolygon2))
                        if (usebyPolygon1)
                        {
                            if (p2.ContainsPoint(edge.CenterPoint()))
                                return true;
                        }
                        else
                        {
                            if (p1.ContainsPoint(edge.CenterPoint()))
                                return true;
                        }
                    break;
                case OverlayType.Union:
                    if (usebyPolygon1 && usebyPolygon2 && edge.OrientationInObject1 == edge.OrientationInObject2)
                        return true;

                    if ((usebyPolygon1 ^ usebyPolygon2))
                        if (usebyPolygon1)
                        {
                            if (!p2.ContainsPoint(edge.CenterPoint()))
                                return true;
                        }
                        else
                        {
                            if (!p1.ContainsPoint(edge.CenterPoint()))
                                return true;
                        }
                    break;
                case OverlayType.Difference:
                    if (usebyPolygon1 && usebyPolygon2 && edge.OrientationInObject1 != edge.OrientationInObject2)
                        return true;

                    if ((usebyPolygon1 ^ usebyPolygon2))
                        if (usebyPolygon1)
                        {
                            if (!p2.ContainsPoint(edge.CenterPoint()))
                                return true;
                        }
                        else
                        {
                            if (p1.ContainsPoint(edge.CenterPoint()))
                                return true;
                        }
                    break;
                case OverlayType.SymmetricDifference:
                    if ((usebyPolygon1 ^ usebyPolygon2))
                        return true;
                    break;
            }

            return false;
        }
Beispiel #53
0
        private void getPointPolygonOverlay(MultiPoint mp, Polygon polygon, OverlayType operation, GeometryCollection result, bool performSnapping, bool inverseArgs)
        {
            try
            {
                _geometry1 = mp;
                _geometry2 = polygon;
                bool isValid = true;

                try
                {
                    init(performSnapping);

                    PlanarGraph graph = PlanarGraph.Build(_geometry1, _geometry2);

                    // duration test of the point inside the polygon to "collect" the original ground
                    foreach (PlanarGraphEdge edge in graph.Edges)
                    {
                        edge.IsVisited = false;
                        edge.Enabled = edge.Label.UsedByObject2;
                    }

                    Polygon pg = graph.BuildPolygon(inverseArgs, !inverseArgs);

                    // classify edges and nodes
                    foreach (PlanarGraphEdge edge in graph.Edges)
                    {
                        edge.IsVisited = false;
                        switch (operation)
                        {
                            case OverlayType.Intersection:
                                edge.Enabled = false;
                                break;
                            case OverlayType.Union:
                                edge.Enabled = edge.Label.UsedByObject2;
                                break;
                            case OverlayType.Difference:
                                edge.Enabled = inverseArgs ? edge.Label.UsedByObject2 : false;
                                break;
                            case OverlayType.SymmetricDifference:
                                edge.Enabled = edge.Label.UsedByObject2;
                                break;
                        }
                    }

                    foreach (PlanarGraphNode node in graph.Nodes)
                    {
                        bool hasEnabledEdges = false;
                        foreach (PlanarGraphEdge edge in node.IncidentEdges)
                            if (edge.Enabled)
                            {
                                hasEnabledEdges = true;
                                break;
                            }
                        if (hasEnabledEdges)
                            node.Enabled = false;
                        else
                        {
                            switch (operation)
                            {
                                case OverlayType.Intersection:
                                    node.Enabled = (pg.ContainsPoint(node.Point) && !node.Label.UsedByObject2) ||
                                                   (node.Label.UsedByObject2 && node.Label.UsedByObject1);
                                    break;
                                case OverlayType.Union:
                                    node.Enabled = !pg.ContainsPoint(node.Point) && !node.Label.UsedByObject2;
                                    break;
                                case OverlayType.Difference:
                                    node.Enabled = inverseArgs ? false : !pg.ContainsPoint(node.Point) && !node.Label.UsedByObject2;
                                    break;
                                case OverlayType.SymmetricDifference:
                                    node.Enabled = !pg.ContainsPoint(node.Point) && !node.Label.UsedByObject2;
                                    break;
                            }
                        }
                    }

                    // build results:
                    // point
                    List<PointD> points = graph.BuildPoints();

                    foreach (PointD p in points)
                        result.Add(p);

                    // The landfill has been constructed to assess the position of the point.
                    // But it must be added to the result only in the case of the calculation of association,
                    // symmetric difference and the difference, which is a decrease.
                    if (operation == OverlayType.Union || operation == OverlayType.SymmetricDifference ||
                       (operation == OverlayType.Difference && inverseArgs))
                    {
                        if (pg.CoordinateCount > 0)
                            result.Add(pg);
                    }

                    for (int i = 0; i < result.Count; i++)
                    {
                        IGeometry g = translateGeometry(result[i], _translationCenter.X, _translationCenter.Y);
                        if (g is PointD)
                            result[i] = g;
                    }
                }
                catch (TopologyException)
                {
                    if (!performSnapping)
                        isValid = false;
                    else
                        throw new InvalidOperationException("Unable to complete operation correctly with this value of tolerance (PlanimertyAlgorithms.Tolerance)");
                }

                if (isValid)
                    return;
                else
                {
                    // overlay has not been calculated.
                    // it may be possible to calculate the overlay aligned to the grid
                    getPointPolygonOverlay(mp, polygon, operation, result, true, inverseArgs);
                    return;
                }
            }
            finally
            {
                _geometry1 = null;
                _geometry2 = null;
            }
        }
Beispiel #54
0
        private bool isNodeEnabled(PlanarGraphNode node, OverlayType operation, Polyline polyline, Polygon polygon, bool inverseArgs)
        {
            switch (operation)
            {
                case OverlayType.Intersection:
                    if (!node.Label.UsedByObject1 || !node.Label.UsedByObject2)
                        return false;
                    break;
                case OverlayType.Union:
                    return false;
                case OverlayType.Difference:
                case OverlayType.SymmetricDifference:
                    return false;
            }
            bool hasEnabledEdges = false;
            foreach (PlanarGraphEdge edge in node.IncidentEdges)
                if (isAreaEdgeEnabled(edge, operation, polygon, inverseArgs) ||
                    isLinearEdgeEnabled(edge, operation, polygon, inverseArgs))
                {
                    hasEnabledEdges = true;
                    break;
                }

            return !hasEnabledEdges;
        }
Beispiel #55
0
        private GeometryCollection calculateOverlay(IGeometry geometry1, IGeometry geometry2, OverlayType operation, bool performSnapping)
        {
            GeometryCollection result = new GeometryCollection();

            if (geometry1 == null && geometry2 == null)
                return result;

            if (geometry2 == null)
            {
                if (operation != OverlayType.Intersection)
                    result.Add((IGeometry)geometry1.Clone());

                return result;
            }

            if (geometry1 == null)
            {
                if (operation == OverlayType.Intersection || operation == OverlayType.Difference)
                    return result;
                result.Add((IGeometry)geometry2.Clone());

                return result;
            }

            // If the bounding rectangles do not intersect, the result of all operations can be obtained easily
            BoundingRectangle br1 = geometry1.GetBoundingRectangle();
            BoundingRectangle br2 = geometry2.GetBoundingRectangle();
            if(!br1.IsEmpty())
                br1.Grow(PlanimetryAlgorithms.Tolerance);
            if (!br2.IsEmpty())
                br2.Grow(PlanimetryAlgorithms.Tolerance);

            if (!br1.Intersects(br2))
                return calculateNonIntersectedObjectsOverlay(geometry1, geometry2, operation, performSnapping);

            // easier to convert the point-to-multipoint to preserve generality
            if (geometry1 is PointD)
            {
                PointD p = (PointD)geometry1.Clone();
                geometry1 = new MultiPoint(new ICoordinate[] { p.Coordinate });
            }

            if (geometry2 is PointD)
            {
                PointD p = (PointD)geometry2.Clone();
                geometry2 = new MultiPoint(new ICoordinate[] { p.Coordinate });
            }

            int minDim = Math.Min((int)geometry1.Dimension, (int)geometry2.Dimension);
            int maxDim = Math.Max((int)geometry1.Dimension, (int)geometry2.Dimension);

            // overlay calculation points
            if (minDim == 0 && maxDim == 0)
                getPointPointOverlay((MultiPoint)geometry1, (MultiPoint)geometry2, operation, result);

            // calculation overlay polylines
            if (minDim == 1 && maxDim == 1)
                getPolylinePolylineOverlay((Polyline)geometry1, (Polyline)geometry2, operation, result, false);

            // calculation of polygon overlay
            if (minDim == 2 && maxDim == 2)
                getPolygonPolygonOverlay((Polygon)geometry1, (Polygon)geometry2, operation, result, false);

            // calculation overlay points and polylines
            if (minDim == 0 && maxDim == 1)
            {
                if (geometry1 is MultiPoint)
                    getPointPolylineOverlay((MultiPoint)geometry1, (Polyline)geometry2, operation, result, false, false);
                else
                    getPointPolylineOverlay((MultiPoint)geometry2, (Polyline)geometry1, operation, result, false, true);
            }

            // calculation point and polygon overlay
            if (minDim == 0 && maxDim == 2)
            {
                if (geometry1 is MultiPoint)
                    getPointPolygonOverlay((MultiPoint)geometry1, (Polygon)geometry2, operation, result, false, false);
                else
                    getPointPolygonOverlay((MultiPoint)geometry2, (Polygon)geometry1, operation, result, false, true);
            }

            // calculation overlay polylines and polygons
            if (minDim == 1 && maxDim == 2)
            {
                if (geometry1 is Polyline)
                    getPolylinePolygonOverlay((Polyline)geometry1, (Polygon)geometry2, operation, result, false, false);
                else
                    getPolylinePolygonOverlay((Polyline)geometry2, (Polygon)geometry1, operation, result, false, true);
            }

            return result;
        }
Beispiel #56
0
        private bool isLinearEdgeEnabled(PlanarGraphEdge edge, OverlayType operation, Polygon polygon, bool inverseArgs)
        {
            if (isAreaEdgeEnabled(edge, operation, polygon, inverseArgs))
                return false;

            switch (operation)
            {
                case OverlayType.Intersection:
                    return edge.Label.UsedByObject1 && (edge.Label.UsedByObject2 || polygon.ContainsPoint(edge.CenterPoint()));
                case OverlayType.Union:
                    return edge.Label.UsedByObject1 && !polygon.ContainsPoint(edge.CenterPoint());
                case OverlayType.Difference:
                    return inverseArgs ? false : 
                                         edge.Label.UsedByObject1 && 
                                         !polygon.ContainsPoint(edge.CenterPoint()) &&
                                         !edge.Label.UsedByObject2;
                case OverlayType.SymmetricDifference:
                    return edge.Label.UsedByObject1 &&
                           !polygon.ContainsPoint(edge.CenterPoint()) &&
                           !edge.Label.UsedByObject2;
            }

            return false;
        }
		/// <summary>
		/// Sets an overlay plane module on the given dataset using the OverlayData attribute.
		/// </summary>
		/// <param name="dataset">The dataset.</param>
		/// <param name="overlayIndex">The index of the overlay plane.</param>
		/// <param name="overlayData">The overlay data.</param>
		/// <param name="type">The overlay type.</param>
		/// <param name="origin">The overlay origin per frame.</param>
		/// <param name="rows">The number of rows per frame.</param>
		/// <param name="columns">The number of columns per frame.</param>
		/// <param name="frames">The number of frames. If NULL, will not set multiframe attributes.</param>
		/// <param name="frameOrigin">The number of the image frame that matches the first overlay frame. If NULL, the attribute is not included and the reader is supposed to assume 1.</param>
		/// <param name="bigEndian">Whether or not the dataset is big endian.</param>
		/// <param name="useOW">Whether or not OverlayData should have a VR of OW.</param>
		/// <exception cref="ArgumentException">Thrown if input values are inconsistent.</exception>
		public static void AddOverlayPlane(IDicomAttributeProvider dataset, int overlayIndex, bool[] overlayData, OverlayType type, Point origin, int rows, int columns, int? frames, int? frameOrigin, bool bigEndian, bool useOW)
		{
			// sanity check
			Platform.CheckForNullReference(dataset, "dataset");
			Platform.CheckForNullReference(overlayData, "overlayData");
			Platform.CheckArgumentRange(overlayIndex, 0, 15, "overlayIndex");
			Platform.CheckTrue(rows*columns*frames.GetValueOrDefault(1) == overlayData.Length, "overlayData must have length equal to rows*columns*frames");

			uint tagOffset = ((uint) overlayIndex)*2*0x10000;

			// set basic attributes
			dataset[tagOffset + DicomTags.OverlayRows].SetInt32(0, rows);
			dataset[tagOffset + DicomTags.OverlayColumns].SetInt32(0, columns);
			dataset[tagOffset + DicomTags.OverlayType].SetString(0, type.ToString());
			dataset[tagOffset + DicomTags.OverlayOrigin].SetStringValue(string.Format(@"{0}\{1}", origin.X, origin.Y));
			dataset[tagOffset + DicomTags.OverlayBitsAllocated].SetInt32(0, 1);
			dataset[tagOffset + DicomTags.OverlayBitPosition].SetInt32(0, 0);

			// set multiframe attributes
			if (frames.HasValue)
			{
				dataset[tagOffset + DicomTags.NumberOfFramesInOverlay].SetInt32(0, frames.Value);
				if (frameOrigin.HasValue)
					dataset[tagOffset + DicomTags.ImageFrameOrigin].SetInt32(0, frameOrigin.Value);
				else
					dataset[tagOffset + DicomTags.ImageFrameOrigin].SetEmptyValue();
			}
			else
			{
				dataset[tagOffset + DicomTags.NumberOfFramesInOverlay].SetEmptyValue();
				dataset[tagOffset + DicomTags.ImageFrameOrigin].SetEmptyValue();
			}

			// set overlay data by bit packing
			var packedBitsLength = (int) Math.Ceiling(overlayData.Length/8f);
			var packedBits = new byte[packedBitsLength + (packedBitsLength%2)];
			if (useOW)
			{
				var highByte = bigEndian ? 0 : 1; // in a big endian word, the high byte is first
				var cursor = 0;
				ushort window = 0;
				for (int n = 0; n < overlayData.Length; n++)
				{
					window = (ushort) (((window >> 1) & 0x007FFF) | (overlayData[n] ? 0x008000 : 0x000000));
					if ((n + 1)%16 == 0)
					{
						packedBits[cursor + highByte] = (byte) ((window >> 8) & 0x00FF);
						packedBits[cursor + 1 - highByte] = (byte) (window & 0x00FF);
						cursor += 2;
						window = 0;
					}
				}

				// flush the last window
				if (cursor == packedBits.Length - 1)
				{
					packedBits[cursor + highByte] = (byte) ((window >> 8) & 0x00FF);
					packedBits[cursor + 1 - highByte] = (byte) (window & 0x00FF);
				}
			}
			else
			{
				var cursor = 0;
				byte window = 0;
				for (int n = 0; n < overlayData.Length; n++)
				{
					window = (byte) (((window >> 1) & 0x007F) | (overlayData[n] ? 0x0080 : 0x0000));
					if ((n + 1)%8 == 0)
					{
						packedBits[cursor++] = window;
						window = 0;
					}
				}

				// flush the last window
				if (cursor == packedBits.Length - 1)
					packedBits[cursor] = window;
			}
			dataset[FixVR(tagOffset + DicomTags.OverlayData, useOW ? DicomVr.OWvr : DicomVr.OBvr)].Values = packedBits;
		}
Beispiel #58
0
        private bool isAreaEdgeEnabled(PlanarGraphEdge edge, OverlayType operation, Polygon polygon, bool inverseArgs)
        {
            bool usebyPolyline = edge.Label.UsedByObject1;
            bool usebyPolygon = edge.Label.UsedByObject2;

            switch (operation)
            {
                case OverlayType.Intersection:
                    return false;
                case OverlayType.Union:
                    if (usebyPolygon) return true;
                    break;
                case OverlayType.Difference:
                    return inverseArgs;
                case OverlayType.SymmetricDifference:
                    if (usebyPolygon) return true;
                    break;
            }

            return false;
        }
		/// <summary>
		/// Sets an overlay plane module on the given dataset using the OverlayData attribute.
		/// </summary>
		/// <param name="dataset">The dataset.</param>
		/// <param name="overlayIndex">The index of the overlay plane.</param>
		/// <param name="overlayData">The overlay data.</param>
		/// <param name="type">The overlay type.</param>
		/// <param name="origin">The overlay origin.</param>
		/// <param name="rows">The number of rows.</param>
		/// <param name="columns">The number of columns.</param>
		/// <param name="bigEndian">Whether or not the dataset is big endian.</param>
		/// <param name="useOW">Whether or not OverlayData should have a VR of OW.</param>
		/// <exception cref="ArgumentException">Thrown if input values are inconsistent.</exception>
		public static void AddOverlayPlane(IDicomAttributeProvider dataset, int overlayIndex, bool[] overlayData, OverlayType type, Point origin, int rows, int columns, bool bigEndian, bool useOW)
		{
			AddOverlayPlane(dataset, overlayIndex, overlayData, type, origin, rows, columns, null, null, bigEndian, useOW);
		}
Beispiel #60
0
        /// <summary>
        /// Calculates an overlay of two geometries.
        /// </summary>
        /// <param name="geometry1">First geometry</param>
        /// <param name="geometry2">Second geometry</param>
        /// <param name="operation">Overlay type</param>
        /// <returns>An overlay of two geometries</returns>
        public GeometryCollection CalculateOverlay(IGeometry geometry1, IGeometry geometry2, OverlayType operation)
        {
            if (!(geometry1 is Polygon))
                if (!(geometry1 is Polyline))
                    if (!(geometry1 is PointD))
                        if (!(geometry1 is MultiPoint))
                            throw new NotSupportedException(string.Format("Overlay calculation for \"{0}\" is not supported", geometry1.GetType().FullName));

            if (!(geometry2 is Polygon))
                if (!(geometry2 is Polyline))
                    if (!(geometry2 is PointD))
                        if (!(geometry2 is MultiPoint))
                            throw new NotSupportedException(string.Format("Overlay calculation for \"{0}\" is not supported", geometry2.GetType().FullName));

            return calculateOverlay(geometry1, geometry2, operation, false);
        }