bool RenderView3D::PickSelectRegion( int nId ) { LayerCollection* lc_mri = MainWindow::GetMainWindow()->GetLayerCollection( "MRI" ); LayerMRI* mri = NULL; for ( int i = 0; i < lc_mri->GetNumberOfLayers(); i++ ) { LayerMRI* mri_temp = (LayerMRI*)lc_mri->GetLayer(i); if ( mri_temp->GetProperty()->GetShowAsContour() ) { mri = mri_temp; break; } } if ( !mri ) { return false; } SurfaceRegion* reg = mri->SelectSurfaceRegion( nId ); if ( reg ) { emit SurfaceRegionSelected(reg); } return true; }
void RenderView3D::DoUpdateRASPosition( int posX, int posY, bool bCursor ) { LayerCollection* lc_mri = MainWindow::GetMainWindow()->GetLayerCollection( "MRI" ); LayerCollection* lc_roi = MainWindow::GetMainWindow()->GetLayerCollection( "ROI" ); LayerCollection* lc_surface = MainWindow::GetMainWindow()->GetLayerCollection( "Surface" ); this->setToolTip(""); if ( lc_mri->IsEmpty() && lc_roi->IsEmpty() && lc_surface->IsEmpty() ) { return; } // MousePositionToRAS( posX, posY, pos ); // vtkPointPicker* picker = vtkPointPicker::SafeDownCast( this->GetPicker() ); vtkCellPicker* picker = vtkCellPicker::SafeDownCast( this->GetRenderWindow()->GetInteractor()->GetPicker() ); // vtkPropPicker* picker = vtkPropPicker::SafeDownCast( this->GetPicker() ); if ( picker ) { picker->InitializePickList(); vtkPropCollection* props = GetRenderer()->GetViewProps(); if ( props ) { props->InitTraversal(); vtkProp* prop = props->GetNextProp(); while ( prop ) { if ( vtkActor::SafeDownCast( prop ) ) { picker->AddPickList( prop ); } prop = props->GetNextProp(); } } // add bounding box for slice frame picking for ( int i = 0; i < 3; i++ ) { picker->AddPickList( m_actorSliceBoundingBox[i] ); } double pos[3]; picker->Pick( posX, rect().height() - posY, 0, GetRenderer() ); picker->GetPickPosition( pos ); vtkProp* prop = picker->GetViewProp(); if ( !prop ) { HighlightSliceFrame( -1 ); return; } // check slice frame selection first bool bFramePicked = false; double tolerance = m_dBoundingTolerance * 1.414; for ( int i = 0; i < 3; i++ ) { if ( m_actorSliceBoundingBox[i].GetPointer() == prop ) { if ( fabs( pos[0] - m_dBounds[0] ) < tolerance || fabs( pos[0] - m_dBounds[1] ) < tolerance || fabs( pos[1] - m_dBounds[2] ) < tolerance || fabs( pos[1] - m_dBounds[3] ) < tolerance || fabs( pos[2] - m_dBounds[4] ) < tolerance || fabs( pos[2] - m_dBounds[5] ) < tolerance ) { // 3D hit test passed, now we check screen distance double screen_pt[3]; double screen_pts[4][3]; int x, y; this->WorldToScreen( pos[0], pos[1], pos[2], x, y ); screen_pt[0] = x; screen_pt[1] = y; screen_pt[2] = 0; vtkPoints* pts = vtkPolyDataMapper::SafeDownCast( m_actorSliceFrames[i]->GetMapper() )->GetInput()->GetPoints(); for ( int j = 0; j < 4; j++ ) { double* p = pts->GetPoint( j ); this->WorldToScreen( p[0], p[1], p[2], x, y ); screen_pts[j][0] = x; screen_pts[j][1] = y; screen_pts[j][2] = 0; } int ids[4][2] = { {0, 1}, {1, 2}, {2, 3}, {3, 0} }; double dMinDist = 1000000000; for ( int j = 0; j < 4; j++ ) { double dist = vtkLine::DistanceToLine( screen_pt, screen_pts[ids[j][0]], screen_pts[ids[j][1]]); if ( dist < dMinDist ) { dMinDist = dist; } } if ( dMinDist < SLICE_PICKER_PIXEL_TOLERANCE ) { HighlightSliceFrame( i ); m_dIntersectPoint[0] = pos[0]; m_dIntersectPoint[1] = pos[1]; m_dIntersectPoint[2] = pos[2]; bFramePicked = true; break; } } } } if ( !bFramePicked ) { // if ( !lc_surface->IsEmpty() && !lc_surface->HasProp( prop ) ) { for ( int i = 0; i < 3; i++ ) { picker->DeletePickList( m_actorSliceBoundingBox[i] ); } picker->Pick( posX, rect().height() - posY, 0, GetRenderer() ); picker->GetPickPosition( pos ); prop = picker->GetViewProp(); } if ( lc_mri->HasProp( prop ) || lc_roi->HasProp( prop ) ) { if ( bCursor ) { LayerMRI* mri = (LayerMRI*)lc_mri->HasProp( prop ); SurfaceRegion* reg = NULL; if ( mri ) { reg = mri->SelectSurfaceRegion( pos ); } if ( reg ) { RequestRedraw( true ); // force redraw emit SurfaceRegionSelected(reg); } } else { LayerVolumeTrack* vt = qobject_cast<LayerVolumeTrack*>(lc_mri->HasProp( prop )); if (vt) { QVariantMap info = vt->GetLabelByProp(prop); if (!info.isEmpty()) { this->setToolTip(QString("%1 %2").arg(info["label"].toInt()).arg(info["name"].toString())); emit VolumeTrackMouseOver(vt, info); } } } } else if ( Layer* layer = lc_surface->HasProp( prop ) ) { if ( bCursor ) { lc_mri->SetCursorRASPosition( pos ); MainWindow::GetMainWindow()->SetSlicePosition( pos ); if (layer) { lc_surface->SetActiveLayer(layer); LayerSurface* surf = (LayerSurface*)layer; surf->SetCurrentVertex(surf->GetVertexIndexAtTarget(pos, NULL)); } emit SurfaceVertexClicked(); } else { lc_mri->SetCurrentRASPosition( pos ); } } HighlightSliceFrame( -1 ); } } }