]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Mesh.cxx
...
[cpPlugins.git] / lib / cpPlugins / Mesh.cxx
index f0e29f50b31054eb8a7fd34558b92640a6e14d62..f06aae0348568315170abdf49d668a8ba5a60980 100644 (file)
@@ -5,15 +5,51 @@
 #include <itkTriangleCell.h>
 #include <itkPolygonCell.h>
 
-#include <vtkActor.h>
-#include <vtkPolyDataNormals.h>
-#include <vtkPolyData.h>
-#include <vtkPolyDataMapper.h>
-#include <vtkQuadricLODActor.h>
-#include <vtkStripper.h>
-
 #define cpPlugins_Mesh_MAX_POLYS 65535
 
+// -------------------------------------------------------------------------
+void cpPlugins::Mesh::MeshActor::
+SetMesh( vtkPolyData* mesh )
+{
+  this->Normals = NULL;
+  this->Stripper = NULL;
+  this->Mapper = NULL;
+  this->LODActor = NULL;
+  this->Actor = NULL;
+  if( mesh != NULL )
+  {
+    unsigned long nPolys = mesh->GetNumberOfPolys( );
+    if( nPolys >= cpPlugins_Mesh_MAX_POLYS )
+    {
+      this->Normals = vtkSmartPointer< vtkPolyDataNormals >::New( );
+      this->Stripper = vtkSmartPointer< vtkStripper >::New( );
+      this->Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
+      this->LODActor = vtkSmartPointer< vtkQuadricLODActor >::New( );
+
+      double r[ 2 ];
+      mesh->GetScalarRange( r );
+
+      this->Normals->SetInputData( mesh );
+      this->Normals->SetFeatureAngle( 60.0 );
+      this->Stripper->SetInputConnection( this->Normals->GetOutputPort( ) );
+      this->Mapper->SetInputConnection( this->Stripper->GetOutputPort( ) );
+      this->Mapper->UseLookupTableScalarRangeOff( );
+      this->Mapper->SetScalarRange( r[ 0 ], r[ 1 ] );
+      this->LODActor->SetMapper( this->Mapper );
+      this->LODActor->DeferLODConstructionOff( );
+    }
+    else
+    {
+      this->Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
+      this->Actor = vtkSmartPointer< vtkActor >::New( );
+      this->Mapper->SetInputData( mesh );
+      this->Actor->SetMapper( this->Mapper );
+
+    } // fi
+
+  } // fi
+}
+
 // -------------------------------------------------------------------------
 void cpPlugins::Mesh::
 SetITK( itk::LightObject* o )
@@ -132,6 +168,17 @@ cpPlugins::Mesh::
 void cpPlugins::Mesh::
 _CreateVTKActor( ) const
 {
+  this->m_MeshActor.SetMesh(
+    const_cast< vtkPolyData* >( this->GetVTK< vtkPolyData >( ) )
+    );
+  if( this->m_MeshActor.LODActor.GetPointer( ) != NULL )
+    this->m_Actor = this->m_MeshActor.LODActor.GetPointer( );
+  else if( this->m_MeshActor.Actor.GetPointer( ) != NULL )
+    this->m_Actor = this->m_MeshActor.Actor.GetPointer( );
+  else
+    this->m_Actor = NULL;
+  
+  /* TODO
   vtkPolyData* mesh =
     const_cast< vtkPolyData* >( this->GetVTK< vtkPolyData >( ) );
   if( mesh != NULL )
@@ -172,6 +219,7 @@ _CreateVTKActor( ) const
     } // fi
 
   } // fi
+  */
 }
 
 // eof - $RCSfile$