CRef<CSeq_id> CSeqIdGenerator::GenerateID(const string& defline, const bool advance)
{
    CRef<CSeq_id> seq_id(new CSeq_id);
    int n = advance ? m_Counter.Add(1) - 1 : m_Counter.Get();
    if (m_Prefix.empty()  &&  m_Suffix.empty()) {
        seq_id->SetLocal().SetId(n);
    } else {
        string& id = seq_id->SetLocal().SetStr();
        id.reserve(128);
        id += m_Prefix;
        id += NStr::IntToString(n);
        id += m_Suffix;
    }
    return seq_id;
}
Beispiel #2
0
void
FE_Utils::create_uses_multiple_stuff (AST_Component *c,
                                      AST_Uses *u,
                                      const char *prefix)
{
  ACE_CString struct_name (prefix);

  if (!struct_name.empty ())
    {
      struct_name += '_';
    }

  struct_name += u->local_name ()->get_string ();
  struct_name += "Connection";
  Identifier struct_id (struct_name.c_str ());
  UTL_ScopedName sn (&struct_id, 0);

  // In case this call comes from the backend. We
  // will pop the scope before returning.
  idl_global->scopes ().push (c);

  AST_Structure *connection =
    idl_global->gen ()->create_structure (&sn, 0, 0);

  struct_id.destroy ();

  /// If the field type is a param holder, we want
  /// to use the lookup to create a fresh one,
  /// since the field will own it and destroy it.
  UTL_ScopedName *fn = u->uses_type ()->name ();
  AST_Decl *d =
    idl_global->root ()->lookup_by_name (fn, true, false);
  AST_Type *ft = AST_Type::narrow_from_decl (d);

  Identifier object_id ("objref");
  UTL_ScopedName object_name (&object_id,
                              0);
  AST_Field *object_field =
    idl_global->gen ()->create_field (ft,
                                      &object_name,
                                      AST_Field::vis_NA);
  (void) DeclAsScope (connection)->fe_add_field (object_field);
  object_id.destroy ();

  Identifier local_id ("Cookie");
  UTL_ScopedName local_name (&local_id,
                             0);
  Identifier module_id ("Components");
  UTL_ScopedName scoped_name (&module_id,
                              &local_name);

  d = c->lookup_by_name (&scoped_name, true);
  local_id.destroy ();
  module_id.destroy ();

  if (d == 0)
    {
      // This would happen if we haven't included Components.idl.
      idl_global->err ()->lookup_error (&scoped_name);
      return;
    }

  AST_ValueType *cookie = AST_ValueType::narrow_from_decl (d);

  Identifier cookie_id ("ck");
  UTL_ScopedName cookie_name (&cookie_id,
                              0);
  AST_Field *cookie_field =
    idl_global->gen ()->create_field (cookie,
                                      &cookie_name,
                                      AST_Field::vis_NA);
  (void) DeclAsScope (connection)->fe_add_field (cookie_field);
  cookie_id.destroy ();

  (void) c->fe_add_structure (connection);

  ACE_CDR::ULong bound = 0;
  AST_Expression *bound_expr =
    idl_global->gen ()->create_expr (bound,
                                     AST_Expression::EV_ulong);
  AST_Sequence *sequence =
    idl_global->gen ()->create_sequence (bound_expr,
                                         connection,
                                         0,
                                         0,
                                         0);

  ACE_CString seq_string (struct_name);
  seq_string += 's';
  Identifier seq_id (seq_string.c_str ());
  UTL_ScopedName seq_name (&seq_id,
                           0);
  AST_Typedef *connections =
    idl_global->gen ()->create_typedef (sequence,
                                        &seq_name,
                                        0,
                                        0);
  seq_id.destroy ();

  (void) c->fe_add_typedef (connections);

  // In case this call comes from the backend.
  idl_global->scopes ().pop ();
}
Beispiel #3
0
int CSampleLds2Application::Run(void)
{
    // Process command line args
    const CArgs& args = GetArgs();

    const string& db_path = args["db"].AsString();

    //
    // Initialize the local data storage
    //
    if ( args["data_dir"] ) {
        try {
            CRef<CLDS2_Manager> mgr(new CLDS2_Manager(db_path));
            // Allow to split GB release bioseq-sets
            mgr->SetGBReleaseMode(CLDS2_Manager::eGB_Guess);
            if ( args["group_aligns"] ) {
                mgr->SetSeqAlignGroupSize(args["group_aligns"].AsInteger());
            }
            mgr->AddDataDir(args["data_dir"].AsString());
            mgr->UpdateData();
        }
        catch(CException& e) {
            ERR_POST("Error initializing local data storage: " << e.what());
            return 1;
        }
    }

    // Create OM and LDS2 data loader
    CRef<CObjectManager> object_manager = CObjectManager::GetInstance();
    try {
        CLDS2_DataLoader::RegisterInObjectManager(*object_manager,
            db_path, -1, CObjectManager::eDefault);
    }
    catch (CException& e) {
        ERR_POST("Error registering LDS2 data loader: " << e.what());
        return 2;
    }

    // Check if an id was requested, try to fetch some data
    if ( args["id"] ) {
        string id = args["id"].AsString();
        // Create Seq-id, set it to the GI specified on the command line
        CSeq_id seq_id(id);
        // Create a new scope ("attached" to our OM).
        CScope scope(*object_manager);
        // Add default loaders (GB loader in this demo) to the scope.
        scope.AddDefaults();

        // Get synonyms
        CBioseq_Handle::TId bh_ids = scope.GetIds(seq_id);
        NcbiCout << "Synonyms for " << id << ": ";
        string sep = "";
        ITERATE (CBioseq_Handle::TId, id_it, bh_ids) {
            cout << sep << id_it->AsString();
            sep = ", ";
        }
        cout << endl;

        // Get Bioseq handle for the Seq-id.
        CBioseq_Handle bioseq_handle = scope.GetBioseqHandle(seq_id);
        if ( !bioseq_handle ) {
            ERR_POST("Bioseq not found, with id=" << id);
        }
        else {
            // Dump the seq-entry.
            if ( args["print_entry"] ) {
                cout << MSerial_AsnText <<
                    *bioseq_handle.GetTopLevelEntry().GetCompleteSeq_entry();
            }
        }

        // Test features
        SAnnotSelector sel;
        sel.SetSearchUnresolved()
            .SetResolveAll();
        CSeq_loc loc;
        loc.SetWhole().Assign(seq_id);
        cout << "Features by location:" << endl;
        CFeat_CI fit(scope, loc, sel);
        int fcount = 0;
        for (; fit; ++fit) {
            if ( args["print_feats"] ) {
                cout << MSerial_AsnText << fit->GetOriginalFeature();
            }
            fcount++;
        }
        cout << fcount << " features found" << endl;

        cout << "Features by product:" << endl;
        sel.SetByProduct(true);
        CFeat_CI fitp(scope, loc, sel);
        fcount = 0;
        for (; fitp; ++fitp) {
            if ( args["print_feats"] ) {
                cout << MSerial_AsnText << fitp->GetOriginalFeature();
            }
            fcount++;
        }
        cout << fcount << " features found" << endl;

        // Test alignments
        cout << "Alignments:" << endl;
        sel.SetByProduct(false);
        CAlign_CI ait(scope, loc, sel);
        int acount = 0;
        for (; ait; ++ait) {
            if ( args["print_aligns"] ) {
                cout << MSerial_AsnText << ait.GetOriginalSeq_align();
            }
            acount++;
        }
        cout << acount << " alignments found" << endl;
    }
Beispiel #4
0
CRef<CBioseq> MakeMaskingBioseq(const CSeq_id& new_id,
                                TSeqPos seq_length,
                                const CSeq_id& original_id,
                                const vector<CRange<TSeqPos> >& mask_ranges)
{
    if ( !s_is_sorted(mask_ranges.begin(), mask_ranges.end(), ByFrom()) ) {
        vector<CRange<TSeqPos> > ranges(mask_ranges);
        sort(ranges.begin(), ranges.end(), ByFrom());
        return MakeMaskingBioseq(new_id, seq_length, original_id, ranges);
    }
    _ASSERT(s_is_sorted(mask_ranges.begin(), mask_ranges.end(), ByFrom()));

    CRef<CBioseq> seq(new CBioseq);
    CRef<CSeq_id> seq_id(new CSeq_id);
    seq->SetId().push_back(seq_id);
    seq_id->Assign(new_id);
    CSeq_inst& inst = seq->SetInst();
    inst.SetRepr(inst.eRepr_delta);
    inst.SetMol(inst.eMol_not_set);
    inst.SetLength(seq_length);
    CDelta_ext& delta = inst.SetExt().SetDelta();
    TSeqPos cur_pos = 0, last_pos = 0;
    vector<CRange<TSeqPos> >::const_iterator mask_it = mask_ranges.begin();
    while ( cur_pos < seq_length && mask_it != mask_ranges.end() ) {
        if ( !mask_it->Empty() ) {
            TSeqPos mask_start = mask_it->GetFrom();
            if ( mask_start <= cur_pos ) {
                TSeqPos mask_end = mask_it->GetToOpen();
                if ( mask_end > cur_pos ) {
                    cur_pos = mask_it->GetToOpen();
                }
            }
            else {
                if ( last_pos < cur_pos ) {
                    // add gap
                    CRef<CDelta_seq> seg(new CDelta_seq);
                    delta.Set().push_back(seg);
                    seg->SetLiteral().SetLength(cur_pos-last_pos);
                }
                CRef<CDelta_seq> seg(new CDelta_seq);
                delta.Set().push_back(seg);
                CSeq_interval& ref_int = seg->SetLoc().SetInt();
                ref_int.SetId().Assign(original_id);
                ref_int.SetFrom(cur_pos);
                if ( mask_start >= seq_length ) {
                    ref_int.SetTo(seq_length-1);
                    last_pos = cur_pos = seq_length;
                    break;
                }
                ref_int.SetTo(mask_start-1);
                last_pos = cur_pos = mask_start;
            }
        }
        ++mask_it;
    }
    if ( last_pos < cur_pos ) {
        // trailing gap
        CRef<CDelta_seq> seg(new CDelta_seq);
        delta.Set().push_back(seg);
        seg->SetLiteral().SetLength(cur_pos-last_pos);
    }
    return seq;
}
int main(int argc, char** argv)
{
    std::string path("/home/chi/arco/test/build/temp/");
    std::string filename("temp_0_0");
    pcl::console::parse_argument(argc, argv, "--f", filename);
    pcl::PointCloud<PointT>::Ptr cloud(new pcl::PointCloud<PointT>());
    pcl::io::loadPCDFile(path+filename+".pcd", *cloud);
    
    int w = cloud->width;
    int h = cloud->height;
    cv::Mat img = cv::Mat::zeros(h, w, CV_8UC3);
    for( size_t i = 0 ; i < cloud->size() ; i++ )
    {
        int r = i / w;
        int c = i % w;
        
        uint32_t rgb_tmp = cloud->at(i).rgba;
        
        img.at<uchar>(r, c*3+2) = (rgb_tmp >> 16) & 0x0000ff;
        img.at<uchar>(r, c*3+1) = (rgb_tmp >> 8) & 0x0000ff;
        img.at<uchar>(r, c*3+0) = (rgb_tmp) & 0x0000ff;
    }
    
    cv::imwrite(filename+".png", img);
    return 0;
    
    
    std::string in_path("/home/chi/JHUIT/raw/");
    std::string out_path("img_tmp/");
    std::string inst_name("driller_kel_0");
    std::string seq_id("1");;
    
    float elev = ELEV;
    int max_frames = 200;
    pcl::console::parse_argument(argc, argv, "--p", in_path);
    pcl::console::parse_argument(argc, argv, "--s", seq_id);
    pcl::console::parse_argument(argc, argv, "--i", inst_name);
    pcl::console::parse_argument(argc, argv, "--elev", elev);
    pcl::console::parse_argument(argc, argv, "--max", max_frames);
        
    std::cerr << "Loading-"<< inst_name << std::endl;
    if( exists_dir(out_path) == false )
            boost::filesystem::create_directories(out_path);
    
    std::ifstream fp;
    fp.open((in_path+"/PlaneCoef_"+ seq_id + ".txt").c_str(), std::ios::in);
    if( fp.is_open() == false )
    {
        std::cerr << "Failed to open: " << in_path+"/PlaneCoef_"+ seq_id + ".txt" << std::endl;
        exit(0);
    }
    pcl::ModelCoefficients::Ptr planeCoef(new pcl::ModelCoefficients());
    planeCoef->values.resize(4);
    fp >> planeCoef->values[0] >> planeCoef->values[1] >> planeCoef->values[2] >> planeCoef->values[3];
    fp.close();
    
    std::vector< pcl::PointCloud<PointT>::Ptr > cloud_set;
    std::vector< KEYSET > keypt_set;
    std::vector< cv::Mat > keydescr_set;
    
    for( size_t j = 0 ; j < max_frames ; j++ )
    {
        std::stringstream ss;
        ss << j;
        
        if( j % 3 != 0 )
            continue;
        
        std::string filename(in_path + inst_name + "/" + inst_name + "_" + seq_id + "_" + ss.str() + ".pcd");
        
        if( exists_test(filename) == false )
            continue;
        
        pcl::PointCloud<PointT>::Ptr cloud(new pcl::PointCloud<PointT>());
        pcl::io::loadPCDFile(filename, *cloud);
        
        int w = cloud->width;
        int h = cloud->height;
        
        //std::cerr << w << " " << h << " " << cloud->size() << std::endl;
        
        cv::Mat rgb = cv::Mat::zeros(h, w, CV_8UC3);
        cv::Mat gray = cv::Mat::zeros(h, w, CV_8UC1);

        for(size_t i = 0 ; i < cloud->size() ; i++ )
        {
            int r_idx = i / w;
            int c_idx = i % w;
            
            uint32_t rgb_tmp = cloud->at(i).rgba;
            rgb.at<uchar>(r_idx, c_idx*3+2) = (rgb_tmp >> 16) & 0x0000ff;
            rgb.at<uchar>(r_idx, c_idx*3+1) = (rgb_tmp >> 8)  & 0x0000ff;
            rgb.at<uchar>(r_idx, c_idx*3+0) = (rgb_tmp)       & 0x0000ff;  
            
        }
        
        cv::cvtColor(rgb,gray,CV_BGR2GRAY);
        
        //cv::imshow("GRAY", rgb);
        //cv::waitKey();
        
        cv::SiftFeatureDetector *sift_det = new cv::SiftFeatureDetector(
            0, // nFeatures
            4, // nOctaveLayers
            0.04, // contrastThreshold 
            10, //edgeThreshold
            1.6 //sigma
            );
    
        cv::SiftDescriptorExtractor * sift_ext = new cv::SiftDescriptorExtractor();
        
        KEYSET keypoints;
        cv::Mat descriptors;
        sift_det->detect(gray, keypoints);
        sift_ext->compute(gray, keypoints, descriptors);
        printf("%d sift keypoints are found.\n", (int)keypoints.size());

        keypt_set.push_back(keypoints);
        keydescr_set.push_back(descriptors);
        
        cloud = cropCloud(cloud, planeCoef, 0.114);
        cloud_set.push_back(cloud);
        
        //cv::imshow("GRAY", in_rgb);
        //cv::waitKey();
        //cv::imwrite(out_path + ss.str() + ".jpg", in_rgb);
        
        //viewer->addPointCloud(cloud, "cloud");
        //viewer->spin();
        //if( show_keys )
        /*
        {
            cv::Mat out_image;
            cv::drawKeypoints(gray, keypoints, out_image);
            cv::imshow("keypoints", out_image);
            cv::waitKey();
        }
        //*/
        
    }
    
    int total = cloud_set.size();
    /*
    std::vector< pcl::PointCloud<PointT>::Ptr > first_half, second_half;
    std::vector< KEYSET > first_keypt, second_keypt;
    std::vector< cv::Mat > first_keydescr, second_keydescr;
    
    first_half.insert(first_half.end(), cloud_set.begin(), cloud_set.begin()+total/2);
    first_keypt.insert(first_keypt.end(), keypt_set.begin(), keypt_set.begin()+total/2);
    first_keydescr.insert(first_keydescr.end(), keydescr_set.begin(), keydescr_set.begin()+total/2);
    
    second_half.push_back(cloud_set[0]);
    second_keypt.push_back(keypt_set[0]);
    second_keydescr.push_back(keydescr_set[0]);
    for( int i = 1 ; i < total/2 ; i++ )
    {
        second_half.push_back(cloud_set[total-i]);
        second_keypt.push_back(keypt_set[total-i]);
        second_keydescr.push_back(keydescr_set[total-i]);
    }
    
    pcl::PointCloud<PointT>::Ptr first_model = Meshing(first_half, first_keypt, first_keydescr);
    pcl::PointCloud<PointT>::Ptr second_model = Meshing(second_half, second_keypt, second_keydescr);
    pcl::PointCloud<PointT>::Ptr full_model (new pcl::PointCloud<PointT>());
    full_model->insert(full_model->end(), first_model->begin(), first_model->end());
    full_model->insert(full_model->end(), second_model->begin(), second_model->end());
    */
    pcl::PointCloud<PointT>::Ptr full_model = Meshing(cloud_set, keypt_set, keydescr_set);
    
    full_model = cropCloud(full_model, planeCoef, elev);
    
    pcl::io::savePCDFile("temp_full.pcd", *full_model);
    
    pcl::PLYWriter ply_writer;
    ply_writer.write("temp_full.ply", *full_model, true);
    
    /*
    pcl::PointCloud<PointT>::Ptr full_model(new pcl::PointCloud<PointT>());
    pcl::io::loadPCDFile("temp_full.pcd", *full_model);
    
    std::vector<int> idx_ff;
    pcl::removeNaNFromPointCloud(*full_model, *full_model, idx_ff);
    
    pcl::PointCloud<NormalT>::Ptr full_model_normals (new pcl::PointCloud<NormalT>());
    computeNormals(full_model, full_model_normals, 0.02);
    
    AdjustCloudNormal(full_model, full_model_normals);
    
    pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer());
    viewer->initCameraParameters();
    viewer->addCoordinateSystem(0.1);
    viewer->setCameraPosition(0, 0, 0.1, 0, 0, 1, 0, -1, 0);
    
    //viewer->addPointCloud(full_model,  "full_model");
    //viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 1.0, 1.0, 1.0, "full_model");
    //viewer->addPointCloudNormals<PointT, NormalT> (full_model, full_model_normals, 5, 0.01, "normals");
    //viewer->spin();
    
    pcl::PointCloud<pcl::PointNormal>::Ptr joint_model (new pcl::PointCloud<pcl::PointNormal>());
    
    pcl::copyPointCloud(*full_model, *joint_model);
    pcl::copyPointCloud(*full_model_normals, *joint_model);
    
    //std::cerr << full_model->size() << " " << full_model_normals->size() << " " << joint_model->size() << std::endl;
    
    //pcl::concatenateFields (*full_model, *full_model_normals, *joint_model);
    pcl::search::KdTree<pcl::PointNormal>::Ptr tree2(new pcl::search::KdTree<pcl::PointNormal>);
    tree2->setInputCloud (joint_model);
    
    pcl::GreedyProjectionTriangulation<pcl::PointNormal> gp3;
    pcl::PolygonMesh model_mesh;

    gp3.setMu(2.5);
    gp3.setMaximumNearestNeighbors(100);
    gp3.setSearchRadius(0.03);
    gp3.setMaximumSurfaceAngle(M_PI/4);         // 45 degrees
    gp3.setMinimumAngle(M_PI/18);               // 10 degrees
    gp3.setMaximumAngle(2*M_PI/3);              // 120 degrees
    gp3.setNormalConsistency(false);

    // Get result
    gp3.setInputCloud (joint_model);
    gp3.setSearchMethod (tree2);
    gp3.reconstruct (model_mesh);
    
    //viewer->addPointCloud(full_model, "model");
    viewer->addPolygonMesh(model_mesh, "full_model_mesh");
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 1.0, 0.55, 0.05, "full_model_mesh");
    viewer->spin();
    */
    
    return 0;
}