Пример #1
0
void DryadSubGraphVertex::MakeInputParser(UInt32 whichInput,
                                          RChannelItemParserRef* pParser)
{
    if (m_virtualInput == s_invalidVertex)
    {
        ReportError(DryadError_VertexInitialization,
                    "MakeInputParser called before initialization");
        return;
    }

    if (whichInput >= m_numberOfInputEdges)
    {
        ReportError(DryadError_VertexInitialization,
                    "MakeInputParser called with illegal port");
        return;
    }

    EdgeInfo* edge = m_inputEdge[whichInput];
    LogAssert(edge->GetSourceVertex() == m_virtualInput);
    LogAssert(edge->GetSourcePort() == whichInput);

    UInt32 inputVertex = edge->GetDestinationVertex();
    LogAssert(inputVertex < m_numberOfVertices);

    VertexInfo* input = &(m_vertex[inputVertex]);
    UInt32 inputPort = edge->GetDestinationPort();
    LogAssert(inputPort < input->GetInputPortCount());

    DryadVertexProgramBase* subProgram = input->GetVertexProgram();

    subProgram->MakeInputParser(inputPort, pParser);

    ReportError(subProgram->GetErrorCode(),
                subProgram->GetErrorMetaData());
}
Пример #2
0
// -------------------------------------------------------------------------
double Pgr_trspHandler::getRestrictionCost(
        int64_t edge_ind,
        const EdgeInfo &edge,
        bool isStart) {
    double cost = 0.0;
    int64_t edge_id = edge.edgeID();
    if (m_ruleTable.find(edge_id) == m_ruleTable.end()) {
        return(0.0);
    }
    auto vecRules = m_ruleTable[edge_id];
    int64_t st_edge_ind = edge_ind;
    for (const auto &rule : vecRules) {
        bool flag = true;
        int64_t v_pos = (isStart? C_EDGE : RC_EDGE);
        edge_ind = st_edge_ind;

        pgassert(!(edge_ind == -1));
        for (auto const &precedence : rule.precedencelist()) {
            if (precedence != m_edges[edge_ind].edgeID()) {
                flag = false;
                break;
            }
            auto m_parent_ind = m_parent[edge_ind].e_idx[v_pos];
            v_pos = m_parent[edge_ind].v_pos[v_pos];
            edge_ind = m_parent_ind;
        }
        if (flag)
            cost += rule.cost();
    }
    return cost;
}
Пример #3
0
void LinkedGEJunctionClosure_Helper( const AcGePoint3d& junctionPt )
{
    //acutPrintf(_T("\n闭合点:(%.3f, %.3f)"), junctionPt.x, junctionPt.y);
    AcDbObjectIdArray objIds;
    FindLinesByPoint( junctionPt, objIds );

    int len = objIds.length();
    //acutPrintf(_T("\n找到要处理闭合的分支个数:%d"), len);
    if( len < 1 ) return;

    EdgeInfo ges;
    BuildJunctionEdgeInfo( objIds, junctionPt, ges );          // 查找junctionPt坐标处的关联分支类图元
    if( ges.size() > 0 )
    {
        SortJunctionEdge( ges );                          // 调整顺序,按角度大小逆时针排列
        EdgeJunctionClosureImpl( junctionPt, ges );            // 处理并修改相邻巷道的参数
    }
    UpdateEdge( objIds );                                          // 更新实体
}
Пример #4
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();
}
Пример #5
0
bool DryadSubGraphVertex::SetUpChannels(WorkQueue* sharedWorkQueue,
                                        RChannelReader** inputChannel,
                                        RChannelWriter** outputChannel)
{
    UInt32 i;
    for (i=0; i<m_numberOfEdges; ++i)
    {
        EdgeInfo* edge = &(m_edge[i]);
        UInt32 srcVertex = edge->GetSourceVertex();
        UInt32 dstVertex = edge->GetDestinationVertex();
        UInt32 srcPort = edge->GetSourcePort();
        UInt32 dstPort = edge->GetDestinationPort();

        m_vertex[dstVertex].SetInputEdge(dstPort, edge);
        m_vertex[srcVertex].SetOutputEdge(srcPort, edge);

        if (srcVertex == m_virtualInput)
        {
            LogAssert(dstVertex != m_virtualOutput);
            m_vertex[dstVertex].SetInputChannel(dstPort, true,
                                                inputChannel[srcPort]);
        }
        else if (dstVertex == m_virtualOutput)
        {
            m_vertex[srcVertex].SetOutputChannel(srcPort, true,
                                                 outputChannel[dstPort]);
        }
        else
        {
            WorkQueue* workQueue = m_vertex[dstVertex].GetWorkQueue();
            if (workQueue == NULL)
            {
                workQueue = sharedWorkQueue;
            }
            edge->MakeFifo(m_internalFifoLength, workQueue);
            m_vertex[dstVertex].SetInputChannel(dstPort, false,
                                                edge->GetReader());
            m_vertex[srcVertex].SetOutputChannel(srcPort, false,
                                                 edge->GetWriter());
        }
    }

    for (i=0; i<m_numberOfVertices; ++i)
    {
        if (!m_vertex[i].Verify())
        {
            return false;
        }
    }

    return true;
}
Пример #6
0
// -------------------------------------------------------------------------
void Pgr_trspHandler::explore(
        int64_t cur_node,
        const EdgeInfo cur_edge,
        bool isStart) {
    double extra_cost = 0.0;
    double totalCost;

    auto vecIndex = cur_edge.get_idx(isStart);

    for (const auto &index : vecIndex) {
        auto edge = m_edges[index];

        extra_cost = getRestrictionCost(
                cur_edge.idx(),
                edge, isStart);

        if ((edge.startNode() == cur_node) && (edge.cost() >= 0.0)) {
            totalCost = get_tot_cost(
                    edge.cost() + extra_cost,
                    cur_edge.idx(),
                    isStart);

            if (totalCost < m_dCost[index].endCost) {
                m_dCost[index].endCost = totalCost;
                m_parent[edge.idx()].v_pos[RC_EDGE] = (isStart? C_EDGE : RC_EDGE);
                m_parent[edge.idx()].e_idx[RC_EDGE] =
                    cur_edge.idx();

                add_to_que(totalCost, edge.idx(), true);
            }
        }

       if ((edge.endNode() == cur_node) && (edge.r_cost() >= 0.0)) {
            totalCost = get_tot_cost(
                    edge.r_cost() + extra_cost,
                    cur_edge.idx(),
                    isStart);

            if (totalCost < m_dCost[index].startCost) {
                m_dCost[index].startCost = totalCost;
                m_parent[edge.idx()].v_pos[C_EDGE] = (isStart? C_EDGE : RC_EDGE);
                m_parent[edge.idx()].e_idx[C_EDGE] = cur_edge.idx();

                add_to_que(totalCost, edge.idx(), false);
            }
        }
    }  // for
}
Пример #7
0
static void BuildJunctionEdgeInfo( const AcDbObjectIdArray& objIds,
                                   const AcGePoint3d& junctionPt,
                                   EdgeInfo& ges )
{
    AcTransaction* pTrans = actrTransactionManager->startTransaction();
    if( pTrans == 0 ) return;

    int n = objIds.length();
    for( int i = 0; i < n; i++ )
    {
        AcDbObjectId objId = objIds.at( i );

        JunctionEdgeInfo info = {objId, true, AcGeVector3d::kIdentity};

        LinkedGE* pEdge = OpenEdge2( pTrans, objId, AcDb::kForRead );
        if( pEdge == 0 ) continue;

        AcGePoint3d startPt, endPt;
        pEdge->getSEPoint( startPt, endPt );
        if( startPt == junctionPt )
        {
            info.startOrEnd = true;
            info.angle = pEdge->getStartPointInExtendAngle();
        }
        else if( endPt == junctionPt )
        {
            info.startOrEnd = false;
            info.angle = pEdge->getEndPointInExtendAngle();
        }

        if( info.angle.isZeroLength() ) continue; // 零向量表示不处理闭合
        //acutPrintf(_T("\nid:%d\tangle:%.3f\tdraw:%s"),
        //			info.objId,
        //			info.angle.angleTo(AcGeVector3d::kXAxis, -AcGeVector3d::kZAxis),
        //			pEdge->getCurrentDraw());

        ges.push_back( info );
    }
    actrTransactionManager->endTransaction();
}
Пример #8
0
static void SortJunctionEdge( EdgeInfo& ges )
{
    // 按照角度大小排序(逆时针)
    std::sort( ges.begin(), ges.end(), SortEdgeByAngle() ); // 不能使用list,只能使用随机容器
}
Пример #9
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();
 }
Пример #10
0
void PasteCommand::prepareEdge(EdgeInfo &edgeData, const QPointF &offset, const QHash<Id, Id> &copiedIds)
{
	edgeData.newId();
	if (!mIsGraphicalCopy) {
		edgeData.newLogicalId();
	}

	edgeData.setSrcId(copiedIds.contains(edgeData.srcId()) ? copiedIds[edgeData.srcId()] : Id::rootId());
	edgeData.setDstId(copiedIds.contains(edgeData.dstId()) ? copiedIds[edgeData.dstId()] : Id::rootId());
	edgeData.setPos(edgeData.position() + offset);
	edgeData.setGraphicalParent(newGraphicalParent(edgeData, copiedIds));
}
Пример #11
0
void DryadSubGraphVertex::ReadEdgeInfo(DryadMetaData* edgeData,
                                       UInt32 edgeIndex)
{
    EdgeInfo* edge = &(m_edge[edgeIndex]);

    LogAssert(NoError());

    UInt32 sourceVertex;
    DrError err = edgeData->LookUpUInt32(Prop_Dryad_SourceVertex,
                                         &sourceVertex);
    if (err != DrError_OK)
    {
        ReportError(DryadError_VertexInitialization, "No SourceVertex Tag");
        return;
    }

    if (sourceVertex >= m_numberOfVertices)
    {
        ReportError(DryadError_VertexInitialization,
                    "Bad Source Vertex Index");
        return;
    }

    UInt32 sourcePort;
    err = edgeData->LookUpUInt32(Prop_Dryad_SourcePort,
                                 &sourcePort);
    if (err != DrError_OK)
    {
        ReportError(DryadError_VertexInitialization, "No SourcePort Tag");
        return;
    }

    if (sourcePort >= m_vertex[sourceVertex].GetOutputPortCount())
    {
        ReportError(DryadError_VertexInitialization, "Bad Source Port Index");
        return;
    }

    if (sourceVertex == m_virtualInput)
    {
        LogAssert(sourcePort < m_numberOfInputEdges);
        if (m_inputEdge[sourcePort] != NULL)
        {
            ReportError(DryadError_VertexInitialization,
                        "Duplicate InputEdge Port");
            return;
        }
        m_inputEdge[sourcePort] = edge;
    }

    UInt32 destinationVertex;
    err = edgeData->LookUpUInt32(Prop_Dryad_DestinationVertex,
                                 &destinationVertex);
    if (err != DrError_OK)
    {
        ReportError(DryadError_VertexInitialization,
                    "No DestinationVertex Tag");
        return;
    }

    if (destinationVertex >= m_numberOfVertices)
    {
        ReportError(DryadError_VertexInitialization,
                    "Bad Destination Vertex Index");
        return;
    }

    UInt32 destinationPort;
    err = edgeData->LookUpUInt32(Prop_Dryad_DestinationPort,
                                 &destinationPort);
    if (err != DrError_OK)
    {
        ReportError(DryadError_VertexInitialization,
                    "No DestinationPort Tag");
        return;
    }

    if (destinationPort >= m_vertex[destinationVertex].GetInputPortCount())
    {
        ReportError(DryadError_VertexInitialization,
                    "Bad Destination Port Index");
        return;
    }

    if (destinationVertex == m_virtualOutput)
    {
        LogAssert(destinationPort < m_numberOfOutputEdges);
        if (m_outputEdge[destinationPort] != NULL)
        {
            ReportError(DryadError_VertexInitialization,
                        "Duplicate OutputEdge Port");
            return;
        }
        m_outputEdge[destinationPort] = edge;
    }

    edge->SetInfo(sourceVertex, sourcePort,
                  destinationVertex, destinationPort);

    LogAssert(NoError());
}