#include <vtkUnstructuredGrid.h>
#include <vtkPassThroughFilter.h>
#include <vtkFeatureEdges.h>
+#include <vtkActor2D.h>
+#include <vtkMaskPoints.h>
+#include <vtkLabeledDataMapper.h>
+#include <vtkSelectVisiblePoints.h>
+#include <vtkTextProperty.h>
+#include <vtkProperty2D.h>
#include <vtkShrinkFilter.h>
#include <vtkShrinkPolyData.h>
aPickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent,
myEventCallbackCommand.GetPointer(),
myPriority);
+
+ //Definition of values labeling pipeline
+
+ myValLblDataSet = vtkUnstructuredGrid::New();
+
+ myValCellCenters = vtkCellCenters::New();
+ myValCellCenters->SetInput(myValLblDataSet);
+
+ myValMaskPoints = vtkMaskPoints::New();
+ myValMaskPoints->SetInput(myValCellCenters->GetOutput());
+ myValMaskPoints->SetOnRatio(1);
+
+ myValSelectVisiblePoints = vtkSelectVisiblePoints::New();
+ myValSelectVisiblePoints->SetInput(myValMaskPoints->GetOutput());
+ myValSelectVisiblePoints->SelectInvisibleOff();
+ myValSelectVisiblePoints->SetTolerance(0.1);
+
+ myValLabeledDataMapper = vtkLabeledDataMapper::New();
+ myValLabeledDataMapper->SetInput(myValSelectVisiblePoints->GetOutput());
+ myValLabeledDataMapper->SetLabelFormat("%g");
+ myValLabeledDataMapper->SetLabelModeToLabelScalars();
+
+ vtkTextProperty* aClsTextProp = vtkTextProperty::New();
+ aClsTextProp->SetFontFamilyToTimes();
+ static int aCellsFontSize = 12;
+ aClsTextProp->SetFontSize(aCellsFontSize);
+ aClsTextProp->SetBold(1);
+ aClsTextProp->SetItalic(0);
+ aClsTextProp->SetShadow(0);
+ myValLabeledDataMapper->SetLabelTextProperty(aClsTextProp);
+ aClsTextProp->Delete();
+
+ myIsValLabeled = false;
+
+ myValLabels = vtkActor2D::New();
+ myValLabels->SetMapper(myValLabeledDataMapper);
+ myValLabels->GetProperty()->SetColor(0,1,0);
+ myValLabels->SetVisibility( myIsValLabeled );
}
//----------------------------------------------------------------------------
VISU_Actor
::~VISU_Actor()
{
+ // Deleting of values labeling pipeline
+ myValLblDataSet->Delete();
+ myValLabeledDataMapper->RemoveAllInputs();
+ myValLabeledDataMapper->Delete();
+ myValSelectVisiblePoints->Delete();
+ myValMaskPoints->Delete();
+ myValCellCenters->Delete();
+ myValLabels->Delete();
+
if(MYDEBUG) MESSAGE("~VISU_Actor() - this = "<<this);
Superclass::SetProperty(NULL);
SetDebug(MYVTKDEBUG);
Superclass::AddToRender(theRenderer);
theRenderer->AddActor(myAnnotationActor.GetPointer());
theRenderer->AddActor(myTextActor.GetPointer());
+
+ myValSelectVisiblePoints->SetRenderer( theRenderer );
+ theRenderer->AddActor2D( myValLabels );
+
}
//==================================================================
{
theRenderer->RemoveActor(myAnnotationActor.GetPointer());
theRenderer->RemoveActor(myTextActor.GetPointer());
+ theRenderer->RemoveActor(myValLabels);
Superclass::RemoveFromRender(theRenderer);
myDestroySignal(this);
}
+//----------------------------------------------------------------------------
+void
+VISU_Actor
+::SetVisibility(int theMode)
+{
+ Superclass::SetVisibility( theMode );
+ myValLabels->SetVisibility( myIsValLabeled && theMode );
+}
+
//----------------------------------------------------------------------------
void
VISU_Actor
Update();
}
+
+// ---------------------------------------------------------------
+
+void VISU_Actor::SetValuesLabeled( const bool theIsValLabeled )
+{
+ vtkDataSet* aGrid = GetValLabelsInput();
+ if ( !aGrid )
+ return;
+
+ bool isOnPnt = VISU::IsDataOnPoints( aGrid );
+ bool isOnCell = VISU::IsDataOnCells( aGrid );
+ if ( !isOnPnt && !isOnCell )
+ {
+ // try to specify location of scalars "manually"
+ vtkCellData* aCData = aGrid->GetCellData();
+ if ( aCData )
+ {
+ vtkDataArray* anArr = aCData->GetScalars();
+ if ( anArr && anArr->GetNumberOfTuples() )
+ isOnCell = true;
+ }
+
+ if ( !isOnCell )
+ {
+ vtkPointData* aPData = aGrid->GetPointData();
+ if ( aPData )
+ {
+ vtkDataArray* anArr = aPData->GetScalars();
+ if ( anArr && anArr->GetNumberOfTuples() )
+ isOnPnt = true;
+ }
+ }
+
+ if ( !isOnPnt && !isOnCell )
+ {
+ myValLabels->SetVisibility( false );
+ return;
+ }
+ }
+
+ myIsValLabeled = theIsValLabeled;
+
+ if ( myIsValLabeled )
+ {
+ vtkDataSet* aDataSet = aGrid;
+
+ if ( isOnCell )
+ {
+ myValCellCenters->SetInput( aDataSet );
+ myValMaskPoints->SetInput( myValCellCenters->GetOutput() );
+ }
+ else if ( isOnPnt )
+ myValMaskPoints->SetInput( aDataSet );
+
+ myValLabels->SetVisibility( GetVisibility() );
+ }
+ else
+ myValLabels->SetVisibility( false );
+
+ Modified();
+}
+
+//----------------------------------------------------------------------------
+
+bool VISU_Actor::GetValuesLabeled() const
+{
+ return myIsValLabeled;
+}
+
+//----------------------------------------------------------------------------
+
+vtkTextProperty* VISU_Actor::GetsValLabelsProps() const
+{
+ return myValLabeledDataMapper->GetLabelTextProperty();
+}
+
+//----------------------------------------------------------------------------
+
+vtkDataSet* VISU_Actor::GetValLabelsInput()
+{
+ vtkDataSet* aDataSet = 0;
+ VISU_PipeLine* aPL = GetPipeLine();
+ if ( aPL )
+ aDataSet = aPL->GetOutput();
+ if ( !aDataSet )
+ aDataSet = GetInput();
+ return aDataSet;
+}
+
class vtkPlane;
class vtkImplicitFunctionCollection;
class vtkFeatureEdges;
+class vtkTextProperty;
+class vtkCellCenters;
+class vtkSelectVisiblePoints;
+class vtkLabeledDataMapper;
+class vtkMaskPoints;
+class vtkActor2D;
class VISU_FramedTextActor;
virtual
void
RemoveFromRender();
+
+ virtual
+ void
+ SetVisibility(int theMode);
//----------------------------------------------------------------------------
virtual
UpdatePickingSettings();
//----------------------------------------------------------------------------
+ //! Methods for values labeling
+ virtual
+ void
+ SetValuesLabeled( const bool theIsValLabeled );
+
+ virtual
+ bool
+ GetValuesLabeled() const;
+
+ virtual
+ vtkDataSet*
+ GetValLabelsInput();
+
+ vtkTextProperty*
+ GetsValLabelsProps() const;
+
protected:
VISU_Actor();
Selection_Mode myLastSelectionMode;
bool myIsSubElementsHighlighted;
+
+ // fields for values labeling
+ bool myIsValLabeled;
+ vtkDataSet* myValLblDataSet;
+ vtkActor2D* myValLabels;
+ vtkMaskPoints* myValMaskPoints;
+ vtkCellCenters* myValCellCenters;
+ vtkLabeledDataMapper* myValLabeledDataMapper;
+ vtkSelectVisiblePoints* myValSelectVisiblePoints;
};
#endif //VISU_ACTOR_H