コード例 #1
0
ファイル: KmeanBehavior.cs プロジェクト: ulisses177/Work
        /// <summary>
        /// Crée les éléments à classer
        /// </summary>
        public void Populate(int n, int width, int height)
        {
            Random random = new Random();

            for (int i = 0; i < n; i++)
            {
                Troll3D.Entity entity = new Troll3D.Entity(Entity);

                entity.transform_.SetPosition(
                    (float)random.NextDouble() * width - width / 2.0f,
                    (float)random.NextDouble() * height - height / 2.0f,
                    0.0f);

                entity.transform_.SetScale(0.02f, 0.02f, 1.0f);

                MaterialDX11 material = new MaterialDX11();
                material.SetMainColor(0.0f, 0.0f, 0.0f, 1.0f);
                MeshRenderer meshrenderer = entity.AddComponent <MeshRenderer>();
                meshrenderer.material_ = material;
                meshrenderer.model_    = Quad.GetMesh();

                Elements.Add(entity);
                ClusterId.Add(-1);
            }
        }
コード例 #2
0
ファイル: DelaunayBehaviour.cs プロジェクト: ulisses177/Work
        /// <summary>
        /// Construit une représentation graphique du Diagramme de Voronoi de la triangulation
        /// </summary>
        public void BuildVoronoi(WingedEdgeMesh mesh)
        {
            List <StandardVertex> lines = new List <StandardVertex>();

            // On va commencer par construire les sommets correspondant aux centre des faces de la triangulation
            // qui sont les noeuds du diagramme de voronoir
            CleanVoronoi();

            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                // On récupère le centre de la face (barycentre)

                List <VertexWE> vertices = mesh.GetFaceVertices(mesh.Faces[i]);

                Vector3 center = vertices[0].Position + vertices[1].Position + vertices[2].Position;
                center = center / 3.0f;

                Troll3D.Entity entity = new Troll3D.Entity(Entity);
                entity.transform_.SetPosition(
                    center.X,
                    center.Y,
                    0.0f);

                entity.transform_.SetScale(0.02f, 0.02f, 1.0f);

                MaterialDX11 material = new MaterialDX11();
                material.SetMainColor(0.0f, 1.0f, 1.0f, 1.0f);
                MeshRenderer meshrenderer = entity.AddComponent <MeshRenderer>();
                meshrenderer.material_ = material;
                meshrenderer.model_    = Quad.GetMesh();

                // On récupère les voisins

                List <FaceWE> neighbours = mesh.GetFaceNeighbours(mesh.Faces[i]);

                for (int j = 0; j < neighbours.Count; j++)
                {
                    // On récupère le centre de la face (barycentre)

                    List <VertexWE> verticesNeighbour = mesh.GetFaceVertices(neighbours[j]);

                    Vector3 centerNeighbour = verticesNeighbour[0].Position + verticesNeighbour[1].Position + verticesNeighbour[2].Position;
                    centerNeighbour = centerNeighbour / 3.0f;

                    lines.Add(new StandardVertex(center));
                    lines.Add(new StandardVertex(centerNeighbour));
                }

                VoronoiPoints.Add(entity);
            }

            if (lines.Count > 0)
            {
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).Display  = true;
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).Vertices = lines;
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).UpdateRenderer();
            }
        }
コード例 #3
0
        public void BuildVoronoi(WingedEdgeMesh mesh)
        {
            List <StandardVertex> lines = new List <StandardVertex>();

            // We start by building the vertices corresponding to the face's center of the triangulation who are node of the Voronoi diagram
            CleanVoronoi();

            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                // We get back the face's center (barycentre)

                List <VertexWE> vertices = mesh.GetFaceVertices(mesh.Faces[i]);

                Vector3 center = vertices[0].Position + vertices[1].Position + vertices[2].Position;
                center = center / 3.0f;

                Troll3D.Entity entity = new Troll3D.Entity(Entity);
                entity.transform_.SetPosition(
                    center.X,
                    center.Y,
                    0.0f);

                entity.transform_.SetScale(0.02f, 0.02f, 1.0f);

                MaterialDX11 material = new MaterialDX11();
                material.SetMainColor(0.0f, 1.0f, 1.0f, 1.0f);
                MeshRenderer meshrenderer = entity.AddComponent <MeshRenderer>();
                meshrenderer.material_ = material;
                meshrenderer.model_    = Quad.GetMesh();

                // We get back the neighbours

                List <FaceWE> neighbours = mesh.GetFaceNeighbours(mesh.Faces[i]);

                for (int j = 0; j < neighbours.Count; j++)
                {
                    // On récupère le centre de la face (barycentre)

                    List <VertexWE> verticesNeighbour = mesh.GetFaceVertices(neighbours[j]);

                    Vector3 centerNeighbour = verticesNeighbour[0].Position + verticesNeighbour[1].Position + verticesNeighbour[2].Position;
                    centerNeighbour = centerNeighbour / 3.0f;

                    lines.Add(new StandardVertex(center));
                    lines.Add(new StandardVertex(centerNeighbour));
                }

                VoronoiPoints.Add(entity);
            }

            if (lines.Count > 0)
            {
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).Display  = true;
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).Vertices = lines;
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).UpdateRenderer();
            }
        }
コード例 #4
0
        public void AddPoint(float x, float y)
        {
            Troll3D.Entity entity = new Troll3D.Entity(Entity);

            entity.transform_.SetPosition(
                x,
                y,
                0.0f);

            entity.transform_.SetScale(0.02f, 0.02f, 1.0f);

            MaterialDX11 material = new MaterialDX11();

            material.SetMainColor(1.0f, 0.0f, 1.0f, 1.0f);
            MeshRenderer meshrenderer = entity.AddComponent <MeshRenderer>();

            meshrenderer.material_ = material;
            meshrenderer.model_    = Quad.GetMesh();

            Points.Add(entity);
        }
コード例 #5
0
        public void AddCircleCenter(float x, float y, float radius)
        {
            Troll3D.Entity entityCircle = new Troll3D.Entity(Entity);
            entityCircle.transform_.RotateEuler(0.0f, 3.1415f / 2.0f, 0.0f);
            entityCircle.transform_.Translate(x, y, 0.0f);
            entityCircle.transform_.SetScale(radius, 1.0f, radius);
            LineRenderer lineRenderer = entityCircle.AddComponent <LineRenderer>();


            lineRenderer.material_ = new MaterialDX11("vDefault.cso", "pUnlit.cso", "gDefaultLine.cso");
            lineRenderer.material_.SetMainColor(0.0f, 1.0f, 0.0f, 1.0f);

            lineRenderer.Vertices = Circle.GetLines(30);
            lineRenderer.UpdateRenderer();

            Circles.Add(entityCircle);

            Troll3D.Entity entity = new Troll3D.Entity(Entity);

            entity.transform_.SetPosition(
                x,
                y,
                0.0f);

            entity.transform_.SetScale(0.02f, 0.02f, 1.0f);

            MaterialDX11 material = new MaterialDX11();

            material.SetMainColor(0.0f, 1.0f, 0.0f, 1.0f);
            MeshRenderer meshrenderer = entity.AddComponent <MeshRenderer>();

            meshrenderer.material_ = material;
            meshrenderer.model_    = Quad.GetMesh();

            CircleCenter.Add(entity);
        }