#include "VTKViewer_PassThroughFilter.h"
#include <stdexcept>
+#include <sstream>
// VTK Includes
#include <vtkProperty.h>
-
+#include <vtkSmartPointer.h>
+#include <vtkTextMapper.h>
+#include <vtkTextActor.h>
+#include <vtkProperty2D.h>
+#include <vtkRenderer.h>
+#include <vtkCellPicker.h>
+#include <vtkCell.h>
+#include <vtkPoints.h>
+#include <vtkInteractorStyle.h>
#include <vtkDataSet.h>
#include <vtkPolyData.h>
#include <vtkUnstructuredGrid.h>
myMapper(vtkDataSetMapper::New()),
myIsShrunk(false),
myIsShrinkable(false),
- myShrinkFilter(VTKViewer_ShrinkFilter::New())
+ myShrinkFilter(VTKViewer_ShrinkFilter::New()),
+ myAnnotationMapper(vtkTextMapper::New()),
+ myAnnotationActor(vtkTextActor::New())
{
SetDebug(MYVTKDEBUG);
myShrinkFilter->SetStoreMapping(true);
SetShrinkFactor();
+
+ myAnnotationMapper->Delete();
+ myAnnotationActor->Delete();
+ myAnnotationActor->SetMapper(myAnnotationMapper.GetPointer());
+ myAnnotationActor.GetPointer()->SetVisibility(0);
}
VISU_Actor::~VISU_Actor(){
return myPipeLine->GetElemCell(theObjID);
}
+
+//==================================================================
+// function: PreHighlight
+// purpose :
+//==================================================================
+bool VISU_Actor::PreHighlight( SVTK_Selector* theSelector,
+ vtkInteractorStyle *theIS,
+ SVTK_SelectionEvent theSelectionEvent,
+ bool theIsHighlight )
+{
+ bool bRet, anIsChanged;
+ float x, y, z;
+ vtkIdType aVtkId;
+
+ bRet=Superclass::PreHighlight(theSelector,
+ theIS,
+ theSelectionEvent,
+ theIsHighlight);
+ //
+ myAnnotationActor->SetVisibility(0);
+ //
+ anIsChanged = false;
+ x = theSelectionEvent.myX;
+ y = theSelectionEvent.myY;
+ z = 0.0;
+ vtkRenderer *aRenderer=theIS->GetCurrentRenderer();
+ //
+ if(theIsHighlight) {
+ switch(mySelectionMode){
+ case CellSelection:{
+ myCellPicker->Pick(x, y, z, aRenderer);
+ //if(myCellPicker->GetActor() != this){
+ // return false;
+ //}
+ aVtkId = myCellPicker->GetCellId();
+ if (aVtkId >= 0 &&
+ theSelector->IsValid( this, aVtkId, true ) &&
+ hasIO() ) {
+ vtkIdType anObjId = GetElemObjId( aVtkId );
+ vtkCell* pCell=GetElemCell(anObjId);
+ if (pCell){
+ int aNbPnts, i, j;
+ float *aCoord, *aCoordX;
+ //
+ aNbPnts=pCell->GetNumberOfPoints();
+ if (aNbPnts){
+ aCoord=new float[3];
+ for (j=0; j<3; ++j) {
+ aCoord[j]=0.;
+ }
+ //
+ vtkPoints * pPnts=pCell->GetPoints();
+ for (i=0; i<aNbPnts; ++i){
+ aCoordX=pPnts->GetPoint(i);
+ for (j=0; j<3; ++j) {
+ aCoord[j]+=aCoordX[j];
+ }
+ }
+ for (j=0; j<3; ++j) {
+ aCoord[j]/=aNbPnts;
+ }
+ //printf(" aVtkId=%d, x=%f, y=%f, {%f, %f, %f}\n",
+ // aVtkId, x, y, aCoord[0], aCoord[1], aCoord[2]);
+ //
+ // Display coordinates
+ float aWorldCoord[4] = {aCoord[0], aCoord[1], aCoord[2], 1.0};
+ aRenderer->SetWorldPoint(aWorldCoord);
+ aRenderer->WorldToDisplay();
+ float aSelectionPoint[3];
+ aRenderer->GetDisplayPoint(aSelectionPoint);
+ myAnnotationActor->SetPosition(aSelectionPoint);
+ //
+ // To prepare the annotation text
+ std::ostringstream aStr;
+ aStr<<"Global ID: "<< anObjId;
+ std::string aString = aStr.str();
+ myAnnotationMapper->SetInput(aString.c_str());
+
+ myAnnotationActor->SetVisibility(1);
+
+ delete aCoord;
+ return true;
+ }
+ }
+ }
+ }
+ break;
+ case NodeSelection:
+ case EdgeOfCellSelection:
+ default:
+ break;
+ }
+ }
+ return bRet;
+
+}
+//==================================================================
+// function: AddToRender
+// purpose :
+//==================================================================
+void VISU_Actor::AddToRender(vtkRenderer* theRenderer)
+{
+
+ Superclass::AddToRender(theRenderer);
+ theRenderer->AddActor(myAnnotationActor.GetPointer());
+}
+//==================================================================
+// function: RemoveFromRender
+// purpose :
+//==================================================================
+void VISU_Actor::RemoveFromRender(vtkRenderer* theRenderer)
+{
+ theRenderer->RemoveActor(myAnnotationActor.GetPointer());
+ Superclass::RemoveFromRender(theRenderer);
+
+}
#include <vtkActor.h>
#include <vtkObjectFactory.h>
+#include <vtkInteractorStyle.h>
#include <sstream>
bool
VISU_GaussPtsAct
::PreHighlight( SVTK_Selector* theSelector,
- vtkRenderer* theRenderer,
+ vtkInteractorStyle *theIS,
SVTK_SelectionEvent theSelectionEvent,
bool theIsHighlight )
{
+ vtkRenderer *aRenderer=theIS->GetCurrentRenderer();
+ //
myTextActor->SetVisibility(false);
mySphereActor->SetVisibility(false);
- if(theSelectionEvent.mySelectionMode == ActorSelection || !theIsHighlight)
- return Superclass::PreHighlight(theSelector,theRenderer,theSelectionEvent,theIsHighlight);
-
+ if(theSelectionEvent.mySelectionMode == ActorSelection || !theIsHighlight) {
+ return Superclass::PreHighlight(theSelector,theIS,theSelectionEvent,theIsHighlight);
+ }
myPreHighlightActor->SetVisibility( false );
bool anIsSelectionModeChanged = (theSelectionEvent.mySelectionMode != mySelectionMode);
case NodeSelection:
case CellSelection:
{
- myPointPicker->Pick( x, y, z, theRenderer );
+ myPointPicker->Pick( x, y, z, aRenderer );
if(myPointPicker->GetActor() != this)
return false;
// To calculate display (2D) position of the annotation
float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.0};
- theRenderer->SetWorldPoint(aWorldCoord);
- theRenderer->WorldToDisplay();
+ aRenderer->SetWorldPoint(aWorldCoord);
+ aRenderer->WorldToDisplay();
float aSelectionPoint[3];
- theRenderer->GetDisplayPoint(aSelectionPoint);
+ aRenderer->GetDisplayPoint(aSelectionPoint);
myTextActor->SetPosition(aSelectionPoint);
// To prepare the annotation text