#include <vtkObjectFactory.h>
#include <vtkImplicitBoolean.h>
#include <SALOME_ExtractGeometry.h>
+#include <vtkExtractPolyDataGeometry.h>
#include <vtkImplicitFunctionCollection.h>
#include <vtkPlane.h>
::VISU_DataSetActor():
myMapper(vtkDataSetMapper::New()),
myExtractor(SALOME_ExtractGeometry::New()),
+ myPolyDataExtractor(vtkExtractPolyDataGeometry::New()),
myFunction(vtkImplicitBoolean::New())
{
if(MYDEBUG) MESSAGE("VISU_DataSetActor::VISU_DataSetActor - this = "<<this);
myExtractor->SetImplicitFunction(myFunction);
+ myPolyDataExtractor->SetImplicitFunction(myFunction);
//myExtractor->ExtractBoundaryCellsOn();
+
myFunction->SetOperationTypeToIntersection();
myMapper->Delete();
myExtractor->Delete();
+ myPolyDataExtractor->Delete();
myFunction->Delete();
}
VISU_DataSetActor
::SetMapperInput(vtkDataSet* theDataSet)
{
- myExtractor->SetInput(theDataSet);
- myMapper->SetInput(myExtractor->GetOutput());
+ if (theDataSet->IsA("vtkPolyData")) {
+ myPolyDataExtractor->SetInput(theDataSet);
+ myMapper->SetInput(myPolyDataExtractor->GetOutput());
+ } else {
+ myExtractor->SetInput(theDataSet);
+ myMapper->SetInput(myExtractor->GetOutput());
+ }
SetMapper(myMapper.GetPointer());
}
//----------------------------------------------------------------------------
bool VISU_DataSetActor::AddClippingPlane(vtkPlane* thePlane)
{
+ vtkImplicitFunctionCollection* aFunctions = GetClippingPlanes();
+ aFunctions->InitTraversal();
+ vtkImplicitFunction* aItem;
+ while ((aItem = aFunctions->GetNextItem())) {
+ if (thePlane == aItem)
+ return false;
+ }
myFunction->AddFunction(thePlane);
+ return true;
}
//----------------------------------------------------------------------------
class vtkDataSetMapper;
class SALOME_ExtractGeometry;
+class vtkExtractPolyDataGeometry;
class vtkImplicitBoolean;
class vtkImplicitFunctionCollection;
//----------------------------------------------------------------------------
vtkSmartPointer<vtkDataSetMapper> myMapper;
vtkSmartPointer<SALOME_ExtractGeometry> myExtractor;
+ vtkSmartPointer<vtkExtractPolyDataGeometry> myPolyDataExtractor;
vtkSmartPointer<vtkImplicitBoolean> myFunction;
};
<source>ICON_WIREFRAME</source>
<translation>Visu_wireframe.png</translation>
</message>
+ <message>
+ <source>ICON_DEACTIVATE_PLANES</source>
+ <translation>Visu_DeactivatePlane.png</translation>
+ </message>
+ <message>
+ <source>ICON_PLANES_MGR</source>
+ <translation>Visu_planemanager.png</translation>
+ </message>
</context>
</TS>
</message>
</context>
<context>
- <name>VisuGUI_ViewExtender</name>
+ <name>VisuGUI_SegmentationMgr</name>
<message>
<source>MNU_CLIPPING_PLANE_MGR</source>
<translation>Clipping planes</translation>
<source>VISU_SETPLANES_MNU</source>
<translation>Set clipping plane...</translation>
</message>
+ <message>
+ <source>MNU_SHOW_CLIPPINGPLANES</source>
+ <translation>Show clipping planes</translation>
+ </message>
+ <message>
+ <source>DSK_SHOW_CLIPPINGPLANES</source>
+ <translation>Show/Hide clipping planes</translation>
+ </message>
+ <message>
+ <source>MNU_ACTIVATE_CLIPPINGPLANES</source>
+ <translation>Deactivate clipping planes</translation>
+ </message>
+ <message>
+ <source>DSK_ACTIVATE_CLIPPINGPLANES</source>
+ <translation>Activate/Deactivate clipping planes</translation>
+ </message>
</context>
</TS>
VisuGUI_ViewExtender* aVisuExtender = dynamic_cast<VisuGUI_ViewExtender*>(myVisuGUI->getViewExtender());
SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI);
- VisuGUI_SegmentationMgr* aSegmentationMgr = aVisuExtender->getSegmentationMgr();
+ VisuGUI_SegmentationMgr* aSegmentationMgr = aVisuExtender->getSegmentationMgr(aViewWindow);
myDSActor->RemoveAllClippingPlanes();
- const QListOfPlanes& aPlanes = aSegmentationMgr->getPlanes(aViewWindow);
+ const QListOfPlanes& aPlanes = aSegmentationMgr->getPlanes();
PlaneDef aPlane;
for (int i = 0; i < myGlobalPlanes->count(); i++) {
if (myGlobalPlanes->item(i)->checkState() == Qt::Checked) {
SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI);
if (!aViewWindow) return false;
- VisuGUI_SegmentationMgr* aSegmentationMgr = aVisuExtender->getSegmentationMgr();
- return aSegmentationMgr->getPlanes(aViewWindow).size() > 0;
+ VisuGUI_SegmentationMgr* aSegmentationMgr = aVisuExtender->getSegmentationMgr(aViewWindow);
+ return aSegmentationMgr->getPlanes().size() > 0;
}
//=================================================================================
if (!myHasGlobalPl) return;
VisuGUI_ViewExtender* aVisuExtender = dynamic_cast<VisuGUI_ViewExtender*>(myVisuGUI->getViewExtender());
SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myVisuGUI);
- VisuGUI_SegmentationMgr* aSegmentationMgr = aVisuExtender->getSegmentationMgr();
+ VisuGUI_SegmentationMgr* aSegmentationMgr = aVisuExtender->getSegmentationMgr(aViewWindow);
double aBounds[6];
ComputeVisiblePropBounds(aViewWindow->getRenderer(), aBounds);
// Add planes names to list
- const QListOfPlanes& aPlanes = aSegmentationMgr->getPlanes(aViewWindow);
+ const QListOfPlanes& aPlanes = aSegmentationMgr->getPlanes();
PlaneDef aPlane;
for (int i = 0; i < aPlanes.size(); i++) {
aPlane = aPlanes.at(i);
#include <vtkImplicitPlaneWidget.h>
#include <vtkGlyph3D.h>
#include <vtkCallbackCommand.h>
-#include <vtkImageData.h>
-#include <vtkCutter.h>
-#include <vtkPolyDataMapper.h>
#include <vtkActorCollection.h>
-#include <vtkActor.h>
#include <vtkPlane.h>
#include <vtkImplicitFunction.h>
#include <vtkImplicitFunctionCollection.h>
-
-#define PRINT3(MARK, VAL) printf("#### %s x=%f, y=%f, z=%f\n", MARK, VAL[0], VAL[1], VAL[2]);
-
-
-void AdjustBounds(const double bounds[6], double newBounds[6], double center[3])
-{
- center[0] = (bounds[0] + bounds[1])/2.0;
- center[1] = (bounds[2] + bounds[3])/2.0;
- center[2] = (bounds[4] + bounds[5])/2.0;
-
- newBounds[0] = center[0] + SIZEFACTOR*(bounds[0]-center[0]);
- newBounds[1] = center[0] + SIZEFACTOR*(bounds[1]-center[0]);
- newBounds[2] = center[1] + SIZEFACTOR*(bounds[2]-center[1]);
- newBounds[3] = center[1] + SIZEFACTOR*(bounds[3]-center[1]);
- newBounds[4] = center[2] + SIZEFACTOR*(bounds[4]-center[2]);
- newBounds[5] = center[2] + SIZEFACTOR*(bounds[5]-center[2]);
-}
-
-
-
-//****************************************************************
-PreviewPlane::PreviewPlane(SVTK_ViewWindow* theWindow, const PlaneDef& thePlane, const double* theBounds):
- myWindow(theWindow),
- myBounds(theBounds)
-{
- double aCenter[3];
- double aBound[6];
-
- AdjustBounds(myBounds, aBound, aCenter);
-
- myPlane = thePlane.plane;
-
- myBox = vtkImageData::New();
- myBox->SetDimensions(2, 2, 2);
- myBox->SetOrigin(aBound[0],aBound[2],aBound[4]);
- myBox->SetSpacing((aBound[1]-aBound[0]),
- (aBound[3]-aBound[2]),
- (aBound[5]-aBound[4]));
-
- myCutter = vtkCutter::New();
- myCutter->SetInput(myBox);
- myCutter->SetCutFunction(myPlane);
-
- myMapper = vtkPolyDataMapper::New();
- myMapper->SetInput(myCutter->GetOutput());
-
- myActor = vtkActor::New();
- myActor->VisibilityOff();
- myActor->PickableOff();
- myActor->SetMapper(myMapper);
- vtkProperty* aProp = vtkProperty::New();
- float anRGB[3];
-
- SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
-
- QColor aFillColor = aResourceMgr->colorValue("SMESH", "fill_color", QColor(0, 170, 255));
- anRGB[0] = aFillColor.red()/255.;
- anRGB[1] = aFillColor.green()/255.;
- anRGB[2] = aFillColor.blue()/255.;
- aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
- aProp->SetOpacity(0.75);
- myActor->SetBackfaceProperty(aProp);
- aProp->Delete();
-
- vtkProperty* aBackProp = vtkProperty::New();
- QColor aBackFaceColor = aResourceMgr->colorValue("SMESH", "backface_color", QColor(0, 0, 255));
- anRGB[0] = aBackFaceColor.red()/255.;
- anRGB[1] = aBackFaceColor.green()/255.;
- anRGB[2] = aBackFaceColor.blue()/255.;
- aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
- aBackProp->SetOpacity(0.75);
- myActor->SetProperty(aBackProp);
- aBackProp->Delete();
-
- myWindow->getRenderer()->AddActor(myActor);
-}
-
-//****************************************************************
-PreviewPlane::~PreviewPlane()
-{
- myWindow->getRenderer()->RemoveActor(myActor);
- myActor->Delete();
-
- myMapper->RemoveAllInputs();
- myMapper->Delete();
- myCutter->Delete();
- myBox->Delete();
-}
-
-
-
-
-
-
//****************************************************************
//****************************************************************
//****************************************************************
VisuGUI_ClippingPlaneMgr::VisuGUI_ClippingPlaneMgr(VisuGUI* theModule,
SVTK_ViewWindow* theViewWindow,
- const QListOfPlanes& thePlanes)
+ VisuGUI_SegmentationMgr* theMgr)
: QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
myModule(theModule),
- myPlanes(thePlanes),
myViewWindow(theViewWindow),
myCurrentPlane(-1),
myPreviewWidget(0),
myCallback( vtkCallbackCommand::New() ),
- myIsRestored(false)
+ mySegmentationMgr(theMgr)
{
+ myPlanes = mySegmentationMgr->getPlanes();
+ myIsVisibleState = mySegmentationMgr->isPlanesVisible();
+ mySegmentationMgr->setPlanesVisible(false);
+
ComputeVisiblePropBounds(myViewWindow->getRenderer(), myBounds);
setWindowTitle(tr("TITLE"));
}
}
myCopyActorsMap = myActorsMap;
- myIsRestored = false;
}
//****************************************************************
//****************************************************************
void VisuGUI_ClippingPlaneMgr::restoreState(const QMap<VISU_DataSetActor*, ListOfvtkPlanes>& theState)
{
- if (myIsRestored) return;
QList<VISU_DataSetActor*> aActors = theState.keys();
VISU_DataSetActor* aActor;
vtkPlane* aPlane;
aActor->AddClippingPlane(aPlane);
}
}
- myIsRestored = true;
}
{
savePlane(myCurrentPlane);
restoreState(myActorsMap);
- emit applyPlanes();
- onClose();
+ mySegmentationMgr->setPlanes(myPlanes);
+ if (myIsVisibleState)
+ mySegmentationMgr->setPlanesVisible(myIsVisibleState);
+ else
+ myViewWindow->Repaint();
+ close();
}
//****************************************************************
void VisuGUI_ClippingPlaneMgr::onClose()
{
restoreState(myCopyActorsMap);
- myViewWindow->Repaint();
+ if (myIsVisibleState)
+ mySegmentationMgr->setPlanesVisible(myIsVisibleState);
+ else
+ myViewWindow->Repaint();
close();
}
void VisuGUI_ClippingPlaneMgr::setEmptyPlane(PlaneDef& thePlane) const
{
thePlane.name = QString("Plane %1").arg(myPlanes.size());
- thePlane.plane = vtkPlane::New();
+ thePlane.plane = CutPlaneFunction::New();
thePlane.plane->Delete();
thePlane.plane->SetOrigin(0.,0.,0.);
thePlane.plane->SetNormal(0.,0.,1.);
thePlane.isAuto = false;
- thePlane.isOn = false;
+ //thePlane.isOn = false;
}
//****************************************************************
class vtkImplicitPlaneWidget;
class vtkCallbackCommand;
-class vtkPolyDataMapper;
-class vtkImageData;
-class vtkCutter;
class VISU_DataSetActor;
#include <vtkSmartPointer.h>
#include <vtkActor.h>
-class PreviewPlane
-{
-public:
- PreviewPlane(SVTK_ViewWindow* theWindow, const PlaneDef& thePlane, const double* theBounds);
- ~PreviewPlane();
-
- void setVisible(bool theVisible)
- { myActor->SetVisibility(theVisible); }
-
- //void setPlane(const PlaneDef& thePlane);
-
-private:
- SVTK_ViewWindow* myWindow;
-
- //SALOME_Actor* myActor;
- vtkActor* myActor;
- vtkPolyDataMapper* myMapper;
- const double* myBounds;
- vtkPlane* myPlane;
- vtkImageData* myBox;
- vtkCutter* myCutter;
-};
-
-
class VisuGUI_ClippingPlaneMgr : public QDialog
{
VisuGUI_ClippingPlaneMgr(VisuGUI* theModule,
SVTK_ViewWindow* theViewWindow,
- const QListOfPlanes& thePlanes);
+ VisuGUI_SegmentationMgr* theMgr);
~VisuGUI_ClippingPlaneMgr();
const QListOfPlanes& getPlanes() const { return myPlanes; }
void restoreState(const QMap<VISU_DataSetActor*, ListOfvtkPlanes>& theState);
+ VisuGUI_SegmentationMgr* mySegmentationMgr;
+
QListWidget* myPlanesList;
QLineEdit* myNameEdt;
VisuGUI* myModule;
SVTK_ViewWindow* myViewWindow;
int myCurrentPlane;
- QList<PreviewPlane*> myPreviewList;
+ ListOfPreview myPreviewList;
vtkImplicitPlaneWidget* myPreviewWidget;
vtkSmartPointer<vtkCallbackCommand> myCallback;
QMap<VISU_DataSetActor*, ListOfvtkPlanes> myActorsMap;
QMap<VISU_DataSetActor*, ListOfvtkPlanes> myCopyActorsMap;
- bool myIsRestored;
-
double myBounds[6];
+
+ bool myIsVisibleState;
};
#endif
#include "VisuGUI_SegmentationMgr.h"
+#include "VisuGUI_Tools.h"
+#include "VisuGUI_ClippingPlaneMgr.h"
#include <SVTK_ViewModel.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
+#include <VTKViewer_Utilities.h>
#include <VISU_PipeLine.hxx>
#include <VISU_Actor.h>
+#include <VISU_DataSetActor.h>
+
#include <vtkRenderer.h>
+#include <vtkImageData.h>
+#include <vtkCutter.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkActor.h>
+#include <vtkImplicitFunctionCollection.h>
+
+#include <QtxAction.h>
+#include <QtxActionToolMgr.h>
+#include <QDialog>
+#include <QMenu>
+
+#define SIZEFACTOR 1.5
+
+
+#define PRINT3(MARK, VAL) printf("#### %s x=%f, y=%f, z=%f\n", MARK, VAL[0], VAL[1], VAL[2]);
+
+
+void AdjustBounds(const double bounds[6], double newBounds[6], double center[3])
+{
+ center[0] = (bounds[0] + bounds[1])/2.0;
+ center[1] = (bounds[2] + bounds[3])/2.0;
+ center[2] = (bounds[4] + bounds[5])/2.0;
+
+ newBounds[0] = center[0] + SIZEFACTOR*(bounds[0]-center[0]);
+ newBounds[1] = center[0] + SIZEFACTOR*(bounds[1]-center[0]);
+ newBounds[2] = center[1] + SIZEFACTOR*(bounds[2]-center[1]);
+ newBounds[3] = center[1] + SIZEFACTOR*(bounds[3]-center[1]);
+ newBounds[4] = center[2] + SIZEFACTOR*(bounds[4]-center[2]);
+ newBounds[5] = center[2] + SIZEFACTOR*(bounds[5]-center[2]);
+}
+
+
+
+//****************************************************************
+PreviewPlane::PreviewPlane(SVTK_ViewWindow* theWindow, const PlaneDef& thePlane, const double* theBounds):
+ myWindow(theWindow),
+ myBounds(theBounds)
+{
+ double aCenter[3];
+ double aBound[6];
+
+ AdjustBounds(myBounds, aBound, aCenter);
+
+ myPlane = thePlane.plane;
+
+ myBox = vtkImageData::New();
+ myBox->SetDimensions(2, 2, 2);
+ myBox->SetOrigin(aBound[0],aBound[2],aBound[4]);
+ myBox->SetSpacing((aBound[1]-aBound[0]),
+ (aBound[3]-aBound[2]),
+ (aBound[5]-aBound[4]));
+
+ myCutter = vtkCutter::New();
+ myCutter->SetInput(myBox);
+ myCutter->SetCutFunction(myPlane);
+
+ myMapper = vtkPolyDataMapper::New();
+ myMapper->SetInput(myCutter->GetOutput());
+
+ myActor = vtkActor::New();
+ myActor->VisibilityOff();
+ myActor->PickableOff();
+ myActor->SetMapper(myMapper);
+ vtkProperty* aProp = vtkProperty::New();
+ float anRGB[3];
+
+ SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
+
+ QColor aFillColor = aResourceMgr->colorValue("SMESH", "fill_color", QColor(0, 170, 255));
+ anRGB[0] = aFillColor.red()/255.;
+ anRGB[1] = aFillColor.green()/255.;
+ anRGB[2] = aFillColor.blue()/255.;
+ aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
+ aProp->SetOpacity(0.75);
+ myActor->SetBackfaceProperty(aProp);
+ aProp->Delete();
+
+ vtkProperty* aBackProp = vtkProperty::New();
+ QColor aBackFaceColor = aResourceMgr->colorValue("SMESH", "backface_color", QColor(0, 0, 255));
+ anRGB[0] = aBackFaceColor.red()/255.;
+ anRGB[1] = aBackFaceColor.green()/255.;
+ anRGB[2] = aBackFaceColor.blue()/255.;
+ aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
+ aBackProp->SetOpacity(0.75);
+ myActor->SetProperty(aBackProp);
+ aBackProp->Delete();
+
+ myWindow->getRenderer()->AddActor(myActor);
+}
+
+//****************************************************************
+PreviewPlane::~PreviewPlane()
+{
+ myWindow->getRenderer()->RemoveActor(myActor);
+ myActor->Delete();
+
+ myMapper->RemoveAllInputs();
+ myMapper->Delete();
+ myCutter->Delete();
+ myBox->Delete();
+}
+
+
+
+
+
+//****************************************************************
+//****************************************************************
+//****************************************************************
+CutPlaneFunction* CutPlaneFunction::New()
+{
+ return new CutPlaneFunction();
+}
+
+void CutPlaneFunction::setActive(bool theActive)
+{
+ myIsActive = theActive;
+ Modified();
+}
+
+double CutPlaneFunction::EvaluateFunction(double x[3])
+{
+ if (myIsActive)
+ return vtkPlane::EvaluateFunction(x);
+ else
+ return -1;
+}
+
+double CutPlaneFunction::EvaluateFunction(double x, double y, double z)
+{
+ if (myIsActive)
+ return vtkPlane::EvaluateFunction(x,y,z);
+ else
+ return -1;
+}
+
+CutPlaneFunction::CutPlaneFunction():
+ myIsActive(true)
+{
+
+}
+
+CutPlaneFunction::~CutPlaneFunction()
+{
+}
+
+
+
+
+//****************************************************************
+//****************************************************************
//****************************************************************
-VisuGUI_SegmentationMgr::VisuGUI_SegmentationMgr(VisuGUI* theModule)
+VisuGUI_SegmentationMgr::VisuGUI_SegmentationMgr(VisuGUI* theModule, SVTK_ViewWindow* theWindow):
+ myIsPlanesNonActive(true),
+ myIsPlanesVisible(false),
+ myWindow(theWindow),
+ myModule(theModule),
+ myNonModalDlg(0)
{
+ QtxAction* aAction;
+ SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
+ aAction = new QtxAction(tr("MNU_CLIPPING_PLANE_MGR"),
+ aResourceMgr->loadPixmap("VISU",tr("ICON_PLANES_MGR")),
+ tr( "DSK_CLIPPING_PLANE_MGR" ),
+ 0,
+ this,
+ false);
+ connect(aAction, SIGNAL( activated() ), this, SLOT( onPlanesMgr() ));
+ myActionsMap[ClippingPlaneMgrId] = aAction;
+
+ aAction = new QtxAction(tr("MNU_SHOW_CLIPPINGPLANES"),
+ aResourceMgr->loadPixmap("VISU",tr("ICON_VVTK_PLANE_SEGMENTATION_SWITCH")),
+ tr( "DSK_SHOW_CLIPPINGPLANES" ),
+ 0,
+ this,
+ true);
+ connect(aAction, SIGNAL( toggled(bool) ), this, SLOT( setPlanesVisible(bool) ));
+ myActionsMap[ShowClippingPlanesId] = aAction;
+
+ aAction = new QtxAction(tr("MNU_ACTIVATE_CLIPPINGPLANES"),
+ aResourceMgr->loadPixmap("VISU",tr("ICON_DEACTIVATE_PLANES")),
+ tr( "DSK_ACTIVATE_CLIPPINGPLANES" ),
+ 0,
+ this,
+ true);
+ connect(aAction, SIGNAL( toggled(bool) ), this, SLOT( setPlanesNonActive(bool) ));
+ myActionsMap[DeactivateClippingPlanesId] = aAction;
}
//****************************************************************
VisuGUI_SegmentationMgr::~VisuGUI_SegmentationMgr()
{
+ deactivate();
}
//****************************************************************
-const QListOfPlanes& VisuGUI_SegmentationMgr::getPlanes(SVTK_ViewWindow* theWindow)
+void VisuGUI_SegmentationMgr::deactivate()
{
- if (!myViewPlanesMap.contains(theWindow)) {
- QListOfPlanes aNewList;
- myViewPlanesMap[theWindow] = aNewList;
+ if (myNonModalDlg) {
+ myNonModalDlg->close();
+ myNonModalDlg = 0;
}
- return myViewPlanesMap[theWindow];
}
//****************************************************************
-void VisuGUI_SegmentationMgr::setPlanes(SVTK_ViewWindow* theWindow, const QListOfPlanes& theNewPlanes)
+int VisuGUI_SegmentationMgr::createToolbar(QtxActionToolMgr* theMgr)
{
- myViewPlanesMap.remove(theWindow);
- myViewPlanesMap[theWindow] = theNewPlanes;
+ int aToolBar = theMgr->createToolBar( tr("VISU_VIEW_TOOLBAR"));
+ theMgr->append( myActionsMap[ClippingPlaneMgrId], aToolBar );
+ theMgr->append( myActionsMap[DeactivateClippingPlanesId], aToolBar );
+ theMgr->append( myActionsMap[ShowClippingPlanesId], aToolBar );
+ return aToolBar;
+}
+
- vtkActorCollection* anActors = theWindow->getRenderer()->GetActors();
+//****************************************************************
+const QListOfPlanes& VisuGUI_SegmentationMgr::getPlanes()
+{
+ return myListOfPlanes;
+}
+
+//****************************************************************
+void VisuGUI_SegmentationMgr::setPlanes(const QListOfPlanes& theNewPlanes)
+{
+ myListOfPlanes = theNewPlanes;
+
+ vtkActorCollection* anActors = myWindow->getRenderer()->GetActors();
anActors->InitTraversal();
vtkActor* aActor = 0;
VISU_Actor* aVisuActor = 0;
while ( (aActor = anActors->GetNextActor()) ) {
aVisuActor = VISU_Actor::SafeDownCast(aActor);
if (aVisuActor) {
- applyPlanes(theWindow, aVisuActor, true);
+ applyPlanes(aVisuActor);
}
}
}
//****************************************************************
-void VisuGUI_SegmentationMgr::onAddActor(SVTK_ViewWindow* theWindow, VTKViewer_Actor* theActor)
+void VisuGUI_SegmentationMgr::onAddActor(VTKViewer_Actor* theActor)
{
VISU_Actor* aActor = VISU_Actor::SafeDownCast(theActor);
if (!aActor) return;
- applyPlanes(theWindow, aActor, true);
+ applyPlanes(aActor);
}
//****************************************************************
-void VisuGUI_SegmentationMgr::applyPlanes(SVTK_ViewWindow* theWindow, VISU_Actor* theActor, bool theAuto)
+void VisuGUI_SegmentationMgr::applyPlanes(VISU_Actor* theActor)
{
- const QListOfPlanes& aPlanes = getPlanes(theWindow);
- for (int i = 0; i < aPlanes.size(); i++) {
- PlaneDef aPlane = aPlanes.at(i);
- if ((theAuto)? aPlane.isAuto : aPlane.isOn) {
+ for (int i = 0; i < myListOfPlanes.size(); i++) {
+ PlaneDef aPlane = myListOfPlanes.at(i);
+ if (aPlane.isAuto && (!isContainsPlane(theActor, aPlane.plane))) {
theActor->AddClippingPlane(aPlane.plane);
}
}
- theWindow->Repaint();
+ myWindow->Repaint();
}
+
//****************************************************************
-void VisuGUI_SegmentationMgr::onViewDeleted(SUIT_ViewWindow* theWindow)
+void VisuGUI_SegmentationMgr::setPlanesNonActive(bool theNonActive)
{
- SVTK_ViewWindow* aWindow = dynamic_cast<SVTK_ViewWindow*>(theWindow);
- if (aWindow) {
- if (myViewPlanesMap.contains(aWindow))
- myViewPlanesMap.remove(aWindow);
+ if (myIsPlanesNonActive == theNonActive) return;
+ myIsPlanesNonActive = theNonActive;
+
+ PlaneDef aPlane;
+ for (int i = 0; i < myListOfPlanes.size(); i++) {
+ aPlane = myListOfPlanes.at(i);
+ aPlane.plane->setActive(!theNonActive);
}
-}
+ myWindow->Repaint();
+}
+
+//****************************************************************
+bool VisuGUI_SegmentationMgr::isPlanesNonActive() const
+{
+ return myIsPlanesNonActive;
+}
+
+//****************************************************************
+void VisuGUI_SegmentationMgr::setPlanesVisible(bool theVisible)
+{
+ if (myIsPlanesVisible == theVisible) return;
+ myIsPlanesVisible = theVisible;
+ if (myIsPlanesVisible) {
+ double aBounds[6];
+ ComputeVisiblePropBounds(myWindow->getRenderer(), aBounds);
+ for (int i = 0; i < myListOfPlanes.size(); i++) {
+ PreviewPlane* aPreview = new PreviewPlane(myWindow, myListOfPlanes.at(i), aBounds);
+ aPreview->setVisible(true);
+ myPlanesPreview.append(aPreview);
+ }
+ } else {
+ PreviewPlane* aPreview;
+ while (myPlanesPreview.size() > 0) {
+ aPreview = myPlanesPreview.last();
+ myPlanesPreview.removeLast();
+ delete aPreview;
+ }
+ }
+ myWindow->Repaint();
+}
+
+//****************************************************************
+bool VisuGUI_SegmentationMgr::isPlanesVisible() const
+{
+ return myIsPlanesVisible;
+}
+
+//****************************************************************
+bool VisuGUI_SegmentationMgr::isContainsPlane(VISU_Actor* theActor, vtkPlane* thePlane)
+{
+ VISU_DataSetActor* aDSActor = dynamic_cast<VISU_DataSetActor*>(theActor);
+ if (!aDSActor) return false;
+
+ vtkImplicitFunctionCollection* aFunctions = aDSActor->GetClippingPlanes();
+ aFunctions->InitTraversal();
+ vtkImplicitFunction* aItem;
+ while ((aItem = aFunctions->GetNextItem())) {
+ if (thePlane == aItem)
+ return true;
+ }
+ return false;
+}
+
+//****************************************************************
+void VisuGUI_SegmentationMgr::onPlanesMgr()
+{
+ if (myNonModalDlg) return;
+
+ VisuGUI_ClippingPlaneMgr* aDlg =
+ new VisuGUI_ClippingPlaneMgr(myModule, myWindow, this);
+
+ myNonModalDlg = aDlg;
+ connect(myNonModalDlg, SIGNAL( destroyed(QObject*) ), this, SLOT( onDialogDestroy() ));
+ myNonModalDlg->show();
+}
+
+//****************************************************************
+void VisuGUI_SegmentationMgr::onDialogDestroy()
+{
+ disconnect(myNonModalDlg, SIGNAL( destroyed(QObject*) ), this, SLOT( onDialogDestroy() ));
+ myNonModalDlg = 0;
+}
+
#include <QObject>
#include <QMap>
#include <QList>
+#include <vtkActor.h>
class VISU_Actor;
class vtkPlane;
+class vtkPolyDataMapper;
+class vtkImageData;
+class vtkCutter;
+class QtxAction;
+class QDialog;
+
+class CutPlaneFunction: public vtkPlane
+{
+public:
+ static CutPlaneFunction* New();
+
+ vtkTypeMacro(CutPlaneFunction, vtkPlane);
+
+ virtual double EvaluateFunction(double x[3]);
+ virtual double EvaluateFunction(double x, double y, double z);
+
+ void setActive(bool theActive);
+ bool isActive() const { return myIsActive; }
+
+protected:
+ CutPlaneFunction();
+ ~CutPlaneFunction();
+
+private:
+ bool myIsActive;
+};
+
struct PlaneDef
{
- // PlaneDef() {
- // plane = 0;
- //}
- //~PlaneDef() { if (plane) plane->DebugOn();}
- vtkSmartPointer<vtkPlane> plane;
+ vtkSmartPointer<CutPlaneFunction> plane;
bool isAuto;
QString name;
- bool isOn;
+};
+
+
+class PreviewPlane
+{
+public:
+ PreviewPlane(SVTK_ViewWindow* theWindow, const PlaneDef& thePlane, const double* theBounds);
+ ~PreviewPlane();
+
+ void setVisible(bool theVisible)
+ { myActor->SetVisibility(theVisible); }
+
+private:
+ SVTK_ViewWindow* myWindow;
+
+ vtkActor* myActor;
+ vtkPolyDataMapper* myMapper;
+ const double* myBounds;
+ vtkPlane* myPlane;
+ vtkImageData* myBox;
+ vtkCutter* myCutter;
};
typedef QList<PlaneDef> QListOfPlanes;
typedef QList<vtkPlane*> ListOfvtkPlanes;
+typedef QList<PreviewPlane*> ListOfPreview;
class VisuGUI_SegmentationMgr: public QObject
{
Q_OBJECT
public:
- VisuGUI_SegmentationMgr(VisuGUI* theModule);
+ VisuGUI_SegmentationMgr(VisuGUI* theModule, SVTK_ViewWindow* theWindow);
~VisuGUI_SegmentationMgr();
- const QListOfPlanes& getPlanes(SVTK_ViewWindow* theWindow);
- void setPlanes(SVTK_ViewWindow* theWindow, const QListOfPlanes& theNewPlanes);
+ const QListOfPlanes& getPlanes();
+ void setPlanes(const QListOfPlanes& theNewPlanes);
+
+ bool isPlanesNonActive() const;
+
+ bool isPlanesVisible() const;
+
+ bool isContainsPlane(VISU_Actor* theActor, vtkPlane* thePlane);
+
+ int createToolbar(QtxActionToolMgr* theMgr);
+
+ void deactivate();
+
+public slots:
+ void onAddActor(VTKViewer_Actor*);
+ void setPlanesVisible(bool);
+ void setPlanesNonActive(bool);
private slots:
- void onAddActor(SVTK_ViewWindow*, VTKViewer_Actor*);
- void onViewDeleted(SUIT_ViewWindow*);
+ void onPlanesMgr();
+ void onDialogDestroy();
+
private:
- void applyPlanes(SVTK_ViewWindow* theWindow, VISU_Actor* theActor, bool theAuto);
+ void applyPlanes(VISU_Actor* theActor);
+
+ enum { ClippingPlaneMgrId, ShowClippingPlanesId, DeactivateClippingPlanesId };
+
+ QMap<int, QtxAction*> myActionsMap;
+
+ SVTK_ViewWindow* myWindow;
+ VisuGUI* myModule;
+
+ QDialog* myNonModalDlg;
+ QListOfPlanes myListOfPlanes;
+ bool myIsPlanesNonActive;
+ bool myIsPlanesVisible;
- QMap<SVTK_ViewWindow*, QListOfPlanes> myViewPlanesMap;
+ ListOfPreview myPlanesPreview;
};
#endif
#include "VisuGUI_ViewExtender.h"
-#include "VisuGUI_ClippingPlaneMgr.h"
#include "VisuGUI.h"
#include "VisuGUI_SegmentationMgr.h"
#include "VisuGUI_ViewTools.h"
#include "VisuGUI_Tools.h"
+#include <VTKViewer_Actor.h>
+
+#include <LightApp_SelectionMgr.h>
+#include <SalomeApp_Application.h>
#include <VISU_PipeLine.hxx>
-#include <SUIT_Session.h>
-#include <SUIT_ResourceMgr.h>
#include <SUIT_ViewManager.h>
+#include <SUIT_ViewWindow.h>
+
#include <SVTK_ViewModel.h>
-#include <LightApp_SelectionMgr.h>
-#include <SalomeApp_Application.h>
+#include <SVTK_ViewWindow.h>
-#include <QtxAction.h>
-#include <QtxActionToolMgr.h>
-#include <QDialog>
-#include <QMenu>
//using namespace std;
VisuGUI_ViewExtender::VisuGUI_ViewExtender(VisuGUI* theModule):
- myModule(theModule),
- myNonModalDlg(0)
+ myModule(theModule)
{
- mySegmentationMgr = new VisuGUI_SegmentationMgr(theModule);
-
-
- QtxAction* aAction;
- SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
- aAction = new QtxAction(tr("MNU_CLIPPING_PLANE_MGR"),
- aResourceMgr->loadPixmap("VISU",tr("ICON_VVTK_PLANE_SEGMENTATION_SWITCH")),
- tr( "DSK_CLIPPING_PLANE_MGR" ),
- 0,
- this,
- false);
- connect(aAction, SIGNAL( activated() ), this, SLOT( onPlanesMgr() ));
- myActionsMap[ClippingPlaneMgrId] = aAction;
}
//****************************************************************
VisuGUI_ViewExtender::~VisuGUI_ViewExtender()
{
- delete mySegmentationMgr;
+ QMapIterator<SVTK_ViewWindow*, VisuGUI_SegmentationMgr*> aIt(myViewMgrMap);
+ while (aIt.hasNext()) {
+ aIt.next();
+ delete aIt.value();
+ }
}
//****************************************************************
-int VisuGUI_ViewExtender::createToolbar(QtxActionToolMgr* theMgr)
+int VisuGUI_ViewExtender::createToolbar(SUIT_ViewWindow* theView)
{
- int aToolBar = theMgr->createToolBar( tr("VISU_VIEW_TOOLBAR"));
- theMgr->append( myActionsMap[ClippingPlaneMgrId], aToolBar );
- return aToolBar;
+ SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(theView);
+ if (!aViewWindow) return -1;
+
+ VisuGUI_SegmentationMgr* aMgr = getSegmentationMgr(aViewWindow);
+ return aMgr->createToolbar(theView->toolMgr());
}
//****************************************************************
// theMenu->addAction(tr("VISU_SETPLANES_MNU"), this, SLOT(onSetPlanes()));
}
-//****************************************************************
-void VisuGUI_ViewExtender::onPlanesMgr()
-{
- if (myNonModalDlg) return;
-
- SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(myModule);
- if (!aViewWindow) return;
-
- VisuGUI_ClippingPlaneMgr* aDlg =
- new VisuGUI_ClippingPlaneMgr(myModule, aViewWindow, mySegmentationMgr->getPlanes(aViewWindow));
- connect(aDlg, SIGNAL(applyPlanes()), this, SLOT(onApplyPlanes()));
-
- myNonModalDlg = aDlg;
- connect(myNonModalDlg, SIGNAL( destroyed(QObject*) ), this, SLOT( onDialogDestroy() ));
- myNonModalDlg->show();
-}
//****************************************************************
void VisuGUI_ViewExtender::activate(SUIT_ViewModel* theViewer)
if (!myViewers.contains(aViewer)) {
SUIT_ViewManager* aMgr = aViewer->getViewManager();
connect(aMgr, SIGNAL(deleteView(SUIT_ViewWindow*)),
- mySegmentationMgr, SLOT(onViewDeleted(SUIT_ViewWindow*)));
+ this, SLOT(onViewDeleted(SUIT_ViewWindow*)));
connect(aViewer, SIGNAL(actorAdded(SVTK_ViewWindow*, VTKViewer_Actor*)),
- mySegmentationMgr, SLOT(onAddActor(SVTK_ViewWindow*, VTKViewer_Actor*)));
+ this, SLOT(onAddActor(SVTK_ViewWindow*, VTKViewer_Actor*)));
myViewers.append(aViewer);
}
}
//****************************************************************
void VisuGUI_ViewExtender::deactivate(SUIT_ViewModel*)
{
- if (myNonModalDlg) {
- myNonModalDlg->close();
- myNonModalDlg = 0;
+ QMapIterator<SVTK_ViewWindow*, VisuGUI_SegmentationMgr*> aIt(myViewMgrMap);
+ while (aIt.hasNext()) {
+ aIt.next();
+ aIt.value()->deactivate();
}
}
+
//****************************************************************
-void VisuGUI_ViewExtender::onDialogDestroy()
+VisuGUI_SegmentationMgr* VisuGUI_ViewExtender::getSegmentationMgr(SVTK_ViewWindow* theWindow)
{
- disconnect(myNonModalDlg, SIGNAL( destroyed(QObject*) ), this, SLOT( onDialogDestroy() ));
- myNonModalDlg = 0;
+ if (myViewMgrMap.contains(theWindow))
+ return myViewMgrMap[theWindow];
+ VisuGUI_SegmentationMgr* aMgr = new VisuGUI_SegmentationMgr(myModule, theWindow);
+ myViewMgrMap[theWindow] = aMgr;
+ return aMgr;
}
//****************************************************************
-void VisuGUI_ViewExtender::onApplyPlanes()
+void VisuGUI_ViewExtender::onViewDeleted(SUIT_ViewWindow* theWindow)
{
- VisuGUI_ClippingPlaneMgr* aDlg = (VisuGUI_ClippingPlaneMgr*) myNonModalDlg;
- mySegmentationMgr->setPlanes(aDlg->getViewWindow(), aDlg->getPlanes());
+ SVTK_ViewWindow* aWindow = dynamic_cast<SVTK_ViewWindow*>(theWindow);
+ if (!aWindow) return;
+
+ if (!myViewMgrMap.contains(aWindow)) return;
+ delete myViewMgrMap[aWindow];
+ myViewMgrMap.remove(aWindow);
}
+//****************************************************************
+void VisuGUI_ViewExtender::onAddActor(SVTK_ViewWindow* theWindow, VTKViewer_Actor* theActor)
+{
+ if (!myViewMgrMap.contains(theWindow)) return;
+ myViewMgrMap[theWindow]->onAddActor(theActor);
+}
#include <QMap>
class VisuGUI;
-class QtxAction;
-class QDialog;
+//class QtxAction;
+//class QDialog;
class VisuGUI_SegmentationMgr;
class SVTK_Viewer;
+class SVTK_ViewWindow;
+class SUIT_ViewWindow;
+class VTKViewer_Actor;
+
class VisuGUI_ViewExtender: public QObject, public CAM_ViewExtender
{
virtual ~VisuGUI_ViewExtender();
- virtual int createToolbar(QtxActionToolMgr* theMgr);
+ virtual int createToolbar(SUIT_ViewWindow* theView);
virtual void contextMenuPopup(QMenu* theMenu);
virtual void activate(SUIT_ViewModel*);
virtual void deactivate(SUIT_ViewModel*);
- VisuGUI_SegmentationMgr* getSegmentationMgr() const { return mySegmentationMgr; }
-
+ VisuGUI_SegmentationMgr* getSegmentationMgr(SVTK_ViewWindow* theWindow);
+
private slots:
- void onPlanesMgr();
- void onDialogDestroy();
- void onApplyPlanes();
+ // void onPlanesMgr();
+ // void onDialogDestroy();
+ // void onShowPlanes(bool);
+ // void onDeactivatePlanes(bool);
+ void onViewDeleted(SUIT_ViewWindow* theWindow);
+ void onAddActor(SVTK_ViewWindow* theWindow, VTKViewer_Actor* theActor);
private:
- enum { ClippingPlaneMgrId };
- QMap<int, QtxAction*> myActionsMap;
+ //enum { ClippingPlaneMgrId, ShowClippingPlanesId, DeactivateClippingPlanesId };
+
+ //QMap<int, QtxAction*> myActionsMap;
VisuGUI* myModule;
- QDialog* myNonModalDlg;
+ //QDialog* myNonModalDlg;
- VisuGUI_SegmentationMgr* mySegmentationMgr;
+ //VisuGUI_SegmentationMgr* mySegmentationMgr;
+ QMap<SVTK_ViewWindow*, VisuGUI_SegmentationMgr*> myViewMgrMap;
QList<SVTK_Viewer*> myViewers;
- SALOME_ListIO myListIO;
+ //SALOME_ListIO myListIO;
};