本文整理汇总了C++中SegmentTree::getOverlap方法的典型用法代码示例。如果您正苦于以下问题:C++ SegmentTree::getOverlap方法的具体用法?C++ SegmentTree::getOverlap怎么用?C++ SegmentTree::getOverlap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SegmentTree
的用法示例。
在下文中一共展示了SegmentTree::getOverlap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
/*
mySF gg;
test(&myF);
test(gg);
*/
PolygonList plygnList;
PolygonParser plygnPrsr("polygon.txt");
if (plygnPrsr.init())
{
Polygon tmpPlygn;
DataTrans tmp(tmpPlygn);
while (plygnPrsr.hasNext())
{
//tmpPlygn.clear();
tmp.getData().clear();
plygnPrsr.getPointVec(tmp,tmp);
plygnList.push_back(tmp.getData());
}
}
VerSegCntnr tmpCntnr;
STD::vector<VerSegCntnr> segInfoVec;
GraphLib::IdType invalidId(STD::numeric_limits<int>::max());
PolygonLinkRec linkRec;
LinkRecList linkRecList;
size_t verSegCnt = 0;
size_t totalVerSegCnt = 0;
for (STD::list<Polygon>::iterator it=plygnList.begin();
it != plygnList.end(); ++it )
{
assert(0 == (*it).size() % 1 && 4 <= (*it).size() );
if (!(0==(*it).size() %1 && 4<= (*it).size()) ) continue;
linkRecList.push_back( STD::make_pair(&(*it), invalidId) );
verSegCnt = (*it).size() >> 2;
totalVerSegCnt += verSegCnt;
tmpCntnr.linkRecPtr_ = &(linkRecList.back());
//assume the first point is the most lowerleft point
//O(n) complexity
//the trap is: itA+=2 could be an action of 2,not as simple as adding.
Polygon::const_iterator itA = (*it).begin()+1;
Polygon::const_iterator itB = itA+1;
for (;itA != (*it).end() && itB != (*it).end();
itA+=2,itB+=2)
{
tmpCntnr.seg_.head_ = ((*itA).y_<=(*itB).y_) ? (*itA) : (*itB);
tmpCntnr.seg_.tail_ = ((*itA).y_<=(*itB).y_) ? (*itB) : (*itA);
printf("PUSH (%d,%d)-(%d,%d)\n", tmpCntnr.seg_.head_.x_,tmpCntnr.seg_.head_.y_,tmpCntnr.seg_.tail_.x_,tmpCntnr.seg_.tail_.y_);
segInfoVec.push_back(tmpCntnr);
}
itB = (*it).begin();
tmpCntnr.seg_.head_ = ((*itA).y_<=(*itB).y_) ? (*itA) : (*itB);
tmpCntnr.seg_.tail_ = ((*itA).y_<=(*itB).y_) ? (*itB) : (*itA);
printf("PUSH (%d,%d)-(%d,%d)\n", tmpCntnr.seg_.head_.x_,tmpCntnr.seg_.head_.y_,tmpCntnr.seg_.tail_.x_,tmpCntnr.seg_.tail_.y_);
segInfoVec.push_back(tmpCntnr);
}
//sort reversely
STD::sort(segInfoVec.begin(), segInfoVec.end(),sortVerSegByRevX);
StNodePtrVec treeNodePtrVec(2,static_cast<StNodePtrVec::value_type>(NULL));
//Collector collector(treeNodePtrVec);
SegmentTree st;
CnstrntGraph graph;
PolygonLinkRec *leftRecPtr = NULL, *rightRecPtr = NULL, *middleRecPtr = NULL;
for(size_t idx = 0; idx < segInfoVec.size(); ++idx )
{
//collect overlapped datas
treeNodePtrVec.clear();
Collector collector(treeNodePtrVec,segInfoVec[idx].linkRecPtr_,segInfoVec[idx].seg_.head_.x_);
st.getOverlap(segInfoVec[idx].seg_.head_.y_,segInfoVec[idx].seg_.tail_.y_, collector);
//use the collected datas to build contraints
if ( treeNodePtrVec[0] || treeNodePtrVec[1] )
{
middleRecPtr = segInfoVec[idx].linkRecPtr_;
if (invalidId == middleRecPtr->second )
middleRecPtr->second = graph.addNode(Gnode(middleRecPtr));
printf("Ref:%d %d %d \n", segInfoVec[idx].seg_.head_.y_, segInfoVec[idx].seg_.tail_.y_,segInfoVec[idx].seg_.tail_.x_);
if (treeNodePtrVec[0])
{
printf("left:%d,%d,%d\n", treeNodePtrVec[0]->getStartCoord(), treeNodePtrVec[0]->getEndCoord(), treeNodePtrVec[0]->getRefCoord());
leftRecPtr = static_cast<PolygonLinkRec*>(treeNodePtrVec[0]->getId());
if ( invalidId == leftRecPtr->second )
leftRecPtr->second = graph.addNode(Gnode(leftRecPtr));
SegCoord diff = segInfoVec[idx].seg_.head_.x_ - treeNodePtrVec[idx]->getRefCoord();
GraphLib::IdType edgeId;
//My personal constraint: only one constraint
if (graph.beginNodeIter(leftRecPtr->second) == graph.endNodeIter(leftRecPtr->second))
edgeId = graph.addEdge(leftRecPtr->second, middleRecPtr->second, diff);
else
edgeId = graph.getEdgeId(leftRecPtr->second,middleRecPtr->second);
if (graph.getEdgeData(edgeId).userData_ > diff)
{
graph.getEdgeData(edgeId).userData_ = diff;
//.........这里部分代码省略.........