void ModernBuilding::run() { std::vector<double> roofColor; roofColor.push_back(0.66); roofColor.push_back(0.66); roofColor.push_back(0.66); std::vector<double> wallColor; wallColor.push_back(196./255.); wallColor.push_back(196./255.); wallColor.push_back(196./255.); std::vector<double> windowColor; windowColor.push_back(0.53); windowColor.push_back(0.81); windowColor.push_back(1); //Get simulation datastream DM::System * city = this->getData("city"); //Create building container DM::Component * building = city->addComponent(new Component(), buildings); //Set building parameters building->addAttribute("type", 1001); building->addAttribute("built_year", buildyear); building->addAttribute("stories", stories); building->addAttribute("stories_below", 0); //cellar counts as story building->addAttribute("stories_height",3 ); building->addAttribute("floor_area", l*b); building->addAttribute("gross_floor_area", l * b * stories); building->addAttribute("V_living", l*b*stories * 3); building->addAttribute("l_bounding", l); building->addAttribute("b_bounding", b); building->addAttribute("h_bounding", stories * 3); building->addAttribute("alpha_bounding", 0); building->addAttribute("alpha_roof", 0); building->addAttribute("cellar_used", 1); building->addAttribute("roof_used", 0); building->addAttribute("T_heating", heatingT); building->addAttribute("T_cooling", 26); //Building Footprint. Orientation matters. Check if the normal vector of the face is in your direction std::vector<DM::Node * > nodes_footprint; DM::Node * n1 = city->addNode(-l/2., -b/2., 0.); DM::Node * n2 = city->addNode( l/2., -b/2., 0.); DM::Node * n3 = city->addNode( l/2., b/2., 0.); DM::Node * n4 = city->addNode(-l/2., b/2., 0.); nodes_footprint.push_back(n1); nodes_footprint.push_back(n2); nodes_footprint.push_back(n3); nodes_footprint.push_back(n4); nodes_footprint.push_back(n1); //To a closed polygon last is first //Overhang DM::Node n1_c (-l/2. - overhang, -b/2. - overhang, 0.); DM::Node n2_c ( l/2. + overhang, -b/2. - overhang, 0.); DM::Node n3_c ( l/2. + overhang, b/2. + overhang, 0.); DM::Node n4_c (-l/2. - overhang, b/2. + overhang, 0.); std::vector<DM::Node> overhang_nodes; overhang_nodes.push_back(n1_c); overhang_nodes.push_back(n2_c); overhang_nodes.push_back(n3_c); overhang_nodes.push_back(n4_c); //Add Footprint DM::Face * footprint = city->addFace(nodes_footprint, footprints); Node n = DM::CGALGeometry::CalculateCentroid(city, footprint); building->addAttribute("centroid_x", n.getX()); building->addAttribute("centroid_y", n.getY()); //Set footprint as floor DM::Face * base_plate = city->addFace(nodes_footprint, geometry); building->getAttribute("Geometry")->addLink(base_plate, "Geometry"); //Define baseplate as cellar base_plate->addAttribute("type", "ceiling_cellar"); //Extrude Footprint for (int story = 0; story < stories; story++) { std::vector<DM::Face*> extruded_faces = TBVectorData::ExtrudeFace(city, geometry, nodes_footprint, 3); //last face in vector is ceiling int unsigned lastID = extruded_faces.size()-1; for (unsigned int i = 0; i < extruded_faces.size(); i++) { DM::Face * f = extruded_faces[i]; //if wall if (i != lastID) { //Add type f->addAttribute("type", "wall_outside"); //Add color f->getAttribute("color")->setDoubleVector(wallColor); //Create Windows every 5m with = 1.5m height = 1.0m std::vector<DM::Face* > windows = LittleGeometryHelpers::CreateHolesInAWall(city, f, w_distance, w_width, w_height, parapet); foreach (DM::Face * w, windows) { city->addComponentToView(w, this->geometry); w->addAttribute("type", "window"); w->getAttribute("color")->setDoubleVector(windowColor); building->getAttribute("Geometry")->addLink(w, "Geometry"); } } //if ceiling else if (story != stories -1){
void urbandevelBuilding::run() { DM::System * sys = this->getData("data"); std::vector<DM::Component *> cities = sys->getAllComponentsInView(cityview); std::vector<DM::Component *> parcels = sys->getAllComponentsInView(parcelview); if (cities.size() != 1 && paramfromCity) { DM::Logger(DM::Warning) << "One component expected. There are " << cities.size(); return; } DM::Component * currentcity = cities[0]; if (paramfromCity) { buildingyear = static_cast<int>(currentcity->getAttribute("year")->getDouble()); offset = static_cast<int>(currentcity->getAttribute("ratio")->getDouble()); } int cyclediff = -1; std::string triggertype = ""; if (genPopulation) { triggertype = currentcity->getAttribute("triggertype")->getString(); //DM::Logger(DM::Warning) << "pop " << cyclepopdiff << ";com " << cyclecomdiff << ";ind " << cycleinddiff; if ( !buildingtype.empty() && !triggertype.empty() ) { if ( buildingtype.compare("res") == 0 && buildingtype.compare(triggertype ) == 0) { cyclediff = static_cast<int>(currentcity->getAttribute("cyclepopdiff")->getDouble()); } else if ( buildingtype == "com" && buildingtype.compare(triggertype) == 0 ) cyclediff = static_cast<int>(currentcity->getAttribute("cyclecomdiff")->getDouble()); else if ( buildingtype == "ind" && buildingtype.compare(triggertype) == 0 ) cyclediff = static_cast<int>(currentcity->getAttribute("cycleinddiff")->getDouble()); } } int currentyear = static_cast<int>(currentcity->getAttribute("currentyear")->getDouble()); int startyear = static_cast<int>(currentcity->getAttribute("startyear")->getDouble()); if ( currentyear <= startyear+1 ) { std::vector<DM::Component *> buildings = sys->getAllComponentsInView(buildingview); for (int i = 0; i < buildings.size(); i++) { std::string bdyear = buildings[i]->getAttribute("year")->getString(); if ( bdyear.empty() ) { QString year = QString::number(startyear) + QString("-1-1"); std::string stdyear = year.toUtf8().constData(); buildings[i]->changeAttribute("year", stdyear); } } } int numberOfHouseBuild = 0; int numberOfPeople = 0; for (int i = 0; i < parcels.size(); i++) { DM::Face * currentparcel = dynamic_cast<DM::Face *>(parcels[i]); double parcel_area = TBVectorData::CalculateArea((DM::System*)sys, (DM::Face*)currentparcel); if (parcel_area < 300) { DM::Logger(DM::Debug) << "BD: parcel to small"; currentparcel->addAttribute("status","recreation"); continue; } std::string parcelstatus = currentparcel->getAttribute("status")->getString(); std::string parceltype = currentparcel->getAttribute("type")->getString(); int parcelheight_avg = static_cast<int>(currentparcel->getAttribute("height_avg")->getDouble()); int parcelheight_min = static_cast<int>(currentparcel->getAttribute("height_min")->getDouble()); int parcelheight_max = static_cast<int>(currentparcel->getAttribute("height_max")->getDouble()); std::string checkstatus = "process"; // do not generate houses if no population (if population should be generated) is available // OR no parcel status equals develop (if development should happen on signal) //DM::Logger(DM::Warning) << "CYCLEDIFF = " << cyclediff << "TYPE = " << buildingtype << parceltype; if ( genPopulation && cyclediff <= 0 ) continue; if ( onSignal ) { if ( parcelstatus.compare(checkstatus) != 0 ) { //DM::Logger(DM::Warning) << "BD: skipping parcel, status = " << parcelstatus; continue; } if (parceltype.compare(buildingtype) != 0 ) { //DM::Logger(DM::Warning) << "BD: skipping parcel, parceltype = " << parceltype << "buidlingtype = " << buildingtype; continue; } } std::vector<DM::Face *> f_off = this->createOffest(sys, currentparcel, offset); if (f_off.size() == 0) { currentparcel->addAttribute("status","recreation"); continue; } foreach (DM::Face * building, f_off) { sys->addComponentToView(building, buildingview); double roof_area = TBVectorData::CalculateArea((DM::System*)sys, (DM::Face*)building); double traffic_area = (parcel_area - roof_area)/3; double impervious_area = parcel_area - traffic_area - roof_area; int stories = static_cast<int>(parcelheight_min + (rand() % (int)(parcelheight_max - parcelheight_min + 1))); DM::Logger(DM::Debug) << "stories - max: " << parcelheight_max << " min: " << parcelheight_min << " calculated: " << stories; QString year = QString::number(currentyear) + QString("-1-1"); std::string stdyear = year.toUtf8().constData(); building->addAttribute("type", buildingtype); building->addAttribute("year", stdyear); building->addAttribute("stories", stories); building->addAttribute("roofarea", roof_area); building->addAttribute("roofarea_effective", 0.8); currentparcel->addAttribute("trafficarea", traffic_area); currentparcel->addAttribute("trafficarea_effective", 0.9); currentparcel->addAttribute("imperviousarea", impervious_area); currentparcel->addAttribute("imperviousarea_effective", 0.1); //Create Links building->getAttribute("PARCEL")->addLink(currentparcel, parcelview.getName()); currentparcel->getAttribute("BUILDING")->addLink(building, buildingview.getName()); numberOfHouseBuild++; if (genPopulation) { int peopleinbuilding = static_cast<int>(roof_area * stories / spacepp); cyclediff = std::max(cyclediff - peopleinbuilding,0); building->addAttribute("POP", peopleinbuilding); numberOfPeople = numberOfPeople + peopleinbuilding; if ( !buildingtype.empty() ) { if ( buildingtype.compare("res") == 0) { currentcity->addAttribute("cyclepopdiff", cyclediff); } else if ( buildingtype == "com") { currentcity->addAttribute("cyclecomdiff", cyclediff); } else if ( buildingtype == "ind") { currentcity->addAttribute("cycleinddiff", cyclediff); } else { currentcity->addAttribute("cyclepopdiff", cyclediff); } } } currentparcel->addAttribute("status", "populated"); building->addAttribute("height", stories*4); building->addAttribute("type", buildingtype); } //DM::Logger(DM::Warning) << "added face(s)"; }