public void Hash()
        {
            var point1 = new FacePoint(new Point(10, 20), 0);
            var point2 = new FacePoint(new Point(10, 20), 1);

            var dictionary = new Dictionary <FacePoint, int>();

            dictionary.Add(point1, dictionary.Count);

            try
            {
                dictionary.Add(point2, dictionary.Count);
            }
            catch
            {
                Assert.True(false, $"{typeof(FacePoint)} must not throw exception.");
            }

            try
            {
                dictionary.Add(point2, dictionary.Count);
                Assert.True(false, $"{typeof(FacePoint)} must throw exception because key is duplicate.");
            }
            catch (ArgumentException)
            {
            }
        }
        public void Equal()
        {
            var point1 = new FacePoint(new Point(10, 20), 0);
            var point2 = new FacePoint(new Point(10, 20), 0);

            Assert.Equal(point1, point2);
            Assert.True(point1 == point2);
            Assert.True(point1.Equals(point2));
            Assert.False(point1 != point2);
        }
Example #3
0
 internal FacePoint(FacePoint other)
 {
     this.Index    = other.Index;
     this.Position = new Vector3(other.Position);
     this.Normals  = new Vector3(other.Normals);
     this.UV       = new Vector2[other.UV.Length];
     for (int i = 0; i < other.UV.Length; i++)
     {
         this.UV[i] = new Vector2(other.UV[i]);
     }
 }
Example #4
0
        internal CTMESH(GEOM geom)
        {
            if (geom.numberVertices > MAX_VERTICES)
            {
                throw new MeshException("This mesh has too many vertices and cannot be converted to a CAS Tools Mesh!");
            }
            if (geom.numberFaces > MAX_TRIANGLES)
            {
                throw new MeshException("This mesh has too many triangles and cannot be converted to a CAS Tools Mesh!");
            }

            this.vertices = new Vector3[geom.numberVertices];
            for (int i = 0; i < geom.numberVertices; i++)
            {
                this.vertices[i] = new Vector3(geom.getPosition(i));
            }

            faces = new Face[geom.numberFaces];
            for (int i = 0; i < geom.numberFaces; i++)
            {
                int[]       f      = geom.getFaceIndices(i);       //vertex indices
                FacePoint[] points = new FacePoint[3];

                for (int p = 0; p < 3; p++)                 //for each vertex in the face
                {
                    Vector3   pos  = new Vector3(geom.getPosition(f[p]));
                    Vector3   norm = new Vector3(geom.getNormal(f[p]));
                    Vector2[] uv   = new Vector2[geom.numberUVsets];
                    for (int u = 0; u < geom.numberUVsets; u++)
                    {
                        uv[u] = new Vector2(geom.getUV(f[p], u));
                    }
                    points[p] = new FacePoint(f[p], pos, norm, uv);
                }

                faces[i] = new Face(f, points);
            }
        }
Example #5
0
 public FaceDetector(string filename)
 {
     facePoint = new FacePoint();
     faceImg   = FindFaceDetector(filename);
 }
Example #6
0
 public FaceDetector()
 {
     facePoint = new FacePoint();
 }
 private static double Euclidean(FacePoint p1, FacePoint p2)
 {
     return(Math.Sqrt(Math.Pow(p1.Point.X - p2.Point.X, 2.0) + Math.Pow(p1.Point.Y - p2.Point.Y, 2.0)));
 }
Example #8
0
        internal void AutoUV(CTMESH reference, int UVset, int numberOfPoints)
        {
            if (reference.faces[0].points[0].UV.Length <= UVset)
            {
                throw new MeshException("Reference mesh does not have UV set " + UVset.ToString() + "!");
            }
            for (int i = 0; i < this.NumberFaces; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    while (this.faces[i].points[j].UV.Length <= UVset)
                    {
                        Vector2[] newUVs = new Vector2[this.faces[i].points[j].UV.Length + 1];
                        Array.Copy(this.faces[i].points[j].UV, newUVs, this.faces[i].points[j].UV.Length);
                        this.faces[i].points[j].UV = newUVs;
                    }
                }
            }

            Triangle[] tr = new Triangle[reference.NumberFaces];
            for (int i = 0; i < reference.NumberFaces; i++)
            {
                tr[i] = new Triangle(reference.faces[i].points[0].Position, reference.faces[i].points[1].Position, reference.faces[i].points[2].Position);
            }

            foreach (Face f in this.faces)
            {
                Triangle t        = new Triangle(f.points[0].Position, f.points[1].Position, f.points[2].Position);
                Face     nearFace = reference.faces[t.NearestTriangleIndex(tr)];

                for (int i = 0; i < 3; i++)
                {
                    Vector3   v         = f.points[i].Position;
                    FacePoint nearPoint = nearFace.points[v.NearestPointIndexSimple(nearFace.Positions)];

                    List <int> faceLinkedVerts = new List <int>();
                    foreach (Face fr in reference.faces)
                    {
                        List <int> tmp = new List <int>(fr.vertexIndices);
                        if (tmp.Contains(nearPoint.Index))
                        {
                            faceLinkedVerts.AddRange(tmp);
                        }
                    }
                    faceLinkedVerts = faceLinkedVerts.Distinct().ToList();

                    int[]     ind      = new int[numberOfPoints];
                    float[]   distance = new float[numberOfPoints];
                    Vector3[] position = new Vector3[numberOfPoints];
                    for (int ii = 0; ii < numberOfPoints; ii++)
                    {
                        distance[ii] = float.MaxValue;
                    }
                    foreach (int ii in faceLinkedVerts)
                    {
                        Vector3 pos = reference.vertices[ii];
                        if (v.positionMatches(pos))     //if position matches
                        {
                            ind      = new int[] { ii };
                            position = new Vector3[] { pos };
                            break;
                        }
                        float tmp = v.Distance(pos);
                        for (int j = 0; j < numberOfPoints; j++)
                        {
                            if (tmp <= distance[j])
                            {
                                for (int k = numberOfPoints - 2; k >= j; k--)
                                {
                                    ind[k + 1]      = ind[k];
                                    distance[k + 1] = distance[k];
                                    position[k + 1] = position[k];
                                }
                                ind[j]      = ii;
                                distance[j] = tmp;
                                position[j] = pos;
                                break;
                            }
                        }
                    }
                    float[] weights = v.GetInterpolationWeights(position, 2f);

                    float newU = 0f, newV = 0f;
                    for (int j = 0; j < weights.Length; j++)
                    {
                        Vector2 linkedUV = (reference.GetFacePointWithIndex(ind[j])).UV[UVset];
                        newU += linkedUV.X * weights[j];
                        newV += linkedUV.Y * weights[j];
                    }

                    f.points[i].UV[UVset] = new Vector2(newU, newV);
                }
            }
        }