void Current_RealisationModule::run() { DM::System * sys = this->getData("City"); DM::Component * cmp = new DM::Component(); sys->addComponent(cmp,Simu); cmp->addAttribute("MusicFileNo",atoi(this->RealisationNr.c_str())); }
void ImportRasterData2::run() { DM::System * sys = this->getData("Data"); DM::View data(dataname, DM::RASTERDATA, DM::WRITE); DM::RasterData * r = this->getRasterData("Data", data); QFile file(QString::fromStdString(FileName)); DM::Component * cmp = new DM::Component(); sys->addComponent(cmp,Coords); QTextStream stream(&file); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { DM::Logger(DM::Error) << "warning, read input file "; return; } QString line("NULL"); int LineCounter = 0; int rowCounter = 0; int ncols = 0; int nrows = 0; double xoffset = 0; double yoffset = 0; double cellsize = 0; double NoDataValue = -9999; //default //Read Header while (!line.isNull() && LineCounter < 6 ) { LineCounter++; line =stream.readLine(); if (LineCounter == 1) { QStringList list = line.split(QRegExp("\\s+")); QString s = QString(list[1]); s.replace(",", "."); ncols = s.toInt(); } if (LineCounter == 2) { QStringList list = line.split(QRegExp("\\s+")); QString s = QString(list[1]); s.replace(",", "."); nrows = s.toInt(); } if (LineCounter == 3) { QStringList list = line.split(QRegExp("\\s+")); QString s = QString(list[1]); s.replace(",", "."); xoffset = s.toDouble(); cmp->addAttribute("Xoffset",xoffset); } if (LineCounter == 4) { QStringList list = line.split(QRegExp("\\s+")); QString s = QString(list[1]); s.replace(",", "."); yoffset = s.toDouble(); cmp->addAttribute("Yoffset",yoffset); } if (LineCounter == 5) { QStringList list = line.split(QRegExp("\\s+")); QString s = QString(list[1]); s.replace(",", "."); cellsize = s.toDouble() * multiplier; } if (LineCounter == 6) { QStringList list = line.split(QRegExp("\\s+")); QString s = QString(list[1]); s.replace(",", "."); NoDataValue = s.toDouble(); } } std::cout <<" Cols " << ncols << std::endl; std::cout <<" Rows " << nrows << std::endl; std::cout <<" Cellsize " << cellsize << std::endl; r->setNoValue(NoDataValue); r->setSize(ncols, nrows, cellsize,cellsize,xoffset,yoffset); while (!line.isNull()) { LineCounter++; line =stream.readLine(); if (LineCounter >= 6 && rowCounter < nrows) { QStringList list = line.split(QRegExp("\\s+")); for ( int i = 0; i < list.size(); i++ ) { QString s = QString(list[i]); s.replace(",", "."); if (flip) r->setCell(i, nrows-rowCounter-1, s.toDouble()); else r->setCell(i, rowCounter, s.toDouble()); } rowCounter++; } } file.close(); }
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 PlaceJobs::run() { DM::System * city = this->getData("City"); std::vector<Component*> personCmps = city->getAllComponentsInView(persons); std::vector<int> person_rand_int_id; for (unsigned int i = 0; i < personCmps.size(); i++) { person_rand_int_id.push_back(i); } for (unsigned int i = 0; i < personCmps.size(); i++) { int index1 = rand() % person_rand_int_id.size(); int index2 = rand() % person_rand_int_id.size(); int p_id_tmp = person_rand_int_id[index1]; person_rand_int_id[index1] = person_rand_int_id[index2]; person_rand_int_id[index2] = p_id_tmp; } std::vector<Component*> gridCmps = city->getAllComponentsInView(grids); int job_id = 0; foreach(DM::Component * grid, gridCmps) { double jobsN = grid->getAttribute("jobs")->getDouble(); if (jobsN < 0.01) continue; //Calcualte Total Area Attribute * attrBuildings = grid->getAttribute("BUILDING"); double building_footprints_tot = 0; std::vector<Component*> linkedBuildings = attrBuildings->getLinkedComponents(); foreach(DM::Component* b, linkedBuildings) building_footprints_tot += b->getAttribute("area")->getDouble(); if (building_footprints_tot < 0.01) continue; //Create Jobs double JobperSqft = jobsN/building_footprints_tot; foreach(DM::Component* b, linkedBuildings) { double area = b->getAttribute("area")->getDouble(); int jobsInBuilding = (int) (area*JobperSqft + 0.5); for (int i = 0; i < jobsInBuilding; i++) { job_id++; DM::Component * job = new DM::Component(); //Person ID DM::Component * person = personCmps[person_rand_int_id[job_id]]; person->addAttribute("job_id", job_id); DM::Component * households = person->getAttribute("HOUSEHOLD")->getLinkedComponents()[0]; households->addAttribute("workers", households->getAttribute("workers")->getDouble()+1); job->addAttribute("id", job_id); job->addAttribute("home_based_status", 0); job->addAttribute("sector_id", 1); job->addAttribute("building_type", 1); Attribute lAttr("BUILDING", Attribute::LINK); lAttr.addLink(b, "BUILDING"); job->addAttribute(lAttr); city->addComponent(job, jobs); Attribute * lBAttr = b->getAttribute("JOB"); lBAttr->addLink(job, "JOB"); } b->addAttribute("non_residential_sqft", 20*jobsInBuilding*1.1); }