#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()
::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);
}
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;
+}
#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
#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();
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;
*/
}
-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();
myPSMapper->SetScalarRange( myMapperTable->GetRange() );
}
-VISU_GaussPointsPL::~VISU_GaussPointsPL()
+VISU_GaussPointsPL
+::~VISU_GaussPointsPL()
{
if (this->myPSMapper)
{
}
//=======================================================================
+VISU::TGaussPointID
+VISU_GaussPointsPL
+::GetObjID(vtkIdType theID) const
+{
+ return myGaussMesh->GetObjID(theID);
+}
+
void
VISU_GaussPointsPL
::SetGaussMesh(const VISU::PGaussMesh& theGaussMesh)
{
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);
+}
+
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);
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