void QuadTreeManager::ActivateChildren(QuadTreeNode* parent)
{
	parent->hasChildren = true;
	ActivateNode(_quadTree[parent->children[0]]);
	ActivateNode(_quadTree[parent->children[1]]);
	ActivateNode(_quadTree[parent->children[2]]);
	ActivateNode(_quadTree[parent->children[3]]);
}
QuadTreeNode* QuadTreeManager::InitNode(int depth, int parentIndex, int childNum, float left, float right, float top, float bottom)
{
	QuadTreeNode* node = new QuadTreeNode();
	node->active = false;
	node->hasChildren = false;
	node->depth = depth;
	node->left = left;
	node->right = right;
	node->top = top;
	node->bottom = bottom;

	RenderShape* outline = new RenderShape(_outlineTemplate.vao(), _outlineTemplate.count(), _outlineTemplate.mode(), _outlineTemplate.shader(), _outlineTemplate.color());
	RenderManager::AddShape(outline);
	node->outline = outline;

	int base = GetDepthIndex(depth) + childNum * 4;
	node->children[0] = base;
	node->children[1] = base + 1;
	node->children[2] = base + 2;
	node->children[3] = base + 3;
	node->parent = parentIndex;

	ActivateNode(node);

	return node;
}
// When updateing the tree, the manager goes through and deactivates every node in the tree and then reactivates the root.
// It then goes through the entire array of interactive shapes and adds them back into the tree. 
void QuadTreeManager::UpdateQuadtree()
{
	unsigned int treeSize = _quadTree.size();
	for (unsigned int i = 0; i < treeSize; ++i)
	{
		DeactivateNode(_quadTree[i]);
	}
	ActivateNode(_quadTree[0]);
	unsigned int shapesSize = _shapes.size();
	for (unsigned int i = 0; i < shapesSize; ++i)
	{
		AddShape(_shapes[i], 0);
	}
}
Esempio n. 4
0
void wxTreeLayout::DoLayout(wxDC& dc, long topId)
{
    if (topId != wxID_ANY)
        SetTopNode(topId);

    long actualTopId = GetTopNode();
    long id = actualTopId;
    while (id != wxID_ANY)
    {
        SetNodeX(id, 0);
        SetNodeY(id, 0);
        ActivateNode(id, false);
        id = GetNextNode(id);
    }
    m_lastY = m_topMargin;
    m_lastX = m_leftMargin;
    CalcLayout(actualTopId, 0, dc);
}
Esempio n. 5
0
/* PropIntoNode
     Propagate tokenset into entry state of LexNode, activating as necessary
*/
void Decoder::PropIntoNode (TokenSet *ts, LexNode *ln, bool updateLMLA) {

   if (!ln->inst)                /* activate if necessary */
      ActivateNode (ln);

   LexNodeInst *inst = ln->inst;
         
   /* propagate tokens from ln's exit into follLN's entry state */
   MergeTokSet (ts, &inst->ts[0], 0.0, TRUE);
   
   /* only update inst->best if no LMLA update necessary or already done! */
   if (ln->type == LN_WORDEND || ln->lmlaIdx == 0){
      inst->best = std::max(inst->ts[0].score, inst->best);
      return;
   }

   if (updateLMLA) {
      UpdateLMlookahead (ln);
      inst->best = std::max(inst->ts[0].score, inst->best);
   }
}
Esempio n. 6
0
void wxTreeLayout::CalcLayout(long nodeId, int level, wxDC& dc)
{
    wxList children;
    GetChildren(nodeId, children);
    int n = children.GetCount();

    if (m_orientation == false)
    {
        // Left to right
        // X Calculations
        if (level == 0)
            SetNodeX(nodeId, m_leftMargin);
        else
        {
            long x = 0;
            long y = 0;
            long parentId = GetNodeParent(nodeId);
            if (parentId != wxID_ANY)
                GetNodeSize(parentId, &x, &y, dc);
            SetNodeX(nodeId, (long)(GetNodeX(parentId) + m_xSpacing + x));
        }

        wxList::compatibility_iterator node = children.GetFirst();
        while (node)
        {
            CalcLayout((long)node->GetData(), level+1, dc);
            node = node->GetNext();
        }

        // Y Calculations
        long averageY;
        ActivateNode(nodeId, true);

        if (n > 0)
        {
            averageY = 0;
            node = children.GetFirst();
            while (node)
            {
                averageY += GetNodeY((long)node->GetData());
                node = node->GetNext();
            }
            averageY = averageY / n;
            SetNodeY(nodeId, averageY);
        }
        else
        {
            SetNodeY(nodeId, m_lastY);
            long x, y;
            GetNodeSize(nodeId, &x, &y, dc);

            m_lastY = m_lastY + y + m_ySpacing;
        }
    }
    else
    {
        // Top to bottom

        // Y Calculations
        if (level == 0)
            SetNodeY(nodeId, m_topMargin);
        else
        {
            long x = 0;
            long y = 0;
            long parentId = GetNodeParent(nodeId);
            if (parentId != wxID_ANY)
                GetNodeSize(parentId, &x, &y, dc);
            SetNodeY(nodeId, (long)(GetNodeY(parentId) + m_ySpacing + y));
        }

        wxList::compatibility_iterator node = children.GetFirst();
        while (node)
        {
            CalcLayout((long)node->GetData(), level+1, dc);
            node = node->GetNext();
        }

        // X Calculations
        long averageX;
        ActivateNode(nodeId, true);

        if (n > 0)
        {
            averageX = 0;
            node = children.GetFirst();
            while (node)
            {
                averageX += GetNodeX((long)node->GetData());
                node = node->GetNext();
            }
            averageX = averageX / n;
            SetNodeX(nodeId, averageX);
        }
        else
        {
            SetNodeX(nodeId, m_lastX);
            long x, y;
            GetNodeSize(nodeId, &x, &y, dc);

            m_lastX = m_lastX + x + m_xSpacing;
        }
    }
}
Esempio n. 7
0
File: HLVRec.c Progetto: didw/HTS
/* InitDecoderInst

     Initialise previously created decoder instance. This needs to be
     called before each utterance.
*/
void InitDecoderInst (DecoderInst *dec, LexNet *net, HTime sampRate, LogFloat beamWidth, 
                      LogFloat relBeamWidth, LogFloat weBeamWidth, LogFloat zsBeamWidth,
                      int maxModel, 
                      LogFloat insPen, float acScale, float pronScale, float lmScale,
                      LogFloat fastlmlaBeam)
{       
   int i;

   dec->net = net;

   if (dec->nLayers) {
      Dispose (&dec->heap,dec->instsLayer);
   }

   /* alloc InstsLayer start pointers */
   dec->nLayers = net->nLayers;
   dec->instsLayer = (LexNodeInst **) New (&dec->heap, net->nLayers * sizeof (LexNodeInst *));

   /* reset inst (i.e. reset pruning, etc.)
      purge all heaps
   */

   ResetHeap (&dec->nodeInstanceHeap);
   ResetHeap (&dec->weHypHeap);
   if (dec->latgen)
      ResetHeap (&dec->altweHypHeap);
#ifdef MODALIGN
   if (dec->modAlign)
      ResetHeap (&dec->modendHypHeap);
#endif
   ResetHeap (&dec->nodeInstanceHeap);
   for (i = 0; i < dec->maxNStates; ++i) 
      ResetHeap (&dec->tokSetHeap[i]);
   ResetHeap (&dec->relTokHeap);

   if (trace & T_MEM) {
      printf ("memory stats at start of recognition\n");
      PrintAllHeapStats ();
   }

   dec->frame = 0;
   dec->frameDur = sampRate / 1.0e7;
   dec->maxModel = maxModel;
   dec->beamWidth = beamWidth;
   dec->weBeamWidth = weBeamWidth;
   dec->zsBeamWidth = zsBeamWidth;
   dec->curBeamWidth = dec->beamWidth;
   dec->relBeamWidth = - relBeamWidth;
   dec->beamLimit = LZERO;

   if (fastlmlaBeam < -LSMALL) {
      dec->fastlmla = TRUE;
      dec->fastlmlaBeam = - fastlmlaBeam;
   }
   else {
      dec->fastlmla = FALSE;
      dec->fastlmlaBeam = LZERO;
   }

   dec->tokSetIdCount = 0;

   dec->insPen = insPen;
   dec->acScale = acScale;
   dec->pronScale = pronScale;
   dec->lmScale = lmScale;

   dec->maxLMLA = dec->lmScale * maxLMLA;

   /*      HRec computes interval of possible predecessor states j for each 
      destination state i in each transition matrix (seIndexes).
   */
   

   /* alloc temp tokenset arrays for use in PropagateInternal */
   for (i=1; i <= dec->maxNStates; ++i) 
      dec->tempTS[i] = NewTokSetArray (dec, i);

   /* alloc winTok array for MergeTokSet */
   dec->winTok = (RelToken *) New (&dec->heap, 2 * dec->nTok * sizeof (RelToken));


   /* init lists of active LexNode Instances  */
   for (i = 0; i < dec->nLayers; ++i)
      dec->instsLayer[i] = NULL;

   /* deactivate all nodes */
   for (i = 0; i < dec->net->nNodes; ++i) {
      dec->net->node[i].inst = NULL;
#ifdef COLLECT_STATS_ACTIVATION
      dec->net->node[i].eventT = -1;
#endif
   }

   ActivateNode (dec, dec->net->start);
   dec->net->start->inst->ts[0].n = 1;
   dec->net->start->inst->ts[0].score = 0.0;
   dec->net->start->inst->ts[0].relTok[0] = startTok;
   dec->net->start->inst->ts[0].relTok[0].lmState = LMInitial (dec->lm);

#ifdef COLLECT_STATS
   dec->stats.nTokSet = 0;
   dec->stats.sumTokPerTS = 0;
   dec->stats.nActive = 0;
   dec->stats.nActivate = 0;
   dec->stats.nDeActivate = 0;
   dec->stats.nFrames = 0;
   dec->stats.nLMlaCacheHit = 0;
   dec->stats.nLMlaCacheMiss = 0;
#ifdef COLLECT_STATS_ACTIVATION

   dec->stats.lnINF = 0;
   {
      int i;
      for (i = 0; i <= STATS_MAXT; ++i)
         dec->stats.lnDeadT[i] = dec->stats.lnLiveT[i] = 0;
   }
#endif
#endif

   /* LM lookahead cache */
   dec->lmCache = CreateLMCache (dec, &dec->heap);

   /* invalidate OutP cache */
   ResetOutPCache (dec->outPCache);
}