• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ istream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中istream的典型用法代码示例。如果您正苦于以下问题:C++ istream类的具体用法?C++ istream怎么用?C++ istream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了istream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: buildGraph

/* Function buildGraph
Takes a properly formatted text input and creates class data
Properly formatted definition
First line contains an int of the number of nodes
Followed by a number of lines equal to the first line with node descriptions
followed by any number of three int with space delimiters
ends with a termination string of 0 0
*/
void GraphL::buildGraph(istream& infile) {
   int fromNode, toNode;              // from and to node ends of edge

   makeEmpty();                       // clear the graph of memory 

   infile >> size;     // read the number of nodes

   if (infile.eof()) return;          // stop if no more data
   
   string s;                          // used to read through to end of line
   getline(infile, s);

   // read graph node information
   for (int i=1; i <= size; i++) {
      // read using setData of the NodeData class,
      // something like: 
      //    adjList[i].data.setData(infile);
      // where adjList is the array of GraphNodes and
      // data is the NodeData object inside of GraphNode
       if(i > MAXNODES-1) {
			getline(infile,s);
		}
	   data[i].setData(infile);
   }
   if(size > MAXNODES-1) {
       size = MAXNODES-1;
   }
   // read the edge data and add to the adjacency list
   for (;;) {
      infile >> fromNode >> toNode;
      if (fromNode ==0 && toNode ==0) return;     // end of edge data
	  insertEdge(fromNode, toNode);
      // insert the edge into the adjacency list for fromNode

   }
}
开发者ID:christran206,项目名称:EducationPrograms,代码行数:44,代码来源:graphl.cpp


示例2: readlist

void readlist (list<T> &mylist, istream &stream, bool &isunique) {
   try {
      for (;;) {
         try {
            string line;
            getline (stream, line);
            if (stream.eof() ) {
               break;
            }
            T elem = from_string<T> (line);
            if (isunique == true) {
               if ( !mylist.contains_elem (elem) ) mylist.push (elem);
            } else {
               mylist.push (elem);
            }
         } catch (list_exn exn) {
            // If there is a problem discovered in any function, an
            // exn is thrown and printed here.
            complain() << exn.what() << endl;
         }
      }
   } catch (list_exit_exn) {
   }
}
开发者ID:Masacs,项目名称:coursework,代码行数:24,代码来源:main.cpp


示例3: menu

// menu prompts for and accepts an option selection from standard input and
// returns the character identifying the selected option
//
char menu(istream& is) {
    char c;
    int  ok = false;

    cout << '\n';
    cout << "Please select from the following options :\n";
    cout << " P - Place an order with a publisher\n";
    cout << " S - Place a special order with a publisher\n";
    cout << " A - Add one copy to an existing order\n";
    cout << " D - Record a delivery from a publisher\n";
    cout << " V - View status of books on order\n";
    cout << " Q - Quit\n";
    do {
        cout << " Your selection : ";
        c = ' ';
        is.get(c);
        if (c >= 'a' && c <= 'z')
            c -= 'a' - 'A';
        if (is.fail()) {
            is.clear();
            is.ignore(2000, '\n');
            cerr << " Invalid input.  Try again." << endl;
        } else if (c == '\n') {
            ; // no input - try again
        } else if (c != 'P' && c != 'S' && c != 'A' && c != 'D' && c != 'V'
         && c != 'Q') {
            is.ignore(2000, '\n');
            cerr << " Invalid Character.  Try again." << endl;
        } else if (is.get() != '\n') {
            is.ignore(2000, '\n');
            cerr << " Trailing Characters.  Try Again. " << endl;
        } else if (c == 'P' || c == 'S' || c == 'A' || c == 'D' || c == 'V'
         || c == 'Q')
            ok = true;
    } while (ok == 0);

    return c;
}
开发者ID:shreyaspatel,项目名称:ISBN-Registration-Application,代码行数:41,代码来源:a4main.cpp


示例4: read_var_

void read_var_(istream& sf, int& fl, double& var, double* same_var, int& i)
{
  i = 0;
  double tmp = HUGE_VAL;
  sf >> ws;
  if (sf.peek() == '*')
  {
    fl = series::fixed;
    sf.ignore();
  }
  else if (sf.peek() == '#')
  {
    fl = series::same;
    sf.ignore();
    if (isdigit(sf.peek()))
    {
      sf >> i;
      if (i >= nvar) i = 0;
      sf.clear();
    }
开发者ID:Teslos,项目名称:tdlib00-,代码行数:20,代码来源:sumsqrin.cpp


示例5: read_poll

//Read the contents of a poll(gender, age, year, studies)
//Receives as parameter the stream from which it reads
Poll read_poll(istream& list_students) {
  char current_studies[SIZE];
  Poll current_poll;
  
  //Set gender as 1 if it is male and 0 otherwise
  current_poll.gender = (list_students.get() == 'M' ? 1 : 0);
  list_students.ignore(1); //Skip the ','
  
  list_students >> current_poll.age;
  list_students.ignore(1); //Skip the ','
  
  list_students.get(current_studies, SIZE, ',');
  current_poll.studies = string(current_studies);
  list_students.ignore(1); //Skip the ','
  
  list_students >> current_poll.year;
  list_students.ignore(1); //Skip the '\n'
  
  return current_poll;
}
开发者ID:angargo,项目名称:TuentiChallenge4,代码行数:22,代码来源:ch01.cpp


示例6: fillVector

void fillVector(vector<int> &v, istream &ist, char terminator)
{
	int x;
	while(ist >> x)
		v.push_back(x);
	if(ist.bad())
		error("Some unusual error occurred, stream is in bad state.");
	if(ist.eof())
		return;
	if(ist.fail()) {
		ist.clear();	// clear stream state
		char c;
		ist >> c;
		if(c == terminator) {
			cout << "found terminator\n";
			return;
		}
		ist.unget();
		ist.clear(ios_base::failbit);	// set the state to fail
	}
开发者ID:kaustubhb,项目名称:PPPCpp,代码行数:20,代码来源:fillvector.cpp


示例7: load

      void load(istream &in){

	 ulint w_size;

	 in.read((char*)&w_size,sizeof(w_size));

	 if(w_size>0){

	    words = vector<uint64_t>(w_size);
	    in.read((char*)words.data(),sizeof(uint64_t)*w_size);

	 }

	 in.read((char*)&psum_,sizeof(psum_));

	 in.read((char*)&MASK,sizeof(MASK));

	 in.read((char*)&size_,sizeof(size_));

	 in.read((char*)&width_,sizeof(width_));

	 in.read((char*)&int_per_word_,sizeof(int_per_word_));

      }
开发者ID:vgteam,项目名称:DYNAMIC,代码行数:24,代码来源:packed_vector.hpp


示例8: readFromStreamBinary

void ImagePatch::readFromStreamBinary(istream& in) {

	char hasData;// = (char)(data != NULL);
	char hasIntegralData;// = (char) (integralData!=NULL);
	int dataRowWidth;


	in.read((char*)&width, sizeof(int));
	in.read((char*)&height, sizeof(int));
	in.read((char*)&dataRowWidth, sizeof(int));
	in.read(&hasData,sizeof(char));
	if (hasData) {
		imgData.create(height, width, CV_8U);
		unsigned char* data = imgData.data;
		in.read((char*)data, height*imageDataRowBytes());
	}
	in.read(&hasIntegralData,sizeof(char));
	if (hasIntegralData) {
		intData.create(height+1, width+1, CV_32S);
		Size s = getIntegralSize();
		integral_type* integralData = (integral_type*) intData.data;
		in.read((char*)integralData,s.height*integralDataRowBytes());
	}
}
开发者ID:hansonrobotics,项目名称:HEAD,代码行数:24,代码来源:ImagePatch.cpp


示例9: applyFilter

void EndlineFilter::applyFilter(istream & inStream, ostream & outStream)
{
	while (inStream.good()) 
	{
		char currentLetter;
		currentLetter = inStream.get();
		while (inStream.good())
		{
			if (currentLetter != '\n')
			{
				outStream << currentLetter;
				currentLetter = inStream.get();
			}
			else
			{
				outStream << "<br>" << " ";
				currentLetter = inStream.get();
			}
		}
		inStream.unget();
	}
};
开发者ID:ShannonSimpson,项目名称:Text-File-to-HTML-Converter,代码行数:22,代码来源:EndlineFilter.cpp


示例10: load

	void load(istream &in){

		ulint encode_size;
		ulint decode_size;

		in.read((char*)&encode_size,sizeof(encode_size));
		in.read((char*)&decode_size,sizeof(decode_size));

		for(ulint i=0;i<encode_size;++i){

			char_type c;
			in.read((char*)&c,sizeof(c));

			vector<bool> B;
			load_vec_bool(in,B);

			encode_.insert({c,B});

		}

		for(ulint i=0;i<decode_size;++i){

			vector<bool> B;
			load_vec_bool(in,B);

			char_type c;
			in.read((char*)&c,sizeof(c));

			decode_.insert({B,c});

		}

		in.read((char*)&sigma,sizeof(sigma));

		in.read((char*)&log_sigma,sizeof(log_sigma));

		in.read((char*)&enc_type,sizeof(enc_type));

	}
开发者ID:nicolaprezza,项目名称:DYNAMIC,代码行数:39,代码来源:alphabet_encoder.hpp


示例11: ReadString

  static void ReadString (istream & ist, char * str)
  {
    //char * hstr = str;
    char ch;

    for (;;)
      {
	ist.get(ch);
	if (!ist.good()) break;

	if (!isspace (ch))
	  {
	    ist.putback (ch);
	    break;
	  }
      }

    for (;;)
      {
	ist.get(ch);
	if (!ist.good()) break;
	if (isalpha(ch) || isdigit(ch))
	  {
	    *str = ch;
	    str++;
	  }
	else
	  {
	    ist.putback (ch);
	    break;
	  }
      }
    *str = 0;
    //  cout << "Read string (" << hstr << ")" 
    //       << "put back: " << ch << endl;
  }
开发者ID:Resistancerus,项目名称:Netgen,代码行数:36,代码来源:solid.cpp


示例12: getFunctionInput

int getFunctionInput(istream &fin, FunctionFormat &function)
{
	function.prepUp();
	fin.ignore(numeric_limits<streamsize>::max(), ':');
	if(fin.eof())
		return 1; //Could not find a function
	fin>>function.newname;
	if(!fin)
		return 1; //There was nothing after colon
	while(fin)
	{
		int temp;
		fin>>temp;
		if(fin)
			function.addReturn(temp);
	}
	fin.clear();
	while(fin.peek()!=':' && !fin.eof())
	{
		char temp_string[1000];
		fin.getline(temp_string, 1000);
		stringstream case_string_stream(temp_string);
		Case temp_case;
		case_string_stream>>temp_case.oldname;
		while(case_string_stream)
		{		
			int temp_int;
			case_string_stream>>temp_int;
			if(case_string_stream)
				temp_case.addArg(temp_int);
		}
		
		function.addCase(temp_case);
	}
	return 0;
}
开发者ID:harpreetrathore,项目名称:scilab-IPT,代码行数:36,代码来源:migrate.cpp


示例13: readImpl

//---------------------------------------------------------------------------
void EclipseGridParser::readImpl(istream& is)
//---------------------------------------------------------------------------
{
    if (!is) {
        cerr << "Could not read given input stream." << endl;
        throw exception();
    }

    // Make temporary maps that will at the end be swapped with the
    // member maps
    // NOTE: Above is no longer true, for easier implementation of
    //       the INCLUDE keyword. We lose the strong exception guarantee,
    //       though (of course retaining the basic guarantee).
    map<string, vector<int> >& intmap = integer_field_map_;
    map<string, vector<double> >& floatmap = floating_field_map_;

    // Actually read the data
    std::string keyword;
    while (is.good()) {
        is >> ignoreWhitespace;
        bool ok = readKeyword(is, keyword);
        if (ok) {
            //#ifdef VERBOSE
            cout << "Keyword found: " << keyword << endl;
            //#endif
            FieldType type = classifyKeyword(keyword);
            // std::cout << "Classification: " << type << std::endl;
            switch (type) {
            case Integer: {
                readVectorData(is, intmap[keyword]);
                break;
            }
            case FloatingPoint: {
                readVectorData(is, floatmap[keyword]);
                break;
            }
            case Timestepping: {
                SpecialMap& sm = special_field_by_epoch_[current_epoch_];
                if (start_date_.is_not_a_date()) {
                    // Set it to START date, or default if no START.
                    // This will only ever happen in the first epoch,
                    // upon first encountering a timestepping keyword.
                    if (hasField("START")) {
                      start_date_ = getSTART().date;
                    } else {
                      start_date_ = boost::gregorian::date( 1983 , 1 , 1 );
                    }
                }
                if (current_reading_mode_ == Regular) {
                    current_reading_mode_ = Timesteps;
                }
                // Get current epoch's TSTEP, if it exists, create new if not.
                SpecialMap::iterator it = sm.find("TSTEP");
                TSTEP* tstep = 0;
                if (it != sm.end()) {
                    tstep = dynamic_cast<TSTEP*>(it->second.get());
                } else {
                    SpecialFieldPtr sb_ptr(new TSTEP());
                    tstep = dynamic_cast<TSTEP*>(sb_ptr.get());
                    sm["TSTEP"] = sb_ptr;
                }
                assert(tstep != 0);
                // Append new steps to current TSTEP object
                if (keyword == "TSTEP") {
                    const int num_steps_old = tstep->tstep_.size();
                    tstep->read(is); // This will append to the TSTEP object.
                    const double added_days
                        = std::accumulate(tstep->tstep_.begin() + num_steps_old, tstep->tstep_.end(), 0.0);
                    current_time_days_ += added_days;
                } else if (keyword == "DATES") {
                    DATES dates;
                    dates.read(is);
                    for (std::size_t dix = 0; dix < dates.dates.size(); ++dix) {
                        boost::gregorian::date_duration since_start = dates.dates[dix] - start_date_;
                        double step = double(since_start.days()) - current_time_days_;
                        tstep->tstep_.push_back(step);
                        current_time_days_ = double(since_start.days());
                    }
                } else {
                    OPM_THROW(std::runtime_error, "Keyword " << keyword << " cannot be handled here.");
                }
                break;
            }
            case SpecialField: {
                if (current_reading_mode_ == Timesteps) {
                    // We have been reading timesteps, but have
                    // now encountered something else.
                    // That means we are in a new epoch.
                    current_reading_mode_ = Regular;
                    special_field_by_epoch_.push_back(SpecialMap());
                    ++current_epoch_;
                    assert(int(special_field_by_epoch_.size()) == current_epoch_ + 1);
                    // Add clones of all existing special fields to new map.
                    SpecialMap& oldmap = special_field_by_epoch_[current_epoch_ - 1];
                    SpecialMap& newmap = special_field_by_epoch_[current_epoch_];
                    for (SpecialMap::iterator it = oldmap.begin(); it != oldmap.end(); ++it) {
                        // if (it->first != "TSTEP") {
                            newmap[it->first] = cloneSpecialField(it->first, it->second);
                            //}
//.........这里部分代码省略.........
开发者ID:karbor,项目名称:opm-core,代码行数:101,代码来源:EclipseGridParser.cpp


示例14: getDump

static bool getDump (istream&          ifile,
		     ostream&          ofile,
		     vector<Data2DF*>& u    )
// ---------------------------------------------------------------------------
// Read next set of field dumps from ifile, put headers on ofile.
// ---------------------------------------------------------------------------
{
  static char* hdr_fmt[] = { 
    "%-25s "    "Session\n",
    "%-25s "    "Created\n",
    "%-25s "    "Nr, Ns, Nz, Elements\n",
    "%-25d "    "Step\n",
    "%-25.6g "  "Time\n",
    "%-25.6g "  "Time step\n",
    "%-25.6g "  "Kinvis\n",
    "%-25.6g "  "Beta\n",
    "%-25s "    "Fields written\n",
    "%-25s "    "Format\n"
  };
  char  buf[StrMax], fmt[StrMax], fields[StrMax];
  int_t i, j, swab, nf, np, nz, nel;

  if (ifile.getline(buf, StrMax).eof()) return false;
  
  if (!strstr (buf, "Session")) message (prog, "not a field file", ERROR);
  ofile << buf << endl;
  ifile.getline (buf, StrMax);
  ofile << buf << endl;

  // -- I/O Numerical description of field sizes.

  ifile >> np >> nz >> nz >> nel;
  ifile.getline (buf, StrMax);
  
  sprintf (fmt, "%1d %1d %1d %1d", np, np, nz, nel);
  sprintf (buf, hdr_fmt[2], fmt);
  ofile << buf;

  for (i = 0; i < 5; i++) {
   ifile.getline (buf, StrMax);
   ofile << buf << endl;
  }

  // -- I/O field names.

  ifile >> fields;
  nf = strlen (fields);
  for (j = 0, i = 0; i < nf; i++) fmt[j++] = fields[i];
  fmt[j] = '\0';
  sprintf (buf, hdr_fmt[8], fmt);
  ofile << buf;
  ifile.getline (buf, StrMax);

  // -- Arrange for byte-swapping if required.

  ifile.getline (buf, StrMax);

  swab = doSwap (buf);

  sprintf (buf, "binary ");
  Veclib::describeFormat (buf + strlen (buf));
  sprintf (fmt, hdr_fmt[9], buf);
  ofile << fmt;

  if (u.size() != nf) {
    u.resize (nf);
    for (i = 0; i < nf; i++) u[i] = new Data2DF (np, nz, nel, fields[i]);
  }

  for (i = 0; i < nf; i++) {
    ifile >> *u[i];
    if (swab) u[i] -> reverse();
  }

  return ifile.good();
}
开发者ID:jueqingsizhe66,项目名称:MrWang,代码行数:76,代码来源:lowpass.C


示例15: readMesh

void 
readMesh  ( istream &is, chunkSize size,char *name )
{
	tab++;

	vector<Point> vertex;
	vector<TriangleIndex> triangle;

	while (1)
	{
		chunkSize subChunkSize = 0;
		chunkID   subChunkID = 0;

		if (!(subChunkID = readChunk(is,subChunkSize))) break;

		switch (subChunkID)
		{
		case 0x4110:						// Vertex List
			{
				unsigned short number;
				is.read((char *) (void *) &number,2);

				TAB(1);
				DOUT(1) << "vertex list: " << number << " points." << endl;

				char buffer[12];

				for (int n=0;n<number;n++)
				{
					is.read(buffer,12);
					vertex.push_back
					( 
						Point
						(
							Vector
							(
								*((float *) &buffer[0]),
								*((float *) &buffer[4]),
								*((float *) &buffer[8])
							),
							Vector0
						)

					);

					TAB(2);
					DOUT(2) << vertex.back() << endl;
				}
			}
			break;
		case 0x4120:						// Face List
			{
				unsigned short number;
				is.read((char *) (void *) &number,2);

				TAB(1);
				DOUT(1) << "face list: " << number << " faces." << endl;

				char buffer[8];

				for (int n=0;n<number;n++)
				{
					is.read(buffer,8);

					TriangleIndex tri;

					tri.a = *((unsigned short *) &buffer[0]);
					tri.b = *((unsigned short *) &buffer[2]);
					tri.c = *((unsigned short *) &buffer[4]);

					if (tri.a>=vertex.size() || tri.b>=vertex.size() || tri.c>=vertex.size())
						cerr << "Error: Face data out of range." << endl;
					else
					{
						triangle.push_back(tri);

						TAB(2);
						DOUT(2) << tri.a << ',' << tri.b << ',' << tri.c << endl;
					}
				}
			}
			break;
		case 0x4130:						// Face Material
			readMaterial(is,subChunkSize-6);
			break;
		default:
			eatChunk(is,subChunkSize-6);
		}

		if (!subChunkID || size<subChunkSize)
			break;

		size -= subChunkSize;
	}

	if (callback)
		callback(vertex,triangle,name);

	tab--;
}
开发者ID:funkjunky,项目名称:Demos-and-Tutorials,代码行数:100,代码来源:read3dsb.cpp


示例16: LoadData

bool CPlayListASX::LoadData(istream& stream)
{
  CLog::Log(LOGNOTICE, "Parsing ASX");

  if(stream.peek() == '[')
  {
    return LoadAsxIniInfo(stream);
  }
  else
  {
    CXBMCTinyXML xmlDoc;
    stream >> xmlDoc;

    if (xmlDoc.Error())
    {
      CLog::Log(LOGERROR, "Unable to parse ASX info Error: %s", xmlDoc.ErrorDesc());
      return false;
    }

    TiXmlElement *pRootElement = xmlDoc.RootElement();

    // lowercase every element
    TiXmlNode *pNode = pRootElement;
    TiXmlNode *pChild = NULL;
    CStdString value;
    value = pNode->Value();
    value.ToLower();
    pNode->SetValue(value);
    while(pNode)
    {
      pChild = pNode->IterateChildren(pChild);
      if(pChild)
      {
        if (pChild->Type() == TiXmlNode::TINYXML_ELEMENT)
        {
          value = pChild->Value();
          value.ToLower();
          pChild->SetValue(value);

          TiXmlAttribute* pAttr = pChild->ToElement()->FirstAttribute();
          while(pAttr)
          {
            value = pAttr->Name();
            value.ToLower();
            pAttr->SetName(value);
            pAttr = pAttr->Next();
          }
        }

        pNode = pChild;
        pChild = NULL;
        continue;
      }

      pChild = pNode;
      pNode = pNode->Parent();
    }
    CStdString roottitle = "";
    TiXmlElement *pElement = pRootElement->FirstChildElement();
    while (pElement)
    {
      value = pElement->Value();
      if (value == "title")
      {
        roottitle = pElement->GetText();
      }
      else if (value == "entry")
      {
        CStdString title(roottitle);

        TiXmlElement *pRef = pElement->FirstChildElement("ref");
        TiXmlElement *pTitle = pElement->FirstChildElement("title");

        if(pTitle)
          title = pTitle->GetText();

        while (pRef)
        { // multiple references may apear for one entry
          // duration may exist on this level too
          value = pRef->Attribute("href");
          if (value != "")
          {
            if(title.IsEmpty())
              title = value;

            CLog::Log(LOGINFO, "Adding element %s, %s", title.c_str(), value.c_str());
            CFileItemPtr newItem(new CFileItem(title));
            newItem->SetPath(value);
            Add(newItem);
          }
          pRef = pRef->NextSiblingElement("ref");
        }
      }
      else if (value == "entryref")
      {
        value = pElement->Attribute("href");
        if (value != "")
        { // found an entryref, let's try loading that url
          auto_ptr<CPlayList> playlist(CPlayListFactory::Create(value));
          if (NULL != playlist.get())
//.........这里部分代码省略.........
开发者ID:Micromax-56,项目名称:xbmc,代码行数:101,代码来源:PlayListPLS.cpp


示例17: LoadAsxIniInfo

bool CPlayListASX::LoadAsxIniInfo(istream &stream)
{
  CLog::Log(LOGINFO, "Parsing INI style ASX");

  string name, value;

  while( stream.good() )
  {
    // consume blank rows, and blanks
    while((stream.peek() == '\r' || stream.peek() == '\n' || stream.peek() == ' ') && stream.good())
      stream.get();

    if(stream.peek() == '[')
    {
      // this is an [section] part, just ignore it
      while(stream.good() && stream.peek() != '\r' && stream.peek() != '\n')
        stream.get();
      continue;
    }
    name = "";
    value = "";
    // consume name
    while(stream.peek() != '\r' && stream.peek() != '\n' && stream.peek() != '=' && stream.good())
      name += stream.get();

    // consume =
    if(stream.get() != '=')
      continue;

    // consume value
    while(stream.peek() != '\r' && stream.peek() != '\n' && stream.good())
      value += stream.get();

    CLog::Log(LOGINFO, "Adding element %s=%s", name.c_str(), value.c_str());
    CFileItemPtr newItem(new CFileItem(value));
    newItem->SetPath(value);
    Add(newItem);
  }

  return true;
}
开发者ID:Micromax-56,项目名称:xbmc,代码行数:41,代码来源:PlayListPLS.cpp


示例18: process

void process(istream &input, ostream &output) {
    int f = 0;
    bool first = true;
    yuv4mpeg_proxy proxy(input, output);
    Mat mat_y[3];
    Mat mat_u[3];
    Mat mat_v[3];
    mat_y[0] = Mat::zeros(proxy.height(), proxy.width(), CV_8U);
    mat_u[0] = Mat::zeros(proxy.height(), proxy.width(), CV_8U);
    mat_v[0] = Mat::zeros(proxy.height(), proxy.width(), CV_8U);
    mat_y[1] = Mat::zeros(proxy.height(), proxy.width(), CV_8U);
    mat_u[1] = Mat::zeros(proxy.height(), proxy.width(), CV_8U);
    mat_v[1] = Mat::zeros(proxy.height(), proxy.width(), CV_8U);
    mat_y[2] = Mat::zeros(proxy.height(), proxy.width(), CV_8U);
    mat_u[2] = Mat::zeros(proxy.height(), proxy.width(), CV_8U);
    mat_v[2] = Mat::zeros(proxy.height(), proxy.width(), CV_8U);
    while(input.good() && output.good()) {
        int f_prev = (f+1)%2; //which is also the next to write...
        int f_now  = f;
        f = (f+1)%2;

        std::vector<unsigned char> frame;
        //for(int i = 0; i < 10; ++i) //skip
            frame = proxy.get();

        //copy frame into opencv..
        for(int y = 0, i = 0; y < proxy.height(); ++y)
        for(int x = 0; x < proxy.width(); ++x, i+=3) {
            mat_y[f_now].at<unsigned char>(y, x) = frame[i+0];
            mat_u[f_now].at<unsigned char>(y, x) = frame[i+1];
            mat_v[f_now].at<unsigned char>(y, x) = frame[i+2];
        }

        if (!first) {
            static int frame_nr = 0;
#define USE_FLOW_FIX
#define RESIZE
#ifdef RESIZE
            Mat mat_y_a_small;
            Mat mat_y_b_small;
#ifndef USE_FLOW_FIX
            int scaler = 3;
#else
            int scaler = 5;//8
#endif
            cv::resize(mat_y[f_prev], mat_y_a_small, Size(proxy.width()/scaler, proxy.height()/scaler));
            cv::resize(mat_y[f_now ], mat_y_b_small, Size(proxy.width()/scaler, proxy.height()/scaler));
            auto flow = dualOpticalFlow(mat_y_a_small, mat_y_b_small);
            std::get<0>(flow) = scaleOpticalFlow(std::get<0>(flow), mat_y[f_prev].size());
            std::get<1>(flow) = scaleOpticalFlow(std::get<1>(flow), mat_y[f_now ].size());
            //blur  ?
            blur_xy(std::get<0>(flow), scaler*2);
            blur_xy(std::get<1>(flow), scaler*2);
#else
            auto flow = dualOpticalFlow(mat_y[f_prev], mat_y[f_now]);
#endif

            //write first frame
            for(int y = 0, i = 0; y < proxy.height(); ++y)
            for(int x = 0; x < proxy.width(); ++x, i+=3) {
                frame[i+0] = mat_y[f_prev].at<unsigned char>(y, x);
                frame[i+1] = mat_u[f_prev].at<unsigned char>(y, x);
                frame[i+2] = mat_v[f_prev].at<unsigned char>(y, x);
            }
            proxy.set(frame);

            //write 50% interpolation
            int max_j = 2;
            for(int j = 1; j<max_j; ++j) {
                double f = j/double(max_j);

#ifdef USE_FLOW_FIX
                std::tuple<Mat, Mat> fixed_flow;
                std::tie(mat_y[2], fixed_flow) = dualTransformFlow_plusFix(mat_y[f_prev], mat_y[f_now], flow, nullptr    , f, 1.0-f, 1.0-f);
                std::tie(mat_u[2], fixed_flow) = dualTransformFlow_plusFix(mat_u[f_prev], mat_u[f_now], flow, &fixed_flow, f, 1.0-f, 1.0-f);
                std::tie(mat_v[2], fixed_flow) = dualTransformFlow_plusFix(mat_v[f_prev], mat_v[f_now], flow, &fixed_flow, f, 1.0-f, 1.0-f);
#else
                mat_y[2] = dualTransformFlow(mat_y[f_prev], mat_y[f_now], flow, f, 1.0-f, 1.0-f);
                mat_u[2] = dualTransformFlow(mat_u[f_prev], mat_u[f_now], flow, f, 1.0-f, 1.0-f);
                mat_v[2] = dualTransformFlow(mat_v[f_prev], mat_v[f_now], flow, f, 1.0-f, 1.0-f);
#endif

                for(int y = 0, i = 0; y < proxy.height(); ++y)
                    for(int x = 0; x < proxy.width(); ++x, i+=3) {
                        frame[i+0] = mat_y[2].at<unsigned char>(y, x);
                        frame[i+1] = mat_u[2].at<unsigned char>(y, x);
                        frame[i+2] = mat_v[2].at<unsigned char>(y, x);
                    }
                proxy.set(frame);
            }
        } else {
            first = false;
        }
    }
}
开发者ID:KoKuToru,项目名称:koku-yuv4mpeg-motioninterpolation-opencv,代码行数:95,代码来源:main.cpp


示例19: readBinary

MStatus blindDoubleData::readBinary( istream& in, unsigned )
{
    in.read( (char*) &fValue, sizeof( fValue ));
    return in.fail() ? MS::kFailure : MS::kSuccess;
}
开发者ID:DimondTheCat,项目名称:xray,代码行数:5,代码来源:blindDoubleDataCmd.cpp


示例20: NifStream

void NifStream( Char8String & val, istream& in, const NifInfo & info ) {
	val.resize(8, '\x0');
	for (int i=0; i<8; ++i)
		in.read( &val[i], 1 );
}
开发者ID:Alecu100,项目名称:niflib,代码行数:5,代码来源:NIF_IO.cpp



注:本文中的istream类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ istringstream类代码示例发布时间:2022-05-31
下一篇:
C++ irept类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap