Creating a Point Cloud Model Asynchronously

This example demonstrates how to create a point cloud model, add points to it, and then load it and fly to it. This example uses IPointCloudCreator81, IPosition81, and ICreator81 properties and methods.

public partial class Form1 : Form

    {

        SGWorld81 SGWorld;

        IPointCloudCreator81 PointCloudCreator;

        IPosition81 cloudCenter;

        public Form1()

        {

            InitializeComponent();

            SGWorld = new SGWorld81();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            try

            {

                object[] obj = new object[] { 0, 0, 1500, 0x8000FFFF, 1, 0, 1500, 0x8000FFFF, 2, 0, 1500, 0x8000FFFF };

                cloudCenter = SGWorld.Creator.CreatePosition();

                PointCloudCreator = SGWorld.Creator.CreateNewPointCloud(cloudCenter, "MyPointCloudCreator");

                PointCloudCreator.AddPointsAsync(obj)

                    .OnResolve(new Action(OnAddPointsResolveHandler))

                    .OnReject((object)new Action<object>(OnAddPointsRejectHandle));

            }

            catch (Exception ex)

            {

                MessageBox.Show("Exception: "+ ex.Message);

            }

        }

 

        public void OnAddPointsResolveHandler()

        {

            PointCloudCreator.FinishAsync()

                .OnResolve((object)new Action<object>(OnFinishAsyncResolveHandler))

                .OnReject((object)new Action<object>(OnFinishAsyncRejectHandle));

        }

        public void OnAddPointsRejectHandle(object error)

        {

            Console.WriteLine("Error: " + error);

        }

        public void OnFinishAsyncResolveHandler(object path)

        {

            SGWorld.Creator.CreatePointCloudModelAsync(path.ToString(), SGWorld.Creator.CreatePosition(), "", "PointCloud")

                .OnResolve((object)new Action<object>(OnCreatePointCloudModelResolveHandler))

                .OnReject((object)new Action<object>(OnCreatePointCloudModelRejectHandle));

        }

        public void OnFinishAsyncRejectHandle(object error)

        {

            Console.WriteLine("Error: " + error);

        }

        public void OnCreatePointCloudModelResolveHandler(object obj)

        {

            ITerrainPointCloudModel81 pointCloudModel = (ITerrainPointCloudModel81)obj;

            pointCloudModel.PointSize = 10; SGWorld.Navigate.FlyTo(pointCloudModel.ID);

        }

        public void OnCreatePointCloudModelRejectHandle(object error)

        {

            Console.WriteLine("Error: " + error);

        }

    }