void Style::addData(TileData& _data, MapTile& _tile, const MapProjection& _mapProjection) { onBeginBuildTile(_tile); std::shared_ptr<VboMesh> mesh(newMesh()); for (auto& layer : _data.layers) { // Skip any layers that this style doesn't have a rule for auto it = m_layers.begin(); while (it != m_layers.end() && it->first != layer.name) { ++it; } if (it == m_layers.end()) { continue; } // Loop over all features for (auto& feature : layer.features) { /* * TODO: do filter evaluation for each feature for sublayer! * construct a unique ID for a the set of filters matched * use this ID pass to the style's parseStyleParams method to construct styleParam cache * NOTE: for the time being use layerName as ID for cache */ feature.props.numericProps["zoom"] = _tile.getID().z; switch (feature.geometryType) { case GeometryType::POINTS: // Build points for (auto& point : feature.points) { buildPoint(point, parseStyleParams(it->first, it->second), feature.props, *mesh); } break; case GeometryType::LINES: // Build lines for (auto& line : feature.lines) { buildLine(line, parseStyleParams(it->first, it->second), feature.props, *mesh); } break; case GeometryType::POLYGONS: // Build polygons for (auto& polygon : feature.polygons) { buildPolygon(polygon, parseStyleParams(it->first, it->second), feature.props, *mesh); } break; default: break; } } } onEndBuildTile(_tile, mesh); if (mesh->numVertices() == 0) { mesh.reset(); } else { mesh->compileVertexBuffer(); _tile.addGeometry(*this, mesh); } }
void drawPolygon(const char *name, const Polygon &polygon) { glfwSetWindowTitle(window, (tesselatorNames[tesselator] + ": " + name).c_str()); const auto shape = buildPolygon(polygon); glViewport(0, 0, fbWidth, fbHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(shape.midX - shape.ext, shape.midX + shape.ext, shape.midY + shape.ext, shape.midY - shape.ext, 0, 1); glMatrixMode(GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT); const auto &v = shape.vertices; const auto &x = shape.indices; // Draw triangle fill if (drawFill) { glBegin(GL_TRIANGLES); glColor3f(0.3f, 0.3f, 0.3f); for (const auto pt : x) { glVertex2f(v[pt][0], v[pt][1]); } glEnd(); } // Draw triangle mesh if (drawMesh) { glLineWidth(float(fbWidth) / width); glBegin(GL_LINES); glColor3f(1, 0, 0); for (size_t i = 0; i < x.size(); i += 3) { glVertex2f(v[x[i]][0], v[x[i]][1]); glVertex2f(v[x[i + 1]][0], v[x[i + 1]][1]); glVertex2f(v[x[i + 1]][0], v[x[i + 1]][1]); glVertex2f(v[x[i + 2]][0], v[x[i + 2]][1]); glVertex2f(v[x[i + 2]][0], v[x[i + 2]][1]); glVertex2f(v[x[i]][0], v[x[i]][1]); } glEnd(); } }
// ============================================================================ Teuchos::RCP<Recti::Domain::Abstract> Recti::Domain::Factory:: build() const { std::string domainType = pList_.get<std::string>("Type"); if ( domainType.compare("Circle")==0 ) return buildCircle(); else if ( domainType.compare("Ellipse")==0 ) return buildEllipse(); else if ( domainType.compare("Polygon")==0 ) return buildPolygon(); else if ( domainType.compare("Rectangle")==0 ) return buildRectangle(); else if ( domainType.compare("Square")==0 ) return buildSquare(); else { TEST_FOR_EXCEPTION( true, std::logic_error, "Unknown domain type \"" << domainType << "\"." ); } }
void Style::buildFeature(Tile& _tile, const Feature& _feat, const DrawRule& _rule) const { if (!checkRule(_rule)) { return; } bool visible; if (_rule.get(StyleParamKey::visible, visible) && !visible) { return; } auto& mesh = _tile.getMesh(*this); if (!mesh) { mesh.reset(newMesh()); } switch (_feat.geometryType) { case GeometryType::points: for (auto& point : _feat.points) { buildPoint(point, _rule, _feat.props, *mesh, _tile); } break; case GeometryType::lines: for (auto& line : _feat.lines) { buildLine(line, _rule, _feat.props, *mesh, _tile); } break; case GeometryType::polygons: for (auto& polygon : _feat.polygons) { buildPolygon(polygon, _rule, _feat.props, *mesh, _tile); } break; default: break; } }
void QtWaveformRendererFilteredSignal::draw(QPainter* painter, QPaintEvent* /*event*/) { const TrackPointer pTrack = m_waveformRenderer->getTrackInfo(); if (!pTrack) return; painter->save(); painter->setRenderHint(QPainter::Antialiasing); painter->resetTransform(); //visual gain float allGain(1.0); getGains(&allGain, NULL, NULL, NULL); double heightGain = allGain * (double)m_waveformRenderer->getHeight()/255.0; if (m_alignment == Qt::AlignTop) { painter->translate(0.0, 0.0); painter->scale(1.0, heightGain); } else if (m_alignment == Qt::AlignBottom) { painter->translate(0.0, m_waveformRenderer->getHeight()); painter->scale(1.0, heightGain); } else { painter->translate(0.0, m_waveformRenderer->getHeight()/2.0); painter->scale(1.0, 0.5*heightGain); } //draw reference line if (m_alignment == Qt::AlignCenter) { painter->setPen(m_pColors->getAxesColor()); painter->drawLine(0,0,m_waveformRenderer->getWidth(),0); } int numberOfPoints = buildPolygon(); if (m_pLowKillControlObject && m_pLowKillControlObject->get() > 0.1) { painter->setPen(QPen(m_lowKilledBrush, 0.0)); painter->setBrush(QColor(150,150,150,20)); } else { painter->setPen(QPen(m_lowBrush, 0.0)); painter->setBrush(m_lowBrush); } painter->drawPolygon(&m_polygon[0][0], numberOfPoints); if (m_pMidKillControlObject && m_pMidKillControlObject->get() > 0.1) { painter->setPen(QPen(m_midKilledBrush, 0.0)); painter->setBrush(QColor(150,150,150,20)); } else { painter->setPen(QPen(m_midBrush, 0.0)); painter->setBrush(m_midBrush); } painter->drawPolygon(&m_polygon[1][0], numberOfPoints); if (m_pHighKillControlObject && m_pHighKillControlObject->get() > 0.1) { painter->setPen(QPen(m_highKilledBrush, 0.0)); painter->setBrush(QColor(150,150,150,20)); } else { painter->setPen(QPen(m_highBrush, 0.0)); painter->setBrush(m_highBrush); } painter->drawPolygon(&m_polygon[2][0], numberOfPoints); painter->restore(); }
int main(int argc , char* argv[]) { if (argc < 7) { std::cerr << "usage: test <input file> <output folder> " "<format (wkt | geojson | sql)> <weight city> <weight town> <weight village>" << std::endl; exit(1); } char* input = argv[1]; char* outdir = argv[2]; char* format = argv[3]; char* swc = argv[4]; char* swt = argv[5]; char* swv = argv[6]; std::ifstream ifs(input); assert( ifs ); double wc, wt, wv; std::istringstream stmc, stmt, stmv; stmc.str(swc); stmc >> wc; stmt.str(swt); stmt >> wt; stmv.str(swv); stmv >> wv; std::cerr << "using weights: city: " << wc << ", town: " << wt << ", village: " << wv << std::endl; /* * prepare data */ // we use a ScalingFactor(SF) here to stretch input values at the // beginning, and divide by SF in the end. This is used because the // point-generation of the hyperbola class is using some arbitrary // internal decision thresholds to decide how many points to generate for // a certain part of the curve. Rule of thumb is: the higher SF the more // detail is used in approximation of the hyperbolas. double SF = 4000; // read in sites from input file SiteList sites = readSites(ifs, SF, wc, wt, wv); printSites(sites); // calculate bounding box of all input sites (and extend it a little). // Extension is important, because we later add artificial sites which are // actually mirrored on the bounds of this rectangle. If we did not extend // some points would lie on the boundary of the bounding box and so would // their artificial clones. This would complicate the whole stuff a lot :) Iso_rectangle_2 crect = extend(boundingBox(sites), 0.1*SF); std::cerr << "rect: " << crect << std::endl; // a number of artificial sites SiteList artificialSites = createArtificialSites(sites, crect); /* * create Apollonius graph */ Apollonius_graph ag; SiteList::iterator itr; // add all original sites to the apollonius graph for (itr = sites.begin(); itr != sites.end(); ++itr) { Site_2 site = *itr; ag.insert(site); } // add all artificial sites to the apollonius graph for (itr = artificialSites.begin(); itr != artificialSites.end(); ++itr) { Site_2 site = *itr; ag.insert(site); } // validate the Apollonius graph assert( ag.is_valid(true, 1) ); std::cerr << std::endl; /* * create polygons from cells */ // we want an identifier for each vertex within the iteration. // this is a loop iteration counter int vertexIndex = 0; // for each vertex in the apollonius graph (this are the sites) for (All_vertices_iterator viter = ag.all_vertices_begin (); viter != ag.all_vertices_end(); ++viter) { // get the corresponding site Site_2 site = viter->site(); Point_2 point = site.point(); // ignore artifical sites, detect them by their position if (!CGAL::do_intersect(crect, point)) { continue; } std::cerr << "vertex " << ++vertexIndex << std::endl; // we than circulate all incident edges. By obtaining the respective // dual of each edge, we get access to the objects forming the boundary // of each voronoi cell in a proper order. Edge_circulator ecirc = ag.incident_edges(viter), done(ecirc); // this is where we store the polylines std::vector<PointList> polylines; // for each incident edge do { // the program may fail in certain situations without this test. // acutally !is_infinite(edge) is a precondition in ag.dual(edge). if (ag.is_infinite(*ecirc)) { continue; } // NOTE: for this to work, we had to make public the dual function in ApolloniusGraph // change line 542 in "Apollonius_graph_2.h" from "private:" to "public:" Object_2 o = ag.dual(*ecirc); handleDual(o, crect, polylines); } while(++ecirc != done); PointList polygon = buildPolygon(site, polylines); for (int i = 0; i < polygon.size(); i++) { Point_2& p = polygon.at(i); p = Point_2(p.x()/SF, p.y()/SF); } if(std::string(format) == "geojson") { writeGeoJSON(site, polygon, outdir); } else if(std::string(format) == "sql") { writeSQL(site, polygon, outdir); } else { writeWKT(site, polygon, outdir); } // check each point for (int i = 0; i < polygon.size(); i++) { Point_2 p = polygon.at(i); if (p.x() > crect.xmax()/SF || p.x() < crect.xmin()/SF || p.y() > crect.ymax()/SF || p.y() < crect.ymin()/SF) { std::cerr << "out of bounds" << std::endl; } } } }