#include #include #include #include #include #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 ) { this->Superclass::SetITK( o ); bool r = this->_ITK_2_VTK< itk::Mesh< float, 2 > >( o ); if( !r ) r = this->_ITK_2_VTK< itk::Mesh< double, 2 > >( o ); if( !r ) r = this->_ITK_2_VTK< itk::Mesh< float, 3 > >( o ); if( !r ) r = this->_ITK_2_VTK< itk::Mesh< double, 3 > >( o ); } // ------------------------------------------------------------------------- void cpPlugins::Mesh:: SetVTK( vtkObjectBase* o ) { 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* >( o ); if( mesh == NULL ) { this->m_ITKObject = NULL; this->Modified( ); return; } // fi if( this->m_VTKObject.GetPointer( ) != mesh ) { this->m_VTKObject = mesh; // 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 vtkCellArray* arrays[ 4 ]; arrays[ 0 ] = mesh->GetLines( ); arrays[ 1 ] = mesh->GetPolys( ); arrays[ 2 ] = NULL; // TODO: mesh->GetStrips( ); arrays[ 3 ] = mesh->GetVerts( ); for( unsigned int c = 0; c < 4; c++ ) { if( arrays[ c ] != NULL ) { vtkSmartPointer< vtkIdList > ids = vtkSmartPointer< vtkIdList >::New( ); arrays[ c ]->InitTraversal( ); while( arrays[ c ]->GetNextCell( ids ) == 1 ) { long nPoints = ids->GetNumberOfIds( ); _TCellAutoPointer icell; if( nPoints == 2 ) { icell.TakeOwnership( new _TLine ); icell->SetPointId( 0, ids->GetId( 0 ) ); icell->SetPointId( 1, ids->GetId( 1 ) ); } else if( nPoints == 3 ) { icell.TakeOwnership( new _TTriangle ); icell->SetPointId( 0, ids->GetId( 0 ) ); icell->SetPointId( 1, ids->GetId( 1 ) ); icell->SetPointId( 2, ids->GetId( 2 ) ); } else if( nPoints > 3 ) { _TPolygon* polygon = new _TPolygon( ); for( long j = 0; j < nPoints; ++j ) polygon->AddPointId( ids->GetId( j ) ); icell.TakeOwnership( polygon ); } // fi imesh->SetCell( imesh->GetNumberOfCells( ), icell ); } // elihw } // fi } // rof this->m_ITKObject = imesh; this->Modified( ); } // fi } // ------------------------------------------------------------------------- cpPlugins::Mesh:: Mesh( ) : Superclass( ) { } // ------------------------------------------------------------------------- cpPlugins::Mesh:: ~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 ) { 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 */ } // eof - $RCSfile$