Salome HOME
#18963 Minimize compiler warnings
[modules/smesh.git] / src / OBJECT / SMESH_DeviceActor.cxx
index aeba34ad97d1ed7c87277dc2227842e659864a2d..882326963314396aa3ab25a17d6c9a902d13d1bc 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -37,6 +37,7 @@
 #include <VTKViewer_Transform.h>
 #include <VTKViewer_TransformFilter.h>
 #include <VTKViewer_ExtractUnstructuredGrid.h>
+#include <VTKViewer_Actor.h>
 
 // VTK Includes
 #include <vtkObjectFactory.h>
@@ -76,7 +77,7 @@ static int MYDEBUG = 0;
 using namespace std;
 
 
-vtkStandardNewMacro(SMESH_DeviceActor);
+vtkStandardNewMacro(SMESH_DeviceActor)
 
 
 SMESH_DeviceActor
@@ -88,14 +89,14 @@ SMESH_DeviceActor
   myIsShrunk = false;
   myIsHighlited = false;
 
-  myRepresentation = eSurface;
+  myRepresentation = SMESH_DeviceActor::EReperesent(-1);
 
   myProperty = vtkProperty::New();
   myMapper = VTKViewer_PolyDataMapper::New();
   myPlaneCollection = vtkPlaneCollection::New();
 
-  vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
-                                                                 myPolygonOffsetUnits);
+  VTKViewer_Actor::GetDefaultPolygonOffsetParameters(myPolygonOffsetFactor,
+                                                     myPolygonOffsetUnits);
 
   myMapper->UseLookupTableScalarRangeOn();
   myMapper->SetColorModeToMapScalars();
@@ -142,7 +143,7 @@ SMESH_DeviceActor
   if(MYDEBUG) MESSAGE("~SMESH_DeviceActor - "<<this);
 
   myMapper->Delete();
-
+  // myPlaneCollection->Delete(); -- it is vtkSmartPointer
   myProperty->Delete();
 
   myExtractGeometry->Delete();
@@ -172,7 +173,8 @@ SMESH_DeviceActor
 ::SetStoreGemetryMapping(bool theStoreMapping)
 {
   myGeomFilter->SetStoreMapping(theStoreMapping);
-  SetStoreClippingMapping(theStoreMapping);
+  // for optimization, switch the mapping explicitly in each filter/algorithm
+  //SetStoreClippingMapping(theStoreMapping);
 }
 
 
@@ -182,7 +184,10 @@ SMESH_DeviceActor
 {
   myStoreClippingMapping = theStoreMapping;
   myExtractGeometry->SetStoreMapping(theStoreMapping && myIsImplicitFunctionUsed);
-  SetStoreIDMapping(theStoreMapping);
+  // EAP, 23315
+  // Mapping in myExtractUnstructuredGrid and myGeomFilter is ON in the pickable DeviceActor only.
+  // To show labels, the mapping is computed explicitly via myExtractUnstructuredGrid->BuildOut2InMap();
+  //SetStoreIDMapping(theStoreMapping);
 }
 
 
@@ -204,7 +209,6 @@ SMESH_DeviceActor
   SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
 }
 
-
 void
 SMESH_DeviceActor
 ::SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
@@ -224,14 +228,14 @@ void
 SMESH_DeviceActor
 ::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid)
 {
-  if(theGrid){
-    //myIsShrinkable = theGrid->GetNumberOfCells() > 10;
-    myIsShrinkable = true;
+  myExtractUnstructuredGrid->SetInputData(theGrid);
 
-    myExtractUnstructuredGrid->SetInputData(theGrid);
+  if ( theGrid )
+  {
+    myIsShrinkable = true;
 
     myMergeFilter->SetGeometryConnection(myExtractUnstructuredGrid->GetOutputPort());
-    
+
     //Pass diameters of the balls
     if(myMapper->GetBallEnabled()) {
       myMergeFilter->SetScalarsConnection(myExtractUnstructuredGrid->GetOutputPort());
@@ -242,7 +246,7 @@ SMESH_DeviceActor
     int anId = 0;
     SetImplicitFunctionUsed(myIsImplicitFunctionUsed);
     myPassFilter[ anId + 1]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
-    
+
     anId++; // 1
     myTransformFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
 
@@ -254,7 +258,7 @@ SMESH_DeviceActor
     myGeomFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
 
     anId++; // 4
-    myPassFilter[ anId ]->SetInputConnection( myGeomFilter->GetOutputPort() ); 
+    myPassFilter[ anId ]->SetInputConnection( myGeomFilter->GetOutputPort() );
     myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
 
     anId++; // 5
@@ -263,8 +267,8 @@ SMESH_DeviceActor
       myMapper->SetClippingPlanes( myPlaneCollection );
 
     vtkLODActor::SetMapper( myMapper );
-    Modified();
   }
+  Modified();
 }
 
 void
@@ -281,6 +285,7 @@ SMESH_DeviceActor
   return myExtractUnstructuredGrid;
 }
 
+#include "SMDS_Mesh.hxx"
 
 vtkUnstructuredGrid* 
 SMESH_DeviceActor
@@ -301,7 +306,7 @@ SMESH_DeviceActor
   if(anIsInitialized){
     vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
 
-    SetStoreIDMapping(true);
+    // SetStoreIDMapping(true);
     myExtractUnstructuredGrid->Update();
     vtkUnstructuredGrid* aGrid = myExtractUnstructuredGrid->GetOutput();
 
@@ -311,14 +316,16 @@ SMESH_DeviceActor
     vtkIdType aNbCells = aGrid->GetNumberOfCells();
     aScalars->SetNumberOfComponents(1);
     aScalars->SetNumberOfTuples(aNbCells);
-    double* range;// = aScalars->GetRange();
+    double* range = 0;// = aScalars->GetRange();
     
     myVisualObj->UpdateFunctor(theFunctor);
 
     using namespace SMESH::Controls;
     if(NumericalFunctor* aNumericalFunctor = dynamic_cast<NumericalFunctor*>(theFunctor.get()))
     {
-      for(vtkIdType i = 0; i < aNbCells; i++){
+      myExtractUnstructuredGrid->BuildOut2InMap();
+      for(vtkIdType i = 0; i < aNbCells; i++)
+      {
         vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
         vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
         double aValue = aNumericalFunctor->GetValue(anObjId);
@@ -334,7 +341,9 @@ SMESH_DeviceActor
     }
     else if(Predicate* aPredicate = dynamic_cast<Predicate*>(theFunctor.get()))
     {
-      for(vtkIdType i = 0; i < aNbCells; i++){
+      myExtractUnstructuredGrid->BuildOut2InMap();
+      for(vtkIdType i = 0; i < aNbCells; i++)
+      {
         vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
         vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
         bool aValue = aPredicate->IsSatisfy(anObjId);
@@ -401,7 +410,7 @@ SMESH_DeviceActor
       aNbCells = 0;
       for(; anIter != aValues.end(); anIter++){
         const Length2D::Value& aValue = *anIter;
-        int aNode[2] = {
+        vtkIdType aNode[2] = {
           myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
           myVisualObj->GetNodeVTKId(aValue.myPntId[1])
         };
@@ -422,7 +431,8 @@ SMESH_DeviceActor
       aCellLocationsArray->SetNumberOfTuples( aNbCells );
 
       aConnectivity->InitTraversal();
-      for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
+      vtkIdType const *pts(nullptr);
+      for( vtkIdType idType = 0, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
         aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
 
       aDataSet->SetCells( aCellTypesArray, aCellLocationsArray, aConnectivity );
@@ -465,7 +475,7 @@ SMESH_DeviceActor
       aNbCells = 0;
       for(; anIter != aValues.end(); anIter++){
         const MultiConnection2D::Value& aValue = (*anIter).first;
-        int aNode[2] = {
+        vtkIdType aNode[2] = {
           myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
           myVisualObj->GetNodeVTKId(aValue.myPntId[1])
         };
@@ -486,7 +496,8 @@ SMESH_DeviceActor
       aCellLocationsArray->SetNumberOfTuples( aNbCells );
 
       aConnectivity->InitTraversal();
-      for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
+      vtkIdType const *pts(nullptr);
+      for( vtkIdType idType = 0, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
         aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
 
       aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
@@ -562,7 +573,7 @@ SMESH_DeviceActor
     FreeEdges::TBorders::const_iterator anIter = aBorders.begin();
     for(; anIter != aBorders.end(); anIter++){
       const FreeEdges::Border& aBorder = *anIter;
-      int aNode[2] = {
+      vtkIdType aNode[2] = {
         myVisualObj->GetNodeVTKId(aBorder.myPntId[0]),
         myVisualObj->GetNodeVTKId(aBorder.myPntId[1])
       };
@@ -580,7 +591,8 @@ SMESH_DeviceActor
     aCellLocationsArray->SetNumberOfTuples( aNbCells );
     
     aConnectivity->InitTraversal();
-    for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
+    vtkIdType const *pts(nullptr);
+    for( vtkIdType idType = 0, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
       aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
     
     aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
@@ -607,11 +619,32 @@ SMESH_DeviceActor
 
 
 
-unsigned long int 
+vtkMTimeType
 SMESH_DeviceActor
 ::GetMTime()
 {
-  unsigned long mTime = this->Superclass::GetMTime();
+  // cout << "DA " << this
+  //      << " GF " << myGeomFilter;
+  // if ( this->Property )
+  //   cout << " P " << this->Property->GetMTime();
+  // if ( this->BackfaceProperty != NULL )
+  //   cout << " BP " << BackfaceProperty->GetMTime();
+  // if ( this->Texture != NULL )
+  //   cout << " T " << this->Texture->GetMTime();
+  // cout << " U " << this->GetUserTransformMatrixMTime()
+  //      << " M " << this->MTime.GetMTime() << endl;
+
+  // cout << "DA " << this
+  //      << " GF " << myGeomFilter
+  //      << " " << this->Superclass::GetMTime()
+  //      << " " << myExtractGeometry->GetMTime()
+  //      << " " << myExtractUnstructuredGrid->GetMTime()
+  //      << " " << myMergeFilter->GetMTime()
+  //      << " " << myGeomFilter->GetMTime()
+  //      << " " << myTransformFilter->GetMTime()
+  //      << " " << myFaceOrientationFilter->GetMTime() << endl;
+
+  vtkMTimeType mTime = this->Superclass::GetMTime();
   mTime = max(mTime,myExtractGeometry->GetMTime());
   mTime = max(mTime,myExtractUnstructuredGrid->GetMTime());
   mTime = max(mTime,myMergeFilter->GetMTime());
@@ -718,8 +751,8 @@ SMESH_DeviceActor
 ::UpdateFaceOrientation()
 {
   bool aShowFaceOrientation = myIsFacesOriented;
-  aShowFaceOrientation &= GetVisibility();
-  aShowFaceOrientation &= myRepresentation == eSurface;
+  aShowFaceOrientation &= vtkLODActor::GetVisibility(); //GetVisibility(); -- avoid calling GetUnstructuredGrid()  
+  aShowFaceOrientation &= ( myRepresentation != ePoint );
   myFaceOrientation->SetVisibility(aShowFaceOrientation);
 }
 
@@ -728,6 +761,8 @@ void
 SMESH_DeviceActor
 ::SetRepresentation(EReperesent theMode)
 {
+  if ( myRepresentation == theMode )
+    return;
   switch(theMode){
   case ePoint:
     myGeomFilter->SetInside(true);
@@ -762,8 +797,9 @@ void
 SMESH_DeviceActor
 ::SetVisibility(int theMode)
 {
-  if(!myExtractUnstructuredGrid->GetInput() || 
-     GetUnstructuredGrid()->GetNumberOfCells())
+  if(( theMode ) &&
+     ( !myExtractUnstructuredGrid->GetInput() || 
+       GetUnstructuredGrid()->GetNumberOfCells()))
   {
     vtkLODActor::SetVisibility(theMode);
   }else{
@@ -777,10 +813,12 @@ int
 SMESH_DeviceActor
 ::GetVisibility()
 {
-  if(!GetUnstructuredGrid()->GetNumberOfCells()){
+  int visibi = vtkLODActor::GetVisibility();
+  if(visibi && !GetUnstructuredGrid()->GetNumberOfCells()){
     vtkLODActor::SetVisibility(false);
+    visibi = 0;
   }
-  return vtkLODActor::GetVisibility();
+  return visibi;
 }
 
 
@@ -821,11 +859,17 @@ SMESH_DeviceActor
 {
   vtkDataSet* aDataSet = myMergeFilter->GetOutput();
   vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID);
-  double* aCoord = (anID >=0) ? aDataSet->GetPoint(anID) : NULL;
+  double* aCoord = (anID >=0 && anID < aDataSet->GetNumberOfPoints()) ? aDataSet->GetPoint(anID) : NULL;
   if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<<theObjID<<"; anID = "<<anID);
   return aCoord;
 }
 
+int
+SMESH_DeviceActor
+::GetNodeVtkId(int theObjID) 
+{
+  return myVisualObj->GetNodeVTKId(theObjID);
+}
 
 int
 SMESH_DeviceActor