Ejemplo n.º 1
0
        //Track contour line with BFS.
        private void bfs(int s, ContourLine line)
        {
            Queue <int> queue = new Queue <int>();

            queue.Enqueue(s);
            while (queue.Count != 0)
            {
                Element e = elements[queue.Dequeue()];
                e.Flag = true;
                if (e.Type == ContourType.T011 || e.Type == ContourType.T100)
                {
                    line.Points.Add(e.Intersections[1]);
                    line.Points.Add(e.Intersections[2]);
                }
                if (e.Type == ContourType.T101 || e.Type == ContourType.T010)
                {
                    line.Points.Add(e.Intersections[0]);
                    line.Points.Add(e.Intersections[1]);
                }
                if (e.Type == ContourType.T110 || e.Type == ContourType.T001)
                {
                    line.Points.Add(e.Intersections[0]);
                    line.Points.Add(e.Intersections[2]);
                }
                for (int i = 0; i < 3; i++)
                {
                    if (e.NeighborIndices[i] != -1 && (elements[e.NeighborIndices[i]].Flag == false))
                    {
                        queue.Enqueue(e.NeighborIndices[i]);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private void GetLines(float value)
 {
     //init all elements
     foreach (var v in elements)
     {
         v.Flag = false;
         int t = 0;
         for (int i = 2; i >= 0; i--)
         {
             t <<= 1;
             if (values[v.VertIndices[i]] > value)
             {
                 t += 1;
             }
         }
         v.Type = (ContourType)t;
         //Ignore no-contour element.
         if (v.Type == ContourType.T000 || v.Type == ContourType.T111)
         {
             v.Flag = true;
         }
         //Interpolate contour point.
         if (v.Type == ContourType.T011 || v.Type == ContourType.T100)
         {
             v.Intersections[1] = Linear(points[v.VertIndices[1]], values[v.VertIndices[1]], points[v.VertIndices[2]], values[v.VertIndices[2]], value);
             v.Intersections[2] = Linear(points[v.VertIndices[0]], values[v.VertIndices[0]], points[v.VertIndices[2]], values[v.VertIndices[2]], value);
         }
         if (v.Type == ContourType.T101 || v.Type == ContourType.T010)
         {
             v.Intersections[1] = Linear(points[v.VertIndices[1]], values[v.VertIndices[1]], points[v.VertIndices[2]], values[v.VertIndices[2]], value);
             v.Intersections[0] = Linear(points[v.VertIndices[0]], values[v.VertIndices[0]], points[v.VertIndices[1]], values[v.VertIndices[1]], value);
         }
         if (v.Type == ContourType.T110 || v.Type == ContourType.T001)
         {
             v.Intersections[0] = Linear(points[v.VertIndices[0]], values[v.VertIndices[0]], points[v.VertIndices[1]], values[v.VertIndices[1]], value);
             v.Intersections[2] = Linear(points[v.VertIndices[0]], values[v.VertIndices[0]], points[v.VertIndices[2]], values[v.VertIndices[2]], value);
         }
     }
     //Find all contour lines.
     for (int l = 0; l < elemCount; l++)
     {
         if (elements[l].Flag)
         {
             continue;
         }
         Element e = elements[l];
         if (e.Type == ContourType.T000 || e.Type == ContourType.T111)
         {
             e.Flag = true;
             continue;
         }
         ContourLine line = new ContourLine(Color.Black);
         bfs(l, line);
         line.GeneVertList();
         if (line.Verts.Length >= 2)
         {
             lines.Add(line);
         }
     }
 }