]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Provides visualization of a cell that corresponds to selected Gauss point
authorpkv <pkv@opencascade.com>
Mon, 19 Sep 2005 10:46:48 +0000 (10:46 +0000)
committerpkv <pkv@opencascade.com>
Mon, 19 Sep 2005 10:46:48 +0000 (10:46 +0000)
src/OBJECT/VISU_GaussPtsAct.cxx
src/OBJECT/VISU_GaussPtsAct.h

index 93b3eb4cfe46cabb20d5cf9b426b2d3cd65169e6..ae87342e95e5cd28264379652da39f732a4463e7 100644 (file)
 #include <vtkCamera.h>
 
 #include <sstream>
+
+#include <vtkUnstructuredGrid.h>
+#include <vtkDataSetMapper.h>
+#include <vtkCell.h>
+#include <vtkCellArray.h>
+
+#include "VISU_Convertor_impl.hxx"
 //
 ///////////////////////////////////////////////////////////////////////////
 //
@@ -104,6 +111,7 @@ public:
 
   void SetPosition(float thePosition[3]);
 
+  void Init();
   //
   vtkTypeMacro(VISU_CursorPyramid, vtkObject);
 
@@ -115,7 +123,6 @@ protected:
 
   virtual ~VISU_CursorPyramid();
 
-  void Init();
 
 protected:
   // sphere parameters
@@ -260,7 +267,41 @@ VISU_GaussPtsAct
   mySphereActor->SetPickable(false);
   //
   myCursorPyramid->Delete();
+  //
+  mySphereSourceSelected=vtkSphereSource::New();
+  mySphereMapperSelected=vtkPolyDataMapper::New();
+  mySphereActorSelected=vtkActor::New();
+  //
+  mySphereSourceSelected->Delete();
+  mySphereMapperSelected->Delete();
+  mySphereActorSelected->Delete();
+  //
+  mySphereMapperSelected->SetInput(mySphereSourceSelected->GetOutput());
+  mySphereActorSelected->SetMapper(mySphereMapperSelected.GetPointer());
+  mySphereActorSelected->SetVisibility(false);
+  mySphereActorSelected->SetPickable(false);
+  float aColorSelected[3]={1.,1.,1.};
+  mySphereActorSelected->GetProperty()->SetColor(aColorSelected);
+  // 
+  // Cell 
+  myCellSource=vtkUnstructuredGrid::New();
+  myCellSource->Allocate();
+  myCellMapper=vtkDataSetMapper::New();
+  myCellActor=vtkActor::New();
+  //
+  myCellSource->Delete();
+  myCellMapper->Delete();
+  myCellActor->Delete();
+  //
+  myCellMapper->SetInput(myCellSource.GetPointer());
+  myCellActor->SetMapper(myCellMapper.GetPointer());
+  myCellActor->SetVisibility(0);
+  myCellActor->SetPickable(0);
   
+  float aColorCell[3]={.9,.9,.9};
+  vtkProperty* pPropertyCell=myCellActor->GetProperty();
+  pPropertyCell->SetColor(aColorCell);
+  pPropertyCell->SetRepresentationToWireframe(); 
 }
 
 VISU_GaussPtsAct
@@ -276,7 +317,9 @@ VISU_GaussPtsAct
   Superclass::AddToRender(theRenderer);
   theRenderer->AddActor(myTextActor.GetPointer());
   theRenderer->AddActor(mySphereActor.GetPointer());
+  theRenderer->AddActor(mySphereActorSelected.GetPointer());
   myCursorPyramid->AddToRender(theRenderer);
+  theRenderer->AddActor(myCellActor.GetPointer());
 }
 
 void 
@@ -286,7 +329,9 @@ VISU_GaussPtsAct
   myCursorPyramid->RemoveFromRender(theRenderer);
   theRenderer->RemoveActor(mySphereActor.GetPointer());
   theRenderer->RemoveActor(myTextActor.GetPointer());
+  theRenderer->RemoveActor(mySphereActorSelected.GetPointer());
   Superclass::RemoveFromRender(theRenderer);
+  theRenderer->RemoveActor(myCellActor.GetPointer());
 }
 
 
@@ -331,6 +376,7 @@ VISU_GaussPtsAct
   mySphereActor->SetVisibility(false);
   myCursorPyramid->SetVisibility(0);
   
+
   if(theSelectionEvent.mySelectionMode == ActorSelection || !theIsHighlight) {
     return Superclass::PreHighlight(theSelector,theIS,theSelectionEvent,theIsHighlight);
   }
@@ -357,7 +403,7 @@ VISU_GaussPtsAct
       if(myPointPicker->GetActor() != this) {
        return false;
       }
-
+      
       vtkIdType aVtkId = myPointPicker->GetPointId();
       if( aVtkId >= 0 && theSelector->IsValid( this, aVtkId, true ) && hasIO() ){
        //float* aSelectionPoint = myPointPicker->GetSelectionPoint();
@@ -398,10 +444,11 @@ VISU_GaussPtsAct
            //
            aMaxPointSize=myGaussPointsPL->GetMaxPointSize();
 
+           myCursorPyramid->SetHeight(aMaxPointSize);
            myCursorPyramid->SetRadius(aRadius);
            myCursorPyramid->SetColor(aColor);
            myCursorPyramid->SetPosition(aNodeCoord);
-           myCursorPyramid->SetHeight(aMaxPointSize);
+           myCursorPyramid->Init();
          }
 
          if(vtkDataArray *aVectorArray = aCellData->GetVectors()){
@@ -429,49 +476,58 @@ VISU_GaussPtsAct
   return anIsChanged;
 }
 
-//----------------------------------------------------------------
-bool
-VISU_GaussPtsAct::Highlight( SVTK_Selector *theSelector,
-                            vtkInteractorStyle *theIS,
-                            SVTK_SelectionEvent theSelectionEvent,
-                            bool theIsHighlight )
+//==================================================================
+// function : Highlight
+// purpose  :
+//==================================================================
+bool VISU_GaussPtsAct::Highlight( SVTK_Selector *theSelector,
+                                 vtkInteractorStyle *theIS,
+                                 SVTK_SelectionEvent theSelectionEvent,
+                                 bool theIsHighlight )
 { 
-  int aTextVisibility, aSphereVisibility;
+  int aTextVisibility, aSphereVisibility, aSphereVisibilitySelected, aSelectionMode;
   //
   aTextVisibility=myTextActor->GetVisibility();
   aSphereVisibility=mySphereActor->GetVisibility();
+  aSphereVisibilitySelected= mySphereActorSelected->GetVisibility();
   //
   myTextActor->SetVisibility(0);
   mySphereActor->SetVisibility(0);
+  mySphereActorSelected->SetVisibility(0);
+  myCellActor->SetVisibility(0);
   //
   vtkRenderer *aRenderer=theIS->GetCurrentRenderer();
   vtkRenderWindowInteractor* aRWI=theIS->GetInteractor();
   //
-  int aSelectionMode = theSelectionEvent.mySelectionMode;
+  aSelectionMode = theSelectionEvent.mySelectionMode;
   mySelectionMode = aSelectionMode;
   //
   if(aSelectionMode==ActorSelection ){ //|| !theIsHighlight) {
     myTextActor->SetVisibility(aTextVisibility);
     mySphereActor->SetVisibility(aSphereVisibility);
+    mySphereActorSelected->SetVisibility(aSphereVisibilitySelected);
     return Superclass::Highlight(theSelector,theIS,theSelectionEvent,theIsHighlight);
   }
   //
-  float x1 = theSelectionEvent.myX;
-  float y1 = theSelectionEvent.myY;
-  float z1 = 0.0;
-  float x2 = theSelectionEvent.myLastX;
-  float y2 = theSelectionEvent.myLastY;
-  float z2 = 0.0;
-  bool isShift = theSelectionEvent.myIsShift;
-  bool isRectangle = theSelectionEvent.myIsRectangle;
-  bool bRet, bHasIO;
+  bool isShift, isRectangle, bRet, bHasIO;
+  float x1, y1, z1, x2, y2, z2;
   //
+  x1 = theSelectionEvent.myX;
+  y1 = theSelectionEvent.myY;
+  z1 = 0.0;
+  x2 = theSelectionEvent.myLastX;
+  y2 = theSelectionEvent.myLastY;
+  z2 = 0.0;
+  
+  isShift = theSelectionEvent.myIsShift;
+  isRectangle = theSelectionEvent.myIsRectangle;
+  
   bHasIO=hasIO();
   bRet=false;
   if( !isRectangle )  {
     myPointPicker->Pick( x1, y1, z1, aRenderer );
-    
     if(myPointPicker->GetActor() != this) {
+      
       myTextActor->SetVisibility(aTextVisibility);
       mySphereActor->SetVisibility(aSphereVisibility);
       return bRet;
@@ -488,6 +544,8 @@ VISU_GaussPtsAct::Highlight( SVTK_Selector *theSelector,
       //
       if( anObjId >= 0 ) {
        bRet=!bRet;
+       //
+       // Update the Selector
        if( theSelector->IsSelected( myIO ) ) {
          theSelector->AddOrRemoveIndex( myIO, anObjId, isShift );
        }
@@ -498,16 +556,80 @@ VISU_GaussPtsAct::Highlight( SVTK_Selector *theSelector,
          theSelector->AddOrRemoveIndex( myIO, anObjId, isShift );
          theSelector->AddIObject( this );
        }
-       float* aNodeCoord = GetNodeCoord(anObjId);
-       aRWI->FlyTo (aRenderer, aNodeCoord); 
-       aRenderer->ResetCameraClippingRange();
+       float *aNodeCoord, aRadius;
+       //
+       aNodeCoord = GetNodeCoord(anObjId);
+       //aRWI->FlyTo (aRenderer, aNodeCoord); 
+       //aRenderer->ResetCameraClippingRange();
        //
        // To calculate display (2D) position of the annotation
-       float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.0};
+       float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.};
        myTextActor->SetWorldPoint(aWorldCoord);
        //
-       float aColor[3]={1.,1.,1.};
-       mySphereActor->GetProperty()->SetColor(aColor);
+       // Selected
+       mySphereSourceSelected->SetCenter(aNodeCoord);
+       //
+       vtkDataSet* aDataSet = GetInput();
+       vtkCellData* aCellData = aDataSet->GetCellData();
+       vtkDataArray *aScalarArray = aCellData->GetScalars();
+       //
+       aRadius = myGaussPointsPL->GetPointSize(anObjId, aScalarArray);
+       mySphereSourceSelected->SetRadius(aRadius);
+       //
+       if (theSelector->HasIndex(myIO)) {
+         mySphereActorSelected->SetVisibility(1);
+       }
+       else {
+         mySphereActorSelected->SetVisibility(0);
+         mySphereActor->SetVisibility(1);
+       }
+       //
+       myTextActor->SetVisibility(1);
+       //
+       if (aSelectionMode==CellSelection) {
+         // Hilighting an element from the parent Mesh
+         int k, aNbPoints, aIDs[20];
+         float *pX;
+         vtkIdType aCellID;
+         vtkCell* pCell; 
+         vtkPoints *pPoints;
+         VISU::TMeshOnEntityImpl* pMeshOnEntityImpl; 
+         //
+         const VISU::PGaussMesh& aGaussMesh=myGaussPointsPL->GetGaussMesh();
+         VISU::TGaussMeshImpl* pGaussMeshImpl=
+           dynamic_cast<VISU::TGaussMeshImpl*>(aGaussMesh.get());
+         //
+         VISU::TGaussPointID anGPID= aGaussMesh->GetObjID(anObjId);
+         aCellID=anGPID.first;
+
+         pMeshOnEntityImpl=pGaussMeshImpl->GetParentMesh();
+         pCell=pMeshOnEntityImpl->GetElemCell(aCellID);
+         //
+         pPoints=pCell->GetPoints();
+         //
+         aNbPoints=pCell->GetNumberOfPoints();
+         for (k=0; k<aNbPoints; ++k) {
+           pX=pPoints->GetPoint(k);
+           aIDs[k]=k;  
+         }
+         myCellSource->Initialize();
+         myCellSource->Allocate();
+         myCellSource->SetPoints(pCell->GetPoints());
+         myCellSource->InsertNextCell(pCell->GetCellType(), aNbPoints, aIDs);
+         //
+         vtkProperty* pPropertyCell=myCellActor->GetProperty();
+         pPropertyCell->SetAmbient(1.0);
+         pPropertyCell->SetDiffuse(0.0);
+         pPropertyCell->SetRepresentationToWireframe(); 
+         if (theSelector->HasIndex(myIO)) {
+           myCellActor->SetVisibility(1);
+         }
+         else { 
+           myCellActor->SetVisibility(0);
+         }
+       }
+       
+       return bRet;
        //
       }// if( anObjId >= 0 ) {
     }//if( aVtkId >= 0  && theSelector->IsValid( this, aVtkId, true ) && hasIO()) 
@@ -618,8 +740,8 @@ VISU_GaussPtsAct::Highlight( SVTK_Selector *theSelector,
       }
     }
   }//else ... if(!isRectangle )
-  myTextActor->SetVisibility(aTextVisibility);
-  mySphereActor->SetVisibility(aSphereVisibility);
+  //myTextActor->SetVisibility(aTextVisibility);
+  //mySphereActor->SetVisibility(aSphereVisibility);
   return bRet;
 }
 //
@@ -757,7 +879,7 @@ void VISU_CursorPyramid::SetColor(const float theColor[3])
 void VISU_CursorPyramid::SetRadius(const float theR)
 {
   myRadius=theR;
-  Init();
+  //Init();
 }
 //==================================================================
 // function : Radius
index dde2d6924912babec96b30db9ed70507ea41555d..12ba41b11d4ac0427023dde05e0609dea967564d 100644 (file)
@@ -45,7 +45,10 @@ class vtkInteractorStyle;
 
 class VISU_CursorPyramid;
 class VISU_GPTextActor;
-
+//xxx 
+class vtkUnstructuredGrid;
+class vtkDataSetMapper;
+//xxx
 class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct
 {
  public:
@@ -106,6 +109,14 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct
   vtkSmartPointer<vtkActor> mySphereActor;
 
   vtkSmartPointer<VISU_CursorPyramid> myCursorPyramid;
+
+  vtkSmartPointer<vtkSphereSource> mySphereSourceSelected;
+  vtkSmartPointer<vtkPolyDataMapper> mySphereMapperSelected;
+  vtkSmartPointer<vtkActor> mySphereActorSelected;
+
+  vtkSmartPointer<vtkUnstructuredGrid> myCellSource;
+  vtkSmartPointer<vtkDataSetMapper>    myCellMapper;
+  vtkSmartPointer<vtkActor>            myCellActor;
 };
 
 #endif