FileInfo* PieView::_FileAt(const BPoint& where) { BRect b = Bounds(); float cx = b.left + b.Width() / 2.0; float cy = b.top + b.Height() / 2.0; float dx = where.x - cx; float dy = where.y - cy; float dist = sqrt(dx*dx + dy*dy); int level; if (dist < kPieCenterSize) level = 0; else level = 1 + (int)((dist - kPieCenterSize) / kPieRingSize); float angle = rad2deg(atan(dy / dx)); angle = ((dx < 0.0) ? 180.0 : (dy < 0.0) ? 0.0 : 360.0) - angle; if (fMouseOverInfo.find(level) == fMouseOverInfo.end()) { // No files in this level (ring) of the pie. return NULL; } SegmentList s = fMouseOverInfo[level]; SegmentList::iterator i = s.begin(); while (i != s.end() && (angle < (*i).begin || (*i).end < angle)) i++; if (i == s.end()) { // Nothing at this angle. return NULL; } return (*i).info; }
static void bufferLinesToLines( const GeoShape& input, double b, GeoShape& output ) { // buffering lines turns them into polygons for( GeoPartList::const_iterator i = input.getParts().begin(); i != input.getParts().end(); i++ ) { const GeoPointList& part = *i; if ( part.size() < 2 ) continue; GeoPointList new_part; // collect all the shifted segments: SegmentList segments; for( GeoPointList::const_iterator j = part.begin(); j != part.end()-1; j++ ) { const osg::Vec3d& p0 = *j; const osg::Vec3d& p1 = *(j+1); osg::Vec3d d = p1-p0; d.normalize(); osg::Vec3d b0( p0.x() + b*d.y(), p0.y() - b*d.x(), p1.z() ); osg::Vec3d b1( p1.x() + b*d.y(), p1.y() - b*d.x(), p1.z() ); segments.push_back( Segment( b0, b1 ) ); } // then intersect each pair of shifted segments to find the new verts: for( SegmentList::iterator k = segments.begin(); k != segments.end()-1; k++ ) { Segment& s0 = *k; Segment& s1 = *(k+1); //(k+1) != segments.end()? *(k+1) : *segments.begin(); if ( k == segments.begin() ) { GeoPoint first( s0.p0, part[0].getSRS() ); first.setDim( part[0].getDim() ); new_part.push_back( first ); } osg::Vec3d isect; if ( getLineIntersection( s0, s1, isect ) ) { GeoPoint r( isect, part[0].getSRS() ); r.setDim( part[0].getDim() ); new_part.push_back( r ); } if ( k == segments.end()-2 ) { GeoPoint last( s1.p1, part[0].getSRS() ); last.setDim( part[0].getDim() ); new_part.push_back( last ); } } if ( new_part.size() > 1 ) output.getParts().push_back( new_part ); } }
void QSegmentWidget::DrawSegments(QPainter *painter, const SegmentList &s, qreal radius) { for (SegmentList::const_iterator i = s.begin(); i != s.end(); i++) { painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::SmoothPixmapTransform); QBrush b(i->color); painter->setBrush(b); QBrush c(i->color.darker(200)); painter->setPen(QPen(c, 0)); int startAngle = qRound(i->first * 16.0); qreal dAngle = i->second - i->first; if (dAngle < 0.0) dAngle += 360.0; int spanAngle = qRound(dAngle * 16.0); QRectF r(-radius, -radius, radius * 2.0, radius * 2.0); if (spanAngle >= 360 * 16) { // qDebug() << QString("DrawSegments drawEllipse (%1, %2)").arg(-radius).arg(radius * 2.0); painter->drawEllipse(r); } else { // qDebug() << QString("DrawSegments drawPie (%1, %2, %3, %4)").arg(-radius).arg(radius * 2.0).arg(startAngle).arg(spanAngle); painter->drawPie(r, startAngle, spanAngle); } } }
static void bufferPolygons( const GeoShape& shape, double b, GeoPartList& output ) { for( GeoPartList::const_iterator i = shape.getParts().begin(); i != shape.getParts().end(); i++ ) { const GeoPointList& part = *i; if ( part.size() < 3 ) continue; GeoPointList new_part; // first build the buffered line segments: SegmentList segments; for( GeoPointList::const_iterator j = part.begin(); j != part.end(); j++ ) { const osg::Vec3d& p0 = *j; const osg::Vec3d& p1 = (j+1) != part.end()? *(j+1) : *part.begin(); osg::Vec3d d = p1-p0; d.normalize(); osg::Vec3d b0( p0.x() + b*d.y(), p0.y() - b*d.x(), p1.z() ); osg::Vec3d b1( p1.x() + b*d.y(), p1.y() - b*d.x(), p1.z() ); segments.push_back( Segment( b0, b1 ) ); } // then intersect each pair of segments to find the new verts: for( SegmentList::iterator k = segments.begin(); k != segments.end(); k++ ) { Segment& s0 = *k; Segment& s1 = (k+1) != segments.end()? *(k+1) : *segments.begin(); osg::Vec3d isect; if ( getLineIntersection( s0, s1, isect ) ) { GeoPoint r( isect, part[0].getSRS() ); r.setDim( part[0].getDim() ); new_part.push_back( r ); } } if ( new_part.size() > 2 ) output.push_back( new_part ); } }
void Tessellation::generateExtrusionContour() { for( auto& pos : positions ) extrusionContourVertices.push_back( pos ); extrusionContourIndices = segments; SegmentList additionalSegments; Vector n; int originalSegments = extrusionContourIndices.size(); for( auto& segment : extrusionContourIndices ) { auto& a = positions[ segment.i1 ]; auto& b = positions[ segment.i2 ]; n.x = (float)(a.y - b.y); n.y = (float)(b.x - a.x); n = n.normalized(); _assignNormal( n, segment, 0, additionalSegments ); _assignNormal( n, segment, 1, additionalSegments ); } //add the created segments to the extrusion segments extrusionContourIndices.insert( extrusionContourIndices.end(), additionalSegments.begin(), additionalSegments.end() ); }
void BlobImageProcessorYUV::processImage(/*const*/ Image &image) { #else void BlobImageProcessorYUV::processImage(const Image &image) { #endif blobs.clear(); int y; BlobList activeblobs; for (y=0; y<image.getHeight(); y++) { // for each row SegmentList segments = getSegments(y, image); // find all the segments for (SegmentList::iterator segment = segments.begin(); segment != segments.end(); ++segment) { // for each segment BlobList::iterator mainblob = matchSegment(*segment, activeblobs.begin(), activeblobs.end()); if (mainblob != activeblobs.end()) { // if the segment matches a blob mainblob->h = y - mainblob->y; // extend its height down to the current row if (segment->start < mainblob->x) { // if the segment starts before the current blob mainblob->w += mainblob->x - segment->start; // extend the current blob mainblob->x = segment->start; // shift it to match the new segment } if (segment->end > mainblob->x + mainblob->w) // if the new segment ends after our current blob mainblob->w = segment->end - mainblob->x; // extend the current blob BlobList::iterator mergeblob = mainblob+1; while ((mergeblob = matchSegment(*segment, mergeblob, activeblobs.end())) != activeblobs.end()) { // continue looking for more blobs // if we match another blob if (mainblob->x > mergeblob->x) { // and it starts before our current blob mainblob->w += mainblob->x - mergeblob->x; // preserve our mergeblob's end point mainblob->x = mergeblob->x; // move our current blob's start position } if (mainblob->x + mainblob->w < mergeblob->x + mergeblob->w) // and it is wider than our main blob mainblob->w = mergeblob->x + mergeblob->w - mainblob->x; // extend our main blob mergeblob = activeblobs.erase(mergeblob); // remove the merged blob } } else { // segment doesn't match a blob Blob newblob; // make a new one newblob.x = segment->start; newblob.w = segment->end - segment->start; newblob.y = y; newblob.h = 1; activeblobs.push_back(newblob); } } for (BlobList::iterator blob = activeblobs.begin(); blob != activeblobs.end();) { // go through all of the active blobs if (blob->y + blob->h + maxgapdist < y) { // if there is too large of a gap if (blob->h > minblobheight) // if they're tall enough blobs.push_back(*blob); // keep it, copy it to the main blob list blob = activeblobs.erase(blob); // remove them from the active blob list } else ++blob; } } blobs.insert(blobs.end(), activeblobs.begin(), activeblobs.end()); // copy all blobs that reached the bottom of the screen to the main blob list if (debug) { for (BlobList::iterator i = blobs.begin(); i != blobs.end(); ++i) { cout << "Blob at (" << i->x << "," << i->y << ") size " << i->w << "x" << i->h << endl; } } }
static void filter_self_intersection( const GeometrySet<Dim>& input, GeometrySet<Dim>& output ) { { typedef std::list< CollectionElement<typename Point_d<Dim>::Type> > PointList; PointList points; std::copy( input.points().begin(), input.points().end(), std::back_inserter( points ) ); typename PointList::iterator it = points.begin(); while ( it != points.end() ) { bool intersectsA = false; for ( typename PointList::iterator it2 = points.begin(); it2 != points.end(); ++it2 ) { if ( it == it2 ) { continue; } PrimitiveHandle<Dim> pa1( &it->primitive() ); PrimitiveHandle<Dim> pa2( &it2->primitive() ); if ( CGAL::do_overlap( it->primitive().bbox(), it2->primitive().bbox() ) && algorithm::intersects( pa1, pa2 ) ) { intersectsA = true; GeometrySet<Dim> temp; algorithm::intersection( pa1, pa2, temp ); std::copy( temp.points().begin(), temp.points().end(), std::back_inserter( points ) ); // erase it2 points.erase( it2 ); break; } } if ( ! intersectsA ) { output.addPrimitive( it->primitive() ); } // suppress A it = points.erase( it ); } } { typedef std::list< CollectionElement<typename Segment_d<Dim>::Type> > SegmentList; SegmentList segments; std::copy( input.segments().begin(), input.segments().end(), std::back_inserter( segments ) ); typename SegmentList::iterator it = segments.begin(); while ( it != segments.end() ) { bool intersectsA = false; for ( typename SegmentList::iterator it2 = segments.begin(); it2 != segments.end(); ++it2 ) { if ( it == it2 ) { continue; } PrimitiveHandle<Dim> pa1( &it->primitive() ); PrimitiveHandle<Dim> pa2( &it2->primitive() ); if ( CGAL::do_overlap( it->primitive().bbox(), it2->primitive().bbox() ) && algorithm::intersects( pa1, pa2 ) ) { intersectsA = true; GeometrySet<Dim> temp; algorithm::intersection( pa1, pa2, temp ); std::copy( temp.segments().begin(), temp.segments().end(), std::back_inserter( segments ) ); // erase it2 segments.erase( it2 ); break; } } if ( ! intersectsA ) { output.addPrimitive( it->primitive() ); } // suppress A it = segments.erase( it ); } } }
static void bufferLinesToPolygons( const GeoShape& input, double b, GeoShape& output ) { // buffering lines turns them into polygons for( GeoPartList::const_iterator i = input.getParts().begin(); i != input.getParts().end(); i++ ) { const GeoPointList& part = *i; if ( part.size() < 2 ) continue; GeoPointList new_part; // collect segments in one direction and then the other. SegmentList segments; for( GeoPointList::const_iterator j = part.begin(); j != part.end()-1; j++ ) { const osg::Vec3d& p0 = *j; const osg::Vec3d& p1 = *(j+1); osg::Vec3d d = p1-p0; d.normalize(); osg::Vec3d b0( p0.x() + b*d.y(), p0.y() - b*d.x(), p1.z() ); osg::Vec3d b1( p1.x() + b*d.y(), p1.y() - b*d.x(), p1.z() ); segments.push_back( Segment( b0, b1 ) ); // after the last seg, add an end-cap: if ( j == part.end()-2 ) { osg::Vec3d b2( p1.x() - b*d.y(), p1.y() + b*d.x(), p1.z() ); segments.push_back( Segment( b1, b2 ) ); } } // now back the other way: for( GeoPointList::const_reverse_iterator j = part.rbegin(); j != part.rend()-1; j++ ) { const osg::Vec3d& p0 = *j; const osg::Vec3d& p1 = *(j+1); osg::Vec3d d = p1-p0; d.normalize(); osg::Vec3d b0( p0.x() + b*d.y(), p0.y() - b*d.x(), p1.z() ); osg::Vec3d b1( p1.x() + b*d.y(), p1.y() - b*d.x(), p1.z() ); segments.push_back( Segment( b0, b1 ) ); // after the last seg, add an end-cap: if ( j == part.rend()-2 ) { osg::Vec3d b2( p1.x() - b*d.y(), p1.y() + b*d.x(), p1.z() ); segments.push_back( Segment( b1, b2 ) ); } } // then intersect each pair of segments to find the new verts: for( SegmentList::iterator k = segments.begin(); k != segments.end(); k++ ) { Segment& s0 = *k; Segment& s1 = (k+1) != segments.end()? *(k+1) : *segments.begin(); osg::Vec3d isect; if ( getLineIntersection( s0, s1, isect ) ) { GeoPoint r( isect, part[0].getSRS() ); r.setDim( part[0].getDim() ); new_part.push_back( r ); } } if ( new_part.size() > 2 ) output.getParts().push_back( new_part ); } }