Esempio n. 1
0
void poseGroupCutManager::getBoneNeighbor(std::vector<arrayInt> &boneAroundB, std::vector<bone*> * boneList)
{
	for (int i = 0; i < boneList->size(); i++)
	{
		auto b = boneList->at(i);
		// Find neighbor of b
		arrayInt nb;
		int idx = findIdx(boneList, b->parent);
		if (idx != -1)
		{
			nb.push_back(idx);
		}

		for (auto c : b->child)
		{
			int cIdx = findIdx(boneList, c);
			if (cIdx != -1)
			{
				nb.push_back(cIdx);
			}
		}

		boneAroundB.push_back(nb);
	}
}
Esempio n. 2
0
void poseManager::constructMapTree()
{
	s_skeleton->getSortedGroupBoneArray(sortedBone);

	// now sort the bone by order of number of neighbor
	std::sort(sortedBone.begin(), sortedBone.end(), compareBoneNeighbor_descen);
	std::vector<bone*> center;
	std::vector<bone*> side;
	for (int i = 0; i < sortedBone.size(); i++)
	{
		if (sortedBone[i]->m_type == CENTER_BONE)
			center.push_back(sortedBone[i]);
		else
			side.push_back(sortedBone[i]);
	}
	sortedBone.clear();
	sortedBone.insert(sortedBone.end(), center.begin(), center.end());
	sortedBone.insert(sortedBone.end(), side.begin(), side.end());

	// Compute volume ratio
	computeVolumeRatioOfBone();


	// Neighbor info
	for (int i = 0; i < sortedBone.size(); i++)
	{
		arrayInt neighborIdx;
		std::vector<bone*> *child = &sortedBone[i]->child;
		if (!sortedBone[i]->bIsGroup)
		{
			for (int j = 0; j < child->size(); j++)
			{
				int idx = findIdx(&sortedBone, child->at(j));

				neighborPair.push_back(Vec2i(i, idx));
				neighborIdx.push_back(idx);
			}			
		}

		if (sortedBone[i]->parent)
		{
			int idx = findIdx(&sortedBone, sortedBone[i]->parent);

			neighborIdx.push_back(idx);
		}

		boneAroundBone.push_back(neighborIdx);
	}

	// The tree contains all available mapping
	m_boneMapTree.sortedBone = &sortedBone;
	m_boneMapTree.boneAroundBone = &boneAroundBone;
	m_boneMapTree.neighborPair = &neighborPair;
	m_boneMapTree.nbCenterBone = center.size();

	m_boneMapTree.constructTree();
}
 vector<int> countSmaller(vector<int>& nums) {
     vector<int> sorted; // maintain an sorted array of numbers have been visited
     vector<int> res(nums.size(), 0); // the results
     
     for(int i = nums.size()-1; i >= 0; i--){
         int idx = findIdx(sorted, nums[i]);
         res[i] = idx;
         sorted.insert(sorted.begin()+idx, nums[i]);
     }
     
     return res;
 }
struct node *buildTree(struct node *inOrder[], struct node *preOrder[], int f, int l) {
  if (f < 0 || l >= 10 || f > l) {
    return NULL;
  }
  /* printf("[%d, %d] - %d\n", f, l, preOrder[f]->data); */
  if (f == l) {
    return preOrder[f];
  }
  struct node *r = preOrder[f];
  int inOrderIdx = findIdx(inOrder, r);
  int i;
  for (i = f + 1; i < l; i++) {
    if (!isPresent(inOrder, preOrder[i], 0, inOrderIdx - 1))
      break;
  }
  /* printf("i: %d\n", i); */
  r->left = buildTree(inOrder, preOrder, f + 1, i - 1);
  r->right = buildTree(inOrder, preOrder, i, l);
  return r;
}
Esempio n. 5
0
	std::string simulate(std::string s)
	{
		if (s.size() <= 1)
			return s;
		bool norepeat = false;
		while (!norepeat)
		{
			//find idx where repeats
			int idx = findIdx(s);
			if (idx >= s.size())
				return s;
			std::cout << "Idx to replace " << idx << "\n";
			std::string curr = remove(s, idx);
			std::cout << "New string " << curr << "\n";
			if (curr.size() < s.size())
			{
				s = curr;
			}
			else
				norepeat = true;
		}
		return s;
	}
Esempio n. 6
0
static int compareLUTs(unsigned int *lut1, int numLut1, int transIdx,
                       unsigned int *lut2, int numLut2, unsigned char *cvtLut,
                       int *retNumLut1, int *retTransIdx, int *jniFlagP)
{
    int i;
    int idx;
    int newTransIdx = -1;
    unsigned int rgb;
    int changed = FALSE;
    int maxSize = (numLut1 > numLut2 ? numLut1 : numLut2);

    *jniFlagP = JNI_ABORT;

    for (i=0; i < maxSize; i++) {
        cvtLut[i] = i;
    }

    for (i=0; i < numLut2; i++) {
        /* If this slot in new palette is different from the
         * same slot in current palette, then we try to find
         * this color in other slots. On failure, add this color
         * to current palette.
         */
        if ((i >= numLut1) ||
            (lut1[i] != lut2[i]))
        {
            rgb = lut2[i];
            /* Transparent */
            if ((rgb & ALPHA_MASK) == 0) {
                if (transIdx == -1) {
                    if (numLut1 < 256) {
                        cvtLut[i] = numLut1;
                        newTransIdx = i;
                        transIdx = i;
                        numLut1++;
                        changed = TRUE;
                    }
                    else {
                        return FALSE;
                    }
                }
                cvtLut[i] = transIdx;
            }
            else {
                if ((idx = findIdx(rgb, lut1, numLut1)) == -1) {
                    if (numLut1 < 256) {
                        lut1[numLut1] = rgb;
                        cvtLut[i] = numLut1;
                        numLut1++;
                        changed = TRUE;
                    }
                    else {
                        /* Bad news...  need to convert image */
                        return FALSE;
                    }
                } else {
                    cvtLut[i] = idx;
                }
            }
        }
    }

    if (changed) {
        *jniFlagP = 0;
        *retNumLut1 = numLut1;
        if (newTransIdx != -1) {
            *retTransIdx = newTransIdx;
        }
    }
    return TRUE;
}
Esempio n. 7
0
/**
 * Find the shortest path between two nodes
 * using a simple implementation of dijkstra's algorithm:
 * http://en.wikipedia.org/wiki/Dijkstra's_algorithm
 *
 * @param graph   Graph to traverse
 * @param node1   Starting node
 * @param node2   Destination node
 * @return  The id which is the nexthop otherwise NULL if no path exists
 */
int shortest_path(graph_t* graph, int node1, int node2)
{
  node_t* u = NULL;
  node_t* v = NULL;
  node_t* target = NULL;
  edge_t* e = NULL;
  int* lut = NULL;
  int* d = NULL;
  int numnodes = 0;
  int i = 0;
  int j = 0;
  int idx = 0;
  int mindist = INFINITY;
  int minidx = -1;
  int ret = 0;

  if(graph == NULL)
    return -1;

  u = findNode(graph, node1);
  v = target = findNode(graph, node2);

  if(u == NULL || v == NULL)
    return -1;


  numnodes = u->edgecount;

  lut = malloc(numnodes * sizeof(int));
  d = malloc(numnodes * sizeof(int));
  memset(d, INFINITY, numnodes * sizeof(int));

  // lut simply maps our node id's into a range from [0, nodecount)
  for(i = 0 ; i < numnodes ; ++i) {
    e = u->edges[i];
    lut[i] = (e->p1 == u) ? ((node_t*)e->p2)->id : ((node_t*)e->p1)->id;
    d[i] = INFINITY;
  }

  u->marked = 1;

  // Now, for each neighbor, find the distance to
  // the target node
  for(i = 0 ; i < numnodes ; ++i) {
    // Unmark all nodes
    for(j = 0 ; j < graph->nodecount ; ++j) {
      if(graph->nodes[j] != u)
        graph->nodes[j]->marked = 0;
    }
    e = u->edges[i];
    if(e->weight == INFINITY) // No longer exists
      continue;
    v = (node_t*)((e->p1 == u) ? e->p2 : e->p1);
    idx = findIdx(lut, v->id, numnodes);
    d[idx] = shortest_path_helper(graph, v, target);
    d[idx] += (d[idx] != INFINITY) ? e->weight : 0;
    if((d[idx] < mindist || mindist == INFINITY) && d[idx] != INFINITY) {
      mindist = d[idx];
      minidx  = idx;
    }
  }

  ret = (minidx >= 0 && minidx < numnodes) ? lut[minidx] : -1;

  free(d);
  free(lut);

  return ret;
}
ossimRefPtr<ossimImageData> ossimClosestToCenterCombiner::getTile(const ossimIrect& rect,
                                                                  ossim_uint32 resLevel)
{
   ossim_uint32 layerIdx = 0;
   if(!isSourceEnabled())
   {
      return ossimImageMosaic::getTile(rect, resLevel);
   }
   if(!theTile.valid())
   {
      allocate();
      if(!theTile.valid())
      {
         return 0;
      }
   }
   theTile->setImageRectangle(rect);
   theTile->makeBlank();
   std::vector<ossimClosestToCenterCombinerInfo > normTileList;
   ossimRefPtr<ossimImageData> currentTile = getNextNormTile(layerIdx, 0, rect);
   while(currentTile.valid())
   {
      normTileList.push_back(ossimClosestToCenterCombinerInfo((ossimImageData*)currentTile->dup(),
                                                              layerIdx));
      currentTile = getNextNormTile(layerIdx, rect, resLevel);
   }

   
   if(normTileList.size() == 1)
   {
      theTile->copyNormalizedBufferToTile((ossim_float32*)normTileList[0].theTile->getBuf());
   }
   else if(normTileList.size() > 1)
   {
      ossimRefPtr<ossimImageData> copyTile    = ossimImageDataFactory::instance()->create(0,
                                                                                          OSSIM_NORMALIZED_FLOAT);
      copyTile->setImageRectangleAndBands(rect,
                                          getNumberOfOutputBands());
      copyTile->initialize();
                                                                                          
      ossim_int32 idx   = 0;
      ossim_uint32 w     = rect.width();
      ossim_uint32 h     = rect.height();
      ossim_uint32 idxW  = 0;
      ossim_uint32 idxH  = 0;
      ossimIpt origin    = rect.ul();
      ossimIpt ulPt      = rect.ul();
      ossim_uint32 band  = 0;
      ossim_uint32 bands = copyTile->getNumberOfBands();
      ossim_uint32 srcBandIdx = 0;
      std::vector<ossim_float32*> bandList(bands);

      for(band = 0; band < bands; ++band)
      {
         bandList[band] = (ossim_float32*)copyTile->getBuf(band);
      }
      ossim_uint32 offset   = 0;
      origin.y = ulPt.y;
      for(idxH = 0; idxH < h; ++idxH)
      {
         origin.x = ulPt.x;
         for(idxW = 0; idxW < w;++idxW)
         {
            idx = findIdx(normTileList, origin, offset);

            if(idx >=0)
            {
               ossim_uint32 tileBands = normTileList[idx].theTile->getNumberOfBands();
               if (tileBands > 0)
               {
                  tileBands -= 1;
                  for(band = 0; band < bands; ++band)
                  {
                     srcBandIdx = ossim::min( tileBands, band );
                     bandList[band][offset] = *(((ossim_float32*)normTileList[idx].theTile->getBuf(srcBandIdx))+offset);
                  }
               }
            }
            ++offset;
            ++origin.x;
         }
         ++origin.y;
      }
      theTile->copyNormalizedBufferToTile((ossim_float32*)copyTile->getBuf());
   }

   theTile->validate();
   
   return theTile;

}