int main(int argc, char* argv[]) { //options // -i inputfile -a annotationfiles -f forcestrand bool showHelp = false; string infile; vector<string> annofiles; bool forcestrand = false; // Show help when has no options if(argc <= 1) { Help(); return 0; } // Parsing options for(int i = 1; i < argc; i++) { int parameterLength = (int)strlen(argv[i]); if((PARAMETER_CHECK("-h", 2, parameterLength)) || (PARAMETER_CHECK("--help", 5, parameterLength))) showHelp=true; else if ((PARAMETER_CHECK("-i", 2, parameterLength)) || (PARAMETER_CHECK("--input", 7, parameterLength))) { if ((++i) < argc) infile=argv[i]; } else if ((PARAMETER_CHECK("-a", 2, parameterLength)) || (PARAMETER_CHECK("--annotations", 13, parameterLength))) { if ((++i) < argc) { StringUtils::tokenize(string(argv[i]),annofiles,","); } } else if ((PARAMETER_CHECK("-s", 2, parameterLength)) || (PARAMETER_CHECK("--forcestrand", 13, parameterLength))) forcestrand = true; else { cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl; showHelp = true; } } // Show help if no proper auguments. if (showHelp) { Help(); return 0; } // definition int annocount=annofiles.size(); // File count vector<BedMap> bedmaps(annocount); // BedMap vector<double> annos(annocount+1,0); // Count reads for each kind of annotaions. The last one counts the remained reads. LINE_ELEMS elems; // Column reader buffer Hits hits; ColumnReader beds(infile); // Load annotations into BedMaps for(int i=0;i<annocount;i++) BedUtils::loadBedFileToMap(bedmaps[i],annofiles[i]); // Annotation beds.open(); while(beds.getNext(elems)!=LINE_INVALID) { Bed tbed(elems); cout << tbed; bool intersectflag=true; for(int i=0;i<annocount;i++) { if(intersectflag) { BedUtils::intersectBed(tbed,bedmaps[i],hits,forcestrand); if(hits.size()) { annos[i]+=tbed.score; cout << "\t" << tbed.score; intersectflag=false; // if found hits, suppress intersection for the following annotations. } else cout << "\t0"; hits.clear(); } else cout << "\t0"; } if(intersectflag) // No overlas with annotations. { cout << "\t" << tbed.score << endl; annos[annocount]+=tbed.score; } else cout << "\t0" << endl; } for(int i=0;i<annocount;i++) cerr << annofiles[i] << "\t" << annos[i] << endl; cerr << "Remained\t" << annos[annocount] << endl; return 0; }
bool Picker::pick( float x, float y, Hits& results ) const { float local_x, local_y = 0.0; const osg::Camera* camera = _view->getCameraContainingPosition(x, y, local_x, local_y); if ( !camera ) camera = _view->getCamera(); osg::ref_ptr<osgEarth::PrimitiveIntersector> picker; double buffer_x = _buffer, buffer_y = _buffer; if ( camera->getViewport() ) { double aspectRatio = camera->getViewport()->width()/camera->getViewport()->height(); buffer_x *= aspectRatio; buffer_y /= aspectRatio; } osg::Matrix windowMatrix; if ( _root.valid() ) { osg::Matrix modelMatrix; if (camera->getViewport()) { windowMatrix = camera->getViewport()->computeWindowMatrix(); modelMatrix.preMult( windowMatrix ); } modelMatrix.preMult( camera->getProjectionMatrix() ); modelMatrix.preMult( camera->getViewMatrix() ); osg::NodePath prunedNodePath( _path.begin(), _path.end()-1 ); modelMatrix.preMult( osg::computeWorldToLocal(prunedNodePath) ); osg::Matrix modelInverse; modelInverse.invert(modelMatrix); osg::Vec3d startLocal(local_x, local_y, 0.0); osg::Vec3d startModel = startLocal * modelInverse; osg::Vec3d endLocal(local_x, local_y, 1.0); osg::Vec3d endModel = endLocal * modelInverse; osg::Vec3d bufferLocal(local_x + buffer_x, local_y + buffer_y, 0.0); osg::Vec3d bufferModel = bufferLocal * modelInverse; double buffer = osg::maximum((bufferModel - startModel).length(), 5.0); //TODO: Setting a minimum of 4.0 may need revisited OE_DEBUG << "local_x:" << local_x << ", local_y:" << local_y << ", buffer_x:" << buffer_x << ", buffer_y:" << buffer_y << ", bm.x:" << bufferModel.x() << ", bm.y:" << bufferModel.y() << ", bm.z:" << bufferModel.z() << ", BUFFER: " << buffer << std::endl; picker = new osgEarth::PrimitiveIntersector(osgUtil::Intersector::MODEL, startModel, endModel, buffer); } else { picker = new osgEarth::PrimitiveIntersector(camera->getViewport() ? osgUtil::Intersector::WINDOW : osgUtil::Intersector::PROJECTION, local_x, local_y, _buffer); } picker->setIntersectionLimit( (osgUtil::Intersector::IntersectionLimit)_limit ); osgUtil::IntersectionVisitor iv(picker.get()); //picker->setIntersectionLimit( osgUtil::Intersector::LIMIT_ONE_PER_DRAWABLE ); // in MODEL mode, we need to window and proj matrixes in order to support some of the // features in osgEarth (like Annotation::OrthoNode). if ( _root.valid() ) { iv.pushWindowMatrix( new osg::RefMatrix(windowMatrix) ); iv.pushProjectionMatrix( new osg::RefMatrix(camera->getProjectionMatrix()) ); iv.pushViewMatrix( new osg::RefMatrix(camera->getViewMatrix()) ); } iv.setTraversalMask( _travMask ); if ( _root.valid() ) _path.back()->accept(iv); else const_cast<osg::Camera*>(camera)->accept(iv); if (picker->containsIntersections()) { results = picker->getIntersections(); return true; } else { results.clear(); return false; } }
bool Picker::pick( float x, float y, Hits& results ) const { float local_x, local_y = 0.0; const osg::Camera* camera = _view->getCameraContainingPosition(x, y, local_x, local_y); if ( !camera ) camera = _view->getCamera(); osg::ref_ptr<osgUtil::PolytopeIntersector> picker; double buffer_x = _buffer, buffer_y = _buffer; if ( camera->getViewport() ) { double aspectRatio = camera->getViewport()->width()/camera->getViewport()->height(); buffer_x *= aspectRatio; buffer_y /= aspectRatio; } double zNear = 0.00001; double zFar = 1.0; double xMin = local_x - buffer_x; double xMax = local_x + buffer_x; double yMin = local_y - buffer_y; double yMax = local_y + buffer_y; osg::Polytope winPT; winPT.add(osg::Plane( 1.0, 0.0, 0.0, -xMin)); winPT.add(osg::Plane(-1.0, 0.0 ,0.0, xMax)); winPT.add(osg::Plane( 0.0, 1.0, 0.0, -yMin)); winPT.add(osg::Plane( 0.0,-1.0, 0.0, yMax)); winPT.add(osg::Plane( 0.0, 0.0, 1.0, zNear)); osg::Matrix windowMatrix; if ( _root.valid() ) { osg::Matrix matrix; if (camera->getViewport()) { windowMatrix = camera->getViewport()->computeWindowMatrix(); matrix.preMult( windowMatrix ); zNear = 0.0; zFar = 1.0; } matrix.preMult( camera->getProjectionMatrix() ); matrix.preMult( camera->getViewMatrix() ); osg::NodePath prunedNodePath( _path.begin(), _path.end()-1 ); matrix.preMult( osg::computeWorldToLocal(prunedNodePath) ); osg::Polytope transformedPT; transformedPT.setAndTransformProvidingInverse( winPT, matrix ); picker = new osgUtil::PolytopeIntersector(osgUtil::Intersector::MODEL, transformedPT); } else { osgUtil::Intersector::CoordinateFrame cf = camera->getViewport() ? osgUtil::Intersector::WINDOW : osgUtil::Intersector::PROJECTION; picker = new osgUtil::PolytopeIntersector(cf, winPT); } //picker->setIntersectionLimit( (osgUtil::Intersector::IntersectionLimit)_limit ); osgUtil::IntersectionVisitor iv(picker.get()); // in MODEL mode, we need to window and proj matrixes in order to support some of the // features in osgEarth (like Annotation::OrthoNode). if ( _root.valid() ) { iv.pushWindowMatrix( new osg::RefMatrix(windowMatrix) ); iv.pushProjectionMatrix( new osg::RefMatrix(camera->getProjectionMatrix()) ); iv.pushViewMatrix( new osg::RefMatrix(camera->getViewMatrix()) ); } iv.setTraversalMask( _travMask ); if ( _root.valid() ) _path.back()->accept(iv); else const_cast<osg::Camera*>(camera)->accept(iv); if (picker->containsIntersections()) { results = picker->getIntersections(); return true; } else { results.clear(); return false; } }