コード例 #1
0
        public override CRS Jacobian(CMesh cm)
        {
            List <Point3d> verts = new List <Point3d>(cm.mesh.Vertices.ToPoint3dArray());
            Mesh           m     = cm.mesh;


            List <double> var     = new List <double>();
            List <int>    r_index = new List <int>();
            List <int>    c_index = new List <int>();

            for (int i = 0; i < this.anchors_index.Count; i++)
            {
                Point3d ancpt = this.anchors_position[this.anchors_index[i]];
                Point3d pt    = m.Vertices[this.anchors_index[i]];
                for (int j = 0; j < 3; j++)
                {
                    var.Add(strength * (pt[j] - ancpt[j]) / (edge_avarage_length * edge_avarage_length));
                    r_index.Add(i);
                    c_index.Add(3 * this.anchors_index[i] + j);
                }
            }


            CRS Jaco = new CRS(var, r_index, c_index, this.anchors_index.Count, verts.Count * 3);

            return(Jaco);
        }
コード例 #2
0
ファイル: GlueVertices.cs プロジェクト: KaiSut0/Crane020
        public override CRS Jacobian(CMesh cm)
        {
            List <Point3d> verts = new List <Point3d>(cm.mesh.Vertices.ToPoint3dArray());
            Mesh           m     = cm.mesh;


            List <double> var     = new List <double>();
            List <int>    r_index = new List <int>();
            List <int>    c_index = new List <int>();

            for (int i = 0; i < this.glue_vertices_index.Count - 1; i++)
            {
                Point3d pti  = m.Vertices[this.glue_vertices_index[i]];
                Point3d pti1 = m.Vertices[this.glue_vertices_index[i + 1]];

                for (int j = 0; j < 3; j++)
                {
                    var.Add((pti[j] - pti1[j]) / (edge_avarage_length * edge_avarage_length));
                    r_index.Add(i);
                    c_index.Add(3 * this.glue_vertices_index[i] + j);
                    var.Add((pti1[j] - pti[j]) / (edge_avarage_length * edge_avarage_length));
                    r_index.Add(i);
                    c_index.Add(3 * this.glue_vertices_index[i + 1] + j);
                }
            }


            CRS Jaco = new CRS(var, r_index, c_index, this.glue_vertices_index.Count - 1, verts.Count * 3);

            return(Jaco);
        }
コード例 #3
0
ファイル: CraneLibrary.cs プロジェクト: KaiSut0/Crane020
 public void Merge(CRS other)
 {
     if (this.Var.Count == 0)
     {
         this.Var     = other.Var;
         this.C_Index = other.C_Index;
         this.R_Ptr   = other.R_Ptr;
         this.C_Size  = other.C_Size;
         this.R_Size  = other.R_Size;
     }
     else
     {
         int c = this.Var.Count;
         this.Var.AddRange(other.Var);
         this.C_Index.AddRange(other.C_Index);
         foreach (int r in other.R_Ptr)
         {
             if (r != 0)
             {
                 this.R_Ptr.Add(r + c);
             }
         }
         this.R_Size += other.R_Size;
     }
 }
コード例 #4
0
ファイル: OnPlane.cs プロジェクト: KaiSut0/Crane020
        public override CRS Jacobian(CMesh cm)
        {
            List <Point3d> verts = new List <Point3d>(cm.mesh.Vertices.ToPoint3dArray());

            List <double> var     = new List <double>();
            List <int>    r_index = new List <int>();
            List <int>    c_index = new List <int>();

            for (int i = 0; i < anchor_vertex_ids.Count; i++)
            {
                Point3d pt_on_plane = goal_plane.ClosestPoint(verts[anchor_vertex_ids[i]]);

                for (int j = 0; j < 3; j++)
                {
                    var.Add(strength * (verts[anchor_vertex_ids[i]][j] - pt_on_plane[j]) / (edge_avarage_length * edge_avarage_length));
                    r_index.Add(i);
                    c_index.Add(3 * anchor_vertex_ids[i] + j);
                }
            }


            CRS Jaco = new CRS(var, r_index, c_index, anchor_vertex_ids.Count, verts.Count * 3);

            return(Jaco);
        }
コード例 #5
0
        public override CRS Jacobian(CMesh cm)
        {
            List <Point3d> verts = new List <Point3d>(cm.mesh.Vertices.ToPoint3dArray());

            List <double> var     = new List <double>();
            List <int>    r_index = new List <int>();
            List <int>    c_index = new List <int>();

            for (int i = 0; i < anchors_index.Count; i++)
            {
                double parm;
                anchor_curve.ClosestPoint(verts[anchors_index[i]], out parm);
                Point3d pt_on_curve = anchor_curve.PointAt(parm);

                for (int j = 0; j < 3; j++)
                {
                    var.Add(strength * (verts[anchors_index[i]][j] - pt_on_curve[j]) / (edge_avarage_length * edge_avarage_length));
                    r_index.Add(i);
                    c_index.Add(3 * anchors_index[i] + j);
                }
            }


            CRS Jaco = new CRS(var, r_index, c_index, anchors_index.Count, verts.Count * 3);

            return(Jaco);
        }
コード例 #6
0
ファイル: CraneLibrary.cs プロジェクト: KaiSut0/Crane020
        public CRS Transpose()
        {
            // Original CRS
            List <double> var0  = this.Var;
            List <int>    cind0 = this.C_Index;
            List <int>    rind0 = new List <int>();
            List <int>    rptr0 = this.R_Ptr;

            // Transposed CRS
            CRS Transposed = new CRS();

            double[] var  = new double[var0.Count];
            int[]    cind = new int[var0.Count];
            int[]    rptr = new int[this.C_Size + 1];

            // Get row index of original CRS
            for (int i = 0; i < rptr0.Count - 1; i++)
            {
                for (int j = 0; j < rptr0[i + 1] - rptr0[i]; j++)
                {
                    rind0.Add(i);
                }
            }

            // Get column ptr of Transposed CRS
            for (int i = 0; i < var0.Count; i++)
            {
                rptr[cind0[i] + 1] += 1;
            }
            for (int i = 1; i < this.C_Size + 1; i++)
            {
                rptr[i] += rptr[i - 1];
            }

            // Get var and row of Transposed CRS
            List <int> nn = new List <int>(rptr);

            for (int i = 0; i < var0.Count; i++)
            {
                int x = nn[cind0[i]];
                nn[cind0[i]] += 1;
                var[x]        = var0[i];
                cind[x]       = rind0[i];
            }
            Transposed.Var.AddRange(var);
            Transposed.C_Index.AddRange(cind);
            Transposed.R_Ptr.AddRange(rptr);
            Transposed.C_Size = this.R_Size;
            Transposed.R_Size = this.C_Size;
            return(Transposed);
        }
コード例 #7
0
        public override CRS Jacobian(CMesh cm)
        {
            List <Point3d> verts = new List <Point3d>(cm.mesh.Vertices.ToPoint3dArray());

            List <double> var     = new List <double>();
            List <int>    r_index = new List <int>();
            List <int>    c_index = new List <int>();

            for (int i = 0; i < this.anchors_index.Count; i++)
            {
                double z = verts[anchors_index[i]].Z;
                var.Add(z / (strength * edge_avarage_length * edge_avarage_length));
                r_index.Add(i);
                c_index.Add(3 * this.anchors_index[i] + 2);
            }


            CRS Jaco = new CRS(var, r_index, c_index, this.anchors_index.Count, verts.Count * 3);

            return(Jaco);
        }
コード例 #8
0
        /// <summary>
        /// Provides an Icon for the component.
        /// </summary>

        public override CRS Jacobian(CMesh cm)
        {
            Mesh          m       = cm.mesh;
            List <double> var     = new List <double>();
            List <int>    r_index = new List <int>();
            List <int>    c_index = new List <int>();
            CRS           Jaco    = new CRS(var, r_index, c_index, 0, 0);

            List <Point3d> verts = new List <Point3d>(m.Vertices.ToPoint3dArray());

            // 等長拘束をかける辺の数取得
            int n = equal_edge_ids.Count;

            // メッシュの TopologyEdges 取得
            MeshTopologyEdgeList topo_edge = m.TopologyEdges;
            List <int>           edges_id  = cm.inner_boundary_edges;


            // 辺長一定拘束 On の時
            if (is_set_length)
            {
                for (int i = 0; i < n; i++)
                {
                    int edge_id    = edges_id[equal_edge_ids[i]];
                    int st_pti_id  = topo_edge.GetTopologyVertices(edge_id).I;
                    int end_pti_id = topo_edge.GetTopologyVertices(edge_id).J;

                    Vector3d vsti = verts[st_pti_id] - verts[end_pti_id];
                    Vector3d veti = -vsti;

                    for (int j = 0; j < 3; j++)
                    {
                        var.Add(vsti[j] / (edge_avarage_length * edge_avarage_length));
                        r_index.Add(i);
                        c_index.Add(3 * st_pti_id + j);
                        var.Add(veti[j] / (edge_avarage_length * edge_avarage_length));
                        r_index.Add(i);
                        c_index.Add(3 * end_pti_id + j);
                    }
                }
                Jaco = new CRS(var, r_index, c_index, n, verts.Count * 3);
            }
            else
            {
                for (int i = 0; i < n - 1; i++)
                {
                    int edge_id_i  = edges_id[equal_edge_ids[i]];
                    int edge_id_i1 = edges_id[equal_edge_ids[i + 1]];

                    int st_pti_id   = topo_edge.GetTopologyVertices(edge_id_i).I;
                    int end_pti_id  = topo_edge.GetTopologyVertices(edge_id_i).J;
                    int st_pti1_id  = topo_edge.GetTopologyVertices(edge_id_i1).I;
                    int end_pti1_id = topo_edge.GetTopologyVertices(edge_id_i1).J;

                    Vector3d vsti  = verts[st_pti_id] - verts[end_pti_id];
                    Vector3d veti  = -vsti;
                    Vector3d vsti1 = verts[end_pti1_id] - verts[st_pti1_id];
                    Vector3d veti1 = -vsti1;

                    for (int j = 0; j < 3; j++)
                    {
                        var.Add(vsti[j] / (edge_avarage_length * edge_avarage_length));
                        r_index.Add(i);
                        c_index.Add(3 * st_pti_id + j);
                        var.Add(veti[j] / (edge_avarage_length * edge_avarage_length));
                        r_index.Add(i);
                        c_index.Add(3 * end_pti_id + j);
                        var.Add(vsti1[j] / (edge_avarage_length * edge_avarage_length));
                        r_index.Add(i);
                        c_index.Add(3 * st_pti1_id + j);
                        var.Add(veti1[j] / (edge_avarage_length * edge_avarage_length));
                        r_index.Add(i);
                        c_index.Add(3 * end_pti1_id + j);
                    }
                }

                Jaco = new CRS(var, r_index, c_index, n - 1, verts.Count * 3);
            }

            return(Jaco);
        }
コード例 #9
0
ファイル: EqualSectorAngle.cs プロジェクト: KaiSut0/Crane020
        public override CRS Jacobian(CMesh cm)
        {
            Mesh m = cm.mesh;

            List <double> var     = new List <double>();
            List <int>    r_index = new List <int>();
            List <int>    c_index = new List <int>();

            var topo = m.TopologyVertices;

            topo.SortEdges();

            List <bool> isNaked          = new List <bool>(m.GetNakedEdgePointStatus());
            List <int>  internalVertices = new List <int>();

            //内部頂点インデックスリスト作成
            for (int i = 0; i < topo.Count; i++)
            {
                if (!isNaked[i])
                {
                    internalVertices.Add(i);
                }
            }

            //各内部頂点について
            for (int r = 0; r < internalVertices.Count; r++)
            {
                //内部頂点のインデックス、位置ベクトル
                int      index_center = internalVertices[r];
                Vector3d center       = new Vector3d(topo[index_center]);

                //接続点のインデックス、位置ベクトル
                List <int>      index_neighbors = new List <int>();
                List <Vector3d> neighbors       = new List <Vector3d>();
                index_neighbors.AddRange(topo.ConnectedTopologyVertices(index_center));

                //エッジベクトル
                List <Vector3d> vecs    = new List <Vector3d>();
                List <Vector3d> normals = new List <Vector3d>();

                int n = index_neighbors.Count;

                //位置ベクトル取得
                foreach (int index_neighbor in index_neighbors)
                {
                    neighbors.Add(new Vector3d(topo[index_neighbor]));
                }

                //方向ベクトル取得
                foreach (Vector3d neighbor in neighbors)
                {
                    Vector3d temp = neighbor - center;
                    vecs.Add(temp);
                }

                //法線ベクトル取得
                for (int i = 0; i < n; i++)
                {
                    Vector3d temp = new Vector3d();
                    if (i == 0)
                    {
                        temp = Vector3d.CrossProduct(vecs[n - 1], vecs[0]);
                    }
                    else
                    {
                        temp = Vector3d.CrossProduct(vecs[i - 1], vecs[i]);
                    }
                    temp.Unitize();
                    normals.Add(temp);
                }

                Vector3d v_center = new Vector3d();

                for (int i = 0; i < n; i++)
                {
                    int      index = index_neighbors[i];
                    Vector3d v1    = Vector3d.CrossProduct(normals[i], vecs[i]);
                    v1 *= 1 / vecs[i].SquareLength;
                    Vector3d v2 = Vector3d.CrossProduct(normals[(i + 1) % n], vecs[i]);
                    v2       *= 1 / vecs[i].SquareLength;
                    v1       -= v2;
                    v_center -= v1;


                    var.Add((double)v1.X);
                    var.Add((double)v1.Y);
                    var.Add((double)v1.Z);
                    c_index.Add(index * 3);
                    c_index.Add(index * 3 + 1);
                    c_index.Add(index * 3 + 2);
                    r_index.Add(r);
                    r_index.Add(r);
                    r_index.Add(r);
                }
                var.Add((double)v_center.X);
                var.Add((double)v_center.Y);
                var.Add((double)v_center.Z);
                c_index.Add(index_center * 3);
                c_index.Add(index_center * 3 + 1);
                c_index.Add(index_center * 3 + 2);
                r_index.Add(r);
                r_index.Add(r);
                r_index.Add(r);
            }

            CRS Jaco = new CRS(var, r_index, c_index, internalVertices.Count, topo.Count * 3);

            return(Jaco);
        }
コード例 #10
0
        public override CRS Jacobian(CMesh cm)
        {
            // 等長拘束をかける辺の数取得
            int n = equal_fold_angle_edge_id.Count;

            List <double> var  = new List <double>();
            List <int>    rind = new List <int>();
            List <int>    cind = new List <int>();


            List <Point3d> verts = new List <Point3d>(cm.mesh.Vertices.ToPoint3dArray());
            Mesh           m     = cm.mesh;

            m.FaceNormals.ComputeFaceNormals();

            // メッシュの TopologyEdges 取得
            MeshTopologyEdgeList topo_edges = m.TopologyEdges;

            for (int i = 0; i < n; i++)
            {
                // Register indices
                int       edge_index = equal_fold_angle_edge_id[i];
                IndexPair edge_ind   = topo_edges.GetTopologyVertices(edge_index);
                int       u          = edge_ind.I;
                int       v          = edge_ind.J;
                IndexPair face_ind   = cm.face_pairs[edge_index];
                int       P          = face_ind[0];
                int       Q          = face_ind[1];

                MeshFace face_P = m.Faces[P];
                MeshFace face_Q = m.Faces[Q];
                int      p      = 0;
                int      q      = 0;
                for (int j = 0; j < 3; j++)
                {
                    if (!edge_ind.Contains(face_P[j]))
                    {
                        p = face_P[j];
                    }
                    if (!edge_ind.Contains(face_Q[j]))
                    {
                        q = face_Q[j];
                    }
                }
                /// Compute normals
                Vector3d normal_P = m.FaceNormals[P];
                Vector3d normal_Q = m.FaceNormals[Q];
                /// Compute h_P & cot_Pu
                Vector3d vec_up = verts[p] - verts[u];
                Vector3d vec_uv = verts[v] - verts[u];
                double   sin_Pu = (Vector3d.CrossProduct(vec_up, vec_uv) / (vec_up.Length * vec_uv.Length)).Length;
                double   cos_Pu = (vec_up * vec_uv) / (vec_up.Length * vec_uv.Length);
                double   cot_Pu = cos_Pu / sin_Pu;
                double   len_up = vec_up.Length;
                double   h_P    = len_up * sin_Pu;
                /// Compute cot_Pv
                Vector3d vec_vp = verts[p] - verts[v];
                Vector3d vec_vu = verts[u] - verts[v];
                double   sin_Pv = (Vector3d.CrossProduct(vec_vp, vec_vu) / (vec_vp.Length * vec_vu.Length)).Length;
                double   cos_Pv = (vec_vp * vec_vu) / (vec_vp.Length * vec_vu.Length);
                double   cot_Pv = cos_Pv / sin_Pv;
                /// Compute h_Q & cot_Qu
                Vector3d vec_uq = verts[q] - verts[u];
                double   sin_Qu = (Vector3d.CrossProduct(vec_uq, vec_uv) / (vec_uq.Length * vec_uv.Length)).Length;
                double   cos_Qu = (vec_uq * vec_uv) / (vec_uq.Length * vec_uv.Length);
                double   cot_Qu = cos_Qu / sin_Qu;
                double   len_uq = vec_uq.Length;
                double   h_Q    = len_uq * sin_Qu;
                /// Compute cot_Qv
                Vector3d      vec_vq        = verts[q] - verts[v];
                double        sin_Qv        = (Vector3d.CrossProduct(vec_vq, vec_vu) / (vec_vq.Length * vec_vu.Length)).Length;
                double        cos_Qv        = vec_vq * vec_vu / (vec_vq.Length * vec_vu.Length);
                double        cot_Qv        = cos_Qv / sin_Qv;
                List <double> normal_P_list = new List <double>();
                List <double> normal_Q_list = new List <double>();
                normal_P_list.Add(normal_P.X);
                normal_P_list.Add(normal_P.Y);
                normal_P_list.Add(normal_P.Z);
                normal_Q_list.Add(normal_Q.X);
                normal_Q_list.Add(normal_Q.Y);
                normal_Q_list.Add(normal_Q.Z);
                /// Compute coefficients
                double co_pv = (-1 * cot_Pv) / (cot_Pu + cot_Pv);
                double co_qv = (-1 * cot_Qv) / (cot_Qu + cot_Qv);
                double co_pu = (-1 * cot_Pu) / (cot_Pu + cot_Pv);
                double co_qu = (-1 * cot_Qu) / (cot_Qu + cot_Qv);
                /// Compute Jacobian
                for (int v_ind = 0; v_ind < verts.Count; v_ind++)
                {
                    if (v_ind == p)
                    {
                        for (int x = 0; x < 3; x++)
                        {
                            var.Add((normal_P_list[x] / (h_P)));
                            cind.Add(3 * v_ind + x);
                            rind.Add(i);
                        }
                    }
                    if (v_ind == q)
                    {
                        for (int x = 0; x < 3; x++)
                        {
                            var.Add((normal_Q_list[x] / (h_Q)));
                            cind.Add(3 * v_ind + x);
                            rind.Add(i);
                        }
                    }
                    if (v_ind == u)
                    {
                        for (int x = 0; x < 3; x++)
                        {
                            var.Add(((co_pv * (normal_P_list[x] / h_P) + co_qv * (normal_Q_list[x] / h_Q))));
                            cind.Add(3 * v_ind + x);
                            rind.Add(i);
                        }
                    }
                    if (v_ind == v)
                    {
                        for (int x = 0; x < 3; x++)
                        {
                            var.Add(((co_pu * (normal_P_list[x] / h_P) + co_qu * (normal_Q_list[x] / h_Q))));
                            cind.Add(3 * v_ind + x);
                            rind.Add(i);
                        }
                    }
                }
            }

            CRS Jaco = new CRS(var, rind, cind, n, verts.Count * 3);

            return(Jaco);
        }