From: apo Date: Wed, 28 Sep 2005 08:55:03 +0000 (+0000) Subject: To implement different actor classes for main and segemented views X-Git-Tag: BR-D5-38-2003_D2005-12-10~127 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f7d260423ce4d3f155dd118be8f85a437aa8b846;p=modules%2Fvisu.git To implement different actor classes for main and segemented views --- diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index 36c8b75a..049819c4 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -39,7 +39,6 @@ #include #include -#include #include #include @@ -67,10 +66,6 @@ #include #include -#include -#include -#include - #include #include "utilities.h" @@ -82,253 +77,80 @@ static int MYDEBUG = 0; #endif -//---------------------------------------------------------------- -class VISU_CursorPyramid : public vtkObject -{ -public: - vtkTypeMacro(VISU_CursorPyramid, vtkObject); - - static - VISU_CursorPyramid* - New(); - - void - AddToRender(vtkRenderer* theRenderer) - { - for(int i = 0; i < myNbCones; ++i) - theRenderer->AddActor(myActors[i].GetPointer()); - } - - void - RemoveFromRender(vtkRenderer* theRenderer) - { - for(int i = 0; i < myNbCones; ++i) - theRenderer->RemoveActor(myActors[i].GetPointer()); - } - - void - SetVisibility(int theVisibility) - { - for(int i = 0; i < myNbCones; ++i) - myActors[i]->SetVisibility(theVisibility); - } +//============================================================================ +vtkStandardNewMacro(VISU_GaussPtsAct); - void - Init(float theHeight, - float theRadius, - float thePos[3], - float theColor[3]) - { - for(int i = 0; i < myNbCones; ++i){ - mySources[i]->SetHeight(theHeight); - // Set the angle of the cone. As a side effect, the angle plus height sets - // the base radius of the cone. - mySources[i]->SetAngle(20.0); - - myActors[i]->SetPosition(thePos[0],thePos[1],thePos[2]); - myActors[i]->GetProperty()->SetColor(theColor); - } - - float aD = -0.5*theHeight - theRadius; - - // X - mySources[0]->SetCenter(aD, 0.,0.); - mySources[1]->SetCenter(aD, 0.,0.); - - // Y - mySources[2]->SetDirection(0., 1., 0.); - mySources[2]->SetCenter(0, aD, 0.); - - mySources[3]->SetDirection(0., 1., 0.); - mySources[3]->SetCenter(0., aD, 0.); - - // Z - mySources[4]->SetDirection(0., 0., 1.); - mySources[4]->SetCenter(0, 0., aD); - - mySources[5]->SetDirection(0., 0., 1.); - mySources[5]->SetCenter(0., 0., aD); - } - -protected: - VISU_CursorPyramid(): - myNbCones(6) - { - for(int i = 0; i < myNbCones; i++){ - vtkConeSource* aConeSource = vtkConeSource::New(); - aConeSource->SetResolution(4); - - vtkPolyDataMapper* aPolyDataMapper = vtkPolyDataMapper::New(); - aPolyDataMapper->SetInput(aConeSource->GetOutput()); - aConeSource->Delete(); - - vtkActor* anActor = vtkActor::New(); - anActor->SetMapper(aPolyDataMapper); - anActor->SetVisibility(0); - anActor->SetPickable(0); - aPolyDataMapper->Delete(); - - mySources[i] = aConeSource; - myMappers[i] = aPolyDataMapper; - myActors[i] = anActor; - anActor->Delete(); - } - - myActors[1]->SetOrientation(0. ,180.,0.); - myActors[3]->SetOrientation(0. , 0. ,180.); - myActors[5]->SetOrientation(180., 0. ,0.); - } - - int myNbCones; - vtkSmartPointer mySources[6]; - vtkSmartPointer myMappers[6]; - vtkSmartPointer myActors[6]; -}; - -vtkStandardNewMacro(VISU_CursorPyramid); - - -//---------------------------------------------------------------- -class VISU_GPTextActor : public vtkTextActor -{ -public: - vtkTypeMacro(VISU_GPTextActor, vtkTextActor); - - static - VISU_GPTextActor* - New(); - - void - Init(const float theWorldPoint[4], - const float theDistance = 10.0) - { - for(int i = 0; i < 4; i++) - myWorldPoint[i] = theWorldPoint[i]; - } - - virtual - int - RenderOpaqueGeometry(vtkViewport *theViewport) - { - float aSelectionPoint[3]; - theViewport->SetWorldPoint(myWorldPoint); - theViewport->WorldToDisplay(); - theViewport->GetDisplayPoint(aSelectionPoint); - - aSelectionPoint[0] += myDistance; - aSelectionPoint[1] += myDistance; - - SetPosition(aSelectionPoint); - Superclass::RenderOpaqueGeometry(theViewport); - } - -protected: - float myWorldPoint[4]; - float myDistance; -}; - -vtkStandardNewMacro(VISU_GPTextActor); - - -//---------------------------------------------------------------- -VISU_GaussPtsAct* -VISU_GaussPtsAct -::New(bool theIsSegmented) -{ - return new VISU_GaussPtsAct(theIsSegmented); -} - -//---------------------------------------------------------------- +//---------------------------------------------------------------------------- VISU_GaussPtsAct -::VISU_GaussPtsAct(bool theIsSegmented): +::VISU_GaussPtsAct(): myEventCallbackCommand(vtkCallbackCommand::New()), - myIsSegmented(theIsSegmented), + myDeviceActor(VISU_GaussPtsDeviceActor::New()), myWidget(NULL), myGaussPointsPL(NULL), + myLastObjPointID(-1), myTextMapper(vtkTextMapper::New()), myTextActor(VISU_GPTextActor::New()), - myLastObjPointID(-1), mySphereSource(vtkSphereSource::New()), mySphereMapper(vtkPolyDataMapper::New()), mySphereActor(vtkActor::New()), - myCursorPyramid(VISU_CursorPyramid::New()) + myCursorPyramid(VISU_CursorPyramid::New()), + mySphereSourceSelected(vtkSphereSource::New()), + mySphereActorSelected(vtkActor::New()), + myCellSource(vtkUnstructuredGrid::New()), + myCellActor(vtkActor::New()) { if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::VISU_GaussPtsAct - this = "<Delete(); + myDeviceActor->Delete(); + + myTextMapper->Delete(); + myTextActor->Delete(); + + mySphereSource->Delete(); + mySphereMapper->Delete(); + mySphereActor->Delete(); + + myCursorPyramid->Delete(); + + mySphereSourceSelected->Delete(); + mySphereActorSelected->Delete(); + + myCellSource->Delete(); + myCellActor->Delete(); myEventCallbackCommand->SetClientData(this); myEventCallbackCommand->SetCallback(VISU_GaussPtsAct::ProcessEvents); - if(!theIsSegmented){ - myDeviceActor = VISU_GaussPtsDeviceActor::New(); - myDeviceActor->SetProperty(GetProperty()); - myDeviceActor->SetVisibility(true); - myDeviceActor->SetPickable(false); - myDeviceActor->Delete(); - - myOutsideDeviceActor = VISU_GaussPtsDeviceActor::New(); - myOutsideDeviceActor->SetProperty(GetProperty()); - myOutsideDeviceActor->SetVisibility(false); - myOutsideDeviceActor->SetPickable(false); - myOutsideDeviceActor->Delete(); - } - myInsideDeviceActor = VISU_GaussPtsDeviceActor::New(); - myInsideDeviceActor->SetProperty(GetProperty()); - myInsideDeviceActor->SetVisibility(theIsSegmented); - myInsideDeviceActor->SetPickable(false); - myInsideDeviceActor->Delete(); - - myTextMapper->Delete(); - myTextActor->Delete(); + myDeviceActor->SetProperty(GetProperty()); + myDeviceActor->SetVisibility(true); + myDeviceActor->SetPickable(false); vtkTextProperty* aTextProperty = myTextMapper->GetTextProperty(); aTextProperty->SetVerticalJustification(VTK_TEXT_BOTTOM); aTextProperty->SetJustification(VTK_TEXT_LEFT); myTextActor->SetMapper(myTextMapper.GetPointer()); - //myTextActor->SetAlignmentPoint(3); myTextActor->SetVisibility(false); myTextActor->SetPickable(false); - mySphereSource->Delete(); - mySphereMapper->Delete(); - mySphereActor->Delete(); - mySphereMapper->SetInput(mySphereSource->GetOutput()); mySphereActor->SetMapper(mySphereMapper.GetPointer()); mySphereActor->SetVisibility(false); mySphereActor->SetPickable(false); - // - myCursorPyramid->Delete(); - // - mySphereSourceSelected = vtkSphereSource::New(); - mySphereSourceSelected->Delete(); - mySphereMapperSelected = vtkPolyDataMapper::New(); - mySphereMapperSelected->Delete(); - mySphereMapperSelected->SetInput(mySphereSourceSelected->GetOutput()); + vtkPolyDataMapper* aSphereMapperSelected = vtkPolyDataMapper::New(); + aSphereMapperSelected->SetInput(mySphereSourceSelected->GetOutput()); - mySphereActorSelected = vtkActor::New(); - mySphereActorSelected->Delete(); - mySphereActorSelected->SetMapper(mySphereMapperSelected.GetPointer()); + mySphereActorSelected->SetMapper(aSphereMapperSelected); + mySphereActorSelected->GetProperty()->SetColor(1.0,1.0,1.0); mySphereActorSelected->SetVisibility(false); mySphereActorSelected->SetPickable(false); - float aColorSelected[3] = {1.,1.,1.}; - mySphereActorSelected->GetProperty()->SetColor(aColorSelected); - // - // Cell - myCellSource = vtkUnstructuredGrid::New(); - myCellSource->Delete(); + myCellSource->Allocate(); - // - myCellMapper = vtkDataSetMapper::New(); - myCellMapper->Delete(); - myCellMapper->SetInput(myCellSource.GetPointer()); - // - myCellActor = vtkActor::New(); - myCellActor->Delete(); - myCellActor->SetMapper(myCellMapper.GetPointer()); + vtkDataSetMapper* aCellMapper = vtkDataSetMapper::New(); + aCellMapper->SetInput(myCellSource.GetPointer()); + myCellActor->SetMapper(aCellMapper); myCellActor->SetVisibility(0); myCellActor->SetPickable(0); myCellActor->GetProperty()->SetAmbient(1.0); @@ -342,15 +164,22 @@ VISU_GaussPtsAct if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::~VISU_GaussPtsAct - this = "<GetPSMapper(); - else - return myInsideDeviceActor->GetPSMapper(); + myGaussPointsPL = dynamic_cast(thePipeLine); + + Superclass::SetPipeLine(thePipeLine); +} + +VISU_GaussPointsPL* +VISU_GaussPtsAct +::GetGaussPointsPL() +{ + return myGaussPointsPL.GetPointer(); } void @@ -359,53 +188,42 @@ VISU_GaussPtsAct { Superclass::ShallowCopyPL(thePipeLine); - vtkPolyData* aDatsSet = GetPSMapper()->GetInput(); - GetPSMapper()->ShallowCopy(thePipeLine->GetMapper()); + VISU_GaussPointsPL* aPipeLine = dynamic_cast(thePipeLine); + myDeviceActor->ShallowCopyPL(aPipeLine); +} - // To restore mapper input from pipeline - GetPSMapper()->SetInput(aDatsSet); - if(VISU_GaussPointsPL* aPipeLine = dynamic_cast(thePipeLine)){ - if(!myIsSegmented){ - myDeviceActor->ShallowCopyPL(aPipeLine); - myOutsideDeviceActor->ShallowCopyPL(aPipeLine); - } - myInsideDeviceActor->ShallowCopyPL(aPipeLine); - - // Restore implicit function - if(myWidget){ - vtkImplicitFunction* aFunction = myWidget->ImplicitFunction(); - if(!myIsSegmented){ - myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(aFunction); - myOutsideDeviceActor->GetPipeLine()->SetExtractInside(true); - myOutsideDeviceActor->GetMapper()->ScalarVisibilityOff(); - } - myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(aFunction); - } - } +//---------------------------------------------------------------------------- +VISU_OpenGLPointSpriteMapper* +VISU_GaussPtsAct +::GetPSMapper() +{ + return myDeviceActor->GetPSMapper(); } vtkDataSet* VISU_GaussPtsAct ::GetInput() { - vtkDataSet* aDataSet = GetMapper()->GetInput(); - aDataSet->Update(); - return aDataSet; + return GetMapper()->GetInput(); } -//---------------------------------------------------------------- +vtkMapper* +VISU_GaussPtsAct +::GetMapper() +{ + return GetPSMapper(); +} + + +//---------------------------------------------------------------------------- void VISU_GaussPtsAct ::AddToRender(vtkRenderer* theRenderer) { Superclass::AddToRender(theRenderer); - if(!myIsSegmented){ - myDeviceActor->AddToRender(theRenderer); - myOutsideDeviceActor->AddToRender(theRenderer); - } - myInsideDeviceActor->AddToRender(theRenderer); + myDeviceActor->AddToRender(theRenderer); theRenderer->AddActor(myTextActor.GetPointer()); theRenderer->AddActor(mySphereActor.GetPointer()); @@ -421,11 +239,7 @@ VISU_GaussPtsAct { Superclass::RemoveFromRender(theRenderer); - if(!myIsSegmented){ - myDeviceActor->RemoveFromRender(theRenderer); - myOutsideDeviceActor->RemoveFromRender(theRenderer); - } - myInsideDeviceActor->RemoveFromRender(theRenderer); + myDeviceActor->RemoveFromRender(theRenderer); theRenderer->RemoveActor(mySphereActor.GetPointer()); theRenderer->RemoveActor(myTextActor.GetPointer()); @@ -439,14 +253,9 @@ void VISU_GaussPtsAct ::SetTransform(VTKViewer_Transform* theTransform) { - if(!myIsSegmented){ - myDeviceActor->SetTransform(theTransform); - myOutsideDeviceActor->SetTransform(theTransform); - } - myInsideDeviceActor->SetTransform(theTransform); - Superclass::SetTransform(theTransform); - Modified(); + + myDeviceActor->SetTransform(theTransform); } int @@ -464,7 +273,7 @@ VISU_GaussPtsAct } -//---------------------------------------------------------------- +//---------------------------------------------------------------------------- void VISU_GaussPtsAct ::SetImplicitFunctionWidget(VISU_ImplicitFunctionWidget* theWidget) @@ -476,18 +285,17 @@ VISU_GaussPtsAct theWidget->AddObserver(vtkCommand::DisableEvent, myEventCallbackCommand.GetPointer(), 0.0); - if(!myIsSegmented) - myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidget->ImplicitFunction()); - myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidget->ImplicitFunction()); - - if(myWidget->IsEnabled()) - OnInteractorEvent(vtkCommand::EnableEvent); - else - OnInteractorEvent(vtkCommand::DisableEvent); +} + +bool +VISU_GaussPtsAct +::ChangeMagnification() +{ + return myChangeMagnification; } -//---------------------------------------------------------------- +//---------------------------------------------------------------------------- namespace { VISU_GaussPointsPL* @@ -504,46 +312,8 @@ void VISU_GaussPtsAct ::SetMapperInput(vtkDataSet* theDataSet) { - if(vtkPolyData* aPolyData = dynamic_cast(theDataSet)){ - if(!myIsSegmented){ - myDeviceActor->SetPipeLine(GetGaussPointsPL()); - if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){ - myInsideDeviceActor->SetPipeLine(aPipeLine); - aPipeLine->Delete(); - } - if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){ - myOutsideDeviceActor->SetPipeLine(aPipeLine); - myOutsideDeviceActor->GetMapper()->ScalarVisibilityOff(); - myOutsideDeviceActor->GetPipeLine()->SetExtractInside(true); - aPipeLine->Delete(); - } - }else - myInsideDeviceActor->SetPipeLine(GetGaussPointsPL()); - vtkLODActor::SetMapper(GetMapper()); - } -} - -vtkMapper* -VISU_GaussPtsAct -::GetMapper() -{ - return GetPSMapper(); -} - -void -VISU_GaussPtsAct -::SetPipeLine(VISU_PipeLine* thePipeLine) -{ - myGaussPointsPL = dynamic_cast(thePipeLine); - - Superclass::SetPipeLine(thePipeLine); -} - -VISU_GaussPointsPL* -VISU_GaussPtsAct -::GetGaussPointsPL() -{ - return myGaussPointsPL.GetPointer(); + myDeviceActor->SetPipeLine(GetGaussPointsPL()); + vtkLODActor::SetMapper(GetMapper()); } void @@ -551,13 +321,11 @@ VISU_GaussPtsAct ::SetFactory(VISU::TActorFactory* theActorFactory) { using namespace VISU; - if(TGaussPtsActorFactory* aFactory = dynamic_cast(theActorFactory)){ - myUpdatePrs3dSignal.connect(boost::bind(&TGaussPtsActorFactory::UpdateFromActor, - aFactory, - _1)); - VISU_Actor::SetFactory(theActorFactory); - myGaussPtsActorFactory = aFactory; - } + myGaussPtsActorFactory = dynamic_cast(theActorFactory); + myUpdatePrs3dSignal.connect(boost::bind(&TGaussPtsActorFactory::UpdateFromActor, + myGaussPtsActorFactory, + _1)); + Superclass::SetFactory(theActorFactory); } VISU::TGaussPtsActorFactory* @@ -567,36 +335,13 @@ VISU_GaussPtsAct return myGaussPtsActorFactory; } -void -VISU_GaussPtsAct -::Connect(VISU_GaussPtsAct* theActor) -{ - mySetVisibilitySignal.connect(boost::bind(&VISU_GaussPtsAct::SetVisibility,theActor,_1)); -} - void VISU_GaussPtsAct ::SetVisibility(int theMode) { Superclass::SetVisibility(theMode); - - if(!myIsSegmented){ - myDeviceActor->SetVisibility(GetVisibility() && !myWidget->IsEnabled()); - myOutsideDeviceActor->SetVisibility(GetVisibility() && myWidget->IsEnabled()); - } - myInsideDeviceActor->SetVisibility(GetVisibility() && myWidget->IsEnabled()); - - mySetVisibilitySignal(GetVisibility()); -} - -bool -VISU_GaussPtsAct -::ChangeMagnification() -{ - return myChangeMagnification; } - //---------------------------------------------------------------------------- void VISU_GaussPtsAct @@ -651,23 +396,13 @@ VISU_GaussPtsAct myUpdatePrs3dSignal(this); break; } - case vtkCommand::EnableEvent: - case vtkCommand::DisableEvent: - if(!myIsSegmented){ - myDeviceActor->SetVisibility(GetVisibility() && !myWidget->IsEnabled()); - myOutsideDeviceActor->SetVisibility(GetVisibility() && myWidget->IsEnabled()); - myOutsideDeviceActor->GetPipeLine()->SetExtractInside(true); - myOutsideDeviceActor->GetMapper()->ScalarVisibilityOff(); - } - myInsideDeviceActor->SetVisibility(GetVisibility() && myWidget->IsEnabled()); - break; default: break; } } -//---------------------------------------------------------------- +//---------------------------------------------------------------------------- bool VISU_GaussPtsAct ::PreHighlight(SVTK_Selector* theSelector, @@ -713,7 +448,7 @@ VISU_GaussPtsAct // To calculate display (2D) position of the annotation float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.0}; - myTextActor->Init(aWorldCoord); + myTextActor->Init(aWorldCoord,10.0); // To prepare the annotation text std::ostringstream aStr; aStr<<"Global ID: "<Init(aWorldCoord); + myTextActor->Init(aWorldCoord,10); // // Selected mySphereSourceSelected->SetCenter(aNodeCoord); @@ -1002,3 +734,242 @@ VISU_GaussPtsAct //mySphereActor->SetVisibility(aSphereVisibility); return bRet; } + + + +//============================================================================== +vtkStandardNewMacro(VISU_GaussPtsAct1); + + +//---------------------------------------------------------------------------- +VISU_GaussPtsAct1 +::VISU_GaussPtsAct1(): + myInsideDeviceActor(VISU_GaussPtsDeviceActor::New()), + myOutsideDeviceActor(VISU_GaussPtsDeviceActor::New()) +{ + if(MYDEBUG) MESSAGE("VISU_GaussPtsAct1::VISU_GaussPtsAct1 - this = "<SetProperty(GetProperty()); + myInsideDeviceActor->SetVisibility(false); + myInsideDeviceActor->SetPickable(false); + myInsideDeviceActor->Delete(); + + myOutsideDeviceActor->SetProperty(GetProperty()); + myOutsideDeviceActor->SetVisibility(false); + myOutsideDeviceActor->SetPickable(false); + myOutsideDeviceActor->Delete(); +} + +VISU_GaussPtsAct1 +::~VISU_GaussPtsAct1() +{ + if(MYDEBUG) MESSAGE("VISU_GaussPtsAct1::~VISU_GaussPtsAct1 - this = "<(thePipeLine); + myInsideDeviceActor->ShallowCopyPL(aPipeLine); + myOutsideDeviceActor->ShallowCopyPL(aPipeLine); + // Restore implicit function + if(myWidget){ + vtkImplicitFunction* aFunction = myWidget->ImplicitFunction(); + + myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(aFunction); + + myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(aFunction); + myOutsideDeviceActor->GetPipeLine()->SetExtractInside(true); + myOutsideDeviceActor->GetMapper()->ScalarVisibilityOff(); + } +} + +//---------------------------------------------------------------------------- +void +VISU_GaussPtsAct1 +::AddToRender(vtkRenderer* theRenderer) +{ + Superclass::AddToRender(theRenderer); + + myInsideDeviceActor->AddToRender(theRenderer); + myOutsideDeviceActor->AddToRender(theRenderer); +} + +void +VISU_GaussPtsAct1 +::RemoveFromRender(vtkRenderer* theRenderer) +{ + Superclass::RemoveFromRender(theRenderer); + + myInsideDeviceActor->RemoveFromRender(theRenderer); + myOutsideDeviceActor->RemoveFromRender(theRenderer); +} + +void +VISU_GaussPtsAct1 +::SetTransform(VTKViewer_Transform* theTransform) +{ + Superclass::SetTransform(theTransform); + + myInsideDeviceActor->SetTransform(theTransform); + myOutsideDeviceActor->SetTransform(theTransform); +} + + +//---------------------------------------------------------------------------- +void +VISU_GaussPtsAct1 +::SetImplicitFunctionWidget(VISU_ImplicitFunctionWidget* theWidget) +{ + Superclass::SetImplicitFunctionWidget(theWidget); + + myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidget->ImplicitFunction()); + myInsideDeviceActor->SetVisibility(GetVisibility() && theWidget->IsEnabled()); + + myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidget->ImplicitFunction()); + myOutsideDeviceActor->SetVisibility(GetVisibility() && theWidget->IsEnabled()); +} + + +//---------------------------------------------------------------------------- +void +VISU_GaussPtsAct1 +::SetMapperInput(vtkDataSet* theDataSet) +{ + Superclass::SetMapperInput(theDataSet); + + if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){ + myInsideDeviceActor->SetPipeLine(aPipeLine); + } + if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){ + myOutsideDeviceActor->SetPipeLine(aPipeLine); + myOutsideDeviceActor->GetMapper()->ScalarVisibilityOff(); + myOutsideDeviceActor->GetPipeLine()->SetExtractInside(true); + } +} + +void +VISU_GaussPtsAct1 +::Connect(VISU_GaussPtsAct2* theActor) +{ + mySetVisibilitySignal.connect(boost::bind(&VISU_GaussPtsAct2::SetVisibility,theActor,_1)); +} + +void +VISU_GaussPtsAct1 +::SetVisibility(int theMode) +{ + Superclass::SetVisibility(theMode); + + myDeviceActor->SetVisibility(GetVisibility() && !myWidget->IsEnabled()); + + myInsideDeviceActor->SetVisibility(GetVisibility() && myWidget->IsEnabled()); + myOutsideDeviceActor->SetVisibility(GetVisibility() && myWidget->IsEnabled()); + + mySetVisibilitySignal(GetVisibility()); +} + + +void +VISU_GaussPtsAct1 +::OnInteractorEvent(unsigned long theEvent) +{ + switch(theEvent){ + case vtkCommand::EnableEvent: + case vtkCommand::DisableEvent: + myDeviceActor->SetVisibility(GetVisibility() && !myWidget->IsEnabled()); + myInsideDeviceActor->SetVisibility(GetVisibility() && myWidget->IsEnabled()); + myOutsideDeviceActor->SetVisibility(GetVisibility() && myWidget->IsEnabled()); + break; + default: + break; + } + Superclass::OnInteractorEvent(theEvent); +} + + +//============================================================================== +vtkStandardNewMacro(VISU_GaussPtsAct2); + + +//---------------------------------------------------------------------------- +VISU_GaussPtsAct2 +::VISU_GaussPtsAct2() +{ + if(MYDEBUG) MESSAGE("VISU_GaussPtsAct2::VISU_GaussPtsAct2 - this = "<GetPSMapper()->GetInput()); } + + +//============================================================================ +#include +#include +#include +#include + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(VISU_CursorPyramid); + + +//---------------------------------------------------------------------------- +void +VISU_CursorPyramid +::AddToRender(vtkRenderer* theRenderer) +{ + for(int i = 0; i < myNbCones; ++i) + theRenderer->AddActor(myActors[i].GetPointer()); +} + +void +VISU_CursorPyramid +::RemoveFromRender(vtkRenderer* theRenderer) +{ + for(int i = 0; i < myNbCones; ++i) + theRenderer->RemoveActor(myActors[i].GetPointer()); +} + +void +VISU_CursorPyramid +::SetVisibility(int theVisibility) +{ + for(int i = 0; i < myNbCones; ++i) + myActors[i]->SetVisibility(theVisibility); +} + +//---------------------------------------------------------------------------- +void +VISU_CursorPyramid +::Init(float theHeight, + float theRadius, + float thePos[3], + float theColor[3]) +{ + for(int i = 0; i < myNbCones; ++i){ + mySources[i]->SetHeight(theHeight); + // Set the angle of the cone. As a side effect, the angle plus height sets + // the base radius of the cone. + mySources[i]->SetAngle(20.0); + + myActors[i]->SetPosition(thePos[0],thePos[1],thePos[2]); + myActors[i]->GetProperty()->SetColor(theColor); + } + + float aD = -0.5*theHeight - theRadius; + + // X + mySources[0]->SetCenter(aD, 0.,0.); + mySources[1]->SetCenter(aD, 0.,0.); + + // Y + mySources[2]->SetDirection(0., 1., 0.); + mySources[2]->SetCenter(0, aD, 0.); + + mySources[3]->SetDirection(0., 1., 0.); + mySources[3]->SetCenter(0., aD, 0.); + + // Z + mySources[4]->SetDirection(0., 0., 1.); + mySources[4]->SetCenter(0, 0., aD); + + mySources[5]->SetDirection(0., 0., 1.); + mySources[5]->SetCenter(0., 0., aD); +} + +//---------------------------------------------------------------------------- +VISU_CursorPyramid +::VISU_CursorPyramid(): + myNbCones(6) +{ + for(int i = 0; i < myNbCones; i++){ + vtkConeSource* aConeSource = vtkConeSource::New(); + aConeSource->SetResolution(4); + + vtkPolyDataMapper* aPolyDataMapper = vtkPolyDataMapper::New(); + aPolyDataMapper->SetInput(aConeSource->GetOutput()); + aConeSource->Delete(); + + vtkActor* anActor = vtkActor::New(); + anActor->SetMapper(aPolyDataMapper); + anActor->SetVisibility(0); + anActor->SetPickable(0); + aPolyDataMapper->Delete(); + + mySources[i] = aConeSource; + myMappers[i] = aPolyDataMapper; + myActors[i] = anActor; + anActor->Delete(); + } + + myActors[1]->SetOrientation(0. ,180.,0.); + myActors[3]->SetOrientation(0. , 0. ,180.); + myActors[5]->SetOrientation(180., 0. ,0.); +} + + +//============================================================================ +vtkStandardNewMacro(VISU_GPTextActor); + +//---------------------------------------------------------------------------- +void +VISU_GPTextActor +::Init(const float theWorldPoint[4], + const float theDistance) +{ + for(int i = 0; i < 4; i++) + myWorldPoint[i] = theWorldPoint[i]; +} + +int +VISU_GPTextActor +::RenderOpaqueGeometry(vtkViewport *theViewport) +{ + float aSelectionPoint[3]; + theViewport->SetWorldPoint(myWorldPoint); + theViewport->WorldToDisplay(); + theViewport->GetDisplayPoint(aSelectionPoint); + + aSelectionPoint[0] += myDistance; + aSelectionPoint[1] += myDistance; + + SetPosition(aSelectionPoint); + Superclass::RenderOpaqueGeometry(theViewport); +} + diff --git a/src/OBJECT/VISU_GaussPtsDeviceActor.h b/src/OBJECT/VISU_GaussPtsDeviceActor.h index c26b6fb8..bfc657de 100644 --- a/src/OBJECT/VISU_GaussPtsDeviceActor.h +++ b/src/OBJECT/VISU_GaussPtsDeviceActor.h @@ -42,7 +42,7 @@ class VISU_OpenGLPointSpriteMapper; class VISU_GaussPointsPL; -//---------------------------------------------------------------------------- +//============================================================================ class VISU_GaussPtsDeviceActor: public vtkLODActor { public: @@ -97,4 +97,72 @@ class VISU_GaussPtsDeviceActor: public vtkLODActor }; +//============================================================================ +class vtkActor; +class vtkConeSource; +class vtkPolyDataMapper; + +#include + +class VISU_CursorPyramid : public vtkObject +{ +public: + vtkTypeMacro(VISU_CursorPyramid, vtkObject); + + static + VISU_CursorPyramid* + New(); + + void + AddToRender(vtkRenderer* theRenderer); + + void + RemoveFromRender(vtkRenderer* theRenderer); + + void + SetVisibility(int theVisibility); + + void + Init(float theHeight, + float theRadius, + float thePos[3], + float theColor[3]); + + +protected: + VISU_CursorPyramid(); + + int myNbCones; + vtkSmartPointer mySources[6]; + vtkSmartPointer myMappers[6]; + vtkSmartPointer myActors[6]; +}; + + +//============================================================================ +#include + +class VISU_GPTextActor : public vtkTextActor +{ +public: + vtkTypeMacro(VISU_GPTextActor,vtkTextActor); + + static + VISU_GPTextActor* + New(); + + void + Init(const float theWorldPoint[4], + const float theDistance); + + virtual + int + RenderOpaqueGeometry(vtkViewport *theViewport); + +protected: + float myWorldPoint[4]; + float myDistance; +}; + + #endif //VISU_GAUSS_PTS_DEVICE_ACTOR_H diff --git a/src/VISU_I/VISU_GaussPoints_i.cc b/src/VISU_I/VISU_GaussPoints_i.cc index aad5a8bc..95b6f5f8 100644 --- a/src/VISU_I/VISU_GaussPoints_i.cc +++ b/src/VISU_I/VISU_GaussPoints_i.cc @@ -276,38 +276,58 @@ VISU::GaussPoints_i //---------------------------------------------------------------------------- -VISU_GaussPtsAct* +bool VISU::GaussPoints_i -::OnCreateActor(bool theIsSegmented, +::OnCreateActor(VISU_GaussPtsAct* theActor, const Handle(SALOME_InteractiveObject)& theIO) { - VISU_GaussPtsAct* anActor = VISU_GaussPtsAct::New(theIsSegmented); try{ - VISU::Prs3d_i::CreateActor(anActor,theIO); - anActor->GetPipeLine()->Delete(); - anActor->SetRepresentation(VTK_POINTS); - UpdateActor(anActor); + VISU::Prs3d_i::CreateActor(theActor,theIO); + theActor->GetPipeLine()->Delete(); + theActor->SetRepresentation(VTK_POINTS); + UpdateActor(theActor); + return true; }catch(...){ - anActor->Delete(); + theActor->Delete(); throw ; } - return anActor; + return false; +} + +VISU_GaussPtsAct1* +VISU::GaussPoints_i +::OnCreateActor1(const Handle(SALOME_InteractiveObject)& theIO) +{ + VISU_GaussPtsAct1* anActor = VISU_GaussPtsAct1::New(); + if(OnCreateActor(anActor,theIO)) + return anActor; + return NULL; +} + +VISU_GaussPtsAct2* +VISU::GaussPoints_i +::OnCreateActor2(const Handle(SALOME_InteractiveObject)& theIO) +{ + VISU_GaussPtsAct2* anActor = VISU_GaussPtsAct2::New(); + if(OnCreateActor(anActor,theIO)) + return anActor; + return NULL; } VISU_Actor* VISU::GaussPoints_i ::CreateActor(const Handle(SALOME_InteractiveObject)& theIO) { - return OnCreateActor(false,theIO); + return OnCreateActor1(theIO); } //---------------------------------------------------------------------------- -VISU_GaussPtsAct* +VISU_GaussPtsAct2* VISU::GaussPoints_i -::CloneActor(VISU_GaussPtsAct* theActor) +::CloneActor(VISU_GaussPtsAct1* theActor) { if(MYDEBUG) MESSAGE("GaussPoints_i::CloneActor - this = "<Connect(anActor); return anActor; } diff --git a/src/VISU_I/VISU_GaussPoints_i.hh b/src/VISU_I/VISU_GaussPoints_i.hh index b0daf2b5..a0b0a47e 100644 --- a/src/VISU_I/VISU_GaussPoints_i.hh +++ b/src/VISU_I/VISU_GaussPoints_i.hh @@ -105,11 +105,18 @@ namespace VISU virtual VISU_PipeLine* GetPipeLine(); - - VISU_GaussPtsAct* - OnCreateActor(bool theIsSegmented, + + bool + OnCreateActor(VISU_GaussPtsAct* theActor, const Handle(SALOME_InteractiveObject)& theIO = NULL); + VISU_GaussPtsAct1* + OnCreateActor1(const Handle(SALOME_InteractiveObject)& theIO = NULL); + + VISU_GaussPtsAct2* + OnCreateActor2(const Handle(SALOME_InteractiveObject)& theIO = NULL); + + VISU_GaussPointsPL *myGaussPointsPL; bool myIsColored; @@ -158,8 +165,8 @@ namespace VISU CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL); virtual - VISU_GaussPtsAct* - CloneActor(VISU_GaussPtsAct* theActor); + VISU_GaussPtsAct2* + CloneActor(VISU_GaussPtsAct1* theActor); virtual void diff --git a/src/VVTK/VVTK_Renderer.cxx b/src/VVTK/VVTK_Renderer.cxx index 625e2fbe..82a8396e 100644 --- a/src/VVTK/VVTK_Renderer.cxx +++ b/src/VVTK/VVTK_Renderer.cxx @@ -153,7 +153,7 @@ VVTK_Renderer1 pTextProperty->SetJustificationToRight(); pTextProperty->SetVerticalJustificationToTop(); pTextProperty->SetFontSize(10); - pTextProperty->SetOpacity (0.75); + //pTextProperty->SetOpacity (0.75); // myTextActor->SetMapper(myTextMapper.GetPointer()); myTextActor->SetPickable(false); @@ -177,7 +177,7 @@ void VVTK_Renderer1 ::AddActor(VTKViewer_Actor* theActor) { - if(VISU_GaussPtsAct* anActor = dynamic_cast(theActor)){ + if(VISU_GaussPtsAct1* anActor = dynamic_cast(theActor)){ anActor->SetImplicitFunctionWidget(GetImplicitFunctionWidget()); SVTK_Renderer::AddActor(anActor); } @@ -189,7 +189,8 @@ VVTK_Renderer1 ::RemoveActor(VTKViewer_Actor* theActor) { using namespace VISU; - if(VISU_GaussPtsAct* anActor = dynamic_cast(theActor)){ + if(VISU_GaussPtsAct1* anActor = dynamic_cast(theActor)){ + anActor->SetImplicitFunctionWidget(NULL); SVTK_Renderer::RemoveActor(theActor); } } @@ -296,9 +297,9 @@ void VVTK_Renderer2 ::AddActor(VTKViewer_Actor* theActor) { - if(VISU_GaussPtsAct* anActor = dynamic_cast(theActor)){ + if(VISU_GaussPtsAct1* anActor = dynamic_cast(theActor)){ if(VISU::TGaussPtsActorFactory* aFactory = anActor->GetGaussPtsFactory()){ - if(VISU_GaussPtsAct* anActor2 = aFactory->CloneActor(anActor)){ + if(VISU_GaussPtsAct2* anActor2 = aFactory->CloneActor(anActor)){ anActor2->SetImplicitFunctionWidget(myWidget); SVTK_Renderer::AddActor(anActor2); } @@ -312,7 +313,8 @@ VVTK_Renderer2 ::RemoveActor(VTKViewer_Actor* theActor) { using namespace VISU; - if(VISU_GaussPtsAct* anActor = dynamic_cast(theActor)){ + if(VISU_GaussPtsAct2* anActor = dynamic_cast(theActor)){ + anActor->SetImplicitFunctionWidget(NULL); SVTK_Renderer::RemoveActor(theActor); } }