Example #1
0
// 至少需要2个元素才能正确的闭合
static void EdgeJunctionClosureImpl( const AcGePoint3d& junctionPt, EdgeInfo& ges )
{
    //acutPrintf(_T("\n队列中的元素个数:%d"), ges.size());
    if( ges.size() == 1 )
    {
        ges.push_back( ges.front() );
    }

    // 把第1个添加到末尾,构成循环
    ges.push_back( ges.front() );

    // 记录每次处理闭合的当前向量
    AcGeVector3d v3 = ges.front().angle;
    v3.rotateBy( PI / 2, AcGeVector3d::kZAxis );

    AcTransaction* pTrans = actrTransactionManager->startTransaction();
    if( pTrans == 0 ) return;

    for( EdgeInfoIter itr = ges.begin(); itr != ges.end(); itr++ )
    {
        EdgeInfoIter itr2 = itr + 1;
        if( itr2 == ges.end() ) break;

        //acutPrintf(_T("\n巷道1角度:%.3f, 巷道2角度:%.3f"),
        //	itr->angle.angleTo(AcGeVector3d::kXAxis, -AcGeVector3d::kZAxis),
        //	itr2->angle.angleTo(AcGeVector3d::kXAxis, -AcGeVector3d::kZAxis));

        AcGeVector3d cv = itr->angle.crossProduct( itr2->angle ); // 叉乘(如果夹角等=0或PI,则向量=0)
        //if(cv.length() > 0.001)
        if( !cv.isZeroLength() )
        {
            //acutPrintf(_T("\n叉乘长度=%.3f"), cv.length());
            //v3 = CaclAverageVector3(itr->angle, itr2->angle);
            v3 = CaclAverageVector2( itr->angle, 1, itr2->angle, 1 );
        }
        else
        {
            // 平行(夹角=0或PI)
            //acutPrintf(_T("\n叉乘=0"));
            v3.negate();
        }

        DealWithBoundary2( pTrans, *itr, junctionPt, v3 );
        DealWithBoundary2( pTrans, *itr2, junctionPt, v3 );
    }
    actrTransactionManager->endTransaction();
}
Example #2
0
static void SortJunctionEdge( EdgeInfo& ges )
{
    // 按照角度大小排序(逆时针)
    std::sort( ges.begin(), ges.end(), SortEdgeByAngle() ); // 不能使用list,只能使用随机容器
}
Example #3
0
 void solve_pending() {
    std::cerr << "solving pending \n";
   for (std::map<Node*, EdgeInfo>::const_iterator p_out = pending_out.begin();
       p_out != pending_out.end(); ++p_out) {
      Node* n1 = (*p_out).first;
      EdgeInfo edgeOut = (*p_out).second;
      if (n1->size()) {
        std::cerr << "source is no longer empty\n";
        PtrAnal::Stmt stmt = n1->back();
        for (EdgeInfo::const_iterator p_edge = edgeOut.begin();
             p_edge != edgeOut.end(); ++p_edge) { 
            Node* n2 = (*p_edge).first;
            assert(n2->size());
            m.contrl_flow( stmt, n2->front(), (*p_edge).second);
        }
      }
      else {
        std::cerr << "source is still empty\n";
        std::map<Node*, EdgeInfo>::iterator p_in = pending_in.find(n1);
        assert(p_in != pending_in.end());
        EdgeInfo edgeIn = (*p_in).second;
        for (EdgeInfo::const_iterator p_edgeIn = edgeIn.begin();
                p_edgeIn != edgeIn.end(); ++p_edgeIn) { 
           n1 = (*p_edgeIn).first;
           assert(n1->size());
           PtrAnal::Stmt stmt1 = n1->back();
           EdgeType t = (*p_edgeIn).second;
           for (EdgeInfo::const_iterator p_edgeOut = edgeOut.begin();
                p_edgeOut != edgeOut.end(); ++p_edgeOut) { 
               EdgeType t2 = (*p_edgeOut).second;
               if (t != ALWAYS) {
                   if (t2 == ALWAYS)  
                       t2 = t;
                   else {
                      std::cerr << "Error at edge type\n"; // assert(t2 == t);
                      t2 = t;
                   }
               }
               Node* n2 = (*p_edgeOut).first;
               assert(n2->size());
                m.contrl_flow( stmt1, n2->front(), t2);
           }
         }
        pending_in.erase(p_in);
      }
   }
   pending_out.clear();
   if (pending_in.size()) {
      PtrAnal::Stmt r = m.funcexit_x(fname);
      for (std::map<Node*, EdgeInfo>::iterator p_in = pending_in.begin();
           p_in != pending_in.end(); ++p_in) {
        EdgeInfo edgeIn = (*p_in).second;
        for (EdgeInfo::const_iterator p_edgeIn = edgeIn.begin();
                p_edgeIn != edgeIn.end(); ++p_edgeIn) { 
           PtrAnal::Stmt stmt1 = (*p_edgeIn).first->back();
           EdgeType t = (*p_edgeIn).second;
           m.contrl_flow( stmt1, r, t);
        }
      }
   }
   pending_in.clear();
 }