Пример #1
0
void GraphManager::broadcastTransform(const ros::TimerEvent& ) {

    tf::Transform cam2rgb;
    cam2rgb.setRotation(tf::createQuaternionFromRPY(-1.57,0,-1.57));
    cam2rgb.setOrigin(tf::Point(0,-0.04,0));


    world2cam_ = cam2rgb*kinect_transform_;
    //printTransform("kinect", kinect_transform_);
    time_of_last_transform_ = ros::Time::now();
    br_.sendTransform(tf::StampedTransform(world2cam_, time_of_last_transform_,
                                           "/openni_camera", "/slam_transform"));

    if(!batch_processing_runs_)
        br_.sendTransform(tf::StampedTransform(cam2rgb, time_of_last_transform_,
                                               "/openni_camera", "/batch_transform"));

    //visualize the transformation
    std::stringstream ss;
    Eigen::Matrix4f transform;
    pcl_ros::transformAsMatrix(kinect_transform_, transform);
    ss << "<b>Current Camera Transformation w.r.t. the Initial Frame</b>";
    ss << "<pre>" <<  transform << "</pre>";
    QString mystring(ss.str().c_str());
    emit newTransformationMatrix(mystring);

}
Пример #2
0
/***	OVERLOADING OF THE + OPERATOR TO FACILITATE STRING CONCATENATION	***/
String& String::operator+(String &s) {
	int l=this->len+s.len;
	char *str=new char[l];
	strcpy(str,this->ch);
	strcat(str,s.ch);
	String mystring(str);
	return mystring;
}
Пример #3
0
int test_iterator_18()
{
	// std::ostreambuf_iterator: 输出流缓存迭代器
	std::string mystring("Some text here...\n");
	std::ostreambuf_iterator<char> out_it(std::cout); // stdout iterator

	std::copy(mystring.begin(), mystring.end(), out_it); // Some text here...

	return 0;
}
Пример #4
0
std::list<int> ProcessControl::getPidProcessByName(std::string name)
{
    std::list<int> result;
    qDebug() << "ProcessControl::getPidProcessByName: Begin:";
#ifndef WIN32
    QProcess myprocess;
    std::string command = std::string("ps -C ")+name+std::string(" -o pid --no-heading");
    qDebug() << "ProcessControl::getPidProcessByName: comando solicitado:" << command.c_str();
    myprocess.start(command.c_str());
    if (!myprocess.waitForFinished()) return result;
    while (!myprocess.atEnd())
    {
        char buf[16];
        qint64 length = myprocess.readLine(buf,sizeof(buf));
        if (length != -1)
        {
            QString mystring(buf);
            result.push_back(mystring.toInt());
        }
        else break;
    }
#else
      DWORD aProcesses[1024], cbNeeded, cProcesses;
      if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
	      return result;
      // Calculate how many process identifiers were returned.

      cProcesses = cbNeeded / sizeof(DWORD);
      for ( int i = 0 ; i < cProcesses; i++)
      {
	      if (aProcesses[i] != 0)
	      {
		      std::wstring nombre = PrintProcessNameAndID( aProcesses[i] );
		      std::string temp;
		      std::copy(nombre.begin(), nombre.end(), std::back_inserter(temp));
		      qDebug() << "ProcessControl::getPidProcessByName: New pid name" << aProcesses[i] <<  temp.c_str();
		      if (QString(temp.c_str()).toLower()==QString(name.c_str()).toLower())
		      {
			      qDebug() << "ProcessControl::getPidProcessByName: found proccess";
			      result.push_back((int)aProcesses[i]);
		      }
	      }
      }
      
      


#endif
    return result;
}
Пример #5
0
SelectionVOI::SelectionVOI( Anatomy *pSourceAnatomy, const float threshold, const ThresholdingOperationType opType )
    : SelectionObject( Vector( 0.0f, 0.0f, 0.0f ), Vector( 0.0f, 0.0f, 0.0f ) ),
      m_voiSize( 0 ),
      m_generationThreshold( threshold ),
      m_thresType( opType ),
      m_pIsoSurface( NULL ),
      m_sourceAnatIndex( pSourceAnatomy->getDatasetIndex() )
{   
    wxString mystring(wxT("[VOI] - ") + pSourceAnatomy->getName());
    m_name          = mystring;
    m_objectType    = VOI_TYPE;
    
    buildSurface( pSourceAnatomy );
    
    setColor( wxColour( 240, 30, 30 ) );
}
Пример #6
0
void runcint()
{
#endif
    string mystring("test string");

    if (!t01(mystring)) {
        fprintf(stderr,"fail to pass by reference\n");
        gSystem->Exit(1);
    }
    if (!t01val(mystring) ) {
        fprintf(stderr,"fail to pass by value\n");
        gSystem->Exit(1);
    }
    if (!t01p(&mystring) ) {
        fprintf(stderr,"fail to pass by address\n");
        gSystem->Exit(1);
    }
}
Пример #7
0
void MainFrame::SaveOverlay()
{
    // save overlay image
    // create a bitmap(the same size as image)
    int width =  m_nWidth;
    int height = m_nHeight;
    wxBitmap *overlay = new wxBitmap(width,height);

    // Create a memory Device Context
    wxMemoryDC memDC;
    //Tell memDC to write on.
    memDC.SelectObject( *overlay );
    m_pOverlayPane->render(memDC);

    memDC.SelectObject( wxNullBitmap );

    stringstream file;
    file<<setfill('0');
    // file<<path;
    // file<<savefolder;
    file<<"./";
    file<<"Overlay";
    file<<"/";

    if(!bfs::exists(file.str().c_str()))
    {
        bfs::create_directory(file.str().c_str());
    }
    file<<"overlay"<<setw(4)<< m_nCurrentFrame <<".png";
    cout<<"saving as "<<file.str()<<endl;

    wxString mystring(file.str().c_str(),wxConvUTF8);
    overlay->SaveFile(mystring, wxBITMAP_TYPE_PNG, (wxPalette*)NULL );

    delete overlay;
}
Пример #8
0
// --------------------------------------------------------------------------
//
// Function
//      Name:    unsigned int ProcessControl::getInstancePID(BBInstance)
//      Purpose: Obtiene el pid del proceso asociado a la instancia
//      Created: 25/6/08
//
// ------------------
unsigned int ProcessControl::getInstancePID(BBInstance myinstance)
{
	qDebug() << "ProcessControl::getInstancePID: begin:";
#ifndef WIN32
    std::string command = std::string("ps -C bbackupd -o pid,uid,command  --no-heading");
    qDebug() << "ProcessControl::getInstancePID: comando solicitado:" << command.c_str();
    QProcess myprocess;
    myprocess.start(command.c_str());
    if (!myprocess.waitForFinished()) 
    {
        myprocess.close();
        return 0;
    }
    while (!myprocess.atEnd())
    {
        char buf[1024];
        qint64 length = myprocess.readLine(buf,sizeof(buf));
        if (length != -1)
        {
            QString mystring(buf);
            QRegExp regex("^\\s*(\\d*)\\s*(\\d*)\\s*((\\w|/)*)\\s((\\w|/|\\.)*).*$");
            qDebug() << "ProcessControl::getInstancePID: Parsing line:" << mystring;
            if (regex.exactMatch(mystring))
            {
                //Comparar, y si es igual devolver
                QStringList strlist = regex.capturedTexts();
                qDebug() << "ProcessControl::getInstancePID: lista:" << strlist;
                if ((myinstance.getConfigPath().absoluteFilePath() == QFileInfo(strlist.at(5)).absoluteFilePath()) && 
                        (ProcessControl::userNamefromUID(strlist.at(2).toUInt()) == myinstance.getUserName()) ) 
                {
                    qDebug() << "Encontrado!";
                    myprocess.close();
                    return strlist.at(1).toUInt();
                }
                else
                {
                    qDebug() << "linea incorrecta" << strlist.at(5) << myinstance.getConfigPath().absoluteFilePath() << strlist.at(2).toUInt() << myinstance.getUserName();
                }
            } 
            else
            {
                qDebug() << "ProcessControl::getInstancePID: Error en la expresion regular";
            }
        }
        else break;
    }
    qDebug() << "No se encontro el proceso";
    myprocess.close();
    return 0;
#else
    std::list<int> listapids = getPidProcessByName("bbackupd.exe");
    //Para cada pid:
    for (std::list<int>::const_iterator i = listapids.begin();
		    i!= listapids.end();
		    i++)
    {
	    //	Comprobar si el uid es el usuario actual
	    //	Comprobar que el parametro es el fichero de configuraci�n que nos interesa
	    qDebug() << "ProcessControl::getInstancePID: Iterando sobre un proceso";
	    //if(getConfigPath(*i) == QString(myinstance.getConfigPath().absolutePath()) 
	    if(QFileInfo(QFileInfo(getBinaryPath(*i))) == myinstance.getBinaryPath()
			    && getPIDUserName(*i) == myinstance.getUserName()) 
	    {
		    return *i;
	    }
    }
    return 0;
#endif
}
Пример #9
0
// [[Rcpp::export]]
Rcpp::NumericVector vcf_stats_gz(std::string x) {
  Rcpp::NumericVector stats(4);  // 4 elements, all zero.  Zero is default.
  stats.names() = Rcpp::StringVector::create("meta", "header", "variants", "columns");
  
  gzFile file;
  file = gzopen (x.c_str(), "r");
  if (! file) {
    Rcpp::Rcerr << "gzopen of " << x << " failed: " << strerror (errno) << ".\n";
    return stats;
  }

  // Scroll through buffers.
  std::string lastline = "";
  while (1) {
    Rcpp::checkUserInterrupt();
    int err;
    int bytes_read;
    char buffer[LENGTH];
    bytes_read = gzread (file, buffer, LENGTH - 1);
    buffer[bytes_read] = '\0';

    std::string mystring(reinterpret_cast<char*>(buffer));  // Recast buffer as a string.
    mystring = lastline + mystring;
    std::vector < std::string > svec;  // Initialize vector of strings for parsed buffer.
    
    char split = '\n'; // Must be single quotes!
    vcfRCommon::strsplit(mystring, svec, split);
        
    // Scroll through lines derived from the buffer.
    unsigned int i = 0;
    for(i=0; i < svec.size() - 1; i++){
      stat_line(stats, svec[i]);
    }
    // Manage the last line.
    lastline = svec[svec.size() - 1];

    // Check for EOF or errors.
    if (bytes_read < LENGTH - 1) {
      if ( gzeof (file) ) {
        if( stats(3) == 0 ){
          // Count columns from last line.
          std::vector < std::string > col_vec;
          char col_split = '\t'; // Must be single quotes!
          vcfRCommon::strsplit(svec[0], col_vec, col_split);
          stats(3) = col_vec.size();
        }
        break;
      }
      else {
        const char * error_string;
        error_string = gzerror (file, & err);
        if (err) {
          Rcpp::Rcerr << "Error: " << error_string << ".\n";
          return stats;
        }
      }
    }
  }
  gzclose (file);

  return stats;
}
Пример #10
0
// [[Rcpp::export]]
Rcpp::CharacterMatrix read_body_gz(std::string x,
                                   Rcpp::NumericVector stats,
                                   int nrows = -1,
                                   int skip = 0,
                                   Rcpp::IntegerVector cols = 0,
                                   int convertNA = 1,
                                   int verbose = 1) {

  // NA matrix for unexpected results.
  Rcpp::StringMatrix na_matrix(1,1);
  na_matrix(0,0) = NA_STRING;
  
  
  /*
   * Manage cols vector.
   * The first eight (1-based) columns are mandatory.
   * We can ensure they are there by adding them,
   * sorting and removing adjacent non-identical values.
   */
//  for( int i=9; i >= 1; i-- ){
  for( int i=8; i >= 1; i-- ){
    cols.push_front(i);
  }
  cols.sort();

  // Remove duplicate values using a set.
  std::set<int> s( cols.begin(), cols.end() );
  cols.assign( s.begin(), s.end() );

  cols = cols - 1; // R is 1-based, C is 0-based.

  
  // Initialize matrix for body data.
  // old: Rcpp::CharacterMatrix gt(stats[2], stats[3]);
  int row_num = 0;
  

  if( ( nrows == -1 ) & ( skip == 0 ) ){
    nrows = stats[2];
  } else if ( ( nrows != -1 ) & ( skip == 0 ) ){
    // nrows = nrows;
  } else if ( ( nrows == -1 ) & ( skip > 0) ){
    nrows = stats[2] - skip;
  } else if ( ( nrows != -1 ) & ( skip > 0) ){
    // nrows = nrows;
  } else {
    Rcpp::Rcerr << "failed to calculate return matrix geometry.";
    return na_matrix;
  }
  Rcpp::CharacterMatrix gt( nrows, cols.size() );
  
//  if ( nrows > -1 & skip == 0 ){
//    row_num = nrows;
//  } else if ( nrows == -1 & skip > 0 ){
//    row_num = stats[2] - skip;
//  } else {
//    row_num = stats[2];    
//  }
//  Rcpp::CharacterMatrix gt( row_num, cols.size() );

  row_num = 0;
  
  if( verbose == 1 ){
    Rcpp::Rcout << "Character matrix gt created.\n";
    Rcpp::Rcout << "Character matrix gt rows: ";  Rcpp::Rcout << gt.rows();
    Rcpp::Rcout << "\n";
    Rcpp::Rcout << "Character matrix gt cols: ";  Rcpp::Rcout << gt.cols();
    Rcpp::Rcout << "\n";
    Rcpp::Rcout << "skip: ";  Rcpp::Rcout << skip;
    Rcpp::Rcout << "\n";
    Rcpp::Rcout << "nrows: ";  Rcpp::Rcout << nrows;
    Rcpp::Rcout << "\n";
    Rcpp::Rcout << "row_num: ";  Rcpp::Rcout << row_num;
    Rcpp::Rcout << "\n";
    Rcpp::Rcout << "\n";
  }

  
  // Create filehandle and open.
  gzFile file;
  file = gzopen (x.c_str(), "r");
  if (! file) {
    Rcpp::Rcerr << "gzopen of " << x << " failed: " << strerror (errno) << ".\n";
    return na_matrix;
  }


  // Because the last line may be incomplete,
  // We'll typically omit it from processing and
  // concatenate it to the first line.
  // But first we'll have to initialize it.
  std::string lastline = "";
  
  // String vector to store the header (^#CHROM...).
  std::vector<std::string> header_vec;
  
  // variant counter.  
  int var_num = 0;


  // Scroll through buffers.
  while (1) {
    Rcpp::checkUserInterrupt();
    int err;

    // Slurp in a buffer.
    int bytes_read;
    char buffer[LENGTH];
    bytes_read = gzread (file, buffer, LENGTH - 1);
    buffer[bytes_read] = '\0'; // Terminate the buffer.

    std::string mystring(reinterpret_cast<char*>(buffer));  // Recast buffer as a string.
    mystring = lastline + mystring; // Concatenate last line to the buffer
    
    // Delimit into lines.
    std::vector < std::string > svec;  // Initialize vector of strings for parsed buffer.
    char split = '\n'; // Must be single quotes!
    vcfRCommon::strsplit(mystring, svec, split);
    
    /* 
    svec should now contain a vector of strings,
    one string for each line
    where the last line may be incomplete.
    We can now process each line except the last.
    */

    // Scroll through lines.
    unsigned int i = 0;
    for(i = 0; i < svec.size() - 1; i++){
      
      // Check and remove carriage returns (Windows).
      if( svec[i][ svec[i].size()-1] == '\r' ){
        svec[i].erase( svec[i].size() - 1 );
      }

      if(svec[i][0] == '#' && svec[i][1] == '#'){
        // Meta line, ignore.
      } else if(svec[i][0] == '#' && svec[i][1] == 'C'){
        // Process header.
//        Rcpp::Rcout << svec[i].substr(0,40) << "\n\n";
        char header_split = '\t';
        vcfRCommon::strsplit(svec[i], header_vec, header_split);
        
        // Subset the header to select columns.
        std::vector<std::string> header_vec2( cols.size() );
        for(int j=0; j<cols.size(); j++){
          header_vec2[j] = header_vec[ cols[j] ];
        }
        header_vec = header_vec2;
      } else {
        // Variant line.

        if ( ( var_num >= skip ) & ( row_num < nrows ) ){
          proc_body_line(gt, row_num, svec[i], cols, convertNA);
          row_num++; // Return matrix row number.
        }
        var_num++; // Input row number.


        if(var_num % nreport == 0 && verbose == 1){
          Rcpp::Rcout << "\rProcessed variant " << var_num;
        }
      }   
    }

    
    // Processed all lines of current buffer.
    // Keep the last line so we can append it to 
    //the beginning of the next buffer.
    lastline = svec[svec.size() - 1];

//    Rcpp::Rcout << "line-2:" << svec[svec.size() - 2].substr(0,40) << "|<-\n";
//    Rcpp::Rcout << "line-1:" << svec[svec.size() - 1].substr(0,40) << "|<-\n";
//    Rcpp::Rcout << "\n";

      
    /*
     * We can bail out early if we have read nrows.
     * Before we do we need to check that:
     * 1) we have read in nrows
     * 2) we have processed the header
     * (important when nrows is small)
     * 3) we actually have a line (when buffer ends at the end of a line).
     */
    if( ( row_num >= nrows ) & ( lastline[0] != '#' ) & ( lastline.size() > 0 ) ){
//        Rcpp::Rcout << "\nBreaking!\n";
//        Rcpp::Rcout << "lastline: " << lastline.substr(0,40) << "\n";
        break;
    }


    // Check for EOF or errors.
    if (bytes_read < LENGTH - 1) {
      if (gzeof (file)) {
        break;
      }
      else {
        const char * error_string;
        error_string = gzerror (file, & err);
        if (err) {
          Rcpp::Rcerr << "Error: " << error_string << ".\n";
          return na_matrix;
        }
      }
    }
    
  // Return to top of loop and process another buffer.
  } // Close while.
  
  // Close filehandle.
  gzclose (file);

//  Rcpp::Rcout << "\n\n>>---<< Made it: file close! >>---<<\n\n";
//  Rcpp::Rcout << "header_vec.size(): " << header_vec.size() << "\n";
  
  
  if( stats[1] == 0 ){
    if( verbose == 1 ){
      Rcpp::Rcout << "Warning: no header information was found! Data contains no sample names!\n";
    }
  } else {

    if( header_vec.size() == (unsigned)gt.ncol() ){
      header_vec[0] = "CHROM";
      gt.attr("dimnames") = Rcpp::List::create(Rcpp::CharacterVector::create(), header_vec);
    } else {
      if( verbose == 1 ){
        Rcpp::Rcout << "Warning: no header information found!\n";
      }
    }
  }

//  Rcpp::Rcout << "\n\n>>---<< Made it! >>---<<\n\n";

    
  if(verbose == 1){
    Rcpp::Rcout << "\rProcessed variant: " << var_num;
    Rcpp::Rcout << "\nAll variants processed\n";
  }

//  Rcpp::DataFrame df1 = Rcpp::DataFrame::create(gt);
//  Rcpp::DataFrame df1(gt);
//  df1.names() = header_vec;
//  if(verbose == 1){
//    Rcpp::Rcout << "Rcpp::DataFrame created.\n";
//  }
  

  return gt;
}
Пример #11
0
// [[Rcpp::export]]
Rcpp::StringVector read_meta_gz(std::string x, Rcpp::NumericVector stats, int verbose) {
  // Read in the meta lines.
  // stats consists of elements ("meta", "header", "variants", "columns");

  Rcpp::StringVector meta(stats[0]);
  std::string line;  // String for reading file into
  int meta_row = 0;

  gzFile file;
  file = gzopen (x.c_str(), "r");
  if (! file) {
    Rcpp::Rcerr << "gzopen of " << x << " failed: " << strerror (errno) << ".\n";
    return Rcpp::StringVector(1);
  }

  // Scroll through buffers.
  std::string lastline = "";
  while (1) {
    Rcpp::checkUserInterrupt();
    int err;
    int bytes_read;
    char buffer[LENGTH];
    bytes_read = gzread (file, buffer, LENGTH - 1);
    buffer[bytes_read] = '\0';

    std::string mystring(reinterpret_cast<char*>(buffer));  // Recast buffer as a string.
    mystring = lastline + mystring;
    std::vector < std::string > svec;  // Initialize vector of strings for parsed buffer.
    char split = '\n'; // Must be single quotes!
    vcfRCommon::strsplit(mystring, svec, split);


    unsigned int i = 0;
    while(meta_row < stats(0) && i < svec.size() - 1){
      
      // Check and remove carriage returns (Windows).
      if( svec[i][ svec[i].size()-1] == '\r' ){
        svec[i].erase( svec[i].size() - 1 );
      }

      meta(meta_row) = svec[i];
      meta_row++;
      i++;
      if(meta_row % nreport == 0 && verbose == 1){
        Rcpp::Rcout << "\rMeta line " << meta_row << " read in.";
      }
    }
    lastline = svec[svec.size() - 1];


    // Check for EOF or errors.
    if (bytes_read < LENGTH - 1) {
      if (gzeof (file)) {
        break;
      }
      else {
        const char * error_string;
        error_string = gzerror (file, & err);
        if (err) {
          Rcpp::Rcerr << "Error: " << error_string << ".\n";
          return Rcpp::StringVector(1);
        }
      }
    }
  }
  gzclose (file);

  if(verbose == 1){
    Rcpp::Rcout << "\rMeta line " << meta_row << " read in.";
    Rcpp::Rcout << "\nAll meta lines processed.\n";
  }

  return meta;
}
Пример #12
0
SelectionVOI::SelectionVOI( /*DatasetHelper *pDH, */Anatomy *pSourceAnatomy, const float threshold, const ThresholdingOperationType opType )
    : SelectionObject( Vector(0.0, 0.0, 0.0), Vector(0.0, 0.0, 0.0) ),
      m_voiSize( 0 )
{
    m_nbRows   = pSourceAnatomy->getRows();
    m_nbCols   = pSourceAnatomy->getColumns();
    m_nbFrames = pSourceAnatomy->getFrames();
    
    vector< float > * const pAnatDataset = pSourceAnatomy->getFloatDataset();
    
    m_includedVoxels.assign( pAnatDataset->size(), false );
    
    if( opType == THRESHOLD_EQUAL )
    {
        std::transform( pAnatDataset->begin(), pAnatDataset->end(),
                       m_includedVoxels.begin(), bind2nd( std::equal_to< float >(), threshold ) );
    }
    else if( opType == THRESHOLD_GREATER )
    {
        std::transform( pAnatDataset->begin(), pAnatDataset->end(),
                       m_includedVoxels.begin(), bind2nd( std::greater< float >(), threshold ) );
    }
    else if( opType == THRESHOLD_GREATER_EQUAL )
    {
        std::transform( pAnatDataset->begin(), pAnatDataset->end(),
                       m_includedVoxels.begin(), bind2nd( std::greater_equal< float >(), threshold ) );
    }
    else if( opType == THRESHOLD_SMALLER )
    {
        std::transform( pAnatDataset->begin(), pAnatDataset->end(),
                       m_includedVoxels.begin(), bind2nd( std::less< float >(), threshold ) );
    }
    else if( opType == THRESHOLD_SMALLER_EQUAL )
    {
        std::transform( pAnatDataset->begin(), pAnatDataset->end(),
                       m_includedVoxels.begin(), bind2nd( std::less_equal< float >(), threshold ) );

    }

    //m_isosurface    = new CIsoSurface( m_datasetHelper, pSourceAnatomy );
    m_pIsoSurface = new CBoolIsoSurface( m_includedVoxels );
    //m_isosurface->setThreshold( threshold );
    //m_isosurface->GenerateWithThreshold();
    m_pIsoSurface->GenerateSurface();
    
    wxString mystring(wxT("[VOI] - ") + pSourceAnatomy->getName());
    m_name          = mystring;
    m_objectType    = VOI_TYPE;

    //m_sourceAnatomy = i_anatomy;*/
    // TODO selection HERE was going to compute the value of the 
    // m_center and m_size params.
    unsigned int xIdxMin( m_nbCols );
    unsigned int yIdxMin( m_nbRows );
    unsigned int zIdxMin( m_nbFrames );
    unsigned int xIdxMax( 0 );
    unsigned int yIdxMax( 0 );
    unsigned int zIdxMax( 0 );
    
    unsigned int dataIdx( 0 );
    for( unsigned int zPos( 0 ); zPos < m_nbFrames; ++zPos )
    {
        for( unsigned int yPos( 0 ); yPos < m_nbRows; ++yPos )
        {
            for( unsigned int xPos( 0 ); xPos < m_nbCols; ++xPos, ++dataIdx )
            {
                if( m_includedVoxels[dataIdx] )
                {
                    xIdxMin = std::min( xIdxMin, xPos );
                    yIdxMin = std::min( yIdxMin, yPos );
                    zIdxMin = std::min( zIdxMin, zPos );
                    xIdxMax = std::max( xIdxMax, xPos );
                    yIdxMax = std::max( yIdxMax, yPos );
                    zIdxMax = std::max( zIdxMax, zPos );
                }
            }
        }
    }
    
    // Convert to space coordinates
    DatasetManager *pDM( DatasetManager::getInstance() );
    float spaceXMin( xIdxMin * pDM->getVoxelX() );
    float spaceYMin( yIdxMin * pDM->getVoxelY() );
    float spaceZMin( zIdxMin * pDM->getVoxelZ() );
    
    // For the max value, since we want to grab all of the voxel,
    // and the idx * the size of the voxel gives the begininng of the voxel
    // in space, we adjust with the +1, then the - 0.1 * voxelSize to
    // make sure not to fall in an inexisting coordinate.
    float spaceXMax( ( xIdxMax + 1 ) * pDM->getVoxelX() - 0.1 * pDM->getVoxelX() );
    float spaceYMax( ( yIdxMax + 1 ) * pDM->getVoxelY() - 0.1 * pDM->getVoxelY() );
    float spaceZMax( ( zIdxMax + 1 ) * pDM->getVoxelZ() - 0.1 * pDM->getVoxelZ() );
    //float spaceXMax( ( xIdxMax  ) * pDH->m_xVoxel  );
    //float spaceYMax( ( yIdxMax  ) * pDH->m_yVoxel  );
    //float spaceZMax( ( zIdxMax  ) * pDH->m_zVoxel  );
    
    setCenter( ( spaceXMax + spaceXMin ) / 2.0f, 
               ( spaceYMax + spaceYMin ) / 2.0f, 
               ( spaceZMax + spaceZMin ) / 2.0f );
    
    setSize( spaceXMax - spaceXMin, spaceYMax - spaceYMin, spaceZMax - spaceZMin );
    
    m_voiSize = std::count( m_includedVoxels.begin(), m_includedVoxels.end(), true );
}
Пример #13
0
// [[Rcpp::export]]
Rcpp::DataFrame read_body_gz(std::string x, Rcpp::NumericVector stats, int verbose = 1) {
  // Read in the fixed and genotype portion of the file.

  // Stats contains:
  // "meta", "header", "variants", "columns"

  // Matrix for body data.
  Rcpp::CharacterMatrix gt(stats[2], stats[3]);

  gzFile file;
  file = gzopen (x.c_str(), "r");
  if (! file) {
    Rcpp::Rcerr << "gzopen of " << x << " failed: " << strerror (errno) << ".\n";
    return Rcpp::StringVector(1);
  }

  // Scroll through buffers.
  std::string lastline = "";
  std::vector<std::string> header_vec;
  int var_num = 0;
  while (1) {
    Rcpp::checkUserInterrupt();
    int err;
    int bytes_read;
    char buffer[LENGTH];
    bytes_read = gzread (file, buffer, LENGTH - 1);
    buffer[bytes_read] = '\0';

    std::string mystring(reinterpret_cast<char*>(buffer));  // Recast buffer as a string.
    mystring = lastline + mystring;
    std::vector < std::string > svec;  // Initialize vector of strings for parsed buffer.
    char split = '\n'; // Must be single quotes!
    common::strsplit(mystring, svec, split);

    for(int i = 0; i < svec.size() - 1; i++){
      if(svec[i][0] == '#' && svec[i][1] == '#'){
        // Meta line, ignore.
      } else if(svec[i][0] == '#' && svec[i][1] != '#'){
        // Process header
        char header_split = '\t';
        common::strsplit(svec[i], header_vec, header_split);
      } else {
        // Variant line.
        proc_body_line(gt, var_num, svec[i]);
        var_num++;
        
        if(var_num % nreport == 0 && verbose == 1){
          Rcpp::Rcout << "\rProcessed variant " << var_num;
        }
      }   
//      }
    }
    lastline = svec[svec.size() - 1];


    // Check for EOF or errors.
    if (bytes_read < LENGTH - 1) {
      if (gzeof (file)) {
        break;
      }
      else {
        const char * error_string;
        error_string = gzerror (file, & err);
        if (err) {
          Rcpp::Rcerr << "Error: " << error_string << ".\n";
          return Rcpp::StringVector(1);
        }
      }
    }
  }
  gzclose (file);
  
  header_vec[0] = "CHROM";

//  Rcpp::Rcout << "Length of header_vec: " << header_vec.size() << "\n";
//  Rcpp::Rcout << "Number of columns in gt: " << gt.ncol() << "\n";
//  Rcpp::Rcout << "Number of rows in gt: " << gt.nrow() << "\n";
    
  gt.attr("dimnames") = Rcpp::List::create(Rcpp::CharacterVector::create(), header_vec);

  if(verbose == 1){
    Rcpp::Rcout << "\rProcessed variant: " << var_num;
    Rcpp::Rcout << "\nAll variants processed\n";
  }

//  Rcpp::DataFrame df1 = Rcpp::DataFrame::create(gt);
  Rcpp::DataFrame df1(gt);
//  df1.names() = header_vec;
  if(verbose == 1){
    Rcpp::Rcout << "Rcpp::DataFrame created.\n";
  }
  
//  return gt;
  return df1;
}
Пример #14
0
int main()
{
    printf("%s\n", mystring());

    return 0;
}
Пример #15
0
void MainFrame::SaveImage()
{
    cout<<"save image"<<endl;
    static unsigned int image_index=0;
    GLint l_ViewPort[4];
    glGetIntegerv(GL_VIEWPORT, l_ViewPort);

    for (int i = 0; i != 4; ++i)
    l_ViewPort[i]-=l_ViewPort[i]%4;

    int width=  (l_ViewPort[2] - l_ViewPort[0]);
    int height=(l_ViewPort[3] - l_ViewPort[1]);
    cout<<"l_Viewport[0] is "<<l_ViewPort[0]<<endl;
    cout<<"l_Viewport[1] is "<<l_ViewPort[1]<<endl;
    cout<<"l_Viewport[2] is "<<l_ViewPort[2]<<endl;
    cout<<"l_Viewport[3] is "<<l_ViewPort[3]<<endl;

    glReadBuffer(GL_BACK);
    glFinish();
    glPixelStorei(GL_PACK_ALIGNMENT, 3);
    glPixelStorei(GL_PACK_ROW_LENGTH, 0);
    glPixelStorei(GL_PACK_SKIP_ROWS, 0);
    glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
    unsigned char *glBitmapData = new unsigned char [3 * width * height];
    unsigned char *glBitmapData_flip = new unsigned char [3 * width * height];
    //  glReadPixels((GLint)0, (GLint)0, (GLint)width, (GLint)height, GL_RGB, GL_BYTE, glBitmapData);
    glReadPixels((GLint)0, (GLint)0, (GLint)width, (GLint)height, GL_RGB, GL_UNSIGNED_BYTE, glBitmapData);
    for(int i=0;i<height;++i)
    memcpy(&glBitmapData_flip[3*i*width],&glBitmapData[3*(height-i-1)*width],3*width);
    //wxImage img (width, height, glBitmapData, true);
    wxImage img (width, height, glBitmapData_flip, true);
    cout<<"width is "<<width<<endl;
    cout<<"height is "<<height<<endl;
    wxInitAllImageHandlers();

    //glReadPixels(l_ViewPort[0], l_ViewPort[1], l_ViewPort[2], l_ViewPort[3],
    //             GL_RGB,GL_UNSIGNED_BYTE,(GLvoid*)&(pixels[0]));
    //wxImage img(width, height, &(pixels[0]),true);
    //img.Mirror(false);
    cout<<"outputed data"<<endl;
    stringstream file;
    file<<setfill('0');
    // file<<path;
    // file<<savefolder;
    file<<"./";
    file<<"Rendering";
    file<<"/";

    if(!bfs::exists(file.str().c_str()))
    {
        bfs::create_directory(file.str().c_str());
    }
    file<<"render"<<setw(4)<< m_nCurrentFrame <<".png";
    //file<<"out"<<setw(3)<<image_index++<<".bmp";
    cout<<"saving as "<<file.str()<<endl;

    wxString mystring(file.str().c_str(),wxConvUTF8);
    cout<<"made mystring"<<endl;
    img.SaveFile(mystring,wxBITMAP_TYPE_PNG);
    //img.SaveFile(mystring,wxBITMAP_TYPE_BMP);
    cout<<"Saved"<<endl;
    // // Second method:

    delete [] glBitmapData;
    delete [] glBitmapData_flip;
}