void mitk::RegistrationTool::CrossTranslateCoronal(int x, int y)
{
	//std::cout << "hi from " << __FUNCSIG__ << std::endl;

	if(x == 0 && y == 0)
	{
		return;
	}

	// Undo / Redo controller
	mitk::Point3D forwardPoint;
	mitk::Point3D reversePoint;

	forwardPoint[0] = (double)x / 10.0;
	forwardPoint[1] = 0.0;
	forwardPoint[2] = -(double)y / 10.0;

	reversePoint[0] = -forwardPoint[0];
	reversePoint[1] = -forwardPoint[1];
	reversePoint[2] = -forwardPoint[2];

	mitk::PointOperation* doOp = new mitk::PointOperation(OpMOVE, forwardPoint);
	if ( m_UndoEnabled )
	{
		mitk::PointOperation* undoOp = new mitk::PointOperation(OpMOVE, reversePoint);
	    OperationEvent *operationEvent = new OperationEvent( m_Ext->GetSurface()->GetGeometry(), doOp, undoOp, "Move surface coronal");
	    m_UndoController->SetOperationEvent(operationEvent);

		if(m_LastTool != 6)
		{
			std::cout << "Change last tool from: " << m_LastTool << ", to: 6.\n"; 
			operationEvent->IncCurrObjectEventId();
			operationEvent->IncCurrGroupEventId();
			m_LastTool = 6;
		}
	}
	//execute the Operation
	m_Ext->GetSurface()->GetGeometry()->ExecuteOperation(doOp);
	m_Ext->GetSurface()->Update();
	m_Ext->GetSurfaceNode()->Modified();

	mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll();

	if(m_AutoReinit)
	{
		m_Ext->Reinit();
	}

	//std::cout << "ciao from " << __FUNCSIG__ << std::endl;
}
Ejemplo n.º 2
0
mitk::OperationEvent* mitk::LimitedLinearUndo::GetLastOfType(OperationActor* destination, OperationType opType)
{
  // When/where is this function needed? In CoordinateSupplier...
  for ( UndoContainerRevIter iter = m_UndoList.rbegin(); iter != m_UndoList.rend(); ++iter )
  {
    OperationEvent* opEvent = dynamic_cast<OperationEvent*>(*iter);
    if (!opEvent) continue;

    if (   opEvent->GetOperation() != NULL
        && opEvent->GetOperation()->GetOperationType() == opType
        && opEvent->IsValid()
        && opEvent->GetDestination() == destination )
      return opEvent;
  }

  return NULL;
}
void mitk::RegistrationTool::CrossRotateZ(int x)
{
	//std::cout << "hi from " << __FUNCSIG__ << std::endl;

	if(x == 0)
	{
		return;
	}

	mitk::Point3D newCenter;
	newCenter = m_Ext->GetSurface()->GetGeometry()->GetCenter();
	mitk::Vector3D rotationAxis;
	rotationAxis[0] = 0.0; rotationAxis[1] = 20.0; rotationAxis[2] = 0.0;
	//(sagittal, coronal, transversal)
	mitk::RotationOperation *doOp = new mitk::RotationOperation(mitk::OpROTATE, newCenter, rotationAxis, x);

	if(m_UndoEnabled)
	{
		mitk::RotationOperation* undoOp = new mitk::RotationOperation(mitk::OpROTATE, newCenter, rotationAxis, -x);
	    OperationEvent *operationEvent = new OperationEvent(m_Ext->GetSurface()->GetGeometry(), doOp, undoOp, "Rotate Coronal (Z)");
	    m_UndoController->SetOperationEvent(operationEvent);

		if(m_LastTool != 3)
		{
			std::cout << "Change last tool from: " << m_LastTool << ", to: 3.\n"; 
			operationEvent->IncCurrObjectEventId();
			operationEvent->IncCurrGroupEventId();
			m_LastTool = 3;
		}
	}
	m_Ext->GetSurface()->GetGeometry()->ExecuteOperation(doOp);
	m_Ext->GetSurface()->Update();
	m_Ext->GetSurfaceNode()->Modified();

	mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll();

	if(m_AutoReinit)
	{
		m_Ext->Reinit();
	}

	//std::cout << "ciao from " << __FUNCSIG__ << std::endl;
}
void mitk::RegistrationTool::ScaleChangedByCross(int scale)
{
	//std::cout << "hi from " << __FUNCSIG__ << std::endl;
	
	if(scale == 0)
	{
		return;
	}
	else if(scale > 0)
	{
		m_Factor = 1.01;
	
	}
	else
	{
		m_Factor = 0.99;
	}
	//std::cout << "Scale factor: " << m_Factor << "\n"; 

	mitk::Geometry3D::Pointer geometry = m_Ext->GetSurface()->GetGeometry();
	// from mitk::Geometry3D:
	/* calculate new scale: newscale = oldscale * (oldscale + scaletoadd)/oldscale */
	mitk::Point3D newScale;
	newScale.Fill(m_Factor);
	mitk::Point3D newScale2;
	newScale2[0] = (newScale[0] - 1) * (m_Ext->GetSurface()->GetGeometry()->GetMatrixColumn(0).magnitude());
	newScale2[1] = (newScale[1] - 1) * (m_Ext->GetSurface()->GetGeometry()->GetMatrixColumn(1).magnitude());
	newScale2[2] = (newScale[2] - 1) * (m_Ext->GetSurface()->GetGeometry()->GetMatrixColumn(2).magnitude());

	mitk::Point3D reverseScale;
	reverseScale[0] = -newScale2[0];
	reverseScale[1] = -newScale2[1];
	reverseScale[2] = -newScale2[2];

	m_CenterBeforeScale = m_Ext->GetSurface()->GetGeometry()->GetCenter();
		
	/* generate Operation and send it to the receiving geometry */
	PointOperation* doOp = new mitk::PointOperation(OpSCALE, newScale2, 0); // Index is not used here

	if (m_UndoEnabled)  //write to UndoMechanism
	{
		mitk::Point3D oldScaleData;
		oldScaleData[0] = -newScale[0];
		oldScaleData[1] = -newScale[1];
		oldScaleData[2] = -newScale[2];

		PointOperation* undoOp = new mitk::PointOperation(OpSCALE, reverseScale/*oldScaleData*/, 0);
		OperationEvent *operationEvent = new OperationEvent(geometry, doOp, undoOp, "Scale surface");
		m_UndoController->SetOperationEvent(operationEvent);

		if(m_LastTool != 0)
		{
			std::cout << "Change last tool from: " << m_LastTool << ", to: 0.\n"; 
			operationEvent->IncCurrObjectEventId();
			operationEvent->IncCurrGroupEventId();
			m_LastTool = 0;
		}
	}
	/* execute the Operation */
	geometry->ExecuteOperation(doOp);
	m_Ext->GetSurface()->Update();
	m_Ext->GetSurfaceNode()->Modified();

	//update rendering
	mitk::RenderingManager::GetInstance()->RequestUpdateAll();

	// translate to keep object at place
	mitk::Point3D forwardPoint;
	mitk::Point3D reversePoint;

	m_CenterAfterScale = m_Ext->GetSurface()->GetGeometry()->GetCenter();

	forwardPoint[0] = m_CenterBeforeScale[0] - m_CenterAfterScale[0];
	forwardPoint[1] = m_CenterBeforeScale[1] - m_CenterAfterScale[1];
	forwardPoint[2] = m_CenterBeforeScale[2] - m_CenterAfterScale[2];

	reversePoint[0] = -forwardPoint[0];
	reversePoint[1] = -forwardPoint[1];
	reversePoint[2] = -forwardPoint[2];

	if(0) // print
	{
		std::cout << "Scale: " << newScale[0] << ", " << newScale[1] << ", " << newScale[2] << "\n";
		std::cout << "Translation: " << forwardPoint[0] << ", " << forwardPoint[1] << ", " << forwardPoint[2] << "\n";
		std::cout << "Center of Surface: " << m_Ext->GetSurface()->GetGeometry()->GetCenter() << "\n";
	}

	mitk::PointOperation* doOp2 = new mitk::PointOperation(OpMOVE, forwardPoint);
	if ( m_UndoEnabled )
	{
		mitk::PointOperation* undoOp2 = new mitk::PointOperation(OpMOVE, reversePoint);
		OperationEvent *operationEvent2 = new OperationEvent(m_Ext->GetSurface()->GetGeometry(), doOp2, undoOp2, "Back transformation (translate after scale)");
		m_UndoController->SetOperationEvent(operationEvent2);
	}
	//execute the Operation
	m_Ext->GetSurface()->GetGeometry()->ExecuteOperation(doOp2);
	m_Ext->GetSurface()->Update();
	m_Ext->GetSurfaceNode()->Modified();

	//update rendering
	mitk::RenderingManager::GetInstance()->RequestUpdateAll();

	if(m_AutoReinit)
	{
		m_Ext->Reinit();
	}
	
	//std::cout << "ciao from " << __FUNCSIG__ << std::endl;
}
bool mitk::CoordinateSupplier::ExecuteAction(Action* action, mitk::StateEvent const* stateEvent)
{
    bool ok = false;

    const PositionEvent* posEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());

    PointOperation* doOp=NULL;
    if(posEvent!=NULL)
    {
      ScalarType timeInMS = 0;
      if(stateEvent->GetEvent()->GetSender()!=NULL)
      {
        timeInMS = stateEvent->GetEvent()->GetSender()->GetTime();
      }
      else
      {
        itkWarningMacro(<<"StateEvent::GetSender()==NULL - setting timeInMS to 0");
      }

      switch (action->GetActionId())
      {
        case AcNEWPOINT:
        {
          if (m_Destination == NULL)
            return false;
          m_OldPoint = posEvent->GetWorldPosition();

          doOp = new mitk::PointOperation(OpADD, timeInMS, m_OldPoint, 0);
          //Undo
          if (m_UndoEnabled)
          {
            PointOperation* undoOp = new PointOperation(OpDELETE, m_OldPoint, 0);
            OperationEvent *operationEvent = new OperationEvent( m_Destination, doOp, undoOp );
            m_UndoController->SetOperationEvent(operationEvent);
          }
          //execute the Operation
          m_Destination->ExecuteOperation(doOp);

          if (!m_UndoEnabled)
            delete doOp;

          ok = true;
          break;
        }
        case AcINITMOVEMENT:
        {
          if (m_Destination == NULL)
            return false;
          //move the point to the coordinate //not used, cause same to MovePoint... check xml-file
          mitk::Point3D movePoint = posEvent->GetWorldPosition();

          mitk::PointOperation doPointOp(OpMOVE, timeInMS, movePoint, 0);
          //execute the Operation
          m_Destination->ExecuteOperation(&doPointOp);
          ok = true;
          break;
        }
        case AcMOVEPOINT:
        case AcMOVE:
        {
          mitk::Point3D movePoint = posEvent->GetWorldPosition();
          m_CurrentPoint = movePoint;
          if (m_Destination == NULL)
            return false;
          mitk::PointOperation doPointOp(OpMOVE, timeInMS, movePoint, 0);
          //execute the Operation
          m_Destination->ExecuteOperation(&doPointOp);
          ok = true;
          break;
        }
        case AcFINISHMOVEMENT:
        {
          if (m_Destination == NULL)
            return false;
          /*finishes a Movement from the coordinate supplier:
          gets the lastpoint from the undolist and writes an undo-operation so
          that the movement of the coordinatesupplier is undoable.*/
          mitk::Point3D movePoint = posEvent->GetWorldPosition();
          mitk::Point3D oldMovePoint; oldMovePoint.Fill(0);

          doOp = new mitk::PointOperation(OpMOVE, timeInMS, movePoint, 0);
          PointOperation finishOp(OpTERMINATE, movePoint, 0);
          if (m_UndoEnabled )
          {
            //get the last Position from the UndoList
            OperationEvent *lastOperationEvent = m_UndoController->GetLastOfType(m_Destination, OpMOVE);
            if (lastOperationEvent != NULL)
            {
              PointOperation* lastOp = dynamic_cast<PointOperation *>(lastOperationEvent->GetOperation());
              if (lastOp != NULL)
              {
                oldMovePoint = lastOp->GetPoint();
              }
            }
            PointOperation* undoOp = new PointOperation(OpMOVE, timeInMS, oldMovePoint, 0, "Move slices");
            OperationEvent *operationEvent = new OperationEvent(m_Destination, doOp, undoOp, "Move slices");
            m_UndoController->SetOperationEvent(operationEvent);
          }
          //execute the Operation
          m_Destination->ExecuteOperation(doOp);

          if (!m_UndoEnabled)
            delete doOp;

          m_Destination->ExecuteOperation(&finishOp);
          ok = true;

          break;
        }
        default:
          ok = false;
          break;
      }
      return ok;
    }