]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Wed, 3 Feb 2016 22:16:44 +0000 (17:16 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Wed, 3 Feb 2016 22:16:44 +0000 (17:16 -0500)
COMPILATION
lib/cpPlugins/Interface/Mesh.cxx
lib/cpPlugins/Interface/Mesh.h
lib/cpPlugins/Plugins/BasicFilters/AppendMeshesFilter.cxx [new file with mode: 0644]
lib/cpPlugins/Plugins/BasicFilters/AppendMeshesFilter.h [new file with mode: 0644]

index de796b54af9667354ca426d2cf3cc1f7b2b5893f..f85b498a7a4dcaaf969ccec7cb2475a3010e2a1d 100644 (file)
@@ -70,7 +70,7 @@
          Module_vtkGUISupportQtWebkit:BOOL=OFF \
        NOTE: Normally, windows compilers already support c++11.
 
-  3. Insight Toolkit -ITK- (>=4.6.0)
+  4. Insight Toolkit -ITK- (>=4.6.0)
     1. Download ITK source code from http://www.itk.org, copy the downloaded
        zip/tar.gz file to your work directory (say ~/sources), uncompress the
        source file and create an empty folder (say ~/sources/itk-build)
index 94adb2bb163ae5f47da17ff9e62abb41d22d74c4..d56d1929aebeb81719640b70f20d80460975c775 100644 (file)
@@ -1,16 +1,85 @@
 #include <cpPlugins/Interface/Mesh.h>
 
+#include <itkMesh.h>
+#include <itkLineCell.h>
+#include <itkTriangleCell.h>
+#include <itkPolygonCell.h>
+
 #include <vtkPolyData.h>
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::Mesh::
-SetVTK( vtkObject* mesh )
+SetVTK( vtkObject* object )
 {
-  if( dynamic_cast< vtkPolyData* >( mesh ) != NULL )
+  typedef itk::Mesh< double, 3 >      _TMesh;
+  typedef _TMesh::CellType            _TCell;
+  typedef _TCell::CellAutoPointer     _TCellAutoPointer;
+  typedef itk::LineCell< _TCell >     _TLine;
+  typedef itk::TriangleCell< _TCell > _TTriangle;
+  typedef itk::PolygonCell< _TCell >  _TPolygon;
+
+  vtkPolyData* mesh = dynamic_cast< vtkPolyData* >( object );
+  if( mesh == NULL )
+  {
+    this->m_ITKObject = NULL;
+    this->Modified( );
+    return;
+
+  } // fi
+
+  if( this->m_VTKObject.GetPointer( ) != mesh )
+  {
     this->m_VTKObject = mesh;
-  else
-    this->m_VTKObject = NULL;
-  this->Modified( );
+
+    // Copy points
+    _TMesh::Pointer imesh = _TMesh::New( );
+    double point[ 3 ];
+    for( long i = 0; i < mesh->GetNumberOfPoints( ); ++i )
+    {
+      mesh->GetPoint( i, point );
+      _TMesh::PointType ipoint;
+      ipoint[ 0 ] = point[ 0 ];
+      ipoint[ 1 ] = point[ 1 ];
+      ipoint[ 2 ] = point[ 2 ];
+      imesh->SetPoint( i, ipoint );
+
+    } // rof
+
+    // Copy cells
+    for( long i = 0; i < mesh->GetNumberOfCells( ); ++i )
+    {
+      auto cell = mesh->GetCell( i );
+      long nPoints = cell->GetNumberOfPoints( );
+      _TCellAutoPointer icell;
+      if( nPoints == 2 )
+      {
+        icell.TakeOwnership( new _TLine );
+        icell->SetPointId( 0, cell->GetPointId( 0 ) );
+        icell->SetPointId( 1, cell->GetPointId( 1 ) );
+      }
+      else if( nPoints == 3 )
+      {
+        icell.TakeOwnership( new _TTriangle );
+        icell->SetPointId( 0, cell->GetPointId( 0 ) );
+        icell->SetPointId( 1, cell->GetPointId( 1 ) );
+        icell->SetPointId( 2, cell->GetPointId( 2 ) );
+      }
+      else if( nPoints > 3 )
+      {
+        _TPolygon* polygon = new _TPolygon( );
+        for( long j = 0; j < nPoints; ++j )
+          polygon->AddPointId( cell->GetPointId( j ) );
+        icell.TakeOwnership( polygon );
+
+      } // fi
+      imesh->SetCell( imesh->GetNumberOfCells( ), icell );
+
+    } // rof
+
+    this->m_ITKObject = imesh;
+    this->Modified( );
+
+  } // fi
 }
 // -------------------------------------------------------------------------
 cpPlugins::Interface::Mesh::
index 8754b0e9931bd7ac6fbdbce1d7ac839b6cb033b6..d1aa65e54a141bf13e5b7351fa1df15c2b281036 100644 (file)
@@ -30,7 +30,7 @@ namespace cpPlugins
       template< class M >
         inline void SetITK( M* mesh );
 
-      virtual void SetVTK( vtkObject* mesh );
+      virtual void SetVTK( vtkObject* object );
 
     protected:
       Mesh( );
diff --git a/lib/cpPlugins/Plugins/BasicFilters/AppendMeshesFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/AppendMeshesFilter.cxx
new file mode 100644 (file)
index 0000000..9121540
--- /dev/null
@@ -0,0 +1,41 @@
+#include "AppendMeshesFilter.h"
+#include <cpPlugins/Interface/Mesh.h>
+
+#include <vtkAppendPolyData.h>
+
+// -------------------------------------------------------------------------
+cpPlugins::BasicFilters::AppendMeshesFilter::
+AppendMeshesFilter( )
+  : Superclass( )
+{
+  this->_AddInput( "Input0" );
+  this->_AddInput( "Input1" );
+  this->_AddOutput< cpPlugins::Interface::Mesh >( "Output" );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::BasicFilters::AppendMeshesFilter::
+~AppendMeshesFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::BasicFilters::AppendMeshesFilter::
+_GenerateData( )
+{
+  auto m0 = this->GetInputData< cpPlugins::Interface::Mesh >( "Input0" );
+  auto m1 = this->GetInputData< cpPlugins::Interface::Mesh >( "Input1" );
+  if( m0 == NULL || m1 == NULL )
+    return( "AppendMeshesFilter: No input meshes." );
+
+  auto filter = this->_CreateVTK< vtkAppendPolyData >( );
+  filter->AddInputData( m0->GetVTK< vtkPolyData >( ) );
+  filter->AddInputData( m1->GetVTK< vtkPolyData >( ) );
+  filter->Update( );
+
+  auto out = this->GetOutputData< cpPlugins::Interface::Mesh >( "Output" );
+  out->SetVTK( filter->GetOutput( ) );
+  return( "" );
+}
+
+// eof - $RCSfile$
diff --git a/lib/cpPlugins/Plugins/BasicFilters/AppendMeshesFilter.h b/lib/cpPlugins/Plugins/BasicFilters/AppendMeshesFilter.h
new file mode 100644 (file)
index 0000000..d814a2a
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef __CPPLUGINS__PLUGINS__APPENDMESHESFILTER__H__
+#define __CPPLUGINS__PLUGINS__APPENDMESHESFILTER__H__
+
+#include <cpPlugins/BasicFilters/cpPluginsBasicFilters_Export.h>
+#include <cpPlugins/Interface/BaseProcessObjects.h>
+
+namespace cpPlugins
+{
+  namespace BasicFilters
+  {
+    /**
+     */
+    class cpPluginsBasicFilters_EXPORT AppendMeshesFilter
+      : public cpPlugins::Interface::MeshToMeshFilter
+    {
+    public:
+      typedef AppendMeshesFilter                     Self;
+      typedef cpPlugins::Interface::MeshToMeshFilter Superclass;
+      typedef itk::SmartPointer< Self >              Pointer;
+      typedef itk::SmartPointer< const Self >        ConstPointer;
+
+    public:
+      itkNewMacro( Self );
+      itkTypeMacro(
+        AppendMeshesFilter,
+        cpPlugins::Interface::MeshToMeshFilter
+        );
+      cpPlugins_Id_Macro(
+        cpPlugins::BasicFilters::AppendMeshesFilter,
+        MeshToMeshFilter
+        );
+
+    protected:
+      AppendMeshesFilter( );
+      virtual ~AppendMeshesFilter( );
+
+      virtual std::string _GenerateData( );
+
+    private:
+      // Purposely not implemented
+      AppendMeshesFilter( const Self& );
+      Self& operator=( const Self& );
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __CPPLUGINS__PLUGINS__APPENDMESHESFILTER__H__
+
+// eof - $RCSfile$