1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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();
}