コード例 #1
0
void DialogTransformVolume::DoRotate()
{
  LayerMRI* layer = ( LayerMRI* )MainWindow::GetMainWindow()->GetActiveLayer( "MRI" );
  if ( layer )
  {
    std::vector<RotationElement> rotations;
    RotationElement re;
    re.SampleMethod = SAMPLE_TRILINEAR;
    if ( ui->radioButtonNearestNeighbor->isChecked() )
    {
      re.SampleMethod = SAMPLE_NEAREST;
    }
    else if (ui->radioButtonCubic->isChecked())
    {
      re.SampleMethod = SAMPLE_CUBIC_BSPLINE;
    }
    if (ui->radioButtonRotateManual->isChecked())
    {
      if ( ui->radioButtonAroundCursor->isChecked() )
      {
        MainWindow::GetMainWindow()->GetLayerCollection( "MRI" )->
        GetSlicePosition( re.Point );
        layer->RemapPositionToRealRAS( re.Point, re.Point );
      }
      else
      {
        // use center of the volume to rotate
        layer->GetRASCenter( re.Point );
      }
  //    else if ( m_radioSinc->GetValue() )
  //      re.SampleMethod = SAMPLE_SINC;

      for ( int i = 0; i < 3; i++ )
      {
        if ( GetRotation( i, re.Plane, re.Angle ) )
        {
          rotations.push_back( re );
        }
      }
      MainWindow::GetMainWindow()->RotateVolume( rotations, false );
    }
    else
    {
      layer->GetRASCenter( re.Point );
      LayerLandmarks* landmarks = (LayerLandmarks*)MainWindow::GetMainWindow()->GetSupplementLayer("Landmarks");
      double* p[4];
      for (int i = 0; i < 4; i++)
        p[i] = landmarks->GetLandmark(i).pos;

      // first figure out landmark vectors
      double v[3][3], ax[3][3];
      int n0 = ui->comboBoxAxis11->currentIndex();
      int n1 = ui->comboBoxAxis12->currentIndex();
      for (int i = 0; i < 3; i++)
        v[0][i] = p[n1][i] - p[n0][i];
      vtkMath::Normalize(v[0]);

      n0 = ui->comboBoxAxis21->currentIndex();
      n1 = ui->comboBoxAxis22->currentIndex();
      for (int i = 0; i < 3; i++)
        v[1][i] = p[n1][i] - p[n0][i];
      vtkMath::Normalize(v[1]);
      vtkMath::Cross(v[0], v[1], v[2]);
      vtkMath::Normalize(v[2]);
      vtkMath::Cross(v[2], v[0], v[1]);

      int n[3];
      n[0] = ui->comboBoxAxisTarget1->currentIndex();
      n[1] = ui->comboBoxAxisTarget2->currentIndex();
      if (n[0] == 0)
        n[2] = (n[1] == 1 ? 2 : 1);
      else if (n[0] == 1)
        n[2] = (n[1] == 0 ? 2 : 0);
      else
        n[2] = (n[1] == 0 ? 1 : 0);

      for (int i = 0; i < 3; i++)
      {
        for (int j = 0; j < 3; j++)
          ax[n[i]][j] = v[i][j];
      }

      double m[16];
      memset(m, 0, sizeof(double)*16);
      for (int i = 0; i < 16; i++)
      {
        if (i/4 < 3 && i%4 < 3)
          m[i] = ax[i/4][i%4];
      }
      m[15] = 1;

      vtkSmartPointer<vtkTransform> tf = vtkSmartPointer<vtkTransform>::New();
      tf->Identity();
      double pt[3];
      layer->RASToTarget( re.Point, pt );
      tf->Translate(pt[0], pt[1], pt[2]);
      tf->Concatenate(m);
      tf->Translate(-pt[0], -pt[1], -pt[2]);
      vtkMatrix4x4::DeepCopy(m, tf->GetMatrix());
      MainWindow::GetMainWindow()->TransformVolume(m, re.SampleMethod);
    }
  }
}
コード例 #2
0
void PixelInfoListCtrl::OnFinishEditing( wxCommandEvent& event )
{
  LayerCollectionManager* lcm = MainWindow::GetMainWindowPointer()->GetLayerCollectionManager();
  LayerCollection* lc = MainWindow::GetMainWindowPointer()->GetLayerCollection( "MRI" );

  // see if entered text is valid
  wxArrayString sa = MyUtils::SplitString( m_textEditor->GetValue(), _(",") );
  long ptr = m_listPtr[m_nRowEdited];
  Layer* layer_ptr = (Layer*)ptr;
  if ( ptr == 1 || ( layer_ptr && layer_ptr->IsTypeOf( "MRI" ) ) )
  {
    if ( sa.Count() < 3 )
      sa = MyUtils::SplitString( m_textEditor->GetValue(), _(" ") );

    if ( sa.Count() < 3 )
    {
      cerr << "Invalid coordinate string. Make sure they are three numbers." << endl;
      return;
    }
  }

  if ( ptr == 1 ) // RAS
  {
    double ras[3];
    if ( sa[0].ToDouble( ras ) && sa[1].ToDouble( ras+1 ) && sa[2].ToDouble( ras+2 ) )
    {
      wxListItem item;
      GetColumn( 0, item );
      LayerMRI* layer = (LayerMRI*)lc->GetLayer( 0 );
      if ( layer )
        layer->RASToTarget( ras, ras );
      if ( item.GetText() == _("Cursor") )
      {
        lc->SetCursorRASPosition( ras );
        lcm->SetSlicePosition( ras );
      }
      else if ( item.GetText() == _("Mouse") )
        lc->SetCurrentRASPosition( ras );
      UpdateList();
      m_textEditor->Hide();
    }
    else
    {
      cerr << "Invalid coordinate string. Make sure they are three numbers." << endl;
    }
  }
  else if ( layer_ptr && layer_ptr->IsTypeOf( "MRI" ) ) // voxel
  {
    long x, y, z;
    if ( sa.Count() < 3 )
    {
      cerr << "Invalid voxel coordinate string. Make sure they are three numbers." << endl;
      return;
    }
    int n = sa[0].Find( wxChar('['), true );
    if ( n != wxNOT_FOUND )
      sa[0] = sa[0].Mid( n+1 );
    n = sa[2].Find( wxChar(']') );
    if ( n != wxNOT_FOUND )
      sa[2] = sa[2].Left( n );
    if ( sa[0].ToLong( &x ) && sa[1].ToLong( &y ) && sa[2].ToLong( &z ) )
    {
      int nv[3] = { x, y, z };
      double ras[3];
      wxListItem item;
      GetColumn( 0, item );
      LayerMRI* layer = (LayerMRI*)layer_ptr;
      layer->OriginalIndexToRAS( nv, ras );
      layer->RASToTarget( ras, ras );
      if ( item.GetText() == _("Cursor") )
      {
        lc->SetCursorRASPosition( ras );
        lcm->SetSlicePosition( ras );
      }
      else if ( item.GetText() == _("Mouse") )
        lc->SetCurrentRASPosition( ras );
      UpdateList();
      m_textEditor->Hide();
    }
    else
    {
      cerr << "Invalid voxel coordinate string. Make sure they are three numbers." << endl;
    }
  }  
  else if ( layer_ptr && layer_ptr->IsTypeOf( "Surface" )  ) // surface
  {
    wxString strg = m_textEditor->GetValue();
    LayerSurface* layer = (LayerSurface*)layer_ptr;
    double ras[3];
    bool bSuccess = false;
    if ( m_listValue[m_nRowEdited].Find( _("Coord") ) == 0 )  // coordinate item
    {
      sa = MyUtils::SplitString( strg, _(",") );
      if ( sa.Count() < 3 )
        sa = MyUtils::SplitString( m_textEditor->GetValue(), _(" ") );
      if ( sa.Count() >= 3 && sa[0].ToDouble( ras ) && sa[1].ToDouble( ras+1 ) && sa[2].ToDouble( ras+2 ) )
      {
        layer->GetTargetAtSurfaceRAS( ras, ras );
        bSuccess = true;
      }
    }
    else        // vertex index item
    {
      long nIndex;
      if ( strg.ToLong( &nIndex ) && layer->GetTargetAtVertex( nIndex, ras ) )
        bSuccess = true;
    }
    if ( bSuccess )
    {
      wxListItem item;
      GetColumn( 0, item );
      if ( item.GetText() == _("Cursor") )
      {
        lc->SetCursorRASPosition( ras );
        lcm->SetSlicePosition( ras );
      }
      else if ( item.GetText() == _("Mouse") )
        lc->SetCurrentRASPosition( ras );
          
      UpdateList();
      m_textEditor->Hide();
    }
    else
      cerr << "Invalid index or coordinate string." << endl;
  }
}
コード例 #3
0
void InfoTreeWidget::OnEditFinished()
{
  if (!m_itemEdited)
  {
    return;
  }

  QStringList list = m_editor->text().trimmed().split(",", QString::SkipEmptyParts);
  QVariantMap map = m_itemEdited->data(1, Qt::UserRole).toMap();
  if ( list.size() < 3)
  {
    list = m_editor->text().trimmed().split(" ", QString::SkipEmptyParts);
  }
  QString type = map["Type"].toString();
  double ras[3];
  bool bSuccess = false;
  QObject* layer = map["Object"].value<QObject*>();
  if ( type == "SurfaceVertex")
  {
    bool bOK;
    int nVertex = list[0].toInt(&bOK);
    if (bOK && qobject_cast<LayerSurface*>(layer)->GetTargetAtVertex(nVertex, ras))
    {
      bSuccess = true;
    }
    else
    {
      std::cerr << "Error: Invalid input";
    }
  }
  else
  {
    if ( list.size() < 3 )
    {
      std::cerr << "Error: Need to enter 3 numbers.";
    }
    else
    {
      bool bOK;
      ras[0] = list[0].toDouble(&bOK);
      ras[1] = list[1].toDouble(&bOK);
      ras[2] = list[2].toDouble(&bOK);
      if (bOK)
      {
        if (type == "RAS")
        {
          LayerMRI* mri = (LayerMRI*)MainWindow::GetMainWindow()->GetLayerCollection("MRI")->GetLayer( 0 );
          if ( mri )
          {
            mri->RASToTarget( ras, ras );
          }
        }
        else if (type == "MRI")
        {
          LayerMRI* mri = qobject_cast<LayerMRI*>(layer);
          int nv[3] = {(int)ras[0], (int)ras[1], (int)ras[2]};
          mri->OriginalIndexToRAS( nv, ras );
          mri->RASToTarget( ras, ras );
        }
        else if (type == "SurfaceRAS")
        {
          qobject_cast<LayerSurface*>(layer)->GetTargetAtSurfaceRAS( ras, ras );
        }
        bSuccess = true;
      }
      else
      {
        std::cerr << "Error: Invalid input";
      }
    }
  }
  if (bSuccess)
  {
    m_editor->hide();
    emit RASChangeTriggered(ras[0], ras[1], ras[2]);
  }
}