Ejemplo n.º 1
0
void
QueryAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("QueryAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("name")) != 0)
        SetName(node->AsString());
    if((node = searchNode->GetNode("variables")) != 0)
        SetVariables(node->AsStringVector());
    if((node = searchNode->GetNode("resultsMessage")) != 0)
        SetResultsMessage(node->AsString());
    if((node = searchNode->GetNode("worldPoint")) != 0)
        SetWorldPoint(node->AsDoubleArray());
    if((node = searchNode->GetNode("domain")) != 0)
        SetDomain(node->AsInt());
    if((node = searchNode->GetNode("element")) != 0)
        SetElement(node->AsInt());
    if((node = searchNode->GetNode("resultsValue")) != 0)
        SetResultsValue(node->AsDoubleVector());
    if((node = searchNode->GetNode("elementType")) != 0)
    {
        // Allow enums to be int or string in the config file
        if(node->GetNodeType() == INT_NODE)
        {
            int ival = node->AsInt();
            if(ival >= 0 && ival < 2)
                SetElementType(ElementType(ival));
        }
        else if(node->GetNodeType() == STRING_NODE)
        {
            ElementType value;
            if(ElementType_FromString(node->AsString(), value))
                SetElementType(value);
        }
    }
    if((node = searchNode->GetNode("timeStep")) != 0)
        SetTimeStep(node->AsInt());
    if((node = searchNode->GetNode("varTypes")) != 0)
        SetVarTypes(node->AsIntVector());
    if((node = searchNode->GetNode("dataType")) != 0)
    {
        // Allow enums to be int or string in the config file
        if(node->GetNodeType() == INT_NODE)
        {
            int ival = node->AsInt();
            if(ival >= 0 && ival < 2)
                SetDataType(DataType(ival));
        }
        else if(node->GetNodeType() == STRING_NODE)
        {
            DataType value;
            if(DataType_FromString(node->AsString(), value))
                SetDataType(value);
        }
    }
    if((node = searchNode->GetNode("pipeIndex")) != 0)
        SetPipeIndex(node->AsInt());
    if((node = searchNode->GetNode("useGlobalId")) != 0)
        SetUseGlobalId(node->AsBool());
    if((node = searchNode->GetNode("xUnits")) != 0)
        SetXUnits(node->AsString());
    if((node = searchNode->GetNode("yUnits")) != 0)
        SetYUnits(node->AsString());
    if((node = searchNode->GetNode("darg1")) != 0)
        SetDarg1(node->AsDoubleVector());
    if((node = searchNode->GetNode("darg2")) != 0)
        SetDarg2(node->AsDoubleVector());
    if((node = searchNode->GetNode("floatFormat")) != 0)
        SetFloatFormat(node->AsString());
    if((node = searchNode->GetNode("xmlResult")) != 0)
        SetXmlResult(node->AsString());
}
Ejemplo n.º 2
0
bool mitk::GizmoInteractor::HasPickedHandle(const InteractionEvent* interactionEvent)
{
  auto positionEvent = dynamic_cast<const InteractionPositionEvent*>(interactionEvent);
  if(positionEvent == NULL)
  {
    return false;
  }

  DataNode::Pointer gizmoNode = this->GetDataNode();

  if (m_Gizmo.IsNull())
  {
    return false;
  }

  if (m_ManipulatedObjectGeometry.IsNull())
  {
    return false;
  }

  if (interactionEvent->GetSender()->GetRenderWindow()->GetNeverRendered())
  {
    return false;
  }

  if (interactionEvent->GetSender()->GetMapperID() == BaseRenderer::Standard2D)
  {
    m_PickedHandle = PickFrom2D(positionEvent);
  }
  else
  {
    m_PickedHandle = PickFrom3D(positionEvent);
  }


  if (m_PickedHandle != Gizmo::NoHandle)
  {
    // if something relevant was picked, we calculate a number of
    // important points and axes for the upcoming geometry manipulations

    // note initial state
    m_InitialClickPosition2D = positionEvent->GetPointerPositionOnScreen();
    m_InitialClickPosition3D = positionEvent->GetPositionInWorld();

    auto renderer = positionEvent->GetSender()->GetVtkRenderer();
    renderer->SetWorldPoint(m_InitialClickPosition3D[0],
                            m_InitialClickPosition3D[1],
                            m_InitialClickPosition3D[2],
                            0);
    renderer->WorldToDisplay();
    m_InitialClickPosition2DZ = renderer->GetDisplayPoint()[2];


    m_InitialGizmoCenter3D = m_Gizmo->GetCenter();
    positionEvent->GetSender()->WorldToDisplay( m_InitialGizmoCenter3D, m_InitialGizmoCenter2D );

    m_InitialManipulatedObjectGeometry = m_ManipulatedObjectGeometry->Clone();

    switch (m_PickedHandle)
    {
      case Gizmo::MoveAlongAxisX:
      case Gizmo::RotateAroundAxisX:
      case Gizmo::ScaleX:
        m_AxisOfMovement = m_InitialManipulatedObjectGeometry->GetAxisVector(0);
        break;
      case Gizmo::MoveAlongAxisY:
      case Gizmo::RotateAroundAxisY:
      case Gizmo::ScaleY:
        m_AxisOfMovement = m_InitialManipulatedObjectGeometry->GetAxisVector(1);
        break;
      case Gizmo::MoveAlongAxisZ:
      case Gizmo::RotateAroundAxisZ:
      case Gizmo::ScaleZ:
        m_AxisOfMovement = m_InitialManipulatedObjectGeometry->GetAxisVector(2);
        break;
      default:
        break;
    }
    m_AxisOfMovement.Normalize();
    m_AxisOfRotation = m_AxisOfMovement;

    // for translation: test whether the user clicked into the "object's real" axis direction
    //                  or into the other one
    Vector3D intendedAxis = m_InitialClickPosition3D - m_InitialGizmoCenter3D;

    if ( intendedAxis * m_AxisOfMovement < 0 )
    {
      m_AxisOfMovement *= -1.0;
    }

    // for rotation: test whether the axis of rotation is more looking in the direction
    //               of the camera or in the opposite
    vtkCamera* camera = renderer->GetActiveCamera();
    vtkVector3d cameraDirection( camera->GetDirectionOfProjection() );

    double angle_rad = vtkMath::AngleBetweenVectors( cameraDirection.GetData(),
                                                     m_AxisOfRotation.GetDataPointer() );

    if ( angle_rad < vtkMath::Pi() / 2.0 )
    {
        m_AxisOfRotation *= -1.0;
    }

    return true;
  }
  else
  {
    return false;
  }
}