]> Creatis software - cpPlugins.git/commitdiff
Ortho normal bases added.
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 27 May 2016 14:52:30 +0000 (09:52 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 27 May 2016 14:52:30 +0000 (09:52 -0500)
lib/cpPlugins/Mesh.cxx
lib/cpPlugins/OrthoNormalBase.cxx [new file with mode: 0644]
lib/cpPlugins/OrthoNormalBase.h [new file with mode: 0644]
lib/cpPlugins/OrthoNormalBase.hxx [new file with mode: 0644]

index 2854840d33f8eeb5158f2cec010214e79302bd82..f0e29f50b31054eb8a7fd34558b92640a6e14d62 100644 (file)
@@ -5,7 +5,14 @@
 #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::
@@ -129,14 +136,40 @@ _CreateVTKActor( ) const
     const_cast< vtkPolyData* >( this->GetVTK< vtkPolyData >( ) );
   if( mesh != NULL )
   {
-    std::cout << "Mesh: " << mesh << std::endl;
-    /* TODO
-       vtkImageSliceMapper* mapper = vtkImageSliceMapper::New( );
-       vtkImageActor* actor = vtkImageActor::New( );
-       mapper->SetInputData( image );
-       actor->SetMapper( mapper );
-       this->m_Actor = actor;
-    */
+    unsigned long nPolys = mesh->GetNumberOfPolys( );
+    if( nPolys >= cpPlugins_Mesh_MAX_POLYS )
+    {
+      auto normals = vtkPolyDataNormals::New( );
+      auto stripper = vtkStripper::New( );
+      auto mapper = vtkPolyDataMapper::New( );
+      auto actor = vtkQuadricLODActor::New( );
+
+      double r[ 2 ];
+      mesh->GetScalarRange( r );
+
+      normals->SetInputData( mesh );
+      normals->SetFeatureAngle( 60.0 );
+      stripper->SetInputConnection( normals->GetOutputPort( ) );
+      mapper->SetInputConnection( stripper->GetOutputPort( ) );
+      mapper->UseLookupTableScalarRangeOff( );
+      mapper->SetScalarRange( r[ 0 ], r[ 1 ] );
+      actor->SetMapper( mapper );
+      actor->DeferLODConstructionOff( );
+      this->m_Actor = actor;
+      mapper->Delete( );
+      stripper->Delete( );
+      normals->Delete( );
+    }
+    else
+    {
+      auto mapper = vtkPolyDataMapper::New( );
+      mapper->SetInputData( mesh );
+      auto actor = vtkActor::New( );
+      actor->SetMapper( mapper );
+      this->m_Actor = actor;
+      mapper->Delete( );
+
+    } // fi
 
   } // fi
 }
diff --git a/lib/cpPlugins/OrthoNormalBase.cxx b/lib/cpPlugins/OrthoNormalBase.cxx
new file mode 100644 (file)
index 0000000..4ad0255
--- /dev/null
@@ -0,0 +1,39 @@
+#include <cpPlugins/OrthoNormalBase.h>
+#include <vtkMatrix4x4.h>
+// -------------------------------------------------------------------------
+void cpPlugins::OrthoNormalBase::
+SetITK( itk::LightObject* o )
+{
+  // Do nothing since itk::Matrix does not belong to LightObject hierarchy.
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::OrthoNormalBase::
+SetVTK( vtkObjectBase* o )
+{
+  auto matrix = dynamic_cast< vtkMatrix4x4* >( o );
+  if( matrix !=  NULL )
+    this->Superclass::SetVTK( matrix );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::OrthoNormalBase::
+OrthoNormalBase( )
+  : Superclass( )
+{
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::OrthoNormalBase::
+~OrthoNormalBase( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::OrthoNormalBase::
+_CreateVTKActor( ) const
+{
+}
+
+// eof - $RCSfile$
diff --git a/lib/cpPlugins/OrthoNormalBase.h b/lib/cpPlugins/OrthoNormalBase.h
new file mode 100644 (file)
index 0000000..46983dc
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef __CPPLUGINS__ORTHONORMALBASE__H__
+#define __CPPLUGINS__ORTHONORMALBASE__H__
+
+#include <cpPlugins/DataObject.h>
+
+namespace cpPlugins
+{
+  /**
+   */
+  class cpPlugins_EXPORT OrthoNormalBase
+    : public DataObject
+  {
+  public:
+    typedef OrthoNormalBase                 Self;
+    typedef DataObject                      Superclass;
+    typedef itk::SmartPointer< Self >       Pointer;
+    typedef itk::SmartPointer< const Self > ConstPointer;
+
+  public:
+    itkNewMacro( Self );
+    itkTypeMacro( OrthoNormalBase, DataObject );
+    cpPlugins_Id_Macro( OrthoNormalBase, Object );
+
+  public:
+    virtual void SetITK( itk::LightObject* o ) ITK_OVERRIDE;
+    virtual void SetVTK( vtkObjectBase* o ) ITK_OVERRIDE;
+
+    template< class _TMatrix >
+      inline void SetITK( const _TMatrix& m );
+
+  protected:
+    OrthoNormalBase( );
+    virtual ~OrthoNormalBase( );
+
+    virtual void _CreateVTKActor( ) const ITK_OVERRIDE;
+
+  private:
+    // Purposely not implemented
+    OrthoNormalBase( const Self& );
+    Self& operator=( const Self& );
+  };
+
+} // ecapseman
+
+#include <cpPlugins/OrthoNormalBase.hxx>
+
+#endif // __CPPLUGINS__ORTHONORMALBASE__H__
+
+// eof - $RCSfile$
diff --git a/lib/cpPlugins/OrthoNormalBase.hxx b/lib/cpPlugins/OrthoNormalBase.hxx
new file mode 100644 (file)
index 0000000..9b9e4e7
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef __CPPLUGINS__ORTHONORMALBASE__HXX__
+#define __CPPLUGINS__ORTHONORMALBASE__HXX__
+
+#include <vtkMatrix4x4.h>
+
+// -------------------------------------------------------------------------
+template< class _TMatrix >
+void cpPlugins::OrthoNormalBase::
+SetITK( const _TMatrix& m )
+{
+  vtkMatrix4x4* matrix = vtkMatrix4x4::New( );
+  matrix->Identity( );
+  for( unsigned int i = 0; i < 4; ++i )
+    if( i < _TMatrix::RowDimensions )
+      for( unsigned int j = 0; j < 4; ++j )
+        if( j < _TMatrix::ColumnDimensions )
+          matrix->SetElement( i, j, m[ i ][ j ] );
+  this->m_VTKObject = matrix;
+}
+
+#endif // __CPPLUGINS__ORTHONORMALBASE__HXX__
+
+// eof - $RCSfile$