コード例 #1
0
    public void InitializeTree(DirectoryInfo directory)
    {
        this.directory = directory;
        meshManager    = new MeshManager(numberOfMeshes, numberOfMeshLoadingJobs);
        FileInfo     index  = directory.GetFiles("voxelIndex.json")[0];
        StreamReader reader = new StreamReader(index.FullName);
        string       s      = reader.ReadToEnd();
        JSONNode     json   = JSON.Parse(s);

        if (json.IsArray)
        {
            topNodes = new PointCloudNode[json.AsArray.Count];
            for (int i = 0; i < json.AsArray.Count; i++)
            {
                topNodes[i] = PointCloudNode.AddNode(json.AsArray[i], this.directory, gameObject, this);
            }
        }
        else
        {
            topNodes    = new PointCloudNode[1];
            topNodes[0] = PointCloudNode.AddNode(json, this.directory, gameObject, this);
        }

        if (moveCameraToCenter)
        {
            Camera.main.transform.position = topNodes[0].boundsInModelSpace.center;
        }

        System.GC.Collect(); //Garbage Collection
    }
コード例 #2
0
    public static PointCloudNode AddNode(JSONNode node, DirectoryInfo directory, GameObject gameObject, IPointCloudManager materialProvider)
    {
        GameObject child = new GameObject("PC Node");

        child.isStatic = true;


        PointCloudNode pcNode = null;

        if (JSONOfLeaf(node))
        {
            pcNode = child.AddComponent <PointCloudLeafNode>();
        }
        else
        {
            pcNode = child.AddComponent <PointCloudParentNode>();
        }

        if (pcNode.Initialize(node, directory, materialProvider))
        {
            child.transform.SetParent(gameObject.transform, false);
            return(pcNode);
        }
        else
        {
            Destroy(child);
            return(null);
        }
    }
コード例 #3
0
        public override bool Run(FeatureContext context)
        {
            const float len  = 100.0f;
            const int   nDim = 50;

            float[] pointBuffer = new float[nDim * nDim * nDim * 3];
            float[] colorBuffer = new float[nDim * nDim * nDim * 3];
            int     idx         = -1;

            for (int ii = 0; ii < nDim; ++ii)
            {
                for (int jj = 0; jj < nDim; ++jj)
                {
                    for (int kk = 0; kk < nDim; ++kk)
                    {
                        ++idx;
                        pointBuffer[idx * 3]     = ii * len;
                        pointBuffer[idx * 3 + 1] = jj * len;
                        pointBuffer[idx * 3 + 2] = kk * len;

                        colorBuffer[idx * 3]     = ((float)ii) / ((float)nDim);
                        colorBuffer[idx * 3 + 1] = ((float)jj) / ((float)nDim);
                        colorBuffer[idx * 3 + 2] = ((float)kk) / ((float)nDim);
                    }
                }
            }

            PointStyle pointStyle = new PointStyle();

            //pointStyle.SetPointSize(4.0f);
            pointStyle.SetMarker("cross");

            PointCloudNode pcn = new PointCloudNode();

            pcn.SetPointStyle(pointStyle);
            pcn.SetPoints(pointBuffer);
            pcn.SetColors(colorBuffer);
            pcn.ComputeBBox();
            AABox   bbox = pcn.GetBBox();
            Vector3 pt   = bbox.MinPt;

            context.ShowSceneNode(pcn);


            return(true);
        }
コード例 #4
0
    public override bool Initialize(JSONNode node, DirectoryInfo directory, IPointCloudManager manager)
    {
        InitializeFromJSON(node);
        gameObject.name = "PC Parent Node";

        JSONArray childrenJSON = node["children"].AsArray;
        ArrayList childrenList = new ArrayList();

        //Debug.Log("N Children: " + childrenJSON.Count);
        for (int i = 0; i < childrenJSON.Count; i++)
        {
            PointCloudNode pcNode = PointCloudNode.AddNode(childrenJSON[i], directory, gameObject, manager);
            if (pcNode != null)
            {
                childrenList.Add(pcNode);
            }
        }
        children = (PointCloudNode[])childrenList.ToArray(typeof(PointCloudNode));

        return(childrenJSON.Count > 0);
    }
コード例 #5
0
    void SelectPoint(Vector2 screenPosition, float maxScreenDistance)
    {
        if (pcListener == null)
        {
            return;
        }

        Debug.Log("Finding selected point.");

        MeshFilter[] mf      = GetComponentsInChildren <MeshFilter>();
        float        maxDist = 10000000.0f;

        Vector3 closestHit      = Vector3.negativeInfinity;
        Color   colorClosestHit = Color.black;
        Ray     ray             = Camera.main.ScreenPointToRay(Input.mousePosition);

        for (int i = 0; i < transform.childCount; i++)
        {
            GameObject     child = transform.GetChild(i).gameObject;
            PointCloudNode node  = child.GetComponent <PointCloudNode>();
            if (node != null)
            {
                Debug.Log("Finding selected point on node.");
                node.GetClosestPointOnRay(ray,
                                          screenPosition,
                                          ref maxDist,
                                          ref closestHit,
                                          ref colorClosestHit,
                                          maxScreenDistance * maxScreenDistance);
            }
        }

        if (!closestHit.Equals(Vector3.negativeInfinity))
        {
            float classCode = GetClassCodeForColor(colorClosestHit);
            pcListener.onPointSelected(closestHit, classCode);
        }
    }
コード例 #6
0
        private void largePointsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            const float len  = 100.0f;
            const int   nDim = 50;

            float[] pointBuffer = new float[nDim * nDim * nDim * 3];
            int     idx         = -1;

            for (int ii = 0; ii < nDim; ++ii)
            {
                for (int jj = 0; jj < nDim; ++jj)
                {
                    for (int kk = 0; kk < nDim; ++kk)
                    {
                        ++idx;
                        pointBuffer[idx * 3]     = ii * len;
                        pointBuffer[idx * 3 + 1] = jj * len;
                        pointBuffer[idx * 3 + 2] = kk * len;
                    }
                }
            }

            PointStyle pointStyle = new PointStyle();

            pointStyle.SetPointSize(4.0f);
            pointStyle.SetColor(new ColorValue(0.0f, 0.0f, 0.0f));

            PointCloudNode pcn = new PointCloudNode();

            pcn.SetPointStyle(pointStyle);
            pcn.SetPoints(pointBuffer);
            pcn.ComputeBBox();

            renderView.SceneManager.AddNode(pcn);

            renderView.RequestDraw();
        }
コード例 #7
0
ファイル: FormMain.cs プロジェクト: xazk027/anycadnetsdkpro
        private void largePointsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            const float len = 100.0f;
            const int nDim = 50;
            float[] pointBuffer = new float[nDim * nDim * nDim * 3];
            float[] colorBuffer = new float[nDim*nDim*nDim*3];
            int idx = -1;
            for (int ii = 0; ii < nDim; ++ii)
                for (int jj = 0; jj < nDim; ++jj)
                    for (int kk = 0; kk < nDim; ++kk)
                    {
                        ++idx;
                        pointBuffer[idx * 3] = ii * len;
                        pointBuffer[idx * 3 + 1] = jj * len;
                        pointBuffer[idx * 3 + 2] = kk * len;

                        colorBuffer[idx*3] = ((float)ii)/((float)nDim);
                        colorBuffer[idx*3 + 1] = ((float)jj)/((float)nDim);
                        colorBuffer[idx * 3 + 2] = ((float)kk) / ((float)nDim);
                    }

            PointStyle pointStyle = new PointStyle();
            pointStyle.SetPointSize(4.0f);

            PointCloudNode pcn = new PointCloudNode();
            pcn.SetPointStyle(pointStyle);
            pcn.SetPoints(pointBuffer);
            pcn.SetColors(colorBuffer);
            pcn.ComputeBBox();
            AABox bbox = pcn.GetBBox();
            Vector3 pt = bbox.MinPt;
            renderView.SceneManager.AddNode(pcn);

            renderView.RequestDraw();
        }
コード例 #8
0
        public override bool Run(FeatureContext context)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "Deformation File (*.txt)|*.txt||";
            if (DialogResult.OK != dlg.ShowDialog())
            {
                return(true);
            }


            String       fileName = dlg.FileName;
            StreamReader sr       = new StreamReader(fileName, Encoding.Default);
            String       line     = sr.ReadLine();

            List <DeformationNode> nodes = new List <DeformationNode>();
            float maxValue = float.NegativeInfinity;
            float minValue = float.PositiveInfinity;

            while ((line = sr.ReadLine()) != null)
            {
                String[] items = line.Split('\t');

                DeformationNode node = new DeformationNode();
                node.Id   = int.Parse(items[0]);
                node.X    = float.Parse(items[1]);
                node.Y    = float.Parse(items[2]);
                node.Z    = float.Parse(items[3]);
                node.Data = float.Parse(items[4]);

                nodes.Add(node);

                if (node.Data > maxValue)
                {
                    maxValue = node.Data;
                }
                if (node.Data < minValue)
                {
                    minValue = node.Data;
                }
            }

            float[] pointBuffer = new float[nodes.Count * 3];
            float[] colorBuffer = new float[nodes.Count * 3];
            float   range       = maxValue - minValue;

            List <ColorValue> colorTables = new List <ColorValue>();

            colorTables.Add(new ColorValue(0, 0, 1.0f));
            colorTables.Add(new ColorValue(0, 108.0f / 255.0f, 1.0f));
            colorTables.Add(new ColorValue(0, 197.0f / 255.0f, 1.0f));
            colorTables.Add(new ColorValue(0, 243 / 255.0f, 1.0f));
            colorTables.Add(new ColorValue(0, 1.0f, 219.0f / 255.0f));
            colorTables.Add(new ColorValue(0, 1.0f, 165.0f / 255.0f));
            colorTables.Add(new ColorValue(0, 1.0f, 54.0f / 255.0f));
            colorTables.Add(new ColorValue(54.0f / 255.0f, 1.0f, 0));
            colorTables.Add(new ColorValue(219.0f / 255.0f, 1.0f, 0));
            //colorTables.Add(new ColorValue(238.0f / 255.0f, 249.0f/255.0f, 0));
            colorTables.Add(new ColorValue(238.0f / 255.0f, 249.0f / 255.0f, 0));
            colorTables.Add(new ColorValue(255.0f / 255.0f, 197.0f / 255.0f, 0));
            colorTables.Add(new ColorValue(251.0f / 255.0f, 102.0f / 255.0f, 17.0f / 255.0f));
            colorTables.Add(new ColorValue(1.0f, 0.0f, 0.0f));

            float segment = range / (colorTables.Count);

            int ii = -1;

            foreach (DeformationNode node in nodes)
            {
                int idx = (int)(node.Data / segment);

                if (idx >= colorTables.Count)
                {
                    idx -= 1;
                }

                ColorValue clr = colorTables.ElementAt(idx);

                pointBuffer[++ii] = node.X;
                colorBuffer[ii]   = clr.R;
                pointBuffer[++ii] = node.Y;
                colorBuffer[ii]   = clr.G;
                pointBuffer[++ii] = node.Z;
                colorBuffer[ii]   = clr.B;
            }

            PointCloudNode pcn = new PointCloudNode();

            pcn.SetPoints(pointBuffer);
            pcn.SetColors(colorBuffer);
            pcn.ComputeBBox();



            context.ShowSceneNode(pcn);
            return(true);
        }