From c5bab6368b8174aa9c53c0c93fd126a54c362af8 Mon Sep 17 00:00:00 2001 From: apo Date: Mon, 5 Sep 2005 07:29:46 +0000 Subject: [PATCH] To introduce Gauss Points ID's mapping --- src/OBJECT/VISU_GaussPtsAct.cxx | 153 +++++++++++++++++++++++++++- src/OBJECT/VISU_GaussPtsAct.h | 41 +++++++- src/PIPELINE/VISU_GaussPointsPL.cxx | 88 +++++++++++++++- src/PIPELINE/VISU_GaussPointsPL.hxx | 61 ++++++++++- 4 files changed, 326 insertions(+), 17 deletions(-) diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index 8de55fe3..9788ee9b 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -28,15 +28,57 @@ #include "VISU_GaussPtsAct.h" #include "VISU_GaussPointsPL.hxx" +#include "SVTK_Actor.h" + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include #include +#include + 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(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: "<GetObjID(anObjId); + VISU::TCellID aCellID = aGaussPointID.first; + VISU::TLocalPntID aLocalPntID = aGaussPointID.second; + aStr<<"\nParentCellID: "<GetCellData(); + if(vtkDataArray *aScalarArray = aCellData->GetScalars()){ + float aVal = aScalarArray->GetTuple1(aVtkId); + aStr<<"\nScalar: "<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: {"<SetInput(aString.c_str()); + + myLastObjPointID = anObjId; + } + myTextActor->SetVisibility(true); + mySphereActor->SetVisibility(true); + + myIsPreselected = theIsHighlight; + anIsChanged = true; + } + } + break; + } + } + + return anIsChanged; +} diff --git a/src/OBJECT/VISU_GaussPtsAct.h b/src/OBJECT/VISU_GaussPtsAct.h index 625eb47f..ae766a54 100644 --- a/src/OBJECT/VISU_GaussPtsAct.h +++ b/src/OBJECT/VISU_GaussPtsAct.h @@ -30,25 +30,56 @@ #define VISU_GaussPtsAct_HeaderFile #include "VISU_ScalarMapAct.h" +#include 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 myGaussPointsPL; + vtkSmartPointer myTextMapper; + vtkSmartPointer myTextActor; + vtkIdType myLastObjPointID; + + vtkSmartPointer mySphereSource; + vtkSmartPointer mySphereMapper; + vtkSmartPointer mySphereActor; }; #endif diff --git a/src/PIPELINE/VISU_GaussPointsPL.cxx b/src/PIPELINE/VISU_GaussPointsPL.cxx index b11a2ab3..d34dcc66 100644 --- a/src/PIPELINE/VISU_GaussPointsPL.cxx +++ b/src/PIPELINE/VISU_GaussPointsPL.cxx @@ -27,6 +27,7 @@ #include "VISU_GaussPointsPL.hxx" +#include "VISU_DeformedShapePL.hxx" #include "VISU_PipeLineUtils.hxx" #include "VISU_OpenGLPointSpriteMapper.hxx" @@ -38,7 +39,10 @@ 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<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); +} + diff --git a/src/PIPELINE/VISU_GaussPointsPL.hxx b/src/PIPELINE/VISU_GaussPointsPL.hxx index 4d7b0bef..3d05e0d6 100644 --- a/src/PIPELINE/VISU_GaussPointsPL.hxx +++ b/src/PIPELINE/VISU_GaussPointsPL.hxx @@ -34,21 +34,41 @@ 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 -- 2.39.2