Exemplo n.º 1
0
int				btDbvt::countLeaves(const btDbvtNode* node)
{
	if(node->isinternal())
		return(countLeaves(node->childs[0])+countLeaves(node->childs[1]));
	else
		return(1);
}
int BST<T1, T2>::countLeaves(BST<T1, T2> *node)
{
	int leaves = 0;
	
	if (isEmpty())
	{
		cout << "The BST has not yet been initialized with any data." << endl;
	}
	else if (node != NULL)
	{
		leaves += countLeaves(node->mLeft);
		
		//If the left node is null, it was counted as a leaf, so dont call the right on the same node.
		if(node->mLeft != NULL) 
		{
			leaves += countLeaves(node->mRight);
		}
	}
	else if (node == NULL )
	{
		leaves++;
	}

	return leaves;
}
Exemplo n.º 3
0
void countLeaves(t_Node* ptTree, int *pnLeaves)
{
  if(ptTree->nId != INTERNAL){
    (*pnLeaves)++;
  } 
  else{
    countLeaves(ptTree->ptLeft, pnLeaves);

    countLeaves(ptTree->ptRight, pnLeaves);
  }
}
Exemplo n.º 4
0
int DendrogramPanel::countLeaves(int node_idx)
{
    if (node_idx >= 0) {
        return 1;
    }
    if (accessed_node.find(node_idx) != accessed_node.end()) {
        // loop!!!
        return 0;
    }
    accessed_node[node_idx] = 1;
    
    return countLeaves(root[-node_idx-1].left) + countLeaves(root[-node_idx-1].right);
}
Exemplo n.º 5
0
int countLeaves(TreeNode T) {
	int Leaves = 0;

	if (T != NULL) {
		if (T->Left == NULL && T->Right == NULL)
			Leaves++;

		if (T->Left != NULL)
			Leaves += countLeaves(T->Left);
		if (T->Right != NULL)
			Leaves += countLeaves(T->Right);
	}
	return Leaves;
}
void drawTreeFossilFilePst(FILE *fo, TypeTree *tree,  TypeFossilIntFeature *fos) {
    double width, height;
	TypeParamDrawTreePst param;

	param.scale = 100.;
	param.xoffset = OFFSET;
	param.yoffset = 0;
	param.leafSep = OFFSET;
	param.labelSep = 3.;
	param.ycenter = 3.;
	param.ydec = 2.;
	param.radius = 3.;
	param.leafCur = param.leafSep;
    param.tmin = tree->minTime;
    param.tmax = tree->maxTime;
	
	height = param.leafSep*(countLeaves(tree))+3*OFFSET+3*LABEL_SEP+FONT_SIZE;
	width = STANDARD_WIDTH;
	if(param.tmin == param.tmax)
		param.tmax++;
    param.scale = (width-(2*param.xoffset+param.labelSep+getMaxLeafLabelWidth(tree)*CHAR_WIDTH))/((param.tmax-param.tmin));
	fprintf(fo, "\\begin{pspicture}(0,0)(%.2lf, %.2lf)\n", width, height);
    drawTreeFossilPst(fo, tree, fos, &param);
    drawScalePst(fo, param.xoffset, height-(OFFSET+LABEL_SEP+FONT_SIZE), &param);
	fprintf(fo, "\\end{pspicture}\n");
}
int BST<T1, T2>::countLeaves()
{
	if(isEmpty())
		return 0;

	return countLeaves(mRootNode);
}
Exemplo n.º 8
0
void DendrogramPanel::Setup(GdaNode* _root, int _nelements, int _nclusters,
                            std::vector<wxInt64>& _clusters, double _cutoff)
{
    if (root != NULL) {
        delete[] root;
    }
    root = new GdaNode[_nelements];
    for (size_t i=0; i<_nelements; ++i) {
        root[i] = _root[i];
    }
    nelements = _nelements;
    clusters = _clusters;
    nclusters = _nclusters;
    cutoffDistance = _cutoff;
    
    color_vec.clear();
    CatClassification::PickColorSet(color_vec, nclusters);
    
    // top Node will be nelements - 2
    accessed_node.clear();
    leaves = countLeaves(-(nelements-2) - 1);
    level_node.clear();
    levels = countLevels(-(nelements-2) - 1, 0);
    
    maxDistance = root[nelements-2].distance;
    
    init();
}
Exemplo n.º 9
0
int DendrogramPanel::countLeaves(GdaNode* node)
{
    if (node->left >= 0 && node->right >= 0) {
        return 2;
    }
    
    if (node->left >= 0 && node->right < 0) {
        return 1 + countLeaves(&root[-node->right-1]);
    }
    
    if (node->left < 0 && node->right >= 0) {
        return 1 + countLeaves(&root[-node->left-1]);
    }
    
    return countLeaves(&root[-node->left-1]) + countLeaves(&root[-node->right-1]);
}
Exemplo n.º 10
0
void countLeaves(struct node *cnode)
{
	if(cnode!=NULL) // to check the case if there is no node in the tree ..
	{
	if(cnode->leftpointer==NULL&&cnode->rightpointer==NULL) //reached the leaf node ..
	{
		count++ ;
		//uncomment to print the leaf nodes ..
	//	printf("%d",cnode->data); 
	}
	else
	{
		if(cnode->leftpointer!=NULL)
		countLeaves(cnode->leftpointer);
		if(cnode->rightpointer!=NULL)
		countLeaves(cnode->rightpointer);
		
	}
	}
}
Exemplo n.º 11
0
main()
{
	printf("SIZE : ");
	int n ;//size of binary tree ..
	scanf("%d",&n) ;
	
	insert(n);	
	countLeaves(root);
	
	//printing total number of leaf nodes ..
	
	printf("\n\nNumber of leave Nodes are : \n\n");
	printf("\n%d\n\n",count);
}
Exemplo n.º 12
0
void writeList(FILE* ofp, t_Node *ptTree, double dMaxSplit)
{
  double dSplitDepth = 0.0, dSplit = 0.0, dDepth = 0.0, dMaxDepth = 0.0;
  t_Node* aptSplit[ptTree->nN];
  int    i = 0, j = 0, nCount = 0, nSplit = 0, nLeaves = 0; 
  int *anLeaves = NULL;

  maxDepth(ptTree, &dMaxDepth);

  while(dSplit < dMaxSplit){
 
    dSplitDepth = dMaxDepth - dSplit;

    nSplit = 0;
    dDepth = 0.0;

    treeSplit(ptTree, &dDepth, dSplitDepth, aptSplit, &nSplit);

    fprintf(ofp,"%f %d ",dSplit, nSplit);

    for(i = 0; i < nSplit; i++){
   
      nLeaves = 0;

      countLeaves(aptSplit[i],&nLeaves);
      
      if(anLeaves != NULL){
	free(anLeaves);
	anLeaves = NULL;
      }

      anLeaves = (int *) malloc(sizeof(int)*nLeaves);
    
      nCount = 0;
    
      getLeavesR(aptSplit[i], anLeaves, &nCount);
      
      for(j = 0; j < nLeaves - 1; j++){
	fprintf(ofp, "%d,",anLeaves[j]);
      }
      
      fprintf(ofp,"%d",anLeaves[nLeaves - 1]);
      if(i < nSplit - 1){
	fprintf(ofp, " ");
      }
    }
    fprintf(ofp, "\n");
    dSplit += 0.01;
  }
}
vector<OctreeSDF::Cube> OctreeSDF::getCubesToMarch()
{
	int numLeaves = countLeaves();
	/*std::cout << "Reserving " << numLeaves * LEAF_SIZE_2D_INNER << std::endl;
	std::vector<Vertex> sharedVertices;
	sharedVertices.reserve(numLeaves * LEAF_SIZE_2D_INNER);
	Vector3iHashGrid<unsigned int> indexMap;
	indexMap.rehash(numLeaves * LEAF_SIZE_2D_INNER);
	auto ts = Profiler::timestamp();
	m_RootNode->getSharedVertices(m_RootArea, sharedVertices, indexMap);
	Profiler::printJobDuration("getSharedVertices", ts);
	std::cout << "Shared vertices: " << sharedVertices.size() << std::endl;*/

	auto ts = Profiler::timestamp();
	vector<Cube> cubes;
	cubes.reserve(numLeaves * LEAF_SIZE_2D_INNER * 2);		// reasonable upper bound
	std::stack<Node*> nodes;
	m_RootNode->getCubesToMarch(m_RootArea, cubes);
	Profiler::printJobDuration("getCubesToMarch", ts);
	return cubes;
}
Exemplo n.º 14
0
int main() {
	TreeNode T = NULL;
	int i, inData;

	printf_s("Elements:\n");
	for (i = 0; i < 7; i++) {
		printf_s("#%d: ", i + 1);
		scanf_s("%d", &inData);
		T = insert(inData, T);
		//T = insert(i + 1, T);
	}

	printf_s("\nTree:\n");
	display(T);
	printf_s("\nNodes: %d", countNodes(T));
	printf_s("\nLeaves: %d", countLeaves(T));
	printf_s("\nFullNodes: %d\n", countFullNodes(T));

	makeEmpty(T);
	return 0;
}
Exemplo n.º 15
0
static size_t countLeaves(const Node *root)
{
    if(!root->getLabel().empty())
        return 1;
    return countLeaves(root->getLeft())+countLeaves(root->getRight());
}
Exemplo n.º 16
0
int main(int argc, char* argv[])
{
  t_Node    *ptTree = NULL;
  FILE      *ifp    = NULL;
  t_Params  tParams;
  t_Data    tData;
  t_Map     tMap;
  t_Node     **aptSplit = (t_Node **) malloc(MAX_SPLIT*sizeof(t_Node *));
  int        nSplit = 0;
  double     dMaxDepth = 0.0, dSplitDepth = 0.0, dDepth = 0.0;
  int        iL = 0, nLast = 0, nCount = 0, i = 0, j = 0;
  int*       anLast = NULL;
  char szDir[MAX_WORD_LENGTH];
  char szTreeFile[MAX_WORD_LENGTH];
  char szDatFile[MAX_WORD_LENGTH];
  char szListFile[MAX_WORD_LENGTH];
  FILE* tfp = NULL, *dfp = NULL, *lfp = NULL;

  getCommandLineParams(&tParams, argc, argv);

  readData(&tData, tParams.szDatFile);

  readMapFile(&tMap, tParams.szMapFile);

  ifp = fopen(tParams.szTreeFile, "r");

  if(ifp){
    addElement(&ptTree, ifp);

    fclose(ifp);
  }
  else{
    printf("Failed to open tree file\n");
  }
  
  setLeaves(ptTree);

  treeSplitEven(ptTree, tParams.nSplit, aptSplit, &nSplit);

  for(i = 0; i < nSplit; i++){

    countLeaves(aptSplit[i],&(aptSplit[i]->nN));

    if(aptSplit[i]->nN < tParams.nMinSize){
      nLast += aptSplit[i]->nN;
    }

    aptSplit[i]->anLeaves = (int *) malloc(sizeof(int)*aptSplit[i]->nN);
    
    nCount = 0;
    
    getLeaves(aptSplit[i],aptSplit[i]->anLeaves, &nCount);
  }

  maxDepth(ptTree, &dMaxDepth);

  setDepth(ptTree, 0.0);

  /*sort on number of leaves*/
  //void qsort(void* field, size_t nElements, size_t sizeOfAnElement,
  //                 int(_USERENTRY *cmpFunc)(const void*, const void*));


  qsort(aptSplit,nSplit,sizeof(t_Node*),compNode);

  i = 0;
  while(i < nSplit && aptSplit[i]->nN >= tParams.nMinSize){

    sprintf(szDir, "C%03d",i);
    
    mkdir(szDir, S_IRWXU);

    sprintf(szTreeFile,"%s/%s%s",szDir,szDir,TREE_SUFFIX);
    sprintf(szDatFile,"%s/%s%s",szDir,szDir,DAT_SUFFIX);
    sprintf(szListFile,"%s/%s%s",szDir,szDir,LIST_SUFFIX);

    printf("%d %d %f\n",i,aptSplit[i]->nN,dMaxDepth - aptSplit[i]->dDepth);


    tfp = fopen(szTreeFile, "w");

    if(tfp){
      writeTree(aptSplit[i], tfp);
      fprintf(tfp, ";\n");
      fclose(tfp);
    }

    dfp = fopen(szDatFile, "w");

    if(dfp){
      writeData(dfp, &tData, aptSplit[i]->nN, aptSplit[i]->anLeaves, &tMap);
    
      fclose(dfp);
    }

    nCount=0;
    renumberLeaves(aptSplit[i], &nCount);

    lfp = fopen(szListFile, "w");

    if(lfp){
      writeList(lfp, aptSplit[i], dMaxDepth - aptSplit[i]->dDepth);
    
      fclose(lfp);
    }
    i++;
  }
  
  if(nLast > 0){
    anLast = (int *) malloc(sizeof(int)*nLast);
    nCount = 0;
    printf("%d %d\n",i,nLast);
    iL = i;
    for(; i < nSplit; i++){
      for(j = 0; j < aptSplit[i]->nN; j++){
	anLast[nCount + j] = aptSplit[i]->anLeaves[j];
      }
      nCount += aptSplit[i]->nN;
    }

    if(nCount > 0){
      sprintf(szDir, "C%03d+",iL);
  
      mkdir(szDir, S_IRWXU);

      sprintf(szTreeFile,"%s/%s%s",szDir,szDir,TREE_SUFFIX);
      sprintf(szDatFile,"%s/%s%s",szDir,szDir,DAT_SUFFIX);
      sprintf(szListFile,"%s/%s%s",szDir,szDir,LIST_SUFFIX);

      dfp = fopen(szDatFile, "w");

      if(dfp){
	writeData(dfp, &tData, nLast, anLast, &tMap);
    
	fclose(dfp);
      }
    }

    free(anLast);
  }
  exit(EXIT_SUCCESS);
}