Example #1
0
void getLeaves(t_Node* ptTree, int* anIDs, int *pnLeaves)
{
  if(ptTree->nId != INTERNAL){
    anIDs[*pnLeaves] = ptTree->nId;

    (*pnLeaves)++;
  } 
  else{
    getLeaves(ptTree->ptLeft, anIDs, pnLeaves);

    getLeaves(ptTree->ptRight, anIDs, pnLeaves);
  }
}
void cultureGroupMapper::processVic2CulturesFile(string culturesFile)
{
	auto obj = parser_8859_15::doParseFile(culturesFile);
	if (obj)
	{
		vector<shared_ptr<Object>> groupsObj = obj->getLeaves();
		for (auto groupsItr: groupsObj)
		{
			string group = groupsItr->getKey();

			vector<shared_ptr<Object>> culturesObj = groupsItr->getLeaves();
			for (auto culturesItr: culturesObj)
			{
				string key = culturesItr->getKey();
				if ((key != "union") && (key != "leader") && (key != "unit") && (key != "is_overseas") && (mappings.find(key) == mappings.end()))
				{
					mappings.insert(make_pair(key, group));
				}
			}
		}
	}
	else
	{
		return;
	}
}
Example #3
0
bool ccKdTree::convertCellIndexToRandomColor()
{
	if (!m_associatedGenericCloud || !m_associatedGenericCloud->isA(CC_TYPES::POINT_CLOUD))
		return false;

	//get leaves
	std::vector<Leaf*> leaves;
	if (!getLeaves(leaves) || leaves.empty())
		return false;

	ccPointCloud* pc = static_cast<ccPointCloud*>(m_associatedGenericCloud);
	if (!pc->resizeTheRGBTable())
		return false;

	//for each cell
	for (size_t i=0; i<leaves.size(); ++i)
	{
		colorType col[3];
		ccColor::Generator::Random(col);
		CCLib::ReferenceCloud* subset = leaves[i]->points;
		if (subset)
		{
			for (unsigned j=0; j<subset->size(); ++j)
				pc->setPointColor(subset->getPointGlobalIndex(j),col);
		}
	}

	pc->showColors(true);

	return true;
}
Example #4
0
void
cpu_tsdf::Octree::getLeaves (std::vector<OctreeNode::Ptr> &leaves, float max_size_x, float max_size_y, float max_size_z) const
{
  int desired_res = std::max (size_x_/max_size_x, std::max (size_y_ / max_size_y, size_z_/max_size_z));
  int num_levels = std::ceil (std::log (desired_res) / std::log (2));
  getLeaves (leaves, num_levels);
}
Example #5
0
bool ccKdTree::convertCellIndexToSF()
{
	if (!m_associatedGenericCloud || !m_associatedGenericCloud->isA(CC_TYPES::POINT_CLOUD))
		return false;

	//get leaves
	std::vector<Leaf*> leaves;
	if (!getLeaves(leaves) || leaves.empty())
		return false;

	ccPointCloud* pc = static_cast<ccPointCloud*>(m_associatedGenericCloud);

	const char c_defaultSFName[] = "Kd-tree indexes";
	int sfIdx = pc->getScalarFieldIndexByName(c_defaultSFName);
	if (sfIdx < 0)
		sfIdx = pc->addScalarField(c_defaultSFName);
	if (sfIdx < 0)
	{
		ccLog::Error("Not enough memory!");
		return false;
	}
	pc->setCurrentScalarField(sfIdx);

	//for each cell
	for (size_t i=0; i<leaves.size(); ++i)
	{
		CCLib::ReferenceCloud* subset = leaves[i]->points;
		if (subset)
		{
			for (unsigned j=0; j<subset->size(); ++j)
				subset->setPointScalarValue(j,(ScalarType)i);
		}
	}

	pc->getScalarField(sfIdx)->computeMinAndMax();
	pc->setCurrentDisplayedScalarField(sfIdx);
	pc->showSF(true);

	return true;
}
Example #6
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);
}