#endif
int SALOME_POINT_SIZE = 3;
+int SALOME_LINE_WIDTH = 2;
+
+//----------------------------------------------------------------------------
+namespace
+{
+ int
+ GetEdgeId(SALOME_Actor* theActor,
+ vtkPicker* thePicker,
+ int theObjId)
+ {
+ int anEdgeId = -1;
+ if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
+ float aPickPosition[3];
+ thePicker->GetPickPosition(aPickPosition);
+ float aMinDist = 1000000.0, aDist = 0;
+ for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){
+ if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){
+ int subId; float pcoords[3], closestPoint[3], weights[3];
+ aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
+ if (aDist < aMinDist) {
+ aMinDist = aDist;
+ anEdgeId = i;
+ }
+ }
+ }
+ }
+ return anEdgeId;
+ }
+}
//----------------------------------------------------------------------------
for(int i = 0; i < 6; i++)
myPassFilter.push_back(VTKViewer_PassThroughFilter::New());
- // from VISU
myPointPicker = vtkPointPicker::New();
+ myPointPicker->Delete();
+
myCellPicker = vtkCellPicker::New();
- myCellRectPicker = VTKViewer_CellRectPicker::New();
+ myCellPicker->Delete();
- myPreHighlightActor = SVTK_Actor::New();
- myPreHighlightActor->GetProperty()->SetColor(0,1,1);
- myPreHighlightActor->GetProperty()->SetPointSize(5);
- myPreHighlightActor->GetProperty()->SetRepresentationToPoints();
+ myCellRectPicker = VTKViewer_CellRectPicker::New();
+ myCellRectPicker->Delete();
- myPointProperty = vtkProperty::New();
- myPointProperty->SetColor(1,1,0);
- myPointProperty->SetPointSize(5);
- myPointProperty->SetRepresentationToPoints();
+ myPreHighlightProperty = vtkProperty::New();
+ myPreHighlightProperty->Delete();
+ myPreHighlightProperty->SetColor(0,1,1);
+ myPreHighlightProperty->SetPointSize(SALOME_POINT_SIZE);
+ myPreHighlightProperty->SetLineWidth(SALOME_LINE_WIDTH);
+ myPreHighlightProperty->SetRepresentationToPoints();
- myCellProperty = vtkProperty::New();
- myCellProperty->SetColor(1,1,0);
- myCellProperty->SetPointSize(5);
- myCellProperty->SetRepresentationToSurface();
+ myPreHighlightActor = SVTK_Actor::New();
+ myPreHighlightActor->Delete();
+ myPreHighlightActor->SetProperty(myPreHighlightProperty.GetPointer());
+ myPreHighlightActor->SetVisibility( false );
- myEdgeProperty = vtkProperty::New();
- myEdgeProperty->SetColor(1,0,0);
- myEdgeProperty->SetPointSize(5);
- myEdgeProperty->SetRepresentationToWireframe();
+ myHighlightProperty = vtkProperty::New();
+ myHighlightProperty->Delete();
+ myHighlightProperty->SetColor(1,1,0);
+ myHighlightProperty->SetPointSize(SALOME_POINT_SIZE);
+ myHighlightProperty->SetLineWidth(SALOME_LINE_WIDTH);
+ myHighlightProperty->SetRepresentationToPoints();
myHighlightActor = SVTK_Actor::New();
myHighlightActor->PickableOff();
- myHighlightActor->SetProperty( myPointProperty );
-
+ myHighlightActor->SetProperty(myHighlightProperty.GetPointer());
+ myHighlightActor->SetVisibility( false );
myOutline = vtkOutlineSource::New();
+ myOutline->Delete();
myOutlineMapper = vtkPolyDataMapper::New();
- myOutlineMapper->SetInput( myOutline->GetOutput() );
+ myOutlineMapper->Delete();
+ myOutlineMapper->SetInput(myOutline->GetOutput());
myOutlineActor = vtkActor::New();
+ myOutlineActor->Delete();
myOutlineActor->PickableOff();
myOutlineActor->DragableOff();
- myOutlineActor->SetMapper( myOutlineMapper );
+ myOutlineActor->SetMapper( myOutlineMapper.GetPointer() );
myOutlineActor->GetProperty()->SetColor(1.0,0.0,0.0);
myOutlineActor->GetProperty()->SetAmbient(1.0);
myOutlineActor->GetProperty()->SetDiffuse(0.0);
}
myProperty->Delete();
+}
- // from VISU
- myPointPicker->Delete();
- myCellPicker->Delete();
- myCellRectPicker->Delete();
- myHighlightActor->Delete();
- myOutline->Delete();
- myOutlineMapper->Delete();
- myOutlineActor->Delete();
+//----------------------------------------------------------------------------
+Standard_Boolean
+SALOME_Actor
+::hasIO()
+{
+ return !myIO.IsNull();
+}
+
+const Handle(SALOME_InteractiveObject)&
+SALOME_Actor
+::getIO()
+{
+ return myIO;
+}
+
+void
+SALOME_Actor
+::setIO(const Handle(SALOME_InteractiveObject)& theIO)
+{
+ myIO = theIO;
+}
+
+const char*
+SALOME_Actor
+::getName()
+{
+ return myName.c_str();
+}
+
+void
+SALOME_Actor
+::setName(const char* theName)
+{
+ if(hasIO())
+ myIO->setName(theName);
+ myName = theName;
+}
+
+
+//----------------------------------------------------------------------------
+bool
+SALOME_Actor
+::hasHighlight()
+{
+ return false;
+}
+
+void
+SALOME_Actor
+::highlight(bool theHighlight)
+{
+ highlight(theHighlight,ActorSelection);
+}
+
+bool
+SALOME_Actor
+::isHighlighted()
+{
+ return myIsHighlighted;
+}
+
+void
+SALOME_Actor
+::SetPreSelected(bool thePreselect)
+{
+ myIsPreselected = thePreselect;
}
theRenderer->AddActor(this);
- theRenderer->AddActor( myPreHighlightActor );
- theRenderer->AddActor( myHighlightActor );
- theRenderer->AddActor( myOutlineActor );
+ theRenderer->AddActor( myPreHighlightActor.GetPointer() );
+ theRenderer->AddActor( myHighlightActor.GetPointer() );
+ theRenderer->AddActor( myOutlineActor.GetPointer() );
}
void
{
theRenderer->RemoveActor(this);
- theRenderer->RemoveActor( myPreHighlightActor );
- theRenderer->RemoveActor( myHighlightActor );
- theRenderer->RemoveActor( myOutlineActor );
+ theRenderer->RemoveActor( myPreHighlightActor.GetPointer() );
+ theRenderer->RemoveActor( myHighlightActor.GetPointer() );
+ theRenderer->RemoveActor( myOutlineActor.GetPointer() );
}
vtkRenderer*
return myRenderer;
}
+void
+SALOME_Actor
+::GetChildActors(vtkActorCollection*)
+{}
+
//----------------------------------------------------------------------------
void
}
void
-SALOME_Actor::GetPolygonOffsetParameters(float& factor, float& units)
+SALOME_Actor
+::GetPolygonOffsetParameters(float& factor, float& units)
{
factor = myPolygonOffsetFactor;
units = myPolygonOffsetUnits;
}
+//----------------------------------------------------------------------------
+float
+SALOME_Actor
+::GetShrinkFactor()
+{
+ return 1.0;
+}
+
+bool
+SALOME_Actor
+::IsShrunkable()
+{
+ return false;
+}
+
+bool
+SALOME_Actor
+::IsShrunk()
+{
+ return false;
+}
+
+void
+SALOME_Actor
+::SetShrink()
+{}
+
+void
+SALOME_Actor
+::UnShrink()
+{}
+
+
//----------------------------------------------------------------------------
vtkDataSet*
SALOME_Actor
//----------------------------------------------------------------------------
+int
+SALOME_Actor
+::GetNodeObjId(int theVtkID)
+{
+ return theVtkID;
+}
+
+float*
+SALOME_Actor
+::GetNodeCoord(int theObjID)
+{
+ return GetInput()->GetPoint(theObjID);
+}
+
vtkCell*
SALOME_Actor
::GetElemCell(int theObjID)
return GetInput()->GetCell(theObjID);
}
-
-float*
-SALOME_Actor::GetNodeCoord(int theObjID)
-{
- return GetInput()->GetPoint(theObjID);
+int
+SALOME_Actor
+::GetElemObjId(int theVtkID)
+{
+ return theVtkID;
}
}
+//----------------------------------------------------------------------------
+bool
+SALOME_Actor
+::IsSetCamera() const
+{
+ return false;
+}
+
+bool
+SALOME_Actor
+::IsResizable() const
+{
+ return false;
+}
+
+void
+SALOME_Actor
+::SetSize( const float )
+{}
+
+
+void
+SALOME_Actor
+::SetCamera( vtkCamera* )
+{}
+
+//----------------------------------------------------------------------------
void
SALOME_Actor
::SetOpacity(float theOpacity)
GetProperty()->SetColor(r,g,b);
}
+void
+SALOME_Actor
+::SetColor(const float theRGB[3])
+{
+ SetColor(theRGB[0],theRGB[1],theRGB[2]);
+}
+
void
SALOME_Actor
::GetColor(float& r,float& g,float& b)
}
+//----------------------------------------------------------------------------
int
SALOME_Actor
::getDisplayMode()
//----------------------------------------------------------------
void
SALOME_Actor
-::highlight( bool theHighlight, int theSelectionMode )
+::highlight(bool theHighlight,
+ Selection_Mode theSelectionMode)
{
myIsHighlighted = theHighlight;
}
-//----------------------------------------------------------------
-int
-SALOME_Actor
-::GetEdgeId( vtkPicker* thePicker, int theObjId )
-{
- int anEdgeId = -1;
- if (vtkCell* aPickedCell = GetElemCell(theObjId)) {
- float aPickPosition[3];
- thePicker->GetPickPosition(aPickPosition);
- float aMinDist = 1000000.0, aDist = 0;
- for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){
- if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){
- int subId; float pcoords[3], closestPoint[3], weights[3];
- aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
- if (aDist < aMinDist) {
- aMinDist = aDist;
- anEdgeId = i;
- }
- }
- }
- }
- return anEdgeId;
-}
-
//----------------------------------------------------------------
bool
SALOME_Actor
-::PreHighlight( SVTK_Selector* theSelector,
- //vtkRenderer* theRenderer,
- vtkInteractorStyle *theIS,
- SVTK_SelectionEvent theSelectionEvent,
- bool theIsHighlight )
+::PreHighlight(SVTK_Selector* theSelector,
+ vtkInteractorStyle *theInteractorStyle,
+ const SVTK_SelectionEvent& theSelectionEvent,
+ bool theIsHighlight)
{
- vtkRenderer *aRenderer=theIS->GetCurrentRenderer();
+ vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
//
myPreHighlightActor->SetVisibility( false );
if ( aVtkId >= 0 && theSelector->IsValid( this, aVtkId ) && hasIO() )
{
int anObjId = GetElemObjId( aVtkId );
- int anEdgeId = GetEdgeId( myCellPicker, anObjId );
+ int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId);
TColStd_IndexedMapOfInteger aMapIndex;
aMapIndex.Add( anObjId );
aMapIndex.Add( anEdgeId );
return anIsChanged;
}
+
+
//----------------------------------------------------------------
bool
SALOME_Actor
-::Highlight( SVTK_Selector* theSelector,
- vtkInteractorStyle* theIS,
- SVTK_SelectionEvent theSelectionEvent,
- bool theIsHighlight )
+::Highlight(SVTK_Selector* theSelector,
+ vtkInteractorStyle *theInteractorStyle,
+ const SVTK_SelectionEvent& theSelectionEvent,
+ bool theIsHighlight)
{
- vtkRenderer *aRenderer=theIS->GetCurrentRenderer();
-
+ vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
//
int aSelectionMode = theSelectionEvent.mySelectionMode;
float x1 = theSelectionEvent.myX;
{
theSelector->ClearIObjects();
}
- int anEdgeId = GetEdgeId( myCellPicker, anObjId );
+ int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId);
if( anEdgeId >= 0 )
{
theSelector->AddOrRemoveIndex( myIO, anObjId, false );
switch( aSelectionMode )
{
case NodeSelection:
- myHighlightActor->SetProperty( myPointProperty );
+ myHighlightProperty->SetRepresentationToPoints();
myHighlightActor->MapPoints( this, aMapIndex );
break;
case EdgeOfCellSelection:
- myHighlightActor->SetProperty( myEdgeProperty );
+ myHighlightProperty->SetRepresentationToWireframe();
myHighlightActor->MapEdge( this, aMapIndex );
break;
case CellSelection:
case EdgeSelection:
case FaceSelection:
case VolumeSelection:
- myHighlightActor->SetProperty( myCellProperty );
+ myHighlightProperty->SetRepresentationToSurface();
myHighlightActor->MapCells( this, aMapIndex );
break;
case ActorSelection:
return true;
}
+//----------------------------------------------------------------------------
+void
+SALOME_Actor
+::SetSelectionProp(const double& theRed,
+ const double& theGreen,
+ const double& theBlue,
+ const int& theWidth)
+{
+ myHighlightProperty->SetColor( theRed, theGreen, theBlue );
+ myHighlightProperty->SetLineWidth( theWidth );
+}
+
+//----------------------------------------------------------------------------
+void
+SALOME_Actor
+::SetPreselectionProp(const double& theRed,
+ const double& theGreen,
+ const double& theBlue,
+ const int& theWidth)
+{
+ myPreHighlightProperty->SetColor( theRed, theGreen, theBlue );
+ myPreHighlightProperty->SetLineWidth( theWidth );
+}
+
+//----------------------------------------------------------------------------
+void
+SALOME_Actor
+::SetSelectionTolerance(const double& theTolNodes,
+ const double& theTolCell)
+{
+ myPointPicker->SetTolerance( theTolNodes );
+ myCellPicker->SetTolerance( theTolCell );
+ myCellRectPicker->SetTolerance( theTolCell );
+}
+
#include <string>
#include <vector>
+#include <vtkSmartPointer.h>
+
class vtkCell;
class vtkPicker;
class vtkPointPicker;
class SVTK_InteractorStyle;
extern int SALOME_POINT_SIZE;
+extern int SALOME_LINE_WIDTH;
class SALOME_Actor;
vtkTypeMacro(SALOME_Actor,vtkLODActor);
+ //----------------------------------------------------------------------------
virtual
Standard_Boolean
- hasIO()
- {
- return !myIO.IsNull();
- }
+ hasIO();
virtual
const Handle(SALOME_InteractiveObject)&
- getIO()
- {
- return myIO;
- }
+ getIO();
virtual
void
- setIO(const Handle(SALOME_InteractiveObject)& theIO)
- {
- myIO = theIO;
- }
+ setIO(const Handle(SALOME_InteractiveObject)& theIO);
virtual
const char*
- getName()
- {
- return myName.c_str();
- }
+ getName();
virtual
void
- setName(const char* theName)
- {
- if(hasIO())
- myIO->setName(theName);
- myName = theName;
- }
+ setName(const char* theName);
+ //----------------------------------------------------------------------------
// To generate highlight automaticaly
virtual
bool
- hasHighlight()
- {
- return false;
- }
+ hasHighlight();
virtual
void
- highlight( bool theHighlight, int theSelectionMode );
+ highlight(bool theHighlight,
+ Selection_Mode theSelectionMode);
virtual
void
- highlight(bool theHighlight)
- {
- highlight(theHighlight,ActorSelection);
- }
+ highlight(bool theHighlight);
virtual
bool
- isHighlighted()
- {
- return myIsHighlighted;
- }
+ isHighlighted();
+ virtual
+ void
+ SetPreSelected(bool thePreselect = false);
+
+ //----------------------------------------------------------------------------
virtual
void
SetOpacity(float theOpacity);
virtual
void
- SetColor(const float theRGB[3])
- {
- SetColor(theRGB[0],theRGB[1],theRGB[2]);
- }
-
- vtkSetObjectMacro(PreviewProperty,vtkProperty);
+ SetColor(const float theRGB[3]);
- virtual
- void
- SetPreSelected(bool thePreselect = false)
- {
- myIsPreselected = thePreselect;
- }
-
- // Used to obtain all dependent actors
- virtual
- void
- GetChildActors(vtkActorCollection*)
- {};
-
+ //----------------------------------------------------------------------------
// For selection mapping purpose
virtual
int
- GetNodeObjId(int theVtkID)
- {
- return theVtkID;
- }
+ GetNodeObjId(int theVtkID);
virtual
float*
virtual
int
- GetElemObjId(int theVtkID)
- {
- return theVtkID;
- }
+ GetElemObjId(int theVtkID);
virtual
vtkCell*
GetElemCell(int theObjID);
+ //----------------------------------------------------------------------------
virtual
int
GetObjDimension( const int theObjId );
unsigned long int
GetMTime();
+ //----------------------------------------------------------------------------
virtual
void
SetRepresentation(int theMode);
void
setDisplayMode(int theMode);
+ //----------------------------------------------------------------------------
// Infinitive means actor without size (point for example),
// which is not taken into account in calculation of boundaries of the scene
void
void
GetBounds(float bounds[6]);
+ //----------------------------------------------------------------------------
+ virtual
+ bool
+ IsSetCamera() const;
+
+ virtual
+ bool
+ IsResizable() const;
+
+ virtual
+ void
+ SetSize( const float );
+
+ virtual
+ void
+ SetCamera( vtkCamera* );
+
+ //----------------------------------------------------------------------------
void
SetResolveCoincidentTopology(bool theIsResolve);
void
Render(vtkRenderer *, vtkMapper *);
+ //----------------------------------------------------------------------------
virtual
float
- GetShrinkFactor()
- {
- return 1.0;
- }
+ GetShrinkFactor();
virtual
bool
- IsShrunkable()
- {
- return false;
- }
+ IsShrunkable();
virtual
bool
- IsShrunk()
- {
- return false;
- }
+ IsShrunk();
virtual
void
- SetShrink()
- {}
+ SetShrink();
virtual
void
- UnShrink()
- {}
-
- virtual
- bool
- IsSetCamera() const
- {
- return false;
- }
-
- virtual
- bool
- IsResizable() const
- {
- return false;
- }
-
- virtual
- void
- SetSize( const float )
- {}
-
- virtual
- void
- SetCamera( vtkCamera* )
- {}
+ UnShrink();
+ //----------------------------------------------------------------------------
virtual
void
SetVisibility( int );
vtkRenderer*
GetRenderer();
+ // Used to obtain all dependent actors
+ virtual
+ void
+ GetChildActors(vtkActorCollection*);
+
//----------------------------------------------------------------------------
virtual
void
//----------------------------------------------------------------------------
virtual
bool
- PreHighlight( SVTK_Selector*,
- vtkInteractorStyle*,
- SVTK_SelectionEvent,
- bool );
+ PreHighlight(SVTK_Selector* theSelector,
+ vtkInteractorStyle* theInteractorStyle,
+ const SVTK_SelectionEvent& theSelectionEvent,
+ bool theIsHighlight);
virtual
bool
- Highlight( SVTK_Selector*,
- vtkInteractorStyle*,
- SVTK_SelectionEvent,
- bool );
-
- vtkProperty*
- getPointProperty()
- {
- return myPointProperty;
- }
-
- vtkProperty*
- getCellProperty()
- {
- return myCellProperty;
- }
-
- vtkProperty*
- getEdgeProperty()
- {
- return myEdgeProperty;
- }
-
- vtkPointPicker*
- getPointPicker()
- {
- return myPointPicker;
- }
-
- vtkCellPicker*
- getCellPicker()
- {
- return myCellPicker;
- }
-
- VTKViewer_CellRectPicker*
- getCellRectPicker()
- {
- return myCellRectPicker;
- }
+ Highlight(SVTK_Selector* theSelector,
+ vtkInteractorStyle* theInteractorStyle,
+ const SVTK_SelectionEvent& theSelectionEvent,
+ bool theIsHighlight);
+
+ virtual
+ void
+ SetSelectionProp(const double& theRed = 1,
+ const double& theGreen = 1,
+ const double& theBlue = 0,
+ const int& theWidth = 5);
+
+ virtual
+ void
+ SetPreselectionProp(const double& theRed = 0,
+ const double& theGreen = 1,
+ const double& theBlue = 1,
+ const int& theWidth = 5);
+
+ virtual
+ void
+ SetSelectionTolerance(const double& theTolNodes = 0.025,
+ const double& theTolCell = 0.001);
+
+ vtkSetObjectMacro(PreviewProperty,vtkProperty);
protected:
+ //----------------------------------------------------------------------------
vtkRenderWindowInteractor* myInteractor;
vtkRenderer* myRenderer;
~SALOME_Actor();
protected:
- int GetEdgeId( vtkPicker*, int );
-
- vtkProperty* myPointProperty;
- vtkProperty* myCellProperty;
- vtkProperty* myEdgeProperty;
+ //----------------------------------------------------------------------------
+ // Highlight/ Prehighlight devices
+ vtkSmartPointer<vtkPointPicker> myPointPicker;
+ vtkSmartPointer<vtkCellPicker> myCellPicker;
+ vtkSmartPointer<VTKViewer_CellRectPicker> myCellRectPicker;
- vtkPointPicker* myPointPicker;
- vtkCellPicker* myCellPicker;
- VTKViewer_CellRectPicker* myCellRectPicker;
+ vtkSmartPointer<vtkProperty> myPreHighlightProperty;
+ vtkSmartPointer<SVTK_Actor> myPreHighlightActor;
- SVTK_Actor* myPreHighlightActor;
- SVTK_Actor* myHighlightActor;
+ vtkSmartPointer<vtkProperty> myHighlightProperty;
+ vtkSmartPointer<SVTK_Actor> myHighlightActor;
- vtkActor* myOutlineActor;
- vtkOutlineSource* myOutline;
- vtkPolyDataMapper* myOutlineMapper;
+ vtkSmartPointer<vtkActor> myOutlineActor;
+ vtkSmartPointer<vtkOutlineSource> myOutline;
+ vtkSmartPointer<vtkPolyDataMapper> myOutlineMapper;
};
#endif // SALOME_ACTOR_H