Package es.iiia.shapegrammar.execution

Examples of es.iiia.shapegrammar.execution.StateExecution


    this.shapeBasket.clear();

    // init start state
    ShapeModel startShape = this.getGrammar().getStartShape().clone();
    startShape.moveToCenter();
    this.startState = new StateExecution(startShape, new AffineTransform());

    // add first shape to the basket
    this.shapeBasket.add(getStartState().getShape());

    // init protocol
View Full Code Here


  protected void expandState(StateExecution state) {
    // set that this step has been expanded and executed
    state.setExecuted(true);

    StateExecution child;
   
    for (RuleModel rule : state.getShape().getGrammar().getRulesForShape(
        state.getShape().getId())) {
      child = new StateExecution(state.getShape(), rule, state
          .getAffineTransform());
     
      // add extended data
      if (state.getExtendedData() != null) {
        child.setExtendedData(state.getExtendedData());
      }
     
      // remember as child
      state.getChildren().add(child);
     
View Full Code Here

    ShapeModel shape = super.getShapeBasket().get(0).clone();
    shape.moveToCenter();
    shape.maximize();

    // get next state
    StateExecution state = this.getNext(monitor, shape);

    if (state == null) {
      monitor.done();
      return false;
    }
   
    // we test if the shape has changed
    // TODO: this will not work for replace   
    ShapeModel newShape = this.execute(shape, state, true);   
    if (newShape == null) {
      Debugger.getInstance().addMessage("Restarting process, no change in shape!");
      return this.executeNext(monitor);
    }
    Debugger.getInstance().addMessage("EXECUTED: " + state.toString());
   
    this.getShapeBasket().clear();
    this.getShapeBasket().add(newShape);
   
    return true;
View Full Code Here

    public TreeSearchProtocol(ShapeGrammarModel grammar, int randomizationLevel) {
        super(grammar, randomizationLevel);
    }
   
    public boolean executeNext(IProgressMonitor monitor) {
        StateExecution state = this.getNext();

        if (state == null) {
            Debugger.getInstance().addMessage("No possible step found!");
            return false;
        }

        // execute current rule
        ShapeModel currentShape = state.getRule().execute(state);
        this.getShapeBasket().add(currentShape);
       
        state.setExecuted(true);

        // this is the code for finding symmetries in object
//        try {
//          ArrayList<ShapeModel> shapes =
//        ShapeTools.findSubShape(currentShape, currentShape, new ArrayList<ShapeModel>(), 1, this
//            .isUseMarkers(), monitor, 100);
//         
//          System.out.println("Found subshapes: " + shapes.size());
//          for (ShapeModel shape : shapes) {
//            AffineTransform trans = new AffineTransform(state.getAffineTransform());
//            trans.preConcatenate(shape.getInitialTransform());
//            StateExecution newState = new StateExecution(
//                shape, trans);
//
//                // create child of current state
//                state.getChildren().add(newState);
//               
//                // insert this state into protocol
//                this.insertState(newState);
//          }
//         
//    } catch (Exception e) {
//      e.printStackTrace();
//    }
       
        // do postprocessing
        // now insert new "shape" state to the execution protocol remembering last transformation
        StateExecution newState = new StateExecution(
                currentShape, new AffineTransform(state.getAffineTransform()));

        // create child of current state
        state.getChildren().add(newState);
View Full Code Here

        return true;
    }

    // Randomization allows us to skip some steps, but always it returns at least one step
    private StateExecution getNext() {
        StateExecution currentState;
        while (true) {

            // get first element
          while ((currentState = getState()) != null) {
            if (!currentState.isExecuted()) {
              break;
            }
          }
           
            // we can have no possibilities
            if (currentState == null)
                    return null;

            // shape nodes expands with possible rules
            if (currentState.getStateType().equals(ExecutionStateTypes.Shape)) {
                this.expandState(currentState);
            }
            else {
                // decide if continue
                if (this.getRandomization() == 1 ||
                        !this.exists() ||
                        super.getRandom().nextInt(maxRandom) % super.getRandomization() == 0) {
                    // if we've found our node we put into collection output shape
                    break;
                }
                else {
                  ExecutionReport.skipNode();
                 
                    if (Debugger.isDebuggerOn()) {
                        Debugger.getInstance().addMessage("SKIPPING: " + currentState.toString());
                    }
                }
            }
        }
        return currentState;
View Full Code Here

TOP

Related Classes of es.iiia.shapegrammar.execution.StateExecution

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.