示例#1
0
void loadSRSML()
{

	cout << "parsing srsml..." << endl;


	// Read the xml file into a vector
	ifstream theFile ("gastrectomy.xml");
	vector<char> buffer((istreambuf_iterator<char>(theFile)), istreambuf_iterator<char>());
	buffer.push_back('\0');
	// Parse the buffer using the xml file parsing library into doc
	doc.parse<0>(&buffer[0]);
	// Find our root node
	cout << "parsing a root element" << endl;
	root_node = doc.first_node("srsml");

	int size = strlen((((root_node->first_node("models"))->first_node("vessels"))->first_attribute("name"))->value());
	int size2 = strlen((((root_node->first_node("models"))->first_node("vessels"))->first_attribute("type"))->value());

	// variables for malloc
	elements=(char*) malloc(size+1);
	elements2=(char*) malloc(size2+1);

	strcpy ((char*)elements,(char*)((((root_node->first_node("models"))->first_node("vessels"))->first_attribute("name"))->value()));
	strcpy ((char*)elements2,(char*)((((root_node->first_node("models"))->first_node("vessels"))->first_attribute("type"))->value()));

	// variables for string
	str_elements.assign((((root_node->first_node("models"))->first_node("vessels"))->first_attribute("name"))->value());
	str_elements2.assign((((root_node->first_node("models"))->first_node("vessels"))->first_attribute("type"))->value());

	// Iterate over the vessels
	if (root_node){
		cout << "if there is a root element" << endl;
		for (xml_node<> * models_node = root_node->first_node("models"); models_node!=NULL; models_node = models_node->next_sibling())
		{
			cout << "here is in the model for loop" << endl;
			for (xml_node<> * vessels_node = models_node->first_node("vessels"); vessels_node!=NULL; vessels_node = vessels_node->next_sibling())
			{
				cout << "here is in the vessels for loop" << endl;
				printf("I have visited in. ");//,
					// Interate over the beers
				cout << "here is before the inner for loop" << endl;
				for(xml_node<> * vessel_node = vessels_node->first_node("vessel"); vessel_node; vessel_node = vessel_node->next_sibling())
				{
					printf("On, I tried their %s which is a %s. ",
							vessel_node->first_attribute("name")->value(),
							vessel_node->first_attribute("type")->value());
				}
				cout << endl;
			}
		}
	}
}
示例#2
0
XmlNodeRef XmlParserImp::parse(char* buffer, int bufLen, const char* rootNodeName, behaviac::string& errorString, bool isFinal)
{
    BEHAVIAC_UNUSED_VAR(bufLen);
    BEHAVIAC_UNUSED_VAR(errorString);
    BEHAVIAC_UNUSED_VAR(isFinal);

    m_parser.parse<0>(buffer);

    xml_node<>* xmlnode = m_parser.first_node(rootNodeName);

    XmlNodeRef node = cloneXmlNodeFrom(xmlnode);

    return node;
}
void osm_loader::load_bounds() 
{
    xml_node *root = doc_.first_node("osm");
    if (root == NULL)
        return;

    string str = root->first_node("bound")->first_attribute("box")->value();
    vector<string> strs;
    boost::split(strs, str, boost::is_any_of(","));

    mins.x = atof(strs[0].c_str());
    mins.y = atof(strs[1].c_str());
    maxs.x = atof(strs[2].c_str());
    maxs.y = atof(strs[3].c_str());
}
示例#4
0
void loadXML()
{

	cout << "Parsing my beer journal..." << endl;


	// Read the xml file into a vector
	cout << "before loading a xml file" << endl;
	ifstream theFile ("beerJournal.xml");
	cout << "after loading a xml file" << endl;
	vector<char> buffer((istreambuf_iterator<char>(theFile)), istreambuf_iterator<char>());
	buffer.push_back('\0');
	// Parse the buffer using the xml file parsing library into doc
	doc.parse<0>(&buffer[0]);
	// Find our root node
	cout << "before parsing a root element" << endl;
	root_node = doc.first_node("MyBeerJournal");
	// Iterate over the brewerys
//	elements = "sldfjlsdjfldsjfldsjflsdjflds";
	elements=(char*) malloc(strlen(((((root_node)->first_node("Brewery"))->first_attribute("name"))->value()))+1);

	strcpy ((char*)elements,(char*)(((root_node)->first_node("Brewery"))->first_attribute("name"))->value());
	elements[strlen(((((root_node)->first_node("Brewery"))->first_attribute("name"))->value()))]='\0';
//	elements = "char";
	printf("here is element:%s\n",elements);
	cout << "after parsing a root element" << endl;
	if (root_node){
		cout << "if there is a root element" << endl;
		for (xml_node<> * brewery_node = root_node->first_node("Brewery"); brewery_node!=NULL; brewery_node = brewery_node->next_sibling())
		{
			cout << "here is in the for loop" << endl;
			printf("I have visited %s in %s. ",
				brewery_node->first_attribute("name")->value(),
				brewery_node->first_attribute("location")->value());
				// Interate over the beers
			cout << "here is before the inner for loop" << endl;
			for(xml_node<> * beer_node = brewery_node->first_node("Beer"); beer_node; beer_node = beer_node->next_sibling())
			{
				printf("On %s, I tried their %s which is a %s. ",
					beer_node->first_attribute("dateSampled")->value(),
					beer_node->first_attribute("name")->value(),
					beer_node->first_attribute("description")->value());
				printf("I gave it the following review: %s", beer_node->value());
			}
			cout << endl;
		}
	}
}
void osm_loader::prepare_verts(unordered_set<xml_id> &verts_pending) 
{
    cout << "Preparing verts" << endl;
    
    xml_node *root = doc_.first_node("osm");
    if (root == NULL)
        return;

    size_t counter = 0;
    xml_node *node = root->first_node("node");
    while (node != NULL)
    {
        xml_id id = atol(node->first_attribute("id")->value());
        verts_pending.insert(id);
        node = node->next_sibling("node");
    }
}
void osm_loader::load_verts() 
{
    xml_node *root = doc_.first_node("osm");
    if (root == NULL)
        return;
    
    size_t counter = 0;
    xml_node *node = root->first_node("node");
    while (node != NULL)
    {
        if (counter >= MAX_VERTS)
            break;
        xml_id id = atol(node->first_attribute("id")->value());

        if (pgraph_->vertex_exists(id))
        {
            vis_coord coord (atof(node->first_attribute("lat")->value()),
                             atof(node->first_attribute("lon")->value()));

            
            vis_vertex &v = pgraph_->get_vertex(id);
            vis_vertex_data &ref_data = v.get_data();

            ref_data.c = coord;
            
            int degree = v.get_out_degree();
            if (degree >= degrees_stats_.size())
                degrees_stats_.resize(degree + 1, 0);
            ++degrees_stats_[degree];
            

            if (counter % 100000 == 0)
                cout << counter << " verts loaded" << endl;
            ++counter;
        }
        node = node->next_sibling("node");
    }

    update_edge_weights();

}
void osm_loader::load_edges()
{
    unordered_set<xml_id> verts_pending;
    prepare_verts(verts_pending);

    cout << "Loading edges" << endl;

    xml_node *root = doc_.first_node("osm");
    if (root == NULL)
        return;

    xml_node *node = root->first_node("way");
    while (node != NULL)
    {
        if (pgraph_->v_count() >= MAX_VERTS)
            break;

        load_way (node, verts_pending);
        node = node->next_sibling("way");
    }

}
示例#8
0
\endverbatim
//! <c>doc</c> object is now a root of DOM tree containing representation of the parsed XML.
//! Because all RapidXml interface is contained inside namespace <c>rapidxml</c>, 
//! users must either bring contents of this namespace into scope, or fully qualify all the names.
//! Class xml_document represents a root of the DOM hierarchy. 
//! By means of public inheritance, it is also an xml_node and a memory_pool.
//! Template parameter of xml_document::parse() function is used to specify parsing flags, 
//! with which you can fine-tune behaviour of the parser.
//! Note that flags must be a compile-time constant.
//!
//! \subsection accessing_dom_tree Accessing The DOM Tree
//!
//! To access the DOM tree, use methods of xml_node and xml_attribute classes:
//! \verbatim
cout << "Name of my first node is: " << doc.first_node()->name() << "\n";
xml_node<> *node = doc.first_node("foobar");
cout << "Node foobar has value " << node->value() << "\n";
for (xml_attribute<> *attr = node->first_attribute();
     attr; attr = attr->next_attribute())
{
    cout << "Node foobar has attribute " << attr->name() << " ";
    cout << "with value " << attr->value() << "\n";
}
\endverbatim
//!
//! \subsection modifying_dom_tree Modifying The DOM Tree
//!
//! DOM tree produced by the parser is fully modifiable. Nodes and attributes can be added/removed,
//! and their contents changed. The below example creates a HTML document, whose sole contents is a link to google.com website:
//! \verbatim
xml_document<> doc;
示例#9
0
void ProjectManager::loadEnvironment(xml_document<> &doc)
{
	objects.clear();

	cout << "loading environment..." << "\n" << flush;
	xml_node<> *profile = doc.first_node()->first_node("profile");
	xml_node<> *user = profile->first_node("user");
	xml_node<> *objecties = profile->first_node("object");
	//read x y z h p r from user block and place object there
	
	cout << "obtained variables..." << "\n" << flush;
	//look at obj nodes, then check the doc for the location, then import and position at the correct location
	
	string path = projectDir + "\\data\\obj";
	//string filename = objecties->first_node("resourceName")->value();
	cout << "projdir: " << projectDir << "\n" << flush;
	vector<string> pathv;
	vector<string> filenamev;
	vector<float> objx;
	vector<float> objy;
	vector<float> objz;
	vector<float> objh;
	vector<float> objp;
	vector<float> objr;
	vector<float> objscale;
	vector<char *> objname;
	//filenamev.push_back(filename);
	
	xml_node<> *userlocation = user->first_node("startingLocation");
	if (userlocation != 0)
	{
		float x = atof(userlocation->first_node("x")->value());
		float y = atof(userlocation->first_node("y")->value());
		float z = atof(userlocation->first_node("z")->value());
		float h = atof(userlocation->first_node("heading")->value());
		float p = atof(userlocation->first_node("pitch")->value());
		float r = atof(userlocation->first_node("roll")->value());
		char *name = user->first_node("name")->value();
		
		objx.push_back(x);
		objy.push_back(y+3.3); //for mrbody this should be y+3
		objz.push_back(z);
		objh.push_back(h);
		objp.push_back(p+180); //for mrbody this should be p-12
		objr.push_back(r);
		objscale.push_back(4); //for mrbody this should be 4
		objname.push_back(name);
		
		//string filename = "MrBodyWithHands.obj";
		string filename = "batman.obj";
		filenamev.push_back(filename);
		string pathy = PATH+"Kosmos\\data\\obj";
		pathv.push_back(pathy);
		//Import::import("cello.obj", x, y, z, h, p, r, "C:\\aszgard5\\szg\\projects\\Kosmos\\data\\obj");
	}
	
	
	
	
	while(objecties != 0)
	{
		cout << "loading object..." << "\n" << flush;
		//filename = "";
		// get xyzhpr and import object
		
		string filename = objecties->first_node("resourceName")->value();
		filenamev.push_back(filename);
		pathv.push_back(path);
		/*int length = filename.length();
		if (filename[length-1] == 'j' && filename[length-2] == 'b' && filename[length-3] == 'o')
		{
			cout << "wth file is obj " << "\n" << flush;
		}*/
		float x = atof(objecties->first_node("x")->value());
		float y = atof(objecties->first_node("y")->value());
		float z = atof(objecties->first_node("z")->value());
		float h = atof(objecties->first_node("heading")->value());
		float p = atof(objecties->first_node("pitch")->value());
		float r = atof(objecties->first_node("roll")->value());
		float s = atof(objecties->first_node("scale")->value());
		char *name = objecties->first_node("name")->value();
		
		objx.push_back(x);
		objy.push_back(y);
		objz.push_back(z);
		objh.push_back(h);
		objp.push_back(p);
		objr.push_back(r);
		objscale.push_back(s);
		objname.push_back(name);
		/*
			<resourceName>cello.obj</resourceName>
			<x>0</x>
			<y>4</y>
			<z>-4</z>
			<heading>0</heading>
			<pitch>0</pitch>
			<roll>0</roll>
		*/
		objecties = objecties->next_sibling();
		if (objecties == 0)
		{
			break;
		}
	}
	
	for( unsigned int i=0; i<filenamev.size(); ++i)
	{
		if (i==0)
		{
			userObject = Import::import(filenamev[i], objx[i], objy[i], objz[i], objh[i], objp[i], objr[i], objscale[i], pathv[i],5,objname[i]);
		}
		else
		{
			Import::import(filenamev[i], objx[i], objy[i], objz[i], objh[i], objp[i], objr[i], objscale[i], pathv[i],2,objname[i]);
		}
	}
	
	filenamev.clear();
	objx.clear();
	objy.clear();
	objz.clear();
	objh.clear();
	objp.clear();
	objr.clear();
	objscale.clear();
	objname.clear();
	pathv.clear();
	
	float wiimoteX = 1.9; //2 for mrbody
	float wiimoteY = 3.5; //4 for mrbody
	float wiimoteZ = -0.6; //-0.7 for mrbody, negative moves closer
	rightWiimote = new Object(4, 0.5, 0.5, 0.5, "MrWiimote.obj");
	rightWiimote->normalize();
	rightWiimote->setMatrix(ar_translationMatrix(wiimoteX, wiimoteY, wiimoteZ)); // initial position
	rightWiimote->setHPR(135,0,0);
	//rightWiimote->disable();
	//rightWiimote->_selected = true;
	//rightWiimote->setHighlight(true);
	objects.push_back(rightWiimote);
	
	leftWiimote = new Object(4, 0.5, 0.5, 0.5, "MrWiimote.obj");
	leftWiimote->normalize();
	leftWiimote->setMatrix(ar_translationMatrix(-wiimoteX, wiimoteY, wiimoteZ)); // initial position
	leftWiimote->setHPR(135,0,0);
	objects.push_back(leftWiimote);
	
	headMountedDisplay = new Object(6, 0.4, 0.4, 0.35, "MrVisor.obj");
	headMountedDisplay->normalize();
	headMountedDisplay->setMatrix(ar_translationMatrix(0, 5.85, -0.09)); // initial position
	headMountedDisplay->setHPR(0,-90,0);
	objects.push_back(headMountedDisplay);
}