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 pCoorPress = vtkSmartPointer::New();
pCoorPress->SetCoordinateSystemToDisplay();
pCoorPress->SetValue( m_pressPoint.x(), nHeight - m_pressPoint.y(), 0.0 );
dPressValue = pCoorPress->GetComputedWorldValue( m_pRenderer );
vtkSmartPointer pCoorMove = vtkSmartPointer::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 pPoints = vtkSmartPointer::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 line1 = vtkSmartPointer::New();
line1->GetPointIds()->SetId( 0, 0 );
line1->GetPointIds()->SetId( 1, 1 );
vtkSmartPointer line2 = vtkSmartPointer::New();
line2->GetPointIds()->SetId( 0, 1 );
line2->GetPointIds()->SetId( 1, 2 );
vtkSmartPointer line3 = vtkSmartPointer::New();
line3->GetPointIds()->SetId( 0, 2 );
line3->GetPointIds()->SetId( 1, 3 );
vtkSmartPointer line4 = vtkSmartPointer::New();
line4->GetPointIds()->SetId( 0, 3 );
line4->GetPointIds()->SetId( 1, 0 );
vtkSmartPointer lineArray = vtkSmartPointer::New();
lineArray->InsertNextCell( line1 );
lineArray->InsertNextCell( line2 );
lineArray->InsertNextCell( line3 );
lineArray->InsertNextCell( line4 );
if( NULL == m_pPolyData )
{
m_pPolyData = vtkSmartPointer::New();
m_pPolyData->SetPoints( pPoints );
m_pPolyData->SetLines( lineArray );
m_pPolyData->Modified();
vtkSmartPointer mapper = vtkSmartPointer::New();
mapper->SetInputData( m_pPolyData );
vtkSmartPointer actor = vtkSmartPointer::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();
}
文章题目:VTK屏幕坐标与世界坐标转换(Qt)
本文路径:
http://bzwzjz.com/article/jospde.html