Beispiel #1
0
void CallPoint(GLint button, GLint state, GLint x, GLint y){

	static int first=1;
	if (state == GLUT_DOWN && button == GLUT_LEFT_BUTTON){

			x1 = x; 
			y10 = hh - y;
			SelectPoint();	
	}
	
	return;
}
SELECTION& PL_SELECTION_TOOL::RequestSelection()
{
    // If nothing is selected do a hover selection
    if( m_selection.Empty() )
    {
        VECTOR2D cursorPos = getViewControls()->GetCursorPosition( true );

        ClearSelection();
        SelectPoint( cursorPos );
        m_selection.SetIsHover( true );
    }

    return m_selection;
}
Beispiel #3
0
void NormalSet::Solve()
{
    EditLinearDegenerates();

    GeneralMinimizer * solver = NULL;   // Initialization avoids compiler warnings

    switch (numericMinimizer)
    {
    case NORMAL_AMOEBA_MIN :
        solver = new AmoebaMinimizer();
        break;
    case NORMAL_POWELL_MIN :
        solver = new PowellMinimizer();
        break;
    case NORMAL_FLETCHER_MIN :
        solver = new FletcherMinimizer();
        break;
    }

    solver->func = new NormalSolver(this);

    // set the number of parameters to minimize
    int parameters = CountParameters();
    solver->Reset(parameters);

    // Reset the number of likelihood evaluations
    evaluations = 0;

    // If we are not using the Nelder-Mead minimizer, use it
    // to conduct a rough pre-optimization.
    if (solver != NORMAL_AMOEBA_MIN)
    {
        AmoebaMinimizer presolver;

        presolver.func = solver->func;
        presolver.Reset(parameters);
        GetStartingPoint(presolver.point);
        presolver.Minimize(precision * 1000);

        solver->point = presolver.point;
    }
    else
        GetStartingPoint(solver->point);

    // Two rounds of minimizing to be safe
    solver->Minimize(precision);

    double lastmin;
    double scale = 2.0;

    do {
        // Find the largest variance ...
        double varMax = solver->point[means.Length()];
        for (int i = means.Length() + vcEstimated - 1; i > means.Length(); i--)
            if (solver->point[i] > varMax)
                varMax = solver->point[i];

        // Check that none of the variances is effectively zero...
        for (int i = means.Length() + vcEstimated - 1; i >= means.Length(); i--)
            if (solver->point[i] < (varMax - 5.0))
                solver->point[i] = varMax - 5.0;

        lastmin = solver->fmin;
        scale *= -0.5;
        solver->Reset(parameters, scale);
        solver->Minimize(precision);
    }
    while (solver->fmin > precision &&
            (lastmin - solver->fmin)/solver->fmin > precision);

    SelectPoint(solver->point);

    delete solver->func;
    delete solver;
}
bool mitk::PointSelectorInteractor::ExecuteAction( Action* action, mitk::StateEvent const* stateEvent )
{
  bool ok = false;//for return type bool

  //checking corresponding Data; has to be a PointSet or a subclass
  mitk::PointSet* pointSet = dynamic_cast<mitk::PointSet*>(m_DataNode->GetData());
  if (pointSet == NULL)
    return false;

  //for reading on the points, Id's etc
  //mitk::PointSet::DataType *itkPointSet = pointSet->GetPointSet();
  //mitk::PointSet::PointsContainer *itkPoints = itkPointSet->GetPoints();

  /*Each case must watch the type of the event!*/
  switch (action->GetActionId())
  {
  case AcADDPOINT:
    break;
  case AcDESELECTALL:
    this->DeselectAllPoints();
    ok = true;
    break;
  case AcCHECKELEMENT :
    /*checking if the Point transmitted is close enough to one point. Then generate a new event with the point and let this statemaschine handle the event.*/
    {
      mitk::PositionEvent const  *posEvent = dynamic_cast <const mitk::PositionEvent *> (stateEvent->GetEvent());
      if (posEvent != NULL)
      {
        mitk::Point3D worldPoint = posEvent->GetWorldPosition();

        int PRECISION = 4;
        mitk::IntProperty *precision = dynamic_cast<IntProperty*>(action->GetProperty("PRECISION"));
        if (precision != NULL)
        {
          PRECISION = precision->GetValue();
        }

        int position = pointSet->SearchPoint(worldPoint, PRECISION);
        if (position>=0)//found a point near enough to the given point
        {
          m_LastPosition = position;//store it to be able to move the point
          worldPoint = pointSet->GetPoint(position);//get that point, the one meant by the user!
          mitk::Point2D displPoint;
          displPoint[0] = worldPoint[0];
          displPoint[1] = worldPoint[1];

          //new Event with information YES and with the correct point
          mitk::PositionEvent const* newPosEvent = new mitk::PositionEvent(posEvent->GetSender(), posEvent->GetType(), 
            posEvent->GetButton(), posEvent->GetButtonState(), posEvent->GetKey(), 
            displPoint, worldPoint);
          mitk::StateEvent* newStateEvent = new mitk::StateEvent(EIDYES, newPosEvent);
          //call HandleEvent to leave the guard-state
          this->HandleEvent( newStateEvent );
          ok = true;
        }
        else
        {
          //new Event with information NO
          mitk::StateEvent* newStateEvent = new mitk::StateEvent(EIDNO, posEvent);
          this->HandleEvent( newStateEvent );
          ok = true;
        }
      }
      else //hardly used, due to 3dPicking of globalInteraction
      {
        mitk::DisplayPositionEvent const  *disPosEvent = dynamic_cast <const mitk::DisplayPositionEvent *> (stateEvent->GetEvent());
        if (disPosEvent != NULL)
        {//2d Koordinates for 3D Interaction; return false to redo the last statechange
          mitk::StateEvent* newStateEvent = new mitk::StateEvent(EIDNO, posEvent);
          this->HandleEvent( newStateEvent );
          ok = true;
        }
      }
    }
    break;
  case AcCHECKSELECTED:
    //check if the point that was hit before is still hit
    {
      mitk::PositionEvent const  *posEvent = dynamic_cast <const mitk::PositionEvent *> (stateEvent->GetEvent());
      if (posEvent != NULL)
      {
        mitk::Point3D worldPoint = posEvent->GetWorldPosition();

        int PRECISION = 4;
        mitk::IntProperty *precision = dynamic_cast<IntProperty*>(action->GetProperty("precision"));
        if (precision != NULL)
        {
          PRECISION = precision->GetValue();
        }

        int position = pointSet->SearchPoint(worldPoint, PRECISION);
        if (position <0)//no point found at the current mouseposition
        {
          //new Event with information NO
          mitk::StateEvent* newStateEvent = new mitk::StateEvent(EIDNO, posEvent);
          this->HandleEvent( newStateEvent );
          ok = true;
          break;
        }

        //point found at the current mouseposition, so check if this point is the same like before
        unsigned int upos = (unsigned int) position;//comparison signed unsigned int
        if (upos == m_LastPosition)//found the same point again
        {
          mitk::StateEvent* newStateEvent = new mitk::StateEvent(EIDYES, posEvent);
          //call HandleEvent to leave the guard-state
          this->HandleEvent( newStateEvent );
          ok = true;
        }
        else
        {
          //new Event with information NO
          mitk::StateEvent* newStateEvent = new mitk::StateEvent(EIDNO, posEvent);
          this->HandleEvent( newStateEvent );
          ok = true;
        }
      }
      else //hardly used, due to 3dPicking of globalInteraction
      {
        mitk::DisplayPositionEvent const  *disPosEvent = dynamic_cast <const mitk::DisplayPositionEvent *> (stateEvent->GetEvent());
        if (disPosEvent != NULL)
        {//2d Koordinates for 3D Interaction; return false to redo the last statechange
          mitk::StateEvent* newStateEvent = new mitk::StateEvent(EIDNO, posEvent);
          this->HandleEvent( newStateEvent );
          ok = true;
        }
      }    
    }
    break;
  case AcINITMOVEMENT:
    break;
  case AcMOVESELECTED://moves the point
    break;
  case AcFINISHMOVEMENT:
    break;
  case AcCHECKGREATERONE:
    break;
  case AcSELECTANOTHEROBJECT:
    //selects an other Point after one point has been removed
    {
      /*select the point "position-1", 
      and if it is the first in list, 
      then contine at the last in list*/
      if (pointSet->GetSize()>0)//only then a select of a point is possible!
      {
        if (m_LastPosition > 0)//not the first in list
        {
          this->SelectPoint( m_LastPosition-1 );
        }
        else//it was the first point in list, that was removed, so select the last in list
        {
          m_LastPosition = pointSet->GetSize()-1;//last in list
          SelectPoint( m_LastPosition );
        }//else
      }//if
      ok = true;
    }
    break;
  case AcREMOVEPOINT:
    break;
  case AcSELECT:
    //select the point found at the given mouseposition
    {
      mitk::PositionEvent const  *posEvent = dynamic_cast <const mitk::PositionEvent *> (stateEvent->GetEvent());
      if (posEvent == NULL) 
        return false;

      mitk::Point3D worldPoint = posEvent->GetWorldPosition();

      //search the point in the list
      //distance set to 0, cause we already got the exact point from last State checkpoint
      //but we also need the position in the list to move it
      int position = pointSet->SearchPoint(worldPoint, 0);

      if (position>=0)//found a point
      {
        PointOperation* doOp = new mitk::PointOperation(OpSELECTPOINT, worldPoint, position);

        //Undo
        if (m_UndoEnabled)  //write to UndoMechanism
        {
          PointOperation* undoOp = new mitk::PointOperation(OpDESELECTPOINT, worldPoint, position);
          OperationEvent *operationEvent = new OperationEvent(pointSet, doOp, undoOp);
          m_UndoController->SetOperationEvent(operationEvent);
        }

        //execute the Operation
        pointSet->ExecuteOperation(doOp);
        ok = true;
      }
    }
    break;
  case AcDESELECT:
    {
      mitk::PositionEvent const  *posEvent = dynamic_cast <const mitk::PositionEvent *> (stateEvent->GetEvent());
      if (posEvent == NULL) 
        return false;

      mitk::Point3D worldPoint = posEvent->GetWorldPosition();

      //search the point in the list
      //distance set to 0, cause we already got the exact point from last State checkpoint
      //but we also need the position in the list to move it
      int position = pointSet->SearchPoint(worldPoint, 0);

      if (position>=0)//found a point
      {
        PointOperation* doOp = new mitk::PointOperation(OpDESELECTPOINT, worldPoint, position);

        //Undo
        if (m_UndoEnabled)  //write to UndoMechanism
        {
          PointOperation* undoOp = new mitk::PointOperation(OpSELECTPOINT, worldPoint, position);
          OperationEvent *operationEvent = new OperationEvent(pointSet, doOp, undoOp);
          m_UndoController->SetOperationEvent(operationEvent);
        }

        //execute the Operation
        pointSet->ExecuteOperation(doOp);
        ok = true;
      }
    }
    break;
  case AcSETSTARTPOINT:
    break;
  default:
    return Superclass::ExecuteAction( action, stateEvent );
  }

  return ok;

}
int PL_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
{
    // Main loop: keep receiving events
    while( OPT_TOOL_EVENT evt = Wait() )
    {
        // Should selected items be added to the current selection or
        // become the new selection (discarding previously selected items)
        m_additive = evt->Modifier( MD_SHIFT );

        // Should selected items be REMOVED from the current selection?
        // This will be ignored if the SHIFT modifier is pressed
        m_subtractive = !m_additive && evt->Modifier( MD_CTRL );

        // Is the user requesting that the selection list include all possible
        // items without removing less likely selection candidates
        m_skip_heuristics = !!evt->Modifier( MD_ALT );

        // Single click? Select single object
        if( evt->IsClick( BUT_LEFT ) )
        {
            // If no modifier keys are pressed, clear the selection
            if( !m_additive )
                ClearSelection();

            SelectPoint( evt->Position());
        }

        // right click? if there is any object - show the context menu
        else if( evt->IsClick( BUT_RIGHT ) )
        {
            bool selectionCancelled = false;

            if( m_selection.Empty() )
            {
                SelectPoint( evt->Position(), &selectionCancelled );
                m_selection.SetIsHover( true );
            }

            if( !selectionCancelled )
                m_menu.ShowContextMenu( m_selection );
        }

        // double click? Display the properties window
        else if( evt->IsDblClick( BUT_LEFT ) )
        {
            // No double-click actions currently defined
        }

        // drag with LMB? Select multiple objects (or at least draw a selection box) or drag them
        else if( evt->IsDrag( BUT_LEFT ) )
        {
            if( m_additive || m_subtractive || m_selection.Empty() )
            {
                selectMultiple();
            }
            else
            {
                // Check if dragging has started within any of selected items bounding box
                if( selectionContains( evt->Position() ) )
                {
                    // Yes -> run the move tool and wait till it finishes
                    m_toolMgr->InvokeTool( "plEditor.InteractiveEdit" );
                }
                else
                {
                    // No -> clear the selection list
                    ClearSelection();
                }
            }
        }

        else if( evt->IsAction( &ACTIONS::cancelInteractive ) || evt->IsCancel() )
        {
            ClearSelection();
        }

        else if( evt->Action() == TA_UNDO_REDO_PRE )
        {
            ClearSelection();
        }

        else if( evt->Action() == TA_CONTEXT_MENU_CLOSED )
        {
            m_menu.CloseContextMenu( evt );
        }

        else
            m_toolMgr->PassEvent();
    }

    // This tool is supposed to be active forever
    assert( false );

    return 0;
}