标签:vtk 坐标转换
void VtkMPRWidget::mousePressEvent( QMouseEvent* event ) { m_bPressed = true; m_pressPoint = event->pos(); } void VtkMPRWidget::mouseMoveEvent( QMouseEvent* event ) { if( !m_bPressed ) return; m_movePoint = event->pos(); int nHeight = height(); double* dPressValue; double* dMoveValue; vtkSmartPointer<vtkCoordinate> pCoorPress = vtkSmartPointer<vtkCoordinate>::New(); pCoorPress->SetCoordinateSystemToDisplay(); pCoorPress->SetValue( m_pressPoint.x(), nHeight - m_pressPoint.y(), 0.0 ); dPressValue = pCoorPress->GetComputedWorldValue( m_pRenderer ); vtkSmartPointer<vtkCoordinate> pCoorMove = vtkSmartPointer<vtkCoordinate>::New(); pCoorMove->SetCoordinateSystemToDisplay(); pCoorMove->SetValue( m_movePoint.x(), nHeight - m_movePoint.y(), 0.0 ); dMoveValue = pCoorMove->GetComputedWorldValue( m_pRenderer ); double dPressVal[3] = { dPressValue[0], dPressValue[1], dPressValue[2] }; double dMoveVal[3] = { dMoveValue[0], dMoveValue[1], dMoveValue[2] }; vtkSmartPointer<vtkPoints> pPoints = vtkSmartPointer<vtkPoints>::New(); pPoints->InsertNextPoint( dPressVal[0], dPressVal[1], 0.0 ); pPoints->InsertNextPoint( dPressVal[0], dMoveVal[1], 0.0 ); pPoints->InsertNextPoint( dMoveVal[0], dMoveVal[1], 0.0 ); pPoints->InsertNextPoint( dMoveVal[0], dPressVal[1], 0.0 ); vtkSmartPointer<vtkLine> line1 = vtkSmartPointer<vtkLine>::New(); line1->GetPointIds()->SetId( 0, 0 ); line1->GetPointIds()->SetId( 1, 1 ); vtkSmartPointer<vtkLine> line2 = vtkSmartPointer<vtkLine>::New(); line2->GetPointIds()->SetId( 0, 1 ); line2->GetPointIds()->SetId( 1, 2 ); vtkSmartPointer<vtkLine> line3 = vtkSmartPointer<vtkLine>::New(); line3->GetPointIds()->SetId( 0, 2 ); line3->GetPointIds()->SetId( 1, 3 ); vtkSmartPointer<vtkLine> line4 = vtkSmartPointer<vtkLine>::New(); line4->GetPointIds()->SetId( 0, 3 ); line4->GetPointIds()->SetId( 1, 0 ); vtkSmartPointer<vtkCellArray> lineArray = vtkSmartPointer<vtkCellArray>::New(); lineArray->InsertNextCell( line1 ); lineArray->InsertNextCell( line2 ); lineArray->InsertNextCell( line3 ); lineArray->InsertNextCell( line4 ); if( NULL == m_pPolyData ) { m_pPolyData = vtkSmartPointer<vtkPolyData>::New(); m_pPolyData->SetPoints( pPoints ); m_pPolyData->SetLines( lineArray ); m_pPolyData->Modified(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mapper->SetInputData( m_pPolyData ); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); actor->SetMapper( mapper ); actor->GetProperty()->SetLineWidth( 1.5 ); actor->GetProperty()->SetColor( 0.3, 0.8, 0.0 ); m_pRenderer->AddActor( actor ); m_pRenderer->Modified(); m_pRednerWindow->Modified(); m_pRednerWindow->Render(); return; } m_pPolyData->SetPoints( pPoints ); m_pPolyData->SetLines( lineArray ); m_pPolyData->Modified(); m_pRednerWindow->Modified(); m_pRednerWindow->Render(); } void VtkMPRWidget::mouseReleaseEvent( QMouseEvent* event ) { m_bPressed = false; m_pPolyData = NULL; //FireObjectChanged(); }
本文出自 “开源,分享,进步” 博客,请务必保留此出处http://weiyuqingcheng.blog.51cto.com/4865776/1940551
标签:vtk 坐标转换
原文地址:http://weiyuqingcheng.blog.51cto.com/4865776/1940551