bool loadAnimFile(MMesh * mesh, const char * filename, const char * repertory) { TiXmlDocument doc(filename); if(! doc.LoadFile()) return false; TiXmlHandle hDoc(&doc); TiXmlElement * pRootNode; TiXmlHandle hRoot(0); // Maratis pRootNode = hDoc.FirstChildElement().Element(); if(! pRootNode) return false; if(strcmp(pRootNode->Value(), "Maratis") != 0) return false; hRoot = TiXmlHandle(pRootNode); return loadAnim(pRootNode, repertory, mesh); }
bool cCentreManager::LoadDataXML(TiXmlHandle hBrothelManager) { Free();//everything should be init even if we failed to load an XML element //watch out, this frees dungeon and rivals too TiXmlElement* pBrothelManager = hBrothelManager.ToElement(); if (pBrothelManager == 0) { return false; } string message = ""; // ................................................... message = "***************** Loading centre ****************"; g_LogFile.write(message); m_NumCentres = 0; TiXmlElement* pBrothels = pBrothelManager->FirstChildElement("Centres"); if (pBrothels) { for (TiXmlElement* pBrothel = pBrothels->FirstChildElement("Centre"); pBrothel != 0; pBrothel = pBrothel->NextSiblingElement("Centre")) { sCentre* current = new sCentre(); bool success = current->LoadCentreXML(TiXmlHandle(pBrothel)); if (success == true) { AddBrothel(current); } else { delete current; continue; } } // load a centre } return true; }
void testApp::loadSettings(){ //load settings TiXmlDocument doc( "userConfig.xml" ); if (!doc.LoadFile()) return; TiXmlHandle hDoc(&doc); TiXmlElement * element; TiXmlHandle hRoot(0); element=hDoc.FirstChildElement().Element(); if (!element) return; hRoot=TiXmlHandle(element); element=hRoot.FirstChild( "Actor" ).Element(); int listPos=0; string myType; for( ; element!=NULL; element=element->NextSiblingElement("Actor")){ myType=element->GetText(); cout << "Loading property type: " << myType << endl; load(element); listPos++; } }
// Load the slot details - ie the current setup in samplechanger.xml void converter::loadSlotDetails(const char* fname) { TiXmlDocument doc(fname); if (!doc.LoadFile()) { errlogPrintf("sampleChanger: Unable to open slot details file \"%s\"\n", fname); return; } TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem=hDoc.FirstChildElement().Element(); if (!pElem) { errlogPrintf("sampleChanger: Unable to parse slot details file \"%s\"\n", fname); return; } // save this for later hRoot=TiXmlHandle(pElem); loadSlotDetails(hRoot); }
void VideoTextureActor::loadMovie(string fileName){ TiXmlDocument doc( fileName ); if (!doc.LoadFile()) return; TiXmlHandle hDoc(&doc); TiXmlElement * element; TiXmlHandle hRoot(0); element=hDoc.FirstChildElement().Element(); // should always have a valid root but handle gracefully if it doesn't if (!element) return; // save this for later hRoot=TiXmlHandle(element); element=hRoot.FirstChild( "Video" ).Element(); string vFileName=element->Attribute("vidFilename"); cout << "LOADING video file: " << vFileName << endl; player->loadMovie(vFileName); player->setLoopState(OF_LOOP_NONE); }
/** * Get a scene from a map file in XML format. */ Scene* MapLoader::getScene(const std::string &path) { scene = new Scene(); TiXmlDocument doc(Environment::getDataDir() + "/maps/" + path + ".xml"); bool loaded = doc.LoadFile(); if (loaded) { TiXmlHandle docHandle(&doc); TiXmlElement *element = docHandle.FirstChildElement().ToElement(); rootHandle = TiXmlHandle(element); extractSpawn(); extractDoor(); extractModels(); extractLights(); extractWalls(); extractTriggers(); cout << "File loaded." << endl; } else { cout << "Unable to load file. " << endl; cout << Environment::getDataDir() << "/" << path << ".xml" << endl; } return scene; }
bool SpriteMeshLoader::loadSpriteMesh( string filename, string meshID ){ //check if meshID already exists! if (renderer->vboList[meshID]){ renderer->vboList.erase(meshID); } // XML File Open cout << "Loading file..." << filename <<endl; TiXmlDocument doc( filename ); if (!doc.LoadFile()) return false; TiXmlHandle hDoc(&doc); TiXmlElement * element; TiXmlHandle hRoot(0); //*********************************************************************** //Skip over first Element //*********************************************************************** element=hDoc.FirstChildElement().Element(); // should always have a valid root but handle gracefully if it doesn't if (!element) return false; // save this for later hRoot=TiXmlHandle(element); //end XML file open; //setup new MeshData MeshData* myMesh=new MeshData; myMesh->bIsSkeletal=false; myMesh->bIsHead=false; myMesh->bVertexColor=true; myMesh->boneCount=0; myMesh->texCoordPerVertexCount=3; myMesh->verticesPerShapeCount=4; myMesh->vertexInterpretation=GL_POINTS; myMesh->drawType=DRAW_VBOMESH; renderer->vboList[meshID]=myMesh; loadVertices(meshID, hRoot.FirstChild("vertices").Element()); loadNormals(meshID, hRoot.FirstChild("normals").Element()); loadTexCoords(meshID, hRoot.FirstChild("texCoords").Element()); loadColors(meshID, hRoot.FirstChild("colors").Element()); loadSecondaryColors(meshID, hRoot.FirstChild("secondaryColors").Element()); loadBoneReferences(meshID, hRoot.FirstChild("boneReferences").Element()); loadVertexWeights(meshID, hRoot.FirstChild("vertexWeights").Element()); cout << "loading bones..." << endl; loadBones(meshID, hRoot.FirstChild("bone").Element()); //fill vertex data for editing if (!renderer->vboList[meshID]->vData.empty()) renderer->vboList[meshID]->vData.clear(); for (int i=0;i<vertexCount;i++){ vertexData myVData; myVData.location=vertices[i]; myVData.normal=normals[i]; myVData.color=colors[i]; myVData.secondaryColor=secondaryColors[i]; myVData.birth=0.0f; myVData.texCoord=texCoords[i]; myVData.vertexWeights=vertexWeights[i]; myVData.boneReferences=boneReference[i]; renderer->vboList[meshID]->vData.push_back(myVData); } cout << "before creating vbos..." << endl; createVBOs(meshID); cout << "after creating vbos..." << endl; //now free our resources: delete(vertices); delete(normals); delete(texCoords); delete(colors); delete(secondaryColors); delete(vertexWeights); delete(boneReference); doc.Clear(); cout << "finished loading SpriteMesh" << endl; return true; }
bool cDungeon::LoadDungeonDataXML(TiXmlHandle hDungeon) // loads all the people (they are stored with the dungeon) { Free();//everything should be init even if we failed to load an XML element TiXmlElement* pDungeon = hDungeon.ToElement(); if (pDungeon == 0) { return false; } // load number died pDungeon->QueryValueAttribute<unsigned long>("NumberDied", &m_NumberDied); // load girls m_NumGirls = 0; stringstream ss; TiXmlElement* pDungeonGirls = pDungeon->FirstChildElement("Dungeon_Girls"); if (pDungeonGirls) { // load each girl and add her for (TiXmlElement* pGirl = pDungeonGirls->FirstChildElement("Girl"); pGirl != 0; pGirl = pGirl->NextSiblingElement("Girl")) { sDungeonGirl* girl = new sDungeonGirl(); girl->m_Girl = new sGirl(); bool success = girl->m_Girl->LoadGirlXML(TiXmlHandle(pGirl)); if (success == true) { ss << "Loading Dungeon Girl: " << girl->m_Girl->m_Realname; g_LogFile.write(ss.str()); ss.str(""); TiXmlElement* pDungeonData = pGirl->FirstChildElement("Dungeon_Data"); if (pDungeonData) { pDungeonData->QueryValueAttribute<bool>("Feeding", &girl->m_Feeding); pDungeonData->QueryIntAttribute("Reason", &girl->m_Reason); pDungeonData->QueryIntAttribute("Weeks", &girl->m_Weeks); } PlaceDungeonGirl(girl); } else { delete girl; continue; } } } // load customers m_NumCusts = 0; ss.str(""); ss << "Loading customers"; g_LogFile.write(ss.str()); TiXmlElement* pDungeonCustomers = pDungeon->FirstChildElement("Dungeon_Customers"); if (pDungeonCustomers) { for (TiXmlElement* pCustomer = pDungeonCustomers->FirstChildElement("Customer"); pCustomer != 0; pCustomer = pCustomer->NextSiblingElement("Customer")) { sDungeonCust* customer = new sDungeonCust(); pCustomer->QueryValueAttribute<bool>("Feeding", &customer->m_Feeding); pCustomer->QueryValueAttribute<bool>("Tort", &customer->m_Tort); pCustomer->QueryValueAttribute<bool>("HasWife", &customer->m_HasWife); pCustomer->QueryIntAttribute("Reason", &customer->m_Reason); pCustomer->QueryIntAttribute("NumDaughters", &customer->m_NumDaughters); pCustomer->QueryIntAttribute("Weeks", &customer->m_Weeks); pCustomer->QueryIntAttribute(gettext("Health"), &customer->m_Health); PlaceDungeonCustomer(customer); } } return true; }
bool Layout::loadSVG(string svgPath) { printf("loading svg from %s\n", svgPath.c_str()); TiXmlDocument doc( svgPath.c_str() ); if (!doc.LoadFile()){ printf("WARNING: Failed to load file!\n"); return false; } TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); // block: SVG - check to make sure this is actually an SVG file { pElem=hDoc.FirstChildElement().Element(); // should always have a valid root but handle gracefully if it does if (!pElem) return false; printf("ROOT: %s\n",pElem->Value()); if( strcmp(pElem->Value(),"svg") != 0 ){ printf("WARNING: Opened XML file bu this is not an SVG file!\n"); return false; } // save this for later hRoot=TiXmlHandle(pElem); } //Search the SVG file for the block we want to parse, this should be in a group node // block: windows { TiXmlElement* pGroupElement = hRoot.FirstChild( "g" ).Element(); if( pGroupElement == NULL ){ printf("Failed to find child g\n"); return false; } for( pGroupElement; pGroupElement; pGroupElement=pGroupElement->NextSiblingElement() ) { const char *pName=pGroupElement->Attribute("id"); if(pName) printf("ID: %s\n",pName); if( pName ){ if( strcmp( pName, keyElementID.c_str() ) == 0 ){ printf("FOUND KEY Element\n"); //Load the main bounding rectanlge TiXmlElement* pElement = pGroupElement->FirstChildElement( "rect" ); if( pElement == NULL ){ printf("Failed to parse rect from file!\n"); return false; } pElement->QueryDoubleAttribute("x", &svgBoundingRect.x); pElement->QueryDoubleAttribute("y", &svgBoundingRect.y); pElement->QueryDoubleAttribute("width", &svgBoundingRect.width); pElement->QueryDoubleAttribute("height", &svgBoundingRect.height); //Search for the wall lines for( pElement = pGroupElement->FirstChildElement("line"); pElement; pElement=pElement->NextSiblingElement() ) { if( strcmp(pElement->Value(),"line") == 0 ){ LINE newLine; pElement->QueryDoubleAttribute("x1", &newLine.x1); pElement->QueryDoubleAttribute("y1", &newLine.y1); pElement->QueryDoubleAttribute("x2", &newLine.x2); pElement->QueryDoubleAttribute("y2", &newLine.y2); // transform line newLine.x1 = newLine.x1 / pixelsPerMeter + boundingRectRealWorldCoordinates.x; newLine.y1 = newLine.y1 / pixelsPerMeter + boundingRectRealWorldCoordinates.y; newLine.x2 = newLine.x2 / pixelsPerMeter + boundingRectRealWorldCoordinates.x; newLine.y2 = newLine.y2 / pixelsPerMeter + boundingRectRealWorldCoordinates.y; wallLines.push_back( newLine ); } } } } } } return true; }
bool xmlImport::importProps() { TiXmlDocument doc(xmlFile.c_str()); if(!doc.LoadFile()){ Logger::getLogger()->debug("Error: could not load properties XML file"); return false; } TiXmlElement* pElem; TiXmlElement* pChild; TiXmlHandle hDoc(&doc); TiXmlHandle hRoot(0); DesignStore::Ptr ds = Game::getGame()->getDesignStore(); int count=0; // item count pElem = hDoc.FirstChildElement("properties").Element(); if(!pElem) return false; hRoot = TiXmlHandle(pElem); for(pElem=hRoot.FirstChild("prop").Element(); pElem != NULL; pElem = pElem->NextSiblingElement()) { TiXmlElement* pCur = 0; std::string propName, propDisplayName, propDescription, propTpclDisplay, propTpclRequirement, propIDName; int propRank; std::map<uint32_t, std::string> propertylist; pChild = hRoot.Child("prop",count).Element(); //debug: cout << "count: " << count << endl; if(pChild) { //read and set the name of the property pCur = pChild->FirstChildElement("name"); if (pCur) { propName = pCur->GetText(); if (propName.empty()) return false; } else { return false; } //read and set the name of the property pCur = pChild->FirstChildElement("displayName"); if (pCur) { propDisplayName = pCur->GetText(); if (propDisplayName.empty()) return false; } else { return false; } //read and set the ID of the property pCur = pChild->FirstChildElement("PropertyIDName"); if (pCur) { propIDName = pCur->GetText(); if (propIDName.empty()) return false; } else { return false; } //read and set the rank of the property pCur = pChild->FirstChildElement("rank"); if (pCur) { if (pCur->QueryIntAttribute("value", &(propRank)) != TIXML_SUCCESS) { return false; } } //read and set the description of the property pCur = pChild->FirstChildElement("description"); if (pCur) { propDescription = pCur->GetText(); if (propDescription.empty()) return false; } else { return false; } //read and set the tpclDisplayFunction of the property pCur = pChild->FirstChildElement("tpclDisplayFunction"); if (pCur) { propTpclDisplay = pCur->GetText(); if (propTpclDisplay.empty()) return false; } else { return false; } //read and set the tpclRequirementsFunction of the property pCur = pChild->FirstChildElement("tpclRequirementsFunction"); if (pCur) { propTpclRequirement = pCur->GetText(); if (propTpclRequirement.empty()) return false; } else { return false; } //do the property Property::Ptr prop( new Property() ); prop->addCategoryId(ds->getCategoryByName(propIDName)); prop->setRank((uint32_t)propRank); prop->setName(propName); prop->setDisplayName(propDisplayName); prop->setDescription(propDescription); prop->setTpclDisplayFunction(propTpclDisplay); prop->setTpclRequirementsFunction(propTpclRequirement); ds->addProperty(prop); } else { return false; } count++; } return true; }
bool CDVDStateSerializer::XMLToDVDState( dvd_state_t *state, const std::string &xmlstate ) { TiXmlDocument xmlDoc; xmlDoc.Parse(xmlstate.c_str()); if( xmlDoc.Error() ) return false; TiXmlHandle hRoot( xmlDoc.RootElement() ); if( strcmp( hRoot.Element()->Value(), "navstate" ) != 0 ) return false; TiXmlElement *element = NULL; TiXmlText *text = NULL; int index = 0; element = hRoot.FirstChildElement("registers").FirstChildElement("sprm").Element(); while( element ) { element->Attribute("index", &index); text = TiXmlHandle( element ).FirstChildElement("value").FirstChild().Text(); if( text && index >= 0 && index < 24 ) sscanf(text->Value(), "0x%hx", &state->registers.SPRM[index]); element = element->NextSiblingElement("sprm"); } element = hRoot.FirstChildElement("registers").FirstChildElement("gprm").Element(); while( element ) { element->Attribute("index", &index); if( index >= 0 && index < 16 ) { text = TiXmlHandle( element ).FirstChildElement("value").FirstChild().Text(); if( text ) sscanf(text->Value(), "0x%hx", &state->registers.GPRM[index]); text = TiXmlHandle( element ).FirstChildElement("mode").FirstChild().Text(); if( text ) sscanf(text->Value(), "0x%c", &state->registers.GPRM_mode[index]); text = TiXmlHandle( element ).FirstChildElement("time").FirstChildElement("tv_sec").FirstChild().Text(); if( text ) sscanf(text->Value(), "%ld", &state->registers.GPRM_time[index].tv_sec); text = TiXmlHandle( element ).FirstChildElement("time").FirstChildElement("tv_usec").FirstChild().Text(); if( text ) sscanf(text->Value(), "%ld", (long int*)&state->registers.GPRM_time[index].tv_usec); } element = element->NextSiblingElement("gprm"); } if( (text = hRoot.FirstChildElement("domain").FirstChild().Text()) ) sscanf(text->Value(), "%d", (int*) &state->domain); if( (text = hRoot.FirstChildElement("vtsn").FirstChild().Text()) ) sscanf(text->Value(), "%d", &state->vtsN); if( (text = hRoot.FirstChildElement("pgcn").FirstChild().Text()) ) sscanf(text->Value(), "%d", &state->pgcN); if( (text = hRoot.FirstChildElement("pgn").FirstChild().Text()) ) sscanf(text->Value(), "%d", &state->pgN); if( (text = hRoot.FirstChildElement("celln").FirstChild().Text()) ) sscanf(text->Value(), "%d", &state->cellN); if( (text = hRoot.FirstChildElement("cell_restart").FirstChild().Text()) ) sscanf(text->Value(), "%d", &state->cell_restart); if( (text = hRoot.FirstChildElement("blockn").FirstChild().Text()) ) sscanf(text->Value(), "%d", &state->blockN); { TiXmlHandle hrsm = hRoot.FirstChildElement("rsm"); if( (text = hrsm.FirstChildElement("vtsn").FirstChild().Text()) ) sscanf(text->Value(), "%d", &state->rsm_vtsN); if( (text = hrsm.FirstChildElement("blockn").FirstChild().Text()) ) sscanf(text->Value(), "%d", &state->rsm_blockN); if( (text = hrsm.FirstChildElement("pgcn").FirstChild().Text()) ) sscanf(text->Value(), "%d", &state->rsm_pgcN); if( (text = hrsm.FirstChildElement("celln").FirstChild().Text()) ) sscanf(text->Value(), "%d", &state->rsm_cellN); element = hrsm.FirstChildElement("registers").FirstChildElement("sprm").Element(); while( element ) { element->Attribute("index", &index); text = TiXmlHandle(element).FirstChildElement("value").FirstChild().Text(); if( text && index >= 0 && index < 5 ) sscanf(text->Value(), "0x%hx", &state->rsm_regs[index]); element = element->NextSiblingElement("sprm"); } } return true; }
bool QfileQts::abrir_infxml(string arquivo){ TiXmlDocument infxml(arquivo.c_str()); if(infxml.LoadFile()){ //o arquivo existe TiXmlHandle hDb(&infxml); TiXmlElement *pElem; TiXmlHandle hRoot(0); pElem = hDb.FirstChildElement("titulo").Element(); Titulo = pElem->GetText(); pElem = hDb.FirstChildElement("gerais").Element(); hRoot = TiXmlHandle(pElem); pElem = hRoot.FirstChildElement().Element(); switch(atoi(pElem->GetText())){ case 0: Tipo = Imagem; break; case 1: Tipo = Video; break; } pElem = pElem->NextSiblingElement(); Extensao = pElem->GetText(); pElem = pElem->NextSiblingElement(); Arquivo = pElem->GetText(); tamanho_arquivo = atoi(pElem->Attribute("tamanho")); pElem = pElem->NextSiblingElement(); Thumb = pElem->GetText(); tamanho_thumb = atoi(pElem->Attribute("tamanho")); pElem = pElem->NextSiblingElement(); Descricao = pElem->GetText(); pElem = pElem->NextSiblingElement(); CorPadrao = pElem->GetText(); pElem = pElem->NextSiblingElement(); pElem = hDb.FirstChildElement("posicao").Element(); hRoot = TiXmlHandle(pElem); pElem = hRoot.FirstChildElement().Element(); xTitulo = atoi(pElem->Attribute("x")); yTitulo = atoi(pElem->Attribute("y")); tpTitulo = atoi(pElem->Attribute("tamanho")); pElem = pElem->NextSiblingElement(); xInicio = atoi(pElem->Attribute("x")); yInicio = atoi(pElem->Attribute("y")); tpInicio = atoi(pElem->Attribute("tamanho")); switch(atoi(pElem->Attribute("posicao_texto"))){ case 0: posTexto = Esquerda; break; case 1: posTexto = Centralizado; break; case 2: posTexto = Direita; break; } return true; } else return false; }
bool ServerSettings::LoadSettings(string filename) { // Clear memory. if(groups) { for(int i = 0; i < groups->size(); i++) { delete (*groups)[i]; } delete groups; } if(databases) { for(int i = 0; i < databases->size(); i++) { delete (*databases)[i]; } delete databases; } groups = new vector<GroupSettings*>(); databases = new vector<DBSettings*>(); TiXmlDocument doc(filename); if(doc.LoadFile()) { cout << filename << " loaded" << endl; } else { cout << "error loading " << filename << endl; if(doc.Error()) { cout << doc.ErrorDesc() << endl; } return false; } TiXmlHandle hDoc(&doc); TiXmlElement* pElement; TiXmlHandle hRoot(0); pElement = hDoc.FirstChildElement().Element(); //Get the root element. // Check if the root element is correct. if( !(pElement->ValueStr() == XMLROOT) ) { cout << "Wrong root element!" << endl; return false; } hRoot = TiXmlHandle(pElement); // Store the root element. // Load server settings. pElement = hRoot.FirstChild(NETWORK).Element(); ServerSettings::LoadServerSettings(pElement); // Load group settings. pElement = hRoot.FirstChild(GROUPS).Element(); ServerSettings::LoadGroupSettings(pElement); // Load database settings. pElement = hRoot.FirstChild(DATABASES).Element(); ServerSettings::LoadDatabaseSettings(pElement); }
void FiberBundleXReader::GenerateOutputInformation() { try { const std::string& locale = "C"; const std::string& currLocale = setlocale( LC_ALL, NULL ); setlocale(LC_ALL, locale.c_str()); std::string ext = itksys::SystemTools::GetFilenameLastExtension(m_FileName); ext = itksys::SystemTools::LowerCase(ext); vtkSmartPointer<vtkDataReader> chooser=vtkDataReader::New(); chooser->SetFileName(m_FileName.c_str() ); if( chooser->IsFilePolyData()) { MITK_INFO << "Reading vtk fiber bundle"; vtkSmartPointer<vtkPolyDataReader> reader = vtkPolyDataReader::New(); reader->SetFileName( m_FileName.c_str() ); reader->Update(); if ( reader->GetOutput() != NULL ) { vtkSmartPointer<vtkPolyData> fiberPolyData = reader->GetOutput(); vtkSmartPointer<vtkCleanPolyData> cleaner = vtkSmartPointer<vtkCleanPolyData>::New(); cleaner->SetInput(fiberPolyData); cleaner->Update(); fiberPolyData = cleaner->GetOutput(); m_OutputCache = OutputType::New(fiberPolyData); } } else // try to read deprecated fiber bundle file format { MITK_INFO << "Reading xml fiber bundle"; vtkSmartPointer<vtkPolyData> fiberPolyData = vtkSmartPointer<vtkPolyData>::New(); vtkSmartPointer<vtkCellArray> cellArray = vtkSmartPointer<vtkCellArray>::New(); vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); TiXmlDocument doc( m_FileName ); if(doc.LoadFile()) { TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem = hDoc.FirstChildElement().Element(); // save this for later hRoot = TiXmlHandle(pElem); pElem = hRoot.FirstChildElement("geometry").Element(); // read geometry mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New(); // read origin mitk::Point3D origin; double temp = 0; pElem->Attribute("origin_x", &temp); origin[0] = temp; pElem->Attribute("origin_y", &temp); origin[1] = temp; pElem->Attribute("origin_z", &temp); origin[2] = temp; geometry->SetOrigin(origin); // read spacing float spacing[3]; pElem->Attribute("spacing_x", &temp); spacing[0] = temp; pElem->Attribute("spacing_y", &temp); spacing[1] = temp; pElem->Attribute("spacing_z", &temp); spacing[2] = temp; geometry->SetSpacing(spacing); // read transform vtkMatrix4x4* m = vtkMatrix4x4::New(); pElem->Attribute("xx", &temp); m->SetElement(0,0,temp); pElem->Attribute("xy", &temp); m->SetElement(1,0,temp); pElem->Attribute("xz", &temp); m->SetElement(2,0,temp); pElem->Attribute("yx", &temp); m->SetElement(0,1,temp); pElem->Attribute("yy", &temp); m->SetElement(1,1,temp); pElem->Attribute("yz", &temp); m->SetElement(2,1,temp); pElem->Attribute("zx", &temp); m->SetElement(0,2,temp); pElem->Attribute("zy", &temp); m->SetElement(1,2,temp); pElem->Attribute("zz", &temp); m->SetElement(2,2,temp); m->SetElement(0,3,origin[0]); m->SetElement(1,3,origin[1]); m->SetElement(2,3,origin[2]); m->SetElement(3,3,1); geometry->SetIndexToWorldTransformByVtkMatrix(m); // read bounds float bounds[] = {0, 0, 0, 0, 0, 0}; pElem->Attribute("size_x", &temp); bounds[1] = temp; pElem->Attribute("size_y", &temp); bounds[3] = temp; pElem->Attribute("size_z", &temp); bounds[5] = temp; geometry->SetFloatBounds(bounds); geometry->SetImageGeometry(true); pElem = hRoot.FirstChildElement("fiber_bundle").FirstChild().Element(); for( pElem; pElem; pElem=pElem->NextSiblingElement()) { TiXmlElement* pElem2 = pElem->FirstChildElement(); vtkSmartPointer<vtkPolyLine> container = vtkSmartPointer<vtkPolyLine>::New(); for( pElem2; pElem2; pElem2=pElem2->NextSiblingElement()) { itk::Point<float> point; pElem2->Attribute("pos_x", &temp); point[0] = temp; pElem2->Attribute("pos_y", &temp); point[1] = temp; pElem2->Attribute("pos_z", &temp); point[2] = temp; geometry->IndexToWorld(point, point); vtkIdType id = points->InsertNextPoint(point.GetDataPointer()); container->GetPointIds()->InsertNextId(id); } cellArray->InsertNextCell(container); } fiberPolyData->SetPoints(points); fiberPolyData->SetLines(cellArray); vtkSmartPointer<vtkCleanPolyData> cleaner = vtkSmartPointer<vtkCleanPolyData>::New(); cleaner->SetInput(fiberPolyData); cleaner->Update(); fiberPolyData = cleaner->GetOutput(); m_OutputCache = OutputType::New(fiberPolyData); } else { MITK_INFO << "could not open xml file"; throw "could not open xml file"; } } setlocale(LC_ALL, currLocale.c_str()); MITK_INFO << "Fiber bundle read"; } catch(...) { throw; } }
namespace glPortal { /** \class MapLoader * Load a map in GlPortal XML format. */ Scene* MapLoader::scene; TiXmlHandle MapLoader::rootHandle = TiXmlHandle(0); /** * Get a scene from a map file in XML format. */ Scene* MapLoader::getScene(const std::string &path) { scene = new Scene(); TiXmlDocument doc(Environment::getDataDir() + "/maps/" + path + ".xml"); bool loaded = doc.LoadFile(); if (loaded) { TiXmlHandle docHandle(&doc); TiXmlElement *element = docHandle.FirstChildElement().ToElement(); rootHandle = TiXmlHandle(element); extractSpawn(); extractDoor(); extractModels(); extractLights(); extractWalls(); extractTriggers(); cout << "File loaded." << endl; } else { cout << "Unable to load file. " << endl; cout << Environment::getDataDir() << "/" << path << ".xml" << endl; } return scene; } /** * Extract a spawn element containing its rotation and position elements */ void MapLoader::extractSpawn() { TiXmlElement *spawnElement = rootHandle.FirstChild("spawn").ToElement(); if (spawnElement) { XmlHelper::extractPosition(spawnElement, scene->player.position); XmlHelper::extractRotation(spawnElement, scene->player.rotation); } else { throw std::runtime_error("No spawn position defined."); } } /** * Extract a light elements containing position (x, y, z) and colour (r, g, b) attributes */ void MapLoader::extractLights() { Vector3f lightPos; Vector3f lightColor; float distance; float energy; TiXmlElement* lightElement = rootHandle.FirstChild("light").ToElement(); do { XmlHelper::pushAttributeVertexToVector(lightElement, lightPos); lightElement->QueryFloatAttribute("r", &lightColor.x); lightElement->QueryFloatAttribute("g", &lightColor.y); lightElement->QueryFloatAttribute("b", &lightColor.z); lightElement->QueryFloatAttribute("distance", &distance); lightElement->QueryFloatAttribute("energy", &energy); scene->lights.emplace_back(); Light &light = scene->lights.back(); light.position.set(lightPos.x, lightPos.y, lightPos.z); light.color.set(lightColor.x, lightColor.y, lightColor.z); light.distance = distance; light.energy = energy; } while ((lightElement = lightElement->NextSiblingElement("light")) != nullptr); } void MapLoader::extractDoor() { TiXmlElement *endElement = rootHandle.FirstChild("end").ToElement(); if (endElement) { VisualEntity door; XmlHelper::extractPosition(endElement, door.position); XmlHelper::extractRotation(endElement, door.rotation); door.texture = TextureLoader::getTexture("Door.png"); door.mesh = MeshLoader::getMesh("Door.obj"); scene->end = door; } else { throw std::runtime_error("No end position defined."); } } void MapLoader::extractWalls() { TiXmlElement *textureElement = rootHandle.FirstChild("texture").ToElement(); string texturePath("none"); string surfaceType("none"); if (textureElement) { do { textureElement->QueryStringAttribute("source", &texturePath); textureElement->QueryStringAttribute("type", &surfaceType); TiXmlElement *wallBoxElement = textureElement->FirstChildElement("wall"); if (wallBoxElement) { do { scene->walls.emplace_back(); PhysicsEntity &wall = scene->walls.back(); XmlHelper::extractPosition(wallBoxElement, wall.position); XmlHelper::extractRotation(wallBoxElement, wall.rotation); XmlHelper::extractScale(wallBoxElement, wall.scale); wall.texture = TextureLoader::getTexture(texturePath); wall.texture.xTiling = 0.5f; wall.texture.yTiling = 0.5f; wall.mesh = MeshLoader::getPortalBox(wall); wall.physBody = BoxCollider::generateCage(wall); } while ((wallBoxElement = wallBoxElement->NextSiblingElement("wall")) != nullptr); } texturePath = "none"; } while ((textureElement = textureElement->NextSiblingElement("texture")) != nullptr); } } void MapLoader::extractTriggers() { TiXmlElement *triggerElement = rootHandle.FirstChild("trigger").ToElement(); string triggerType("none"); if (triggerElement) { do { TiXmlElement *triggerTypeElement; scene->triggers.emplace_back(); Trigger &trigger = scene->triggers.back(); if (triggerElement) { triggerElement->QueryStringAttribute("type", &trigger.type); } if (triggerType == "none") { throw std::runtime_error("Trigger must define a type attribute."); } XmlHelper::extractPosition(triggerElement, trigger.position); XmlHelper::extractScale(triggerElement, trigger.scale); } while ((triggerElement = triggerElement->NextSiblingElement()) != nullptr); } } void MapLoader::extractModels() { Vector3f modelPos; string texture("none"); string mesh("none"); TiXmlElement *modelElement = rootHandle.FirstChild("model").ToElement(); if (modelElement){ do { modelElement->QueryStringAttribute("texture", &texture); modelElement->QueryStringAttribute("mesh", &mesh); XmlHelper::pushAttributeVertexToVector(modelElement, modelPos); scene->models.emplace_back(); VisualEntity &model = scene->models.back(); XmlHelper::extractPosition(modelElement, model.position); XmlHelper::extractRotation(modelElement, model.rotation); model.texture = TextureLoader::getTexture(texture); model.mesh = MeshLoader::getMesh(mesh); } while ((modelElement = modelElement->NextSiblingElement("model")) != nullptr); } } void MapLoader::extractButtons() { TiXmlElement *textureElement = rootHandle.FirstChild("texture").ToElement(); string texturePath("none"); string surfaceType("none"); Vector2f position; Vector2f size; if (textureElement) { do { textureElement->QueryStringAttribute("source", &texturePath); textureElement->QueryStringAttribute("type", &surfaceType); TiXmlElement *buttonElement = textureElement->FirstChildElement("GUIbutton"); if (buttonElement) { do { scene->buttons.emplace_back(); GUIButton &button = scene->buttons.back(); buttonElement->QueryFloatAttribute("x", &position.x); buttonElement->QueryFloatAttribute("y", &position.y); buttonElement->QueryFloatAttribute("w", &size.x); buttonElement->QueryFloatAttribute("h", &size.y); button.texture = TextureLoader::getTexture(texturePath); button.texture.xTiling = 0.5f; button.texture.yTiling = 0.5f; } while ((buttonElement = buttonElement->NextSiblingElement("GUIbutton")) != nullptr); } texturePath = "none"; } while ((textureElement = textureElement->NextSiblingElement("texture")) != nullptr); } } } /* namespace glPortal */
/** createResolutionData Create Android resolution file as follow imported resolution file */ int CreateResolutionData(RESOLUTION* resolutionResult, int index, TiXmlElement* pSubElement, char* directory) { /** Get node */ TiXmlHandle hRoot(0); TiXmlElement* pElement = pSubElement; TiXmlAttribute* pAttribute = NULL; /** Set current dept node to root node */ hRoot = TiXmlHandle(pElement); /** Check has child root */ pElement = hRoot.FirstChildElement().Element(); /** Set xml properties and root node for save file */ TiXmlDocument docArray[RESOLUTION_TYPE_COUNT]; TiXmlDeclaration* dec[RESOLUTION_TYPE_COUNT] = { ENCODING, ENCODING, ENCODING, ENCODING }; for (int i = 0; i < RESOLUTION_TYPE_COUNT; i++) { docArray[i].LinkEndChild(dec[i]); } /** Add root node */ TiXmlElement* pRoot[RESOLUTION_TYPE_COUNT] = { FIRST_NODE, FIRST_NODE, FIRST_NODE, FIRST_NODE }; for (int i = 0; i < RESOLUTION_TYPE_COUNT; i++) { docArray[i].LinkEndChild(pRoot[i]); } /** Add child node */ TiXmlElement* pElementArray[RESOLUTION_TYPE_COUNT]; /** If has child */ if (pElement) { char* pszNode = NULL; /** For save node */ char* pszAttributeValue = NULL; /** For save attribute's name (key) */ char* pszAttributeName = NULL; /** for save attribute's name (value) */ /** Repeat if has child node */ while (pElement) { /** Get node */ pszNode = (char*)pElement->Value(); /** Get attribute */ pAttribute = pElement->FirstAttribute(); /** If has attribute */ while (pAttribute) { pszAttributeValue = (char*)pAttribute->Name(); pszAttributeName = (char*)pAttribute->Value(); pAttribute = pAttribute->Next(); } /** Get resoultion unit info */ char* pszText = (char*)pElement->GetText(); /** Calculete resolution size */ struct RESOLUTION result; result = ConvertResolution(pszAttributeName, strtod(pszText, NULL), RESOLUTION_HDPI); //It's HDPI type unconditionally in prototype resolutionResult[index++] = result; double resolution_value[RESOLUTION_TYPE_COUNT] = { result.ldpi, result.mdpi, result.hdpi, result.xhdpi }; char temp[100]; for (int i = 0; i < RESOLUTION_TYPE_COUNT; i++) { /** For create new resolution file */ sprintf_s(temp, sizeof(temp), "%.2lfdp", resolution_value[i]); pElementArray[i] = new TiXmlElement("dimen"); pElementArray[i]->LinkEndChild(new TiXmlText(temp)); pRoot[i]->LinkEndChild(pElementArray[i]); pElementArray[i]->SetAttribute("name", pszAttributeName); } /** Call self recursively for search child node of current node */ CreateResolutionData(resolutionResult, index, pElement, NULL); pElement = pElement->NextSiblingElement(); } } /** Save file */ if (directory != NULL) { char savepath[RESOLUTION_TYPE_COUNT][100] = { "_ldpi.xml", "_mdpi.xml", "_hdpi.xml", "_xhdpi.xml" }; for (int i = 0; i < RESOLUTION_TYPE_COUNT; i++) { char filepath[100] = ""; strncpy_s(filepath, directory, sizeof(filepath)); strcat_s(filepath, sizeof(filepath), savepath[i]); docArray[i].SaveFile(filepath); } AfxMessageBox(_T("Save successfully!")); } return index; }
std::vector<itk::SmartPointer<BaseData> > ConnectomicsNetworkReader::Read() { std::vector<itk::SmartPointer<mitk::BaseData> > result; std::string location = GetInputLocation(); std::string ext = itksys::SystemTools::GetFilenameLastExtension(location); ext = itksys::SystemTools::LowerCase(ext); if ( location == "") { MITK_ERROR << "No file name specified."; } else if (ext == ".cnf") { try { mitk::ConnectomicsNetwork::Pointer outputNetwork = mitk::ConnectomicsNetwork::New(); TiXmlDocument doc( location ); bool loadOkay = doc.LoadFile(); if(!loadOkay) { mitkThrow() << "Could not open file " << location << " for reading."; } TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem = hDoc.FirstChildElement().Element(); // save this for later hRoot = TiXmlHandle(pElem); pElem = hRoot.FirstChildElement(mitk::ConnectomicsNetworkDefinitions::XML_GEOMETRY).Element(); // read geometry mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New(); // read origin mitk::Point3D origin; double temp = 0; pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_ORIGIN_X, &temp); origin[0] = temp; pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_ORIGIN_Y, &temp); origin[1] = temp; pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_ORIGIN_Z, &temp); origin[2] = temp; geometry->SetOrigin(origin); // read spacing ScalarType spacing[3]; pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_SPACING_X, &temp); spacing[0] = temp; pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_SPACING_Y, &temp); spacing[1] = temp; pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_SPACING_Z, &temp); spacing[2] = temp; geometry->SetSpacing(spacing); // read transform vtkMatrix4x4* m = vtkMatrix4x4::New(); pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_XX, &temp); m->SetElement(0,0,temp); pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_XY, &temp); m->SetElement(1,0,temp); pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_XZ, &temp); m->SetElement(2,0,temp); pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_YX, &temp); m->SetElement(0,1,temp); pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_YY, &temp); m->SetElement(1,1,temp); pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_YZ, &temp); m->SetElement(2,1,temp); pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_ZX, &temp); m->SetElement(0,2,temp); pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_ZY, &temp); m->SetElement(1,2,temp); pElem->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_MATRIX_ZZ, &temp); m->SetElement(2,2,temp); m->SetElement(0,3,origin[0]); m->SetElement(1,3,origin[1]); m->SetElement(2,3,origin[2]); m->SetElement(3,3,1); geometry->SetIndexToWorldTransformByVtkMatrix(m); geometry->SetImageGeometry(true); outputNetwork->SetGeometry(geometry); // read network std::map< int, mitk::ConnectomicsNetwork::VertexDescriptorType > idToVertexMap; // read vertices pElem = hRoot.FirstChildElement(mitk::ConnectomicsNetworkDefinitions::XML_VERTICES).Element(); { // walk through the vertices TiXmlElement* vertexElement = pElem->FirstChildElement(); for( ; vertexElement; vertexElement=vertexElement->NextSiblingElement()) { std::vector< float > pos; std::string label; int vertexID(0); vertexElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_X, &temp); pos.push_back(temp); vertexElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_Y, &temp); pos.push_back(temp); vertexElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_Z, &temp); pos.push_back(temp); vertexElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_ID, &vertexID); vertexElement->QueryStringAttribute(mitk::ConnectomicsNetworkDefinitions::XML_VERTEX_LABEL, &label); mitk::ConnectomicsNetwork::VertexDescriptorType newVertex = outputNetwork->AddVertex( vertexID ); outputNetwork->SetLabel( newVertex, label ); outputNetwork->SetCoordinates( newVertex, pos ); if ( idToVertexMap.count( vertexID ) > 0 ) { MITK_ERROR << "Aborting network creation, duplicate vertex ID in file."; return result; } idToVertexMap.insert( std::pair< int, mitk::ConnectomicsNetwork::VertexDescriptorType >( vertexID, newVertex) ); } } // read edges pElem = hRoot.FirstChildElement(mitk::ConnectomicsNetworkDefinitions::XML_EDGES).Element(); { // walk through the edges TiXmlElement* edgeElement = pElem->FirstChildElement(); for( ; edgeElement; edgeElement=edgeElement->NextSiblingElement()) { int edgeID(0), edgeSourceID(0), edgeTargetID(0), edgeWeight(0); edgeElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_EDGE_ID, &edgeID); edgeElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_EDGE_SOURCE_ID, &edgeSourceID); edgeElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_EDGE_TARGET_ID, &edgeTargetID); edgeElement->Attribute(mitk::ConnectomicsNetworkDefinitions::XML_EDGE_WEIGHT_ID, &edgeWeight); mitk::ConnectomicsNetwork::VertexDescriptorType source = idToVertexMap.find( edgeSourceID )->second; mitk::ConnectomicsNetwork::VertexDescriptorType target = idToVertexMap.find( edgeTargetID )->second; outputNetwork->AddEdge( source, target, edgeSourceID, edgeTargetID, edgeWeight); } } outputNetwork->UpdateBounds(); result.push_back(outputNetwork.GetPointer()); MITK_INFO << "Network read"; } catch (mitk::Exception e) { MITK_ERROR << e.GetDescription(); } catch(...) { MITK_ERROR << "Unknown error occured while trying to read file."; } } return result; }
void InformationStorage::loadAll(string file) { //Clear out the object types first terrainTypes.clear(); buildingTypes.clear(); unitTypes.clear(); TiXmlDocument doc( file.c_str()); if(doc.LoadFile()) { TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem = hDoc.FirstChildElement().Element(); hRoot=TiXmlHandle(pElem); //--------------------------------Load in Units---------------------- TiXmlNode* pUnitNode=hRoot.FirstChild( "Units" ).FirstChild().ToNode(); TiXmlNode* pUnitInfoNode; //For loop will cycle through each unit within the Units tag for( pUnitNode; pUnitNode; pUnitNode=pUnitNode->NextSiblingElement()) { //Need to iterate through the data of a unit; can make a pointer to the first child of pUnitNode for ID, get NextSiblingElement for other elements, use //query attributes for combat stats. UnitInfo u = UnitInfo(); u.load(pUnitNode); unitTypes[u.id] = u; } //----------------------Load in Terrain------------------------------- TiXmlNode* pTerrainNode=hRoot.FirstChild( "Terrain" ).FirstChild().ToNode(); TiXmlNode* pTerrainInfoNode; //For loop will cycle through each unit within the Units tag for( pTerrainNode; pTerrainNode; pTerrainNode=pTerrainNode->NextSiblingElement()) { //Need to iterate through the data of a unit; can make a pointer to the first child of pUnitNode for ID, get NextSiblingElement for other elements, use //query attributes for combat stats. TerrainInfo t = TerrainInfo(); t.load(pTerrainNode); terrainTypes[t.id] = t; } //---------------------------------Load in Buildings-------------------------------------- TiXmlNode* pBuildingNode=hRoot.FirstChild( "Buildings" ).FirstChild().ToNode(); //TiXmlNode* pBuildingInfoNode; //TiXmlNode* pProductionIDNode; //For loop will cycle through each unit within the Units tag for( pBuildingNode; pBuildingNode; pBuildingNode=pBuildingNode->NextSiblingElement()) { //Need to iterate through the data of a unit; can make a pointer to the first child of pUnitNode for ID, get NextSiblingElement for other elements, use //query attributes for combat stats. BuildingInfo b = BuildingInfo(); b.load(pBuildingNode); buildingTypes[b.id] = b; } //-------------------------------Load in Commander Cards-------------------------------- TiXmlNode* pCardNode = hRoot.FirstChild( "Cards" ).FirstChild().ToNode(); for( pCardNode; pCardNode; pCardNode=pCardNode->NextSiblingElement()) { CardInfo c = CardInfo(); c.load(pCardNode); cardTypes[c.id] = c; } } else { //std::cout << "\nFailed to load the units\n"; } DeveloperConsole::write("Buildings Loaded: "); DeveloperConsole::writeLine(buildingTypes.size()); DeveloperConsole::write("Units Loaded: "); DeveloperConsole::writeLine(unitTypes.size()); DeveloperConsole::write("Terrain Loaded: "); DeveloperConsole::writeLine(terrainTypes.size()); }
bool sCentre::LoadCentreXML(TiXmlHandle hBrothel) { //no need to init this, we just created it TiXmlElement* pBrothel = hBrothel.ToElement(); if (pBrothel == 0) { return false; } if (pBrothel->Attribute("Name")) { m_Name = pBrothel->Attribute("Name"); } int tempInt = 0; std::string message = "Loading centre: "; message += m_Name; g_LogFile.write(message); pBrothel->QueryIntAttribute("id", &m_id); pBrothel->QueryIntAttribute("NumRooms", &tempInt); m_NumRooms = tempInt; tempInt = 0; pBrothel->QueryIntAttribute("MaxNumRooms", &tempInt); m_MaxNumRooms = tempInt; tempInt = 0; if (m_MaxNumRooms < 200) m_MaxNumRooms = 200; else if (m_MaxNumRooms > 600) m_MaxNumRooms = 600; pBrothel->QueryIntAttribute("Filthiness", &m_Filthiness); pBrothel->QueryIntAttribute("SecurityLevel", &m_SecurityLevel); // load variables for sex restrictions pBrothel->QueryValueAttribute<bool>("RestrictAnal", &m_RestrictAnal); pBrothel->QueryValueAttribute<bool>("RestrictBDSM", &m_RestrictBDSM); pBrothel->QueryValueAttribute<bool>("RestrictBeast", &m_RestrictBeast); pBrothel->QueryValueAttribute<bool>("RestrictFoot", &m_RestrictFoot); pBrothel->QueryValueAttribute<bool>("RestrictGroup", &m_RestrictGroup); pBrothel->QueryValueAttribute<bool>("RestrictHand", &m_RestrictHand); pBrothel->QueryValueAttribute<bool>("RestrictLesbian", &m_RestrictLesbian); pBrothel->QueryValueAttribute<bool>("RestrictNormal", &m_RestrictNormal); pBrothel->QueryValueAttribute<bool>("RestrictOral", &m_RestrictOral); pBrothel->QueryValueAttribute<bool>("RestrictStrip", &m_RestrictStrip); pBrothel->QueryValueAttribute<bool>("RestrictTitty", &m_RestrictTitty); pBrothel->QueryValueAttribute<unsigned short>("AdvertisingBudget", &m_AdvertisingBudget); pBrothel->QueryIntAttribute("AntiPregPotions", &m_AntiPregPotions); pBrothel->QueryIntAttribute("AntiPregUsed", &m_AntiPregUsed); pBrothel->QueryValueAttribute<bool>("KeepPotionsStocked", &m_KeepPotionsStocked); // Load girls m_NumGirls = 0; TiXmlElement* pGirls = pBrothel->FirstChildElement("Girls"); if (pGirls) { for (TiXmlElement* pGirl = pGirls->FirstChildElement("Girl"); pGirl != 0; pGirl = pGirl->NextSiblingElement("Girl"))// load each girl and add her { sGirl* girl = new sGirl(); bool success = girl->LoadGirlXML(TiXmlHandle(pGirl)); if (success == true) { girl->m_InCentre = true; AddGirl(girl); } else { delete girl; continue; } } } //commented out before the conversion to XML //building.load(ifs); return true; }
Mesh* Charger_Collada(std::string __nom_du_fichier){ Mesh *objet_charge = NULL; std::cout <<"Chargement de mesh, fichier: "<< __nom_du_fichier << ".xml\n"; // Chargement du fichier avec TinyXML string name=__nom_du_fichier; TiXmlDocument fileXML(name.c_str()); if (!fileXML.LoadFile()){ std::cerr << "Le fichier "<<__nom_du_fichier<<" n'existe pas"<<std::endl; return NULL; } // Elements de TinyXML TiXmlHandle docHandle( &fileXML ); TiXmlElement* elem; TiXmlElement* elem2; TiXmlElement* elem3; // Chargement de la racine TiXmlHandle root=TiXmlHandle(docHandle.FirstChildElement().Element()); // Parcours de <COLLADA> <library_geometries> elem=root.FirstChild("library_geometries").Element(); if (!elem) { std::cerr << "Probleme de lecture"<<std::endl; return NULL; } root=TiXmlHandle(elem); Debug::_trace(7,"<library_geometries>"); // Parcours de <geometry> elem=root.FirstChild("geometry").Element(); if (!elem) { std::cerr << "Probleme de lecture"<<std::endl; return NULL; } Debug::_trace(7,"<geometry>"); root=TiXmlHandle(elem); //std::cout << "Geometry name : " <<elem->Attribute("name")<<" id : "<< elem->Attribute("id")<< std::endl; // Parcours de <mesh> // Un seul mesh sera chargé ! elem2=root.FirstChild("mesh").Element(); if (!elem2) { std::cerr << "Probleme de lecture"<<std::endl; return NULL; } Debug::_trace(7,"<mesh>"); root=TiXmlHandle(elem2); //------------------------------------- // ----- Chargement des vertex //------------------------------------- // <source> <float_array> elem3=root.FirstChild("source").FirstChild("float_array").Element(); Debug::_trace(7,"<source> <float_array>"); // Definition du mesh objet_charge = new Mesh(); objet_charge->_nb_vertex = (atoi(elem3->Attribute("count")) / 3 ); const char *parcour = elem3->GetText(); objet_charge->_tab_vertex = new Vertex[objet_charge->_nb_vertex]; //Chargement des vertex for (int i = 0; i < objet_charge->_nb_vertex; i ++) { //printf("%f \n",atof(parcour)); objet_charge->_tab_vertex[i]._position[0] = atof(parcour); while (*parcour != ' '){ parcour ++; } parcour ++; objet_charge->_tab_vertex[i]._position[1] = atof(parcour); while (*parcour != ' '){ parcour ++; } parcour ++; objet_charge->_tab_vertex[i]._position[2] = atof(parcour); while (*parcour != ' '){ parcour ++; } parcour ++; } Debug::_trace(7,"</float_array> </source> "); // </source> </float_array> //------------------------------------- // ----- Chargement des faces //------------------------------------- // <triangles> <p> elem3=root.FirstChild("triangles").Element(); Debug::_trace(7,"<triangles> "); objet_charge->_nb_triangles = atoi(elem3->Attribute("count")); objet_charge->_tab_triangles = new Triangles[objet_charge->_nb_triangles]; bool normal = false; bool coord = false; bool color = false; int vertex_offset; int coord_offset; int color_offset; int total_offset; // On recupere les infos des offsets root=TiXmlHandle(elem3); // <geometry> elem3=root.FirstChild("input").Element(); if (!elem3) return 0; total_offset = 0; for( ; elem3 ; elem3=elem3->NextSiblingElement("input")){ total_offset++; std::string att = elem3->Attribute("semantic"); if ( att == "VERTEX"){ vertex_offset = atoi(elem3->Attribute("offset")); std::cout<<"Vertex\n"; } att = elem3->Attribute("semantic"); if ( att == "NORMAL"){ normal = true; std::cout<<"Normal\n"; } att = elem3->Attribute("semantic"); if ( att == "TEXCOORD"){ coord = true; coord_offset = atoi(elem3->Attribute("offset")); std::cout<<"Text\n"; } att = elem3->Attribute("semantic"); if ( att == "COLOR"){ color = true; color_offset = atoi(elem3->Attribute("offset")); std::cout<<"Color\n"; } } elem3=root.FirstChild("p").Element(); Debug::_trace(7,"<p> "); parcour = elem3->GetText(); for (int i = 0; i < (objet_charge->_nb_triangles) * total_offset -1 ; i++) { std::cout << "boucle i " << i << std::endl; objet_charge->_tab_triangles[i]._vertexIndices[0] = atoi(&parcour[vertex_offset]); // trouve le prochain chiffre while (*parcour != ' '){ parcour ++; } // ignore la normale if(normal){ parcour ++; while (*parcour != ' '){ parcour ++; } } // textcoord if(coord){ parcour ++; while (*parcour != ' '){ parcour ++; } } parcour ++; objet_charge->_tab_triangles[i]._vertexIndices[1] = atoi(&parcour[vertex_offset]); // trouve le prochain chiffre while (*parcour != ' '){ parcour ++; } // ignore la normale if(normal){ parcour ++; while (*parcour != ' '){ parcour ++; } } // textcoord if(coord){ parcour ++; while (*parcour != ' '){ parcour ++; } } parcour ++; objet_charge->_tab_triangles[i]._vertexIndices[2] = atoi(&parcour[vertex_offset]); // trouve le prochain chiffre while (*parcour != ' '){ parcour ++; } // ignore la normale if(normal){ parcour ++; while (*parcour != ' '){ parcour ++; } } // textcoord if(coord){ parcour ++; while (*parcour != ' '){ parcour ++; } } parcour ++; } Debug::_trace(7,"</triangles> </p> "); // --------- Debug::_trace(7,"</mesh>"); Debug::_trace(7,"</geometry>"); Debug::_trace(7,"</library_geometries> </COLLADA> "); std::cout <<"Loaded: "<< name << ".xml" << std::endl; return objet_charge; }
void Manager::loadParam(const char* pFilename){ // Open parameter file TiXmlDocument doc(pFilename); if (!doc.LoadFile()) return; // Define handles and elements TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); // Get root pElem=hDoc.FirstChildElement("LeggedStateEstimator").Element(); if (pElem){ hRoot=TiXmlHandle(pElem); pElem=hRoot.FirstChild("MeasurementSettings").FirstChild("Imu").FirstChild("AccelerometerStd").Element(); if (pElem){ pElem->QueryDoubleAttribute("x", &Rf_(0,0)); pElem->QueryDoubleAttribute("y", &Rf_(1,1)); pElem->QueryDoubleAttribute("z", &Rf_(2,2)); } pElem=hRoot.FirstChild("MeasurementSettings").FirstChild("Imu").FirstChild("GyroscopeStd").Element(); if (pElem){ pElem->QueryDoubleAttribute("x", &Rw_(0,0)); pElem->QueryDoubleAttribute("y", &Rw_(1,1)); pElem->QueryDoubleAttribute("z", &Rw_(2,2)); } pElem=hRoot.FirstChild("MeasurementSettings").FirstChild("Imu").FirstChild("TransOffset").Element(); if (pElem){ pElem->QueryDoubleAttribute("x", &B_r_BI_(0)); pElem->QueryDoubleAttribute("y", &B_r_BI_(1)); pElem->QueryDoubleAttribute("z", &B_r_BI_(2)); } pElem=hRoot.FirstChild("MeasurementSettings").FirstChild("Imu").FirstChild("RotOffset").Element(); if (pElem){ pElem->QueryDoubleAttribute("x", &q_IB_(0)); pElem->QueryDoubleAttribute("y", &q_IB_(1)); pElem->QueryDoubleAttribute("z", &q_IB_(2)); pElem->QueryDoubleAttribute("w", &q_IB_(3)); } pElem=hRoot.FirstChild("MeasurementSettings").FirstChild("Kinematic").FirstChild("EncoderStd").Element(); for(int i=0;i<LSE_DOF_LEG && pElem;i++){ pElem->QueryDoubleAttribute("a", &Ra_(i,i)); pElem = pElem->NextSiblingElement("EncoderStd"); } pElem=hRoot.FirstChild("MeasurementSettings").FirstChild("Kinematic").FirstChild("ContactStd").Element(); if (pElem){ pElem->QueryDoubleAttribute("x", &Rs_(0,0)); pElem->QueryDoubleAttribute("y", &Rs_(1,1)); pElem->QueryDoubleAttribute("z", &Rs_(2,2)); } pElem=hRoot.FirstChild("MeasurementSettings").FirstChild("Kinematic").FirstChild("TransOffset").Element(); if (pElem){ pElem->QueryDoubleAttribute("x", &B_r_BK_(0)); pElem->QueryDoubleAttribute("y", &B_r_BK_(1)); pElem->QueryDoubleAttribute("z", &B_r_BK_(2)); } pElem=hRoot.FirstChild("MeasurementSettings").FirstChild("Kinematic").FirstChild("RotOffset").Element(); if (pElem){ pElem->QueryDoubleAttribute("x", &q_KB_(0)); pElem->QueryDoubleAttribute("y", &q_KB_(1)); pElem->QueryDoubleAttribute("z", &q_KB_(2)); pElem->QueryDoubleAttribute("w", &q_KB_(3)); } } Rf_ = Rf_*Rf_; Rw_ = Rw_*Rw_; Rs_ = Rs_*Rs_; Ra_ = Ra_*Ra_; }
void FiberBundleReader::GenerateOutputInformation() { m_OutputCache = OutputType::New(); std::string ext = itksys::SystemTools::GetFilenameLastExtension(m_FileName); ext = itksys::SystemTools::LowerCase(ext); if ( m_FileName == "") { } else if (ext == ".fib") { try { TiXmlDocument doc( m_FileName ); doc.LoadFile(); TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem = hDoc.FirstChildElement().Element(); // save this for later hRoot = TiXmlHandle(pElem); pElem = hRoot.FirstChildElement(FiberBundleReader::XML_GEOMETRY).Element(); // read geometry mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New(); // read origin mitk::Point3D origin; double temp = 0; pElem->Attribute(FiberBundleReader::XML_ORIGIN_X, &temp); origin[0] = temp; pElem->Attribute(FiberBundleReader::XML_ORIGIN_Y, &temp); origin[1] = temp; pElem->Attribute(FiberBundleReader::XML_ORIGIN_Z, &temp); origin[2] = temp; geometry->SetOrigin(origin); // read spacing float spacing[3]; pElem->Attribute(FiberBundleReader::XML_SPACING_X, &temp); spacing[0] = temp; pElem->Attribute(FiberBundleReader::XML_SPACING_Y, &temp); spacing[1] = temp; pElem->Attribute(FiberBundleReader::XML_SPACING_Z, &temp); spacing[2] = temp; geometry->SetSpacing(spacing); // read transform vtkMatrix4x4* m = vtkMatrix4x4::New(); pElem->Attribute(FiberBundleReader::XML_MATRIX_XX, &temp); m->SetElement(0,0,temp); pElem->Attribute(FiberBundleReader::XML_MATRIX_XY, &temp); m->SetElement(1,0,temp); pElem->Attribute(FiberBundleReader::XML_MATRIX_XZ, &temp); m->SetElement(2,0,temp); pElem->Attribute(FiberBundleReader::XML_MATRIX_YX, &temp); m->SetElement(0,1,temp); pElem->Attribute(FiberBundleReader::XML_MATRIX_YY, &temp); m->SetElement(1,1,temp); pElem->Attribute(FiberBundleReader::XML_MATRIX_YZ, &temp); m->SetElement(2,1,temp); pElem->Attribute(FiberBundleReader::XML_MATRIX_ZX, &temp); m->SetElement(0,2,temp); pElem->Attribute(FiberBundleReader::XML_MATRIX_ZY, &temp); m->SetElement(1,2,temp); pElem->Attribute(FiberBundleReader::XML_MATRIX_ZZ, &temp); m->SetElement(2,2,temp); m->SetElement(0,3,origin[0]); m->SetElement(1,3,origin[1]); m->SetElement(2,3,origin[2]); m->SetElement(3,3,1); geometry->SetIndexToWorldTransformByVtkMatrix(m); // read bounds float bounds[] = {0, 0, 0, 0, 0, 0}; pElem->Attribute(FiberBundleReader::XML_SIZE_X, &temp); bounds[1] = temp; pElem->Attribute(FiberBundleReader::XML_SIZE_Y, &temp); bounds[3] = temp; pElem->Attribute(FiberBundleReader::XML_SIZE_Z, &temp); bounds[5] = temp; geometry->SetFloatBounds(bounds); // read bounds float bounds2[] = {0, 0, 0}; bounds2[0] = bounds[1]; bounds2[1] = bounds[3]; bounds2[2] = bounds[5]; m_OutputCache->SetBounds(bounds2); geometry->SetImageGeometry(true); m_OutputCache->SetGeometry(geometry); // generate tract container ContainerType::Pointer tractContainer = ContainerType::New(); int fiberID = 0; pElem = hRoot.FirstChildElement(FiberBundleReader::XML_FIBER_BUNDLE).FirstChild().Element(); for( pElem; pElem; pElem=pElem->NextSiblingElement()) { TiXmlElement* pElem2 = pElem->FirstChildElement(); ContainerTractType::Pointer tract = ContainerTractType::New(); for( pElem2; pElem2; pElem2=pElem2->NextSiblingElement()) { ContainerPointType point; pElem2->Attribute(FiberBundleReader::XML_POS_X, &temp); point[0] = temp; pElem2->Attribute(FiberBundleReader::XML_POS_Y, &temp); point[1] = temp; pElem2->Attribute(FiberBundleReader::XML_POS_Z, &temp); point[2] = temp; tract->InsertElement(tract->Size(), point); } pElem->Attribute(FiberBundleReader::XML_ID, &fiberID); tractContainer->CreateIndex(fiberID); tractContainer->SetElement(fiberID, tract); } m_OutputCache->addTractContainer(tractContainer); m_OutputCache->initFiberGroup(); MITK_INFO << "Fiber bundle read"; } catch(...) { MITK_INFO << "Could not read file "; } } else if (ext == ".vfib") { // generate tract container ContainerType::Pointer tractContainer = ContainerType::New(); mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New(); ///We create a Generic Reader to test de .vtk/ vtkDataReader *chooser=vtkDataReader::New(); chooser->SetFileName(m_FileName.c_str() ); if( chooser->IsFilePolyData()) { vtkPolyDataReader *reader = vtkPolyDataReader::New(); reader->SetFileName( m_FileName.c_str() ); reader->Update(); if ( reader->GetOutput() != NULL ) { vtkPolyData* output = reader->GetOutput(); output->ComputeBounds(); double bounds[3]; output->GetBounds(bounds); double center[3]; output->GetCenter(center); Point3D origin; origin.SetElement(0, -center[0]); origin.SetElement(1, -center[1]); origin.SetElement(2, -center[2]); MITK_INFO << origin; mitk::Surface::Pointer surf = mitk::Surface::New(); surf->SetVtkPolyData(output); mitk::Geometry3D* geom = surf->GetGeometry(); //geom->SetOrigin(origin); geom->SetImageGeometry(true); m_OutputCache->SetBounds(bounds); m_OutputCache->SetGeometry(geom); vtkCellArray* cells = output->GetLines(); cells->InitTraversal(); for (int i=0; i<output->GetNumberOfCells(); i++) { ContainerTractType::Pointer tract = ContainerTractType::New(); vtkCell* cell = output->GetCell(i); int p = cell->GetNumberOfPoints(); vtkPoints* points = cell->GetPoints(); for (int j=0; j<p; j++) { double p[3]; points->GetPoint(j, p); ContainerPointType point; point[0] = p[0]; point[1] = p[1]; point[2] = p[2]; tract->InsertElement(tract->Size(), point); } tractContainer->InsertElement(i, tract); } } reader->Delete(); } chooser->Delete(); m_OutputCache->addTractContainer(tractContainer); m_OutputCache->initFiberGroup(); MITK_INFO << "Fiber bundle read"; } }
int CBuddyManager::Load() { DWORD dwBuddyID = 0; SetCurrentDirectory(USER_SAVE_PATH); TiXmlDocument doc("Buddies.xml"); if (!doc.LoadFile()) { m_log.AddLogInfo(GS_LOG_INFO,"Error loading buddies.xml file or file didn't exsist."); return 1; } TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem=hDoc.FirstChildElement().Element(); // should always have a valid root but handle gracefully if it does if (!pElem) return 1; // const char *szP = pElem->Value(); //Should return BuddiesRoot // save this for later hRoot=TiXmlHandle(pElem); //Default values TiXmlElement* pElement; char szVersion[50]; pElement=hRoot.FirstChild("Versions").ToElement(); pElement = pElement->FirstChild()->ToElement(); if(pElement!=NULL) { ReadCfgStr2(pElement , "MainVersion",szVersion,sizeof(szVersion)); } TiXmlElement* pBuddy; pBuddy=hRoot.FirstChild("Buddies").ToElement(); if(pBuddy!=NULL) { if(pBuddy->FirstChild()!=NULL) { pBuddy = pBuddy->FirstChild()->ToElement(); while(pBuddy!=NULL) { if(pBuddy!=NULL) { BUDDY_INFO bi; ZeroMemory(&bi,sizeof(BUDDY_INFO)); TiXmlElement* pBud = pBuddy->FirstChild()->ToElement(); ReadCfgStr2(pBud , "Name",bi.szPlayerName,sizeof(bi.szPlayerName)); ReadCfgStr2(pBud , "Clan",bi.szClan,sizeof(bi.szClan)); ReadCfgStr2(pBud , "LastSeenServerName",bi.szLastSeenServerName,sizeof(bi.szLastSeenServerName)); ReadCfgStr2(pBud , "LastSeenIP",bi.szLastSeenIPaddress,sizeof(bi.szLastSeenIPaddress)); ReadCfgInt2(pBud , "MatchOnColorEncoded",(int&)bi.cMatchOnColorEncoded); ReadCfgInt2(pBud , "ExactMatch",(int&)bi.cMatchExact); ReadCfgInt2(pBud , "LastSeenGameIdx",(int&)bi.cGAMEINDEX); bi.dwID = dwBuddyID++; bi.sIndex = -1; //reset BuddyList.push_back(bi); } pBuddy = pBuddy->NextSiblingElement(); } }else { m_log.AddLogInfo(GS_LOG_ERROR,"No buddies found."); } }else { m_log.AddLogInfo(GS_LOG_ERROR,"Error loading buddy xml data."); } return 0; }
bool Brothel::LoadBrothelXML( TiXmlHandle hBrothel ) { //no need to init this, we just created it TiXmlElement* pBrothel = hBrothel.ToElement(); if( pBrothel == nullptr ) { return false; } if( pBrothel->Attribute( "Name" ) ) { m_Name = pBrothel->Attribute( "Name" ); } int tempInt = 0; std::string message = "Loading brothel: "; message += m_Name; g_LogFile.write( message ); // load variables for sex restrictions pBrothel->QueryValueAttribute<bool>( "RestrictAnal", &m_RestrictAnal ); pBrothel->QueryValueAttribute<bool>( "RestrictBDSM", &m_RestrictBDSM ); pBrothel->QueryValueAttribute<bool>( "RestrictBeast", &m_RestrictBeast ); pBrothel->QueryValueAttribute<bool>( "RestrictGroup", &m_RestrictGroup ); pBrothel->QueryValueAttribute<bool>( "RestrictNormal", &m_RestrictNormal ); pBrothel->QueryValueAttribute<bool>( "RestrictLesbian", &m_RestrictLesbian ); pBrothel->QueryValueAttribute<unsigned short>( "AdvertisingBudget", &m_AdvertisingBudget ); pBrothel->QueryIntAttribute( "Bar", &tempInt ); m_Bar = tempInt; tempInt = 0; pBrothel->QueryIntAttribute( "Fame", &tempInt ); m_Fame = tempInt; tempInt = 0; pBrothel->QueryIntAttribute( "GamblingHall", &tempInt ); m_GamblingHall = tempInt; tempInt = 0; pBrothel->QueryValueAttribute<unsigned short>( "Happiness", &m_Happiness ); pBrothel->QueryIntAttribute( "HasBarStaff", &tempInt ); m_HasBarStaff = tempInt; tempInt = 0; pBrothel->QueryIntAttribute( "id", &m_id ); pBrothel->QueryIntAttribute( "HasGambStaff", &tempInt ); m_HasGambStaff = tempInt; tempInt = 0; pBrothel->QueryIntAttribute( "NumRooms", &tempInt ); m_NumRooms = tempInt; tempInt = 0; pBrothel->QueryIntAttribute( "Filthiness", &m_Filthiness ); pBrothel->QueryIntAttribute( "SecurityLevel", &m_SecurityLevel ); m_Finance.loadGoldXML( hBrothel.FirstChild( "Gold" ) ); // Load girls m_NumGirls = 0; TiXmlElement* pGirls = pBrothel->FirstChildElement( "Girls" ); if( pGirls ) { for( TiXmlElement* pGirl = pGirls->FirstChildElement( "Girl" ); pGirl != nullptr; pGirl = pGirl->NextSiblingElement( "Girl" ) ) // load each girl and add her { Girl* girl = new Girl(); bool success = girl->LoadGirlXML( TiXmlHandle( pGirl ) ); if( success == true ) { AddGirl( girl ); } else { delete girl; continue; } } } //commented out before the conversion to XML //building.load(ifs); return true; }
bool xmlImport::importComps() { TiXmlDocument doc(xmlFile.c_str()); if(!doc.LoadFile()){ Logger::getLogger()->debug("Error: could not load components XML file"); return false; } TiXmlElement* pElem; TiXmlElement* pChild; TiXmlHandle hDoc(&doc); TiXmlHandle hRoot(0); DesignStore::Ptr ds = Game::getGame()->getDesignStore(); int count=0; // item count pElem = hDoc.FirstChildElement("components").Element(); if(!pElem) return false; hRoot = TiXmlHandle(pElem); for(pElem=hRoot.FirstChild("comp").Element(); pElem != NULL; pElem = pElem->NextSiblingElement()) { TiXmlElement* pCur = 0; std::string compName, compDescription, compTpcl, compIDName; std::map<uint32_t, std::string> propertylist; pChild = hRoot.Child("comp",count).Element(); //debug: cout << "count: " << count << endl; if(pChild) { //read and set the name of the component pCur = pChild->FirstChildElement("name"); if (pCur) { compName = pCur->GetText(); if (compName.empty()) return false; } else { return false; } //read and set the ID of the component pCur = pChild->FirstChildElement("ComponentIDName"); if (pCur) { compIDName = pCur->GetText(); if (compIDName.empty()) return false; } else { return false; } //read and set the description of the component pCur = pChild->FirstChildElement("description"); if (pCur) { compDescription = pCur->GetText(); if (compDescription.empty()) return false; } else { return false; } //read and set the tpclRequirementsFunction of the component pCur = pChild->FirstChildElement("tpclRequirementsFunction"); if (pCur) { compTpcl = pCur->GetText(); if (compTpcl.empty()) return false; } else { return false; } //read and set the tpclRequirementsFunction of the component pCur = pChild->FirstChildElement("propertylist"); if (pCur) { TiXmlElement* pElem; for(pElem=pCur->FirstChildElement(); pElem != NULL; pElem=pElem->NextSiblingElement()) { std::string pKey=pElem->Value(); std::string pText=pElem->GetText(); if (!pKey.empty() && !pText.empty()) { propertylist[ds->getPropertyByName(pKey)] = pText; } else { return false; } } } else { return false; } //do the component Component::Ptr comp( new Component() ); comp->addCategoryId(ds->getCategoryByName(compIDName)); comp->setName(compName); comp->setDescription(compDescription); comp->setTpclRequirementsFunction(compTpcl); comp->setPropertyList(propertylist); ds->addComponent(comp); } else { return false; } count++; } return true; }
int WindowParams::LoadParamsFromXML(char fileName[]) { TiXmlDocument doc(fileName); if (!doc.LoadFile()) return -1; TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem = hDoc.FirstChildElement().Element(); if (!pElem) return -1; hRoot = TiXmlHandle(pElem); pElem = hRoot.FirstChild("HOGParams").Element(); if (pElem) { pElem->QueryIntAttribute("cell_width", &m_DetectionParams.m_HOG_Params.m_cell.width); pElem->QueryIntAttribute("cell_height", &m_DetectionParams.m_HOG_Params.m_cell.height); pElem->QueryIntAttribute("block_width", &m_DetectionParams.m_HOG_Params.m_block.width); pElem->QueryIntAttribute("block_height", &m_DetectionParams.m_HOG_Params.m_block.height); pElem->QueryIntAttribute("total_bin", &m_DetectionParams.m_HOG_Params.m_inBin); pElem->QueryFloatAttribute("overlap", &m_DetectionParams.m_HOG_Params.m_fStepOverlap); } pElem = hRoot.FirstChild("SVMParams").Element(); if (pElem) { pElem->QueryFloatAttribute("confidence_score", &m_DetectionParams.m_SVM_Params.m_fConfidenceScore); } pElem = hRoot.FirstChild("GaussianParams").Element(); if (pElem) { pElem->QueryFloatAttribute("threshold", &m_DetectionParams.m_Gaussian_Params.m_fThreshold); } pElem = hRoot.FirstChild("HeadParams").Element(); if (pElem) { pElem->QueryIntAttribute("min_area", &m_DetectionParams.m_Head_Params.m_iMinHeadArea); pElem->QueryIntAttribute("max_area", &m_DetectionParams.m_Head_Params.m_iMaxHeadArea); pElem->QueryIntAttribute("relative_width_height", &m_DetectionParams.m_Head_Params.m_iRelative_Width_Height); pElem->QueryIntAttribute("relative_height_width", &m_DetectionParams.m_Head_Params.m_iRelative_Height_Width); pElem->QueryIntAttribute("max_width", &m_DetectionParams.m_Head_Params.m_iMaxWidth); pElem->QueryIntAttribute("min_width", &m_DetectionParams.m_Head_Params.m_iMinWidth); pElem->QueryIntAttribute("max_head_area_top", &m_DetectionParams.m_Head_Params.m_iMaxHeadAreaTop); pElem->QueryIntAttribute("min_head_area_bottom", &m_DetectionParams.m_Head_Params.m_iMinHeadAreaBottom); } const char* tmp; pElem = hRoot.FirstChild("ModelSVM").Element(); if (pElem) { tmp = pElem->GetText(); m_modelSVMPath = new char[strlen(tmp)]; strcpy(m_modelSVMPath,pElem->GetText()); } pElem = hRoot.FirstChild("ModelGauss").Element(); if (pElem) { tmp = pElem->GetText(); m_modelGaussPath = new char[strlen(tmp)]; strcpy( m_modelGaussPath, pElem->GetText()); } return 0; }
/**------------------------------------------------------------------------------- load actuator trajectory from XML file @brief @param actuators @param filename @return void ---------------------------------------------------------------------------------*/ void Trajectory::load(const std::vector<boost::shared_ptr<Actuator > >& actuators) { if (!mFilename.empty()) { TCHAR path[MAX_PATH+1]; GetCurrentDirectory(MAX_PATH, path); strcat_s(path, MAX_PATH, "\\resources\\"); strcat_s(path, MAX_PATH, mFilename.c_str()); TiXmlDocument doc(path); if (doc.LoadFile()) { TiXmlHandle hDoc(&doc); TiXmlElement* el = hDoc.FirstChildElement().Element(); if (el) { TiXmlHandle hRoot = TiXmlHandle(el); TiXmlHandle hJoint = hRoot.FirstChild("joint"); TiXmlElement* elemJoint = hJoint.Element(); for (elemJoint; elemJoint; elemJoint = elemJoint->NextSiblingElement()) { Actuator* actuator = NULL; BOOST_FOREACH(boost::shared_ptr<Actuator> a, actuators) { if (elemJoint->Attribute("name") == a->getJoint()->getName()) { actuator = a.get(); break; } } if (actuator) { TiXmlElement* elemItem = elemJoint->FirstChildElement(); for (elemItem; elemItem; elemItem = elemItem->NextSiblingElement()) { double time = 0; if (elemItem->Attribute("time")) { elemItem->QueryDoubleAttribute("time", &time); if (elemItem->Attribute("type")) { // controller type change std::string type = elemItem->Attribute("type"); boost::shared_ptr<TrajectoryQueue> q(new QueueElementType(*actuator, time, type)); addQueue(q); } if (elemItem->Attribute("setPoint")) { // set-point change double val = 0; elemItem->QueryDoubleAttribute("setPoint", &val); boost::shared_ptr<TrajectoryQueue> q(new QueueElementSP(*actuator, time, val)); addQueue(q); } if (elemItem->Attribute("force")) { int actor; elemItem->QueryIntAttribute("actor", &actor); std::string forceType = elemItem->Attribute("force_type"); NxVec3 val = NxOgre::NxFromString<NxVec3>(elemItem->Attribute("value")); boost::shared_ptr<TrajectoryQueue> q(new QueueElementForce(*actuator, time, val, forceType, actor)); addQueue(q); } } } } } } }
// This method generates an XML file describing the crash BOOL CErrorReportExporter::CreateCrashDescriptionXML(CErrorReportInfo& eri) { BOOL bStatus = FALSE; ERIFileItem fi; CString sFileName = eri.GetErrorReportDirName() + _T("\\crashrpt.xml"); CString sErrorMsg; strconv_t strconv; TiXmlDocument doc; FILE* f = NULL; CString sNum; CString sCrashRptVer; CString sOSIs64Bit; CString sExceptionType; fi.m_bMakeCopy = false; fi.m_sDesc = _T("±ÀÀ£³ÌÐòÊôÐÔ¼¯"); fi.m_sDestFile = _T("crashrpt.xml"); fi.m_sSrcFile = sFileName; fi.m_sErrorStatus = sErrorMsg; // Add this file to the list eri.AddFileItem(&fi); TiXmlNode* root = root = new TiXmlElement("CrashRpt"); doc.LinkEndChild(root); sCrashRptVer.Format(_T("%d"), CRASHRPT_VER); TiXmlHandle(root).ToElement()->SetAttribute("version", strconv.t2utf8(sCrashRptVer)); TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "" ); doc.InsertBeforeChild(root, *decl); AddElemToXML(_T("CrashGUID"), eri.GetCrashGUID(), root); AddElemToXML(_T("AppName"), eri.GetAppName(), root); AddElemToXML(_T("AppVersion"), eri.GetAppVersion(), root); AddElemToXML(_T("ImageName"), eri.GetImageName(), root); AddElemToXML(_T("OperatingSystem"), eri.GetOSName(), root); sOSIs64Bit.Format(_T("%d"), eri.IsOS64Bit()); AddElemToXML(_T("OSIs64Bit"), sOSIs64Bit, root); AddElemToXML(_T("GeoLocation"), eri.GetGeoLocation(), root); AddElemToXML(_T("SystemTimeUTC"), eri.GetSystemTimeUTC(), root); if(eri.GetExceptionAddress()!=0) { sNum.Format(_T("0x%I64x"), eri.GetExceptionAddress()); AddElemToXML(_T("ExceptionAddress"), sNum, root); AddElemToXML(_T("ExceptionModule"), eri.GetExceptionModule(), root); sNum.Format(_T("0x%I64x"), eri.GetExceptionModuleBase()); AddElemToXML(_T("ExceptionModuleBase"), sNum, root); AddElemToXML(_T("ExceptionModuleVersion"), eri.GetExceptionModuleVersion(), root); } sExceptionType.Format(_T("%d"), m_CrashInfo.m_nExceptionType); AddElemToXML(_T("ExceptionType"), sExceptionType, root); if(m_CrashInfo.m_nExceptionType==CR_SEH_EXCEPTION) { CString sExceptionCode; sExceptionCode.Format(_T("%d"), m_CrashInfo.m_dwExceptionCode); AddElemToXML(_T("ExceptionCode"), sExceptionCode, root); } else if(m_CrashInfo.m_nExceptionType==CR_CPP_SIGFPE) { CString sFPESubcode; sFPESubcode.Format(_T("%d"), m_CrashInfo.m_uFPESubcode); AddElemToXML(_T("FPESubcode"), sFPESubcode, root); } else if(m_CrashInfo.m_nExceptionType==CR_CPP_INVALID_PARAMETER) { AddElemToXML(_T("InvParamExpression"), m_CrashInfo.m_sInvParamExpr, root); AddElemToXML(_T("InvParamFunction"), m_CrashInfo.m_sInvParamFunction, root); AddElemToXML(_T("InvParamFile"), m_CrashInfo.m_sInvParamFile, root); CString sInvParamLine; sInvParamLine.Format(_T("%d"), m_CrashInfo.m_uInvParamLine); AddElemToXML(_T("InvParamLine"), sInvParamLine, root); } CString sGuiResources; sGuiResources.Format(_T("%d"), eri.GetGuiResourceCount()); AddElemToXML(_T("GUIResourceCount"), sGuiResources, root); CString sProcessHandleCount; sProcessHandleCount.Format(_T("%d"), eri.GetProcessHandleCount()); AddElemToXML(_T("OpenHandleCount"), sProcessHandleCount, root); AddElemToXML(_T("MemoryUsageKbytes"), eri.GetMemUsage(), root); if(eri.GetScreenshotInfo().m_bValid) { TiXmlHandle hScreenshotInfo = new TiXmlElement("ScreenshotInfo"); root->LinkEndChild(hScreenshotInfo.ToNode()); TiXmlHandle hVirtualScreen = new TiXmlElement("VirtualScreen"); sNum.Format(_T("%d"), eri.GetScreenshotInfo().m_rcVirtualScreen.left); hVirtualScreen.ToElement()->SetAttribute("left", strconv.t2utf8(sNum)); sNum.Format(_T("%d"), eri.GetScreenshotInfo().m_rcVirtualScreen.top); hVirtualScreen.ToElement()->SetAttribute("top", strconv.t2utf8(sNum)); sNum.Format(_T("%d"), eri.GetScreenshotInfo().m_rcVirtualScreen.Width()); hVirtualScreen.ToElement()->SetAttribute("width", strconv.t2utf8(sNum)); sNum.Format(_T("%d"), eri.GetScreenshotInfo().m_rcVirtualScreen.Height()); hVirtualScreen.ToElement()->SetAttribute("height", strconv.t2utf8(sNum)); hScreenshotInfo.ToNode()->LinkEndChild(hVirtualScreen.ToNode()); TiXmlHandle hMonitors = new TiXmlElement("Monitors"); hScreenshotInfo.ToElement()->LinkEndChild(hMonitors.ToNode()); size_t i; for(i=0; i<eri.GetScreenshotInfo().m_aMonitors.size(); i++) { MonitorInfo& mi = eri.GetScreenshotInfo().m_aMonitors[i]; TiXmlHandle hMonitor = new TiXmlElement("Monitor"); sNum.Format(_T("%d"), mi.m_rcMonitor.left); hMonitor.ToElement()->SetAttribute("left", strconv.t2utf8(sNum)); sNum.Format(_T("%d"), mi.m_rcMonitor.top); hMonitor.ToElement()->SetAttribute("top", strconv.t2utf8(sNum)); sNum.Format(_T("%d"), mi.m_rcMonitor.Width()); hMonitor.ToElement()->SetAttribute("width", strconv.t2utf8(sNum)); sNum.Format(_T("%d"), mi.m_rcMonitor.Height()); hMonitor.ToElement()->SetAttribute("height", strconv.t2utf8(sNum)); hMonitor.ToElement()->SetAttribute("file", strconv.t2utf8(Utility::GetFileName(mi.m_sFileName))); hMonitors.ToElement()->LinkEndChild(hMonitor.ToNode()); } TiXmlHandle hWindows = new TiXmlElement("Windows"); hScreenshotInfo.ToElement()->LinkEndChild(hWindows.ToNode()); for(i=0; i<eri.GetScreenshotInfo().m_aWindows.size(); i++) { WindowInfo& wi = eri.GetScreenshotInfo().m_aWindows[i]; TiXmlHandle hWindow = new TiXmlElement("Window"); sNum.Format(_T("%d"), wi.m_rcWnd.left); hWindow.ToElement()->SetAttribute("left", strconv.t2utf8(sNum)); sNum.Format(_T("%d"), wi.m_rcWnd.top); hWindow.ToElement()->SetAttribute("top", strconv.t2utf8(sNum)); sNum.Format(_T("%d"), wi.m_rcWnd.Width()); hWindow.ToElement()->SetAttribute("width", strconv.t2utf8(sNum)); sNum.Format(_T("%d"), wi.m_rcWnd.Height()); hWindow.ToElement()->SetAttribute("height", strconv.t2utf8(sNum)); hWindow.ToElement()->SetAttribute("title", strconv.t2utf8(wi.m_sTitle)); hWindows.ToElement()->LinkEndChild(hWindow.ToNode()); } } TiXmlHandle hCustomProps = new TiXmlElement("CustomProps"); root->LinkEndChild(hCustomProps.ToNode()); int i; for(i=0; i<eri.GetPropCount(); i++) { CString sName; CString sVal; eri.GetPropByIndex(i, sName, sVal); TiXmlHandle hProp = new TiXmlElement("Prop"); hProp.ToElement()->SetAttribute("name", strconv.t2utf8(sName)); hProp.ToElement()->SetAttribute("value", strconv.t2utf8(sVal)); hCustomProps.ToElement()->LinkEndChild(hProp.ToNode()); } TiXmlHandle hFileItems = new TiXmlElement("FileList"); root->LinkEndChild(hFileItems.ToNode()); for(i=0; i<eri.GetFileItemCount(); i++) { ERIFileItem* rfi = eri.GetFileItemByIndex(i); TiXmlHandle hFileItem = new TiXmlElement("FileItem"); hFileItem.ToElement()->SetAttribute("name", strconv.t2utf8(rfi->m_sDestFile)); hFileItem.ToElement()->SetAttribute("description", strconv.t2utf8(rfi->m_sDesc)); if(rfi->m_bAllowDelete) hFileItem.ToElement()->SetAttribute("optional", "1"); if(!rfi->m_sErrorStatus.IsEmpty()) hFileItem.ToElement()->SetAttribute("error", strconv.t2utf8(rfi->m_sErrorStatus)); hFileItems.ToElement()->LinkEndChild(hFileItem.ToNode()); } #if _MSC_VER<1400 f = _tfopen(sFileName, _T("w")); #else _tfopen_s(&f, sFileName, _T("w")); #endif if(f==NULL) { sErrorMsg = _T("Error opening file for writing"); goto cleanup; } doc.useMicrosoftBOM = true; bool bSave = doc.SaveFile(f); if(!bSave) { sErrorMsg = doc.ErrorDesc(); goto cleanup; } fclose(f); f = NULL; bStatus = TRUE; cleanup: if(f) fclose(f); if(!bStatus) { eri.GetFileItemByName(fi.m_sDestFile)->m_sErrorStatus = sErrorMsg; } return bStatus; }
void GDTextureObject::OpenXML(const char* fileName) { const char* dims[] = { "0", "1D", "2D", "3D", "CubeMap" }; const char* funcs[] = { "Modulate", "Decal", "Blend", "Replace" }; const char* wraps[] = { "Clamp", "Repeat", "ClampToEdge" }; const char* str[] = { "S", "T", "R" }; const char* rgba[] = { "R", "G", "B", "A" }; TiXmlDocument doc(fileName); if(!doc.LoadFile()) return; TiXmlHandle hDoc(&doc); TiXmlElement* elementPtr; TiXmlHandle hRoot(0); elementPtr = hDoc.FirstChildElement().Element(); if( !elementPtr ) return; string rootName = elementPtr->Value(); if( strcmp(rootName.c_str(), "GDTextureObject") != 0 ) return; hRoot = TiXmlHandle(elementPtr); elementPtr = hRoot.FirstChild( "Name" ).Element(); if( elementPtr != 0 ) name = elementPtr->GetText(); elementPtr = hRoot.FirstChild( "Dimensions" ).Element(); if( elementPtr != 0 ) { const char* pVal = elementPtr->GetText(); dimension = 0; for(int i = 0; i < 5; ++i) if( strcmp( pVal, dims[i] ) == 0 ) { dimension = i; break; } } elementPtr = hRoot.FirstChild( "TextureFunc" ).Element(); if( elementPtr != 0 ) { const char* pVal = elementPtr->GetText(); textureFunc = 0; for( int i = 0; i < 4; ++i ) if( strcmp( pVal, funcs[i] ) == 0 ) { textureFunc = i; break; } } elementPtr = hRoot.FirstChild( "WrapModes" ).Element(); if( elementPtr != 0 ) { for( int dimension = 0; dimension < 3; ++dimension ) { TiXmlElement* pChildElem = elementPtr->FirstChildElement( str[dimension] ); if( pChildElem != 0 ) { const char* pVal = pChildElem->GetText(); wrapMode[dimension] = 0; for( int i = 0; i < 3; ++i ) if( strcmp( pVal, wraps[i] ) == 0 ) { wrapMode[dimension] = i; break; } } } } elementPtr = hRoot.FirstChild( "BorderColor" ).Element(); if( elementPtr != 0 ) { borderColor[0] = borderColor[1] = borderColor[2] = 0.0f; borderColor[3] = 1.0f; for( int colorindex = 0; colorindex < 4; ++colorindex ) { TiXmlElement* pChildElem = elementPtr->FirstChildElement( rgba[colorindex] ); if( pChildElem != 0 ) { const char* pVal = pChildElem->GetText(); int val = atoi( pVal ); borderColor[colorindex] = ((float)val) / 255.0f; if( borderColor[colorindex] < 0.0f ) borderColor[colorindex] = 0.0f; else if( borderColor[colorindex] > 1.0f ) borderColor[colorindex] = 1.0f; } } } elementPtr = hRoot.FirstChild( "TextureFileName" ).Element(); textureFileNames.clear(); while( elementPtr != 0 ) { string textureFileName = elementPtr->GetText(); textureFileNames.push_back( textureFileName ); elementPtr = elementPtr->NextSiblingElement( "TextureFileName" ); } }
/* Method load_xml */ bool ClusterSettings::load_xml (const Glib::ustring& filename) { /* Create xml document */ TiXmlDocument doc (filename.c_str ()); /* Test xml file */ if (!doc.LoadFile ()) return false; /* XML handles */ TiXmlHandle hdoc (&doc); TiXmlHandle hroot (0); /* Root element */ TiXmlElement *root = hdoc.FirstChildElement ().ToElement (); Glib::ustring check_xml; check_xml.assign (root->Value ()); if (!root && !check_xml.compare ("SensorsClusterSettings")) return false; hroot = TiXmlHandle (root); /* Cluster element */ TiXmlElement *cluster = hroot.FirstChildElement ("Cluster").ToElement (); if (!cluster) return false; /* Get cluster attribute */ set_name (cluster->Attribute ("name")); /* Sensors element */ TiXmlElement *sensorsNode = hroot.FirstChildElement ("Sensors").ToElement (); if (!sensorsNode) return false; /* Get sensors and attributes */ TiXmlElement *sensor; sensor = hroot.FirstChildElement ("Sensors").FirstChild ("Sensor").ToElement (); if (!sensor) return false; for (sensor; sensor; sensor = sensor->NextSiblingElement ()) { std::string sensor_tag, sensor_type; int sensor_online, sensor_adata; double sensor_x_coord, sensor_y_coord; SensorSettings sensor_settings; sensor_tag.assign (sensor->Attribute ("tag")); if (sensor_tag.empty ()) return false; if (sensor->QueryIntAttribute ("online", &sensor_online) != TIXML_SUCCESS) return false; if (sensor->QueryDoubleAttribute ("x", &sensor_x_coord) != TIXML_SUCCESS) return false; if (sensor->QueryDoubleAttribute ("y", &sensor_y_coord) != TIXML_SUCCESS) return false; if (sensor->QueryIntAttribute ("adata", &sensor_adata) != TIXML_SUCCESS) return false; sensor_type.assign (sensor->Attribute ("type")); if (sensor_type.empty ()) return false; m_Sensors.push_back (SensorSettings (sensor_tag, sensor_online, sensor_x_coord, sensor_y_coord, sensor_adata, sensor_type)); } return true; }