ArcObjects Library Reference  

DrawUtilities

About the 3D multipatch examples Sample

[C#]

DrawUtilities.cs

using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Analyst3D;
using System;

namespace MultiPatchExamples
{
    public static class DrawUtilities
    {
        private static object _missing = Type.Missing;

        public static void DrawAxes(IGraphicsContainer3D axesGraphicsContainer3D)
        {
            const esriSimple3DLineStyle AxisStyle = esriSimple3DLineStyle.esriS3DLSTube;
            const double AxisWidth = 0.25;

            DrawAxis(axesGraphicsContainer3D, GeometryUtilities.ConstructPoint3D(-10, 0, 0), GeometryUtilities.ConstructPoint3D(10, 0, 0), ColorUtilities.GetColor(255, 0, 0), AxisStyle, AxisWidth);
            DrawAxis(axesGraphicsContainer3D, GeometryUtilities.ConstructPoint3D(0, -10, 0), GeometryUtilities.ConstructPoint3D(0, 10, 0), ColorUtilities.GetColor(0, 0, 255), AxisStyle, AxisWidth);
            DrawAxis(axesGraphicsContainer3D, GeometryUtilities.ConstructPoint3D(0, 0, -10), GeometryUtilities.ConstructPoint3D(0, 0, 10), ColorUtilities.GetColor(0, 255, 0), AxisStyle, AxisWidth);

            DrawEnd(axesGraphicsContainer3D, GeometryUtilities.ConstructPoint3D(10, 0, 0), GeometryUtilities.ConstructVector3D(0, 10, 0), 90, ColorUtilities.GetColor(255, 0, 0), 0.2 * AxisWidth);
            DrawEnd(axesGraphicsContainer3D, GeometryUtilities.ConstructPoint3D(0, 10, 0), GeometryUtilities.ConstructVector3D(10, 0, 0), -90, ColorUtilities.GetColor(0, 0, 255), 0.2 * AxisWidth);
            DrawEnd(axesGraphicsContainer3D, GeometryUtilities.ConstructPoint3D(0, 0, 10), null, 0, ColorUtilities.GetColor(0, 255, 0), 0.2 * AxisWidth);
        }

        private static void DrawAxis(IGraphicsContainer3D axesGraphicsContainer3D, IPoint axisFromPoint, IPoint axisToPoint, IColor axisColor, esriSimple3DLineStyle axisStyle, double axisWidth)
        {
            IPointCollection axisPointCollection = new PolylineClass();

            axisPointCollection.AddPoint(axisFromPoint, ref _missing, ref _missing);
            axisPointCollection.AddPoint(axisToPoint, ref _missing, ref _missing);

            GeometryUtilities.MakeZAware(axisPointCollection as IGeometry);

            GraphicsLayer3DUtilities.AddAxisToGraphicsLayer3D(axesGraphicsContainer3D, axisPointCollection as IGeometry, axisColor, axisStyle, axisWidth);
        }

        private static void DrawEnd(IGraphicsContainer3D endGraphicsContainer3D, IPoint endPoint, IVector3D axisOfRotationVector3D, double degreesOfRotation, IColor endColor, double endRadius)
        {
            IGeometry endGeometry = Vector3DExamples.GetExample2();

            ITransform3D transform3D = endGeometry as ITransform3D;

            IPoint originPoint = GeometryUtilities.ConstructPoint3D(0, 0, 0);

            transform3D.Scale3D(originPoint, endRadius, endRadius, 2 * endRadius);

            if (degreesOfRotation != 0)
            {
                double angleOfRotationInRadians = GeometryUtilities.GetRadians(degreesOfRotation);

                transform3D.RotateVector3D(axisOfRotationVector3D, angleOfRotationInRadians);
            }

            transform3D.Move3D(endPoint.X - originPoint.X, endPoint.Y - originPoint.Y, endPoint.Z - originPoint.Z);

            GraphicsLayer3DUtilities.AddMultiPatchToGraphicsLayer3D(endGraphicsContainer3D, endGeometry, endColor);
        }

        public static void DrawMultiPatch(IGraphicsContainer3D multiPatchGraphicsContainer3D, IGeometry geometry)
        {
            const int Yellow_R = 255;
            const int Yellow_G = 255;
            const int Yellow_B = 0;

            IColor multiPatchColor = ColorUtilities.GetColor(Yellow_R, Yellow_G, Yellow_B);

            multiPatchGraphicsContainer3D.DeleteAllElements();

            GraphicsLayer3DUtilities.AddMultiPatchToGraphicsLayer3D(multiPatchGraphicsContainer3D, geometry, multiPatchColor);
        }

        public static void DrawOutline(IGraphicsContainer3D outlineGraphicsContainer3D, IGeometry geometry)
        {
            const esriSimple3DLineStyle OutlineStyle = esriSimple3DLineStyle.esriS3DLSTube;
            const double OutlineWidth = 0.1;

            const int Black_R = 0;
            const int Black_G = 0;
            const int Black_B = 0;

            IColor outlineColor = ColorUtilities.GetColor(Black_R, Black_G, Black_B);

            outlineGraphicsContainer3D.DeleteAllElements();

            GraphicsLayer3DUtilities.AddOutlineToGraphicsLayer3D(outlineGraphicsContainer3D, GeometryUtilities.ConstructMultiPatchOutline(geometry), outlineColor, OutlineStyle, OutlineWidth);
        }
    }
}
[Visual Basic .NET]

DrawUtilities.vb

Imports Microsoft.VisualBasic
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.Analyst3D
Imports System


Public Class DrawUtilities
    Private Shared _missing As Object = Type.Missing

    Private Sub New()
    End Sub
    Public Shared Sub DrawAxes(ByVal axesGraphicsContainer3D As IGraphicsContainer3D)
        Const AxisStyle As esriSimple3DLineStyle = esriSimple3DLineStyle.esriS3DLSTube
        Const AxisWidth As Double = 0.25

        DrawAxis(axesGraphicsContainer3D, GeometryUtilities.ConstructPoint3D(-10, 0, 0), GeometryUtilities.ConstructPoint3D(10, 0, 0), ColorUtilities.GetColor(255, 0, 0), AxisStyle, AxisWidth)
        DrawAxis(axesGraphicsContainer3D, GeometryUtilities.ConstructPoint3D(0, -10, 0), GeometryUtilities.ConstructPoint3D(0, 10, 0), ColorUtilities.GetColor(0, 0, 255), AxisStyle, AxisWidth)
        DrawAxis(axesGraphicsContainer3D, GeometryUtilities.ConstructPoint3D(0, 0, -10), GeometryUtilities.ConstructPoint3D(0, 0, 10), ColorUtilities.GetColor(0, 255, 0), AxisStyle, AxisWidth)

        DrawEnd(axesGraphicsContainer3D, GeometryUtilities.ConstructPoint3D(10, 0, 0), GeometryUtilities.ConstructVector3D(0, 10, 0), 90, ColorUtilities.GetColor(255, 0, 0), 0.2 * AxisWidth)
        DrawEnd(axesGraphicsContainer3D, GeometryUtilities.ConstructPoint3D(0, 10, 0), GeometryUtilities.ConstructVector3D(10, 0, 0), -90, ColorUtilities.GetColor(0, 0, 255), 0.2 * AxisWidth)
        DrawEnd(axesGraphicsContainer3D, GeometryUtilities.ConstructPoint3D(0, 0, 10), Nothing, 0, ColorUtilities.GetColor(0, 255, 0), 0.2 * AxisWidth)
    End Sub

    Private Shared Sub DrawAxis(ByVal axesGraphicsContainer3D As IGraphicsContainer3D, ByVal axisFromPoint As IPoint, ByVal axisToPoint As IPoint, ByVal axisColor As IColor, ByVal axisStyle As esriSimple3DLineStyle, ByVal axisWidth As Double)
        Dim axisPointCollection As IPointCollection = New PolylineClass()

        axisPointCollection.AddPoint(axisFromPoint, _missing, _missing)
        axisPointCollection.AddPoint(axisToPoint, _missing, _missing)

        GeometryUtilities.MakeZAware(TryCast(axisPointCollection, IGeometry))

        GraphicsLayer3DUtilities.AddAxisToGraphicsLayer3D(axesGraphicsContainer3D, TryCast(axisPointCollection, IGeometry), axisColor, axisStyle, axisWidth)
    End Sub

    Private Shared Sub DrawEnd(ByVal endGraphicsContainer3D As IGraphicsContainer3D, ByVal endPoint As IPoint, ByVal axisOfRotationVector3D As IVector3D, ByVal degreesOfRotation As Double, ByVal endColor As IColor, ByVal endRadius As Double)
        Dim endGeometry As IGeometry = Vector3DExamples.GetExample2()

        Dim transform3D As ITransform3D = TryCast(endGeometry, ITransform3D)

        Dim originPoint As IPoint = GeometryUtilities.ConstructPoint3D(0, 0, 0)

        transform3D.Scale3D(originPoint, endRadius, endRadius, 2 * endRadius)

        If degreesOfRotation <> 0 Then
            Dim angleOfRotationInRadians As Double = GeometryUtilities.GetRadians(degreesOfRotation)

            transform3D.RotateVector3D(axisOfRotationVector3D, angleOfRotationInRadians)
        End If

        transform3D.Move3D(endPoint.X - originPoint.X, endPoint.Y - originPoint.Y, endPoint.Z - originPoint.Z)

        GraphicsLayer3DUtilities.AddMultiPatchToGraphicsLayer3D(endGraphicsContainer3D, endGeometry, endColor)
    End Sub

    Public Shared Sub DrawMultiPatch(ByVal multiPatchGraphicsContainer3D As IGraphicsContainer3D, ByVal geometry As IGeometry)
        Const Yellow_R As Integer = 255
        Const Yellow_G As Integer = 255
        Const Yellow_B As Integer = 0

        Dim multiPatchColor As IColor = ColorUtilities.GetColor(Yellow_R, Yellow_G, Yellow_B)

        multiPatchGraphicsContainer3D.DeleteAllElements()

        GraphicsLayer3DUtilities.AddMultiPatchToGraphicsLayer3D(multiPatchGraphicsContainer3D, geometry, multiPatchColor)
    End Sub

    Public Shared Sub DrawOutline(ByVal outlineGraphicsContainer3D As IGraphicsContainer3D, ByVal geometry As IGeometry)
        Const OutlineStyle As esriSimple3DLineStyle = esriSimple3DLineStyle.esriS3DLSTube
        Const OutlineWidth As Double = 0.1

        Const Black_R As Integer = 0
        Const Black_G As Integer = 0
        Const Black_B As Integer = 0

        Dim outlineColor As IColor = ColorUtilities.GetColor(Black_R, Black_G, Black_B)

        outlineGraphicsContainer3D.DeleteAllElements()

        GraphicsLayer3DUtilities.AddOutlineToGraphicsLayer3D(outlineGraphicsContainer3D, GeometryUtilities.ConstructMultiPatchOutline(geometry), outlineColor, OutlineStyle, OutlineWidth)
    End Sub
End Class