From: vsv Date: Wed, 4 Jun 2008 06:29:14 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: TG_VISU_2008_2008-06-26~28 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e62427458a4c20c01ac109f33dd6275874d225e4;p=modules%2Fvisu.git *** empty log message *** --- diff --git a/src/OBJECT/VISU_DataSetActor.cxx b/src/OBJECT/VISU_DataSetActor.cxx index c19e829f..2ac67770 100644 --- a/src/OBJECT/VISU_DataSetActor.cxx +++ b/src/OBJECT/VISU_DataSetActor.cxx @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -54,16 +55,20 @@ VISU_DataSetActor ::VISU_DataSetActor(): myMapper(vtkDataSetMapper::New()), myExtractor(SALOME_ExtractGeometry::New()), + myPolyDataExtractor(vtkExtractPolyDataGeometry::New()), myFunction(vtkImplicitBoolean::New()) { if(MYDEBUG) MESSAGE("VISU_DataSetActor::VISU_DataSetActor - this = "<SetImplicitFunction(myFunction); + myPolyDataExtractor->SetImplicitFunction(myFunction); //myExtractor->ExtractBoundaryCellsOn(); + myFunction->SetOperationTypeToIntersection(); myMapper->Delete(); myExtractor->Delete(); + myPolyDataExtractor->Delete(); myFunction->Delete(); } @@ -93,8 +98,13 @@ void 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()); } @@ -120,7 +130,15 @@ vtkIdType VISU_DataSetActor::GetNumberOfClippingPlanes() //---------------------------------------------------------------------------- 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; } //---------------------------------------------------------------------------- diff --git a/src/OBJECT/VISU_DataSetActor.h b/src/OBJECT/VISU_DataSetActor.h index 18ef7958..65804229 100644 --- a/src/OBJECT/VISU_DataSetActor.h +++ b/src/OBJECT/VISU_DataSetActor.h @@ -32,6 +32,7 @@ class vtkDataSetMapper; class SALOME_ExtractGeometry; +class vtkExtractPolyDataGeometry; class vtkImplicitBoolean; class vtkImplicitFunctionCollection; @@ -84,6 +85,7 @@ class VTKOCC_EXPORT VISU_DataSetActor : public VISU_Actor //---------------------------------------------------------------------------- vtkSmartPointer myMapper; vtkSmartPointer myExtractor; + vtkSmartPointer myPolyDataExtractor; vtkSmartPointer myFunction; }; diff --git a/src/VISUGUI/VISU_images.ts b/src/VISUGUI/VISU_images.ts index 12a5e828..cbae951c 100644 --- a/src/VISUGUI/VISU_images.ts +++ b/src/VISUGUI/VISU_images.ts @@ -330,5 +330,13 @@ ICON_WIREFRAME Visu_wireframe.png + + ICON_DEACTIVATE_PLANES + Visu_DeactivatePlane.png + + + ICON_PLANES_MGR + Visu_planemanager.png + diff --git a/src/VISUGUI/VISU_msg_en.ts b/src/VISUGUI/VISU_msg_en.ts index 4e10ca2d..580e1a2e 100644 --- a/src/VISUGUI/VISU_msg_en.ts +++ b/src/VISUGUI/VISU_msg_en.ts @@ -3424,7 +3424,7 @@ Please, refer to the documentation. - VisuGUI_ViewExtender + VisuGUI_SegmentationMgr MNU_CLIPPING_PLANE_MGR Clipping planes @@ -3441,5 +3441,21 @@ Please, refer to the documentation. VISU_SETPLANES_MNU Set clipping plane... + + MNU_SHOW_CLIPPINGPLANES + Show clipping planes + + + DSK_SHOW_CLIPPINGPLANES + Show/Hide clipping planes + + + MNU_ACTIVATE_CLIPPINGPLANES + Deactivate clipping planes + + + DSK_ACTIVATE_CLIPPINGPLANES + Activate/Deactivate clipping planes + diff --git a/src/VISUGUI/VisuGUI_ClippingDlg.cxx b/src/VISUGUI/VisuGUI_ClippingDlg.cxx index dc5b5938..0daf34c9 100644 --- a/src/VISUGUI/VisuGUI_ClippingDlg.cxx +++ b/src/VISUGUI/VisuGUI_ClippingDlg.cxx @@ -646,10 +646,10 @@ void VisuGUI_ClippingDlg::applyGlobalPlanes() VisuGUI_ViewExtender* aVisuExtender = dynamic_cast(myVisuGUI->getViewExtender()); SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow(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) { @@ -1357,8 +1357,8 @@ bool VisuGUI_ClippingDlg::hasGlobalPlanes() SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow(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; } //================================================================================= @@ -1370,13 +1370,13 @@ void VisuGUI_ClippingDlg::initGlobalPlanes() if (!myHasGlobalPl) return; VisuGUI_ViewExtender* aVisuExtender = dynamic_cast(myVisuGUI->getViewExtender()); SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow(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); diff --git a/src/VISUGUI/VisuGUI_ClippingPlaneMgr.cxx b/src/VISUGUI/VisuGUI_ClippingPlaneMgr.cxx index 8fce9c4a..a0e1440f 100644 --- a/src/VISUGUI/VisuGUI_ClippingPlaneMgr.cxx +++ b/src/VISUGUI/VisuGUI_ClippingPlaneMgr.cxx @@ -55,11 +55,7 @@ #include #include #include -#include -#include -#include #include -#include #include #include #include @@ -70,115 +66,24 @@ using namespace std; - -#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")); @@ -402,7 +307,6 @@ void VisuGUI_ClippingPlaneMgr::saveState() } } myCopyActorsMap = myActorsMap; - myIsRestored = false; } //**************************************************************** @@ -429,7 +333,6 @@ void VisuGUI_ClippingPlaneMgr::deletePlaneFromActors(int thePlaneId) //**************************************************************** void VisuGUI_ClippingPlaneMgr::restoreState(const QMap& theState) { - if (myIsRestored) return; QList aActors = theState.keys(); VISU_DataSetActor* aActor; vtkPlane* aPlane; @@ -443,7 +346,6 @@ void VisuGUI_ClippingPlaneMgr::restoreState(const QMapAddClippingPlane(aPlane); } } - myIsRestored = true; } @@ -452,15 +354,22 @@ void VisuGUI_ClippingPlaneMgr::onOk() { 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(); } @@ -629,12 +538,12 @@ void VisuGUI_ClippingPlaneMgr::showPlane(int thePlaneNb) 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; } //**************************************************************** diff --git a/src/VISUGUI/VisuGUI_ClippingPlaneMgr.h b/src/VISUGUI/VisuGUI_ClippingPlaneMgr.h index 0163b370..bacc1d6e 100644 --- a/src/VISUGUI/VisuGUI_ClippingPlaneMgr.h +++ b/src/VISUGUI/VisuGUI_ClippingPlaneMgr.h @@ -35,9 +35,6 @@ class PreviewPlane; class vtkImplicitPlaneWidget; class vtkCallbackCommand; -class vtkPolyDataMapper; -class vtkImageData; -class vtkCutter; class VISU_DataSetActor; @@ -46,30 +43,6 @@ class VISU_DataSetActor; #include #include -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 { @@ -78,7 +51,7 @@ public: VisuGUI_ClippingPlaneMgr(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow, - const QListOfPlanes& thePlanes); + VisuGUI_SegmentationMgr* theMgr); ~VisuGUI_ClippingPlaneMgr(); const QListOfPlanes& getPlanes() const { return myPlanes; } @@ -119,6 +92,8 @@ private slots: void restoreState(const QMap& theState); + VisuGUI_SegmentationMgr* mySegmentationMgr; + QListWidget* myPlanesList; QLineEdit* myNameEdt; VisuGUI* myModule; @@ -139,7 +114,7 @@ private slots: SVTK_ViewWindow* myViewWindow; int myCurrentPlane; - QList myPreviewList; + ListOfPreview myPreviewList; vtkImplicitPlaneWidget* myPreviewWidget; vtkSmartPointer myCallback; @@ -148,9 +123,9 @@ private slots: QMap myActorsMap; QMap myCopyActorsMap; - bool myIsRestored; - double myBounds[6]; + + bool myIsVisibleState; }; #endif diff --git a/src/VISUGUI/VisuGUI_SegmentationMgr.cxx b/src/VISUGUI/VisuGUI_SegmentationMgr.cxx index 5c1981cc..3e768972 100644 --- a/src/VISUGUI/VisuGUI_SegmentationMgr.cxx +++ b/src/VISUGUI/VisuGUI_SegmentationMgr.cxx @@ -27,79 +27,363 @@ #include "VisuGUI_SegmentationMgr.h" +#include "VisuGUI_Tools.h" +#include "VisuGUI_ClippingPlaneMgr.h" #include +#include +#include +#include #include #include +#include + #include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#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(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(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; +} + diff --git a/src/VISUGUI/VisuGUI_SegmentationMgr.h b/src/VISUGUI/VisuGUI_SegmentationMgr.h index 7cc51f40..c9e7a70f 100644 --- a/src/VISUGUI/VisuGUI_SegmentationMgr.h +++ b/src/VISUGUI/VisuGUI_SegmentationMgr.h @@ -35,47 +35,120 @@ #include #include #include +#include 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 plane; + vtkSmartPointer 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 QListOfPlanes; typedef QList ListOfvtkPlanes; +typedef QList 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 myActionsMap; + + SVTK_ViewWindow* myWindow; + VisuGUI* myModule; + + QDialog* myNonModalDlg; + QListOfPlanes myListOfPlanes; + bool myIsPlanesNonActive; + bool myIsPlanesVisible; - QMap myViewPlanesMap; + ListOfPreview myPlanesPreview; }; #endif diff --git a/src/VISUGUI/VisuGUI_ViewExtender.cxx b/src/VISUGUI/VisuGUI_ViewExtender.cxx index 37bcce55..21ab0c0c 100644 --- a/src/VISUGUI/VisuGUI_ViewExtender.cxx +++ b/src/VISUGUI/VisuGUI_ViewExtender.cxx @@ -29,59 +29,49 @@ #include "VisuGUI_ViewExtender.h" -#include "VisuGUI_ClippingPlaneMgr.h" #include "VisuGUI.h" #include "VisuGUI_SegmentationMgr.h" #include "VisuGUI_ViewTools.h" #include "VisuGUI_Tools.h" +#include + +#include +#include #include -#include -#include #include +#include + #include -#include -#include +#include -#include -#include -#include -#include //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 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(theView); + if (!aViewWindow) return -1; + + VisuGUI_SegmentationMgr* aMgr = getSegmentationMgr(aViewWindow); + return aMgr->createToolbar(theView->toolMgr()); } //**************************************************************** @@ -100,22 +90,6 @@ void VisuGUI_ViewExtender::contextMenuPopup(QMenu* theMenu) // theMenu->addAction(tr("VISU_SETPLANES_MNU"), this, SLOT(onSetPlanes())); } -//**************************************************************** -void VisuGUI_ViewExtender::onPlanesMgr() -{ - if (myNonModalDlg) return; - - SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow(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) @@ -126,9 +100,9 @@ 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); } } @@ -137,24 +111,39 @@ void VisuGUI_ViewExtender::activate(SUIT_ViewModel* theViewer) //**************************************************************** void VisuGUI_ViewExtender::deactivate(SUIT_ViewModel*) { - if (myNonModalDlg) { - myNonModalDlg->close(); - myNonModalDlg = 0; + QMapIterator 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(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); +} diff --git a/src/VISUGUI/VisuGUI_ViewExtender.h b/src/VISUGUI/VisuGUI_ViewExtender.h index 39b68be1..2193a388 100644 --- a/src/VISUGUI/VisuGUI_ViewExtender.h +++ b/src/VISUGUI/VisuGUI_ViewExtender.h @@ -35,11 +35,15 @@ #include 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 { @@ -50,33 +54,38 @@ 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 myActionsMap; + //enum { ClippingPlaneMgrId, ShowClippingPlanesId, DeactivateClippingPlanesId }; + + //QMap myActionsMap; VisuGUI* myModule; - QDialog* myNonModalDlg; + //QDialog* myNonModalDlg; - VisuGUI_SegmentationMgr* mySegmentationMgr; + //VisuGUI_SegmentationMgr* mySegmentationMgr; + QMap myViewMgrMap; QList myViewers; - SALOME_ListIO myListIO; + //SALOME_ListIO myListIO; };