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; } }
void RenderView3D::MoveSliceToScreenCoord( int x, int y ) { if ( m_nSliceHighlighted < 0 ) { return; } MainWindow* mainwnd = MainWindow::GetMainWindow(); LayerCollection* lc = mainwnd->GetLayerCollection( "MRI" ); if ( lc->IsEmpty() ) { lc = mainwnd->GetLayerCollection( "Surface" ); } double* bounds = m_dBounds; double slicepos[3]; lc->GetSlicePosition( slicepos ); double pt[3]; pt[0] = m_dIntersectPoint[0]; pt[1] = m_dIntersectPoint[1]; pt[2] = m_dIntersectPoint[2]; double v[3] = { 0, 0, 0 }; switch ( m_nSliceHighlighted ) { case 0: if ( qMin( fabs( pt[1] - bounds[2] ), fabs( pt[1] - bounds[3] ) ) < qMin( fabs( pt[2] - bounds[4] ), fabs( pt[2] - bounds[5] ) ) ) { v[1] = 1; if ( fabs( pt[1] - bounds[2] ) < fabs( pt[1] - bounds[3] ) ) { pt[1] = bounds[2]; } else { pt[1] = bounds[3]; } } else { v[2] = 1; if ( fabs( pt[2] - bounds[4] ) < fabs( pt[2] - bounds[5] ) ) { pt[2] = bounds[4]; } else { pt[2] = bounds[5]; } } break; case 1: if ( qMin( fabs( pt[0] - bounds[0] ), fabs( pt[0] - bounds[1] ) ) < qMin( fabs( pt[2] - bounds[4] ), fabs( pt[2] - bounds[5] ) ) ) { v[0] = 1; if ( fabs( pt[0] - bounds[0] ) < fabs( pt[0] - bounds[1] ) ) { pt[0] = bounds[0]; } else { pt[0] = bounds[1]; } } else { v[2] = 1; if ( fabs( pt[2] - bounds[4] ) < fabs( pt[2] - bounds[5] ) ) { pt[2] = bounds[4]; } else { pt[2] = bounds[5]; } } break; case 2: if ( qMin( fabs( pt[0] - bounds[0] ), fabs( pt[0] - bounds[1] ) ) < qMin( fabs( pt[1] - bounds[2] ), fabs( pt[1] - bounds[3] ) ) ) { v[0] = 1; if ( fabs( pt[0] - bounds[0] ) < fabs( pt[0] - bounds[1] ) ) { pt[0] = bounds[0]; } else { pt[0] = bounds[1]; } } else { v[1] = 1; if ( fabs( pt[1] - bounds[2] ) < fabs( pt[1] - bounds[3] ) ) { pt[1] = bounds[2]; } else { pt[1] = bounds[3]; } } break; } pt[m_nSliceHighlighted] = slicepos[m_nSliceHighlighted]; double pt1[3], pt2[3]; this->ScreenToWorld( x, y, -100, pt1[0], pt1[1], pt1[2] ); this->ScreenToWorld( x, y, 100, pt2[0], pt2[1], pt2[2] ); double new_pt[3], t = 0; vtkPlane::IntersectWithLine( pt1, pt2, v, pt, t, new_pt ); if ( t > 100000 ) { new_pt[0] = pt[0]; new_pt[1] = pt[1]; new_pt[2] = pt[2]; } if ( new_pt[m_nSliceHighlighted] < bounds[m_nSliceHighlighted*2] ) { new_pt[m_nSliceHighlighted] = bounds[m_nSliceHighlighted*2]; } else if ( new_pt[m_nSliceHighlighted] > bounds[m_nSliceHighlighted*2+1] ) { new_pt[m_nSliceHighlighted] = bounds[m_nSliceHighlighted*2+1]; } mainwnd->OffsetSlicePosition( m_nSliceHighlighted, new_pt[m_nSliceHighlighted] - slicepos[m_nSliceHighlighted], false ); slicepos[m_nSliceHighlighted] = new_pt[m_nSliceHighlighted]; lc->SetCursorRASPosition( slicepos ); }