]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
To introduce Gauss Points ID's mapping
authorapo <apo@opencascade.com>
Mon, 5 Sep 2005 07:29:46 +0000 (07:29 +0000)
committerapo <apo@opencascade.com>
Mon, 5 Sep 2005 07:29:46 +0000 (07:29 +0000)
src/OBJECT/VISU_GaussPtsAct.cxx
src/OBJECT/VISU_GaussPtsAct.h
src/PIPELINE/VISU_GaussPointsPL.cxx
src/PIPELINE/VISU_GaussPointsPL.hxx

index 8de55fe330bfae4df22e149de911d0726d0c5325..9788ee9b4cc347af7b53a814b10ef628d1a6a257 100644 (file)
 
 #include "VISU_GaussPtsAct.h"
 #include "VISU_GaussPointsPL.hxx"
+#include "SVTK_Actor.h"
+
+#include <vtkRenderer.h>
+#include <vtkPointPicker.h>
+
+#include <vtkTextActor.h>
+#include <vtkTextMapper.h>
+#include <vtkTextProperty.h>
+
+#include <vtkCellData.h>
+#include <vtkDataArray.h>
+
+#include <vtkSphereSource.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkActor.h>
 
 #include <vtkObjectFactory.h>
 
+#include <sstream>
+
 vtkStandardNewMacro(VISU_GaussPtsAct);
 
 VISU_GaussPtsAct
 ::VISU_GaussPtsAct():
-  myGaussPointsPL(NULL)
-{}
+  myGaussPointsPL(NULL),
+  myTextMapper(vtkTextMapper::New()),
+  myTextActor(vtkTextActor::New()),
+  myLastObjPointID(-1),
+  mySphereSource(vtkSphereSource::New()),
+  mySphereMapper(vtkPolyDataMapper::New()),
+  mySphereActor(vtkActor::New())
+{
+  myTextMapper->Delete();
+  myTextActor->Delete();
+
+  vtkTextProperty* aTextProperty = myTextMapper->GetTextProperty();
+  aTextProperty->SetVerticalJustification(VTK_TEXT_BOTTOM);
+  aTextProperty->SetJustification(VTK_TEXT_LEFT);
+
+  myTextActor->SetMapper(myTextMapper.GetPointer());
+  //myTextActor->SetAlignmentPoint(3);
+  myTextActor->SetVisibility(false);
+
+  mySphereSource->Delete();
+  mySphereMapper->Delete();
+  mySphereActor->Delete();
+
+  mySphereMapper->SetInput(mySphereSource->GetOutput());
+  mySphereActor->SetMapper(mySphereMapper.GetPointer());
+  mySphereActor->SetVisibility(false);
+}
 
 VISU_GaussPtsAct
 ::~VISU_GaussPtsAct()
@@ -47,12 +89,16 @@ VISU_GaussPtsAct
 ::AddToRender(vtkRenderer* theRenderer)
 {
   Superclass::AddToRender(theRenderer);
+  theRenderer->AddActor(myTextActor.GetPointer());
+  theRenderer->AddActor(mySphereActor.GetPointer());
 }
 
 void 
 VISU_GaussPtsAct
 ::RemoveFromRender(vtkRenderer* theRenderer)
 {
+  theRenderer->RemoveActor(mySphereActor.GetPointer());
+  theRenderer->RemoveActor(myTextActor.GetPointer());
   Superclass::RemoveFromRender(theRenderer);
 }
 
@@ -63,3 +109,106 @@ VISU_GaussPtsAct
   myGaussPointsPL = dynamic_cast<VISU_GaussPointsPL*>(thePipeLine);
   Superclass::SetPipeLine(thePipeLine);
 }
+
+//----------------------------------------------------------------
+bool
+VISU_GaussPtsAct
+::PreHighlight( SVTK_Selector* theSelector,
+               vtkRenderer* theRenderer,
+               SVTK_SelectionEvent theSelectionEvent,
+               bool theIsHighlight )
+{
+  myTextActor->SetVisibility(false);
+  mySphereActor->SetVisibility(false);
+
+  if(theSelectionEvent.mySelectionMode == ActorSelection || !theIsHighlight)
+    return Superclass::PreHighlight(theSelector,theRenderer,theSelectionEvent,theIsHighlight);
+
+  myPreHighlightActor->SetVisibility( false );
+    
+  bool anIsSelectionModeChanged = (theSelectionEvent.mySelectionMode != mySelectionMode);
+  if(!anIsSelectionModeChanged && mySelectionMode == ActorSelection)
+    return false;
+
+  mySelectionMode = theSelectionEvent.mySelectionMode;
+
+  float x = theSelectionEvent.myX;
+  float y = theSelectionEvent.myY;
+  float z = 0.0;
+
+  bool anIsChanged = false;
+  if(theIsHighlight){
+    switch(mySelectionMode){
+    case NodeSelection: 
+    case CellSelection:
+    {
+      myPointPicker->Pick( x, y, z, theRenderer );
+
+      if(myPointPicker->GetActor() != this)
+       return false;
+
+      vtkIdType aVtkId = myPointPicker->GetPointId();
+      if( aVtkId >= 0 && theSelector->IsValid( this, aVtkId, true ) && hasIO() ){
+       //float* aSelectionPoint = myPointPicker->GetSelectionPoint();
+       vtkIdType aVtkId = myPointPicker->GetPointId();
+       vtkIdType anObjId = GetNodeObjId( aVtkId );
+       if(myLastObjPointID != anObjId){
+         float* aNodeCoord = GetNodeCoord(anObjId);
+
+         // To calculate display (2D) position of the annotation
+         float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.0};
+         theRenderer->SetWorldPoint(aWorldCoord);
+         theRenderer->WorldToDisplay();
+         float aSelectionPoint[3];
+         theRenderer->GetDisplayPoint(aSelectionPoint);
+         myTextActor->SetPosition(aSelectionPoint);
+         
+         // To prepare the annotation text
+         std::ostringstream aStr;
+         aStr<<"Global ID: "<<anObjId;
+
+         VISU::TGaussPointID aGaussPointID = myGaussPointsPL->GetObjID(anObjId);
+         VISU::TCellID aCellID = aGaussPointID.first;
+         VISU::TLocalPntID aLocalPntID = aGaussPointID.second;
+         aStr<<"\nParentCellID: "<<aCellID;
+         aStr<<"\nLocalPntID: "<<aLocalPntID;
+
+         vtkDataSet* aDataSet = GetInput();
+         vtkCellData* aCellData = aDataSet->GetCellData();
+         if(vtkDataArray *aScalarArray = aCellData->GetScalars()){
+           float aVal = aScalarArray->GetTuple1(aVtkId);
+           aStr<<"\nScalar: "<<aVal;
+
+           mySphereSource->SetCenter(aNodeCoord);
+           float aRadius = myGaussPointsPL->GetPointSize(anObjId,aScalarArray);
+           mySphereSource->SetRadius(aRadius);
+
+           float aColor[3];
+           VISU_LookupTable* aLookupTable = myGaussPointsPL->GetMapperTable();
+           aLookupTable->GetColor(aVal,aColor);
+           mySphereActor->GetProperty()->SetColor(aColor);
+         }
+
+         if(vtkDataArray *aVectorArray = aCellData->GetVectors()){
+           float* aVal = aVectorArray->GetTuple3(aVtkId);
+           aStr<<"\nVector: {"<<aVal[0]<<"; "<<aVal[1]<<"; "<<aVal[2]<<"}";
+         }
+
+         std::string aString = aStr.str();
+         myTextMapper->SetInput(aString.c_str());
+         
+         myLastObjPointID = anObjId;
+       }
+       myTextActor->SetVisibility(true);
+       mySphereActor->SetVisibility(true);
+
+       myIsPreselected = theIsHighlight;
+       anIsChanged = true;
+      }
+    }
+    break;
+    }
+  }
+
+  return anIsChanged;
+}
index 625eb47f612c06302fcbd88c149f79495ae0978c..ae766a5473b7abf32a013a45a85fff9210a85fdb 100644 (file)
 #define VISU_GaussPtsAct_HeaderFile
 
 #include "VISU_ScalarMapAct.h"
+#include <vtkSmartPointer.h>
 
 class VISU_GaussPointsPL;
+class vtkTextMapper;
+class vtkTextActor;
+
+class vtkSphereSource;
+class vtkPolyDataMapper;
+class vtkActor;
 
 class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct
 {
  public:
   vtkTypeMacro(VISU_GaussPtsAct,VISU_ScalarMapAct);
-  static VISU_GaussPtsAct* New();
 
-  virtual void SetPipeLine(VISU_PipeLine* thePipeLine) ;
+  static
+  VISU_GaussPtsAct* 
+  New();
+
+  virtual
+  void
+  SetPipeLine(VISU_PipeLine* thePipeLine) ;
 
-  virtual void AddToRender(vtkRenderer* theRenderer); 
-  virtual void RemoveFromRender(vtkRenderer* theRenderer);
+  virtual
+  void
+  AddToRender(vtkRenderer* theRenderer); 
 
+  virtual
+  void
+  RemoveFromRender(vtkRenderer* theRenderer);
+
+  virtual
+  bool
+  PreHighlight( SVTK_Selector* theSelector,
+               vtkRenderer* theRenderer,
+               SVTK_SelectionEvent theSelectionEvent,
+               bool theIsHighlight );
  protected:
   VISU_GaussPtsAct();
   virtual ~VISU_GaussPtsAct();
 
-  VISU_GaussPointsPL* myGaussPointsPL;
+  vtkSmartPointer<VISU_GaussPointsPL> myGaussPointsPL;
+  vtkSmartPointer<vtkTextMapper> myTextMapper;
+  vtkSmartPointer<vtkTextActor> myTextActor;
+  vtkIdType myLastObjPointID;
+
+  vtkSmartPointer<vtkSphereSource> mySphereSource;
+  vtkSmartPointer<vtkPolyDataMapper> mySphereMapper;
+  vtkSmartPointer<vtkActor> mySphereActor;
 };
 
 #endif
index b11a2ab31fa80bcda45d354145ab81c0772a5253..d34dcc66559669ea51985a7d6b6931579a73528e 100644 (file)
@@ -27,6 +27,7 @@
 
 
 #include "VISU_GaussPointsPL.hxx"
+#include "VISU_DeformedShapePL.hxx"
 #include "VISU_PipeLineUtils.hxx"
 #include "VISU_OpenGLPointSpriteMapper.hxx"
 
 
 vtkStandardNewMacro(VISU_GaussPointsPL);
 
-VISU_GaussPointsPL::VISU_GaussPointsPL()
+VISU_GaussPointsPL
+::VISU_GaussPointsPL():
+  myRelativeMinSize(0.03),
+  myRelativeMaxSize(0.30)
 {
   myPSMapper = VISU_OpenGLPointSpriteMapper::New();
   //myPSMapper->DebugOn();
@@ -46,19 +50,24 @@ VISU_GaussPointsPL::VISU_GaussPointsPL()
   myGeomFilter = vtkGeometryFilter::New();
 }
 
-VISU_PipeLine::TMapper* VISU_GaussPointsPL::GetMapper()
+VISU_PipeLine::TMapper* 
+VISU_GaussPointsPL
+::GetMapper()
 {
   if(GetInput()){
     if(!myPSMapper->GetInput()){
       GetInput2()->Update();
       Build();
+      Init();
     }
     myPSMapper->Update();
   }
   return myPSMapper;
 }
 
-void VISU_GaussPointsPL::Build()
+void
+VISU_GaussPointsPL
+::Build()
 {
   //cout << "VISU_GaussPointsPL::Build" << endl;
 
@@ -119,7 +128,27 @@ void VISU_GaussPointsPL::Build()
   */
 }
 
-void VISU_GaussPointsPL::Update()
+void 
+VISU_GaussPointsPL::
+Init()
+{
+  VISU_ScalarMapPL::Init();
+
+  GetSourceRange(mySourceScalarRange);
+  myDeltaScalarRange = mySourceScalarRange[1] - mySourceScalarRange[0];
+
+  vtkMapper* aMapper = GetMapper();
+  vtkDataSet* aDataSet = aMapper->GetInput();
+  myAverageCelllSize = VISU_DeformedShapePL::GetScaleFactor(aDataSet);
+
+  vtkCellData* aCellData = aDataSet->GetCellData();
+  myScalarArray = aCellData->GetScalars();
+  cout<<myScalarArray<<endl;
+}
+
+void
+VISU_GaussPointsPL
+::Update()
 {
   VISU_ScalarMapPL::Update();
 
@@ -127,7 +156,8 @@ void VISU_GaussPointsPL::Update()
   myPSMapper->SetScalarRange( myMapperTable->GetRange() );
 }
 
-VISU_GaussPointsPL::~VISU_GaussPointsPL()
+VISU_GaussPointsPL
+::~VISU_GaussPointsPL()
 {
   if (this->myPSMapper)
   {
@@ -142,6 +172,13 @@ VISU_GaussPointsPL::~VISU_GaussPointsPL()
 }
 
 //=======================================================================
+VISU::TGaussPointID 
+VISU_GaussPointsPL
+::GetObjID(vtkIdType theID) const
+{
+  return myGaussMesh->GetObjID(theID);
+}
+
 void
 VISU_GaussPointsPL
 ::SetGaussMesh(const VISU::PGaussMesh& theGaussMesh)
@@ -156,3 +193,44 @@ VISU_GaussPointsPL
 {
   return myGaussMesh;
 }
+
+//=======================================================================
+void
+VISU_GaussPointsPL
+::SetRelativeMinSize(float theRelativeMinSize)
+{
+  myRelativeMinSize = theRelativeMinSize;
+  Modified();
+}
+
+void
+VISU_GaussPointsPL
+::SetRelativeMaxSize(float theRelativeMaxSize)
+{
+  myRelativeMaxSize = theRelativeMaxSize;
+  Modified();
+}
+
+float
+VISU_GaussPointsPL
+::GetPointSize(vtkIdType theID, vtkDataArray* theScalarArray)
+{
+  float aMaxSize = myAverageCelllSize*myRelativeMaxSize;
+  float aMinSize = myAverageCelllSize*myRelativeMinSize;
+  float aDelta = aMaxSize - aMinSize;
+  float aVal = theScalarArray->GetTuple1(theID);
+
+  return aMinSize + aDelta*(aVal - mySourceScalarRange[0])/myDeltaScalarRange;
+}
+
+float
+VISU_GaussPointsPL
+::GetPointSize(vtkIdType theID)
+{
+  vtkMapper* aMapper = GetMapper();
+  vtkDataSet* aDataSet = aMapper->GetInput();
+  vtkCellData* aCellData = aDataSet->GetCellData();
+  vtkDataArray* aScalarArray = aCellData->GetScalars();
+  return GetPointSize(theID,aScalarArray);
+}
+
index 4d7b0beff2b0185c5bb9f4f275f49953999dfcf6..3d05e0d6901c0716d5b341c99ae4eb4a1c47704c 100644 (file)
 class VISU_OpenGLPointSpriteMapper;
 
 class vtkGeometryFilter;
+class vtkDataArray;
 
 class VISU_GaussPointsPL : public VISU_ScalarMapPL
 {
 protected:
   VISU_GaussPointsPL();
-  virtual ~VISU_GaussPointsPL();
+
+  virtual
+  ~VISU_GaussPointsPL();
 
 public:
   vtkTypeMacro(VISU_GaussPointsPL,VISU_ScalarMapPL);
-  static VISU_GaussPointsPL* New();
 
-  virtual TMapper* GetMapper();
+  static 
+  VISU_GaussPointsPL* New();
+
+  virtual
+  TMapper* 
+  GetMapper();
+
+  virtual
+  void
+  Build();
 
-  virtual void Build();
-  virtual void Update();
+  virtual
+  void
+  Init();
+
+  virtual
+  void
+  Update();
+
+  virtual 
+  VISU::TGaussPointID 
+  GetObjID(vtkIdType theID) const;
 
   void 
   SetGaussMesh(const VISU::PGaussMesh& theGaussMesh);
@@ -56,10 +76,41 @@ public:
   const VISU::PGaussMesh&  
   GetGaussMesh()const;
 
+  void
+  SetRelativeMinSize(float theRelativeMinSize);
+
+  float 
+  GetRelativeMinSize()
+  {
+    return myRelativeMinSize;
+  }
+
+  void
+  SetRelativeMaxSize(float theRelativeMaxSize);
+
+  float 
+  GetRelativeMaxSize()
+  {
+    return myRelativeMaxSize;
+  }
+
+  float
+  GetPointSize(vtkIdType theID);
+
+  float
+  GetPointSize(vtkIdType theID, vtkDataArray* theScalarArray);
+
 protected:
   VISU_OpenGLPointSpriteMapper* myPSMapper;
   vtkGeometryFilter* myGeomFilter;
   VISU::PGaussMesh myGaussMesh;
+
+  vtkDataArray *myScalarArray;
+  float mySourceScalarRange[2];
+  float myDeltaScalarRange;
+  float myAverageCelllSize;
+  float myRelativeMinSize;
+  float myRelativeMaxSize;
 };
   
 #endif