Exemplo n.º 1
0
void VolumeFiltering::process() {
    if (!enableProcessing_.get()) {
        outport_.setData(const_cast<VolumeBase*>(inport_.getData()), false);
    }
    else if (forceUpdate_ || inport_.hasChanged()) {
        applyOperator();
    }
}
bool BoolLogicCondition::isConditionTrue() const{
  ConstConditionList::const_iterator it = conditions_.begin();
  bool toReturn = (*it)->isConditionTrue();
  ++it;
  for(;it != conditions_.end(); ++it){
    toReturn = applyOperator(toReturn,(*it)->isConditionTrue());
  }
  return toReturn;
}
Exemplo n.º 3
0
void VolumeFiltering::process() {
    if (!enableProcessing_.get()) {
        outport_.setData(inport_.getData());
        volumeOwner_ = false;
    }
    else if (forceUpdate_ || inport_.hasChanged()) {
        applyOperator();
    }
}
Exemplo n.º 4
0
void RawModel::updateOperators(QModelIndexList chlist) {
    if(chlist.empty())
        for(qint32 i=0; i < m_chInfolist.size(); ++i)
            chlist.append(createIndex(i,1));

    for(qint32 i=0; i < chlist.size(); ++i) {
        if(m_assignedOperators.contains(chlist[i].row()))
            for(qint32 j=0; j < m_assignedOperators.values(chlist[i].row()).size(); ++j)
                applyOperator(chlist[i],m_assignedOperators.values(chlist[i].row())[j],true);
    }
}
Exemplo n.º 5
0
void RawModel::applyOperator(QModelIndexList chlist, const QSharedPointer<MNEOperator>& operatorPtr, bool reset)
{
    //filter all when chlist is empty
    if(chlist.empty()) {
        for(qint32 i=0; i < m_chInfolist.size(); ++i)
            chlist.append(createIndex(i,1));
    }

    for(qint32 i=0; i < chlist.size(); ++i) { //iterate through selected channels to filter
        applyOperator(chlist[i],operatorPtr,reset);
    }

    qDebug() << "RawModel: using FilterType" << operatorPtr->m_sName;
}
void CSEMachine::processCurrentToken(Token &currToken,stack<Token> &controlStack, stack<Token> &executionStack)
{
	if(currToken.type == RecursiveParser::OPT)
	{
		Token firstToken = executionStack.top();
		executionStack.pop();
		Token secondToken = executionStack.top();
		executionStack.pop();
		Token resultToken = applyOperator(firstToken, secondToken, currToken);		
		executionStack.push(resultToken);
	}
	else if(currToken.type == "neg")
	{
		Token firstToken = executionStack.top();
		executionStack.pop();
		int paramVal = atoi(firstToken.value.c_str());
		paramVal = -paramVal;
		Token newToken(intToString(paramVal), RecursiveParser::INT);
		executionStack.push(newToken);
	}
	else if(currToken.type =="not")
	{
		Token firstToken = executionStack.top();
		executionStack.pop();
		if(firstToken.value != "true")
		{			
			executionStack.push(Token("true","true"));
		}
		else
		{
			executionStack.push(Token("false","false"));
		}
	}
	else if(currToken.type == RecursiveParser::ID && isParamter(currToken))
	{
		string varName = currToken.value;
		int temp = currEnv;
	
		pair<int,string> keyPair(temp,varName);
		map<key_pair,Token>::iterator it = paramMap.find(keyPair);
		while(paramMap.end() == it && temp>=0)
		{
			temp = envMap[temp];
			keyPair.first = temp;		
			it = paramMap.find(keyPair);
		}
		if(paramMap.end() != it)
		{
			Token paramValToken = it->second;		
			executionStack.push(paramValToken);
		}
	}
	else if(currToken.type == "gamma")
	{
		Token topExeToken = executionStack.top();
		executionStack.pop();
		if(topExeToken.type == "lambdaClosure")
		{
			Token env("env",++envCounter);		
			envMap[envCounter] = topExeToken.lambdaEnv;
			envStack.push(envCounter);
			currEnv = envCounter;
			if(topExeToken.isTuple == false)
			{
				string paramName = topExeToken.lambdaParam;
				Token paramToken = executionStack.top();
				executionStack.pop();			
				pair<int,string> keyPair(envCounter,paramName);
				paramMap[keyPair] = paramToken;				
			}
			else
			{			
				string tuple = topExeToken.lambdaParam;
				vector<string> params = split(tuple,',');
				Token valueTuple = executionStack.top();			
				executionStack.pop();
				vector<Token> tupleVector = valueTuple.tuple;
				unsigned int i=0;				
				
				while(i<params.size())
				{
					if(params[i] != "")
					{
						pair<int,string> keyPair(envCounter,params[i].c_str());
						paramMap[keyPair] = tupleVector[i];
					}				
					i++;	
				}				
			}
			controlStack.push(env);
			executionStack.push(env);
			int lambdaNum = topExeToken.lambdaNum;
			vector<Token> delta = deltaMap[lambdaNum];
			int i=0;
			
			while(i<delta.size())
			{
				controlStack.push(delta[i]);
				i++;
			}
		}
		else if(topExeToken.type == "YSTAR")
		{
			Token nextToken = executionStack.top();		
			executionStack.pop();
			nextToken.type ="eta";
			executionStack.push(nextToken);
		}
		else if(topExeToken.type == "eta")
		{
			Token lambdaToken = topExeToken;
			lambdaToken.type = "lambdaClosure";
			executionStack.push(topExeToken);
			executionStack.push(lambdaToken);
		
			Token gammaToken("gamma","gamma");
			controlStack.push(gammaToken);
			controlStack.push(gammaToken);
		}
		else if(topExeToken.value == "Stern" || topExeToken.value == "stern")
		{
			Token stringToken = executionStack.top();
			executionStack.pop();
			string tokenValue = stringToken.value;
			tokenValue = tokenValue.substr(2,tokenValue.size()-3);
			tokenValue = "'"+tokenValue+"'";
			stringToken.value = tokenValue;
			executionStack.push(stringToken);
		}
		else if(topExeToken.value == "Stem" || topExeToken.value == "stem")
		{
			Token stringToken = executionStack.top();
			executionStack.pop();
			string tokenValue = stringToken.value;
			tokenValue = tokenValue.substr(1,1);
			tokenValue = "'"+tokenValue+"'";
			stringToken.value = tokenValue;
			executionStack.push(stringToken);
		}
		else if(topExeToken.value == "Conc" || topExeToken.value == "conc")
		{
			Token firstToken = executionStack.top();
			executionStack.pop();
			Token secondToken = executionStack.top();
			executionStack.pop();		
			string concatValue = firstToken.value.substr(1,firstToken.value.size()-2)+secondToken.value.substr(1,secondToken.value.size()-2);
			concatValue = "'"+concatValue+"'";			
			Token newToken(concatValue,RecursiveParser::STR);
			executionStack.push(newToken);			
			controlStack.pop();
		}
		else if(topExeToken.value == "ItoS" || topExeToken.value == "itos")
		{
			Token firstToken = executionStack.top();
			executionStack.pop();
			firstToken.type = RecursiveParser::STR;
			firstToken.value = "'"+firstToken.value+"'";
			executionStack.push(firstToken);		
		}
		else if(topExeToken.value == "Print" || topExeToken.value == "print")
		{
			printCalled = true;		
			Token t = executionStack.top();
			executionStack.pop();
			if(t.isTuple != true)
			{
				if(t.type== RecursiveParser::STR)
				{
					string tempStr =unescape(t.value.substr(1,t.value.size()-2));
					cout << tempStr;
					if(tempStr[tempStr.size()-1] == '\n')
						cout<<endl;				
				}
				else if(t.type == "lambdaClosure")
				{
					cout <<"[lambda closure: "<<t.lambdaParam<<": "<<t.lambdaNum<<"]";
				}
				else
				{				
					cout<<t.value;
				}
				Token dummyToken("dummy","dummy");
				executionStack.push(dummyToken);
			}
			else
			{
				vector<Token> tupleVector = t.tuple;
				int i=0;
			
				while(i<tupleVector.size())
				{
					if(i!=0)
					{						
						cout<<", ";
					}
					else
					{
						cout<<"(";
					}
					if(tupleVector[i].type == RecursiveParser::STR)
					{
						cout<< unescape(tupleVector[i].value.substr(1,tupleVector[i].value.size()-2));
					}
					else if(tupleVector[i].isTuple == true )
					{
						cout<<"Inside else if"<<endl;
						vector<Token> innerTuple = tupleVector[i].tuple;
						cout << "Size" << innerTuple.size()<<endl;
						if(innerTuple.size() == 1)
						{
							if(innerTuple[0].type == RecursiveParser::STR)
								cout<< unescape(innerTuple[0].value.substr(1,innerTuple[0].value.size()-2));
						}
					}
					else
					{
						cout << tupleVector[i].value;
					}
					if(i==tupleVector.size() -1)
					{
						cout<<")";
					}
					i++;
				}
			}			
		}
		else if(topExeToken.value == "Isinteger")
		{
			Token t = executionStack.top();
			executionStack.pop();
			if (t.type == RecursiveParser::INT)
				executionStack.push(Token("true","true"));
			else
				executionStack.push(Token("false","false"));
		}
		else if(topExeToken.value == "Istruthvalue")
		{
			Token t = executionStack.top();
			executionStack.pop();
			if (t.value=="true" || t.value=="false")
				executionStack.push(Token("true","true"));
			else
				executionStack.push(Token("false","false"));
		}
		else if(topExeToken.value == "Isstring")
		{
			Token t = executionStack.top();
			executionStack.pop();
			if (t.type==RecursiveParser::STR)
				executionStack.push(Token("true","true"));
			else
				executionStack.push(Token("false","false"));
		}
		else if(topExeToken.value == "Istuple")
		{		
			Token t = executionStack.top();
			executionStack.pop();
			if (t.isTuple==true)
				executionStack.push(Token("true","true"));
			else
				executionStack.push(Token("false","false"));
		}
		else if(topExeToken.value == "Isdummy")
		{
			Token t = executionStack.top();
			executionStack.pop();
			if (t.value=="dummy")
				executionStack.push(Token("true","true"));
			else
				executionStack.push(Token("false","false"));
		}
		else if(topExeToken.value == "Isfunction")
		{
			Token t = executionStack.top();
			executionStack.pop();
			if (t.type=="lambdaClosure")
				executionStack.push(Token("true","true"));
			else
				executionStack.push(Token("false","false"));
		}
		else if(topExeToken.value == "Order")
		{		
			Token t = executionStack.top();
			executionStack.pop();			
			executionStack.push(Token(intToString(t.tuple.size()),RecursiveParser::INT));
		}
		else if(topExeToken.value == "Null")
		{		
			Token t = executionStack.top();
			executionStack.pop();
			if (t.value == "nil")
				executionStack.push(Token("true","true"));
			else
				executionStack.push(Token("false","false"));
		}
		else if(topExeToken.isTuple == true)
		{
			Token t = executionStack.top();
			executionStack.pop();
			if(t.type == RecursiveParser::INT)
			{
				int indx = atoi(t.value.c_str());
				indx -=1;
				executionStack.push(topExeToken.tuple[indx]);
			}
		}
	}
	else if(currToken.type == "env")
	{
		Token topToken = executionStack.top();
		executionStack.pop();
		executionStack.pop();
		executionStack.push(topToken);
		envStack.pop();
		currEnv = envStack.top();
	}
	else if(currToken.type == "beta")
	{
		Token topToken = executionStack.top();
		executionStack.pop();
		vector<Token> delta;
		unsigned int i=0;
		
		if(topToken.value != "true")
		{			
			delta = deltaMap[currToken.betaElseDeltaNum];
		}
		else
		{
			delta = deltaMap[currToken.betaIfDeltaNum];
		}
		
		while(i<delta.size())	
		{
			controlStack.push(delta[i]);
			i++;
		}
	}
	else if(currToken.value == "tau")
	{
		int tauCount = currToken.tauCount;	
		string tuple="(";
		vector<Token> tupleVector;
		int i=0;
		
		while(i<tauCount)	
		{
			Token t = executionStack.top();
			tupleVector.push_back(t);
			executionStack.pop();
			if(i != tauCount -1)				
				tuple += t.value +", ";
			else
				tuple += t.value;
			i++;
		}
		tuple +=")";		
		Token newToken(tuple,"tuple");
		newToken.tuple = tupleVector;
		newToken.isTuple = true;
		executionStack.push(newToken);
	}
	else if(currToken.value == "nil")
	{
		currToken.isTuple = true;
		executionStack.push(currToken);
	}
	else if(currToken.value == "aug")
	{	
		Token tuple = executionStack.top();
		executionStack.pop();
		Token toAdd = executionStack.top();
		executionStack.pop();
		if(tuple.value == "nil")
		{		
			Token newToken(toAdd.value,"tuple");
			newToken.isTuple = true;
			newToken.tuple = vector<Token>();
			newToken.tuple.push_back(toAdd);
			executionStack.push(newToken);
		}
		else
		{
			tuple.tuple.push_back(toAdd);
			executionStack.push(tuple);
		}
	}
	else if(currToken.type == "lambdaClosure")
	{	
		currToken.lambdaEnv = currEnv;
		executionStack.push(currToken);
	}
	else
	{
		executionStack.push(currToken);
	}
}
Exemplo n.º 7
0
/* adding code here to make sure the resulting x,y,z values is in [0:1] 
 * for instance, -1/2-x should really be -1/2-x+1 
 */
bool UnitCell::applyOperator(const char* xyz)
{
	lua_State* L = lua_open();
	luaL_openlibs(L);
	
	char* operation = new char[strlen(xyz)+1];
	int n = strlen(xyz);
	for(int i=0; i<n; i++)
	{
		operation[i] = lcase(xyz[i]);
	}
	operation[n] = 0;
	
	char* cmd = new char[strlen(xyz) + 1024];
	
	sprintf(cmd, "function op(x, y, z) return %s end", operation);

	if(luaL_dostring(L, cmd))
	{
		lua_close(L);
		return false;
	}
	
	lua_getglobal(L, "op");
	
	/* test for data range */
	{
		lua_pushvalue(L, -1);
		lua_pushnumber(L, 0.5);
		lua_pushnumber(L, 0.5);
		lua_pushnumber(L, 0.5);
		if(lua_pcall(L, 3,3,0))
		{
			lua_close(L);
			return false;
		}
		double xyz[3];
		xyz[0] = lua_tonumber(L, -3);
		xyz[1] = lua_tonumber(L, -2);
		xyz[2] = lua_tonumber(L, -1);
		
		double d[3] = {0,0,0};

		for(int i=0; i<3; i++)
		{
			while((xyz[i]+d[i]) < 0.25) d[i]++;
			while((xyz[i]+d[i]) > 0.75) d[i]--;
		}
		
		sprintf(cmd, "function op(x, y, z)\n\ta,b,c = %s\n\treturn a+%f,b+%f,c+%f end\n", operation, d[0], d[1], d[2]);
		if(luaL_dostring(L, cmd))
		{
			lua_close(L);
			return false;
		}
		lua_pop(L, lua_gettop(L));
		lua_getglobal(L, "op");
	}
	
	bool r = applyOperator(L, lua_gettop(L));
	
	lua_close(L);
	return r;
}
Exemplo n.º 8
0
void RawModel::updateOperators(QModelIndex chan) {
    for(qint32 i=0; i < m_assignedOperators.values(chan.row()).size(); ++i)
        applyOperator(chan,m_assignedOperators.values(chan.row())[i],true);
}
Exemplo n.º 9
0
int main() {
    ActionStack *actionStack = newActionStack(STACK_SIZE);
    OperatorStack *operatorStack = newOperatorStack(STACK_SIZE);
    OperandStack *operandStack = newOperandStack(STACK_SIZE);

    pushOperatorStack(operatorStack, EMP);

    char c = EOF;
    while ((c = (char)getchar()) != '\n' && c != EOF) {
        float x;
        Operator currOperator = EMP;

        switch (c) {
            case K_SPACE: break;
            case K_SUB:
                // Is unary minus
                if (popActionStack(actionStack) &&
                    popActionStack(actionStack)) {
                    currOperator = UNA;
                } else {
                    currOperator = SUB;
                }
                break;
            case K_ADD: currOperator = ADD; break;
            case K_DIV: currOperator = DIV; break;
            case K_MUL: currOperator = MUL; break;
            case K_LBR: currOperator = LBR; break;
            case K_RBR: currOperator = RBR; break;
            default:
                ungetc(c, stdin);
                if (scanf("%f", &x) != 1) {
                    throw_error("[error]");
                    exit(0);
                } else {
                    pushOperandStack(operandStack, x);
                    pushActionStack(actionStack, OPERAND_ACTION);
                }
                continue;
        }

        if (currOperator != EMP) {
            // push LBR into operatorStack
            if (currOperator == LBR) {
                pushOperatorStack(operatorStack, currOperator);
                pushActionStack(actionStack, OPERATOR_ACTION);
                continue;
            }

            // evaluate expression inside brackets
            if (currOperator == RBR) {
                Operator operatorForApply;
                while ((operatorForApply = popOperatorStack(operatorStack)) !=
                       LBR) {
                    applyOperator(operandStack, actionStack, operatorForApply);
                }
                continue;
            }

            // Insert current operator
            Operator prevOperator = popOperatorStack(operatorStack);
            if ((int)prevOperator < (int)currOperator ) {
                pushOperatorStack(operatorStack, prevOperator);
            } else {
                applyOperator(operandStack, actionStack, prevOperator);
            }

            pushOperatorStack(operatorStack, currOperator);
            pushActionStack(actionStack, OPERATOR_ACTION);
        }
    }
    // Evaluate result
    Operator operator;
    while ((operator= popOperatorStack(operatorStack)) != EMP) {
        applyOperator(operandStack, actionStack, operator);
    }

    // Round and Print result
    printf("%.2f", roundf(popOperandStack(operandStack) * 100) / 100);

    // Clean up
    deleteActionStack(actionStack);
    deleteOperatorStack(operatorStack);
    deleteOperandStack(operandStack);

    return 0;
}