Example #1
0
        public int Insert(JointVoxel voxel)
        {
            var data = new SearchData();

            //_tree.Search(voxel.BoundingBox, SearchCallback, data);
            _tree.Search(voxel.Sphere, SearchCallback, data);

            // voxel is contained in other voxel, return that containing index
            if (data.FoundSomething)
            {
                return(data.ContainedIndex);
            }

            // otherwise insert voxel in tree
            _tree.Insert(voxel.BoundingBox, voxel.Index);
            return(voxel.Index);
        }
Example #2
0
        public static IEnumerable <Joint> CreateJoints(IEnumerable <Beam> beams, double jointRadius, out Beam[] beamArray)
        {
            beamArray = (from beam in beams select beam.Duplicate()).ToArray();
            var indices        = Enumerable.Range(0, beamArray.Length);
            var beamIndexPairs = indices.Permutations().ToArray();
            var tol            = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;

            var jointTree     = new TragwerkTree();
            var beamTable     = new Dictionary <int, List <Beam> >();
            var voxelTable    = new Dictionary <int, JointVoxel>();
            var unusedIndices = new Stack <int>();

            ///TODO: write this method utilizing voxels
            /// The idea is to have an insert method on the voxel tree, which returns
            /// either the index integer of the voxel to be inserted
            /// or the index of another voxel containing this voxel
            /// From that we can build up our beamTable with its voxel indices
            /// storing lists of beams inside of them
            ///

            for (int i = 0; i < beamIndexPairs.Length; i++)
            {
                var curPair = beamIndexPairs[i];
                var beamA   = beamArray[curPair.Item1];
                var beamB   = beamArray[curPair.Item2];
                var iUsed   = false;

                var xEvents = Intersection.CurveCurve(beamA.Axis, beamB.Axis, tol * 2.0, 0.0);
                if (xEvents.Count == 0)
                {
                    unusedIndices.Push(i);
                    continue;
                }

                foreach (var curveIntersection in xEvents)
                {
                    if (!curveIntersection.IsPoint)
                    {
                        continue;
                    }
                    //var intPoint = RoundPoint(curveIntersection.PointA, tol);
                    var intPoint   = curveIntersection.PointA;
                    var voxelIndex = iUsed ? unusedIndices.Pop() : i;
                    var voxel      = new JointVoxel(intPoint, jointRadius, voxelIndex);

                    var index = jointTree.Insert(voxel);
                    if (i == index)
                    {
                        iUsed = true;
                    }

                    if (!beamTable.ContainsKey(index))
                    {
                        beamTable[index] = new List <Beam> {
                            beamA, beamB
                        };
                        voxelTable[index] = voxel;
                    }
                    else
                    {
                        // DEBUG WHY DO I NEED THIS LINE MCNEEEEEEEEEEEEL?!?!?!!?
                        // If it finds something in the tree it should mean it is contained right?
                        // WROOOOOOOOONG!!
                        if (voxelTable[index].Contains(intPoint))
                        {
                            if (!beamTable[index].Contains(beamA))
                            {
                                beamTable[index].Add(beamA);
                            }
                            if (!beamTable[index].Contains(beamB))
                            {
                                beamTable[index].Add(beamB);
                            }
                        }
                    }
                }

                if (!iUsed)
                {
                    unusedIndices.Push(i);
                }
            }

            return(from valuePair in beamTable select new Joint(valuePair.Value, voxelTable[valuePair.Key]));
        }
Example #3
0
 public Joint(List <Beam> beams, JointVoxel voxel)
 {
     Beams  = beams;
     Voxel  = voxel;
     Center = Voxel.Center;
 }