Beispiel #1
0
        public ConstantVolumePressureGoal(Mesh mesh, float volumePressureConstant, float weight = 1f)
        {
            try
            {
                currentVolumeInversed = 1f / (float)mesh.Volume;
            }
            catch (Exception)
            {
                throw new Exception("The input mesh is not valid (It must be a closed mesh so that its volume is computable)");
            }

            Mesh   = mesh;
            faces  = Mesh.VertexIndicesByTri();
            Weight = weight;
            VolumePressureConstant = volumePressureConstant;
            List <Point> vertices = mesh.Vertices();

            StartingPositions = new Triple[mesh.VertexCount];
            for (int i = 0; i < mesh.VertexCount; i++)
            {
                StartingPositions[i] = vertices[i].ToTriple();
            }

            Moves   = new Triple[StartingPositions.Length];
            Weights = new float[StartingPositions.Length];
        }
Beispiel #2
0
        public Octree(MeshToolkit mesh, bool cubic = true)
        {
            this._mesh  = mesh;
            this._cubic = cubic;
            //this.triangles = _mesh.Triangles();
            this.vertices         = _mesh.Vertices();
            this.vertexIndexByTri = Core.List.Chop <int>(_mesh.VertexIndicesByTri(), 3);
            BoundingBox bbox = Graphical.Geometry.MeshToolkit.BoundingBox(this._mesh);

            // Extending the BoundingBox to be cubical from the centre.
            // Done by getting the max component of the Bounding box and translating min and max points outwards.
            // https://github.com/diwi/Space_Partitioning_Octree_BVH/blob/b7f66fe04e4af3b98ab9404363ab33f5dc1628a9/SpacePartitioning/src/DwOctree/Octree.java#L83
            if (cubic)
            {
                using (Point center = Geometry.Point.MidPoint(bbox.MinPoint, bbox.MaxPoint))
                {
                    Vector   bboxSize       = Vector.ByTwoPoints(bbox.MinPoint, bbox.MaxPoint);
                    Vector   halfSize       = bboxSize.Scale(0.5);
                    double[] halfComponents = new double[3] {
                        halfSize.X, halfSize.Y, halfSize.Z
                    };
                    double maxComponent       = halfComponents[getSubdivisionPlane(bbox)];
                    Vector expansionDirection = Vector.ByCoordinates(maxComponent, maxComponent, maxComponent);
                    bbox = BoundingBox.ByCorners(
                        (Point)center.Translate(-maxComponent, -maxComponent, -maxComponent),
                        (Point)center.Translate(maxComponent, maxComponent, maxComponent)
                        );
                }
            }

            _root = new OctreeNode(0, bbox);
        }
Beispiel #3
0
        public static List <List <Point> > GetVerticesOfAllPairOfTriangles(Mesh mesh)
        {
            List <int> faceVertexIndices = mesh.VertexIndicesByTri();
            int        vertexCount       = (int)mesh.VertexCount;
            Dictionary <int, List <int> > edgeFaceTopology = new Dictionary <int, List <int> >();

            for (int i = 0; i < mesh.TriangleCount; i++)
            {
                int A = faceVertexIndices[i * 3];
                int B = faceVertexIndices[i * 3 + 1];
                int C = faceVertexIndices[i * 3 + 2];

                InsertEdgeFaceTopology(edgeFaceTopology, i, A, B, vertexCount);
                InsertEdgeFaceTopology(edgeFaceTopology, i, B, C, vertexCount);
                InsertEdgeFaceTopology(edgeFaceTopology, i, C, A, vertexCount);
            }

            List <List <Point> > facePairVertices = new List <List <Point> >();

            foreach (List <int> connectedFaces in edgeFaceTopology.Values)
            {
                if (connectedFaces.Count < 2)
                {
                    continue;
                }

                HashSet <int> hashSet = new HashSet <int>();
                hashSet.Add(faceVertexIndices[connectedFaces[0] * 3]);
                hashSet.Add(faceVertexIndices[connectedFaces[0] * 3 + 1]);
                hashSet.Add(faceVertexIndices[connectedFaces[0] * 3 + 2]);
                hashSet.Add(faceVertexIndices[connectedFaces[1] * 3]);
                hashSet.Add(faceVertexIndices[connectedFaces[1] * 3 + 1]);
                hashSet.Add(faceVertexIndices[connectedFaces[1] * 3 + 2]);

                List <Point> vertices = new List <Point>();

                foreach (int i in hashSet)
                {
                    vertices.Add(mesh.Vertices()[i]);
                }

                facePairVertices.Add(vertices);
            }

            return(facePairVertices);
        }
        /// <summary>
        ///
        /// </summary>
        internal void CreateAgents()
        {
            var agentsDict = new Dictionary <HashSet <int>, tAgent>(HashSet <int> .CreateSetComparer());

            var indices  = _mesh.VertexIndicesByTri();
            var faces    = SplitList(indices);
            var normals  = _mesh.TriangleNormals();
            var surfaces = MakeOffsetFaces(faces, _mesh.Vertices(), normals);

            // Loop through every face
            for (int i = 0; i < faces.Count; i++)
            {
                for (int j = 0; j < faces[i].Count; j++)
                {
                    int start = faces[i][j];
                    int end   = faces[i][(j + 1) % faces[i].Count];
                    var key   = new HashSet <int> {
                        start, end
                    };

                    if (!agentsDict.ContainsKey(key))
                    {
                        agentsDict[key]       = new tAgent(agentsDict.Count);
                        agentsDict[key]._edge = Geo.Line.ByStartPointEndPoint(_mesh.Vertices()[start], _mesh.Vertices()[end]);
                    }
                }
            }

            // Loop through every face
            for (int i = 0; i < faces.Count; i++)
            {
                // Loop through every edge of every face
                for (int j = 0; j < faces[i].Count; j++)
                {
                    int start = faces[i][j];
                    int end   = faces[i][(j + 1) % faces[i].Count];
                    int third = faces[i][(j + 2) % faces[i].Count];
                    var key   = new HashSet <int> {
                        start, end
                    };

                    if (agentsDict[key]._faceIndexA != -1)
                    {
                        agentsDict[key]._isNaked      = false;
                        agentsDict[key]._faceIndexB   = i;
                        agentsDict[key]._faceNormalB  = normals[i];
                        agentsDict[key]._faceSurfaceB = surfaces[i];
                        var neighborsB1 = agentsDict[new HashSet <int> {
                                                         start, third
                                                     }]._name;
                        var neighborsB2 = agentsDict[new HashSet <int> {
                                                         end, third
                                                     }]._name;
                        agentsDict[key]._neighborsB = new int[] { neighborsB1, neighborsB2 };
                    }
                    else
                    {
                        agentsDict[key]._faceIndexA   = i;
                        agentsDict[key]._faceNormalA  = normals[i];
                        agentsDict[key]._faceSurfaceA = surfaces[i];
                        var neighborsA1 = agentsDict[new HashSet <int> {
                                                         start, third
                                                     }]._name;
                        var neighborsA2 = agentsDict[new HashSet <int> {
                                                         end, third
                                                     }]._name;
                        agentsDict[key]._neighborsA = new int[] { neighborsA1, neighborsA2 };
                    }
                }
            }

            _agents = agentsDict.Values.ToArray();

            foreach (tAgent agent in _agents)
            {
                agent.Setup();
            }
        }