void MatrixOp::normalizeRow(const Ring& R, Vector& x) { typename Vector::iterator i_x = x.begin (); typename Ring::Element inv; Context<Ring> ctx (R); if(x.empty ()) return; if(R.inv(inv, i_x->second) != true) //should be invertible throw "Non Invertible Value"; BLAS1::scal(ctx, inv, x); //Lela implementation is buggy over non primes P! handle it }
// The general idea here is to, conceptually, start with the original polygon and slide // the vertices along the bisectors until the first intersection. At that // point two of the edges collapse and the process repeats on the new polygon. // The polygon state is captured in the Ring class while the GrAAConvexTessellator // controls the iteration. The CandidateVerts holds the formative points for the // next ring. bool GrAAConvexTessellator::tessellate(const SkMatrix& m, const SkPath& path) { if (!this->extractFromPath(m, path)) { return false; } SkScalar coverage = 1.0f; if (fStrokeWidth >= 0.0f) { Ring outerStrokeRing; this->createOuterRing(fInitialRing, fStrokeWidth / 2 - kAntialiasingRadius, coverage, &outerStrokeRing); outerStrokeRing.init(*this); Ring outerAARing; this->createOuterRing(outerStrokeRing, kAntialiasingRadius * 2, 0.0f, &outerAARing); } else { Ring outerAARing; this->createOuterRing(fInitialRing, kAntialiasingRadius, 0.0f, &outerAARing); } // the bisectors are only needed for the computation of the outer ring fBisectors.rewind(); if (fStrokeWidth >= 0.0f && fInitialRing.numPts() > 2) { Ring* insetStrokeRing; SkScalar strokeDepth = fStrokeWidth / 2 - kAntialiasingRadius; if (this->createInsetRings(fInitialRing, 0.0f, coverage, strokeDepth, coverage, &insetStrokeRing)) { Ring* insetAARing; this->createInsetRings(*insetStrokeRing, strokeDepth, coverage, strokeDepth + kAntialiasingRadius * 2, 0.0f, &insetAARing); } } else { Ring* insetAARing; this->createInsetRings(fInitialRing, 0.0f, 0.5f, kAntialiasingRadius, 1.0f, &insetAARing); } SkDEBUGCODE(this->validate();) return true;
inline bool operator()(Ring const& ring) const { if (ring.size() >= core_detail::closure::minimum_ring_size < geometry::closure<Ring>::value >::value) { double a = area(ring); double p = perimeter(ring); return geometry::math::abs(a / p) < m_ratio; } // Rings with less then 4 points (including closing) // are also considered as small and thus removed return true; }
int main(){ Ring<string> rs; rs.push_back("one"); rs.push_back("two"); rs.push_back("three"); rs.push_back("four"); rs.push_back("five"); Ring<string>::iterator it = rs.begin(); ++it; ++it; it.insert("six"); it = rs.begin(); //twice around the ring for(int i=0; i< rs.size()*2; i++) cout << *it++ << endl; }
int main(int argc, char* argv[]) { Ring<string> rs; rs.push_back("one"); rs.push_back("two"); rs.push_back("three"); rs.push_back("four"); rs.push_back("five"); Ring<string>::iterator it = rs.begin(); it++; it++; it.insert("six"); it = rs.begin(); // Twice around the ring: for (int i = 0; i < rs.size()*2; i++) { cout << *it++ << endl; } return 0; } ///:~
inline bool operator()(Ring const& ring) const { return ring.size() < 4; }
size_t StructuredGauss::echelonize_reduced(const Ring& R, Matrix& A) { #ifdef SHOW_PROGRESS std::ostream &report = commentator.report (Commentator::LEVEL_NORMAL, INTERNAL_DESCRIPTION); #endif Context<Ring> ctx(R); uint32 coldim = A.coldim (); uint32 npiv = 0; //number of pivots found so far uint32 N = A.rowdim(); uint32 piv[N]; uint32 pivot_rows_index[coldim]; typename Matrix::Row::const_iterator it, end_iterator; typename Matrix::RowIterator i_A; typename Ring::Element a; typename Ring::Element tmpDenseArray[coldim]; for (uint i = 0; i < coldim; ++i) { pivot_rows_index[i] = 0; } //make sure first row is not null for (uint i=0; i < N; ++i) { if(!isRowNull(A[i])) { if(i!= 0) swapRows(A[i], A[0]); normalizeRow(R, A[0]); piv[npiv] = 0; npiv++; pivot_rows_index[head_generic(ctx, a, A[0])] = 0+1; //indexes are +1 shifted, 0 means no row is at this index break; } } commentator.start("First reduction", __FUNCTION__); uint32 new_entry, curr_head; uint32 j, i=1; i_A = A.rowBegin (); ++i_A; for(; i_A != A.rowEnd (); ++i_A, ++i) { #ifdef SHOW_PROGRESS report << " \r"; report << "\t" << npiv; #endif curr_head = head_generic(ctx, a, *i_A); razArray_in(R, tmpDenseArray, coldim); copySparseVectorToDenseArray_in(R, i_A->begin (), i_A->end (), tmpDenseArray); for (j=0; j < npiv; ++j) { register typename Ring::Element h_a = R.zero (); if(head_generic(ctx, h_a, A[piv[j]]) < curr_head) continue; it = A[piv[j]].begin (); end_iterator = A[piv[j]].end (); if(it != end_iterator) { if(R.isZero(tmpDenseArray[it->first])) continue; else { R.copy(h_a, tmpDenseArray[it->first]); R.negin(h_a); } } #ifdef PRAGMA_UNROLL register uint32 x=0, xl = A[piv[j]].size () % 32; while(x<xl) { R.axpyin(tmpDenseArray[it->first], h_a, it->second); ++x; ++it; } for(x=xl; x<A[piv[j]].size (); x+=32) { //#pragma unroll(32) for(char t=0; t<32; ++t) { R.axpyin(tmpDenseArray[(it+t)->first], h_a, (it+t)->second); } it += 32; } #else while (it != end_iterator) { R.axpyin(tmpDenseArray[it->first], h_a, it->second); ++it; } #endif } copyDenseArrayToSparseVector_in(R, tmpDenseArray, coldim, *i_A); normalizeRow(R, *i_A); new_entry = head_generic(ctx, a, *i_A); if(!isRowNull( *i_A ) && pivot_rows_index[new_entry]==0) { piv[npiv] = i; npiv++; pivot_rows_index[new_entry] = i+1; //new_entry must not be -1 since the row is not empty } } #ifdef SHOW_PROGRESS report << "\r " << std::endl; #endif commentator.stop(MSG_DONE); commentator.start("Second reduction", __FUNCTION__); for (uint i = 0; i < npiv; ++i) { #ifdef SHOW_PROGRESS report << " \r"; report << "\t" << i; #endif razArray_in(R, tmpDenseArray, coldim); copySparseVectorToDenseArray_in(R, A[piv[i]], tmpDenseArray); //there is no reason to start from the begining, because this row had already been eliminated by all //the pivots discovered before it in the previous loop for (uint j = i+1; j < npiv; ++j) //npiv; ++j) { //TODO change this { it = A[piv[j]].begin (); //this vector is garanteed not to be null since it's in the pivot list end_iterator = A[piv[j]].end (); register typename Ring::Element h_a = R.zero (); if(R.isZero(tmpDenseArray[it->first])) continue; else { R.copy(h_a, tmpDenseArray[it->first]); R.negin(h_a); } #ifdef PRAGMA_UNROLL register uint32 x=0, xl = A[piv[j]].size () % 32; while(x<xl) { R.axpyin(tmpDenseArray[it->first], h_a, it->second); ++x; ++it; } for(x=xl; x<A[piv[j]].size (); x+=32) { //#pragma unroll(32) for(char t=0; t<32; ++t) { R.axpyin(tmpDenseArray[(it+t)->first], h_a, (it+t)->second); } it += 32; } #else while (it != end_iterator) { R.axpyin(tmpDenseArray[it->first], h_a, it->second); ++it; } #endif } copyDenseArrayToSparseVector_in(R, tmpDenseArray, coldim, A[piv[i]]); } #ifdef SHOW_PROGRESS report << "\r " << std::endl; #endif commentator.stop(MSG_DONE); commentator.start("Sorting pivots", __FUNCTION__); sortRows(A, pivot_rows_index); commentator.stop(MSG_DONE); return npiv; }
void Polygon::push_back (Ring &ring) { if ((empty() && !ring.is_ccw()) || (!empty() && ring.is_ccw())) ring.reverse_orientation(); this->Polygon_base::push_back(ring); }
void BuildGeometryFilter::tileAndBuildPolygon(Geometry* ring, const SpatialReference* featureSRS, const SpatialReference* mapSRS, bool makeECEF, bool tessellate, osg::Geometry* osgGeom, const osg::Matrixd &world2local) { #define MAX_POINTS_PER_CROP_TILE 1024 #define TARGET_TILE_SIZE_EXTENT_DEGREES 5.0 // Tile the incoming polygon if necessary GeometryCollection tiles; prepareForTesselation( ring, featureSRS, TARGET_TILE_SIZE_EXTENT_DEGREES, MAX_POINTS_PER_CROP_TILE, tiles); osg::ref_ptr<osg::Geode> geode = new osg::Geode; // Process each ring independently for (int ringIndex = 0; ringIndex < tiles.size(); ringIndex++) { Ring* geom = dynamic_cast< Ring*>(tiles[ringIndex].get()); if (geom) { // temporary target geometry for this cell: osg::ref_ptr<osg::Geometry> temp = new osg::Geometry(); temp->setVertexArray( new osg::Vec3Array() ); // establish a local plane for this cell based on its centroid: GeoPoint cellCenter(featureSRS, geom->getBounds().center()); cellCenter.transform(mapSRS, cellCenter); osg::Matrix world2cell; cellCenter.createWorldToLocal( world2cell ); // build the localized polygon: buildPolygon(geom, featureSRS, mapSRS, makeECEF, tessellate, temp.get(), world2cell); // if successful, transform the verts back into our master LTP: if ( temp->getNumPrimitiveSets() > 0 ) { // Tesselate the polygon while the coordinates are still in the LTP if (tesselateGeometry( temp.get() )) { osg::Vec3Array* verts = static_cast<osg::Vec3Array*>(temp->getVertexArray()); if ( verts->getNumElements() > 0 ) { // Convert the coordinates back to the master LTP. // This is ok, but you will probably run into precision errors if the tile size is very large. osg::Matrix cell2world; cell2world.invert( world2cell ); osg::Matrix cell2local = cell2world * world2local; // pre-multiply to avoid precision loss for(int i=0; i<verts->size(); ++i) { (*verts)[i] = (*verts)[i] * cell2local; } geode->addDrawable(temp.get()); } } } } } // The geode is going to contain all of our polygons now, so merge them into one. osgUtil::Optimizer optimizer; osgUtil::Optimizer::MergeGeometryVisitor mgv; // We only want one Geometry, so don't limit the number of vertices. mgv.setTargetMaximumNumberOfVertices(UINT_MAX); mgv.apply( *geode.get() ); // and copy them into the output geometry. if ( geode->getNumDrawables() > 0 ) { // If we have more than one drawable after the MergeGeometryVisitor ran, we have a problem so // dump out some info to help debug. if (geode->getNumDrawables() != 1) { OE_WARN << LC << "MergeGeometryVisitor failed to merge geometries into a single one. Num drawables " << geode->getNumDrawables() << std::endl; for (unsigned int i = 0; i < geode->getNumDrawables(); i++) { osg::Geometry* g = geode->getDrawable(i)->asGeometry(); if (g) { osg::Vec3Array* verts = dynamic_cast<osg::Vec3Array*>(g->getVertexArray()); OE_WARN << "Geometry " << i << " has " << verts->size() << " verts" << std::endl; OE_WARN << "Geometry " << i << " has " << g->getNumPrimitiveSets() << " primitive sets" << std::endl; for (unsigned int j = 0; j < g->getNumPrimitiveSets(); j++) { osg::PrimitiveSet* ps = g->getPrimitiveSet(j); OE_WARN << "PrimitiveSet " << j << ps->className() << std::endl; } } } } osgGeom->setVertexArray( geode->getDrawable(0)->asGeometry()->getVertexArray() ); osgGeom->setPrimitiveSetList( geode->getDrawable(0)->asGeometry()->getPrimitiveSetList() ); } osgUtil::SmoothingVisitor::smooth( *osgGeom ); }
bool testGaussTransform (const Ring &F, size_t m, size_t n) { commentator.start ("Testing GaussJordan::echelonize", __FUNCTION__); std::ostream &report = commentator.report (Commentator::LEVEL_NORMAL, INTERNAL_DESCRIPTION); std::ostream &error = commentator.report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR); bool pass = true; DenseMatrix<typename Ring::Element> R (m, n); RandomDenseStream<Ring, typename DenseMatrix<typename Ring::Element>::Row> A_stream (F, n, m); DenseMatrix<typename Ring::Element> A (A_stream), A_copy (m, n); typename GaussJordan<Ring>::Permutation P; Context<Ring> ctx (F); Elimination<Ring> elim (ctx); GaussJordan<Ring> GJ (ctx); size_t rank; typename Ring::Element det; BLAS3::copy (ctx, A, R); BLAS3::copy (ctx, A, A_copy); GJ.echelonize (R, P, rank, det); report << "A = " << std::endl; BLAS3::write (ctx, report, A); report << "P = "; BLAS1::write_permutation (report, P.begin (), P.end ()) << std::endl; report << "R, L = " << std::endl; BLAS3::write (ctx, report, R); BLAS3::permute_rows (ctx, P.begin (), P.end (), A); report << "PA = " << std::endl; BLAS3::write (ctx, report, A); typename DenseMatrix<typename Ring::Element>::SubmatrixType Rp (R, 0, 0, R.rowdim (), R.rowdim ()); BLAS3::trmm (ctx, F.one (), Rp, A, LowerTriangular, true); report << "LPA = " << std::endl; BLAS3::write (ctx, report, A); report << "Computed rank = " << rank << std::endl; report << "Computed det = "; F.write (report, det); report << std::endl; // Trick to eliminate part below diagonal so that equality-check works elim.move_L (R, R); if (!BLAS3::equal (ctx, A, R)) { error << "ERROR: LPA != R" << std::endl; pass = false; } elim.echelonize (A_copy, P, rank, det, false); report << "Result of Elimination::echelonize: " << std::endl; BLAS3::write (ctx, report, A_copy); if (!BLAS3::equal (ctx, A_copy, R)) { error << "ERROR: Results from Elimination and GaussJordan not equal" << std::endl; pass = false; } commentator.stop (MSG_STATUS (pass)); return pass; }
FilterContext push(FeatureList& input, FilterContext& context) { if (_featureSource.valid()) { // Get any features that intersect this query. FeatureList boundaries; getFeatures(context.extent().get(), boundaries ); // The list of output features FeatureList output; if (boundaries.empty()) { // No intersecting features. If contains is false, then just the output to the input. if (contains() == false) { output = input; } } else { // Transform the boundaries into the coordinate system of the features for (FeatureList::iterator itr = boundaries.begin(); itr != boundaries.end(); ++itr) { itr->get()->transform( context.profile()->getSRS() ); } for(FeatureList::const_iterator f = input.begin(); f != input.end(); ++f) { Feature* feature = f->get(); if ( feature && feature->getGeometry() ) { osg::Vec2d c = feature->getGeometry()->getBounds().center2d(); if ( contains() == true ) { // coarsest: if (_featureSource->getFeatureProfile()->getExtent().contains(GeoPoint(feature->getSRS(), c.x(), c.y()))) { for (FeatureList::iterator itr = boundaries.begin(); itr != boundaries.end(); ++itr) { Ring* ring = dynamic_cast< Ring*>(itr->get()->getGeometry()); if (ring && ring->contains2D(c.x(), c.y())) { output.push_back( feature ); } } } } else { bool contained = false; // coarsest: if (_featureSource->getFeatureProfile()->getExtent().contains(GeoPoint(feature->getSRS(), c.x(), c.y()))) { for (FeatureList::iterator itr = boundaries.begin(); itr != boundaries.end(); ++itr) { Ring* ring = dynamic_cast< Ring*>(itr->get()->getGeometry()); if (ring && ring->contains2D(c.x(), c.y())) { contained = true; break; } } } if ( !contained ) { output.push_back( feature ); } } } } } OE_INFO << LC << "Allowed " << output.size() << " out of " << input.size() << " features\n"; input = output; } return context; }
void MatrixUtils::loadF4Matrix(const Ring &R, SparseMatrix<typename Ring::Element>& A, const char *fileName) { std::ostream &report = commentator.report(Commentator::LEVEL_NORMAL, INTERNAL_DESCRIPTION); // Code adapted from C version of dump_matrix.c FILE *f = fopen(fileName, "r"); if (f == NULL) { commentator.report(Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR) << "Can't open " << fileName << std::endl; throw std::runtime_error ("Can't open file"); } unsigned short int *nz, *onz; unsigned int *pos, *opos; unsigned int *sz, *osz; unsigned int n; unsigned int m; unsigned int mod; unsigned long long nb; if (fread(&n, sizeof(unsigned int), 1, f) != 1) throw std::runtime_error ("Error while reading file"); if (fread(&m, sizeof(unsigned int), 1, f) != 1) throw std::runtime_error ("Error while reading file"); if (fread(&mod, sizeof(unsigned int), 1, f) != 1) throw std::runtime_error ("Error while reading file"); if (fread(&nb, sizeof(unsigned long long), 1, f) != 1) throw std::runtime_error ("Error while reading file"); report << "loading file " << fileName << std::endl; report << n << " x " << m << " matrix" << std::endl; report << "mod " << mod << std::endl; { double Nz = (double) (n) * (double) (m); Nz = (double) (nb) / Nz; Nz *= 100.0; report << "Nb of Nz elements " << nb << " (density " << Nz << ")" << std::endl; } A = SparseMatrix<typename Ring::Element> (n, m); typename SparseMatrix<typename Ring::Element>::RowIterator i_A; uint32 i; onz = nz = (unsigned short int*) malloc(nb * sizeof(unsigned short int)); opos = pos = (unsigned int*) malloc(nb * sizeof(unsigned int)); osz = sz = (unsigned int*) malloc(n * sizeof(unsigned int)); if (fread(nz, sizeof(short int), nb, f) != nb) throw std::runtime_error ("Error while reading file"); if (fread(pos, sizeof(unsigned int), nb, f) != nb) throw std::runtime_error ("Error while reading file"); if (fread(sz, sizeof(unsigned int), n, f) != n) throw std::runtime_error ("Error while reading file"); for (i_A = A.rowBegin(), i = 0; i < n; i++, ++i_A) { const unsigned int szi = sz[i]; unsigned int j; i_A->reserve(szi); for (j = 0; j < szi; j++) { i_A->push_back( typename Vector<Ring>::Sparse::value_type(pos[j], typename Ring::Element())); R.init(i_A->back().second, nz[j]); } nz += szi; pos += szi; } //free memory free(onz); free(opos); free(osz); fclose(f); }
bool testRandomSolve (const Ring& R, const Field& f, LinBox::VectorStream<Vector>& stream1, LinBox::VectorStream<Vector>& stream2) { std::ostringstream str; commentator().start ("Testing Nonsingular Random Diagonal solve ", "testNonsingularRandomDiagonalSolve"); bool ret = true; bool iter_passed = true; VectorDomain<Ring> VD (R); Vector d, b, x, y; VectorWrapper::ensureDim (d, stream1.n ()); VectorWrapper::ensureDim (b, stream1.n ()); VectorWrapper::ensureDim (x, stream1.n ()); VectorWrapper::ensureDim (y, stream1.n ()); int n = (int)d. size(); while (stream1 && stream2) { commentator().startIteration ((unsigned)stream1.j ()); //ActivityState state = commentator().saveActivityState (); iter_passed = true; bool zeroEntry; do { stream1.next (d); zeroEntry = false; for (size_t i=0; i<stream1.n(); i++) zeroEntry |= R.isZero(d[i]); } while (zeroEntry); stream2.next (b); std::ostream &report = commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_DESCRIPTION); report << "Diagonal entries: "; VD.write (report, d); report << endl; report << "Right-hand side: "; VD.write (report, b); report << endl; //Diagonal<Ring> D(R, d); BlasMatrix<Ring> D(R, n, n); for(int i = 0; i < n; ++i) R.init (D[i][i], d[i]); typedef RationalSolverAdaptive RSolver; RSolver rsolver; //std::vector<std::pair<typename Ring::Element, typename Ring::Element> > answer(n); std::vector<typename Ring::Element> num(n); typename Ring::Element den; SolverReturnStatus solveResult = rsolver.solveNonsingular(num, den, D, b); //often 5 primes are not enough #if 0 typename Ring::Element lden; R. init (lden, 1); typename std::vector<std::pair<typename Ring::Element, typename Ring::Element> >::iterator p; for (p = answer.begin(); p != answer.end(); ++ p) R. lcm (lden, lden, p->second); typename Vector::iterator p_x; //typename Vector::iterator p_y; #endif if (solveResult == SS_OK) { #if 0 for (p = answer.begin(), p_x = x. begin(); p != answer.end(); ++ p, ++ p_x) { R. mul (*p_x, p->first, lden); R. divin (*p_x, p->second); } D. apply (y, x); #endif D. apply (y, num); VD. mulin(b, den); if (!VD.areEqual (y, b)) { ret = iter_passed = false; commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR) << "ERROR: Computed solution is incorrect" << endl; } } else { ret = iter_passed = false; commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR) << "ERROR: Did not return OK solving status" << endl; } commentator().stop ("done"); commentator().progress (); } stream1.reset (); stream2.reset (); commentator().stop (MSG_STATUS (ret), (const char *) 0, "testNonsingularRandomDiagonalSolve"); return ret; }
// // NOTE: run this sample from the repo/tests directory. // int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc,argv); bool useRaster = arguments.read("--rasterize"); bool useOverlay = arguments.read("--overlay"); bool useStencil = arguments.read("--stencil"); bool useMem = arguments.read("--mem"); bool useLabels = arguments.read("--labels"); osgViewer::Viewer viewer(arguments); // Start by creating the map: Map* map = new Map(); // Start with a basemap imagery layer; we'll be using the GDAL driver // to load a local GeoTIFF file: GDALOptions basemapOpt; basemapOpt.url() = "../data/world.tif"; map->addImageLayer( new ImageLayer( ImageLayerOptions("basemap", basemapOpt) ) ); // Next we add a feature layer. First configure a feature driver to // load the vectors from a shapefile: OGRFeatureOptions featureOpt; if ( !useMem ) { featureOpt.url() = "../data/usa.shp"; } else { Ring* line = new Ring(); line->push_back( osg::Vec3d(-60, 20, 0) ); line->push_back( osg::Vec3d(-120, 20, 0) ); line->push_back( osg::Vec3d(-120, 60, 0) ); line->push_back( osg::Vec3d(-60, 60, 0) ); featureOpt.geometry() = line; } // Define a style for the feature data. Since we are going to render the // vectors as lines, configure the line symbolizer: Style style; LineSymbol* ls = style.getOrCreateSymbol<LineSymbol>(); ls->stroke()->color() = osg::Vec4f( 1,1,0,1 ); // yellow ls->stroke()->width() = 2.0f; // Add some text labels. if ( useLabels ) { TextSymbol* text = style.getOrCreateSymbol<TextSymbol>(); text->provider() = "overlay"; text->content() = StringExpression( "[name]" ); text->priority() = NumericExpression( "[area]" ); text->removeDuplicateLabels() = true; text->size() = 16.0f; text->fill()->color() = Color::White; text->halo()->color() = Color::DarkGray; } // That's it, the map is ready; now create a MapNode to render the Map: MapNodeOptions mapNodeOptions; mapNodeOptions.enableLighting() = false; MapNode* mapNode = new MapNode( map, mapNodeOptions ); // Now we'll choose the AGG-Lite driver to render the features. By the way, the // feature data is actually polygons, so we override that to treat it as lines. // We apply the feature driver and set the style as well. if (useStencil) { FeatureStencilModelOptions worldOpt; worldOpt.featureOptions() = featureOpt; worldOpt.geometryTypeOverride() = Geometry::TYPE_LINESTRING; worldOpt.styles() = new StyleSheet(); worldOpt.styles()->addStyle( style ); worldOpt.enableLighting() = false; worldOpt.depthTestEnabled() = false; map->addModelLayer( new ModelLayer( "my features", worldOpt ) ); } else if (useRaster) { AGGLiteOptions worldOpt; worldOpt.featureOptions() = featureOpt; worldOpt.geometryTypeOverride() = Geometry::TYPE_LINESTRING; worldOpt.styles() = new StyleSheet(); worldOpt.styles()->addStyle( style ); map->addImageLayer( new ImageLayer( ImageLayerOptions("world", worldOpt) ) ); } else //if (useGeom || useOverlay) { FeatureGeomModelOptions worldOpt; worldOpt.featureOptions() = featureOpt; worldOpt.geometryTypeOverride() = Geometry::TYPE_LINESTRING; worldOpt.styles() = new StyleSheet(); worldOpt.styles()->addStyle( style ); worldOpt.enableLighting() = false; worldOpt.depthTestEnabled() = false; ModelLayerOptions options( "my features", worldOpt ); options.overlay() = useOverlay; map->addModelLayer( new ModelLayer(options) ); } viewer.setSceneData( mapNode ); viewer.setCameraManipulator( new EarthManipulator() ); if ( !useStencil && !useOverlay ) viewer.addEventHandler( new osgEarth::Util::AutoClipPlaneHandler ); // add some stock OSG handlers: viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); return viewer.run(); }
void Polygon::push(const Ring &v, int beg, bool within) { int sz = v.size(); double coords[2]; mbr(v.xa(), v.ya(), v.xb(), v.yb()); int f = 0, offset = 0; bool turn = false; double xa, ya, xb, yb; for (int i = beg; i < beg + sz; ) { int ind = i % sz; OuterRing rng; xa = xb = v[ind].x(); ya = yb = v[ind].y(); rng.push(xa, ya); if (turn && 0 == offset) { if (0 == f % 2) b_[f].push_back(index_t(xa, -f)); else b_[f].push_back(index_t(ya, -f)); } offset = 0; turn = false; for (int j = (ind+1) % sz; true; j = (j+1) % sz) { const point_t &p = v[j]; rng.push(p.x(), p.y()); if (p.x() < xa) xa = p.x(); if (p.x() > xb) xb = p.x(); if (p.y() < ya) ya = p.y(); if (p.y() > yb) yb = p.y(); coords[(f+1)%2] = p.x(); coords[f%2] = p.y(); if (fuzzy_eq(coords[0], mbr_[f])) { turn = fuzzy_eq(coords[1], mbr_[(f+1)%4]); break; } else if (fuzzy_eq(coords[1], mbr_[(f+1)%4])) { rng.push(corner_[f].x(), corner_[f].y()); offset = 1; turn = true; break; } } int bak = rng.size() - 1 - offset; if (within) { int t = (f + offset) % 4; int kk = (1 == offset || !turn) ? outer_.size() : -f-1; if (0 == t % 2) b_[t].push_back(index_t(rng[bak].x(), kk)); else b_[t].push_back(index_t(rng[bak].y(), kk)); if (1 == offset) rng.corner(); } if (turn) f = (f+1) % 4; i += bak; rng.mbr(xa, ya, xb, yb); outer_.push_back(rng); } if (within) _sort(f%4); }
void mult(elem &result, elem a, elem b) const { result = R->mult(a,b); }
Graph::Graph(const int *cartan, const std::vector<Word>& gens, //namesake const std::vector<Word>& v_cogens, const std::vector<Word>& e_gens, const std::vector<Word>& f_gens, const Vect& weights) { //define symmetry group relations std::vector<Word> words = words_from_cartan(cartan); { const Logging::fake_ostream& os = logger.debug(); os << "relations ="; for (int w=0; w<6; ++w) { Word& word = words[w]; os << "\n "; for (unsigned i=0; i<word.size(); ++i) { os << word[i]; } } os |0; } //check vertex stabilizer generators { const Logging::fake_ostream& os = logger.debug(); os << "v_cogens ="; for (unsigned w=0; w<v_cogens.size(); ++w) { const Word& jenn = v_cogens[w]; //namesake os << "\n "; for (unsigned t=0; t<jenn.size(); ++t) { int j = jenn[t]; os << j; Assert (0<=j and j<4, "generator out of range: letter w[" << w << "][" << t << "] = " << j ); } } os |0; } //check edge generators { const Logging::fake_ostream& os = logger.debug(); os << "e_gens ="; for (unsigned w=0; w<e_gens.size(); ++w) { const Word& edge = e_gens[w]; os << "\n "; for (unsigned t=0; t<edge.size(); ++t) { int j = edge[t]; os << j; Assert (0<=j and j<4, "generator out of range: letter w[" << w << "][" << t << "] = " << j ); } } os |0; } //check face generators { const Logging::fake_ostream& os = logger.debug(); os << "f_gens ="; for (unsigned w=0; w<f_gens.size(); ++w) { const Word& face = f_gens[w]; os << "\n "; for (unsigned t=0; t<face.size(); ++t) { int j = face[t]; os << j; Assert (0<=j and j<4, "generator out of range: letter w[" << w << "][" << t << "] = " << j ); } } os |0; } //build symmetry group Group group(words); logger.debug() << "group.ord = " << group.ord |0; //build subgroup std::vector<int> subgroup; subgroup.push_back(0); std::set<int> in_subgroup; in_subgroup.insert(0); for (unsigned g=0; g<subgroup.size(); ++g) { int g0 = subgroup[g]; for (unsigned j=0; j<gens.size(); ++j) { int g1 = group.left(g0,gens[j]); if (in_subgroup.find(g1) != in_subgroup.end()) continue; subgroup.push_back(g1); in_subgroup.insert(g1); } } logger.debug() << "subgroup.ord = " << subgroup.size() |0; //build cosets and count ord std::map<int,int> coset; //maps group elements to cosets ord = 0; //used as coset number for (unsigned g=0; g<subgroup.size(); ++g) { int g0 = subgroup[g]; if (coset.find(g0) != coset.end()) continue; int c0 = ord++; coset[g0] = c0; std::vector<int> members(1, g0); std::vector<int> others(0); for (unsigned i=0; i<members.size(); ++i) { int g1 = members[i]; for (unsigned w=0; w<v_cogens.size(); ++w) { int g2 = group.left(g1, v_cogens[w]); if (coset.find(g2) != coset.end()) continue; coset[g2] = c0; members.push_back(g2); } } } logger.info() << "cosets table built: " << " ord = " << ord |0; //build edge lists std::vector<std::set<int> > neigh(ord); for (unsigned g=0; g<subgroup.size(); ++g) { int g0 = subgroup[g]; int c0 = coset[g0]; for (unsigned w=0; w<e_gens.size(); ++w) { int g1 = group.left(g0, e_gens[w]); Assert (in_subgroup.find(g1) != in_subgroup.end(), "edge leaves subgroup"); int c1 = coset[g1]; if (c0 != c1) neigh[c0].insert(c1); } } // make symmetric for (int c0=0; c0<ord; ++c0) { const std::set<int>& n = neigh[c0]; for (std::set<int>::iterator c1=n.begin(); c1!=n.end(); ++c1) { neigh[*c1].insert(c0); } } // build edge table adj.resize(ord); for (int c=0; c<ord; ++c) { adj[c].insert(adj[c].begin(), neigh[c].begin(), neigh[c].end()); } neigh.clear(); deg = adj[0].size(); logger.info() << "edge table built: deg = " << deg |0; //define faces for (unsigned g=0; g<f_gens.size(); ++g) { const Word& face = f_gens[g]; logger.debug() << "defining faces on " << face |0; Logging::IndentBlock block; //define basic face in group Ring basic(1,0); // g = 0; int g0 = 0; for (unsigned c=0; true; ++c) { g0 = group.left(g0, face[c%face.size()]); if (c >= face.size() and g0 == 0) break; if (in_subgroup.find(g0) != in_subgroup.end() and g0 != basic.back()) { basic.push_back(g0); } } for (unsigned c=0; c<basic.size(); ++c) { logger.debug() << " corner: " << basic[c] |0; } logger.debug() << "sides/face (free) = " << basic.size() |0; //build orbit of basic face std::vector<Ring> faces_g; faces_g.push_back(basic); FaceRecognizer recognized; recognized(basic); for (unsigned i=0; i<faces_g.size(); ++i) { const Ring f = faces_g[i]; for (unsigned j=0; j<gens.size(); ++j) { //right action of group on faces Ring f_j(f.size()); for (unsigned c=0; c<f.size(); ++c) { f_j[c] = group.right(f[c],gens[j]); } //add face if (not recognized(f_j)) { faces_g.push_back(f_j); //logger.debug() << "new face: " << f_j |0; } else { //logger.debug() << "old face: " << f_j|0; } } } //hom face down to quotient graph recognized.clear(); for (unsigned f=0; f<faces_g.size(); ++f) { const Ring face_g = faces_g[f]; Ring face; face.push_back(coset[face_g[0]]); for (unsigned i=1; i<face_g.size(); ++i) { int c = coset[face_g[i]]; if (c != face.back() and c != face[0]) { face.push_back(c); } } if (face.size() < 3) continue; if (not recognized(face)) { faces.push_back(face); } } } ord_f = faces.size(); logger.info() << "faces defined: order = " << ord_f |0; //define vertex coset std::vector<Word> vertex_coset; for (unsigned g=0; g<subgroup.size(); ++g) { int g0 = subgroup[g]; if (coset[g0]==0) vertex_coset.push_back(group.parse(g0)); } //build geometry std::vector<Mat> gen_reps(gens.size()); points.resize(ord); build_geom(cartan, vertex_coset, gens, v_cogens, weights, gen_reps, points[0]); std::vector<int> pointed(ord,0); pointed[0] = true; logger.debug() << "geometry built" |0; //build point sets std::vector<int> reached(1,0); std::set<int> is_reached; is_reached.insert(0); for (unsigned g=0; g<subgroup.size(); ++g) { int g0 = reached[g]; for (unsigned j=0; j<gens.size(); ++j) { int g1 = group.right(g0,gens[j]); if (is_reached.find(g1) == is_reached.end()) { if (not pointed[coset[g1]]) { vect_mult(gen_reps[j], points[coset[g0]], points[coset[g1]]); pointed[coset[g1]] = true; } reached.push_back(g1); is_reached.insert(g1); } } } logger.debug() << "point set built." |0; //build face normals normals.resize(ord_f); for (int f=0; f<ord_f; ++f) { Ring& face = faces[f]; Vect &a = points[face[0]]; Vect &b = points[face[1]]; Vect &c = points[face[2]]; Vect &n = normals[f]; cross4(a,b,c, n); normalize(n); /* Assert1(fabs(inner(a,n)) < 1e-6, "bad normal: <n,a> = " << fabs(inner(a,n))); Assert1(fabs(inner(b,n)) < 1e-6, "bad normal: <n,b> = " << fabs(inner(b,n))); Assert1(fabs(inner(c,n)) < 1e-6, "bad normal: <n,b> = " << fabs(inner(c,n))); */ } logger.debug() << "face normals built." |0; }
void PolynomialOver<T>::Randomize(RandomNumberGenerator &rng, const RandomizationParameter ¶meter, const Ring &ring) { m_coefficients.resize(parameter.m_coefficientCount); for (unsigned int i=0; i<m_coefficients.size(); ++i) m_coefficients[i] = ring.RandomElement(rng, parameter.m_coefficientParameter); }
TEST(RingCCC, ones) { Ring *R = CCC::create(100); EXPECT_TRUE(R->is_equal(R->one(), R->from_long(1))); EXPECT_TRUE(R->is_equal(R->minus_one(), R->from_long(-1))); EXPECT_TRUE(R->is_equal(R->zero(), R->from_long(0))); EXPECT_TRUE(R->is_zero(R->from_long(0))); }
void divide(elem &result, elem a, elem b) const { result = R->divide(a,b); }
void MatrixUtils::loadF4Matrix__low_memory(const Ring &R, SparseMatrix<typename Ring::Element>& A, const char *fileName) { std::ostream &report = commentator.report(Commentator::LEVEL_NORMAL, INTERNAL_DESCRIPTION); // Code adapted from C version of dump_matrix.c FILE *f = fopen(fileName, "r"); if (f == NULL) { commentator.report(Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR) << "Can't open " << fileName << std::endl; throw std::runtime_error ("Can't open file"); } uint16 *nz; uint32 *pos; uint32 sz; uint32 n; uint32 m; uint32 mod; uint64 nb; if (fread(&n, sizeof(unsigned int), 1, f) != 1) throw std::runtime_error ("Error while reading file"); if (fread(&m, sizeof(unsigned int), 1, f) != 1) throw std::runtime_error ("Error while reading file"); if (fread(&mod, sizeof(unsigned int), 1, f) != 1) throw std::runtime_error ("Error while reading file"); if (fread(&nb, sizeof(unsigned long long), 1, f) != 1) throw std::runtime_error ("Error while reading file"); report << n << " x " << m << " matrix" << std::endl; report << "mod " << mod << std::endl; { double Nz = (double) (n) * (double) (m); Nz = (double) (nb) / Nz; Nz *= 100.0; report << "Nb of Nz elements " << nb << " (density " << Nz << ")" << std::endl; } A = SparseMatrix<typename Ring::Element>(n, m); typename SparseMatrix<typename Ring::Element>::RowIterator i_A; uint32 i; nz = new unsigned short int[m]; //has a size of at most a full row of the matrix pos = new uint32[m]; //save the arrays original pointers uint16 *oNz = nz; uint32 *oPos = pos; uint32 header_size = sizeof(uint32) * 3 + sizeof(uint64); //size of n, m, mod and nb in the header of the file uint64 row_sizes_offset, row_values_offset, row_positions_offset; //cursors in the file //row sizes if positioned after the values and the positions of the elements in the file row_sizes_offset = nb * sizeof(uint16) + nb * sizeof(uint32) + header_size; row_values_offset = header_size; row_positions_offset = nb * sizeof(uint16) + header_size; for (i_A = A.rowBegin(), i = 0; i < n; i++, ++i_A) { //get the size of the current row fseek(f, row_sizes_offset, SEEK_SET); if (fread(&sz, sizeof(uint32), 1, f) != 1) throw "Error while reading file"; row_sizes_offset += sizeof(uint32); assert(sz <= m); //number of elements in a row at max equal to the size of a row in the matrix //read sz elements from the values part of the file fseek(f, row_values_offset, SEEK_SET); if (fread(nz, sizeof(uint16), sz, f) != sz) throw "Error while reading file"; row_values_offset += sz * sizeof(uint16); //read sz elements from the posistions part of the file fseek(f, row_positions_offset, SEEK_SET); if (fread(pos, sizeof(uint32), sz, f) != sz) throw "Error while reading file"; row_positions_offset += sz * sizeof(uint32); i_A->reserve(sz); for (uint32 j = 0; j < sz; j++) { i_A->push_back( typename Vector<Ring>::Sparse::value_type(pos[j], typename Ring::Element())); R.init(i_A->back().second, nz[j]); assert(pos[j] < m); } } //free memory delete[] oNz; delete[] oPos; fclose(f); }
bool testPLUQ (const Ring &F, const char *text, Matrix &A) { std::ostringstream str; str << "Testing Elimination::pluq for " << text << " matrices" << std::ends; commentator.start (str.str ().c_str (), __FUNCTION__); std::ostream &report = commentator.report (Commentator::LEVEL_NORMAL, INTERNAL_DESCRIPTION); std::ostream &error = commentator.report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR); bool pass = true; Context<Ring> ctx (F); Elimination<Ring> elim (ctx); typename Matrix::ContainerType Acopy (A.rowdim (), A.coldim ()), L (A.rowdim (), A.rowdim ()); BLAS3::copy (ctx, A, Acopy); typename Elimination<Ring>::Permutation P, Q; size_t rank; typename Ring::Element det; report << "A = " << std::endl; BLAS3::write (ctx, report, A, FORMAT_PRETTY); elim.pluq (A, P, Q, rank, det); report << "L, U = " << std::endl; BLAS3::write (ctx, report, A, FORMAT_PRETTY); report << "P = "; BLAS1::write_permutation (report, P.begin (), P.end ()) << std::endl; report << "Q = "; BLAS1::write_permutation (report, Q.begin (), Q.end ()) << std::endl; BLAS3::scal (ctx, ctx.F.zero (), L); elim.move_L (L, A); report << "L = " << std::endl; BLAS3::write (ctx, report, L, FORMAT_PRETTY); report << "U = " << std::endl; BLAS3::write (ctx, report, A, FORMAT_PRETTY); BLAS3::trmm (ctx, F.one (), L, A, LowerTriangular, true); report << "LU = " << std::endl; BLAS3::write (ctx, report, A, FORMAT_PRETTY); BLAS3::permute_rows (ctx, P.begin (), P.end (), A); report << "PLU = " << std::endl; BLAS3::write (ctx, report, A); BLAS3::permute_cols (ctx, Q.begin (), Q.end (), A); report << "PLUQ = " << std::endl; BLAS3::write (ctx, report, A); report << "Computed rank = " << rank << std::endl; report << "Computed det = "; F.write (report, det); report << std::endl; if (!BLAS3::equal (ctx, A, Acopy)) { error << "PLUQ != A, not okay" << std::endl; BLAS3::axpy (ctx, ctx.F.minusOne (), A, Acopy); error << "Difference is:" << std::endl; BLAS3::write (ctx, error, Acopy); pass = false; } commentator.stop (MSG_STATUS (pass)); return pass; }
bool testGaussJordanTransform (const Ring &F, size_t m, size_t n) { commentator.start ("Testing GaussJordan::echelonize_reduced", __FUNCTION__); std::ostream &report = commentator.report (Commentator::LEVEL_NORMAL, INTERNAL_DESCRIPTION); std::ostream &error = commentator.report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR); bool pass = true; DenseMatrix<typename Ring::Element> R (m, n); RandomDenseStream<Ring, typename DenseMatrix<typename Ring::Element>::Row> A_stream (F, n, m); DenseMatrix<typename Ring::Element> A (A_stream), L (m, m), LPA (m, n); typename GaussJordan<Ring>::Permutation P; Context<Ring> ctx (F); GaussJordan<Ring> GJ (ctx); size_t rank; typename Ring::Element det; BLAS3::copy (ctx, A, R); GJ.echelonize_reduced (R, L, P, rank, det); report << "A = " << std::endl; BLAS3::write (ctx, report, A); report << "P = "; BLAS1::write_permutation (report, P.begin (), P.end ()) << std::endl; report << "R = " << std::endl; BLAS3::write (ctx, report, R); report << "L = " << std::endl; BLAS3::write (ctx, report, L); BLAS3::permute_rows (ctx, P.begin (), P.end (), A); report << "PA = " << std::endl; BLAS3::write (ctx, report, A); BLAS3::scal (ctx, F.zero (), LPA); BLAS3::gemm (ctx, F.one (), L, A, F.zero (), LPA); report << "LPA = " << std::endl; BLAS3::write (ctx, report, LPA); report << "Computed rank = " << rank << std::endl; report << "Computed det = "; F.write (report, det); report << std::endl; // Trick to eliminate part below diagonal so that equality-check works Elimination<Ring> elim (ctx); elim.move_L (R, R); if (!BLAS3::equal (ctx, LPA, R)) { error << "ERROR: LPA != R" << std::endl; pass = false; } commentator.stop (MSG_STATUS (pass)); return pass; }
bool testEchelonizeReduced (const Ring &F, const char *text, Matrix &A) { std::ostringstream str; str << "Testing Elimination::echelonize_reduced for " << text << " matrices" << std::ends; commentator.start (str.str ().c_str (), __FUNCTION__); std::ostream &report = commentator.report (Commentator::LEVEL_NORMAL, INTERNAL_DESCRIPTION); std::ostream &error = commentator.report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR); bool pass = true; Context<Ring> ctx (F); Elimination<Ring> elim (ctx); typename Matrix::ContainerType Acopy (A.rowdim (), A.coldim ()), LPA (A.rowdim (), A.coldim ()), L (A.rowdim (), A.rowdim ()); BLAS3::copy (ctx, A, Acopy); typename Elimination<Ring>::Permutation P; size_t rank; typename Ring::Element det; report << "A = " << std::endl; BLAS3::write (ctx, report, A, FORMAT_PRETTY); elim.echelonize_reduced (A, L, P, rank, det, true); report << "R = " << std::endl; BLAS3::write (ctx, report, A, FORMAT_PRETTY); report << "L = " << std::endl; BLAS3::write (ctx, report, L, FORMAT_PRETTY); report << "P = "; BLAS1::write_permutation (report, P.begin (), P.end ()) << std::endl; BLAS3::permute_rows (ctx, P.begin (), P.end (), Acopy); report << "PA = " << std::endl; BLAS3::write (ctx, report, Acopy, FORMAT_PRETTY); BLAS3::scal (ctx, F.zero (), LPA); BLAS3::gemm (ctx, F.one (), L, Acopy, F.zero (), LPA); report << "LPA = " << std::endl; BLAS3::write (ctx, report, LPA); report << "Computed rank = " << rank << std::endl; report << "Computed det = "; F.write (report, det); report << std::endl; if (!BLAS3::equal (ctx, LPA, A)) { error << "LPA != R, not okay" << std::endl; pass = false; } commentator.stop (MSG_STATUS (pass)); return pass; }
osg::Geode* BuildGeometryFilter::processPolygonizedLines(FeatureList& features, bool twosided, FilterContext& context) { osg::Geode* geode = new osg::Geode(); // establish some referencing bool makeECEF = false; const SpatialReference* featureSRS = 0L; const SpatialReference* mapSRS = 0L; if ( context.isGeoreferenced() ) { makeECEF = context.getSession()->getMapInfo().isGeocentric(); featureSRS = context.extent()->getSRS(); mapSRS = context.getSession()->getMapInfo().getProfile()->getSRS(); } // iterate over all features. for( FeatureList::iterator i = features.begin(); i != features.end(); ++i ) { Feature* input = i->get(); // extract the required line symbol; bail out if not found. const LineSymbol* line = input->style().isSet() && input->style()->has<LineSymbol>() ? input->style()->get<LineSymbol>() : _style.get<LineSymbol>(); if ( !line ) continue; // run a symbol script if present. if ( line->script().isSet() ) { StringExpression temp( line->script().get() ); input->eval( temp, &context ); } // The operator we'll use to make lines into polygons. PolygonizeLinesOperator polygonizer( *line->stroke() ); // iterate over all the feature's geometry parts. We will treat // them as lines strings. GeometryIterator parts( input->getGeometry(), true ); while( parts.hasMore() ) { Geometry* part = parts.next(); // if the underlying geometry is a ring (or a polygon), close it so the // polygonizer will generate a closed loop. Ring* ring = dynamic_cast<Ring*>(part); if ( ring ) ring->close(); // skip invalid geometry if ( part->size() < 2 ) continue; // transform the geometry into the target SRS and localize it about // a local reference point. osg::ref_ptr<osg::Vec3Array> verts = new osg::Vec3Array(); osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array(); transformAndLocalize( part->asVector(), featureSRS, verts.get(), normals.get(), mapSRS, _world2local, makeECEF ); // turn the lines into polygons. osg::Geometry* geom = polygonizer( verts.get(), normals.get(), twosided ); if ( geom ) { geode->addDrawable( geom ); } // record the geometry's primitive set(s) in the index: if ( context.featureIndex() ) context.featureIndex()->tagDrawable( geom, input ); // install clamping attributes if necessary if (_style.has<AltitudeSymbol>() && _style.get<AltitudeSymbol>()->technique() == AltitudeSymbol::TECHNIQUE_GPU) { Clamping::applyDefaultClampingAttrs( geom, input->getDouble("__oe_verticalOffset", 0.0) ); } } polygonizer.installShaders( geode ); } return geode; }
// // NOTE: run this sample from the repo/tests directory. // int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc,argv); if ( arguments.read("--help") ) return usage( argv[0] ); bool useRaster = arguments.read("--rasterize"); bool useOverlay = arguments.read("--overlay"); bool useStencil = arguments.read("--stencil"); bool useMem = arguments.read("--mem"); bool useLabels = arguments.read("--labels"); if ( useStencil ) osg::DisplaySettings::instance()->setMinimumNumStencilBits( 8 ); osgViewer::Viewer viewer(arguments); // Start by creating the map: Map* map = new Map(); // Start with a basemap imagery layer; we'll be using the GDAL driver // to load a local GeoTIFF file: GDALOptions basemapOpt; basemapOpt.url() = "../data/world.tif"; map->addImageLayer( new ImageLayer( ImageLayerOptions("basemap", basemapOpt) ) ); // Next we add a feature layer. OGRFeatureOptions featureOptions; if ( !useMem ) { // Configures the feature driver to load the vectors from a shapefile: featureOptions.url() = "../data/world.shp"; } else { // the --mem options tells us to just make an in-memory geometry: Ring* line = new Ring(); line->push_back( osg::Vec3d(-60, 20, 0) ); line->push_back( osg::Vec3d(-120, 20, 0) ); line->push_back( osg::Vec3d(-120, 60, 0) ); line->push_back( osg::Vec3d(-60, 60, 0) ); featureOptions.geometry() = line; } // Define a style for the feature data. Since we are going to render the // vectors as lines, configure the line symbolizer: Style style; LineSymbol* ls = style.getOrCreateSymbol<LineSymbol>(); ls->stroke()->color() = Color::Yellow; ls->stroke()->width() = 2.0f; // That's it, the map is ready; now create a MapNode to render the Map: MapNodeOptions mapNodeOptions; mapNodeOptions.enableLighting() = false; MapNode* mapNode = new MapNode( map, mapNodeOptions ); osg::Group* root = new osg::Group(); root->addChild( mapNode ); viewer.setSceneData( root ); viewer.setCameraManipulator( new EarthManipulator() ); // Process cmdline args MapNodeHelper().parse(mapNode, arguments, &viewer, root, new LabelControl("Features Demo")); if (useStencil) { FeatureStencilModelOptions stencilOptions; stencilOptions.featureOptions() = featureOptions; stencilOptions.styles() = new StyleSheet(); stencilOptions.styles()->addStyle( style ); stencilOptions.enableLighting() = false; stencilOptions.depthTestEnabled() = false; ls->stroke()->width() = 0.1f; map->addModelLayer( new ModelLayer("my features", stencilOptions) ); } else if (useRaster) { AGGLiteOptions rasterOptions; rasterOptions.featureOptions() = featureOptions; rasterOptions.styles() = new StyleSheet(); rasterOptions.styles()->addStyle( style ); map->addImageLayer( new ImageLayer("my features", rasterOptions) ); } else //if (useGeom || useOverlay) { FeatureGeomModelOptions geomOptions; geomOptions.featureOptions() = featureOptions; geomOptions.styles() = new StyleSheet(); geomOptions.styles()->addStyle( style ); geomOptions.enableLighting() = false; ModelLayerOptions layerOptions( "my features", geomOptions ); map->addModelLayer( new ModelLayer(layerOptions) ); } if ( useLabels ) { // set up symbology for drawing labels. We're pulling the label // text from the name attribute, and its draw priority from the // population attribute. Style labelStyle; TextSymbol* text = labelStyle.getOrCreateSymbol<TextSymbol>(); text->content() = StringExpression( "[cntry_name]" ); text->priority() = NumericExpression( "[pop_cntry]" ); text->removeDuplicateLabels() = true; text->size() = 16.0f; text->alignment() = TextSymbol::ALIGN_CENTER_CENTER; text->fill()->color() = Color::White; text->halo()->color() = Color::DarkGray; // and configure a model layer: FeatureGeomModelOptions geomOptions; geomOptions.featureOptions() = featureOptions; geomOptions.styles() = new StyleSheet(); geomOptions.styles()->addStyle( labelStyle ); map->addModelLayer( new ModelLayer("labels", geomOptions) ); } if ( !useStencil ) viewer.getCamera()->addCullCallback( new osgEarth::Util::AutoClipPlaneCullCallback(mapNode) ); // add some stock OSG handlers: viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.addEventHandler(new osgViewer::WindowSizeHandler()); viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet())); return viewer.run(); }
Geometry * PolyParser::Parse ( cvct::VCTGeometry & geo ) { typedef std::vector<std::string> Ring;//存线 typedef std::vector<Ring> RingList;//存环 Ring pt; RingList ringlist; char * pTemp = NULL; Read ( &pTemp, geo.start_pos, geo.end_pos ); char ** poLine = CSLTokenizeString2 ( pTemp, " \n\r\t,", 0 ); Geometry * pGeo = new Geometry(); //由线转面 //线变成一个环 //变成一个环 //先判断是否反转 //查找对象 //变成一个环 poLine = CSLAddString(poLine, "0"); for ( int i = 0; i != CSLCount ( poLine ); ++i ) { if ( EQUAL ( poLine[i], "0" ) ) { ringlist.push_back ( pt ); pt.clear(); } else { pt.push_back ( std::string ( poLine[i] ) ); } } for ( auto iRing = ringlist.begin(); iRing != ringlist.end(); ++iRing ) { GeometryPart * ring = new GeometryPart(); for ( auto iLine = iRing->begin(); iLine != iRing->end(); ++iLine ) { bool bset;//true,表示反方向,false,正方向 int objid = atoi(iLine->c_str()); //查找是否有“-”号,是否反转 if ( objid > 0 ) { bset = false; } else { objid = -objid; bset = true; } //在所有的要素中,查找线,或面对像 auto it = vctindex->GetFeatureById(objid); Geometry * geoline = NULL; //解析线对象 if (it->geotype == cvct::GT_LINE) { LineParser iline(vctfile, vctindex); geoline = iline.Parse ( it->geometry ); } //解析面对象 else if (it->geotype == cvct::GT_POLYGON) { PolyParser ipoly(vctfile, vctindex); geoline = ipoly.Parse ( it->geometry ); } /// 增加结点个数 geo.nVertices += it->geometry.nVertices; //将线对象放到环中 if ( bset ) { ring->insert ( ring->end(), geoline->operator[](0)->rbegin(), geoline->operator[](0)->rend() ); } else { ring->insert ( ring->end(), geoline->operator[](0)->begin(), geoline->operator[](0)->end() ); } } if (ring->empty()) { continue; } else { pGeo->push_back ( ring ); } } CSLDestroy ( poLine ); CPLFree ( pTemp ); return pGeo; }
TEST(RingQQ, ones) { Ring *R = globalQQ; EXPECT_TRUE(R->is_equal(R->one(), R->from_int(1))); EXPECT_TRUE(R->is_equal(R->minus_one(), R->from_int(-1))); EXPECT_TRUE(R->is_equal(R->zero(), R->from_int(0))); EXPECT_TRUE(R->is_zero(R->from_int(0))); }
bool testRandom(const Ring& R, size_t n) { bool pass = true; commentator().start ("Testing Iloipoulos elimination:", "testRandom"); using namespace std; ostream &report = commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_DESCRIPTION); BlasMatrixDomain<Ring> BMD(R); BlasMatrix<Ring> D(R, n, n), L(R, n, n), U(R, n, n), A(R,n,n); // D is Smith Form const int m = 16; int p[m] = {1,1,1,1,1,1,2, 2, 2, 4, 3, 3, 3, 5, 7, 101}; typename Ring::Element x, y; R.assign(x, R.one); if (n > 0) D.setEntry(0,0,x); for(size_t i = 1; i < n; ++i){ R.init(y, p[rand()%m]); D.setEntry(i,i, R.mulin(x, y)); } if (n > 0) D.setEntry(n-1,n-1, R.zero); // L and U are random unit triangular. for (size_t i = 0; i < n; ++ i) { for (size_t j = 0; j < i; ++ j) { L.setEntry(i,j, R.init(x, rand() % 10)); U.setEntry(j,i, R.init(x, rand() % 10)); } L.setEntry(i,i, R.one); U.setEntry(i,i, R.one); } // A is ULDU BMD.mul(A, U, L); BMD.mulin_left(A, D); BMD.mulin_left(A, U); D.write( report << "Smith form matrix:\n " ) << endl; A.write( report << "input matrix:\n " ) << endl; // SmithFormIliopoulos::smithFormIn (A); // A.write( report << "smith of input matrix direct:\n " ) << endl; report << "Using PIRModular<int32_t>\n"; typename Ring::Element d; R.init(d,16*101);//16*101*5*7*9); for (size_t i = 0; i < n-1; ++i) R.mulin(d, D.getEntry(x, i, i)); R.write(report << "modulus: ", d) << endl; //det(d, D); //PIRModular<int32_t> Rd( (int32_t)(s % LINBOX_MAX_MODULUS)); PIRModular<int32_t> Rp( (int32_t)d); BlasMatrix<PIRModular<int32_t> > Ap(Rp, n, n), Dp(Rp, n, n); MatrixHom::map (Ap, A); SmithFormIliopoulos::smithFormIn (Ap); Ap.write( report << "Computed Smith form: \n") << endl; MatrixHom::map (Dp, D); BlasMatrixDomain<PIRModular<int32_t> > BMDp(Rp); pass = pass and BMDp.areEqual(Dp, Ap); commentator().stop (MSG_STATUS (pass), (const char *) 0, "testRandom"); return pass; }
int main() { std::cout << "In TestRing \n"; Ring<Hn>* ring = new Ring<Hn>(5); for(int i =0; i < 10 ; i++) { Hn* hn1 = new Hn(); hn1->x = i; hn1->y = i; ring->Enqueue(hn1); std::cout << "Size is " << ring->GetSize() << "\n"; } Hn* hnr = ring->GetLatest(); std::cout << "Latest " << hnr->x << "\n"; Hn* hnr0 = ring->GetLatestMinus(0); std::cout << "Minus 0 " << hnr0->x << "\n"; Hn* hnr1 = ring->GetLatestMinus(1); std::cout << "Minus 1 " << hnr1->x << "\n"; Hn* hnr2 = ring->GetLatestMinus(2); std::cout << "Minus 2 " << hnr2->x << "\n"; Hn* hnr3 = ring->GetLatestMinus(3); std::cout << "Minus 3 " << hnr3->x << "\n"; Hn* hnr4 = ring->GetLatestMinus(4); std::cout << "Minus 4 " << hnr4->x << "\n"; Hn* hnr5 = ring->GetLatestMinus(5); std::cout << "Minus 5 " << hnr5->x << "\n"; Hn* hnr6 = ring->GetLatestMinus(6); std::cout << "Minus 6 " << hnr6->x << "\n"; Hn* hnr7 = ring->GetLatestMinus(7); std::cout << "Minus 7 " << hnr7->x << "\n"; delete ring; }