Example #1
0
void Transformed::divideTools(const std::vector<TopoDS_Shape> &toolsIn, std::vector<TopoDS_Shape> &individualsOut,
                              TopoDS_Compound &compoundOut) const
{
  typedef std::pair<TopoDS_Shape, Bnd_Box> ShapeBoundPair;
  typedef std::list<ShapeBoundPair> PairList;
  typedef std::vector<ShapeBoundPair> PairVector;
  
  PairList pairList;
  
  std::vector<TopoDS_Shape>::const_iterator it;
  for (it = toolsIn.begin(); it != toolsIn.end(); ++it)
  {
    Bnd_Box bound;
    BRepBndLib::Add(*it, bound);
    bound.SetGap(0.0);
    ShapeBoundPair temp = std::make_pair(*it, bound);
    pairList.push_back(temp);
  }
  
  BRep_Builder builder;
  builder.MakeCompound(compoundOut);
  
  while(!pairList.empty())
  {
    PairVector currentGroup;
    currentGroup.push_back(pairList.front());
    pairList.pop_front();
    PairList::iterator it = pairList.begin();
    while(it != pairList.end())
    {
      PairVector::const_iterator groupIt;
      bool found(false);
      for (groupIt = currentGroup.begin(); groupIt != currentGroup.end(); ++groupIt)
      {
	if (!(*it).second.IsOut((*groupIt).second))//touching means is out.
	{
	  found = true;
	  break;
	}
      }
      if (found)
      {
	currentGroup.push_back(*it);
	pairList.erase(it);
	it=pairList.begin();
	continue;
      }
      it++;
    }
    if (currentGroup.size() == 1)
      builder.Add(compoundOut, currentGroup.front().first);
    else
    {
      PairVector::const_iterator groupIt;
      for (groupIt = currentGroup.begin(); groupIt != currentGroup.end(); ++groupIt)
	individualsOut.push_back((*groupIt).first);
    }
  }
}
Example #2
0
int main()
{
   Reader reader;

   /// Если одна большая плитка стоит больше чем две маленькие, то можно ничего не искать
   if( reader.A() > reader.B()*2 )
   {
      std::cout << ( reader.Stars()*reader.B() );
      return 0;
   }

   TableType adj;

   /// заполняем данными из входного файла
   reader.DoFill(adj);

   /// представляем итые клетки в виде двудольного графа
   /// представляем паркет в виде шахматной доски, черные в одной доле, белые в другой
   /// ищем максимум паросочетаний
   PairList pairs;
   FindPairs( reader.VCount(), reader.UCount(), adj, pairs );

   /// считаем найденные пары
   int count = std::count_if( pairs.begin(), pairs.end(), Compare() );
   
   std::cout << count*reader.A() + ( reader.Stars() - count*2 )*reader.B();

   return 0;
}
Example #3
0
void DomUtil::writePairListEntry(QDomDocument &doc, const QString &path, const QString &tag,
                                 const QString &firstAttr, const QString &secondAttr,
                                 const PairList &value)
{
    QDomElement el = createElementByPath(doc, path);

    PairList::ConstIterator it;
    for (it = value.begin(); it != value.end(); ++it) {
        QDomElement subEl = doc.createElement(tag);
        subEl.setAttribute(firstAttr, (*it).first);
        subEl.setAttribute(secondAttr, (*it).second);
        el.appendChild(subEl);
    }
}
void CURRENT_CLASS::computeCameraPairs()
{
    // Nothing in the scene, so no cameras needed
    if(_distancePairs.empty())
        return;

    // Entire scene can be handled by just one camera
    if(_limits.first >= _limits.second * _nearFarRatio)
    {
        _cameraPairs.push_back(_limits);
        return;
    }

    PairList::iterator i, j;

    // Sort the list of distance pairs by descending far distance
    std::sort(_distancePairs.begin(),_distancePairs.end(),precedes);

    // Combine overlapping distance pairs. The resulting set of distance
    // pairs (called combined pairs) will not overlap.
    PairList combinedPairs;
    DistancePair currPair = _distancePairs.front();
    for(i = _distancePairs.begin(); i != _distancePairs.end(); ++i)
    {
        // Current distance pair does not overlap current combined pair, so
        // save the current combined pair and start a new one.
        if(i->second < 0.99 * currPair.first)
        {
            combinedPairs.push_back(currPair);
            currPair = *i;
        }

        // Current distance pair overlaps current combined pair, so expand
        // current combined pair to encompass distance pair.
        else
            currPair.first = std::min(i->first,currPair.first);
    }
    combinedPairs.push_back(currPair); // Add last pair

    // Compute the (near,far) distance pairs for each camera.
    // Each of these distance pairs is called a "view segment".
    double currNearLimit, numSegs, new_ratio;
    double ratio_invlog = 1.0 / log(_nearFarRatio);
    unsigned int temp;
    for(i = combinedPairs.begin(); i != combinedPairs.end(); ++i)
    {
        currPair = *i; // Save current view segment

        // Compute the fractional number of view segments needed to span
        // the current combined distance pair.
        currNearLimit = currPair.second * _nearFarRatio;
        if(currPair.first >= currNearLimit)
            numSegs = 1.0;
        else
        {
            numSegs = log(currPair.first / currPair.second) * ratio_invlog;

            // Compute the near plane of the last view segment
            //currNearLimit *= pow(_nearFarRatio, -floor(-numSegs) - 1);
            for(temp = (unsigned int)(-floor(-numSegs)); temp > 1; temp--)
            {
                currNearLimit *= _nearFarRatio;
            }
        }

        // See if the closest view segment can absorb other combined pairs
        for(j = i + 1; j != combinedPairs.end(); ++j)
        {
            // No other distance pairs can be included
            if(j->first < currNearLimit)
                break;
        }

        // If we did absorb another combined distance pair, recompute the
        // number of required view segments.
        if(i != j - 1)
        {
            i = j - 1;
            currPair.first = i->first;
            if(currPair.first >= currPair.second * _nearFarRatio)
                numSegs = 1.0;
            else
                numSegs = log(currPair.first / currPair.second) * ratio_invlog;
        }

        /* Compute an integer number of segments by rounding the fractional
         number of segments according to how many segments there are.
         In general, the more segments there are, the more likely that the 
         integer number of segments will be rounded down.
         The purpose of this is to try to minimize the number of view segments
         that are used to render any section of the scene without violating
         the specified _nearFarRatio by too much. */
        if(numSegs < 10.0)
            numSegs = floor(numSegs + 1.0 - 0.1 * floor(numSegs));
        else
            numSegs = floor(numSegs);

        // Compute the near/far ratio that will be used for each view segment
        // in this section of the scene.
        new_ratio = pow(currPair.first / currPair.second,1.0 / numSegs);

        // Add numSegs new view segments to the camera pairs list
        for(temp = (unsigned int)numSegs; temp > 0; temp--)
        {
            currPair.first = currPair.second * new_ratio;
            _cameraPairs.push_back(currPair);
            currPair.second = currPair.first;
        }
    }
}