Esempio n. 1
0
        GraphGenerator roomstuff(IList <Element> rooms, Document doc)
        {
            GraphGenerator gg = new GraphGenerator(doc);

            foreach (Element e in rooms)
            {
                Room room = e as Room;
                SpatialElementBoundaryOptions options = new SpatialElementBoundaryOptions();
                options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center;
                IList <IList <BoundarySegment> > segments = room.GetBoundarySegments(options);
                foreach (IList <BoundarySegment> list in segments)
                {
                    foreach (BoundarySegment element in list)
                    {
                        Element    sep  = doc.GetElement(element.ElementId);
                        Categories cats = doc.Settings.Categories;
                        ElementId  rsp  = cats.get_Item(BuiltInCategory.OST_RoomSeparationLines).Id;
                        ElementId  door = cats.get_Item(BuiltInCategory.OST_Doors).Id;
                        if (sep.Category.Id.Equals(rsp) || sep.Category.Id.Equals(door))
                        {
                            BoundingBoxXYZ bb    = sep.get_BoundingBox(null);
                            XYZ            n     = bb.Max - bb.Min;
                            XYZ            nn    = new XYZ(n.Y, -n.X, n.Z).Normalize();
                            XYZ            exitp = floorCenter(bb);
                            gg.AddRoomExit(nn, exitp, new RoomData {
                                Number = room.Number, Area = room.Area, Position = floorCenter(room.get_BoundingBox(null)), Vertices = GetPolygon(room, doc), Original = room
                            });
                        }
                    }
                }
            }
            gg.Final();
            return(gg);
        }
Esempio n. 2
0
 public static bool operator ==(RoomData a, RoomData b)
 {
     if ((object)a == null || (object)b == null)
     {
         return(false);
     }
     return(a.Number == b.Number && a.Area == b.Area && GraphGenerator.posEquals(a.Position, b.Position));
 }
Esempio n. 3
0
 XYZ getTarget(GraphGenerator gg, XYZ crowd)
 {
     foreach (ExitData e in gg.Exits)
     {
         foreach (RoomData rd in e.Rooms)
         {
             if (rd.Number.ToLower().Contains("outside"))
             {
                 return(e.Position);
             }
         }
     }
     throw new Exception("Not implemented.");
 }
Esempio n. 4
0
 public RoomRelationship(GraphGenerator gg)
 {
     InitializeComponent();
     graphGenerator = gg;
     foreach (ExitData ed in gg.Exits)
     {
         ListViewItem lbi = new ListViewItem();
         StackPanel   sp  = new StackPanel();
         sp.Orientation = Orientation.Horizontal;
         List <object> tlist = new List <object>();
         tlist.Add(ed);
         {
             TextBlock a = new TextBlock();
             a.Text = ed.Rooms[0].Number;
             TextBox valuer = new TextBox();
             valuer.Text  = ed.Weight2.ToString();
             valuer.Width = 30;
             TextBlock b = new TextBlock();
             b.Text = ed.Rooms[1].Number;
             sp.Children.Add(a);
             sp.Children.Add(valuer);
             sp.Children.Add(b);
             tlist.Add(valuer);
         }
         {
             TextBlock a = new TextBlock();
             a.Text = ed.Rooms[1].Number;
             TextBox valuer = new TextBox();
             valuer.Text  = ed.Weight1.ToString();
             valuer.Width = 30;
             TextBlock b = new TextBlock();
             b.Text = ed.Rooms[0].Number;
             sp.Children.Add(a);
             sp.Children.Add(valuer);
             sp.Children.Add(b);
             tlist.Add(valuer);
         }
         lbi.Tag     = tlist;
         lbi.Content = sp;
         lister.Items.Add(lbi);
     }
 }
Esempio n. 5
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document                 doc             = commandData.Application.ActiveUIDocument.Document;
            UIApplication            uiapp           = commandData.Application;
            FilteredElementCollector finalCollector  = new FilteredElementCollector(doc);
            FilteredElementCollector finalCollector2 = new FilteredElementCollector(doc);
            FilteredElementCollector finalCollector3 = new FilteredElementCollector(doc);
            IList <Element>          walls           = finalCollector.WherePasses(new ElementCategoryFilter(BuiltInCategory.OST_Walls)).WhereElementIsNotElementType().ToElements();
            IList <Element>          elem            = finalCollector2.OfCategory(BuiltInCategory.OST_GenericModel).ToElements();
            IList <Element>          rooms           = finalCollector3.OfCategory(BuiltInCategory.OST_Rooms).ToElements();
            var              crowdPoints             = elem.Where <Element>(o => o.Name.Contains("crowdPoint"));
            var              flagPoints = elem.Where <Element>(o => o.Name.Contains("flagPoint"));
            GraphGenerator   gg         = roomstuff(rooms, doc);
            RoomRelationship rr         = new RoomRelationship(gg);

            if (rr.ShowDialog() == true)
            {
                string file = exportFile(walls, crowdPoints, flagPoints, gg, doc, rr.GetGraphData());
                start(file);
            }
            return(Result.Succeeded);
        }
Esempio n. 6
0
        string exportFile(IList <Element> walls, IEnumerable <Element> crowdPoints, IEnumerable <Element> flagPoints, GraphGenerator data, Document doc, string graphData)
        {
            string         xmlfile    = "";
            BoundingBoxXYZ worldbound = getWorldBounds(walls, crowdPoints, flagPoints, doc);

            xmlfile  = "<SteerBenchTestCase xmlns=\"http://www.magix.ucla.edu/steerbench\" xmlns:xsi = \"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation = \"http://www.magix.ucla.edu/steerbenchTestCaseSchema.xsd\">";
            xmlfile += $@"<header>
    <version>1.0</version>
    <name>bottleneck-squeeze</name>
    <worldBounds>
      <xmin>{worldbound.Min.Y - 5}</xmin>
      <xmax>{worldbound.Max.Y + 5}</xmax>
      <ymin>0</ymin>
      <ymax>0</ymax>
      <zmin>{worldbound.Min.X - 5}</zmin>
      <zmax>{worldbound.Max.X + 5}</zmax>
    </worldBounds>
  </header>";
            XYZ worldCenter = floorCenter(worldbound);

            xmlfile += $@"<suggestedCameraView>
    <position> <x>44</x> <y>30</y> <z>0</z> </position>
    <lookat> <x>{worldCenter.X}</x> <y>0</y> <z>{worldCenter.Y}</z> </lookat>
    <up> <x>0</x> <y>1</y> <z>0</z> </up>
    <fovy>45</fovy></suggestedCameraView>";
            for (int i = 0; i < walls.Count; i++)
            {
                BoundingBoxXYZ bb = doc.GetElement(walls[i].Id).get_BoundingBox(doc.ActiveView);
                xmlfile += "<obstacle>";
                xmlfile += "<xmin>" + bb.Min.Y + "</xmin><xmax>" + bb.Max.Y + "</xmax>";
                xmlfile += "<ymin>" + bb.Min.Z + "</ymin><ymax>" + bb.Max.Z + "</ymax>";
                xmlfile += "<zmin>" + bb.Min.X + "</zmin><zmax>" + bb.Max.X + "</zmax>";
                xmlfile += "</obstacle>";
            }
            foreach (Element e in crowdPoints)
            {
                int            count  = Int32.Parse(e.Name.Replace("crowdPoint", ""));
                BoundingBoxXYZ bb     = doc.GetElement(e.Id).get_BoundingBox(null);
                XYZ            target = getTarget(data, floorCenter(bb));
                xmlfile += $@"<agentRegion>
    <numAgents>{count}</numAgents>
    <regionBounds>
      <xmin>{bb.Min.Y}</xmin>
      <xmax>{bb.Max.Y}</xmax>
      <ymin>{bb.Min.Z}</ymin>
      <ymax>{bb.Max.Z}</ymax>
      <zmin>{bb.Min.X}</zmin>
      <zmax>{bb.Max.X}</zmax>
    </regionBounds>
    <initialConditions>
      <direction> <random>true</random> </direction>
      <radius>0.5</radius>
      <speed>0</speed>
    </initialConditions>
    <goalSequence>
      <seekStaticTarget>
        <targetLocation> <x>{target.Y}</x> <y>{target.Z}</y> <z>{target.X}</z> </targetLocation>
        <desiredSpeed>1.3</desiredSpeed>
        <timeDuration>1000.0</timeDuration>
      </seekStaticTarget>
    </goalSequence>

  </agentRegion>";
            }
            xmlfile += graphData;
            xmlfile += getEvacuationTarget(flagPoints, doc);
            xmlfile += "</SteerBenchTestCase>";
            string filepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\";
            string filename = "";
            Random rand     = new Random(DateTime.Now.Millisecond);

            do
            {
                filename = "";
                for (int i = 0; i < 20; i++)
                {
                    filename += rand.Next(0, 10);
                }
            } while (File.Exists(filepath + filename + ".xml"));
            File.WriteAllText(filepath + filename + ".xml", xmlfile);
            return(filepath + @"\" + filename + ".xml");
        }