Esempio n. 1
0
/*!
* Считать данные из XML-файла и построить деревья
* \param[in] filename - имя входного файла
* \param[out] root1 - указатель на корень первого дерева
* \param[out] root2 - указатель на корень второго дерева
*/
void readXML(QString filename, node*& root1, node*& root2){
	QFile input(filename);
	
	// 1. Открыть XML файл с именем filename с режимом чтения. Если файл не может открыт, то выбросить исключение (ошибка COULD_NOT_OPEN_FILE) 
	if (!input.open(QFile::ReadOnly | QFile::Text))
		throw error(COULD_NOT_OPEN_FILE, 0, filename);

	QXmlStreamAttributes attr;

	// создать XML поток
	QXmlStreamReader xmlStream;
	xmlStream.setDevice(&input);
	xmlStream.readNext();
	xmlStream.readNext();
	xmlStream.readNext();
	
	// 2. Считать данные из XML-файла средствами библиотеки Qt методом потокового чтения с использованиемм класса QXmlStreamReader и при помощи функции readTree.
	try{
		readTree(xmlStream, root1, 1);
		readTree(xmlStream, root2, 2);
	} catch(const error& e){
		// 3. Если возникла ошибка, выбросить эту ошибку
		throw;
	}
}
Esempio n. 2
0
   //@recursively inserts items from a file into binary search tree
   //@pre: treeptr and data are assigned
   //@post: gets items from a file, and inserts into binary search tree
   //@      using treeptr's root.
   //@usage: readTree(mroot, itemCount);
void cbstree::readTree(Cnode*& treeptr, ifstream& infile, int data) 
{
   if (data > 0)
   {
      Citem item;
      treeptr = new Cnode(item, NULL, NULL);
      readTree(treeptr -> mleftptr, infile, (data / 2));
      infile >> item;
      treeptr -> mitem = item;
      readTree(treeptr -> mrightptr, infile, (data - 1)/2);
   }   
void mode1 (FILE *in, FILE *out) {
	//line number and point number
	int ln = 0, pn = 0;
	
	//get lines 
	TLine *lines = getLines(in, &ln);
	
	//get points
	TPoint *points = getPoints(in, &pn);
	
	//read tree from file
	Tree T = readTree(in, lines);
	
	//need lines no longer
	free(lines);
	lines = NULL;
	
	//label regions using points
	labelRegions(T, points, pn);
	
	//need points no longer
	free(points);
	points = NULL;
	
	//print tree
	printTree(out, T);
	fprintf(out, "\n");
	
	//solve all points 
	localizePoints(in, out, T);
	
	destroyTree(&T);
}
Esempio n. 4
0
int main(){
  Node *node;
  FILE *fp=fopen("tree.txt","r");
  printf("start\n");
  printf("file opened %p\n", fp);
  readTree(fp, &node);
  printf("Reading done\n");
  print(node);
}
Esempio n. 5
0
void readTree(FILE *fp, Node **root) {

  char command[5];
  int v;

  fscanf(fp,"%s\b",command);
  printf("command = %s\n", command);

  if(!strcmp(command, "end")){
    return;
  }

  sscanf(command,"%d\n",&v);
  *root=newNode(v);

  readTree(fp, &((*root)->left));
  readTree(fp, &((*root)->right));

}
Esempio n. 6
0
void morf_node::readTree(morf_node* tree, const char* fileName ) 
{
  FILE * fd;

  if( fileName == NULL )
    fd = fopen("underEvolution.evo", "r");
  else
    fd = fopen(fileName, "r");

  readTree(tree, fd);

  fclose(fd);
}
Esempio n. 7
0
void morf_node::readTree(morf_node* tree, FILE* fd) 
{
  int i, size;

  if (tree==NULL) return;

  readNode( tree, fd );

  fread( &size, sizeof(int), 1, fd);

  for (i=0;i<size;i++){
    tree->subnodes.push_back( new morf_node() );

    readTree(tree->subnodes[i], fd);
  }
}
Esempio n. 8
0
EasyXml::EasyXml(QString path)
{

    outputTreeWidget = new QTreeWidget;

    QDomDocument doc("mydocument");
    QFile file( path );
    if (!file.open(QIODevice::ReadOnly))
            return;
    if (!doc.setContent(&file)) {
            file.close();
            return;
    }
    file.close();

    QDomElement docElem = doc.documentElement();
    readTree(docElem.firstChild());

}
Esempio n. 9
0
void EasyXml::readTree(QDomNode n, QTreeWidgetItem *item)
{

    while(!n.isNull()) {
        QDomElement e = n.toElement(); // try to convert the node to an element.
        if(!e.isNull()) {
            QTreeWidgetItem *item2;
            if (item)
                item2 = new QTreeWidgetItem(item);
            else
                item2 = new QTreeWidgetItem(outputTreeWidget);
            item2->setText( 0, e.tagName() );
            item2->setText( 1, e.text() );
            item2->setSelected(true);

            readTree(n.firstChild(), item2);

         }
         n = n.nextSibling();
    }
}
Esempio n. 10
0
void readForest(forest_t* f, const char* fname){
    int i;
    FILE* fp = fopen(fname,"r");
    if(fp == NULL){
        fprintf(stderr,"could not read input file: %s\n",fname);
        exit(1);
    }
    fscanf(fp, "%*s%d%*s",&f->committee);
    fscanf(fp, "%*s%d", &f->ngrown);
    fscanf(fp, "%*s%d", &f->nfeat);
    fscanf(fp, "%*s%d", &f->maxdepth);
    if(fscanf(fp, "%*s%g", &f->factor)==EOF) {
        fprintf(stderr,"corrupt input file: %s\n",fname);
        exit(1);
    }
    f->tree = (node_t**)malloc(sizeof(node_t*)*f->ngrown);
    for(i=0; i<f->ngrown; i++){
        readTree(fp,&(f->tree[i]));
    }
    if(fscanf(fp, "%*s")!=EOF){
        fprintf(stderr,"garbage at the end of input file: %s\n",fname);
    }
    fclose(fp);
}
Esempio n. 11
0
void test_Persistency3(bool withdot=false) {
  writeTree(withdot);
  printf("**** Write finished...\n");
  readTree(withdot);
  printf("**** Read finished...\n");
}
Esempio n. 12
0
   //@builds a balanced tree
   //@pre: items are assigned
   //@post: puts items into tree to build a balanced tree
   //@usage: bst.rebalanceTree();
void cbstree::rebalanceTree(ifstream& infile)
{
   destroyTree(mroot);
   infile >> itemCount;
   readTree(mroot, infile, itemCount);
}
Esempio n. 13
0
void ParseTreeLablerForm::init(int argc, char** argv)
{
    if(argc!=5 && argc!=6)
    {
        cerr<<"usage:"<<argv[0]<<" <segmented_PCD> <neighborMap> <inputTree> <typenames>"<<endl;
        exit(-1);
    }
        labelColors[0]= new ColorRGB(1,0,0);
        labelColors[1]= new ColorRGB(0,1,0);
        labelColors[2]= new ColorRGB(0,0,1);
        labelColors[3]= new ColorRGB(1,1,0);
        labelColors[4]= new ColorRGB(0,1,1);
        labelColors[5]= new ColorRGB(1,0,1);
        labelColors[6]= new ColorRGB(0.5,0,0);
        labelColors[7]= new ColorRGB(0,0.5,0);
        labelColors[8]= new ColorRGB(0,0,0.5);
        labelColors[9]= new ColorRGB(0.5,0,0.5);


    std::ifstream fileI;
    std::string line;
    typeListFile=argv[4];
    fileI.open(typeListFile);

    if (fileI.is_open()) {
        int count = 1;
        while (fileI.good()) {
            getline(fileI, line); //each line is a label
            if (line.size() == 0)
                break;
            cout << "adding typename " << line  << endl;
            widget.comboBox->addItem(QString(line.data()));
            count++;
            typeMaxId[line]=0;
        }
    } else {
        cout << "could not open typenames file...exiting\n";
        exit(-1);
    }
                        
    fileI.close();


    parseNbrMap(argv[2],nbrMap,INT_MAX);
    parseTreeFileName=argv[3];
  //  setUpTree(argv[3]);
    readTree(argv[3]);
//    exit(-1);

    nodeTableModel=new PTNodeTableModel(0);
    colorMapTableModel=new ColorMapTableModel(0);
    widget.colorTable->setModel(colorMapTableModel);
    widget.tableView->setModel(nodeTableModel);
    // read from file
    pcdFileName=argv[1];
    if ( pcl::io::loadPCDFile<PointT > (pcdFileName, cloud_orig) == -1) {
        ROS_ERROR("Couldn't read file ");
        exit (-1);
    }
    
    //viewer.createViewPort(0.0, 0.0, 1.0, 1.0);
    cloud_colored=cloud_orig;
    updatePCDVis();
    
     QItemSelectionModel *selectionModel= widget.treeView->selectionModel();
     connect(selectionModel, SIGNAL(selectionChanged (const QItemSelection &, const QItemSelection &)),
             this, SLOT(selectionChangedSlot(const QItemSelection &, const QItemSelection &)));

     connect(widget.addButton, SIGNAL(clicked ()),
             this, SLOT(addNodeButtonClicked()));
     connect(widget.combineButton, SIGNAL(clicked ()),
             this, SLOT(combineButtonClicked()));
     connect(widget.clearButton, SIGNAL(clicked ()),
             this, SLOT(clearButtonClicked()));
     connect(this, SIGNAL(finished (int)),
             this, SLOT(windowClosing()));
     connect(widget.deleteButton, SIGNAL(clicked ()),
             this, SLOT(deleteNodeButtonClicked()));
     connect(widget.showNbrButton, SIGNAL(clicked ()),
             this, SLOT(showNbrButtonClicked()));
     connect(widget.splitButton, SIGNAL(clicked ()),
             this, SLOT(splitButtonClicked()));
     connect(widget.undoSplitButton, SIGNAL(clicked ()),
             this, SLOT(undoSplitButtonClicked()));
     connect(widget.treeView, SIGNAL(doubleClicked(const QModelIndex &)),
             this, SLOT(addNodeFromTree(const QModelIndex &)));
     
     widget.comboBox->setEditable(true);
     widget.comboBox->setDuplicatesEnabled(false);
     widget.filenameLabel->setText(argv[1]);
 
    // Convert to the templated message type
  //  pcl::fromROSMsg(cloud_blob_orig, cloud_orig);
   // pcl::PointCloud<PointT>::Ptr orig_cloud_ptr(new pcl::PointCloud<PointT > (cloud_orig));



//    get_sorted_indices(cloud_orig, segmentIndices);
//    sizeSortColors(segmentIndices, colorToSeg);

    


 //   color_handler_orig.reset(new pcl_visualization::PointCloudColorHandlerRGBField<sensor_msgs::PointCloud2 > (cloud_blob_orig));

  //  viewer.addPointCloud(*orig_cloud_ptr, color_handler_orig, "orig");

    
}