private static aim_dotnet.IGeometricShape Create2DGeoShape(RoiGraphic roiGraphic, string imageUID, int frameNumber) { Platform.CheckForEmptyString(imageUID, "imageUID"); aim_dotnet.IGeometricShape geoShape = null; var roi = roiGraphic.Roi; if (roi is EllipticalRoi) { var ellipticalRoi = roi as EllipticalRoi; Platform.CheckForNullReference(ellipticalRoi, "ellipticalRoi"); var ellipseShape = new aim_dotnet.Ellipse(); ellipseShape.EllipseCollection = new List<aim_dotnet.ISpatialCoordinate>(); ellipseShape.EllipseCollection.Add( Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Left, ellipticalRoi.BoundingBox.Top + ellipticalRoi.BoundingBox.Height/2, imageUID, frameNumber, 0)); ellipseShape.EllipseCollection.Add( Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Right, ellipticalRoi.BoundingBox.Top + ellipticalRoi.BoundingBox.Height/2, imageUID, frameNumber, 1)); ellipseShape.EllipseCollection.Add( Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Left + ellipticalRoi.BoundingBox.Width/2, ellipticalRoi.BoundingBox.Top, imageUID, frameNumber, 2)); ellipseShape.EllipseCollection.Add( Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Left + ellipticalRoi.BoundingBox.Width/2, ellipticalRoi.BoundingBox.Bottom, imageUID, frameNumber, 3)); geoShape = ellipseShape; } else if (roi is PolygonalRoi) { var polygonalRoi = roi as PolygonalRoi; Platform.CheckForNullReference(polygonalRoi, "polygonalRoi"); var polylineShape = new aim_dotnet.Polyline(); polylineShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>(); polylineShape.IsIncludeFlag = true; for (var i = 0; i < polygonalRoi.Polygon.Vertices.Count; i++) { polylineShape.SpatialCoordinateCollection.Add( Create2DSpatialCoordinate(polygonalRoi.Polygon.Vertices[i].X, polygonalRoi.Polygon.Vertices[i].Y, imageUID, frameNumber, i)); } if (polygonalRoi.Polygon.Vertices.Count > 0 && polygonalRoi.Polygon.Vertices[polygonalRoi.Polygon.Vertices.Count - 1] != polygonalRoi.Polygon.Vertices[0]) { polylineShape.SpatialCoordinateCollection.Add( Create2DSpatialCoordinate(polygonalRoi.Polygon.Vertices[0].X, polygonalRoi.Polygon.Vertices[0].Y, imageUID, frameNumber, 0)); } geoShape = polylineShape; } else if (roi is ProtractorRoiInfo) { var protractorRoi = roi as ProtractorRoiInfo; Platform.CheckForNullReference(protractorRoi, "protractorRoi"); var multipointShape = new aim_dotnet.MultiPoint(); multipointShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>(); multipointShape.IsIncludeFlag = true; for (var i = 0; i < protractorRoi.Points.Count; i++) { multipointShape.SpatialCoordinateCollection.Add( Create2DSpatialCoordinate(protractorRoi.Points[i].X, protractorRoi.Points[i].Y, imageUID, frameNumber, i)); } geoShape = multipointShape; } else if (roi is LinearRoi) { var linearRoi = roi as LinearRoi; Platform.CheckForNullReference(linearRoi, "linearRoi"); var multipointShape = new aim_dotnet.MultiPoint(); multipointShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>(); multipointShape.IsIncludeFlag = true; for (var i = 0; i < linearRoi.Points.Count; i++) { multipointShape.SpatialCoordinateCollection.Add( Create2DSpatialCoordinate(linearRoi.Points[i].X, linearRoi.Points[i].Y, imageUID, frameNumber, i)); } geoShape = multipointShape; } else if (roi is RectangularRoi) { var rectangularRoi = roi as RectangularRoi; Platform.CheckForNullReference(rectangularRoi, "rectangularRoi"); var polylineShape = new aim_dotnet.Polyline(); polylineShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>(); // Top Left polylineShape.SpatialCoordinateCollection.Add( Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Left, rectangularRoi.BoundingBox.Top, imageUID, frameNumber, 0)); // Top Right polylineShape.SpatialCoordinateCollection.Add( Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Right, rectangularRoi.BoundingBox.Top, imageUID, frameNumber, 1)); // Buttom Right polylineShape.SpatialCoordinateCollection.Add( Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Right, rectangularRoi.BoundingBox.Bottom, imageUID, frameNumber, 2)); // Buttom Left polylineShape.SpatialCoordinateCollection.Add( Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Left, rectangularRoi.BoundingBox.Bottom, imageUID, frameNumber, 3)); geoShape = polylineShape; } else Platform.Log(LogLevel.Error, "AIMHelper.CreateGeoShape. Unhandled ROI type: " + roi.GetType().FullName); return geoShape; }
private static aim_dotnet.IGeometricShape Create2DGeoShape(RoiGraphic roiGraphic, string imageUID, int frameNumber) { Platform.CheckForEmptyString(imageUID, "imageUID"); aim_dotnet.IGeometricShape geoShape = null; Roi roi = roiGraphic.Roi; //Platform.CheckTrue(graphics.CoordinateSystem == CoordinateSystem.Source, "Source Coordinate System"); if (roi is EllipticalRoi) { EllipticalRoi ellipticalRoi = roi as EllipticalRoi; Platform.CheckForNullReference(ellipticalRoi, "ellipticalRoi"); aim_dotnet.Ellipse ellipseShape = new aim_dotnet.Ellipse(); ellipseShape.EllipseCollection = new List<aim_dotnet.ISpatialCoordinate>(); // Bounding box coordinates to DICOM ellipse conversion. // Since ellipse's bounding box is not rotated, we just need to find major axis // and store the center points of bounding box' side as ellipse vertices. // if (ellipseGraphics.Width >= ellipseGraphics.Height) { // Horizontal major axis points ellipseShape.EllipseCollection.Add( Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Left, ellipticalRoi.BoundingBox.Top + ellipticalRoi.BoundingBox.Height/2, imageUID, frameNumber, 0)); ellipseShape.EllipseCollection.Add( Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Right, ellipticalRoi.BoundingBox.Top + ellipticalRoi.BoundingBox.Height/2, imageUID, frameNumber, 1)); // Vertical minor axis points ellipseShape.EllipseCollection.Add( Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Left + ellipticalRoi.BoundingBox.Width/2, ellipticalRoi.BoundingBox.Top, imageUID, frameNumber, 2)); ellipseShape.EllipseCollection.Add( Create2DSpatialCoordinate(ellipticalRoi.BoundingBox.Left + ellipticalRoi.BoundingBox.Width/2, ellipticalRoi.BoundingBox.Bottom, imageUID, frameNumber, 3)); } //else //{ // // Vertical major axis // ellipseShape.EllipseCollection.Add(Create2DSpatialCoordinate( // ellipseGraphics.Left + ellipseGraphics.Width/2, ellipseGraphics.Top, imageUID, frameNumber, 0)); // ellipseShape.EllipseCollection.Add(Create2DSpatialCoordinate( // ellipseGraphics.Left + ellipseGraphics.Width/2, ellipseGraphics.Bottom, imageUID, frameNumber, 1)); // // Horizontal minor axis // ellipseShape.EllipseCollection.Add(Create2DSpatialCoordinate( // ellipseGraphics.Left, ellipseGraphics.Top + ellipseGraphics.Height/2, imageUID, frameNumber, 2)); // ellipseShape.EllipseCollection.Add(Create2DSpatialCoordinate( // ellipseGraphics.Right, ellipseGraphics.Top + ellipseGraphics.Height/2, imageUID, frameNumber, 3)); //} geoShape = ellipseShape; } else if (roi is PolygonalRoi) { PolygonalRoi polygonalRoi = roi as PolygonalRoi; Platform.CheckForNullReference(polygonalRoi, "polygonalRoi"); //if (!polygonalRoi.IsClosed) //{ // Platform.Log(LogLevel.Error, "Object state error: Given polygon is not closed"); // return null; //} aim_dotnet.Polyline polylineShape = new aim_dotnet.Polyline(); polylineShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>(); polylineShape.IsIncludeFlag = true; for (int i = 0; i < polygonalRoi.Polygon.Vertices.Count; i++) { polylineShape.SpatialCoordinateCollection.Add( Create2DSpatialCoordinate(polygonalRoi.Polygon.Vertices[i].X, polygonalRoi.Polygon.Vertices[i].Y, imageUID, frameNumber, i)); } geoShape = polylineShape; } else if (roi is ProtractorRoiInfo) { ProtractorRoiInfo protractorRoi = roi as ProtractorRoiInfo; Platform.CheckForNullReference(protractorRoi, "protractorRoi"); aim_dotnet.MultiPoint multipointShape = new aim_dotnet.MultiPoint(); multipointShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>(); multipointShape.IsIncludeFlag = true; for (int i = 0; i < protractorRoi.Points.Count; i++) { multipointShape.SpatialCoordinateCollection.Add( Create2DSpatialCoordinate(protractorRoi.Points[i].X, protractorRoi.Points[i].Y, imageUID, frameNumber, i)); } geoShape = multipointShape; } else if (roi is LinearRoi) { LinearRoi linearRoi = roi as LinearRoi; Platform.CheckForNullReference(linearRoi, "linearRoi"); aim_dotnet.MultiPoint multipointShape = new aim_dotnet.MultiPoint(); multipointShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>(); multipointShape.IsIncludeFlag = true; for (int i = 0; i < linearRoi.Points.Count; i++) { multipointShape.SpatialCoordinateCollection.Add( Create2DSpatialCoordinate(linearRoi.Points[i].X, linearRoi.Points[i].Y, imageUID, frameNumber, i)); } geoShape = multipointShape; } //else if (roi is PolygonalRoi) //{ // PolygonalRoi polylineGraphics = roi as PolygonalRoi; // Platform.CheckForNullReference(polylineGraphics, "polylineGraphics"); // if (polylineGraphics.Polygon.CountVertices > 2 && // polylineGraphics.Polygon.Vertices[0] == polylineGraphics.Polygon.Vertices[polylineGraphics.Polygon.Vertices.Count - 1]) // { // // Closed polyline graphics // Polyline polylineShape = new Polyline(); // polylineShape.SpatialCoordinateCollection = new List<ISpatialCoordinate>(); // polylineShape.IsIncludeFlag = true; // for (int i = 0; i < polylineGraphics.Polygon.CountVertices - 1; i++) // no need for the end point - we will have implicitly closed Polyline // { // polylineShape.SpatialCoordinateCollection.Add( // Create2DSpatialCoordinate(polylineGraphics.Polygon.Vertices[i].X, polylineGraphics.Polygon.Vertices[i].Y, imageUID, frameNumber, i)); // } // geoShape = polylineShape; // } // else // { // MultiPoint multipointShape = new MultiPoint(); // multipointShape.SpatialCoordinateCollection = new List<ISpatialCoordinate>(); // multipointShape.IsIncludeFlag = true; // for (int i = 0; i < polylineGraphics.Polygon.CountVertices; i++) // { // multipointShape.SpatialCoordinateCollection.Add( // Create2DSpatialCoordinate(polylineGraphics.Polygon.Vertices[i].X, polylineGraphics.Polygon.Vertices[i].Y, imageUID, frameNumber, i)); // } // geoShape = multipointShape; // } //} else if (roi is RectangularRoi) { RectangularRoi rectangularRoi = roi as RectangularRoi; Platform.CheckForNullReference(rectangularRoi, "rectangularRoi"); aim_dotnet.Polyline polylineShape = new aim_dotnet.Polyline(); polylineShape.SpatialCoordinateCollection = new List<aim_dotnet.ISpatialCoordinate>(); // Top Left polylineShape.SpatialCoordinateCollection.Add( Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Left, rectangularRoi.BoundingBox.Top, imageUID, frameNumber, 0)); // Top Right polylineShape.SpatialCoordinateCollection.Add( Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Right, rectangularRoi.BoundingBox.Top, imageUID, frameNumber, 1)); // Buttom Right polylineShape.SpatialCoordinateCollection.Add( Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Right, rectangularRoi.BoundingBox.Bottom, imageUID, frameNumber, 2)); // Buttom Left polylineShape.SpatialCoordinateCollection.Add( Create2DSpatialCoordinate(rectangularRoi.BoundingBox.Left, rectangularRoi.BoundingBox.Bottom, imageUID, frameNumber, 3)); geoShape = polylineShape; } else Console.WriteLine("AIMHelper.CreateGeoShape. Unhandled ROI type: " + roi.GetType().FullName); return geoShape; }