Пример #1
0
ObjMesh LoadObjMesh(std::string filename)
{
	ObjMesh myMesh;

	    std::vector<Vector3f>           positions;
	    std::vector<Vector2f>           texcoords;
	    std::vector<Vector3f>           normals;
	    std::vector<_ObjMeshFaceIndex>  faces;
	    /**
	     * Load file, parse it
	     * Lines beginning with:
	     * '#'  are comments can be ignored
	     * 'v'  are vertices positions (3 floats that can be positive or negative)
	     * 'vt' are vertices texcoords (2 floats that can be positive or negative)
	     * 'vn' are vertices normals   (3 floats that can be positive or negative)
	     * 'f'  are faces, 3 values that contain 3 values which are separated by / and <space>
	     */

	    std::ifstream filestream;
	    filestream.open(filename.c_str());

		std::string line_stream;
		while(std::getline(filestream, line_stream)){
			std::stringstream str_stream(line_stream);
			std::string type_str;
	        str_stream >> type_str;
	        if(type_str == TOKEN_VERTEX_POS){
	            Vector3f pos;
	            str_stream >> pos.x >> pos.y >> pos.z;
	            positions.push_back(pos);
	        }else if(type_str == TOKEN_VERTEX_TEX){
Пример #2
0
int stringToNumber(string str)
{
	string input = str;
	istringstream str_stream(input);
	int number;
	str_stream >> number;
	return number;
}
Пример #3
0
				template<class T> Matrix<T> Read (const std::string& dname) const {

					Matrix<T> M;

					ISMRMRD::IsmrmrdDataset ds (m_fname.c_str(),dname.c_str());

					size_t i = 0, na = ds.getNumberOfAcquisitions();

					boost::shared_ptr<std::string> xml = ds.readHeader();
					std::istringstream str_stream(*xml, std::stringstream::in);

					//Let's print some information from the header
					boost::shared_ptr<ISMRMRD::ismrmrdHeader> cfg;

					try {
						cfg = boost::shared_ptr<ISMRMRD::ismrmrdHeader>(ISMRMRD::ismrmrdHeader_ (str_stream,0,m_props));
					}  catch (const xml_schema::exception& e) {
						std::cout << "Failed to parse XML Parameters: " << e.what() << std::endl;
					}

					ISMRMRD::ismrmrdHeader::encoding_sequence e_seq = cfg->encoding();
					if (e_seq.size() != 1) {
						std::cout << "Number of encoding spaces: " << e_seq.size() << std::endl;
						std::cout << "This simple reconstruction application only supports one encoding space" << std::endl;
					}

					ISMRMRD::encodingSpaceType e_space = (*e_seq.begin()).encodedSpace();
					ISMRMRD::encodingSpaceType r_space = (*e_seq.begin()).reconSpace();
					ISMRMRD::encodingLimitsType e_limits = (*e_seq.begin()).encodingLimits();

					std::cout << "Encoding Matrix Size        : [" << e_space.matrixSize().x() << ", " << e_space.matrixSize().y() << ", " << e_space.matrixSize().z() << "]" << std::endl;
					std::cout << "Reconstruction Matrix Size  : [" << r_space.matrixSize().x() << ", " << r_space.matrixSize().y() << ", " << r_space.matrixSize().z() << "]" << std::endl;
					std::cout << "Number of acquisitions      : " << ds.getNumberOfAcquisitions() << std::endl;

					if (e_space.matrixSize().z() != 1) {
						std::cout << "This simple reconstruction application only supports 2D encoding spaces" << std::endl;
					}


					// Loop over acquisitions
					for (; i < na; i++) {

						boost::shared_ptr<ISMRMRD::Acquisition> acq = ds.readAcquisition(i);

						//acq->head_.idx.kspace_encode_step_1
						//size_t offset = acq->head_.idx.kspace_encode_step_1*buffer.dimensions_[0];
						//memcpy(&buffer.data_[offset],acq->data_,sizeof(float)*2*buffer.dimensions_[0]);

					}

					printf ("%zu\n", i);

					return M;

				}
Пример #4
0
std::vector<std::string> & split(
    const std::string &s,
    char delimiter,
    std::vector<std::string> & elements) {
    std::stringstream str_stream(s);
    std::string item;
    while (std::getline(str_stream, item, delimiter)) {
        elements.push_back(item);
    }
    return elements;
}
Пример #5
0
pn::Mesh pn::RenderFactory::loadMeshFromObj(const char* filename) {
	/*
	Modified from 2010 Wouter Lindenhof (http://limegarden.net)
	*/
	
	static const std::string TOKEN_VERTEX_POS = "v";
	static const std::string TOKEN_VERTEX_NOR = "vn";
	static const std::string TOKEN_VERTEX_TEX = "vt";
	static const std::string TOKEN_FACE = "f";
	static const std::string BOUNDING_AABB = "AABB";
	static const std::string BOUNDING_OBB = "OBB";
	static const std::string BOUNDING_SPHERE = "SPHERE";
	
	std::vector<GLfloat> temp_vertices;
	temp_vertices.reserve(50000 * 3);

	std::vector<GLfloat> temp_normals;
	temp_normals.reserve(50000 * 3);

	std::vector<GLfloat> temp_texes;
	temp_texes.reserve(3 * 2);

	std::vector<GLuint> v_indices;
	v_indices.reserve(300000);

	std::vector<GLuint> vn_indices;
	vn_indices.reserve(300000);

	std::vector<GLuint> vt_indices;
	vt_indices.reserve(300000);

	std::shared_ptr<pn::BoundingContainer> bounding_container_ptr = nullptr;

	std::ifstream filestream;
	filestream.open(filename);

	if (!filestream) {
		std::cout << "OBJ Loader: Could not open file " << filename << std::endl;
	}

	std::string line_stream;
	while (std::getline(filestream, line_stream)){
		std::stringstream str_stream(line_stream);
		std::string type_str;
		str_stream >> type_str;
		if (type_str == TOKEN_VERTEX_POS){
			GLfloat pos_x, pos_y, pos_z;
			str_stream >> pos_x >> pos_y >> pos_z;
			temp_vertices.push_back(pos_x);
			temp_vertices.push_back(pos_y);
			temp_vertices.push_back(pos_z);
		}
		else if (type_str == TOKEN_VERTEX_TEX){
Пример #6
0
bool SimpleReaderBase::ReadSingleLine(vector<vector<string> >& line)
{
	if(!m_pFile->is_open() || m_pFile->eof()) return false;

	string strLine, innerToken;
	line.clear();
	getline(*m_pFile, strLine);
	istringstream str_stream(strLine);

	vector<string> header;
	vector<string> obj_part;

	if(m_nVarPerObj == 0)
	{
		while(getline(str_stream, innerToken, m_Separator))
		{
			obj_part.push_back(innerToken);
		}

		line.push_back(obj_part);
		return true;
	}
	else
	{
		int iCounter = 0;
		while(iCounter < m_nLineHeaders && getline(str_stream, innerToken, m_Separator))
		{
			header.push_back(innerToken);
			iCounter++;
		}
		obj_part.insert(obj_part.begin(), header.begin(), header.end());

		iCounter = 1;

		while(getline(str_stream, innerToken, m_Separator))
		{
			obj_part.push_back(innerToken);
			if(iCounter == m_nVarPerObj)
			{
				line.push_back(obj_part);
				obj_part.clear();

				iCounter = 0;
				obj_part.insert(obj_part.begin(), header.begin(), header.end());

			}
			iCounter++;
		}
	}

	return true;
}
Пример #7
0
void SimpleReaderBase::ParseDataTitles(const string& header)
{
	if(header.size()==0) return;

	string innerToken;
	istringstream str_stream(header);
	m_DataTitlesHeader.clear();
	while(getline(str_stream, innerToken, m_Separator))
	{
		if(innerToken.compare(m_HeaderRepeatKey)!=0)
			m_DataTitlesHeader.push_back(innerToken);
	}
}
bool is_sub_str_of(string sub_str, string str){
  if(sub_str.length() < 2){
    return false;
  }
	istringstream str_stream(str);
	while(!str_stream.eof()){
	  string temp;
	  getline(str_stream, temp, '-');
	  if(sub_str.compare(temp) == 0){
	    return true;
	  }
	}
	return false;
}
Пример #9
0
/* Call this function to load a model, only loads triangulated meshes */
void LoadObjMesh(std::string filename, ObjMesh & mesh) {

	/*std::vector<Vector3f>           positions;
	std::vector<Vector2f>           texcoords;
	std::vector<Vector3f>           normals;
	std::vector<_ObjMeshFaceIndex>  faces;
	*/
	/**
	 * Load file, parse it
	 * Lines beginning with: 
	 * '#'  are comments can be ignored
	 * 'v'  are vertices positions (3 floats that can be positive or negative)
	 * 'vt' are vertices texcoords (2 floats that can be positive or negative)
	 * 'vn' are vertices normals   (3 floats that can be positive or negative)
	 * 'f'  are faces, 3 values that contain 3 values which are separated by / and <space>
	 */

	std::vector<int> posIndices;
	std::vector<int> normalIndices;
	std::vector<int> texIndices;
	std::vector<int> faceIndices;
	std::vector<float> positions;
	std::vector<float> normals;
	std::vector<float> texCoords;

	std::ifstream filestream;
	filestream.open(filename.c_str());

	std::string line_stream;	// No longer depending on char arrays thanks to: Dale Weiler
	while(std::getline(filestream, line_stream)){	
		std::stringstream str_stream(line_stream);
		
		std::string type_str;
		str_stream >> type_str;
		if(type_str == TOKEN_VERTEX_POS){
			Vector3f pos;
			str_stream >> pos.x >> pos.y >> pos.z;
			positions.push_back(pos.x);
			positions.push_back(pos.y);
			positions.push_back(pos.z);
		}else if(type_str == TOKEN_VERTEX_TEX){
Пример #10
0
//----------------------------------------------------------------------------
qplot_xy_t qplot_read_text(
  const std::string file, long start, long size, long step,
  char separator, int xCol, int yCol)
{
  qplot_xy_t data;
  data.size = 0;

  qDebug("qplot_read_text(file='%s')", file.c_str());
  
  long cnt = 0;
  long step_cnt = 0;

  if (xCol < 0 && yCol < 0)
    return data; // stupid mission

  std::ifstream fs(file.c_str());
  std::string line;
  while (std::getline(fs, line))
  {
    if (start != 0)
    {
      start--;
      continue;
    }

    if (step_cnt-- != 0)
      continue;
    step_cnt = step - 1;

    if (size != -1 && cnt >= size)
      break;

    std::stringstream str_stream(line);
    std::string cell;
    std::vector<std::string> cells;
    cells.clear();

    while (std::getline(str_stream, cell, separator))
    { //!!! FIXME (use standart trim algoritm next time)
      str_t str = str_cstr(cell.c_str());
      str_t str_trimmed = str_trim(&str);
      
      if (separator == ' ')
      {
        if (str_size(&str_trimmed))
          cells.push_back(str_c(&str_trimmed));
      }
      else
        cells.push_back(str_c(&str_trimmed));
      
      str_free(&str_trimmed);
      str_free(&str);
    }

    if (yCol < 0)
    { // xCol >= 0 && yCol < 0
      if ((int) cells.size() > xCol)
        if (cells[yCol].size())
        {
          data.x.push_back(atof(cells[xCol].c_str()));
          data.y.push_back((double) cnt);
					cnt++;
        }
    }
    else if (xCol < 0)
    { // xCol < 0 && yCol >= 0
      if ((int) cells.size() > yCol)
        if (cells[yCol].size())
        {
          data.x.push_back((double) cnt);
          data.y.push_back(atof(cells[yCol].c_str()));
					cnt++;
        }
    }
    else
    { // xCol >= 0 && yCol >= 0
      if ((int) cells.size() > xCol && (int) cells.size() > yCol)
        if (cells[xCol].size() && cells[yCol].size())
        {
          data.x.push_back(atof(cells[xCol].c_str()));
          data.y.push_back(atof(cells[yCol].c_str()));
					cnt++;
        }
    }
  } // while (std::getline(fs, line))

  data.size = cnt;
  return data;
}