Exemple #1
0
bool 
Frame::has_references () const
{
  std::set<symbol> all;
  entries (all);
  
  for (std::set<symbol>::const_iterator i = all.begin ();
       i != all.end ();
       i++)
    {
      const symbol key = *i;
      if (is_reference (key))
        return true;;
      if (!check (key))
        continue;
      
      Attribute::type type = lookup (key);
      int size = type_size (key);
      switch (type)
        {
        case Attribute::Submodel:
          if (size == Attribute::Singleton)
            {
              if (submodel (key).has_references ())
                return true;
            }
          else
            {
              const std::vector<boost::shared_ptr<const FrameSubmodel> >& models
                = submodel_sequence (key);
              for (size_t i = 0; i < models.size (); i++)
                if (models[i]->has_references ())
                  return true;
            }
          break;
        case Attribute::Model:
          if (size == Attribute::Singleton)
            {
              if (model (key).has_references ())
                return true;
            }
          else
            {
              const std::vector<boost::shared_ptr<const FrameModel> >& models
                = model_sequence (key);
              for (size_t i = 0; i < models.size (); i++)
                if (models[i]->has_references ())
                  return true;
            }
          break;
        default:
          break;
        }
    }
  return false;
}
Exemple #2
0
bool ObjectModelReader::readParallelpipedModel(SpModelInterface model, QDomNode& n) {
    QDomElement e;
    QString aux;
    QDomNode m, v;
    std::vector<QString> names;
    names.push_back("width");
    names.push_back("height");
    names.push_back("depth");
    names.push_back("velocity");

    std::vector<QString>::iterator it, it_end = names.end();
    model->velocity_defined = false;
    for(it = names.begin(); it != it_end; it++) {
        if( ( m = XmlCommon::getParameterNode(*it, n) ).isNull() ) {
            if(*it != "velocity") { //It can be undefined, as a default is built
                AppendToLog("ObjectModelReader: Error reading ParallelpipedModel. Attribute model parameter " + *it + " must be defined for a ParallelpipedModel in file '" + m_fileName + "'. Execution will be aborted.");
                return false;
            }
        } else {
            e = m.toElement();
            if( !e.isNull() ) {
                if( (aux = e.attribute( "model", "" )) != "GaussianFunction" ) {
                    AppendToLog("ObjectModelReader: Error reading ParallelpipedModel. Parameter 'model' value '" + aux + "' does not define an available attribute model in file '" + m_fileName + "'. Valid models are: ParallelpipedModel. Execution will be aborted.");
                    return false;
                }
            } else  {
                AppendToLog("ObjectModelReader: ParallelpipedModel: Error reading XML information. Node to element transform failed in file '" + m_fileName + "'. Execution will be aborted.");
                return false;
            }
            SpGaussianFunction g(new GaussianFunction());
            g->setParameters(m);
            (model->m_mapCriteria)[*it].score = 0.0;
            model->m_mapCriteria[*it].reliability = 0.0;
            model->m_mapCriteria[*it].spFunction = g;
            if(*it == "velocity")
                model->velocity_defined = true;
        }
    }

    if(!model->velocity_defined) {
        double max = m_data->sceneModel->m_MaximalObjectSpeed;        
        SpGaussianFunction g(new GaussianFunction());
        g->mean = max/2.0;
        g->sigma = max*2.0;
        g->min = 0.0;
        g->max = max;
        model->m_mapCriteria["velocity"].spFunction = g;
        model->m_mapCriteria["velocity"].score = 0.0;
        model->m_mapCriteria["velocity"].reliability = 0.0;
    }

    if(!model->IsRigid) {
        if( ( m = XmlCommon::getParameterNode("PostureList", n) ).isNull() ) {
            AppendToLog("ObjectModelReader: reading ParallelpipedModel: warning: Parameter 'PostureList' not defined for a postural object. Changing to rigid.");
            model->IsRigid = true;
        } else {
            QDomNode k = m.toElement().firstChild();
            QString omodel;
            ObjectSubtype subtype;
            if(k.isNull()) {
                AppendToLog("ObjectModelReader: reading ParallelpipedModel: warning: No parameters 'Posture' inside 'PostureList'. Changing to rigid.");
                model->IsRigid = true;
            }
            while( !k.isNull() ) {
                e = k.toElement();
                SpModelInterface submodel(new ModelInterface(m_data));
                if( !e.isNull() ) {
                    if( e.tagName() == "Posture" ) {
                        if( (aux = e.attribute( "name", "" )) == "") {
                            AppendToLog("ObjectModelReader: Error reading XML information. Undefined attribute 'name' for Posture in file '" + m_fileName + "'. Execution will be aborted.");
                            return false;
                        }
                        subtype = Blob::getSubtypeFromName(aux.toStdString());
                        if(subtype == ST_UNKNOWN) {
                            AppendToLog("ObjectModelReader: Error reading XML information. Attribute 'name' does not correspond to any pre-defined subtype. Check ObjectSubtype in file 'src/common.h' for allowed subtypes. Execution will be aborted.");
                            return false;
                        }

                        submodel->IsRigid = true;

                        if( (omodel = e.attribute( "model", "" )) == "") {
                            AppendToLog("ObjectModelReader: Error reading XML information. Undefined attribute 'model' for ObjectModel in file '" + m_fileName + "'. Execution will be aborted.");
                            return false;
                        }
                    }
                } else {
                    AppendToLog("ObjectModelReader: Parallelpiped model: Error reading XML information. Node to element transform failed in file '" + m_fileName + "'. Execution will be aborted.");
                    return false;
                }

                if(omodel == "ParallelpipedModel") {
                    if(!readParallelpipedModel(submodel, k))
                        return false;
                } else {
                    AppendToLog("ParallelpipedModel: Error reading XML information. Parameter 'model' value '" + omodel + "' does not define an available object model in file '" + m_fileName + "'. Valid models are: ParallelpipedModel. Execution will be aborted.");
                    return false;
                }

                model->addSubModel(subtype, submodel);
                k = k.nextSibling();
            }
        }
    }
    return true;
}