コード例 #1
0
ファイル: ProcessModel.cpp プロジェクト: DrSobik/IPPS
ProcessModel& ProcessModel::operator=(const ProcessModel &other) {
	ListDigraph::NodeMap<ListDigraph::Node> noderef(other.graph);

	if (other.head == INVALID || other.tail == INVALID) { // The other is invalid => clear this one
		clear();
		//Debugger::warn << "ProcessModel::operator= : The other PM is not valid!" << ENDL;
		return *this;
	}

	// Delete the saved stuff
	clearSaved();

	// Delete the previous operations
	clearCurrent();

	// Copy nodes and arc map of the process model
	digraphCopy(other.graph, this->graph).node(other.head, this->head).node(other.tail, this->tail).nodeRef(noderef).arcMap(other.p, this->p).arcMap(other.conjunctive, this->conjunctive).run();

	// Create and copy the operations
	for (ListDigraph::NodeIt nit(other.graph); nit != INVALID; ++nit) {
		this->ops[noderef[nit]] = new Operation(*other.ops[nit]);
	}

	return *this;
}
コード例 #2
0
sss (rtx insn, int code1, int code2, int code3)
{
  _Bool D1562;
  struct rtx_def * body;
  int i;
  int n_sets;
  int D1544;

  body = insn->u.fld[5].rt_rtx;
  D1544 = body->code;
  n_sets = 1;
  if (D1544 == 55) goto L7; else goto L1;

L1:
  n_sets = 0;
  if (code3 == 99) goto L2; else goto L11;

L2:
  D1562 = code1 == 10;
  n_sets = (int) D1562;
  if (n_sets > 0) goto L7; else goto L11;

L37:
  if (code2 == 42) goto L8; else goto L9;

L8:
  arf ();

L9:
  i = i + 1;
  if (i < n_sets) goto L37; else goto L32;

L32:

L11:
  if (n_sets > 1) goto L12; else goto L15;

L12:
  nit ();

L14:
  i = 0;
  goto L38;

L15:
  if (n_sets > 0) goto L14; else goto L16;

L38:
  frob ();
  i = i + 1;
  if (n_sets > i) goto L38; else goto L16;

L16:
  return;

L7:
  i = 0;
  goto L37;

}
コード例 #3
0
ファイル: ProcessModel.cpp プロジェクト: DrSobik/IPPS
void ProcessModel::clearSchedRelData() {

	// Collect the selection arcs
	QList<ListDigraph::Arc> selectionArcs;

	selectionArcs.clear();
	for (ListDigraph::ArcIt ait(this->graph); ait != INVALID; ++ait) {
		if (!this->conjunctive[ait]) {
			selectionArcs.append(ait);
		}
		this->p[ait] = 0.0;
	}

	// Clear the scheduling relevant data
	for (ListDigraph::NodeIt nit(this->graph); nit != INVALID; ++nit) {
		this->ops[nit]->machID = -1;
		this->ops[nit]->machAvailTime(0.0);
		this->ops[nit]->r(this->ops[nit]->ir());
		this->ops[nit]->s(this->ops[nit]->r());
		this->ops[nit]->p(0.0);
	}

	// Clear the selection arcs
	for (int i = 0; i < selectionArcs.size(); i++) {
		this->graph.erase(selectionArcs[i]);
	}
}
コード例 #4
0
ファイル: ProcessModel.cpp プロジェクト: DrSobik/IPPS
ProcessModel::~ProcessModel() {
	for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) {
		delete this->ops[nit];
	}

	// Clear the saved model if present
	clearSaved();
}
コード例 #5
0
ファイル: ProcessModel.cpp プロジェクト: DrSobik/IPPS
void ProcessModel::clearCurrent() {
	// Delete the operations
	for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) {
		delete ops[nit];
	}

	// Clear the saved graph
	graph.clear();

	head = INVALID;
	tail = INVALID;
}
コード例 #6
0
ファイル: DualGraph.cpp プロジェクト: yuwuyi/DualGraph
void DualGraph::saveGraph(const char *filename) {
    std::ofstream output(filename);
    for (NodeIter nit(this); !nit.end(); ++nit) {
        GraphNode *node = *nit;
		output << "v " << node->id() << "\n";
	}

    for (EdgeIter eit(this); !eit.end(); ++eit) {
        GraphEdge *edge = *eit;
        output << "e " << edge->from()->id() << " " << edge->to()->id() << "\n";
	}
    output.close();
}
コード例 #7
0
	void Surface::QueueOp(const gds_DrawingOp &op, gds_OpParameters *params){
		if(params){
			QueueItem it(ParamOp);
			it.paramOp.op = op;
			it.paramOp.params.reset(params);
			queue.push_back(move(it));
		}else{
			if(queue.empty() || queue.back().itemType != OpList){
				QueueItem nit(OpList);
				queue.push_back(move(nit));
			}
			auto &it = queue.back();
			it.opList.push_back(move(op));
		}
	}
コード例 #8
0
ファイル: dnachar.cpp プロジェクト: medvedevgroup/TwoPaCo
	bool DnaChar::LessSelfReverseComplement(std::string::const_iterator pit, size_t size)
	{
		std::string::const_reverse_iterator nit(pit + size);
		for (size_t i = 0; i < size; i++)
		{
			char reverse = DnaChar::ReverseChar(*nit);
			if (*pit != reverse)
			{
				return *pit < reverse;
			}

			++nit;
			++pit;
		}

		return false;
	}
コード例 #9
0
ファイル: ProcessModel.cpp プロジェクト: DrSobik/IPPS
void ProcessModel::clearSaved() {

	if (saved) {

		// TESTING
		savedOps.clear();
		savedArcs.clear();
		savedP.clear();
		savedConjunctive.clear();
		// TESTING

		saved = false;

		return;

		// Delete the saved operations
		for (ListDigraph::NodeIt nit(savedGraph); nit != INVALID; ++nit) {
			delete savedops[nit];
		}

		// Clear the saved graph
		savedGraph.clear();

		savedHead = INVALID;
		savedTail = INVALID;

		/*
		for (QHash<int, Operation* >::iterator iter = savedOps.begin(); iter != savedOps.end(); iter++) {
			delete iter.value();
		}

		savedOps.clear();

		savedArcs.clear();
		savedP.clear();
		savedConjunctive.clear();
		 */

	}

}
コード例 #10
0
ファイル: jif.cpp プロジェクト: BrysonBR/ANTsR
SEXP addNeighborhoodToImageHelper(
  SEXP r_antsimage,
  SEXP r_center,
  SEXP r_rad,
  SEXP r_vec)
{
  typedef typename ImageType::Pointer  ImagePointerType;
  const unsigned int ImageDimension = ImageType::ImageDimension;
  typedef float                        PixelType;
  typename ImageType::Pointer image =
    Rcpp::as< ImagePointerType >( r_antsimage );
  Rcpp::NumericVector center( r_center );
  Rcpp::NumericVector rad( r_rad );
  Rcpp::NumericVector intvec( r_vec );
  if ( center.size() != ImageDimension )
    Rcpp::stop("addNeighborhoodToImageHelper dim error.");
  typename itk::NeighborhoodIterator<ImageType>::SizeType nSize;
  typename ImageType::IndexType ind;
  ind.Fill( 0 );
  for ( unsigned int i=0; i<ImageDimension; i++ )
    {
    nSize[i] = rad[i];
    ind[i] = center[i]; // R coords to ITK
    }
  itk::NeighborhoodIterator<ImageType> nit( nSize, image,
    image->GetLargestPossibleRegion() ) ;
// for each location in nitSearch, compute the correlation
// of the intvec with the nit neighborhood
  nit.SetLocation( ind );
  for( unsigned int i = 0; i < nit.Size(); i++ )
    {
    typename ImageType::IndexType ind2 = nit.GetIndex(i);
    PixelType lval = image->GetPixel( ind2 );
    image->SetPixel( ind2, lval + intvec[i] );
    }
  return 0;
}
コード例 #11
0
ファイル: value.cpp プロジェクト: FirstGitHubID/avian
bool Value::uniqueSite(Context* c, Site* s)
{
  SiteIterator it(c, this);
  Site* p UNUSED = it.next();
  if (it.hasMore()) {
    // the site is not this word's only site, but if the site is
    // shared with the next word, it may be that word's only site
    if (this->nextWord != this
        and s->registerSize(c) > c->targetInfo.pointerSize) {
      SiteIterator nit(c, this->nextWord);
      Site* p = nit.next();
      if (nit.hasMore()) {
        return false;
      } else {
        return p == s;
      }
    } else {
      return false;
    }
  } else {
    assertT(c, p == s);
    return true;
  }
}
コード例 #12
0
ファイル: ProcessModel.cpp プロジェクト: DrSobik/IPPS
void ProcessModel::updateHeads() {

	QList<ListDigraph::Node> ts = topolSort();

	updateHeads(ts);

	return;

	BellmanFord<ListDigraph, ListDigraph::ArcMap<double> > bf(graph, p);

	ListDigraph::Node prodHead = INVALID;
	for (ListDigraph::OutArcIt oait(graph, head); oait != INVALID; ++oait) {
		prodHead = graph.target(oait);
		for (ListDigraph::OutArcIt oaitcur(graph, prodHead); oaitcur != INVALID; ++oaitcur) {
			p[oaitcur] = -ops[prodHead]->ir();
		}
	}

	bf.init();
	bf.addSource(head);
	//Debugger::info << "Running the BF algorithm..."<<ENDL;
	bf.start();
	//Debugger::info << "Done running the BF algorithm."<<ENDL;

	// #### IMPORTANT  #### Local ready times of the operations must be updated, but the initial ready times must be considered
	// Update the ready time of the operation
	for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) {
#ifdef DEBUG
		if (!bf.reached(nit)) {
			Debugger::err << "ProcessModel::updateHeads : Operation ID= " << ops[nit]->OID << ":" << ops[nit]->ID << " can not be reached from the root node " << ops[head]->OID << ":" << ops[head]->ID << "!" << ENDL;
		}
#endif
		ops[nit]->r(Math::max(-bf.dist(nit), ops[nit]->ir()));
		//out << "The found length: " << ops[opnodes[i]]->r() << endl;
	}
}
コード例 #13
0
ファイル: ProcessModel.cpp プロジェクト: DrSobik/IPPS
QMap<ListDigraph::Node, QMap<ListDigraph::Node, double> > ProcessModel::longestPathsLen() {
	/**
	 * Algorithm:
	 * 
	 * 1. Apply the Bellman-Ford algorithm
	 * 
	 */

	Debugger::info << "ProcessModel::longestPathsLen : Searching the longest paths in the graph..." << ENDL;

	QMap<ListDigraph::Node, QMap<ListDigraph::Node, double> > res;

	BellmanFord<ListDigraph, ListDigraph::ArcMap<double> > bf(graph, p);

	for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) { // Iterate over all nodes in the graph

		ListDigraph::Node curNode = nit;

		// Rund the B-F algorithm
		bf.run(curNode);

		// Collect the result for the current node
		for (ListDigraph::NodeIt nitOther(graph); nitOther != INVALID; ++nitOther) {
			if (bf.reached(nitOther)) {
				res[nit][nitOther] = -bf.dist(nitOther); // Minus, since the arcs have negative weights
			}
		}

	}



	Debugger::info << "ProcessModel::longestPathsLen : Longest paths found." << ENDL;

	return res;
}
コード例 #14
0
ファイル: BillOfMaterials.cpp プロジェクト: DrSobik/IPPS
void BillOfMaterials::fromDOMElement(const QDomElement& domel) {
	QDomNodeList bom_node_list; // List of nodes of the BOM in the DOM document
	QDomNodeList bom_arc_list; // List of arcs of the BOM in the DOM document
	QDomNode cur_node;
	QHash<int, ListDigraph::Node> node_map; // <node_id, actual_node>
	QMap<ListDigraph::Node, int> node_itm_type_map; // <actual_node, item_type>
	QList<QPair<int, int> > bom_arcs; // List of pairs of node_ids
	QStringList bom_arcs_str; // String representation of BOM arcs
	int bom_id;

	bom_id = domel.attribute("id").toInt();

	ID = bom_id;
	//out << "Current read BOM id: " << pboms[prod_type_id].last()->ID << endl;

	// Read the node descriptions
	cur_node = domel.firstChildElement("nodes");
	bom_node_list = cur_node.childNodes();
	node_map.clear();
	node_itm_type_map.clear();
	for (int k = 0; k < bom_node_list.size(); k++) {
		node_map[bom_node_list.item(k).toElement().attribute("id").toInt()] = graph.addNode();
		node_itm_type_map[node_map[bom_node_list.item(k).toElement().attribute("id").toInt()]] = bom_node_list.item(k).toElement().text().toInt();
		//out << "Read BOM node with id: " << bom_node_list.item(k).toElement().attribute("id").toInt() << endl;
	}

	// Read the arc descriptions
	cur_node = domel.firstChildElement("arcs");
	bom_arc_list = cur_node.childNodes();
	bom_arcs.clear();
	for (int k = 0; k < bom_arc_list.size(); k++) {
		bom_arcs_str = bom_arc_list.item(k).toElement().text().split(",");
		bom_arcs.append(QPair<int, int>());
		bom_arcs.last().first = bom_arcs_str[0].toInt();
		bom_arcs.last().second = bom_arcs_str[1].toInt();
		//out << "Read BOM arc: " << bom_arcs.last().first << "," << bom_arcs.last().second << endl;
	}

	// Create the actual BOM
	for (int ca = 0; ca < bom_arcs.size(); ca++) {
		// Add the current arc to the BOM graph
		graph.addArc(node_map[bom_arcs[ca].first], node_map[bom_arcs[ca].second]);
	}

	// Set the types of the items for each non-fictive node of the BOM graph
	for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) {
		itypeID[nit] = node_itm_type_map[nit];
	}

	// Add the head and the tail
	head = graph.addNode();
	itypeID[head] = -1;
	tail = graph.addNode();
	itypeID[tail] = -2;

	// Add the arcs from the head and the tail
	for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) {
		if (nit == head) continue;
		if (nit == tail) continue;
		// If the current node has no incoming arcs then it must be connected to the head 
		if (countInArcs(graph, nit) == 0) {
			graph.addArc(head, nit);
		}
		// If the current node has no outgoing arcs then it must be connected to the tail 
		if (countOutArcs(graph, nit) == 0) {
			graph.addArc(nit, tail);
		}
	}

	setItemIDs();

}
コード例 #15
0
ファイル: ProcessModel.cpp プロジェクト: DrSobik/IPPS
void ProcessModel::restore() {
	if (!saved) {
		Debugger::err << "ProcessModel::restore : Trying to restore an empty PM!" << ENDL;
		return;
	}

	if (saved) {

		// clearCurrent();

		// #######  TESTING
		// Remove all disjunctive arcs in the graph
		QList<ListDigraph::Arc> arcsToRem;
		for (ListDigraph::ArcIt ait(graph); ait != INVALID; ++ait) {
			ListDigraph::Arc curArc = ait;

			if (!conjunctive[ait]) arcsToRem.append(curArc);
		}

		for (int i = 0; i < arcsToRem.size(); i++) {
			ListDigraph::Arc curArc = arcsToRem[i];
			graph.erase(curArc);
		}

		// Restore the information about the operations
		for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) {
			ListDigraph::Node curNode = nit;
			*(ops[curNode]) = savedOps[curNode];
		}

		// Restore the DISJUNCTIVE arcs and the information about the arcs
		for (int i = 0; i < savedArcs.size(); i++) {
			if (!savedConjunctive[i]) { // This arc is disjunctive

				ListDigraph::Node curStartNode = savedArcs[i].first;
				ListDigraph::Node curEndNode = savedArcs[i].second;
				ListDigraph::Arc curArc = graph.addArc(curStartNode, curEndNode);

				p[curArc] = savedP[i];

				conjunctive[curArc] = savedConjunctive[i];
			}

		}

		// Restore the lengths of all arcs
		for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) {
			ListDigraph::Node curNode = nit;
			double curP = ops[curNode]->p();
			for (ListDigraph::OutArcIt oait(graph, curNode); oait != INVALID; ++oait) {
				ListDigraph::Arc curArc = oait;
				p[curArc] = -curP;
			}
		}

		// ################

		return;

		// Copy the saved graph into the current one
		ListDigraph::NodeMap<ListDigraph::Node> noderef(savedGraph);
		digraphCopy(savedGraph, graph).node(savedHead, head).node(savedTail, tail).nodeRef(noderef).arcMap(savedp, p).arcMap(savedconjunctive, conjunctive).run();

		// Create and copy the operations
		for (ListDigraph::NodeIt nit(savedGraph); nit != INVALID; ++nit) {
			this->ops[noderef[nit]] = new Operation(*savedops[nit]);
		}

		/*
		// Restore the operations
		for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) {
		 *ops[nit] = *savedOps[ops[nit]->ID];
		}

		// Restore the arcs
		for (ListDigraph::ArcIt ait(graph); ait != INVALID; ++ait) {
			arcsdel.append(ait);
		}

		for (int i = 0; i < arcsdel.size(); i++) {
			graph.erase(arcsdel[i]);
		}

		for (int i = 0; i < savedArcs.size(); i++) {
			arc = graph.addArc(savedArcs[i].first, savedArcs[i].second);
			p[arc] = savedP[i];
			conjunctive[arc] = savedConjunctive[i];
		}
		 */
	}

	//out1 << "Restored PM: " << *this << endl;
}
コード例 #16
0
ファイル: ProcessModel.cpp プロジェクト: DrSobik/IPPS
void ProcessModel::save() {
	//out1 << "Saving PM ..." << endl;

	// Delete the previous operations
	clearSaved();

	// Mark the PM to be saved
	saved = true;

	// #######  TESTING
	// Preserve the information about the operations
	savedOps.clear();
	for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) {
		ListDigraph::Node curNode = nit;
		Operation& curOp = (Operation&) * ops[curNode];

		savedOps[curNode] = curOp;
	}

	// Preserve the information about the arcs
	savedArcs.clear();
	savedP.clear();
	savedConjunctive.clear();
	for (ListDigraph::ArcIt ait(graph); ait != INVALID; ++ait) {
		ListDigraph::Arc curArc = ait;
		ListDigraph::Node curStartNode = graph.source(curArc);
		ListDigraph::Node curEndNode = graph.target(curArc);

		savedArcs.append(QPair<ListDigraph::Node, ListDigraph::Node>(curStartNode, curEndNode));

		savedP.append(p[curArc]);

		savedConjunctive.append(conjunctive[curArc]);
	}

	// ################

	return;

	// Copy the current graph into the saved graph
	//out1 << "Copying the current graph..." << endl;
	ListDigraph::NodeMap<ListDigraph::Node> noderef(graph);
	digraphCopy(graph, this->savedGraph).node(head, this->savedHead).node(tail, savedTail).nodeRef(noderef).arcMap(p, savedp).arcMap(conjunctive, savedconjunctive).run();
	//out1 << "Done copying the current graph." << endl;

	// Create and copy the operations
	//out1 << "Copying the current operations into the saved operations ..."<<endl;
	for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) {
		this->savedops[noderef[nit]] = new Operation(*ops[nit]);
	}
	//out1 << "Done copying the current operations into the saved operations."<<endl;

	/*
	// Save the operations
	for (ListDigraph::NodeIt nit(graph); nit != INVALID; ++nit) {
		savedOps[ops[nit]->ID] = new Operation(*ops[nit]);
	}

	// Save the arcs and the assigned data
	for (ListDigraph::ArcIt ait(graph); ait != INVALID; ++ait) {
		savedArcs.append(QPair<ListDigraph::Node, ListDigraph::Node > (graph.source(ait), graph.target(ait)));
		savedP.append(p[ait]);
		savedConjunctive.append(conjunctive[ait]);
	}
	 */

	//out1 << "Saved PM: " << *this << endl;
}
コード例 #17
0
ファイル: jif.cpp プロジェクト: BrysonBR/ANTsR
SEXP jointLabelFusionNeighborhoodSearchHelper(
  SEXP r_intvec,
  SEXP r_center,
  unsigned int rad,
  unsigned int radSearch,
  SEXP r_antsimage,
  SEXP r_antsimageseg)
{
  unsigned int segval = 0;
  typedef typename ImageType::Pointer  ImagePointerType;
  const unsigned int ImageDimension = ImageType::ImageDimension;
  typedef float                        PixelType;
  typename ImageType::Pointer image =
    Rcpp::as< ImagePointerType >( r_antsimage );
  typename ImageType::Pointer imageseg =
      Rcpp::as< ImagePointerType >( r_antsimageseg );
  Rcpp::NumericVector intvec( r_intvec );
  Rcpp::NumericVector outvec =
    Rcpp::NumericVector( intvec.size(), Rcpp::NumericVector::get_na() );
  Rcpp::NumericVector bestvec =
    Rcpp::NumericVector( intvec.size(), Rcpp::NumericVector::get_na() );
  Rcpp::NumericVector outsegvec =
    Rcpp::NumericVector( intvec.size(), Rcpp::NumericVector::get_na() );
  Rcpp::NumericVector bestsegvec =
    Rcpp::NumericVector( intvec.size(), Rcpp::NumericVector::get_na() );
  Rcpp::NumericVector center( r_center );
  if ( center.size() != ImageDimension )
    Rcpp::stop("jointLabelFusionNeighborhoodSearchHelper dim error.");
  typename itk::NeighborhoodIterator<ImageType>::SizeType nSize;
  typename itk::NeighborhoodIterator<ImageType>::SizeType nSizeSearch;
  typename ImageType::IndexType ind;
  ind.Fill( 0 );
  for ( unsigned int i=0; i<ImageDimension; i++ )
    {
    nSize[i] = rad;
    nSizeSearch[i] = radSearch;
    ind[i] = center[i]; // R coords to ITK
    }
  itk::NeighborhoodIterator<ImageType> nit( nSize, image,
    image->GetLargestPossibleRegion() ) ;
  itk::NeighborhoodIterator<ImageType> nitSearch( nSizeSearch, image,
    image->GetLargestPossibleRegion() ) ;
// for each location in nitSearch, compute the correlation
// of the intvec with the nit neighborhood
  nitSearch.SetLocation( ind );
  PixelType bestcor = 1.e11;
  PixelType bestsd = 0;
  PixelType bestmean = 0;
  for( unsigned int i = 0; i < nitSearch.Size(); i++ )
    {
    typename ImageType::IndexType ind2 = nitSearch.GetIndex(i);
    nit.SetLocation( ind2 );
    PixelType outmean = 0;
    PixelType outsd = 0;
    PixelType inmean = 0;
    PixelType insd = 0;
    for ( unsigned int i=0; i < intvec.size(); i++ ) {
      PixelType pix = image->GetPixel( nit.GetIndex(i) );
      outvec[i] = pix;
      outsegvec[i] = imageseg->GetPixel( nit.GetIndex(i) );
      outmean += pix;
      inmean += intvec[i];
      }
    outmean /= ( static_cast<PixelType>(intvec.size()) );
    inmean /= ( static_cast<PixelType>(intvec.size()) );
    for ( unsigned int i=0; i < intvec.size(); i++ ) {
      // should use recursive formula in above loop
      outsd += ( outvec[i] - outmean ) * ( outvec[i] - outmean );
      insd += ( intvec[i] - inmean ) * ( intvec[i] - inmean );
      }
    outsd = sqrt(  outsd  );
    insd = sqrt(  insd  );
    PixelType sum_uv = 0;
    PixelType sum_psearch = 0;
    PixelType ssq_psearch = 0;
    unsigned int n = intvec.size();
    for(unsigned int i = 0; i < n; i++)
      {
      PixelType v = intvec[i];
      PixelType u = outvec[i];
      sum_psearch += u;
      ssq_psearch += u * u;
      sum_uv += u * v;
      }
    PixelType var_u_unnorm = ssq_psearch - sum_psearch * sum_psearch / n;
    if(var_u_unnorm < 1.0e-6)
      var_u_unnorm = 1.0e-6;
    PixelType locor = 0;
    if ( sum_uv > 0 )
      locor = ( -1.0 * (sum_uv * sum_uv) / var_u_unnorm );
    else
      locor = ( sum_uv * sum_uv ) / var_u_unnorm;
//  - (\Sum u_i v_i)^2 / z,   where z = sigma_v^2 * (n-1)
//      locor = locor / ( insd * outsd );
      if ( locor < bestcor )
        {
        segval = imageseg->GetPixel( ind2 );
        for ( unsigned int i=0; i < intvec.size(); i++ ) {
          bestvec[i] = outvec[i];
          bestsegvec[i] = outsegvec[i];
          }
        bestcor = locor;
        bestsd = outsd;
        bestmean = outmean;
        }
    }
  return Rcpp::List::create( Rcpp::Named("segval") = segval,
    Rcpp::Named("values") = bestvec,
    Rcpp::Named("bestmean") = bestmean,
    Rcpp::Named("bestsd") = bestsd,
    Rcpp::Named("bestcor") = bestcor,
    Rcpp::Named("bestsegvec") = bestsegvec  );
}
コード例 #18
0
ファイル: nit.c プロジェクト: suborb/reelvdr
void cNitFilter::Process(u_short Pid, u_char Tid, const u_char *Data, int Length)
{
  SI::NIT nit(Data, false);
  if (!nit.CheckCRCAndParse())
     return;
  // Some broadcasters send more than one NIT, with no apparent way of telling which
  // one is the right one to use. This is an attempt to find the NIT that contains
  // the transponder it was transmitted on and use only that one:
  int ThisNIT = -1;
  if (!networkId) {
     for (int i = 0; i < numNits; i++) {
         if (nits[i].networkId == nit.getNetworkId()) {
            if (nit.getSectionNumber() == 0) {
               // all NITs have passed by
               for (int j = 0; j < numNits; j++) {
                   if (nits[j].hasTransponder) {
                      networkId = nits[j].networkId;
                      //printf("taking NIT with network ID %d\n", networkId);
                      //XXX what if more than one NIT contains this transponder???
                      break;
                      }
                   }
               if (!networkId) {
                  //printf("none of the NITs contains transponder %d\n", Transponder());
                  return;
                  }
               }
            else {
               ThisNIT = i;
               break;
               }
            }
         }
     if (!networkId && ThisNIT < 0 && numNits < MAXNITS) {
        if (nit.getSectionNumber() == 0) {
           *nits[numNits].name = 0;
           SI::Descriptor *d;
           for (SI::Loop::Iterator it; (d = nit.commonDescriptors.getNext(it)); ) {
               switch (d->getDescriptorTag()) {
                 case SI::NetworkNameDescriptorTag: {
                      SI::NetworkNameDescriptor *nnd = (SI::NetworkNameDescriptor *)d;
#ifdef USE_PROVIDERCHARSET
                      nnd->name.getText(nits[numNits].name, MAXNETWORKNAME, NULL);
#else
                      nnd->name.getText(nits[numNits].name, MAXNETWORKNAME);
#endif
                      }
                      break;
                 default: ;
                 }
               delete d;
               }
           nits[numNits].networkId = nit.getNetworkId();
           nits[numNits].hasTransponder = false;
           //printf("NIT[%d] %5d '%s'\n", numNits, nits[numNits].networkId, nits[numNits].name);
           ThisNIT = numNits;
           numNits++;
           }
        }
     }
  else if (networkId != nit.getNetworkId())
     return; // ignore all other NITs
  else if (!sectionSyncer.Sync(nit.getVersionNumber(), nit.getSectionNumber(), nit.getLastSectionNumber()))
     return;
  if (!Channels.Lock(true, 10))
     return;
  SI::NIT::TransportStream ts;
  for (SI::Loop::Iterator it; nit.transportStreamLoop.getNext(ts, it); ) {
      SI::Descriptor *d;

      SI::Loop::Iterator it2;
      SI::FrequencyListDescriptor *fld = (SI::FrequencyListDescriptor *)ts.transportStreamDescriptors.getNext(it2, SI::FrequencyListDescriptorTag);
      int NumFrequencies = fld ? fld->frequencies.getCount() + 1 : 1;
      int Frequencies[NumFrequencies];
      if (fld) {
         int ct = fld->getCodingType();
         if (ct > 0) {
            int n = 1;
            for (SI::Loop::Iterator it3; fld->frequencies.hasNext(it3); ) {
                int f = fld->frequencies.getNext(it3);
                switch (ct) {
                  case 1: f = BCD2INT(f) / 100; break;
                  case 2: f = BCD2INT(f) / 10; break;
                  case 3: f = f * 10;  break;
                  default: ;
                  }
                Frequencies[n++] = f;
                }
            }
         else
            NumFrequencies = 1;
         }
      delete fld;

      for (SI::Loop::Iterator it2; (d = ts.transportStreamDescriptors.getNext(it2)); ) {
          switch (d->getDescriptorTag()) {
            case SI::SatelliteDeliverySystemDescriptorTag: {
                 SI::SatelliteDeliverySystemDescriptor *sd = (SI::SatelliteDeliverySystemDescriptor *)d;
                 cDvbTransponderParameters dtp;
                 int Source = cSource::FromData(cSource::stSat, BCD2INT(sd->getOrbitalPosition()), sd->getWestEastFlag());
                 int Frequency = Frequencies[0] = BCD2INT(sd->getFrequency()) / 100;
                 static char Polarizations[] = { 'H', 'V', 'L', 'R' };
                 dtp.SetPolarization(Polarizations[sd->getPolarization()]);
                 static int CodeRates[] = { FEC_NONE, FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_7_8, FEC_8_9, FEC_3_5, FEC_4_5, FEC_9_10, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_NONE };
                 dtp.SetCoderateH(CodeRates[sd->getFecInner()]);
                 static int Modulations[] = { QAM_AUTO, QPSK, PSK_8, QAM_16 };
                 dtp.SetModulation(Modulations[sd->getModulationType()]);
                 dtp.SetSystem(sd->getModulationSystem() ? SYS_DVBS2 : SYS_DVBS);
                 static int RollOffs[] = { ROLLOFF_35, ROLLOFF_25, ROLLOFF_20, ROLLOFF_AUTO };
                 dtp.SetRollOff(sd->getModulationSystem() ? RollOffs[sd->getRollOff()] : ROLLOFF_AUTO);
                 int SymbolRate = BCD2INT(sd->getSymbolRate()) / 10;
                 if (ThisNIT >= 0) {
                    for (int n = 0; n < NumFrequencies; n++) {
                        if (ISTRANSPONDER(cChannel::Transponder(Frequencies[n], dtp.Polarization()), Transponder())) {
                           nits[ThisNIT].hasTransponder = true;
                           //printf("has transponder %d\n", Transponder());
                           break;
                           }
                        }
                    break;
                    }
                 if (Setup.UpdateChannels >= 5) {
                    bool found = false;
                    bool forceTransponderUpdate = false;
                    for (cChannel *Channel = Channels.First(); Channel; Channel = Channels.Next(Channel)) {
                        if (!Channel->GroupSep() && Channel->Source() == Source && Channel->Nid() == ts.getOriginalNetworkId() && Channel->Tid() == ts.getTransportStreamId()) {
                           int transponder = Channel->Transponder();
                           found = true;
                           if (!ISTRANSPONDER(cChannel::Transponder(Frequency, dtp.Polarization()), transponder)) {
                              for (int n = 0; n < NumFrequencies; n++) {
                                  if (ISTRANSPONDER(cChannel::Transponder(Frequencies[n], dtp.Polarization()), transponder)) {
                                     Frequency = Frequencies[n];
                                     break;
                                     }
                                  }
                              }
                           if (ISTRANSPONDER(cChannel::Transponder(Frequency, dtp.Polarization()), Transponder())) // only modify channels if we're actually receiving this transponder
                              Channel->SetTransponderData(Source, Frequency, SymbolRate, dtp.ToString('S'));
                           else if (Channel->Srate() != SymbolRate || strcmp(Channel->Parameters(), dtp.ToString('S')))
                              forceTransponderUpdate = true; // get us receiving this transponder
                           }
                        }
                    if (!found || forceTransponderUpdate) {
                       for (int n = 0; n < NumFrequencies; n++) {
                           cChannel *Channel = new cChannel;
                           Channel->SetId(ts.getOriginalNetworkId(), ts.getTransportStreamId(), 0, 0);
                           if (Channel->SetTransponderData(Source, Frequencies[n], SymbolRate, dtp.ToString('S')))
                              EITScanner.AddTransponder(Channel);
                           else
                              delete Channel;
                           }
                       }
                    }
                 }
                 break;
            case SI::CableDeliverySystemDescriptorTag: {
                 SI::CableDeliverySystemDescriptor *sd = (SI::CableDeliverySystemDescriptor *)d;
                 cDvbTransponderParameters dtp;
                 int Source = cSource::FromData(cSource::stCable);
                 int Frequency = Frequencies[0] = BCD2INT(sd->getFrequency()) / 10;
                 //XXX FEC_outer???
                 static int CodeRates[] = { FEC_NONE, FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_7_8, FEC_8_9, FEC_3_5, FEC_4_5, FEC_9_10, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_AUTO, FEC_NONE };
                 dtp.SetCoderateH(CodeRates[sd->getFecInner()]);
                 static int Modulations[] = { QPSK, QAM_16, QAM_32, QAM_64, QAM_128, QAM_256, QAM_AUTO };
                 dtp.SetModulation(Modulations[min(sd->getModulation(), 6)]);
                 int SymbolRate = BCD2INT(sd->getSymbolRate()) / 10;
                 if (ThisNIT >= 0) {
                    for (int n = 0; n < NumFrequencies; n++) {
                        if (ISTRANSPONDER(Frequencies[n] / 1000, Transponder())) {
                           nits[ThisNIT].hasTransponder = true;
                           //printf("has transponder %d\n", Transponder());
                           break;
                           }
                        }
                    break;
                    }
                 if (Setup.UpdateChannels >= 5) {
                    bool found = false;
                    bool forceTransponderUpdate = false;
                    for (cChannel *Channel = Channels.First(); Channel; Channel = Channels.Next(Channel)) {
                        if (!Channel->GroupSep() && Channel->Source() == Source && Channel->Nid() == ts.getOriginalNetworkId() && Channel->Tid() == ts.getTransportStreamId()) {
                           int transponder = Channel->Transponder();
                           found = true;
                           if (!ISTRANSPONDER(Frequency / 1000, transponder)) {
                              for (int n = 0; n < NumFrequencies; n++) {
                                  if (ISTRANSPONDER(Frequencies[n] / 1000, transponder)) {
                                     Frequency = Frequencies[n];
                                     break;
                                     }
                                  }
                              }
                           if (ISTRANSPONDER(Frequency / 1000, Transponder())) // only modify channels if we're actually receiving this transponder
                              Channel->SetTransponderData(Source, Frequency, SymbolRate, dtp.ToString('C'));
                           else if (Channel->Srate() != SymbolRate || strcmp(Channel->Parameters(), dtp.ToString('C')))
                              forceTransponderUpdate = true; // get us receiving this transponder
                           }
                        }
                    if (!found || forceTransponderUpdate) {
                        for (int n = 0; n < NumFrequencies; n++) {
                           cChannel *Channel = new cChannel;
                           Channel->SetId(ts.getOriginalNetworkId(), ts.getTransportStreamId(), 0, 0);
                           if (Channel->SetTransponderData(Source, Frequencies[n], SymbolRate, dtp.ToString('C')))
                              EITScanner.AddTransponder(Channel);
                           else
                              delete Channel;
                           }
                       }
                    }
                 }
                 break;
            case SI::TerrestrialDeliverySystemDescriptorTag: {
                 SI::TerrestrialDeliverySystemDescriptor *sd = (SI::TerrestrialDeliverySystemDescriptor *)d;
                 cDvbTransponderParameters dtp;
                 int Source = cSource::FromData(cSource::stTerr);
                 int Frequency = Frequencies[0] = sd->getFrequency() * 10;
                 static int Bandwidths[] = { 8000000, 7000000, 6000000, 0, 0, 0, 0, 0 };
                 dtp.SetBandwidth(Bandwidths[sd->getBandwidth()]);
                 static int Constellations[] = { QPSK, QAM_16, QAM_64, QAM_AUTO };
                 dtp.SetModulation(Constellations[sd->getConstellation()]);
                 static int Hierarchies[] = { HIERARCHY_NONE, HIERARCHY_1, HIERARCHY_2, HIERARCHY_4, HIERARCHY_AUTO, HIERARCHY_AUTO, HIERARCHY_AUTO, HIERARCHY_AUTO };
                 dtp.SetHierarchy(Hierarchies[sd->getHierarchy()]);
                 static int CodeRates[] = { FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_7_8, FEC_AUTO, FEC_AUTO, FEC_AUTO };
                 dtp.SetCoderateH(CodeRates[sd->getCodeRateHP()]);
                 dtp.SetCoderateL(CodeRates[sd->getCodeRateLP()]);
                 static int GuardIntervals[] = { GUARD_INTERVAL_1_32, GUARD_INTERVAL_1_16, GUARD_INTERVAL_1_8, GUARD_INTERVAL_1_4 };
                 dtp.SetGuard(GuardIntervals[sd->getGuardInterval()]);
                 static int TransmissionModes[] = { TRANSMISSION_MODE_2K, TRANSMISSION_MODE_8K, TRANSMISSION_MODE_AUTO, TRANSMISSION_MODE_AUTO };
                 dtp.SetTransmission(TransmissionModes[sd->getTransmissionMode()]);
                 if (ThisNIT >= 0) {
                    for (int n = 0; n < NumFrequencies; n++) {
                        if (ISTRANSPONDER(Frequencies[n] / 1000000, Transponder())) {
                           nits[ThisNIT].hasTransponder = true;
                           //printf("has transponder %d\n", Transponder());
                           break;
                           }
                        }
                    break;
                    }
                 if (Setup.UpdateChannels >= 5) {
                    bool found = false;
                    bool forceTransponderUpdate = false;
                    for (cChannel *Channel = Channels.First(); Channel; Channel = Channels.Next(Channel)) {
                        if (!Channel->GroupSep() && Channel->Source() == Source && Channel->Nid() == ts.getOriginalNetworkId() && Channel->Tid() == ts.getTransportStreamId()) {
                           int transponder = Channel->Transponder();
                           found = true;
                           if (!ISTRANSPONDER(Frequency / 1000000, transponder)) {
                              for (int n = 0; n < NumFrequencies; n++) {
                                  if (ISTRANSPONDER(Frequencies[n] / 1000000, transponder)) {
                                     Frequency = Frequencies[n];
                                     break;
                                     }
                                  }
                              }
                           if (ISTRANSPONDER(Frequency / 1000000, Transponder())) // only modify channels if we're actually receiving this transponder
                              Channel->SetTransponderData(Source, Frequency, 0, dtp.ToString('T'));
                           else if (strcmp(Channel->Parameters(), dtp.ToString('T')))
                              forceTransponderUpdate = true; // get us receiving this transponder
                           }
                        }
                    if (!found || forceTransponderUpdate) {
                       for (int n = 0; n < NumFrequencies; n++) {
                           cChannel *Channel = new cChannel;
                           Channel->SetId(ts.getOriginalNetworkId(), ts.getTransportStreamId(), 0, 0);
                           if (Channel->SetTransponderData(Source, Frequencies[n], 0, dtp.ToString('T')))
                              EITScanner.AddTransponder(Channel);
                           else
                              delete Channel;
                           }
                        }
                    }
                 }
                 break;
            default: ;
            }
          delete d;
          }
      }
  Channels.Unlock();
}