]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Mesh.cxx
829c1f53417839f1c41aa9ef3fea1bbdf3f4ab4f
[cpPlugins.git] / lib / cpPlugins / Interface / Mesh.cxx
1 #include <cpPlugins/Interface/Mesh.h>
2
3 #include <vtkPolyData.h>
4
5 // -------------------------------------------------------------------------
6 void cpPlugins::Interface::Mesh::
7 SetVTK( vtkObject* mesh )
8 {
9   if( dynamic_cast< vtkPolyData* >( mesh ) != NULL )
10     this->m_VTKObject = mesh;
11   else
12     this->m_VTKObject = NULL;
13   this->m_Mapper = NULL;
14   this->m_Actor = NULL;
15   this->Modified( );
16 }
17
18 // -------------------------------------------------------------------------
19 void cpPlugins::Interface::Mesh::
20 CreateVTKActor( )
21 {
22   vtkPolyData* pd = this->GetVTK< vtkPolyData >( );
23   if(
24     pd != NULL &&
25     (
26       this->m_Mapper.GetPointer( ) == NULL ||
27       this->m_Actor.GetPointer( ) == NULL
28       )
29     )
30   {
31     double range[ 2 ];
32     pd->GetScalarRange( range );
33
34     this->m_Normals = vtkSmartPointer< vtkPolyDataNormals >::New( );
35     this->m_Stripper = vtkSmartPointer< vtkStripper >::New( );
36     this->m_Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
37     this->m_Actor = vtkSmartPointer< vtkQuadricLODActor >::New( );
38
39     this->m_Normals->SetInputData( pd );
40     this->m_Normals->SetFeatureAngle( 60.0 );
41     this->m_Stripper->SetInputConnection( this->m_Normals->GetOutputPort( ) );
42     this->m_Mapper->SetInputConnection( this->m_Stripper->GetOutputPort( ) );
43     this->m_Mapper->UseLookupTableScalarRangeOff( );
44     this->m_Mapper->SetScalarRange(
45       range[ 0 ], ( ( range[ 1 ] - range[ 0 ] ) * 0.75 ) + range[ 0 ]
46       );
47     this->m_Actor->SetMapper( this->m_Mapper );
48     this->m_Actor->DeferLODConstructionOff( );
49     this->Modified( );
50
51     /*
52       TODO: vtkQuadricLODActor : AllocatedRenderTime
53     */
54
55   } // fi
56 }
57
58 // -------------------------------------------------------------------------
59 vtkActor* cpPlugins::Interface::Mesh::
60 GetVTKActor( )
61 {
62   return( this->m_Actor );
63 }
64
65 // -------------------------------------------------------------------------
66 const vtkActor* cpPlugins::Interface::Mesh::
67 GetVTKActor( ) const
68 {
69   return( this->m_Actor );
70 }
71
72 // -------------------------------------------------------------------------
73 cpPlugins::Interface::Mesh::
74 Mesh( )
75   : Superclass( ),
76     m_Mapper( NULL ),
77     m_Actor( NULL )
78 {
79 }
80
81 // -------------------------------------------------------------------------
82 cpPlugins::Interface::Mesh::
83 ~Mesh( )
84 {
85 }
86
87 // eof - $RCSfile$