Ejemplo n.º 1
0
    /**Creates an instance of a function
     * @param input :: An input string which defines the function and initial values for the parameters.
     * Parameters of different functions are separated by ';'. Parameters of the same function
     * are separated by ','. parameterName=value pairs are used to set a parameter value. For each function
     * "name" parameter must be set to a function name. E.g.
     * input = "name=LinearBackground,A0=0,A1=1; name = Gaussian, PeakCentre=10.,Sigma=1"
     * @return A pointer to the created function
     */
    IFitFunction* FunctionFactoryImpl::createInitialized(const std::string& input) const
    {
      //std::vector<std::string> ops;
      //ops.push_back(";");
      //ops.push_back(",");
      //ops.push_back("=");
      //ops.push_back("== < > <= >=");

      Expression expr;
      try
      {
        expr.parse(input);
      }
      catch(...)
      {
        inputError(input);
      }

      const Expression& e = expr.bracketsRemoved();

      if (e.name() == ";")
      {
        IFitFunction* fun = createComposite(e);
        if (!fun) inputError();
        return fun;
      }

      return createSimple(e);

    }
void LLViewerTexLayerSet::requestUpdate()
{
	if( mUpdatesEnabled )
	{
		createComposite();
		getViewerComposite()->requestUpdate(); 
	}
}
Ejemplo n.º 3
0
/**Creates an instance of a function
 * @param input :: An input string which defines the function and initial values
 * for the parameters.
 * Parameters of different functions are separated by ';'. Parameters of the
 * same function
 * are separated by ','. parameterName=value pairs are used to set a parameter
 * value. For each function
 * "name" parameter must be set to a function name. E.g.
 * input = "name=LinearBackground,A0=0,A1=1; name = Gaussian,
 * PeakCentre=10.,Sigma=1"
 * @return A pointer to the created function
 */
IFunction_sptr
FunctionFactoryImpl::createInitialized(const std::string &input) const {
  Expression expr;
  try {
    expr.parse(input);
  } catch (...) {
    inputError(input);
  }

  const Expression &e = expr.bracketsRemoved();
  std::map<std::string, std::string> parentAttributes;
  if (e.name() == ";") {
    IFunction_sptr fun = createComposite(e, parentAttributes);
    if (!fun)
      inputError();
    return fun;
  }

  return createSimple(e, parentAttributes);
}
Ejemplo n.º 4
0
// ---
QGAMES::CompositeObject* QGAMES::ObjectBuilder::readComposite (TiXmlElement* e)
{
	int id = -1;
	double x, y, z;
	x = y = x = 0.0;
	QGAMES::Objects objs;
	std::map <std::string, std::string> pties;
	e -> Attribute (__QGAMES_COMPOSITEATTRID__, &id);
	e -> Attribute (__QGAMES_COMPOSITEATTRX__, &x);
	e -> Attribute (__QGAMES_COMPOSITEATTRY__, &y);
	e -> Attribute (__QGAMES_COMPOSITEATTRZ__, &z);
	assert (id != -1);

	// Read the elements this composite is made up of
	for (TiXmlElement* groupElement = e -> FirstChildElement ();
		groupElement != NULL; groupElement = groupElement -> NextSiblingElement ())
	{
		// One element...
		if (strcmp (groupElement -> Value (), __QGAMES_ELEMENTSBLOCK__) == 0)
		{
			int idElmnt = -1;
			QGAMES::Object* obj = NULL;
			groupElement -> Attribute (__QGAMES_COMPOSITEATTRID__, &idElmnt);
			std::map <int, QGAMES::Object*>::const_iterator i = _objects.find (idElmnt);
			assert (i != _objects.end ());
			objs.push_back ((*i).second); // The composite doesn't own its objects...
		}

		// The attributes zone...
		// There should be one zone of this maximum (as DTD definition)
		// If there is more than one, then the properties will be relaced
		if (strcmp (groupElement -> Value (), __QGAMES_ATTRSBLOCK__) == 0)
			pties = readPropertiesSection (groupElement);
	}

	// Creates the composite object and returns...
	return (createComposite (id, QGAMES::Position (__BD x, __BD y, __BD z), objs, pties));
}
Ejemplo n.º 5
0
    /** 
     * Create a composite function from an expression.
     * @param expr :: The input expression
     * @return A pointer to the created function
     */
    CompositeFunction* FunctionFactoryImpl::createComposite(const Expression& expr)const
    {
      if (expr.name() != ";") inputError(expr.str());

      if (expr.size() == 0)
      {
        return 0;
      }

      const std::vector<Expression>& terms = expr.terms();
      std::vector<Expression>::const_iterator it = terms.begin();
      const Expression& term = it->bracketsRemoved();

      CompositeFunction* cfun = 0;
      std::string wsName,wsParam;
      if (term.name() == "=")
      {
        if (term.terms()[0].name() == "composite")
        {
          cfun = dynamic_cast<CompositeFunction*>(createFunction(term.terms()[1].name()));
          if (!cfun) inputError(expr.str());
          ++it;
        }
        else if (term.terms()[0].name() == "name")
        {
          cfun = dynamic_cast<CompositeFunction*>(createFunction("CompositeFunctionMW"));
          if (!cfun) inputError(expr.str());
        }
        else
        {
          inputError(expr.str());
        }
      }
      else if (term.name() == ",")
      {
        std::vector<Expression>::const_iterator firstTerm = term.terms().begin();
        if (firstTerm->name() == "=")
        {
          if (firstTerm->terms()[0].name() == "composite")
          {
            cfun = dynamic_cast<CompositeFunction*>(createSimple(term));
            if (!cfun) inputError(expr.str());
            ++it;
          }
          else if (firstTerm->terms()[0].name() == "name")
          {
            cfun = dynamic_cast<CompositeFunction*>(createFunction("CompositeFunctionMW"));
            if (!cfun) inputError(expr.str());
          }
          else
          {
            inputError(expr.str());
          }
        }
      }
      else if (term.name() == ";")
      {
        cfun = dynamic_cast<CompositeFunction*>(createFunction("CompositeFunctionMW"));
        if (!cfun) inputError(expr.str());
      }
      else
      {
        inputError(expr.str());
      }

      for(;it!=terms.end();++it)
      {
        const Expression& term = it->bracketsRemoved();
        IFitFunction* fun = NULL;
        if (term.name() == ";")
        {
          fun = createComposite(term);
          if (!fun) continue;
        }
        else
        {
          std::string parName = term[0].name();
          std::string parValue = term[1].str();
          if (term[0].name().size() >= 10 && term[0].name().substr(0,10) == "constraint")
          {
            addConstraints(cfun,term[1]);
            continue;
          }
          else if (term[0].name() == "ties")
          {
            addTies(cfun,term[1]);
            continue;
          }
          else if (parName == "Workspace")
          {
            wsName = parValue;
          }
          else if (parName == "WSParam")
          {
            wsParam = parValue;
          }
          else
          {
            fun = createSimple(term);
          }
        }
        cfun->addFunction(fun);
      }

      if (!wsName.empty())
      {
        Workspace_sptr ws = AnalysisDataService::Instance().retrieve(wsName);
        cfun->setWorkspace(ws,wsParam);
      }

      return cfun;
    }
void LLViewerTexLayerSet::updateComposite()
{
	createComposite();
	getViewerComposite()->requestUpdateImmediate();
}
void LLViewerTexLayerSet::requestUpload()
{
	createComposite();
	getViewerComposite()->requestUpload();
}
Ejemplo n.º 8
0
/**
 * Create a composite function from an expression.
 * @param expr :: The input expression
 * @param parentAttributes :: An output map filled with the attribute name &
 * values of the parent function
 * @return A pointer to the created function
 */
CompositeFunction_sptr FunctionFactoryImpl::createComposite(
    const Expression &expr,
    std::map<std::string, std::string> &parentAttributes) const {
  if (expr.name() != ";")
    inputError(expr.str());

  if (expr.size() == 0) {
    return CompositeFunction_sptr();
  }

  const std::vector<Expression> &terms = expr.terms();
  auto it = terms.cbegin();
  const Expression &term = it->bracketsRemoved();

  CompositeFunction_sptr cfun;
  if (term.name() == "=") {
    if (term.terms()[0].name() == "composite") {
      cfun = boost::dynamic_pointer_cast<CompositeFunction>(
          createFunction(term.terms()[1].name()));
      if (!cfun)
        inputError(expr.str());
      ++it;
    } else if (term.terms()[0].name() == "name") {
      cfun = boost::dynamic_pointer_cast<CompositeFunction>(
          createFunction("CompositeFunction"));
      if (!cfun)
        inputError(expr.str());
    } else {
      inputError(expr.str());
    }
  } else if (term.name() == ",") {
    auto firstTerm = term.terms().cbegin();
    if (firstTerm->name() == "=") {
      if (firstTerm->terms()[0].name() == "composite") {
        cfun = boost::dynamic_pointer_cast<CompositeFunction>(
            createSimple(term, parentAttributes));
        if (!cfun)
          inputError(expr.str());
        ++it;
      } else if (firstTerm->terms()[0].name() == "name") {
        cfun = boost::dynamic_pointer_cast<CompositeFunction>(
            createFunction("CompositeFunction"));
        if (!cfun)
          inputError(expr.str());
      } else {
        inputError(expr.str());
      }
    }
  } else if (term.name() == ";") {
    cfun = boost::dynamic_pointer_cast<CompositeFunction>(
        createFunction("CompositeFunction"));
    if (!cfun)
      inputError(expr.str());
  } else {
    inputError(expr.str());
  }

  if (!cfun)
    inputError(expr.str());

  for (; it != terms.end(); ++it) {
    const Expression &term = it->bracketsRemoved();
    IFunction_sptr fun;
    std::map<std::string, std::string> pAttributes;
    if (term.name() == ";") {
      fun = createComposite(term, pAttributes);
      if (!fun)
        continue;
    } else {
      std::string parName = term[0].name();
      if (parName.size() >= 10 && parName.substr(0, 10) == "constraint") {
        addConstraints(cfun, term[1]);
        continue;
      } else if (parName == "ties") {
        addTies(cfun, term[1]);
        continue;
      } else {
        fun = createSimple(term, pAttributes);
      }
    }
    cfun->addFunction(fun);
    size_t i = cfun->nFunctions() - 1;
    for (auto &pAttribute : pAttributes) {
      // Apply parent attributes of the child function to this function. If this
      // function doesn't have those attributes, they get passed up the chain to
      // this function's parent.
      if (cfun->hasLocalAttribute(pAttribute.first)) {
        cfun->setLocalAttributeValue(i, pAttribute.first, pAttribute.second);
      } else {
        parentAttributes[pAttribute.first] = pAttribute.second;
      }
    }
  }

  if (cfun) {
    cfun->applyTies();
  }
  return cfun;
}
Ejemplo n.º 9
0
    /** 
     * Create a composite function from an expression.
     * @param expr :: The input expression
     * @param parentAttributes :: An output map filled with the attribute name & values of the parent function
     * @return A pointer to the created function
     */
    CompositeFunction_sptr FunctionFactoryImpl::createComposite(const Expression& expr, std::map<std::string,std::string>& parentAttributes)const
    {
      if (expr.name() != ";") inputError(expr.str());

      if (expr.size() == 0)
      {
        return CompositeFunction_sptr();
      }

      const std::vector<Expression>& terms = expr.terms();
      std::vector<Expression>::const_iterator it = terms.begin();
      const Expression& term = it->bracketsRemoved();

      CompositeFunction_sptr cfun;
      if (term.name() == "=")
      {
        if (term.terms()[0].name() == "composite")
        {
          cfun = boost::dynamic_pointer_cast<CompositeFunction>(createFunction(term.terms()[1].name()));
          if (!cfun) inputError(expr.str());
          ++it;
        }
        else if (term.terms()[0].name() == "name")
        {
          cfun = boost::dynamic_pointer_cast<CompositeFunction>(createFunction("CompositeFunction"));
          if (!cfun) inputError(expr.str());
        }
        else
        {
          inputError(expr.str());
        }
      }
      else if (term.name() == ",")
      {
        std::vector<Expression>::const_iterator firstTerm = term.terms().begin();
        if (firstTerm->name() == "=")
        {
          if (firstTerm->terms()[0].name() == "composite")
          {
            cfun = boost::dynamic_pointer_cast<CompositeFunction>(createSimple(term,parentAttributes));
            if (!cfun) inputError(expr.str());
            ++it;
          }
          else if (firstTerm->terms()[0].name() == "name")
          {
            cfun = boost::dynamic_pointer_cast<CompositeFunction>(createFunction("CompositeFunction"));
            if (!cfun) inputError(expr.str());
          }
          else
          {
            inputError(expr.str());
          }
        }
      }
      else if (term.name() == ";")
      {
        cfun = boost::dynamic_pointer_cast<CompositeFunction>(createFunction("CompositeFunction"));
        if (!cfun) inputError(expr.str());
      }
      else
      {
        inputError(expr.str());
      }

      for(;it!=terms.end();++it)
      {
        const Expression& term = it->bracketsRemoved();
        IFunction_sptr fun;
        std::map<std::string,std::string> pAttributes;
        if (term.name() == ";")
        {
          fun = createComposite(term,pAttributes);
          if (!fun) continue;
        }
        else
        {
          std::string parName = term[0].name();
          if (parName.size() >= 10 && parName.substr(0,10) == "constraint")
          {
            addConstraints(cfun,term[1]);
            continue;
          }
          else if (parName == "ties")
          {
            addTies(cfun,term[1]);
            continue;
          }
          else
          {
            fun = createSimple(term,pAttributes);
          }
        }
        cfun->addFunction(fun);
        size_t i = cfun->nFunctions() - 1;
        for(auto att = pAttributes.begin(); att != pAttributes.end(); ++att)
        {
          cfun->setLocalAttributeValue(i,att->first,att->second);
        }
      }

      cfun->applyTies();
      return cfun;
    }