]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Since now ElnoDisassemblyFilter has ability to shrink the newly generated point coord...
authorapo <apo@opencascade.com>
Fri, 2 May 2008 08:05:09 +0000 (08:05 +0000)
committerapo <apo@opencascade.com>
Fri, 2 May 2008 08:05:09 +0000 (08:05 +0000)
src/PIPELINE/VISUPipeLine.cxx
src/PIPELINE/VISU_ElnoDisassembleFilter.cxx
src/PIPELINE/VISU_ElnoExtractScalars.cxx
src/PIPELINE/VISU_ElnoExtractScalars.hxx

index 79d4cae4a86ca8ca928526717a2fd1770c497e6a..692c7e7475ff0336e6b1b85f17368e7a59038b48 100644 (file)
@@ -51,6 +51,9 @@
 #include "VISU_ElnoDisassembleFilter.hxx"
 #include "VISU_ElnoExtractScalars.hxx"
 
+#include <vtkShrinkFilter.h>
+#include <vtkPointLocator.h>
+
 #include <vtkCutter.h>
 #include <vtkPlane.h>
 
@@ -253,11 +256,23 @@ main(int argc, char** argv)
              VISU::WriteToFile( aDisassembleFilter->GetOutput(), "/data/apo/elno_from_disassemble.vtk" );
 
              VISU_ElnoExtractScalars* anExtractScalars = VISU_ElnoExtractScalars::New();
+              anExtractScalars->SetScalarMode( aComponentNumber );
              anExtractScalars->SetInput( aDisassembleFilter->GetOutput() );
              VISU::WriteToFile( anExtractScalars->GetOutput(), "/data/apo/elno_from_scalars.vtk" );
 
+             vtkShrinkFilter* aShrinkFilter = vtkShrinkFilter::New();
+             aShrinkFilter->SetInput( anExtractScalars->GetOutput() );
+             aShrinkFilter->SetShrinkFactor( 0.999 );
+             VISU::WriteToFile( aShrinkFilter->GetOutput(), "/data/apo/elno_from_shrink.vtk" );
+
              vtkCutter *aCutter = vtkCutter::New();
-             aCutter->SetInput( anUnstructuredGrid );
+
+             vtkPointLocator* aPointLocator = vtkPointLocator::New();
+             aCutter->SetLocator( aPointLocator );
+             aPointLocator->Delete();
+
+             aCutter->SetInput( anExtractScalars->GetOutput() );
+             //aCutter->SetInput( aShrinkFilter->GetOutput() );
 
              vtkPlane *aPlane = vtkPlane::New();
              //aPlane->SetOrigin( 100.0, 100.0, 100.0 );
@@ -281,7 +296,8 @@ main(int argc, char** argv)
 
              vtkFloatingPointType aScalarRange[ 2 ];
              aGeometryFilter->GetRange( aScalarRange );
-
+             anExtractScalars->GetOutput()->GetScalarRange( aScalarRange );
+             aCutter->GetOutput()->GetScalarRange( aScalarRange );
              // To calculate and apply default scale factor
              //{
              //        vtkFloatingPointType aScale = VISU_DeformedShapePL::GetScaleFactor( anElnoWarpVector->GetOutput() );
@@ -289,8 +305,12 @@ main(int argc, char** argv)
              //        anElnoWarpVector->SetScaleFactor( aScale );
              //}
 
-              VISU_OpenGLElnoMapper* aMapper = VISU_OpenGLElnoMapper::New();
-              aMapper->SetInput( aGeometryFilter->GetOutput() );              
+              //VISU_OpenGLElnoMapper* aMapper = VISU_OpenGLElnoMapper::New();
+             vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
+             aMapper->SetScalarModeToUsePointData();
+
+              //aMapper->SetInput( aGeometryFilter->GetOutput() );              
+             aMapper->SetInput( aCutter->GetOutput() );
 
               VISU_LookupTable* aMapperTable( VISU_LookupTable::New() );
               aMapperTable->SetHueRange( 0.667, 0.0 );
@@ -302,7 +322,7 @@ main(int argc, char** argv)
               aMapper->SetColorModeToMapScalars();
               aMapper->ScalarVisibilityOn();
 
-              anActor->SetMapper( aMapper );
+             anActor->SetMapper( aMapper );
 
               vtkScalarBarActor* aScalarBar = vtkScalarBarActor::New();
               aScalarBar->SetLookupTable( aMapperTable );
index f103f6341bc9fd6b597e28d6ba68ea9c3ab93892..e7ecfedf7d7274550c518a5c2680161ee926bb29 100644 (file)
@@ -91,21 +91,58 @@ namespace
     TElnoDataArray* anElnoPointsDataArray = TElnoDataArray::New();
     anElnoPointsDataArray->SetNumberOfComponents( aGetElnoNodeData.getNbComp() );
     anElnoPointsDataArray->SetNumberOfTuples( aNbPoints );
-    anElnoPointsDataArray->SetName( "ELNO_POINTS_DATA" );
+    anElnoPointsDataArray->SetName( "ELNO_POINT_DATA" );
+
+    TPointsDataArray* aPointCoords = TPointsDataArray::New();
+    aPointCoords->SetNumberOfComponents( 3 );
+    aPointCoords->SetNumberOfTuples( aNbPoints );
+    aPointCoords->SetName( "ELNO_POINT_COORDS" );
 
     aConnectivity->InitTraversal();
     vtkIdType aNbPts = 0, *aPts = 0;
     for ( vtkIdType aCellId = 0; aConnectivity->GetNextCell( aNbPts, aPts ); aCellId++ ) {
+
+      TPointsDataType aCenter[ 3 ] = { TPointsDataType(), 
+                                      TPointsDataType(), 
+                                      TPointsDataType() };
+
+      for ( vtkIdType aPntId = 0; aPntId < aNbPts; aPntId++ ) {
+       TPointsDataType aCoords[ 3 ];
+       anInputPointsArray->GetTupleValue( aPts[ aPntId ], aCoords );
+
+       aCenter[ 0 ] += aCoords[ 0 ];
+       aCenter[ 1 ] += aCoords[ 1 ];
+       aCenter[ 2 ] += aCoords[ 2 ];
+      }
+
+      aCenter[ 0 ] /= aNbPts;
+      aCenter[ 1 ] /= aNbPts;
+      aCenter[ 2 ] /= aNbPts;
+
       for ( vtkIdType aPntId = 0; aPntId < aNbPts; aPntId++ ) {
        TPointsDataType aCoords[ 3 ];
        vtkIdType aCurrentPntId = aPts[ aPntId ];
        anInputPointsArray->GetTupleValue( aCurrentPntId, aCoords );
-       aPts[ aPntId ] = anOutputPointsArray->InsertNextTupleValue( aCoords );
 
-       aPointData->CopyData( anInputPointData, aCurrentPntId, aPts[ aPntId ] );
+       TPointsDataType aNewCoords[ 3 ];
+       static vtkFloatingPointType SHRINK_FACTOR = 0.999;
+
+       aNewCoords[ 0 ] = aCenter[ 0 ]  + 
+         TPointsDataType( SHRINK_FACTOR * ( aCoords[ 0 ] - aCenter[ 0 ] ) );
+       aNewCoords[ 1 ] = aCenter[ 1 ]  + 
+         TPointsDataType( SHRINK_FACTOR * ( aCoords[ 1 ] - aCenter[ 1 ] ) );
+       aNewCoords[ 2 ] = aCenter[ 2 ]  + 
+         TPointsDataType( SHRINK_FACTOR * ( aCoords[ 2 ] - aCenter[ 2 ] ) );
+
+       aPts[ aPntId ] = anOutputPointsArray->InsertNextTupleValue( aNewCoords );
+       vtkIdType aNewPntId = aPts[ aPntId ];
+
+       aPointCoords->SetTupleValue( aNewPntId, aCoords );
+
+       aPointData->CopyData( anInputPointData, aCurrentPntId, aNewPntId );
 
        TElnoDataType* anElnoData = aGetElnoNodeData( aCellId, aPntId );
-       anElnoPointsDataArray->SetTupleValue( aPts[ aPntId ],  anElnoData );
+       anElnoPointsDataArray->SetTupleValue( aNewPntId,  anElnoData );
       }
     }
     
@@ -115,11 +152,18 @@ namespace
                         theInput->GetCellLocationsArray(),
                         aConnectivity );
     
-    theOutput->GetCellData()->PassData( theInput->GetCellData() );
+    vtkCellData *aCellData = theOutput->GetCellData();
+    aCellData->PassData( theInput->GetCellData() );
+
+    aCellData->RemoveArray( "ELNO_COMPONENT_MAPPER" );
+    aCellData->RemoveArray( "ELNO_FIELD" );
 
     aPointData->AddArray( anElnoPointsDataArray );
     anElnoPointsDataArray->Delete();
     
+    aPointData->AddArray( aPointCoords );
+    aPointCoords->Delete();
+    
     return 1;
   }
           
index 6af5b7b9a7dda43d6f8a87d320d07835aced17b8..c61786464ff37238b2f8725609d746619e4846f7 100644 (file)
@@ -42,7 +42,7 @@ VISU_ElnoExtractScalars::VISU_ElnoExtractScalars()
                                0, // port
                                0, // connection
                                vtkDataObject::FIELD_ASSOCIATION_POINTS, // field association
-                               "ELNO_POINTS_DATA" ); // name
+                               "ELNO_POINT_DATA" ); // name
 
   myScalarMode = 1;
 }
@@ -53,6 +53,24 @@ VISU_ElnoExtractScalars::~VISU_ElnoExtractScalars()
 {}
 
 
+//----------------------------------------------------------------------------
+void VISU_ElnoExtractScalars::SetScalarMode( vtkIdType theValue )
+{
+  if ( myScalarMode == theValue ) 
+    return;
+
+  myScalarMode = theValue;
+  this->Modified();
+}
+
+
+//----------------------------------------------------------------------------
+vtkIdType VISU_ElnoExtractScalars::GetScalarMode()
+{
+  return myScalarMode;
+}
+
+
 //----------------------------------------------------------------------------
 namespace
 {
index fba4ac27fceacb0b1e9cd267a47c4603d4b85b47..d33ad146a9e51148450a3501c393737bcfbee661 100644 (file)
@@ -29,7 +29,6 @@ public:
 
   static VISU_ElnoExtractScalars *New();
 
-  //! Specify value to scale displacement.
   void SetScalarMode( vtkIdType theValue );
   vtkIdType GetScalarMode();