Beispiel #1
0
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);
  }
}
Beispiel #2
0
OSMNode::OSMNode(TiXmlElement *element) :
  id(0),
  x(0),
  y(0),
  x_string(0),
  y_string(0)
{
   if (element->Value() != std::string("node"))
   {
      std::cerr << "Unexpected '" << element->Value() << "' XML node, expected 'node'" << std::endl;
      throw std::runtime_error("wrong node");
   }
   
   std::string id_string;
   
   element->QueryStringAttribute("id", &id_string);
   
   std::stringstream ss;
   
   ss << id_string;
   ss >> id;
   
   element->QueryDoubleAttribute("lat", &y);
   element->QueryDoubleAttribute("lon", &x);
   
   std::string lx_string, ly_string;
   element->QueryStringAttribute("lat", &ly_string);
   element->QueryStringAttribute("lon", &lx_string);
   
   element->QueryStringAttribute("timestamp", &timestamp);
   element->QueryStringAttribute("uid",       &uid);
   element->QueryStringAttribute("user",      &user);
   element->QueryStringAttribute("version",   &version);
   element->QueryStringAttribute("changeset", &changeset);
   
   x_string = new std::string(lx_string);
   y_string = new std::string(ly_string);
   
   //std::cout << "id: " << id << " lat_precision: " << y_string.size()-1 << std::endl;
   //std::cout << "id: " << m_id  << " x: " <<x << " y: " << y << std::endl;
   
   TiXmlHandle refH(element);
   TiXmlElement *ref = refH.FirstChild().Element();
   
   for (; ref; ref=ref->NextSiblingElement())
   {   
      if (ref->Value() == std::string("tag"))
      {
         std::string key, value;
         ref->QueryStringAttribute("k", &key);
         ref->QueryStringAttribute("v", &value);      
         
         if (!key.empty() && !value.empty())
         {
            //std::cout << "Reading key: " << key << " value: " << value << std::endl;
           tags[key] = value;
         }
      }
   }
}
Beispiel #3
0
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);
  }
}
Beispiel #4
0
	bool SVG::read( const char* data ) {
        
		TiXmlDocument doc;
		doc.Parse( data );
        
        if (doc.Error()) {
            return false;
        }
		
		TiXmlElement* root = doc.FirstChild( "svg" )->ToElement();
		recursive_parse( root );        
        
        // get bounds information from the svg file, ignoring non-pixel values
        
        string numberWithUnitString;
        regex numberWithUnitPattern( "^(-?\\d+)(px)?$" );
        
        _handler->_minX = 0.0f;
        if ( root->QueryStringAttribute( "x", &numberWithUnitString ) == TIXML_SUCCESS ) {
            match_results<string::const_iterator> matches;
            if ( regex_search( numberWithUnitString, matches, numberWithUnitPattern ) ) {
                _handler->_minX = ::atof( matches[1].str().c_str() );
            }
        }
        
        _handler->_minY = 0.0f;
        if ( root->QueryStringAttribute( "y", &numberWithUnitString ) == TIXML_SUCCESS ) {
            match_results<string::const_iterator> matches;
            if ( regex_search( numberWithUnitString, matches, numberWithUnitPattern ) ) {
                _handler->_minY = ::atof( matches[1].str().c_str() );
            }
        }
        
        _handler->_width = 0.0f;
        if ( root->QueryStringAttribute( "width", &numberWithUnitString ) == TIXML_SUCCESS ) {
            match_results<string::const_iterator> matches;
            if ( regex_search( numberWithUnitString, matches, numberWithUnitPattern ) ) {
                _handler->_width = ::atof( matches[1].str().c_str() );
            }
        }
        
        _handler->_height = 0.0f;
        if ( root->QueryStringAttribute( "height", &numberWithUnitString ) == TIXML_SUCCESS ) {
            match_results<string::const_iterator> matches;
            if ( regex_search( numberWithUnitString, matches, numberWithUnitPattern ) ) {
                _handler->_height = ::atof( matches[1].str().c_str() );
            }
        }
		
		return true;
		
	}
Beispiel #5
0
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);
  }
}
Beispiel #6
0
void Graphe::importTemplate(QString & filename){

    TiXmlDocument doc(filename.toStdString());
    if(doc.LoadFile()){
        //TiXmlHandle hDoc(&doc);
        TiXmlElement * pRoot;
        TiXmlElement * pChildren;
        std::string temps;
        TiXmlElement * pGraph;
        pGraph = doc.FirstChildElement("Graph");
        if(pGraph){
            pRoot = pGraph->FirstChildElement("Nodes");
            int i, x, y;
            if(pRoot){
                pChildren = pRoot->FirstChildElement("Node");
                while(pChildren){
                    pChildren->QueryIntAttribute("id", &i);
                    if(i<n){
                        pChildren->QueryIntAttribute("x", &x);
                        pChildren->QueryIntAttribute("y", &y);
                        noeuds[i]= Noeud(x,y);
                        //qDebug()<<i;
                        if(pChildren->QueryStringAttribute("Label", &temps) == TIXML_SUCCESS){
                            //qDebug()<<QString(temps.c_str());
                            labels[i]= QString(temps.c_str());

                        }
                    }
                    pChildren = pChildren->NextSiblingElement("Node");
                }
            }
        }
    }
}
Beispiel #7
0
std::string Loader::getAttribute(const TiXmlElement &element, const std::string &attribute) const
{
  std::string value = "";
  if (element.QueryStringAttribute(attribute.c_str(), &value) != TIXML_SUCCESS) {
    throw std::invalid_argument("attribute " + attribute + " not defined");
  }
  return value;
}
Vector ParticleComponentLoader::loadVector(const TiXmlElement& xmlElement, const char* pname)
{
   Vector result;
   std::string value;
   if ( xmlElement.QueryStringAttribute(pname, &value) == TIXML_SUCCESS )
   {
      result = parseVector(value);
   }

   return result;
}
Beispiel #9
0
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);
  }
}
Beispiel #10
0
std::unique_ptr<ISkill> DamageSkillLoader::mt_Load_Element(const TiXmlElement& element)
{
	std::unique_ptr<ISkill> l_ret(nullptr);
	std::string l_skill_name, l_tmp;
	int l_skill_damages;
	DamageSkill::DamageSkillOperator l_skill_operator;

	/** name **/
	element.QueryStringAttribute("name", &l_skill_name);

	/** damages **/
	element.QueryIntAttribute("damages", &l_skill_damages);

	/** operator **/
	element.QueryStringAttribute("operator", &l_tmp);
	l_skill_operator = DamageSkill::mt_String_To_Operator(l_tmp);

	/** new object **/
	//if (l_fn_returned == TIXML_SUCCESS) l_ret = new DamageSkill(l_skill_name, l_skill_damages, l_skill_operator);

	return l_ret;
}
Beispiel #11
0
void playlist::load(std::string filename)
{
	music.clear();

	if (access(filename.c_str(), F_OK)==-1) {
		printf("No playlist found(%s).  No music will played.\n",
			filename.c_str());
		return;
	}

	TiXmlDocument doc(filename.c_str());
	doc.LoadFile();

	TiXmlHandle hDoc(&doc);
	TiXmlElement* pElem;
	TiXmlHandle hRoot(0);

	pElem=hDoc.FirstChildElement().Element();
	// should always have a valid root but handle gracefully if it doesn't
	if (!pElem) {
		printf("Error opening: %s.  No music will played.\n", filename.c_str());
		return;
	}
//	printf("name: %s\n", pElem->Value());
	hRoot=TiXmlHandle(pElem);
	TiXmlElement * songs = hRoot.FirstChild().Element();

	for (; songs!=NULL; songs=songs->NextSiblingElement()) {
		const char *pKey=songs->Value();
		const char *pText=songs->GetText();

		if (!pKey || !pText)
			continue;
//	printf("loop: %s %s\n", pKey, pText);

		std::string file = pText;
		std::string disp;
//	songs->QueryStringAttribute("display", &disp);
		if (songs->QueryStringAttribute("display", &disp)!= TIXML_SUCCESS)
			disp = file;
//	printf("%s: %s\n", disp.c_str(), file.c_str());
		if (access(file.c_str(), F_OK)==-1) {
			//no file found
		}
		else {
			music.push_back(std::make_pair(disp, file));
		}
	}


}
Beispiel #12
0
RobotInterface::ParamList RobotInterface::XMLReader::Private::readParamListTag(TiXmlElement* paramListElem)
{
    if (paramListElem->ValueStr().compare("paramlist") != 0) {
        SYNTAX_ERROR(paramListElem->Row()) << "Expected \"paramlist\". Found" << paramListElem->ValueStr();
    }

    ParamList params;
    Param mainparam;

    if (paramListElem->QueryStringAttribute("name", &mainparam.name()) != TIXML_SUCCESS) {
        SYNTAX_ERROR(paramListElem->Row()) << "\"paramlist\" element should contain the \"name\" attribute";
    }

    params.push_back(mainparam);

    // yDebug() << "Found paramlist [" << params.at(0).name() << "]";

    for (TiXmlElement* childElem = paramListElem->FirstChildElement(); childElem != 0; childElem = childElem->NextSiblingElement()) {
        if (childElem->ValueStr().compare("elem") != 0) {
            SYNTAX_ERROR(childElem->Row()) << "Expected \"elem\". Found" << childElem->ValueStr();
        }

        Param childParam;

        if (childElem->QueryStringAttribute("name", &childParam.name()) != TIXML_SUCCESS) {
            SYNTAX_ERROR(childElem->Row()) << "\"elem\" element should contain the \"name\" attribute";
        }

        const char *valueText = childElem->GetText();
        if (!valueText) {
            SYNTAX_ERROR(childElem->Row()) << "\"elem\" element should have a value [ \"name\" = " << childParam.name() << "]";
        }
        childParam.value() = valueText;

        params.push_back(childParam);
    }

    if (params.empty()) {
        SYNTAX_ERROR(paramListElem->Row()) << "\"paramlist\" cannot be empty";
    }

    // +1 skips the first element, that is the main param
    for (ParamList::iterator it = params.begin() + 1; it != params.end(); ++it) {
        Param &param = *it;
        params.at(0).value() += (params.at(0).value().empty() ? "(" : " ") + param.name();
    }
    params.at(0).value() += ")";

    // yDebug() << params;
    return params;
}
Beispiel #13
0
void HierClassifier::loadCache(boost::filesystem::path file){
	cout << "Loading cache from file " << file.string() << endl;
	TiXmlDocument doc(file.c_str());
	if(!doc.LoadFile()){
		cout << "Could not load cache file" << endl;
		throw "Could not load cache file";
	}
	TiXmlElement* pWeakClassifiers = doc.FirstChildElement("weak_classifiers");
	if(!pWeakClassifiers){
		throw "Bad cache file - no weak_classifiers";
	}
	int numClassifiers;
	pWeakClassifiers->QueryIntAttribute("num", &numClassifiers);
	pWeakClassifiers->QueryIntAttribute("num_labels", &numLabels);
	TiXmlElement* pClassifier = pWeakClassifiers->FirstChildElement("classifier");
	while(pClassifier){
		string cacheFile;
		double weight;
		WeakClassifierInfo info;
		string classifierType;
		pClassifier->QueryStringAttribute("type", &classifierType);
		pClassifier->QueryStringAttribute("cache_file", &cacheFile);
		pClassifier->QueryDoubleAttribute("weight", &weight);
		pClassifier->QueryIntAttribute("desc_beg", &(info.descBeg));
		pClassifier->QueryIntAttribute("desc_end", &(info.descEnd));
		weights.push_back(weight);
		classifiersInfo.push_back(info);
		if(classifierType == "SVM"){
			classifiers.push_back(new ClassifierSVM());
		}
		else if(classifierType == "RF"){
			classifiers.push_back(new ClassifierRF());
		}
		classifiers.back()->loadCache(pClassifier, cacheFile);

		pClassifier = pClassifier->NextSiblingElement("classifier");
	}
}
Beispiel #14
0
void 
StateLoader::LoadEnums(TiXmlHandle &hRoot, std::string functionName, IGlobalState *state)
{
	std::string name = "";
	std::string valueString = "";
	TiXmlElement *pElem;

	TiXmlHandle handle(hRoot.FirstChild("enums").Element());

	pElem = handle.FirstChild().Element();
	for (; 0 != pElem; pElem = pElem->NextSiblingElement()) {

		int value, length = 1;
		pElem->QueryStringAttribute("name", &name);
		pElem->QueryStringAttribute("value", &valueString);
		if (pElem->QueryIntAttribute("length", &length) != TIXML_SUCCESS){
			length = 1;
		}
		value = (int)strtol(valueString.c_str(), NULL, 0);

		state->addStateEnum(name, functionName, value, length);
	}
}
Beispiel #15
0
	bool SVG::read( const char* data ) {
        
		TiXmlDocument doc;
		doc.Parse( data );
        
        if (doc.Error()) {
            return false;
        }
		
		TiXmlElement* root = doc.FirstChild( "svg" )->ToElement();
		recursive_parse( root );        
        
        // get bounds information from the svg file, ignoring non-pixel values
        string numberWithUnitString;

        _handler->_minX = 0.0f;
        if ( root->QueryStringAttribute( "x", &numberWithUnitString ) == TIXML_SUCCESS ) {
			_handler->_minX = findNumberWithUnit( numberWithUnitString, _handler->_minX );
        }
        
        _handler->_minY = 0.0f;
        if ( root->QueryStringAttribute( "y", &numberWithUnitString ) == TIXML_SUCCESS ) {
			_handler->_minY = findNumberWithUnit( numberWithUnitString, _handler->_minY );
        }
        
        _handler->_width = 0.0f;
        if ( root->QueryStringAttribute( "width", &numberWithUnitString ) == TIXML_SUCCESS ) {
			_handler->_width = findNumberWithUnit( numberWithUnitString, _handler->_width );
        }
        
        _handler->_height = 0.0f;
        if ( root->QueryStringAttribute( "height", &numberWithUnitString ) == TIXML_SUCCESS ) {
			_handler->_height = findNumberWithUnit( numberWithUnitString, _handler->_height );
        }
		return true;
		
	}
Beispiel #16
0
void 
StateLoader::LoadFunctionEnums(TiXmlHandle &handle, IGlobalState *state) {

	TiXmlElement *pElem;

	std::string name;
	std::string data = "";
	std::string functionName;

	pElem = handle.FirstChild().Element();
	for (; 0 != pElem; pElem = pElem->NextSiblingElement()) {

		TiXmlHandle methodHandle(pElem);
		pElem->QueryStringAttribute("function", &functionName);
		
		LoadEnums(methodHandle, functionName, state);
	}
}
Beispiel #17
0
  void mitk::XMLSerializable::FromXMLFile(const std::string& file
                                          , const std::string& elemName)
  {
    endodebug( "Trying to read from " << file )

    TiXmlDocument doc( file.c_str() );
    bool loadOkay = doc.LoadFile();
    if(!loadOkay)
    {
      std::ostringstream s; s << "File " << file
          << " could not be loaded!";
      throw std::logic_error(s.str().c_str());
    }

    m_XMLFileName = file;

    TiXmlElement* elem = doc.FirstChildElement();
    endoAssertMsg( elem, "No root element found" );

    // determine element to read from
    std::string elementName = elemName;
    if(elementName.empty())
      elementName = this->GetNameOfClass();
    // try again with the first element
    if(strcmp(elem->Value(), elementName.c_str()) != 0)
      elem = elem->FirstChildElement(elementName.c_str());

    endoAssertMsg( elem, "No child element \"" << elementName <<
                 "\" found in " << file );

    // if theres an attribute as file reference try to load the class
    // from that file
    std::string filename;
    if(elem->QueryStringAttribute(FILE_REFERENCE_ATTRIBUTE_NAME.c_str(), &filename)
      == TIXML_SUCCESS)
    {
      if( !itksys::SystemTools::FileIsFullPath(filename.c_str()) )
        filename = itksys::SystemTools::GetFilenamePath(file) + "/" + filename;
      this->FromXMLFile(filename);
      return; // exit!
    }

    this->FromXML( elem );
  }
Range ParticleComponentLoader::loadValueRange(const TiXmlElement& xmlElement, const char* pname)
{
   Range result;
   std::string value;
   if ( xmlElement.QueryStringAttribute(pname, &value) == TIXML_SUCCESS )
   {
      std::size_t index = value.find(':');
      if ( index != value.npos )
      {
         std::string leftstr = value.substr(0, index);
         std::string rightstr = value.substr(index+1, value.length() - index - 1);

         float left = (float) std::atof(leftstr.c_str());
         float right = (float) std::atof(rightstr.c_str());

         result.set(left, right - left);
      }
   }
   return result;
}
TiXmlElement *CLibraryDirectory::LoadXML(const std::string &xmlFile)
{
  if (!CFile::Exists(xmlFile))
    return NULL;

  if (!m_doc.LoadFile(xmlFile))
    return NULL;

  TiXmlElement *xml = m_doc.RootElement();
  if (!xml || xml->ValueStr() != "node")
    return NULL;

  // check the condition
  std::string condition;
  xml->QueryStringAttribute("visible", &condition);
  if (condition.empty() || g_infoManager.EvaluateBool(condition))
    return xml;

  return NULL;
}
VectorRange ParticleComponentLoader::loadVectorRange(const TiXmlElement& xmlElement, const char* pname)
{
   VectorRange result;
   std::string value;
   if ( xmlElement.QueryStringAttribute(pname, &value) == TIXML_SUCCESS )
   {
      std::size_t index = value.find(':');
      if ( index != value.npos )
      {
         std::string leftrange = value.substr(0, index);
         std::string rightrange = value.substr(index+1, value.length() - index - 1);

         Vector left = parseVector(leftrange);
         Vector right = parseVector(rightrange);

         result.set(left, right);
      }
   }

   return result;
}
Beispiel #21
0
bool AutoTimer::UpdateFrom(TiXmlElement* autoTimerNode, Channels &channels)
{
  std::string strTmp;
  int iTmp;

  m_type = Timer::EPG_AUTO_SEARCH;

  //this is an auto timer so the state is always scheduled unless it's disabled
  m_state = PVR_TIMER_STATE_SCHEDULED;

  m_tags.clear();
  if (XMLUtils::GetString(autoTimerNode, "e2tags", strTmp))
    m_tags = strTmp;

  if (autoTimerNode->QueryStringAttribute("name", &strTmp) == TIXML_SUCCESS)
    m_title = strTmp;

  if (autoTimerNode->QueryStringAttribute("match", &strTmp) == TIXML_SUCCESS)
    m_searchPhrase = strTmp;

  if (autoTimerNode->QueryStringAttribute("enabled", &strTmp) == TIXML_SUCCESS)
  {
    if (strTmp == AUTOTIMER_ENABLED_NO)
    {
      m_state = PVR_TIMER_STATE_DISABLED;
    }
  }

  if (autoTimerNode->QueryIntAttribute("id", &iTmp) == TIXML_SUCCESS)
    m_backendId = iTmp;

  std::string from;
  std::string to;
  std::string avoidDuplicateDescription;
  std::string searchForDuplicateDescription;
  autoTimerNode->QueryStringAttribute("from", &from);
  autoTimerNode->QueryStringAttribute("to", &to);
  autoTimerNode->QueryStringAttribute("avoidDuplicateDescription", &avoidDuplicateDescription);
  autoTimerNode->QueryStringAttribute("searchForDuplicateDescription", &searchForDuplicateDescription);

  if (avoidDuplicateDescription != AUTOTIMER_AVOID_DUPLICATE_DISABLED)
  {
    if (searchForDuplicateDescription == AUTOTIMER_CHECK_SEARCH_FOR_DUP_IN_TITLE)
      m_deDup = AutoTimer::DeDup::CHECK_TITLE;
    else if (searchForDuplicateDescription == AUTOTIMER_CHECK_SEARCH_FOR_DUP_IN_TITLE_AND_SHORT_DESC)
      m_deDup = AutoTimer::DeDup::CHECK_TITLE_AND_SHORT_DESC;
    else if (searchForDuplicateDescription.empty() || searchForDuplicateDescription == AUTOTIMER_CHECK_SEARCH_FOR_DUP_IN_TITLE_AND_ALL_DESCS) //Even though this value should be 2 it is sent as ommitted for this attribute, we'll allow 2 anyway incase it changes in the future
      m_deDup = AutoTimer::DeDup::CHECK_TITLE_AND_ALL_DESCS;
  }

  if (autoTimerNode->QueryStringAttribute("encoding", &strTmp) == TIXML_SUCCESS)
    m_encoding = strTmp;

  if (autoTimerNode->QueryStringAttribute("searchType", &strTmp) == TIXML_SUCCESS)
  {
    m_searchType = strTmp;
    if (strTmp == AUTOTIMER_SEARCH_TYPE_DESCRIPTION)
      m_searchFulltext = true;
  }

  if (autoTimerNode->QueryStringAttribute("searchCase", &strTmp) == TIXML_SUCCESS)
    m_searchCase = strTmp;

  TiXmlElement* serviceNode = autoTimerNode->FirstChildElement("e2service");

  if (serviceNode)
  {
    const TiXmlElement *nextServiceNode = serviceNode->NextSiblingElement("e2service");

    if (!nextServiceNode)
    {
      //If we only have one channel
      if (XMLUtils::GetString(serviceNode, "e2servicereference", strTmp))
      {
        m_channelId = channels.GetChannelUniqueId(Channel::NormaliseServiceReference(strTmp.c_str()));

        // For autotimers for channels we don't know about, such as when the addon only uses one bouquet or an old channel referene that doesn't exist
        // we'll default to any channel (as that is what kodi PVR does) and leave in ERROR state
        if (m_channelId == PVR_CHANNEL_INVALID_UID)
        {
          m_state = PVR_TIMER_STATE_ERROR;
          Logger::Log(LEVEL_DEBUG, "%s Overriding AutoTimer state as channel not found, state is: ERROR", __FUNCTION__);
          m_channelName = LocalizedString(30520); // Invalid Channel
          m_channelId = PVR_TIMER_ANY_CHANNEL;
          m_anyChannel = true;
        }
        else
        {
          m_channelName = channels.GetChannel(m_channelId)->GetChannelName();
        }
      }
    }
    else //otherwise set to any channel
    {
      m_channelId = PVR_TIMER_ANY_CHANNEL;
      m_anyChannel = true;
    }
  }
  else //otherwise set to any channel
  {
    m_channelId = PVR_TIMER_ANY_CHANNEL;
    m_anyChannel = true;
  }

  m_weekdays = 0;

  TiXmlElement* includeNode = autoTimerNode->FirstChildElement("include");

  if (includeNode)
  {
    for (; includeNode != nullptr; includeNode = includeNode->NextSiblingElement("include"))
    {
      std::string includeVal = includeNode->GetText();

      std::string where;
      if (includeNode->QueryStringAttribute("where", &where) == TIXML_SUCCESS)
      {
        if (where == "dayofweek")
        {
          m_weekdays = m_weekdays |= (1 << atoi(includeVal.c_str()));
        }
      }
    }
  }

  if (m_weekdays != PVR_WEEKDAY_NONE)
  {
    std::time_t t = std::time(nullptr);
    std::tm timeinfo = *std::localtime(&t);
    timeinfo.tm_sec = 0;
    m_startTime = 0;
    if (!from.empty())
    {
      ParseTime(from, timeinfo);
      m_startTime = std::mktime(&timeinfo);
    }

    timeinfo = *std::localtime(&t);
    timeinfo.tm_sec = 0;
    m_endTime = 0;
    if (!to.empty())
    {
      ParseTime(to, timeinfo);
      m_endTime = std::mktime(&timeinfo);
    }
  }
  else
  {
    for (int i = 0; i < DAYS_IN_WEEK; i++)
    {
      m_weekdays = m_weekdays |= (1 << i);
    }
    m_startAnyTime = true;
    m_endAnyTime = true;
  }

  if (ContainsTag(TAG_FOR_GENRE_ID))
  {
    int genreId = 0;
    if (std::sscanf(ReadTagValue(TAG_FOR_GENRE_ID).c_str(), "0x%02X", &genreId) == 1)
    {
      m_genreType = genreId & 0xF0;
      m_genreSubType = genreId & 0x0F;
    }
    else
    {
      m_genreType = 0;
      m_genreSubType = 0;
    }
  }

  return true;
}
BaseProperty::Pointer mitk::TransferFunctionPropertySerializer::Deserialize(TiXmlElement* element)
{
  if (!element)
    return nullptr;

  mitk::LocaleSwitch localeSwitch("C");

  TransferFunction::Pointer tf = TransferFunction::New();

  // deserialize scalar opacity function
  TiXmlElement* scalarOpacityPointlist = element->FirstChildElement("ScalarOpacity");
  if (scalarOpacityPointlist == nullptr)
  {
    return nullptr;
  }

  tf->ClearScalarOpacityPoints();

  try
  {
    for( TiXmlElement* pointElement = scalarOpacityPointlist->FirstChildElement("point");
         pointElement != nullptr;
         pointElement = pointElement->NextSiblingElement("point"))
    {
      std::string x;
      std::string y;
      if (pointElement->QueryStringAttribute("x", &x) != TIXML_SUCCESS) return nullptr;
      if (pointElement->QueryStringAttribute("y", &y) != TIXML_SUCCESS) return nullptr;
      tf->AddScalarOpacityPoint(boost::lexical_cast<double>(x), boost::lexical_cast<double>(y));
    }

    TiXmlElement* gradientOpacityPointlist = element->FirstChildElement("GradientOpacity");
    if (gradientOpacityPointlist == nullptr)
    {
      return nullptr;
    }

    tf->ClearGradientOpacityPoints();

    for( TiXmlElement* pointElement = gradientOpacityPointlist->FirstChildElement("point");
         pointElement != nullptr;
         pointElement = pointElement->NextSiblingElement("point"))
    {
      std::string x;
      std::string y;
      if (pointElement->QueryStringAttribute("x", &x) != TIXML_SUCCESS) return nullptr;
      if (pointElement->QueryStringAttribute("y", &y) != TIXML_SUCCESS) return nullptr;
      tf->AddGradientOpacityPoint(boost::lexical_cast<double>(x), boost::lexical_cast<double>(y));
    }

    TiXmlElement* rgbPointlist = element->FirstChildElement("Color");
    if (rgbPointlist == nullptr)
    {
      return nullptr;
    }
    vtkColorTransferFunction* ctf = tf->GetColorTransferFunction();
    if (ctf == nullptr)
    {
      return nullptr;
    }

    ctf->RemoveAllPoints();

    for( TiXmlElement* pointElement = rgbPointlist->FirstChildElement("point");
         pointElement != nullptr;
         pointElement = pointElement->NextSiblingElement("point"))
    {
      std::string x;
      std::string r,g,b, midpoint, sharpness;
      if (pointElement->QueryStringAttribute("x", &x) != TIXML_SUCCESS) return nullptr;
      if (pointElement->QueryStringAttribute("r", &r) != TIXML_SUCCESS) return nullptr;
      if (pointElement->QueryStringAttribute("g", &g) != TIXML_SUCCESS) return nullptr;
      if (pointElement->QueryStringAttribute("b", &b) != TIXML_SUCCESS) return nullptr;
      if (pointElement->QueryStringAttribute("midpoint", &midpoint) != TIXML_SUCCESS) return nullptr;
      if (pointElement->QueryStringAttribute("sharpness", &sharpness) != TIXML_SUCCESS) return nullptr;
      ctf->AddRGBPoint(boost::lexical_cast<double>(x),
                       boost::lexical_cast<double>(r), boost::lexical_cast<double>(g), boost::lexical_cast<double>(b),
                       boost::lexical_cast<double>(midpoint),
                       boost::lexical_cast<double>(sharpness));
    }
  }
  catch ( boost::bad_lexical_cast& e )
  {
    MITK_ERROR << "Could not parse string as number: " << e.what();

    return nullptr;
  }

  return TransferFunctionProperty::New(tf).GetPointer();
}
  void EndoDebugFromXmlFile::Update()
  {
    endodebug( __FUNCTION__ )

    std::string _FileName = *d->m_FileName;
    if( !itksys::SystemTools::FileExists( _FileName.c_str() ) )
    {
      endodebug(_FileName << " does not exist");
      return;
    }

    long int _FileModifiedTime
      = itksys::SystemTools::ModifiedTime( _FileName.c_str() );
    // file has changed: we know an older version...
    if( d->m_FileModifiedTime >= _FileModifiedTime )
    {
        endodebug("File not changed. No Update necessary.");
        return;
    }

    // reread
    endodebugvar( _FileName )
    TiXmlDocument doc( _FileName );
    doc.LoadFile();
    TiXmlHandle docHandle( &doc );
    TiXmlElement* elem = docHandle.FirstChildElement().FirstChildElement( "EndoDebug" ).ToElement();

    if(elem == 0)
    {
      endodebug("EndoDebug element not found");
      return;
    }

    int _DebugEnabled = d->m_EndoDebug->GetDebugEnabled();
    if( elem->QueryIntAttribute("DebugEnabled",&_DebugEnabled) != TIXML_SUCCESS )
      endodebug("DebugEnabled attribute not found");

    int _ShowImagesInDebug = d->m_EndoDebug->GetShowImagesInDebug();
    if( elem->QueryIntAttribute("ShowImagesInDebug",&_ShowImagesInDebug) != TIXML_SUCCESS )
      endodebug("ShowImagesInDebug attribute not found");

    int _ShowImagesTimeOut = d->m_EndoDebug->GetShowImagesTimeOut();
    if( elem->QueryIntAttribute("ShowImagesTimeOut",&_ShowImagesTimeOut) != TIXML_SUCCESS )
      endodebug("ShowImagesTimeOut attribute not found");

    std::string _DebugImagesOutputDirectory = d->m_EndoDebug->GetDebugImagesOutputDirectory();
    if( elem->QueryStringAttribute("DebugImagesOutputDirectory",&_DebugImagesOutputDirectory) != TIXML_SUCCESS )
      endodebug("DebugImagesOutputDirectory attribute not found");

    std::set<std::string> _FilesToDebug;
    std::string _FilesToDebugString;
    if( elem->QueryStringAttribute("FilesToDebug",&_FilesToDebugString) != TIXML_SUCCESS )
    {
      endodebug("FilesToDebug attribute not found");
    }
    else
    {
        StringExplode( _FilesToDebugString, ";", &_FilesToDebug );
    }

    std::set<std::string> _SymbolsToDebug;
    std::string _SymbolsToDebugString;
    if( elem->QueryStringAttribute("SymbolsToDebug",&_SymbolsToDebugString) != TIXML_SUCCESS )
    {
      endodebug("SymbolsToDebug attribute not found");
    }
    else
    {
        StringExplode( _SymbolsToDebugString, ";", &_SymbolsToDebug );
    }

    // save
    mitk::EndoDebug::GetInstance().SetDebugEnabled( _DebugEnabled == 1? true: false );
    mitk::EndoDebug::GetInstance().SetShowImagesInDebug( _ShowImagesInDebug == 1? true: false  );
    mitk::EndoDebug::GetInstance().SetShowImagesTimeOut( _ShowImagesTimeOut );
    mitk::EndoDebug::GetInstance().SetDebugImagesOutputDirectory( _DebugImagesOutputDirectory );
    mitk::EndoDebug::GetInstance().SetFilesToDebug(_FilesToDebug);
    mitk::EndoDebug::GetInstance().SetSymbolsToDebug(_SymbolsToDebug);

    // save that modified time
    d->m_FileModifiedTime = _FileModifiedTime;
  }
Beispiel #24
0
bool Guldmannen::Level::Load(std::string _filename)
{
	filename = "resources/levels/" + _filename;
	TiXmlDocument doc(filename.c_str());
	doc.LoadFile();
	TiXmlHandle root(&doc);
	TiXmlElement *tempElement;
	tempElement = root.FirstChild("level").Element();
	if(tempElement)
	{
		std::cout << "Loading level with \"name\": " << tempElement->Attribute("name") << "\n";
		tilesetfile = tempElement->Attribute("tileset");
		tempElement->QueryIntAttribute("width",&width);
		tempElement->QueryIntAttribute("height",&height);
		std::cout << "height: " << height << ", width: " << width <<".\n";

		//loading level relations and their offsets [4]
		tempElement = root.FirstChild("level").FirstChild("worldrelations").FirstChild("left").Element();
		if(tempElement){
			tempElement->QueryStringAttribute("level",&leadsTo[0]);
			tempElement->QueryIntAttribute("offset",&leadsTo_offset[0]);
		}

		tempElement = root.FirstChild("level").FirstChild("worldrelations").FirstChild("right").Element();
		if(tempElement){
			tempElement->QueryStringAttribute("level",&leadsTo[1]);
			tempElement->QueryIntAttribute("offset",&leadsTo_offset[1]);
		}

		tempElement = root.FirstChild("level").FirstChild("worldrelations").FirstChild("up").Element();
		if(tempElement){
			tempElement->QueryStringAttribute("level",&leadsTo[2]);
			tempElement->QueryIntAttribute("offset",&leadsTo_offset[2]);
		}

		tempElement = root.FirstChild("level").FirstChild("worldrelations").FirstChild("down").Element();
		if(tempElement){
			tempElement->QueryStringAttribute("level",&leadsTo[3]);
			tempElement->QueryIntAttribute("offset",&leadsTo_offset[3]);
		}
	}
	else
	{
		std::cout << "Failed to begin load level\n";
		return false;
	}
	tempElement = root.FirstChild("level").FirstChild("tile").Element();
	if(!tempElement)
	{
		std::cout << "Error, no tile nodes!\n";
		return false;
	}
	int temptile[4] = {-1};
	for(int i = 0 ; i<height*width ; tempElement = tempElement->NextSiblingElement("tile"), i++)
	{
		//if(tempElement->QueryIntAttribute("id",&temptile))
		//{
		tempElement->QueryIntAttribute("id",&temptile[0]);
		if(tempElement->QueryIntAttribute("id2",&temptile[1]) == 1)
			temptile[1] = -1;
		if(tempElement->QueryIntAttribute("id3",&temptile[2]) == 1)
			temptile[2] = -1;
		if(tempElement->QueryIntAttribute("id4",&temptile[3]) == 1)
			temptile[3] = -1;
		//if(i<100)	Tiles.push_back(new Tile(temptile,1));
		//else
		int temp_type = 0;
		if(tempElement->QueryIntAttribute("type",&temp_type) == 1)
			temp_type = 0;

		float temp_tps = 0;
		if(tempElement->QueryFloatAttribute("tps",&temp_tps) == 1)
			temp_tps = 0;

		int temp_frames = 0;
		tempElement->QueryIntAttribute("frames",&temp_frames);
			Tiles.push_back(new Tile(temptile,temp_type,temp_frames,temp_tps));
		//}
		/*else
		{
			std::cout << "Failed to load level\n";
			return false;
		}*/
		TiXmlElement *twarp = tempElement->FirstChildElement("warp");
		if(twarp != NULL)
		{
			std::cout << "hmm warp?\n";
			std::string destination;
			int destX;
			int destY;
			if(twarp->QueryIntAttribute("dest_x",&destX) != 1)
			{
				if(twarp->QueryIntAttribute("dest_y",&destY) != 1)
				{
					if(twarp->QueryStringAttribute("dest_level",&destination) == 1)
					{
						destination = "";
					}
					Warps.push_back(new Warp(i%width,(i-(i%width))/width,destX,destY,destination));
					std::cout << "addade ett warp!! :D " << i%width << " " << (i-(i%width))/width << " " << destX << " " << destY << " " << destination << ".\n\n\n\n\n\n";
				}
			}
		}
		TiXmlElement *entity = tempElement->FirstChildElement("entity");
		if(entity != NULL)
		{
			std::cout << "adding an entity..\n";
			entityHandler->AddEntity(entity, vec2d(i%width,(i-(i%width))/width));
		}
	}
	tileSheet = Resources->GetTexture("resources/tilesets/" + tilesetfile);
	if(tileSheet == NULL)
	{
		std::cout << "tileSheet was never loaded!\n";
		return false;
	}
	//else if(render)
	{
		RenderImage *gt_temp = NULL;//new RenderImage(tileSheet,true);
		int t = 0;
		for(int i=0;i<height;i++)
		{
			for(int j=0;j<width;j++)
			{
				for(int l=0;l<4;l++)
				{
					if(Tiles[t]->id[l] != -1)
					{
						gt_temp = new RenderImage(tileSheet,true);
						int W = tileSheet->Width/32;
						int H = tileSheet->Height/32;
						gt_temp->SetPosition(j*32,i*32);
						gt_temp->SetSize(32,32);
						gt_temp->SetTexClip(32,32,(Tiles[t]->id[l])%W*32, ((Tiles[t]->id[l]*32) - (Tiles[t]->id[l])%W*32) /W);
						if(l == 2)
							gt_temp->SetZ(0.5 + (0.0001*((i*32)+32)));
						else
							gt_temp->SetZ(0.4 + (0.1*l));
						graphical_tiles.push_back(gt_temp);
						Tiles[t]->graphic_id[l] = (int)graphical_tiles.size()-1;
					}
				}
				t++;
			}
		}
	}
	return true;
}
Beispiel #25
0
void ClassifierSVM::loadSettings(TiXmlElement* settings){
	string tmp;

	cacheEnabled = true;
	TiXmlElement* pPtr = settings->FirstChildElement("cache");
	if(!pPtr){
		throw "Bad settings file - no cache setting for ClassifierSVM";
	}
	pPtr->QueryBoolAttribute("enabled", &cacheEnabled);

	pPtr = settings->FirstChildElement("svm");
	if(!pPtr){
		throw "Bad settings file - no svm settings";
	}

	int svmType;
	pPtr->QueryStringAttribute("type", &tmp);
	if(tmp == "C_SVC"){
		svmType = C_SVC;
	}
	else if(tmp == "NU_SVC"){
		svmType = NU_SVC;
	}
	else if(tmp == "ONE_CLASS"){
		svmType = ONE_CLASS;
	}
	else{
		throw "Bad settings file - wrong SVM type";
	}

	int kernelType;
	TiXmlElement* svmPtr = pPtr->FirstChildElement("kernelType");
	if(!svmPtr){
		throw "Bad settings file - no kernel type";
	}
	svmPtr->QueryStringAttribute("value", &tmp);
	if(tmp == "LINEAR"){
		kernelType = LINEAR;
	}
	else if(tmp == "POLY"){
		kernelType = POLY;
	}
	else if(tmp == "RBF"){
		kernelType = RBF;
	}
	else if(tmp == "SIGMOID"){
		kernelType = SIGMOID;
	}
	else{
		throw "Bad settings file - wrong kernel type";
	}

	double gamma = 0.5;
	svmPtr = pPtr->FirstChildElement("gamma");
	if(!svmPtr){
		throw "Bad settings file - no gamma value";
	}
	svmPtr->QueryDoubleAttribute("value", &gamma);

	double degree = 2;
	svmPtr = pPtr->FirstChildElement("degree");
	if(!svmPtr){
		throw "Bad settings file - no degree value";
	}
	svmPtr->QueryDoubleAttribute("value", &degree);

	double C = 1;
	svmPtr = pPtr->FirstChildElement("C");
	if(!svmPtr){
		throw "Bad settings file - no C value";
	}
	svmPtr->QueryDoubleAttribute("value", &C);

	svmParams.svm_type = svmType;
	svmParams.kernel_type = kernelType;
	svmParams.gamma = gamma;
	svmParams.degree = degree;
	svmParams.C = C;
}
BOOL CSpecialZipCache::ReadCache()
{
	std::string strInfoXmlPath;
	strInfoXmlPath = ZTools::FormatString("%s%s_%s\\info.xml", GetSpacialCacheBasePath().c_str(), m_strThisFileMd5.c_str(), m_strThisFileSize.c_str());

	if (!PathFileExists(strInfoXmlPath.c_str()))
	{
		return FALSE;
	}

	TiXmlBase::SetCondenseWhiteSpace(false);
	TiXmlDocument doc;

#ifdef TIXML_USE_STL
	doc.LoadFile(strInfoXmlPath, TIXML_ENCODING_UTF8);
#else
	doc.LoadFile(strInfoXmlPath.c_str(), TIXML_ENCODING_UTF8);
#endif


// 	std::string m_strFileIdListJson;
// 	std::string m_strMainFileId;
// 	std::string m_strThisFileId;
// 	std::string m_strThisFileMd5;

	TiXmlElement* rootElement = doc.RootElement();
	if (rootElement == NULL)
	{
		return FALSE;
	}

#ifdef TIXML_USE_STL
	rootElement->QueryStringAttribute("fileIdListJson", &m_strFileIdListJson);
	rootElement->QueryStringAttribute("mainFileId", &m_strMainFileId);
	//rootElement->QueryStringAttribute("thisFileId", &m_strThisFileId);
	rootElement->QueryStringAttribute("thisFileMd5", &m_strThisFileMd5);

	rootElement->QueryStringAttribute("componentFileName", &m_strComponentFileName);
	rootElement->QueryStringAttribute("componentFileId", &m_strComponentFileId);
	rootElement->QueryStringAttribute("componentManifest", &m_strComponentManifest);
	rootElement->QueryStringAttribute("formFileName", &m_strFormFileName);
	rootElement->QueryStringAttribute("formFileId", &m_strFormFileId);
	rootElement->QueryStringAttribute("formManifest", &m_strFormManifest);
#else
	const char* pStrFileIdListJson = rootElement->Attribute("fileIdListJson");
	if (pStrFileIdListJson != NULL)
	{
		m_strFileIdListJson = std::string(pStrFileIdListJson);
	}
	const char* pStrMainFileId = rootElement->Attribute("mainFileId");
	if (pStrMainFileId != NULL)
	{
		m_strMainFileId = std::string(pStrMainFileId);
	}
// 	const char* pStrThisFileId = rootElement->Attribute("thisFileId");
// 	if (pStrThisFileId != NULL)
// 	{
// 		m_strThisFileId = std::string(pStrThisFileId);
// 	}
	const char* pStrThisFileMd5 = rootElement->Attribute("thisFileMd5");
	if (pStrThisFileMd5 != NULL)
	{
		m_strThisFileMd5 = std::string(pStrThisFileMd5);
	}
	const char* pStrComponentFileName = rootElement->Attribute("componentFileName");
	if (pStrComponentFileName != NULL)
	{
		m_strComponentFileName = std::string(pStrComponentFileName);
	}
	const char* pStrComponentFileId = rootElement->Attribute("componentFileId");
	if (pStrComponentFileId != NULL)
	{
		m_strComponentFileId = std::string(pStrComponentFileId);
	}
	const char* pStrComponentManifest = rootElement->Attribute("componentManifest");
	if (pStrComponentManifest != NULL)
	{
		m_strComponentManifest = std::string(pStrComponentManifest);
	}
	const char* pStrFormFileName = rootElement->Attribute("formFileName");
	if (pStrFormFileName != NULL)
	{
		m_strFormFileName = std::string(pStrFormFileName);
	}
	const char* pStrFormFileId = rootElement->Attribute("formFileId");
	if (pStrFormFileId != NULL)
	{
		m_strFormFileId = std::string(pStrFormFileId);
	}
	const char* pStrFormManifest = rootElement->Attribute("formManifest");
	if (pStrFormManifest != NULL)
	{
		m_strFormManifest = std::string(pStrFormManifest);
	}
#endif

	ZTools::UTF8ToMB(m_strFileIdListJson);
	ZTools::UTF8ToMB(m_strMainFileId);
	ZTools::UTF8ToMB(m_strThisFileMd5);

	ZTools::UTF8ToMB(m_strComponentFileName);
	ZTools::UTF8ToMB(m_strComponentFileId);
	ZTools::UTF8ToMB(m_strComponentManifest);
	ZTools::UTF8ToMB(m_strFormFileName);
	ZTools::UTF8ToMB(m_strFormFileId);
	ZTools::UTF8ToMB(m_strFormManifest);
		
	return TRUE;
}
bool XmlSceneLoader::loadScene(std::string file, interface::Scene& scene, vector<ObjectLoaded>& objects)
{
    TiXmlDocument doc(file);

    if(!doc.LoadFile())
        return false;

    TiXmlElement* root=doc.FirstChildElement();
    TiXmlElement* elem = root;

    // first parse meshasset
    std::map<int, vector<XmlMeshAssetLoader::MeshElementModel>> meshAssets;
    std::map<int, std::string> meshAssetsName;

    int nbObject=0;

    while(elem)
    {
        if(elem->ValueStr() == std::string("MeshAsset"))
        {
            int index=-1;
            elem->QueryIntAttribute("index", &index);

            std::string name;
            meshAssets[index] = interface::XmlMeshAssetLoader::parseMeshAssetElement(elem, name);
            meshAssetsName[index] = name;
        }
        else if(elem->ValueStr() == std::string("Object"))
        {
            nbObject++;
        }
        else if(elem->ValueStr() == std::string("DirLight"))
        {
            int shadow=0;
            vec3 color = {1,1,1};
            vec3 dir={0,0,-1};

            elem->QueryIntAttribute("shadows", &shadow);
            std::string strColor = StringUtils::str(elem->Attribute("color"));
            std::string strDir = StringUtils::str(elem->Attribute("direction"));
            if(!strColor.empty()) color = toVec<3>(strColor);
            if(!strDir.empty()) dir = toVec<3>(strDir);

            scene.globalLight.dirLights.push_back({dir, vec4(color,1), shadow==1});
        }

        elem=elem->NextSiblingElement();
    }

    elem = root;
    vector<std::string> skybox;

    while(elem)
    {
        if(elem->ValueStr() == std::string("Object"))
        {
            std::string name;
            elem->QueryStringAttribute("name", &name);

            int index=-1;
            elem->QueryIntAttribute("model", &index);

            if(index < 0 || meshAssets.find(index)==meshAssets.end())
            {
                elem=elem->NextSiblingElement();
                continue;
            }

            bool isStatic = true, isPhysic = true, isVisible = true;
            elem->QueryBoolAttribute("isStatic", &isStatic);
            elem->QueryBoolAttribute("isPhysic", &isPhysic);
            elem->QueryBoolAttribute("isVisible", &isVisible);

            vec3 tr, sc;
            mat3 rot;
            ObjectLoaded obj;
            parseTransformation(elem, tr, sc, rot, &obj.collider);

            obj.name = name;
            obj.model = meshAssetsName[index];
            obj.type = ObjectLoaded::MESH_INSTANCE;
            obj.asset = meshAssets[index];
            obj.isPhysic = isPhysic;
            obj.isStatic = isStatic;
            obj.isVisible = isVisible;
            obj.scale = sc;
            obj.translation = tr;
            obj.rotation = rot;

            if(isVisible)
                obj.meshInstance = &scene.scene.add<MeshInstance>(XmlMeshAssetLoader::constructMesh(meshAssets[index], Texture::genParam(true,true,true, 0), false),
                                                                  mat4::constructTransformation(rot, tr, sc));
            else
                obj.meshInstance = nullptr;

            objects.push_back(obj);
        }
        else if(elem->ValueStr() == std::string("Skybox"))
        {
            skybox = parseSkyboxXmlElement(elem);
        }

        elem=elem->NextSiblingElement();
    }

    if(skybox.size() == 6)
    {
        scene.globalLight.skybox = renderer::IndirectLightRenderer::loadAndProcessSkybox(skybox, ShaderPool::instance().get("processSpecularCubeMap"));
    }

    return true;
}
Beispiel #28
0
void HierClassifier::loadSettings(TiXmlElement* settings){
	if(settings->QueryIntAttribute("debug", &debugLevel) != TIXML_SUCCESS){
		throw "Bad settings file - wrong debug level";
	}

	TiXmlElement* pPtr;

	/*pPtr = settings->FirstChildElement("cache");
	if(!pPtr){
		throw "Bad settings file - no cache setting for HierClassifier";
	}
	pPtr->QueryBoolAttribute("enabled", &cacheEnabled);*/

	pPtr = settings->FirstChildElement("segmentation");
	if(!pPtr){
		throw "Bad settings file - no segmentation setting for HierClassifier";
	}
	pPtr->QueryFloatAttribute("k", &kSegment);
	pPtr->QueryIntAttribute("min_size", &minSizeSegment);

	pPtr = settings->FirstChildElement("descriptor");
	if(!pPtr){
		throw "Bad settings file - no descriptor setting for HierClassifier";
	}
	std::vector<int> descLen;
	TiXmlElement* dPtr = pPtr->FirstChildElement();
	while(dPtr){
		if(dPtr->Value() == string("hist_HS")){
			dPtr->QueryIntAttribute("len_H", &histHLen);
			dPtr->QueryIntAttribute("len_S", &histSLen);
			if(descLen.size() < 1){
				descLen.resize(1);
			}
			descLen[0] = histHLen*histSLen;
		}
		else if(dPtr->Value() == string("hist_V")){
			dPtr->QueryIntAttribute("len", &histVLen);
			if(descLen.size() < 2){
				descLen.resize(2);
			}
			descLen[1] = histVLen;
		}
		else if(dPtr->Value() == string("mean_HSV")){
			dPtr->QueryIntAttribute("len", &meanHSVLen);
			if(descLen.size() < 3){
				descLen.resize(3);
			}
			descLen[2] = meanHSVLen;
		}
		else if(dPtr->Value() == string("covar_HSV")){
			dPtr->QueryIntAttribute("len", &covarHSVLen);
			if(descLen.size() < 4){
				descLen.resize(4);
			}
			descLen[3] = covarHSVLen;
		}
		else if(dPtr->Value() == string("hist_DI")){
			dPtr->QueryIntAttribute("len_D", &histDLen);
			dPtr->QueryIntAttribute("len_I", &histILen);
			if(descLen.size() < 5){
				descLen.resize(5);
			}
			descLen[4] = histDLen*histILen;
		}
		else if(dPtr->Value() == string("mean_laser")){
			dPtr->QueryIntAttribute("len", &meanLaserLen);
			if(descLen.size() < 6){
				descLen.resize(6);
			}
			descLen[5] = meanLaserLen;
		}
		else if(dPtr->Value() == string("covar_laser")){
			dPtr->QueryIntAttribute("len", &covarLaserLen);
			if(descLen.size() < 7){
				descLen.resize(7);
			}
			descLen[6] = covarLaserLen;
		}
		//else if(dPtr->Value() == string("kurt_laser")){
		//	dPtr->QueryIntAttribute("len", &kurtLaserLen);
		//	if(descLen.size() < 7){
		//		descLen.resize(7);
		//	}
		//	descLen[6] = kurtLaserLen;
		//}
		else{
			throw "Bad settings file - no such descriptor";
		}
		dPtr = dPtr->NextSiblingElement();
	}

	descBeg.assign(descLen.size(), 0);
	for(int d = 1; d < descLen.size(); d++){
		descBeg[d] = descBeg[d - 1] + descLen[d - 1];
	}
	descBeg.push_back(descBeg.back() + descLen.back());

	for(int c = 0; c < weakClassifiersSet.size(); c++){
		delete weakClassifiersSet[c];
	}
	weakClassifiersSet.clear();
	weakClassInfo.clear();

	numWeakClassifiers = 0;
	TiXmlElement* cPtr = settings->FirstChildElement("Classifier");
	while(cPtr){
		string type;
		cPtr->QueryStringAttribute("type", &type);
		if(type == "SVM"){
			weakClassifiersSet.push_back(new ClassifierSVM(cPtr));
			TiXmlElement* iPtr = cPtr->FirstChildElement("info");
			if(!iPtr){
				throw "Bad settings file - no info setting for Classifier type = SVM";
			}
			int dBeg, dEnd;
			iPtr->QueryIntAttribute("desc_beg", &dBeg);
			iPtr->QueryIntAttribute("desc_end", &dEnd);
			weakClassInfo.push_back(WeakClassifierInfo(descBeg[dBeg], descBeg[dEnd]));
		}
		else if(type == "RF"){
			weakClassifiersSet.push_back(new ClassifierRF(cPtr));
			TiXmlElement* iPtr = cPtr->FirstChildElement("info");
			if(!iPtr){
				throw "Bad settings file - no info setting for Classifier type = RF";
			}
			int dBeg, dEnd;
			iPtr->QueryIntAttribute("desc_beg", &dBeg);
			iPtr->QueryIntAttribute("desc_end", &dEnd);
			weakClassInfo.push_back(WeakClassifierInfo(descBeg[dBeg], descBeg[dEnd]));
		}
		numWeakClassifiers++;
		cPtr = cPtr->NextSiblingElement("Classifier");
	}

	numIterations = 1;
}
Beispiel #29
0
Graphe::Graphe(QString &filename){
    n=0;



    int i, j, x, y;
    TiXmlDocument doc(filename.toStdString());
    if(doc.LoadFile()){
        //TiXmlHandle hDoc(&doc);
        TiXmlElement * pGraph;
        pGraph = doc.FirstChildElement("Graph");
        if(pGraph){
            pGraph->QueryIntAttribute("n", &n);
            if(pGraph->Attribute("Title"))
                title = QString(pGraph->Attribute("Title"));
            if(pGraph->Attribute("Color")){
                if(pGraph->Attribute("Color")[0] == 'r')
                    color_r = 200;
                if(pGraph->Attribute("Color")[0] == 'b')
                    color_b = 200;

            }
            noeuds = new Noeud[n];

            labels = new QString[n];

            //Init
            for(int i=0; i<n; i++)
                labels[i]=QString();

            for(int i=0; i<n; i++){
                noeuds[i] = Noeud(50 + 40*cos(2*3.14159/n*i), 50 + 40*sin(2*3.14159/n*i));
            }

            adj = new float*[n];

            for(int i=0; i<n; i++){
                adj[i] = new float [n];
                for(int j=0; j<n; j++){
                    adj[i][j]=0.;
                }
            }
            TiXmlElement * pRoot;
            TiXmlElement * pChildren;
            std::string temps;
            pRoot = pGraph->FirstChildElement("Nodes");
            if(pRoot){
                pChildren = pRoot->FirstChildElement("Node");
                while(pChildren){
                    pChildren->QueryIntAttribute("id", &i);

                    pChildren->QueryIntAttribute("x", &x);
                    pChildren->QueryIntAttribute("y", &y);
                    noeuds[i]= Noeud(x,y);
                    if(pChildren->QueryStringAttribute("Label", &temps) == TIXML_SUCCESS)
                        labels[i]= QString(temps.c_str());
                    pChildren = pChildren->NextSiblingElement("Node");
                }
            }
            pRoot = pGraph->FirstChildElement("Arrows");
            if(pRoot){
                pChildren = pRoot->FirstChildElement("Arrow");
                while(pChildren){
                    pChildren->QueryIntAttribute("From", &i);
                    pChildren->QueryIntAttribute("To", &j);
                    setlocale(LC_NUMERIC, "C");
                    if(pChildren)
                        adj[i][j] = std::atof(pChildren->Attribute("Value"));
                    //qDebug() << i << j << pChildren->Attribute("Value");
                    pChildren = pChildren->NextSiblingElement("Arrow");
                }
            }
            this->findMaxadj();
            pRoot = pGraph ->FirstChildElement("Config");
            if(pRoot){
                pChildren = pRoot;
                setlocale(LC_NUMERIC, "C");
                if(pChildren->Attribute("ScaleMax"))
                    maxadj=std::atof(pChildren->Attribute("ScaleMax"));

            }
        }
    }

}
  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;
  }