From ca855cf0c75723ed15055c13b673ffcac9f19eed Mon Sep 17 00:00:00 2001 From: pkv Date: Wed, 9 Nov 2005 14:20:58 +0000 Subject: [PATCH] Implementation spherical cursor. Implementation avi recorder --- src/OBJECT/VISU_GaussPtsAct.cxx | 116 +- src/OBJECT/VISU_GaussPtsAct.h | 16 +- src/PIPELINE/Makefile.in | 10 +- src/PIPELINE/VISUPipeLine.cxx | 188 +- src/PIPELINE/VISU_ImplicitFunctionWidget.cxx | 1607 +--------------- src/PIPELINE/VISU_ImplicitFunctionWidget.hxx | 79 + src/PIPELINE/VISU_PlanesWidget.cxx | 1614 +++++++++++++++++ ...FunctionWidget.h => VISU_PlanesWidget.hxx} | 29 +- src/PIPELINE/VISU_SphereWidget.cxx | 718 ++++++++ src/PIPELINE/VISU_SphereWidget.hxx | 129 ++ src/PIPELINE/VISU_WidgetCtrl.cxx | 350 ++++ src/PIPELINE/VISU_WidgetCtrl.hxx | 110 ++ src/VISUGUI/VisuGUI_Module.cxx | 39 +- src/VVTK/Makefile.in | 13 +- src/VVTK/VVTK_ImageWriter.cxx | 187 ++ src/VVTK/VVTK_ImageWriter.h | 71 + src/VVTK/VVTK_ImageWriterMgr.cxx | 175 ++ src/VVTK/VVTK_ImageWriterMgr.h | 62 + src/VVTK/VVTK_MainWindow.cxx | 86 +- src/VVTK/VVTK_MainWindow.h | 14 +- src/VVTK/VVTK_Recorder.cxx | 362 ++++ src/VVTK/VVTK_Recorder.h | 107 ++ src/VVTK/VVTK_Renderer.cxx | 100 +- src/VVTK/VVTK_Renderer.h | 14 +- src/VVTK/VVTK_SegmentationCursorDlg.cxx | 61 +- src/VVTK/VVTK_SegmentationCursorDlg.h | 9 +- src/VVTK/VVTK_ViewWindow.cxx | 14 +- 27 files changed, 4297 insertions(+), 1983 deletions(-) create mode 100644 src/PIPELINE/VISU_ImplicitFunctionWidget.hxx create mode 100644 src/PIPELINE/VISU_PlanesWidget.cxx rename src/PIPELINE/{VISU_ImplicitFunctionWidget.h => VISU_PlanesWidget.hxx} (93%) create mode 100755 src/PIPELINE/VISU_SphereWidget.cxx create mode 100755 src/PIPELINE/VISU_SphereWidget.hxx create mode 100644 src/PIPELINE/VISU_WidgetCtrl.cxx create mode 100644 src/PIPELINE/VISU_WidgetCtrl.hxx create mode 100755 src/VVTK/VVTK_ImageWriter.cxx create mode 100755 src/VVTK/VVTK_ImageWriter.h create mode 100755 src/VVTK/VVTK_ImageWriterMgr.cxx create mode 100755 src/VVTK/VVTK_ImageWriterMgr.h create mode 100755 src/VVTK/VVTK_Recorder.cxx create mode 100755 src/VVTK/VVTK_Recorder.h diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index eecbf2e2..b1714888 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -30,7 +30,7 @@ #include "VISU_GaussPointsPL.hxx" #include "VISU_GaussPtsSettings.h" #include "VISU_GaussPtsDeviceActor.h" -#include "VISU_ImplicitFunctionWidget.h" +#include "VISU_WidgetCtrl.hxx" #include "VISU_OpenGLPointSpriteMapper.hxx" #include "VISU_ScalarBarCtrl.hxx" #include "VISU_ScalarBarActor.hxx" @@ -94,7 +94,7 @@ VISU_GaussPtsAct myEventCallbackCommand(vtkCallbackCommand::New()), myPriority(0.0), myDeviceActor(VISU_GaussPtsDeviceActor::New()), - myWidget(NULL), + myWidgetCtrl(NULL), myGaussPointsPL(NULL), myLastObjPointID(-1), myTextActor(VISU_FramedTextActor::New()), @@ -153,7 +153,7 @@ VISU_GaussPtsAct ::~VISU_GaussPtsAct() { if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::~VISU_GaussPtsAct - this = "< -#include - -#include -#include -#include -#include -#include - -#include - -#include "utilities.h" - -using namespace std; - -static int isOnlyMesh = false; - -int main(int argc, char** argv){ - try{ - if(argc > 1){ - vtkRenderWindow *renWin = vtkRenderWindow::New(); - vtkRenderer *ren = vtkRenderer::New(); - renWin->AddRenderer(ren); - ren->GetActiveCamera()->ParallelProjectionOn(); - vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); - iren->SetRenderWindow(renWin); - VISU_Convertor* aConvertor = CreateConvertor(argv[1]); - const VISU::TMeshMap& aMeshMap = aConvertor->GetMeshMap(); - VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); - if(aMeshMapIter == aMeshMap.end()) return 0; - const string& aMeshName = aMeshMapIter->first; - const VISU::PMesh aMesh = aMeshMapIter->second; - const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; - VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter; - if(isOnlyMesh){ - const VISU::TEntity& anEntity = VISU::CELL_ENTITY; - aMeshOnEntityMapIter = aMeshOnEntityMap.find(anEntity); - - VISU::PIDMapper anIDMapper = - aConvertor->GetMeshOnEntity(aMeshName,anEntity); - VISU::TVTKOutput* aDataSet = anIDMapper->GetVTKOutput(); - - VISU_MeshPL* aPresent = VISU_MeshPL::New(); - aPresent->SetInput(aDataSet); - aPresent->Build(); - - vtkActor* aActor = vtkActor::New(); - aActor->SetMapper(aPresent->GetMapper()); - aActor->GetProperty()->SetRepresentation(VTK_WIREFRAME); - //ren->ResetCameraClippingRange(); - - ren->AddActor(aActor); - - renWin->Render(); - iren->Start(); - return 0; - } - //Import fields - aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); - for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) { - const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first; - const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second; - const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap; - VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin(); - for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){ - const VISU::PField aField = aFieldMapIter->second; - /* - if(aField->myNbComp == 1) - continue; - */ - const string& aFieldName = aFieldMapIter->first; - const VISU::TValField& aValField = aField->myValField; - VISU::TValField::const_iterator aValFieldIter = aValField.begin(); - if(aValFieldIter == aValField.end()) return 0; - int aTimeStamp = aValFieldIter->first; - - VISU::PIDMapper anIDMapper; - if(anEntity != VISU::NODE_ENTITY){ - anIDMapper = aConvertor->GetTimeStampOnGaussPts(aMeshName,anEntity,aFieldName,aTimeStamp); - }else{ - continue; - anIDMapper = aConvertor->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp); - } - VISU::TVTKOutput* aDataSet = anIDMapper->GetVTKOutput(); - - TPresent* aPresent = TPresent::New(); - aPresent->SetInput(aDataSet); - aPresent->Build(); - aPresent->Init(); - aPresent->SetSourceRange(); - vtkDataSet* anOutput = aPresent->GetMapper()->GetInput(); - //for(int i = 0, iEnd = anOutput->GetNumberOfCells(); i < iEnd; i++){ - // cout<GetPointSize(i)<SetNumberOfContours(50); - //aPresent->SetNbParts(1); - //aPresent->SetOrientation(VISU_CutPlanesPL::XY,0.0,0.0); - //aPresent->SetScaling(VTK_SCALE_LOG10); - - char aMainTexture[80]; - strcpy( aMainTexture, getenv( "VISU_ROOT_DIR" ) ); - strcat( aMainTexture, "/share/salome/resources/sprite_texture.vti" ); - //cout << aMainTexture << endl; - - char anAlphaTexture[80]; - strcpy( anAlphaTexture, getenv( "VISU_ROOT_DIR" ) ); - strcat( anAlphaTexture, "/share/salome/resources/sprite_alpha.vti" ); - //cout << anAlphaTexture << endl; - - aPresent->SetImageData( VISU_GaussPointsPL::MakeTexture( aMainTexture, anAlphaTexture ) ); - - aPresent->Update(); - - vtkActor* anActor = vtkActor::New(); - anActor->SetMapper(aPresent->GetMapper()); - - VISU_ScalarBarActor * aScalarBar = VISU_ScalarBarActor::New(); - aScalarBar->SetLookupTable(aPresent->GetBarTable()); - - aPresent->Build(); - - ren->AddActor(anActor); - ren->AddActor2D(aScalarBar); - - renWin->Render(); - ren->ResetCamera(); - - iren->Start(); - return 0; - } - } - } - }catch(std::exception& exc){ - MESSAGE("Follow exception was occured :\n"< +// +//==================================================================== +// function: main +// purpose: +//==================================================================== +int main( int argc, char *argv[] ) +{ + return 0; } diff --git a/src/PIPELINE/VISU_ImplicitFunctionWidget.cxx b/src/PIPELINE/VISU_ImplicitFunctionWidget.cxx index 844371c9..3a3c21a8 100644 --- a/src/PIPELINE/VISU_ImplicitFunctionWidget.cxx +++ b/src/PIPELINE/VISU_ImplicitFunctionWidget.cxx @@ -26,67 +26,17 @@ // Module : SALOME // $Header$ -#include "VISU_ImplicitFunctionWidget.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//// +#include "VISU_ImplicitFunctionWidget.hxx" +// #include #include #include #include -//// -//================================================================== -// class : VISU_UnScaledActor -// purpose : -//================================================================== -class VISU_UnScaledActor: public vtkFollower -{ - -public: - - vtkTypeMacro(VISU_UnScaledActor,vtkFollower); - static VISU_UnScaledActor *New(); - - - void SetCenter(float *); - virtual void SetSize(int theSize); - virtual void Render(vtkRenderer *theRenderer); - virtual float *GetBounds(); - -protected: - VISU_UnScaledActor(); - ~VISU_UnScaledActor(){} - - float myCenter[3]; - int mySize; -}; - -//// - +#include +#include +#include +#include +// vtkStandardNewMacro(VISU_UnScaledActor); //==================================================================== @@ -163,181 +113,19 @@ void VISU_UnScaledActor::SetSize(int theSize) { mySize = theSize; } -//// -static float DistanceToPlane(const float x[3], - const float n[3], - const float p0[3]); - -static void GetBndPoints(vtkDataSet *pDataSet, - float aPnts[24]); - -static - bool IsValidPlane2Position(vtkPlane *pPx, - vtkDataSet *pDataSet, - float aTol=0.003); +//================================================================== +// class: VISU_ImplicitFunctionWidget +// vtkCxxRevisionMacro(VISU_ImplicitFunctionWidget, "$Revision$"); -vtkStandardNewMacro(VISU_ImplicitFunctionWidget); - //================================================================== // function: VISU_ImplicitFunctionWidget // purpose : //================================================================== VISU_ImplicitFunctionWidget::VISU_ImplicitFunctionWidget() : - vtkPolyDataSourceWidget() + vtk3DWidget() { - State = VISU_ImplicitFunctionWidget::Start; - EventCallbackCommand->SetCallback(VISU_ImplicitFunctionWidget::ProcessEvents); - - NormalToXAxis = 0; - NormalToYAxis = 0; - NormalToZAxis = 0; - - HandleMoveEvent = true; - HandleLeftButtonEvent = true; - HandleMiddleButtonEvent = false; - HandleRightButtonEvent = false; - - // Build the representation of the widget - // - myPlane1 = vtkPlane::New(); - myPlane1->SetNormal(0,0,1); - myPlane1->SetOrigin(0,0,0); - // - myDistance = 10.; - myPlane2 = vtkPlane::New(); - myPlane2->SetNormal(0.,0.,-1.); - myPlane2->SetOrigin(0,0,myDistance); - // - myImplicitFunction = vtkImplicitBoolean::New(); - myImplicitFunction->SetOperationType(VTK_UNION); - // - myBox = vtkImageData::New(); - myBox->SetDimensions(2,2,2); - myOutline = vtkOutlineFilter::New(); - myOutline->SetInput(myBox); - myOutlineMapper = vtkPolyDataMapper::New(); - myOutlineMapper->SetInput(myOutline->GetOutput()); - myOutlineActor = vtkActor::New(); - this->myOutlineActor->SetMapper(this->myOutlineMapper); - this->myOutlineActor->PickableOff(); - this->OutlineTranslation = 0; - - this->myCutter1 = vtkCutter::New(); - this->myCutter1->SetInput(myBox); - this->myCutter1->SetCutFunction(myPlane1); - this->myCutMapper1 = vtkPolyDataMapper::New(); - this->myCutMapper1->SetInput(this->myCutter1->GetOutput()); - this->myCutActor1 = vtkActor::New(); - this->myCutActor1->SetMapper(this->myCutMapper1); - this->myDrawPlane = 1; - - this->myEdges1 = vtkFeatureEdges::New(); - myEdges1->SetColoring(0); - this->myEdges1->SetInput(this->myCutter1->GetOutput()); - this->myEdgesMapper1 = vtkPolyDataMapper::New(); - this->myEdgesMapper1->SetInput(this->myEdges1->GetOutput()); - this->myEdgesActor1 = vtkActor::New(); - this->myEdgesActor1->SetMapper(this->myEdgesMapper1); - myEdgesActor1->GetProperty()->SetLineWidth(4.); - myEdgesActor1->GetProperty()->SetColor(0., .5, .7); - - this->myCutter2 = vtkCutter::New(); - this->myCutter2->SetInput(myBox); - this->myCutter2->SetCutFunction(this->myPlane2); - this->myCutMapper2 = vtkPolyDataMapper::New(); - this->myCutMapper2->SetInput(this->myCutter2->GetOutput()); - this->myCutActor2 = vtkActor::New(); - this->myCutActor2->SetMapper(this->myCutMapper2); - - myEdges2 = vtkFeatureEdges::New(); - myEdges2->SetColoring(0); - myEdges2->SetInput(myCutter2->GetOutput()); - myEdgesMapper2 = vtkPolyDataMapper::New(); - myEdgesMapper2->SetInput(myEdges2->GetOutput()); - myEdgesActor2 = vtkActor::New(); - myEdgesActor2->SetMapper(myEdgesMapper2); - myEdgesActor2->GetProperty()->SetLineWidth(4.); - myEdgesActor2->GetProperty()->SetColor(.7, .0, .0); - - // Create the + plane normal - this->LineSource = vtkLineSource::New(); - this->LineSource->SetResolution(1); - this->LineMapper = vtkPolyDataMapper::New(); - this->LineMapper->SetInput(this->LineSource->GetOutput()); - this->LineActor = vtkActor::New(); - this->LineActor->SetMapper(this->LineMapper); - - this->ConeSource = vtkConeSource::New(); - this->ConeSource->SetResolution(12); - this->ConeSource->SetAngle(20.); - this->ConeMapper = vtkPolyDataMapper::New(); - this->ConeMapper->SetInput(this->ConeSource->GetOutput()); - this->ConeActor = VISU_UnScaledActor::New(); - this->ConeActor->SetMapper(this->ConeMapper); - ConeActor->SetSize(36); - ConeActor->SetCenter(ConeSource->GetCenter()); - - // Create the - plane normal - this->LineSource2 = vtkLineSource::New(); - this->LineSource2->SetResolution(1); - this->LineMapper2 = vtkPolyDataMapper::New(); - this->LineMapper2->SetInput(this->LineSource2->GetOutput()); - this->LineActor2 = vtkActor::New(); - this->LineActor2->SetMapper(this->LineMapper2); - - this->ConeSource2 = vtkConeSource::New(); - this->ConeSource2->SetResolution(12); - this->ConeSource2->SetAngle(20.); - this->ConeMapper2 = vtkPolyDataMapper::New(); - this->ConeMapper2->SetInput(this->ConeSource2->GetOutput()); - this->ConeActor2 = VISU_UnScaledActor::New(); - this->ConeActor2->SetMapper(this->ConeMapper2); - ConeActor2->SetSize(36); - ConeActor2->SetCenter(ConeSource2->GetCenter()); - - // Create the origin handle - this->Sphere = vtkSphereSource::New(); - this->Sphere->SetThetaResolution(16); - this->Sphere->SetPhiResolution(8); - this->SphereMapper = vtkPolyDataMapper::New(); - this->SphereMapper->SetInput(this->Sphere->GetOutput()); - this->SphereActor = VISU_UnScaledActor::New(); - this->SphereActor->SetMapper(this->SphereMapper); - SphereActor->SetSize(36); - SphereActor->SetCenter(Sphere->GetCenter()); - - this->Transform = vtkTransform::New(); - - // Define the point coordinates - float bounds[6]; - bounds[0] = -0.5; - bounds[1] = 0.5; - bounds[2] = -0.5; - bounds[3] = 0.5; - bounds[4] = -0.5; - bounds[5] = 0.5; - - // Initial creation of the widget, serves to initialize it - this->PlaceWidget(bounds); - - //Manage the picking stuff - this->Picker = vtkCellPicker::New(); - this->Picker->SetTolerance(0.005); - this->Picker->AddPickList(this->myCutActor1); - this->Picker->AddPickList(this->myCutActor2); - this->Picker->AddPickList(this->LineActor); - this->Picker->AddPickList(this->ConeActor); - this->Picker->AddPickList(this->LineActor2); - this->Picker->AddPickList(this->ConeActor2); - this->Picker->AddPickList(this->SphereActor); - this->Picker->AddPickList(this->myOutlineActor); - this->Picker->PickFromListOn(); - - // Set up the initial properties - this->CreateDefaultProperties(); - } //================================================================== // function: ~ @@ -345,1377 +133,4 @@ VISU_ImplicitFunctionWidget::VISU_ImplicitFunctionWidget() //================================================================== VISU_ImplicitFunctionWidget::~VISU_ImplicitFunctionWidget() { - myPlane1->Delete(); - - this->myPlane2->Delete(); - this->myImplicitFunction->Delete(); - - myBox->Delete(); - this->myOutline->Delete(); - this->myOutlineMapper->Delete(); - this->myOutlineActor->Delete(); - - this->myCutter1->Delete(); - this->myCutMapper1->Delete(); - this->myCutActor1->Delete(); - - this->myEdges1->Delete(); - this->myEdgesMapper1->Delete(); - this->myEdgesActor1->Delete(); - - myCutter2->Delete(); - myCutMapper2->Delete(); - myCutActor2->Delete(); - - myEdges2->Delete(); - myEdgesMapper2->Delete(); - myEdgesActor2->Delete(); - - this->LineSource->Delete(); - this->LineMapper->Delete(); - this->LineActor->Delete(); - - this->ConeSource->Delete(); - this->ConeMapper->Delete(); - this->ConeActor->Delete(); - - this->LineSource2->Delete(); - this->LineMapper2->Delete(); - this->LineActor2->Delete(); - - this->ConeSource2->Delete(); - this->ConeMapper2->Delete(); - this->ConeActor2->Delete(); - - this->Sphere->Delete(); - this->SphereMapper->Delete(); - this->SphereActor->Delete(); - - this->Transform->Delete(); - - this->Picker->Delete(); - - this->NormalProperty->Delete(); - this->SelectedNormalProperty->Delete(); - this->PlaneProperty->Delete(); - this->SelectedPlaneProperty->Delete(); - this->OutlineProperty->Delete(); - this->SelectedOutlineProperty->Delete(); - this->EdgesProperty->Delete(); -} -//================================================================== -// function: ImplicitFunction -// purpose : -//================================================================== -vtkImplicitFunction* VISU_ImplicitFunctionWidget::ImplicitFunction() -{ - return this->myImplicitFunction; -} -//================================================================== -// function: SetDistance -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::SetDistance(const float theDistance) -{ - if( theDistance <= 0.0 || theDistance == myDistance ) - return; - - myDistance=theDistance; - // - float *origin, *normal, oNew[3], aN2[3]; - origin = myPlane1->GetOrigin(); - normal = myPlane1->GetNormal(); - vtkMath::Normalize(normal); - oNew[0] = origin[0] + myDistance*normal[0]; - oNew[1] = origin[1] + myDistance*normal[1]; - oNew[2] = origin[2] + myDistance*normal[2]; - myPlane2->SetOrigin(oNew); - aN2[0] = -normal[0]; - aN2[1] = -normal[1]; - aN2[2] = -normal[2]; - myPlane2->SetNormal(aN2); -} -//================================================================== -// function: Distance -// purpose : -//================================================================== -float VISU_ImplicitFunctionWidget::Distance()const -{ - return myDistance; -} -//================================================================== -// function: SetEnabled -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::SetEnabled(int enabling) -{ - if ( ! this->Interactor ) { - vtkErrorMacro(<<"The interactor must be set prior to enabling/disabling widget"); - return; - } - - if ( enabling ) {//------------------------------------------------------------ - vtkDebugMacro(<<"Enabling plane widget"); - - if ( this->Enabled ){ //already enabled, just return - return; - } - - if ( ! this->CurrentRenderer ){ - this->CurrentRenderer = this->Interactor->FindPokedRenderer( - this->Interactor->GetLastEventPosition()[0], - this->Interactor->GetLastEventPosition()[1]); - if (this->CurrentRenderer == NULL) { - return; - } - } - // - vtkCamera *pCamera=CurrentRenderer->GetActiveCamera(); - pCamera->SetParallelProjection(1); - // - this->myImplicitFunction->AddFunction(myPlane1); - this->myImplicitFunction->AddFunction(this->myPlane2); - - this->Enabled = 1; - - // listen for the following events - vtkRenderWindowInteractor *i = this->Interactor; - if( this->HandleMoveEvent ) { - i->AddObserver(vtkCommand::MouseMoveEvent, - this->EventCallbackCommand, - this->Priority); - } - if( this->HandleLeftButtonEvent ) { - i->AddObserver(vtkCommand::LeftButtonPressEvent, - this->EventCallbackCommand, - this->Priority); - i->AddObserver(vtkCommand::LeftButtonReleaseEvent, - this->EventCallbackCommand, - this->Priority); - } - if( this->HandleMiddleButtonEvent ) { - i->AddObserver(vtkCommand::MiddleButtonPressEvent, - this->EventCallbackCommand, - this->Priority); - i->AddObserver(vtkCommand::MiddleButtonReleaseEvent, - this->EventCallbackCommand, - this->Priority); - } - if( this->HandleRightButtonEvent ) { - i->AddObserver(vtkCommand::RightButtonPressEvent, - this->EventCallbackCommand, - this->Priority); - i->AddObserver(vtkCommand::RightButtonReleaseEvent, - this->EventCallbackCommand, - this->Priority); - } - // add the outline - this->CurrentRenderer->AddActor(this->myOutlineActor); - this->myOutlineActor->SetProperty(this->OutlineProperty); - - // add the edges - this->CurrentRenderer->AddActor(this->myEdgesActor1); - this->CurrentRenderer->AddActor(myEdgesActor2); - - this->myOutlineActor->SetProperty(this->EdgesProperty); - - // add the normal vector - this->CurrentRenderer->AddActor(this->LineActor); - this->LineActor->SetProperty(this->NormalProperty); - this->CurrentRenderer->AddActor(this->ConeActor); - this->ConeActor->SetProperty(this->NormalProperty); - - this->CurrentRenderer->AddActor(this->LineActor2); - this->LineActor2->SetProperty(this->NormalProperty); - this->CurrentRenderer->AddActor(this->ConeActor2); - this->ConeActor2->SetProperty(this->NormalProperty); - - // add the origin handle - this->CurrentRenderer->AddActor(this->SphereActor); - this->SphereActor->SetProperty(this->NormalProperty); - - // add the plane (if desired) - if ( this->myDrawPlane ) { - this->CurrentRenderer->AddActor(this->myCutActor1); - this->CurrentRenderer->AddActor(this->myCutActor2); - } - this->myCutActor1->SetProperty(this->PlaneProperty); - myCutActor2->SetProperty(this->PlaneProperty); - - this->UpdateRepresentation(); - this->SizeHandles(); - this->InvokeEvent(vtkCommand::EnableEvent,NULL); - } - - else {//disabling---------------------------------------------------------- - vtkDebugMacro(<<"Disabling plane widget"); - - if ( ! this->Enabled ) {//already disabled, just return - return; - } - - if(vtkImplicitFunctionCollection* aFunction = this->myImplicitFunction->GetFunction()){ - aFunction->RemoveAllItems(); - this->myImplicitFunction->Modified(); // VTK bug - } - - this->Enabled = 0; - - // don't listen for events any more - this->Interactor->RemoveObserver(this->EventCallbackCommand); - - // turn off the various actors - this->CurrentRenderer->RemoveActor(this->myOutlineActor); - this->CurrentRenderer->RemoveActor(this->myEdgesActor1); - this->CurrentRenderer->RemoveActor(myEdgesActor2); - this->CurrentRenderer->RemoveActor(this->LineActor); - this->CurrentRenderer->RemoveActor(this->ConeActor); - this->CurrentRenderer->RemoveActor(this->LineActor2); - this->CurrentRenderer->RemoveActor(this->ConeActor2); - this->CurrentRenderer->RemoveActor(this->SphereActor); - this->CurrentRenderer->RemoveActor(this->myCutActor1); - this->CurrentRenderer->RemoveActor(myCutActor2); - - this->InvokeEvent(vtkCommand::DisableEvent,NULL); - this->CurrentRenderer = NULL; - } - - this->Interactor->Render(); -} -//================================================================== -// function: IsEnabled -// purpose : -//================================================================== -int VISU_ImplicitFunctionWidget::IsEnabled() -{ - return this->Enabled; -} -//================================================================== -// function: ProcessEvents -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::ProcessEvents(vtkObject* vtkNotUsed(object), - unsigned long event, - void* clientdata, - void* vtkNotUsed(calldata)) -{ - VISU_ImplicitFunctionWidget* self = - reinterpret_cast( clientdata ); - - //okay, let's do the right thing - switch(event) - { - case vtkCommand::LeftButtonPressEvent: - self->OnLeftButtonDown(); - break; - case vtkCommand::LeftButtonReleaseEvent: - self->OnLeftButtonUp(); - break; - case vtkCommand::MiddleButtonPressEvent: - self->OnMiddleButtonDown(); - break; - case vtkCommand::MiddleButtonReleaseEvent: - self->OnMiddleButtonUp(); - break; - case vtkCommand::RightButtonPressEvent: - self->OnRightButtonDown(); - break; - case vtkCommand::RightButtonReleaseEvent: - self->OnRightButtonUp(); - break; - case vtkCommand::MouseMoveEvent: - self->OnMouseMove(); - break; - default: - break; - } -} -//================================================================== -// function: HighlightNormal -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::HighlightNormal(int highlight) -{ - if ( highlight ) { - this->LineActor->SetProperty(this->SelectedNormalProperty); - this->ConeActor->SetProperty(this->SelectedNormalProperty); - this->LineActor2->SetProperty(this->SelectedNormalProperty); - this->ConeActor2->SetProperty(this->SelectedNormalProperty); - this->SphereActor->SetProperty(this->SelectedNormalProperty); - } - else - { - this->LineActor->SetProperty(this->NormalProperty); - this->ConeActor->SetProperty(this->NormalProperty); - this->LineActor2->SetProperty(this->NormalProperty); - this->ConeActor2->SetProperty(this->NormalProperty); - this->SphereActor->SetProperty(this->NormalProperty); - } -} -//================================================================== -// function: HighlightPlane -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::HighlightPlane(int highlight) -{ - if ( highlight ) { - this->myCutActor1->SetProperty(this->SelectedPlaneProperty); - myCutActor2->SetProperty(this->SelectedPlaneProperty); - } - else { - this->myCutActor1->SetProperty(this->PlaneProperty); - myCutActor2->SetProperty(this->PlaneProperty); - } -} -//================================================================== -// function: HighlightOutline -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::HighlightOutline(int highlight) -{ - if (highlight) { - this->myOutlineActor->SetProperty(this->SelectedOutlineProperty); - } - else { - this->myOutlineActor->SetProperty(this->OutlineProperty); - } -} -//================================================================== -// function: OnLeftButtonDown -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::OnLeftButtonDown() -{ - // We're only here if we are enabled - int X = this->Interactor->GetEventPosition()[0]; - int Y = this->Interactor->GetEventPosition()[1]; - // - // Okay, we can process this. See if we've picked anything. - // Make sure it's in the activated renderer - vtkRenderer *ren = this->Interactor->FindPokedRenderer(X,Y); - if ( ren != this->CurrentRenderer ) { - this->State = VISU_ImplicitFunctionWidget::Outside; - return; - } - - vtkAssemblyPath *path; - this->Picker->Pick(X,Y,0.0,this->CurrentRenderer); - path = this->Picker->GetPath(); - - if ( path == NULL ) {//not picking this widget - this->HighlightPlane(0); - this->HighlightNormal(0); - this->HighlightOutline(0); - this->State = VISU_ImplicitFunctionWidget::Outside; - return; - } - - vtkProp *prop = path->GetFirstNode()->GetProp(); - this->ValidPick = 1; - this->Picker->GetPickPosition(this->LastPickPosition); - // - if ( prop == this->ConeActor || prop == this->LineActor || - prop == this->ConeActor2 || prop == this->LineActor2 ) { - this->HighlightPlane(1); - this->HighlightNormal(1); - this->State = VISU_ImplicitFunctionWidget::Rotating; - } - else if ( prop == this->myCutActor1) { - this->HighlightPlane(1); - this->State = VISU_ImplicitFunctionWidget::Pushing; - } - else if ( prop == this->SphereActor ) { - this->HighlightNormal(1); - this->State = VISU_ImplicitFunctionWidget::MovingOrigin; - } - else if (prop == myCutActor2) { - this->HighlightPlane(1); - this->State = VISU_ImplicitFunctionWidget::ChangeDistance; - } - else { - if ( this->OutlineTranslation ) { - this->HighlightOutline(1); - this->State = VISU_ImplicitFunctionWidget::MovingOutline; - } - } - - this->EventCallbackCommand->SetAbortFlag(1); - this->StartInteraction(); - this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL); - this->Interactor->Render(); -} -//================================================================== -// function: OnLeftButtonUp -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::OnLeftButtonUp() -{ - if ( this->State == VISU_ImplicitFunctionWidget::Outside ) { - return; - } - - this->State = VISU_ImplicitFunctionWidget::Start; - this->HighlightPlane(0); - this->HighlightOutline(0); - this->HighlightNormal(0); - this->SizeHandles(); - - this->EventCallbackCommand->SetAbortFlag(1); - this->EndInteraction(); - this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); - this->Interactor->Render(); -} -//================================================================== -// function: OnMiddleButtonDown -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::OnMiddleButtonDown() -{ - int X = this->Interactor->GetEventPosition()[0]; - int Y = this->Interactor->GetEventPosition()[1]; - - // Okay, we can process this. See if we've picked anything. - // Make sure it's in the activated renderer - vtkRenderer *ren = this->Interactor->FindPokedRenderer(X,Y); - if ( ren != this->CurrentRenderer ) { - this->State = VISU_ImplicitFunctionWidget::Outside; - return; - } - - // Okay, we can process this. - vtkAssemblyPath *path; - this->Picker->Pick(X,Y,0.0,this->CurrentRenderer); - path = this->Picker->GetPath(); - - if ( path == NULL ) {//nothing picked - this->State = VISU_ImplicitFunctionWidget::Outside; - return; - } - - this->ValidPick = 1; - this->Picker->GetPickPosition(this->LastPickPosition); - this->State = VISU_ImplicitFunctionWidget::MovingPlane; - this->HighlightNormal(1); - this->HighlightPlane(1); - - this->EventCallbackCommand->SetAbortFlag(1); - this->StartInteraction(); - this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL); - this->Interactor->Render(); -} -//================================================================== -// function: OnMiddleButtonUp -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::OnMiddleButtonUp() -{ - if ( this->State == VISU_ImplicitFunctionWidget::Outside ) { - return; - } - - this->State = VISU_ImplicitFunctionWidget::Start; - this->HighlightPlane(0); - this->HighlightOutline(0); - this->HighlightNormal(0); - this->SizeHandles(); - - this->EventCallbackCommand->SetAbortFlag(1); - this->EndInteraction(); - this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); - this->Interactor->Render(); -} -//================================================================== -// function: OnRightButtonDown -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::OnRightButtonDown() -{ - this->State = VISU_ImplicitFunctionWidget::Scaling; - - int X = this->Interactor->GetEventPosition()[0]; - int Y = this->Interactor->GetEventPosition()[1]; - - // Okay, we can process this. See if we've picked anything. - // Make sure it's in the activated renderer - vtkRenderer *ren = this->Interactor->FindPokedRenderer(X,Y); - if ( ren != this->CurrentRenderer ) { - this->State = VISU_ImplicitFunctionWidget::Outside; - return; - } - - // Okay, we can process this. Try to pick handles first; - // if no handles picked, then pick the bounding box. - vtkAssemblyPath *path; - this->Picker->Pick(X,Y,0.0,this->CurrentRenderer); - path = this->Picker->GetPath(); - if ( path == NULL ){ //nothing picked - this->State = VISU_ImplicitFunctionWidget::Outside; - return; - } - - this->ValidPick = 1; - this->Picker->GetPickPosition(this->LastPickPosition); - this->HighlightPlane(1); - this->HighlightOutline(1); - this->HighlightNormal(1); - - this->EventCallbackCommand->SetAbortFlag(1); - this->StartInteraction(); - this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL); - this->Interactor->Render(); -} -//================================================================== -// function: OnRightButtonUp -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::OnRightButtonUp() -{ - if ( this->State == VISU_ImplicitFunctionWidget::Outside ) { - return; - } - - this->State = VISU_ImplicitFunctionWidget::Start; - this->HighlightPlane(0); - this->HighlightOutline(0); - this->HighlightNormal(0); - this->SizeHandles(); - - this->EventCallbackCommand->SetAbortFlag(1); - this->EndInteraction(); - this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); - this->Interactor->Render(); -} -//================================================================== -// function: OnMouseMove -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::OnMouseMove() -{ - this->SizeHandles(); - - // See whether we're active - if ( this->State == VISU_ImplicitFunctionWidget::Outside || - this->State == VISU_ImplicitFunctionWidget::Start ) { - return; - } - - int X = this->Interactor->GetEventPosition()[0]; - int Y = this->Interactor->GetEventPosition()[1]; - - // Do different things depending on state - // Calculations everybody does - double focalPoint[4], pickPoint[4], prevPickPoint[4]; - double z, vpn[3]; - - vtkCamera *camera = this->CurrentRenderer->GetActiveCamera(); - if ( !camera ) { - return; - } - - // Compute the two points defining the motion vector - this->ComputeWorldToDisplay(this->LastPickPosition[0], this->LastPickPosition[1], - this->LastPickPosition[2], focalPoint); - z = focalPoint[2]; - this->ComputeDisplayToWorld(double(this->Interactor->GetLastEventPosition()[0]), - double(this->Interactor->GetLastEventPosition()[1]), - z, prevPickPoint); - this->ComputeDisplayToWorld(double(X), double(Y), z, pickPoint); - - // Process the motion - if ( this->State == VISU_ImplicitFunctionWidget::MovingPlane ) { - //this->TranslatePlane(prevPickPoint, pickPoint); - //printf(" TranslatePlane\n"); - } - else if ( this->State == VISU_ImplicitFunctionWidget::MovingOutline ) { - //this->TranslateOutline(prevPickPoint, pickPoint); - //printf(" TranslateOutline\n"); - } - else if ( this->State == VISU_ImplicitFunctionWidget::MovingOrigin ) { - this->TranslateOrigin(prevPickPoint, pickPoint); - //printf(" TranslateOrigin\n"); - } - else if ( this->State == VISU_ImplicitFunctionWidget::Pushing ) { - this->Push(prevPickPoint, pickPoint); - // printf(" Push\n"); - } - else if ( this->State == VISU_ImplicitFunctionWidget::Scaling ) { - //this->Scale(prevPickPoint, pickPoint, X, Y); - //printf(" Scale\n"); - } - else if ( this->State == VISU_ImplicitFunctionWidget::Rotating ) { - camera->GetViewPlaneNormal(vpn); - this->Rotate(X, Y, prevPickPoint, pickPoint, vpn); - //printf(" Rotate\n"); - } - else if ( this->State == VISU_ImplicitFunctionWidget::ChangeDistance ) { - this->PushDistance(prevPickPoint, pickPoint); - //printf(" PushDistance\n"); - } - // Interact, if desired - this->EventCallbackCommand->SetAbortFlag(1); - this->InvokeEvent(vtkCommand::InteractionEvent,NULL); - - this->Interactor->Render(); -} -//================================================================== -// function: Push -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::Push(double *p1, double *p2) -{ - //Get the motion vector - int i; - float v[3]; - // - for (i=0; i<3; ++i){ - v[i] = p2[i] - p1[i]; - } - // - float aOr1[3], aNr1[3], aNr2[3], aD, z1; - // - myPlane1->GetOrigin(aOr1); - myPlane1->GetNormal(aNr1); - myPlane2->GetNormal(aNr2); - // - aD=vtkMath::Dot(v, aNr2); - z1 = aOr1[2]+aD*aNr2[2]; - if( z1 <= myBox->GetOrigin()[2] ){ - return; - } - // - aD=vtkMath::Dot(v, aNr1); - for (i=0; i < 3; ++i) { - aOr1[i]=aOr1[i]+aD*aNr1[i]; - } - SetOriginInternal(aOr1); - this->UpdateRepresentation(); -} -//================================================================== -// function: TranslateOrigin -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::TranslateOrigin(double *p1, double *p2) -{ - //Get the motion vector - int i; - double v[3]; - // - for (i=0; i<3; ++i){ - v[i] = p2[i] - p1[i]; - } - // - //Add to the current point, project back down onto plane - float *o = myPlane1->GetOrigin(); - float *n = myPlane1->GetNormal(); - float newOrigin[3]; - // - for (i=0; i<3; ++i){ - newOrigin[i]=o[i] + v[i]; - } - vtkPlane::ProjectPoint(newOrigin, o, n, newOrigin); - SetOriginInternal(newOrigin); - this->UpdateRepresentation(); -} -//================================================================== -// function: SetOriginInternal -// purpose : Set the origin of the plane.(for Internal calls) -//================================================================== -void VISU_ImplicitFunctionWidget::SetOriginInternal(float x[3]) -{ - float *bounds = this->myOutline->GetOutput()->GetBounds(); - int i, j; - for (i=0; i<3; ++i) { - j=2*i; - if ( x[i] < bounds[j] ) { - x[i] = bounds[j]; - } - else if ( x[i] > bounds[j+1] ) { - x[i] = bounds[j+1]; - } - } - // - bool bFlag; - float aOr2[3], aNr2[3], aNr1[3]; - vtkPlane *pPx; - // - myPlane1->GetNormal(aNr1); - myPlane2->GetNormal(aNr2); - for (i=0; i<3; ++i) { - aOr2[i]=x[i]+myDistance*aNr1[i]; - } - pPx=vtkPlane::New(); - pPx->SetOrigin(aOr2); - pPx->SetNormal(aNr2); - bFlag=IsValidPlane2Position(pPx, myBox); - if (bFlag){ - myPlane1->SetOrigin(x); - myPlane2->SetOrigin(aOr2); - } - pPx->Delete(); -} -//================================================================== -// function: Rotate -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::Rotate(int X, int Y, - double *p1, double *p2, - double *vpn) -{ - double v[3]; //vector of motion - double axis[3]; //axis of rotation - double theta; //rotation angle - int i; - - // mouse motion vector in world space - for (i=0; i<3; ++i){ - v[i] = p2[i] - p1[i]; - } - // - float *origin = myPlane1->GetOrigin(); - float *normal = myPlane1->GetNormal(); - - // Create axis of rotation and angle of rotation - vtkMath::Cross(vpn,v,axis); - if ( vtkMath::Normalize(axis) == 0.0 ) { - return; - } - - int *size = this->CurrentRenderer->GetSize(); - double l2 = (X-this->Interactor->GetLastEventPosition()[0])* - (X-this->Interactor->GetLastEventPosition()[0]) + - (Y-this->Interactor->GetLastEventPosition()[1])* - (Y-this->Interactor->GetLastEventPosition()[1]); - theta = 360.0 * sqrt(l2/((double)size[0]*size[0]+size[1]*size[1])); - - //Manipulate the transform to reflect the rotation - this->Transform->Identity(); - this->Transform->Translate(origin[0],origin[1],origin[2]); - this->Transform->RotateWXYZ(theta,axis); - this->Transform->Translate(-origin[0],-origin[1],-origin[2]); - - //Set the new normal - float nNew[3], aN2[3], oNew[3]; - this->Transform->TransformNormal(normal,nNew); - // - for (i=0; i<3; ++i){ - aN2[i] = -nNew[i]; - } - vtkMath::Normalize(nNew); - for (i=0; i<3; ++i){ - oNew[i] = origin[i] + myDistance*nNew[i]; - } - // - vtkPlane *pPx=vtkPlane::New(); - pPx->SetNormal(aN2); - pPx->SetOrigin(oNew); - // - bool bFlag=IsValidPlane2Position(pPx, myBox); - if (bFlag) { - myPlane1->SetNormal(nNew); - this->myPlane2->SetNormal(aN2); - this->myPlane2->SetOrigin(oNew); - } - pPx->Delete(); - this->UpdateRepresentation(); -} -//================================================================== -// function: PushDistance -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::PushDistance(double *p1, double *p2) -{ - int i; - float v[3], *anOrigin1, *aN1, *anOrigin2, *aN2, aD; - //Get the motion vector - for (i=0; i<3; ++i){ - v[i] = p2[i] - p1[i]; - } - // - anOrigin1 = myPlane1->GetOrigin(); - aN1 = myPlane1->GetNormal(); - anOrigin2 = myPlane2->GetOrigin(); - aN2 = myPlane2->GetNormal(); - - vtkMath::Normalize(aN1); - - float origin[3]; - double distance = vtkMath::Dot( v, aN2 ); - for(i=0; i<3; ++i) { - origin[i] = anOrigin2[i] + distance * aN2[i]; - } - float d = DistanceToPlane(origin, aN1, anOrigin1); - if( d <= 0.0 ) - return; - // - bool bFlag; - float aOr2[3], aNr2[3]; - vtkPlane *pPx; - // - myPlane2->GetOrigin(aOr2); - myPlane2->GetNormal(aNr2); - pPx=vtkPlane::New(); - pPx->SetNormal(aNr2); - aD=vtkMath::Dot(v, aNr2); - for (i=0; i < 3; ++i) { - aOr2[i]=aOr2[i]+aD*aNr2[i]; - } - pPx->SetOrigin(aOr2); - bFlag=IsValidPlane2Position(pPx, myBox); - if(bFlag) { - myPlane2->SetOrigin(aOr2); - myPlane2->Modified(); - aD=DistanceToPlane(aOr2, aN1, anOrigin1); - // - myDistance=aD; - } - pPx->Delete(); - this->UpdateRepresentation(); -} - -//================================================================== -// function: TranslatePlane -// purpose : Loop through all points and translate them -//================================================================== -void VISU_ImplicitFunctionWidget::TranslatePlane(double *p1, double *p2) -{ - //Get the motion vector - double v[3]; - v[0] = p2[0] - p1[0]; - v[1] = p2[1] - p1[1]; - v[2] = p2[2] - p1[2]; - - //Translate the plane - float oNew[3]; - float *origin = myPlane1->GetOrigin(); - oNew[0] = origin[0] + v[0]; - oNew[1] = origin[1] + v[1]; - oNew[2] = origin[2] + v[2]; - myPlane1->SetOrigin(oNew); - - origin = this->myPlane2->GetOrigin(); - oNew[0] = origin[0] + v[0]; - oNew[1] = origin[1] + v[1]; - oNew[2] = origin[2] + v[2]; - this->myPlane2->SetOrigin(oNew); - - this->UpdateRepresentation(); -} -//================================================================== -// function: TranslateOutline -// purpose :Loop through all points and translate them -//================================================================== -void VISU_ImplicitFunctionWidget::TranslateOutline(double *p1, double *p2) -{ - //Get the motion vector - double v[3]; - v[0] = p2[0] - p1[0]; - v[1] = p2[1] - p1[1]; - v[2] = p2[2] - p1[2]; - - //Translate the bounding box - float *origin = myBox->GetOrigin(); - float oNew[3]; - oNew[0] = origin[0] + v[0]; - oNew[1] = origin[1] + v[1]; - oNew[2] = origin[2] + v[2]; - myBox->SetOrigin(oNew); - - //Translate the plane - origin = myPlane1->GetOrigin(); - oNew[0] = origin[0] + v[0]; - oNew[1] = origin[1] + v[1]; - oNew[2] = origin[2] + v[2]; - myPlane1->SetOrigin(oNew); - - origin = this->myPlane2->GetOrigin(); - oNew[0] = origin[0] + v[0]; - oNew[1] = origin[1] + v[1]; - oNew[2] = origin[2] + v[2]; - this->myPlane2->SetOrigin(oNew); - - this->UpdateRepresentation(); -} - -//================================================================== -// function: Scale -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::Scale(double *p1, double *p2, - int vtkNotUsed(X), int Y) -{ - //Get the motion vector - double v[3]; - v[0] = p2[0] - p1[0]; - v[1] = p2[1] - p1[1]; - v[2] = p2[2] - p1[2]; - - //int res = this->PlaneSource->GetXResolution(); - float *o = myPlane1->GetOrigin(); - - // Compute the scale factor - float sf = vtkMath::Norm(v) / this->myOutline->GetOutput()->GetLength(); - if ( Y > this->Interactor->GetLastEventPosition()[1] ) { - sf = 1.0 + sf; - } - else { - sf = 1.0 - sf; - } - - this->Transform->Identity(); - this->Transform->Translate(o[0],o[1],o[2]); - this->Transform->Scale(sf,sf,sf); - this->Transform->Translate(-o[0],-o[1],-o[2]); - - float *origin = myBox->GetOrigin(); - float *spacing = myBox->GetSpacing(); - float oNew[3], p[3], pNew[3]; - p[0] = origin[0] + spacing[0]; - p[1] = origin[1] + spacing[1]; - p[2] = origin[2] + spacing[2]; - - this->Transform->TransformPoint(origin,oNew); - this->Transform->TransformPoint(p,pNew); - - myBox->SetOrigin(oNew); - myBox->SetSpacing( (pNew[0]-oNew[0]), (pNew[1]-oNew[1]), (pNew[2]-oNew[2]) ); - - this->UpdateRepresentation(); -} - - - -//================================================================== -// function: CreateDefaultProperties -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::CreateDefaultProperties() -{ - // Normal properties - this->NormalProperty = vtkProperty::New(); - this->NormalProperty->SetColor(1,1,1); - this->NormalProperty->SetLineWidth(2); - - this->SelectedNormalProperty = vtkProperty::New(); - this->SelectedNormalProperty->SetColor(1,0,0); - this->NormalProperty->SetLineWidth(2); - - // Plane properties - this->PlaneProperty = vtkProperty::New(); - this->PlaneProperty->SetAmbient(1.0); - this->PlaneProperty->SetAmbientColor(1.0,1.0,1.0); - - this->SelectedPlaneProperty = vtkProperty::New(); - this->SelectedPlaneProperty->SetAmbient(1.0); - this->SelectedPlaneProperty->SetAmbientColor(0.0,1.0,0.0); - this->SelectedPlaneProperty->SetOpacity(0.25); - - // Outline properties - this->OutlineProperty = vtkProperty::New(); - this->OutlineProperty->SetAmbient(1.0); - this->OutlineProperty->SetAmbientColor(1.0,1.0,1.0); - - this->SelectedOutlineProperty = vtkProperty::New(); - this->SelectedOutlineProperty->SetAmbient(1.0); - this->SelectedOutlineProperty->SetAmbientColor(0.0,1.0,0.0); - - // Edge property - this->EdgesProperty = vtkProperty::New(); - this->EdgesProperty->SetAmbient(1.0); - this->EdgesProperty->SetAmbientColor(1.0,1.0,1.0); -} -//================================================================== -// function: InitialPlaceWidget -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::InitialPlaceWidget(float bds[6]) -{ - float bounds[6], origin[3]; - - PlaceWidget(bds); - // - this->AdjustBounds(bds, bounds, origin); - this->SetOrigin((bounds[1]+bounds[0])/2.0, - (bounds[3]+bounds[2])/2.0, - (bounds[5]+bounds[4])/2.0); - - static float DIST_COEFF = 0.1; - SetDistance(this->InitialLength*DIST_COEFF); - // - this->UpdateRepresentation(); -} -//================================================================== -// function: PlaceWidget -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::PlaceWidget(float bds[6]) -{ - int i; - float bounds[6], origin[3]; - - this->AdjustBounds(bds, bounds, origin); - - // Set up the bounding box - myBox->SetOrigin(bounds[0],bounds[2],bounds[4]); - myBox->SetSpacing((bounds[1]-bounds[0]),(bounds[3]-bounds[2]), - (bounds[5]-bounds[4])); - this->myOutline->Update(); - - if (this->Input || this->Prop3D) { - this->LineSource->SetPoint1(myPlane1->GetOrigin()); - if ( this->NormalToYAxis ) { - myPlane1->SetNormal(0,1,0); - myPlane2->SetNormal(0,-1,0); - this->LineSource->SetPoint2(0,1,0); - } - else if ( this->NormalToZAxis ) { - myPlane1->SetNormal(0,0,1); - myPlane2->SetNormal(0,0,-1); - this->LineSource->SetPoint2(0,0,1); - } - else{ //default or x-normal - myPlane1->SetNormal(1,0,0); - myPlane2->SetNormal(-1,0,0); - this->LineSource->SetPoint2(1,0,0); - } - } - - for (i=0; i<6; i++) { - this->InitialBounds[i] = bounds[i]; - } - - this->InitialLength = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) + - (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) + - (bounds[5]-bounds[4])*(bounds[5]-bounds[4])); - - this->UpdateRepresentation(); -} -//================================================================== -// function: SetOrigin -// purpose :Set the origin of the plane.(for external calls) -//================================================================== -void VISU_ImplicitFunctionWidget::SetOrigin(float x, float y, float z) -{ - float origin[3]; - origin[0] = x; - origin[1] = y; - origin[2] = z; - this->SetOrigin(origin); -} -//================================================================== -// function: SetOrigin -// purpose : Set the origin of the plane.(for external calls) -//================================================================== -void VISU_ImplicitFunctionWidget::SetOrigin(float x[3]) -{ - float *bounds = this->myOutline->GetOutput()->GetBounds(); - for (int i=0; i<3; i++) { - if ( x[i] < bounds[2*i] ) { - x[i] = bounds[2*i]; - } - else if ( x[i] > bounds[2*i+1] ) { - x[i] = bounds[2*i+1]; - } - } - myPlane1->SetOrigin(x); - float *origin, *normal, oNew[3]; - origin = myPlane1->GetOrigin(); - normal = myPlane1->GetNormal(); - vtkMath::Normalize(normal); - oNew[0] = origin[0] + myDistance*normal[0]; - oNew[1] = origin[1] + myDistance*normal[1]; - oNew[2] = origin[2] + myDistance*normal[2]; - this->myPlane2->SetOrigin(oNew); - this->UpdateRepresentation(); -} -//================================================================== -// function: GetOrigin -// purpose :Get the origin of the plane. -//================================================================== -float* VISU_ImplicitFunctionWidget::GetOrigin() -{ - return myPlane1->GetOrigin(); -} - -void VISU_ImplicitFunctionWidget::GetOrigin(float xyz[3]) -{ - myPlane1->GetOrigin(xyz); -} -//================================================================== -// function: SetNormal -// purpose :Set the normal to the plane. -//================================================================== -void VISU_ImplicitFunctionWidget::SetNormal(float x, float y, float z) -{ - float n[3]; - n[0] = x; - n[1] = y; - n[2] = z; - vtkMath::Normalize(n); - myPlane1->SetNormal(n); - n[0] =- x; - n[1] =- y; - n[2] =- z; - this->myPlane2->SetNormal(n); - - this->UpdateRepresentation(); -} - -//================================================================== -// function: SetNormal -// purpose :Set the normal to the plane. -//================================================================== -void VISU_ImplicitFunctionWidget::SetNormal(float n[3]) -{ - this->SetNormal(n[0], n[1], n[2]); -} -//================================================================== -// function: GetNormal -// purpose :Get the normal to the plane. -//================================================================== -float* VISU_ImplicitFunctionWidget::GetNormal() -{ - return myPlane1->GetNormal(); -} -//================================================================== -// function: GetNormal -// purpose :Get the normal to the plane. -//================================================================== -void VISU_ImplicitFunctionWidget::GetNormal(float xyz[3]) -{ - myPlane1->GetNormal(xyz); -} -//================================================================== -// function: SetDrawPlane -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::SetDrawPlane(int drawPlane) -{ - if ( drawPlane == this->myDrawPlane ) { - return; - } - - this->Modified(); - this->myDrawPlane = drawPlane; - if ( this->Enabled ) { - if ( drawPlane ) { - this->CurrentRenderer->AddActor(this->myCutActor1); - this->CurrentRenderer->AddActor(myCutActor2); - } - else { - this->CurrentRenderer->RemoveActor(this->myCutActor1); - this->CurrentRenderer->RemoveActor(myCutActor2); - } - this->Interactor->Render(); - } -} -//================================================================== -// function: SetNormalToXAxis -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::SetNormalToXAxis (int var) -{ - if (this->NormalToXAxis != var) { - this->NormalToXAxis = var; - this->Modified(); - } - if (var) { - this->NormalToYAxisOff(); - this->NormalToZAxisOff(); - } -} -//================================================================== -// function: SetNormalToYAxis -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::SetNormalToYAxis (int var) -{ - if (this->NormalToYAxis != var) { - this->NormalToYAxis = var; - this->Modified(); - } - if (var) { - this->NormalToXAxisOff(); - this->NormalToZAxisOff(); - } -} -//================================================================== -// function: SetNormalToZAxis -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::SetNormalToZAxis (int var) -{ - if (this->NormalToZAxis != var) { - this->NormalToZAxis = var; - this->Modified(); - } - if (var) { - this->NormalToXAxisOff(); - this->NormalToYAxisOff(); - } -} -//================================================================== -// function: GetPolyData -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::GetPolyData(vtkPolyData *pd) -{ - pd->ShallowCopy(this->myCutter1->GetOutput()); -} -//================================================================== -// function: GetPolyDataSource -// purpose : -//================================================================== -vtkPolyDataSource *VISU_ImplicitFunctionWidget::GetPolyDataSource() -{ - return this->myCutter1; -} -//================================================================== -// function:GetPlane -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::GetPlane(vtkPlane *plane) -{ - if ( plane == NULL ) { - return; - } - - plane->SetNormal(myPlane1->GetNormal()); - plane->SetOrigin(myPlane1->GetOrigin()); -} -//================================================================== -// function:UpdatePlacement -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::UpdatePlacement(void) -{ - this->myOutline->Update(); - this->myCutter1->Update(); - this->myEdges1->Update(); -} -//================================================================== -// function:UpdateRepresentation -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::UpdateRepresentation() -{ - if ( ! this->CurrentRenderer ) { - return; - } - - float *origin = myPlane1->GetOrigin(); - float *normal = myPlane1->GetNormal(); - float p2[3]; - - // Setup the plane normal - float d = this->myOutline->GetOutput()->GetLength(); - - p2[0] = origin[0] + 0.30 * d * normal[0]; - p2[1] = origin[1] + 0.30 * d * normal[1]; - p2[2] = origin[2] + 0.30 * d * normal[2]; - - this->LineSource->SetPoint1(origin); - this->LineSource->SetPoint2(p2); - this->ConeSource->SetCenter(p2); - this->ConeSource->SetDirection(normal); - ConeActor->SetCenter(p2); - - p2[0] = origin[0] - 0.30 * d * normal[0]; - p2[1] = origin[1] - 0.30 * d * normal[1]; - p2[2] = origin[2] - 0.30 * d * normal[2]; - - this->LineSource2->SetPoint1(origin); - this->LineSource2->SetPoint2(p2); - this->ConeSource2->SetCenter(p2); - this->ConeSource2->SetDirection(normal); - ConeActor2->SetCenter(p2); - - // Set up the position handle - this->Sphere->SetCenter(origin); - SphereActor->SetCenter(origin); - - this->myEdgesMapper1->SetInput(this->myEdges1->GetOutput()); -} -//================================================================== -// function:SizeHandles -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::SizeHandles() -{ - // float radius = - this->vtk3DWidget::SizeHandles(1.35); -} -//================================================================== -// function:PrintSelf -// purpose : -//================================================================== -void VISU_ImplicitFunctionWidget::PrintSelf(ostream& os, vtkIndent indent) -{ - this->Superclass::PrintSelf(os,indent); -} -//================================================================== -// function: IsValidPlane2Position -// purpose : -//================================================================== -bool IsValidPlane2Position(vtkPlane *pPx, - vtkDataSet *pDataSet, - float aTol) -{ - bool bRet; - int i, iFound; - float aD, aDmax, aPnts[24], aDiagonal; - float aTol1, aOr[3], aN[3]; - // - bRet=false; - aDiagonal=pDataSet->GetLength(); - aTol1=aDiagonal*aTol; - // - GetBndPoints(pDataSet, aPnts); - // - pPx->GetOrigin(aOr); - pPx->GetNormal(aN); - vtkMath::Normalize(aN); - // - iFound=0; - aDmax=0.; - for (i=0; i<24; i+=3){ - aD=-DistanceToPlane(aPnts+i, aN, aOr); - if (aD>aDmax){ - aDmax=aD; - iFound=1; - } - } - if (iFound && aDmax>aTol1) { - bRet=!bRet; - } - return bRet; -} -//================================================================== -// function: GetBndPoints -// purpose : -//================================================================== -void GetBndPoints(vtkDataSet *pDataSet, - float aPnts[24]) -{ - int aIndx[24]={ - 0,2,4,1,2,4,1,3,4,0,3,4, - 0,2,5,1,2,5,1,3,5,0,3,5 - }; - int i; - float *pBounds=pDataSet->GetBounds(); - // - for (i=0; i<24; ++i){ - aPnts[i]=pBounds[aIndx[i]]; - } -} -//================================================================== -// function: DistanceToPlane -// purpose : -//================================================================== -float DistanceToPlane(const float x[3], - const float n[3], - const float p0[3]) -{ - return ((float) (n[0]*(x[0]-p0[0]) + - n[1]*(x[1]-p0[1]) + - n[2]*(x[2]-p0[2]))); } diff --git a/src/PIPELINE/VISU_ImplicitFunctionWidget.hxx b/src/PIPELINE/VISU_ImplicitFunctionWidget.hxx new file mode 100644 index 00000000..8f46e43b --- /dev/null +++ b/src/PIPELINE/VISU_ImplicitFunctionWidget.hxx @@ -0,0 +1,79 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VISU_PlanesWidget.h +// Author : Peter KURNEV +// Module : SALOME +// $Header$ + +#ifndef __VISU_ImplicitFunctionWidget_h +#define __VISU_ImplicitFunctionWidget_h +//// +//================================================================== +// class : VISU_UnScaledActor +// purpose : +//================================================================== +#include +class VISU_UnScaledActor: public vtkFollower +{ + +public: + + vtkTypeMacro(VISU_UnScaledActor,vtkFollower); + static VISU_UnScaledActor *New(); + + + void SetCenter(float *); + virtual void SetSize(int theSize); + virtual void Render(vtkRenderer *theRenderer); + virtual float *GetBounds(); + +protected: + VISU_UnScaledActor(); + ~VISU_UnScaledActor(){} + + float myCenter[3]; + int mySize; +}; + +#include + +class vtkImplicitFunction; + +class VISU_ImplicitFunctionWidget : public vtk3DWidget +{ +public: + vtkTypeRevisionMacro(VISU_ImplicitFunctionWidget,vtk3DWidget); + + virtual vtkImplicitFunction* ImplicitFunction()=0; + +protected: + VISU_ImplicitFunctionWidget(); + ~VISU_ImplicitFunctionWidget(); + +private: + VISU_ImplicitFunctionWidget(const VISU_ImplicitFunctionWidget&); //Not implemented + void operator=(const VISU_ImplicitFunctionWidget&); //Not implemented +}; + +#endif diff --git a/src/PIPELINE/VISU_PlanesWidget.cxx b/src/PIPELINE/VISU_PlanesWidget.cxx new file mode 100644 index 00000000..93efa07b --- /dev/null +++ b/src/PIPELINE/VISU_PlanesWidget.cxx @@ -0,0 +1,1614 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VVTK_ImplicitFunctionWidget.cxx +// Author : Peter KURNEV +// Module : SALOME +// $Header$ + +#include "VISU_PlanesWidget.hxx" +#include "VISU_ImplicitFunctionWidget.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//// +#include +#include +#include +#include + +static + bool IsValidPlane2Position(vtkPlane *pPx, + vtkDataSet *pDataSet, + float aTol=0.003); +static + void GetBndPoints(vtkDataSet *pDataSet, + float aPnts[24]); +static + float DistanceToPlane(const float x[3], + const float n[3], + const float p0[3]); + +vtkCxxRevisionMacro(VISU_PlanesWidget, "$Revision$"); +vtkStandardNewMacro(VISU_PlanesWidget); + +//================================================================== +// function: VISU_PlanesWidget +// purpose : +//================================================================== +VISU_PlanesWidget::VISU_PlanesWidget() +: + VISU_ImplicitFunctionWidget() +{ + State = VISU_PlanesWidget::Start; + EventCallbackCommand->SetCallback(VISU_PlanesWidget::ProcessEvents); + + NormalToXAxis = 0; + NormalToYAxis = 0; + NormalToZAxis = 0; + + HandleMoveEvent = true; + HandleLeftButtonEvent = true; + HandleMiddleButtonEvent = false; + HandleRightButtonEvent = false; + + // Build the representation of the widget + // + myPlane1 = vtkPlane::New(); + myPlane1->SetNormal(0,0,1); + myPlane1->SetOrigin(0,0,0); + // + myDistance = 10.; + myPlane2 = vtkPlane::New(); + myPlane2->SetNormal(0.,0.,-1.); + myPlane2->SetOrigin(0,0,myDistance); + // + myImplicitFunction = vtkImplicitBoolean::New(); + myImplicitFunction->SetOperationType(VTK_UNION); + // + myBox = vtkImageData::New(); + myBox->SetDimensions(2,2,2); + myOutline = vtkOutlineFilter::New(); + myOutline->SetInput(myBox); + myOutlineMapper = vtkPolyDataMapper::New(); + myOutlineMapper->SetInput(myOutline->GetOutput()); + myOutlineActor = vtkActor::New(); + this->myOutlineActor->SetMapper(this->myOutlineMapper); + this->myOutlineActor->PickableOff(); + this->OutlineTranslation = 0; + + this->myCutter1 = vtkCutter::New(); + this->myCutter1->SetInput(myBox); + this->myCutter1->SetCutFunction(myPlane1); + this->myCutMapper1 = vtkPolyDataMapper::New(); + this->myCutMapper1->SetInput(this->myCutter1->GetOutput()); + this->myCutActor1 = vtkActor::New(); + this->myCutActor1->SetMapper(this->myCutMapper1); + this->myDrawPlane = 1; + + this->myEdges1 = vtkFeatureEdges::New(); + myEdges1->SetColoring(0); + this->myEdges1->SetInput(this->myCutter1->GetOutput()); + this->myEdgesMapper1 = vtkPolyDataMapper::New(); + this->myEdgesMapper1->SetInput(this->myEdges1->GetOutput()); + this->myEdgesActor1 = vtkActor::New(); + this->myEdgesActor1->SetMapper(this->myEdgesMapper1); + myEdgesActor1->GetProperty()->SetLineWidth(4.); + myEdgesActor1->GetProperty()->SetColor(0., .5, .7); + + this->myCutter2 = vtkCutter::New(); + this->myCutter2->SetInput(myBox); + this->myCutter2->SetCutFunction(this->myPlane2); + this->myCutMapper2 = vtkPolyDataMapper::New(); + this->myCutMapper2->SetInput(this->myCutter2->GetOutput()); + this->myCutActor2 = vtkActor::New(); + this->myCutActor2->SetMapper(this->myCutMapper2); + + myEdges2 = vtkFeatureEdges::New(); + myEdges2->SetColoring(0); + myEdges2->SetInput(myCutter2->GetOutput()); + myEdgesMapper2 = vtkPolyDataMapper::New(); + myEdgesMapper2->SetInput(myEdges2->GetOutput()); + myEdgesActor2 = vtkActor::New(); + myEdgesActor2->SetMapper(myEdgesMapper2); + myEdgesActor2->GetProperty()->SetLineWidth(4.); + myEdgesActor2->GetProperty()->SetColor(.7, .0, .0); + + // Create the + plane normal + this->LineSource = vtkLineSource::New(); + this->LineSource->SetResolution(1); + this->LineMapper = vtkPolyDataMapper::New(); + this->LineMapper->SetInput(this->LineSource->GetOutput()); + this->LineActor = vtkActor::New(); + this->LineActor->SetMapper(this->LineMapper); + + this->ConeSource = vtkConeSource::New(); + this->ConeSource->SetResolution(12); + this->ConeSource->SetAngle(20.); + this->ConeMapper = vtkPolyDataMapper::New(); + this->ConeMapper->SetInput(this->ConeSource->GetOutput()); + this->ConeActor = VISU_UnScaledActor::New(); + this->ConeActor->SetMapper(this->ConeMapper); + ConeActor->SetSize(36); + ConeActor->SetCenter(ConeSource->GetCenter()); + + // Create the - plane normal + this->LineSource2 = vtkLineSource::New(); + this->LineSource2->SetResolution(1); + this->LineMapper2 = vtkPolyDataMapper::New(); + this->LineMapper2->SetInput(this->LineSource2->GetOutput()); + this->LineActor2 = vtkActor::New(); + this->LineActor2->SetMapper(this->LineMapper2); + + this->ConeSource2 = vtkConeSource::New(); + this->ConeSource2->SetResolution(12); + this->ConeSource2->SetAngle(20.); + this->ConeMapper2 = vtkPolyDataMapper::New(); + this->ConeMapper2->SetInput(this->ConeSource2->GetOutput()); + this->ConeActor2 = VISU_UnScaledActor::New(); + this->ConeActor2->SetMapper(this->ConeMapper2); + ConeActor2->SetSize(36); + ConeActor2->SetCenter(ConeSource2->GetCenter()); + + // Create the origin handle + this->Sphere = vtkSphereSource::New(); + this->Sphere->SetThetaResolution(16); + this->Sphere->SetPhiResolution(8); + this->SphereMapper = vtkPolyDataMapper::New(); + this->SphereMapper->SetInput(this->Sphere->GetOutput()); + this->SphereActor = VISU_UnScaledActor::New(); + this->SphereActor->SetMapper(this->SphereMapper); + SphereActor->SetSize(36); + SphereActor->SetCenter(Sphere->GetCenter()); + + this->Transform = vtkTransform::New(); + + // Define the point coordinates + float bounds[6]; + bounds[0] = -0.5; + bounds[1] = 0.5; + bounds[2] = -0.5; + bounds[3] = 0.5; + bounds[4] = -0.5; + bounds[5] = 0.5; + + // Initial creation of the widget, serves to initialize it + this->PlaceWidget(bounds); + + //Manage the picking stuff + this->Picker = vtkCellPicker::New(); + this->Picker->SetTolerance(0.005); + this->Picker->AddPickList(this->myCutActor1); + this->Picker->AddPickList(this->myCutActor2); + this->Picker->AddPickList(this->LineActor); + this->Picker->AddPickList(this->ConeActor); + this->Picker->AddPickList(this->LineActor2); + this->Picker->AddPickList(this->ConeActor2); + this->Picker->AddPickList(this->SphereActor); + this->Picker->AddPickList(this->myOutlineActor); + this->Picker->PickFromListOn(); + + // Set up the initial properties + this->CreateDefaultProperties(); + +} +//================================================================== +// function: ~ +// purpose : +//================================================================== +VISU_PlanesWidget::~VISU_PlanesWidget() +{ + myPlane1->Delete(); + + this->myPlane2->Delete(); + this->myImplicitFunction->Delete(); + + myBox->Delete(); + this->myOutline->Delete(); + this->myOutlineMapper->Delete(); + this->myOutlineActor->Delete(); + + this->myCutter1->Delete(); + this->myCutMapper1->Delete(); + this->myCutActor1->Delete(); + + this->myEdges1->Delete(); + this->myEdgesMapper1->Delete(); + this->myEdgesActor1->Delete(); + + myCutter2->Delete(); + myCutMapper2->Delete(); + myCutActor2->Delete(); + + myEdges2->Delete(); + myEdgesMapper2->Delete(); + myEdgesActor2->Delete(); + + this->LineSource->Delete(); + this->LineMapper->Delete(); + this->LineActor->Delete(); + + this->ConeSource->Delete(); + this->ConeMapper->Delete(); + this->ConeActor->Delete(); + + this->LineSource2->Delete(); + this->LineMapper2->Delete(); + this->LineActor2->Delete(); + + this->ConeSource2->Delete(); + this->ConeMapper2->Delete(); + this->ConeActor2->Delete(); + + this->Sphere->Delete(); + this->SphereMapper->Delete(); + this->SphereActor->Delete(); + + this->Transform->Delete(); + + this->Picker->Delete(); + + this->NormalProperty->Delete(); + this->SelectedNormalProperty->Delete(); + this->PlaneProperty->Delete(); + this->SelectedPlaneProperty->Delete(); + this->OutlineProperty->Delete(); + this->SelectedOutlineProperty->Delete(); + this->EdgesProperty->Delete(); +} +//================================================================== +// function: ImplicitFunction +// purpose : +//================================================================== +vtkImplicitFunction* VISU_PlanesWidget::ImplicitFunction() +{ + return this->myImplicitFunction; +} +//================================================================== +// function: SetDistance +// purpose : +//================================================================== +void VISU_PlanesWidget::SetDistance(const float theDistance) +{ + if( theDistance <= 0.0 || theDistance == myDistance ) + return; + + myDistance=theDistance; + // + float *origin, *normal, oNew[3], aN2[3]; + origin = myPlane1->GetOrigin(); + normal = myPlane1->GetNormal(); + vtkMath::Normalize(normal); + oNew[0] = origin[0] + myDistance*normal[0]; + oNew[1] = origin[1] + myDistance*normal[1]; + oNew[2] = origin[2] + myDistance*normal[2]; + myPlane2->SetOrigin(oNew); + aN2[0] = -normal[0]; + aN2[1] = -normal[1]; + aN2[2] = -normal[2]; + myPlane2->SetNormal(aN2); +} +//================================================================== +// function: Distance +// purpose : +//================================================================== +float VISU_PlanesWidget::Distance()const +{ + return myDistance; +} +//================================================================== +// function: SetEnabled +// purpose : +//================================================================== +void VISU_PlanesWidget::SetEnabled(int enabling) +{ + if ( ! this->Interactor ) { + vtkErrorMacro(<<"The interactor must be set prior to enabling/disabling widget"); + return; + } + + if ( enabling ) {//------------------------------------------------------------ + vtkDebugMacro(<<"Enabling plane widget"); + + if ( this->Enabled ){ //already enabled, just return + return; + } + + if ( ! this->CurrentRenderer ){ + this->CurrentRenderer = this->Interactor->FindPokedRenderer( + this->Interactor->GetLastEventPosition()[0], + this->Interactor->GetLastEventPosition()[1]); + if (this->CurrentRenderer == NULL) { + return; + } + } + // + vtkCamera *pCamera=CurrentRenderer->GetActiveCamera(); + pCamera->SetParallelProjection(1); + // + this->myImplicitFunction->AddFunction(myPlane1); + this->myImplicitFunction->AddFunction(this->myPlane2); + + this->Enabled = 1; + + // listen for the following events + vtkRenderWindowInteractor *i = this->Interactor; + if( this->HandleMoveEvent ) { + i->AddObserver(vtkCommand::MouseMoveEvent, + this->EventCallbackCommand, + this->Priority); + } + if( this->HandleLeftButtonEvent ) { + i->AddObserver(vtkCommand::LeftButtonPressEvent, + this->EventCallbackCommand, + this->Priority); + i->AddObserver(vtkCommand::LeftButtonReleaseEvent, + this->EventCallbackCommand, + this->Priority); + } + if( this->HandleMiddleButtonEvent ) { + i->AddObserver(vtkCommand::MiddleButtonPressEvent, + this->EventCallbackCommand, + this->Priority); + i->AddObserver(vtkCommand::MiddleButtonReleaseEvent, + this->EventCallbackCommand, + this->Priority); + } + if( this->HandleRightButtonEvent ) { + i->AddObserver(vtkCommand::RightButtonPressEvent, + this->EventCallbackCommand, + this->Priority); + i->AddObserver(vtkCommand::RightButtonReleaseEvent, + this->EventCallbackCommand, + this->Priority); + } + // add the outline + this->CurrentRenderer->AddActor(this->myOutlineActor); + this->myOutlineActor->SetProperty(this->OutlineProperty); + + // add the edges + this->CurrentRenderer->AddActor(this->myEdgesActor1); + this->CurrentRenderer->AddActor(myEdgesActor2); + + this->myOutlineActor->SetProperty(this->EdgesProperty); + + // add the normal vector + this->CurrentRenderer->AddActor(this->LineActor); + this->LineActor->SetProperty(this->NormalProperty); + this->CurrentRenderer->AddActor(this->ConeActor); + this->ConeActor->SetProperty(this->NormalProperty); + + this->CurrentRenderer->AddActor(this->LineActor2); + this->LineActor2->SetProperty(this->NormalProperty); + this->CurrentRenderer->AddActor(this->ConeActor2); + this->ConeActor2->SetProperty(this->NormalProperty); + + // add the origin handle + this->CurrentRenderer->AddActor(this->SphereActor); + this->SphereActor->SetProperty(this->NormalProperty); + + // add the plane (if desired) + if ( this->myDrawPlane ) { + this->CurrentRenderer->AddActor(this->myCutActor1); + this->CurrentRenderer->AddActor(this->myCutActor2); + } + this->myCutActor1->SetProperty(this->PlaneProperty); + myCutActor2->SetProperty(this->PlaneProperty); + + this->UpdateRepresentation(); + //this->SizeHandles(); + this->InvokeEvent(vtkCommand::EnableEvent,NULL); + } + + else {//disabling---------------------------------------------------------- + vtkDebugMacro(<<"Disabling plane widget"); + + if ( ! this->Enabled ) {//already disabled, just return + return; + } + + if(vtkImplicitFunctionCollection* aFunction = this->myImplicitFunction->GetFunction()){ + aFunction->RemoveAllItems(); + this->myImplicitFunction->Modified(); // VTK bug + } + + this->Enabled = 0; + + // don't listen for events any more + this->Interactor->RemoveObserver(this->EventCallbackCommand); + + // turn off the various actors + this->CurrentRenderer->RemoveActor(this->myOutlineActor); + this->CurrentRenderer->RemoveActor(this->myEdgesActor1); + this->CurrentRenderer->RemoveActor(myEdgesActor2); + this->CurrentRenderer->RemoveActor(this->LineActor); + this->CurrentRenderer->RemoveActor(this->ConeActor); + this->CurrentRenderer->RemoveActor(this->LineActor2); + this->CurrentRenderer->RemoveActor(this->ConeActor2); + this->CurrentRenderer->RemoveActor(this->SphereActor); + this->CurrentRenderer->RemoveActor(this->myCutActor1); + this->CurrentRenderer->RemoveActor(myCutActor2); + + this->InvokeEvent(vtkCommand::DisableEvent,NULL); + this->CurrentRenderer = NULL; + } + + this->Interactor->Render(); +} +//================================================================== +// function: ProcessEvents +// purpose : +//================================================================== +void VISU_PlanesWidget::ProcessEvents(vtkObject* vtkNotUsed(object), + unsigned long event, + void* clientdata, + void* vtkNotUsed(calldata)) +{ + VISU_PlanesWidget* self = + reinterpret_cast( clientdata ); + + //okay, let's do the right thing + switch(event) + { + case vtkCommand::LeftButtonPressEvent: + self->OnLeftButtonDown(); + break; + case vtkCommand::LeftButtonReleaseEvent: + self->OnLeftButtonUp(); + break; + case vtkCommand::MiddleButtonPressEvent: + self->OnMiddleButtonDown(); + break; + case vtkCommand::MiddleButtonReleaseEvent: + self->OnMiddleButtonUp(); + break; + case vtkCommand::RightButtonPressEvent: + self->OnRightButtonDown(); + break; + case vtkCommand::RightButtonReleaseEvent: + self->OnRightButtonUp(); + break; + case vtkCommand::MouseMoveEvent: + self->OnMouseMove(); + break; + default: + break; + } +} +//================================================================== +// function: HighlightNormal +// purpose : +//================================================================== +void VISU_PlanesWidget::HighlightNormal(int highlight) +{ + if ( highlight ) { + this->LineActor->SetProperty(this->SelectedNormalProperty); + this->ConeActor->SetProperty(this->SelectedNormalProperty); + this->LineActor2->SetProperty(this->SelectedNormalProperty); + this->ConeActor2->SetProperty(this->SelectedNormalProperty); + this->SphereActor->SetProperty(this->SelectedNormalProperty); + } + else + { + this->LineActor->SetProperty(this->NormalProperty); + this->ConeActor->SetProperty(this->NormalProperty); + this->LineActor2->SetProperty(this->NormalProperty); + this->ConeActor2->SetProperty(this->NormalProperty); + this->SphereActor->SetProperty(this->NormalProperty); + } +} +//================================================================== +// function: HighlightPlane +// purpose : +//================================================================== +void VISU_PlanesWidget::HighlightPlane(int highlight) +{ + if ( highlight ) { + this->myCutActor1->SetProperty(this->SelectedPlaneProperty); + myCutActor2->SetProperty(this->SelectedPlaneProperty); + } + else { + this->myCutActor1->SetProperty(this->PlaneProperty); + myCutActor2->SetProperty(this->PlaneProperty); + } +} +//================================================================== +// function: HighlightOutline +// purpose : +//================================================================== +void VISU_PlanesWidget::HighlightOutline(int highlight) +{ + if (highlight) { + this->myOutlineActor->SetProperty(this->SelectedOutlineProperty); + } + else { + this->myOutlineActor->SetProperty(this->OutlineProperty); + } +} +//================================================================== +// function: OnLeftButtonDown +// purpose : +//================================================================== +void VISU_PlanesWidget::OnLeftButtonDown() +{ + // We're only here if we are enabled + int X = this->Interactor->GetEventPosition()[0]; + int Y = this->Interactor->GetEventPosition()[1]; + // + // Okay, we can process this. See if we've picked anything. + // Make sure it's in the activated renderer + vtkRenderer *ren = this->Interactor->FindPokedRenderer(X,Y); + if ( ren != this->CurrentRenderer ) { + this->State = VISU_PlanesWidget::Outside; + return; + } + + vtkAssemblyPath *path; + this->Picker->Pick(X,Y,0.0,this->CurrentRenderer); + path = this->Picker->GetPath(); + + if ( path == NULL ) {//not picking this widget + this->HighlightPlane(0); + this->HighlightNormal(0); + this->HighlightOutline(0); + this->State = VISU_PlanesWidget::Outside; + return; + } + + vtkProp *prop = path->GetFirstNode()->GetProp(); + this->ValidPick = 1; + this->Picker->GetPickPosition(this->LastPickPosition); + // + if ( prop == this->ConeActor || prop == this->LineActor || + prop == this->ConeActor2 || prop == this->LineActor2 ) { + this->HighlightPlane(1); + this->HighlightNormal(1); + this->State = VISU_PlanesWidget::Rotating; + } + else if ( prop == this->myCutActor1) { + this->HighlightPlane(1); + this->State = VISU_PlanesWidget::Pushing; + } + else if ( prop == this->SphereActor ) { + this->HighlightNormal(1); + this->State = VISU_PlanesWidget::MovingOrigin; + } + else if (prop == myCutActor2) { + this->HighlightPlane(1); + this->State = VISU_PlanesWidget::ChangeDistance; + } + else { + if ( this->OutlineTranslation ) { + this->HighlightOutline(1); + this->State = VISU_PlanesWidget::MovingOutline; + } + } + + this->EventCallbackCommand->SetAbortFlag(1); + this->StartInteraction(); + this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL); + this->Interactor->Render(); +} +//================================================================== +// function: OnLeftButtonUp +// purpose : +//================================================================== +void VISU_PlanesWidget::OnLeftButtonUp() +{ + if ( this->State == VISU_PlanesWidget::Outside ) { + return; + } + + this->State = VISU_PlanesWidget::Start; + this->HighlightPlane(0); + this->HighlightOutline(0); + this->HighlightNormal(0); + //this->SizeHandles(); + + this->EventCallbackCommand->SetAbortFlag(1); + this->EndInteraction(); + this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); + this->Interactor->Render(); +} +//================================================================== +// function: OnMiddleButtonDown +// purpose : +//================================================================== +void VISU_PlanesWidget::OnMiddleButtonDown() +{ + int X = this->Interactor->GetEventPosition()[0]; + int Y = this->Interactor->GetEventPosition()[1]; + + // Okay, we can process this. See if we've picked anything. + // Make sure it's in the activated renderer + vtkRenderer *ren = this->Interactor->FindPokedRenderer(X,Y); + if ( ren != this->CurrentRenderer ) { + this->State = VISU_PlanesWidget::Outside; + return; + } + + // Okay, we can process this. + vtkAssemblyPath *path; + this->Picker->Pick(X,Y,0.0,this->CurrentRenderer); + path = this->Picker->GetPath(); + + if ( path == NULL ) {//nothing picked + this->State = VISU_PlanesWidget::Outside; + return; + } + + this->ValidPick = 1; + this->Picker->GetPickPosition(this->LastPickPosition); + this->State = VISU_PlanesWidget::MovingPlane; + this->HighlightNormal(1); + this->HighlightPlane(1); + + this->EventCallbackCommand->SetAbortFlag(1); + this->StartInteraction(); + this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL); + this->Interactor->Render(); +} +//================================================================== +// function: OnMiddleButtonUp +// purpose : +//================================================================== +void VISU_PlanesWidget::OnMiddleButtonUp() +{ + if ( this->State == VISU_PlanesWidget::Outside ) { + return; + } + + this->State = VISU_PlanesWidget::Start; + this->HighlightPlane(0); + this->HighlightOutline(0); + this->HighlightNormal(0); + //this->SizeHandles(); + + this->EventCallbackCommand->SetAbortFlag(1); + this->EndInteraction(); + this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); + this->Interactor->Render(); +} +//================================================================== +// function: OnRightButtonDown +// purpose : +//================================================================== +void VISU_PlanesWidget::OnRightButtonDown() +{ + this->State = VISU_PlanesWidget::Scaling; + + int X = this->Interactor->GetEventPosition()[0]; + int Y = this->Interactor->GetEventPosition()[1]; + + // Okay, we can process this. See if we've picked anything. + // Make sure it's in the activated renderer + vtkRenderer *ren = this->Interactor->FindPokedRenderer(X,Y); + if ( ren != this->CurrentRenderer ) { + this->State = VISU_PlanesWidget::Outside; + return; + } + + // Okay, we can process this. Try to pick handles first; + // if no handles picked, then pick the bounding box. + vtkAssemblyPath *path; + this->Picker->Pick(X,Y,0.0,this->CurrentRenderer); + path = this->Picker->GetPath(); + if ( path == NULL ){ //nothing picked + this->State = VISU_PlanesWidget::Outside; + return; + } + + this->ValidPick = 1; + this->Picker->GetPickPosition(this->LastPickPosition); + this->HighlightPlane(1); + this->HighlightOutline(1); + this->HighlightNormal(1); + + this->EventCallbackCommand->SetAbortFlag(1); + this->StartInteraction(); + this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL); + this->Interactor->Render(); +} +//================================================================== +// function: OnRightButtonUp +// purpose : +//================================================================== +void VISU_PlanesWidget::OnRightButtonUp() +{ + if ( this->State == VISU_PlanesWidget::Outside ) { + return; + } + + this->State = VISU_PlanesWidget::Start; + this->HighlightPlane(0); + this->HighlightOutline(0); + this->HighlightNormal(0); + //this->SizeHandles(); + + this->EventCallbackCommand->SetAbortFlag(1); + this->EndInteraction(); + this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); + this->Interactor->Render(); +} +//================================================================== +// function: OnMouseMove +// purpose : +//================================================================== +void VISU_PlanesWidget::OnMouseMove() +{ + //this->SizeHandles(); + + // See whether we're active + if ( this->State == VISU_PlanesWidget::Outside || + this->State == VISU_PlanesWidget::Start ) { + return; + } + + int X = this->Interactor->GetEventPosition()[0]; + int Y = this->Interactor->GetEventPosition()[1]; + + // Do different things depending on state + // Calculations everybody does + double focalPoint[4], pickPoint[4], prevPickPoint[4]; + double z, vpn[3]; + + vtkCamera *camera = this->CurrentRenderer->GetActiveCamera(); + if ( !camera ) { + return; + } + + // Compute the two points defining the motion vector + this->ComputeWorldToDisplay(this->LastPickPosition[0], this->LastPickPosition[1], + this->LastPickPosition[2], focalPoint); + z = focalPoint[2]; + this->ComputeDisplayToWorld(double(this->Interactor->GetLastEventPosition()[0]), + double(this->Interactor->GetLastEventPosition()[1]), + z, prevPickPoint); + this->ComputeDisplayToWorld(double(X), double(Y), z, pickPoint); + + // Process the motion + if ( this->State == VISU_PlanesWidget::MovingPlane ) { + //this->TranslatePlane(prevPickPoint, pickPoint); + //printf(" TranslatePlane\n"); + } + else if ( this->State == VISU_PlanesWidget::MovingOutline ) { + //this->TranslateOutline(prevPickPoint, pickPoint); + //printf(" TranslateOutline\n"); + } + else if ( this->State == VISU_PlanesWidget::MovingOrigin ) { + this->TranslateOrigin(prevPickPoint, pickPoint); + //printf(" TranslateOrigin\n"); + } + else if ( this->State == VISU_PlanesWidget::Pushing ) { + this->Push(prevPickPoint, pickPoint); + // printf(" Push\n"); + } + else if ( this->State == VISU_PlanesWidget::Scaling ) { + //this->Scale(prevPickPoint, pickPoint, X, Y); + //printf(" Scale\n"); + } + else if ( this->State == VISU_PlanesWidget::Rotating ) { + camera->GetViewPlaneNormal(vpn); + this->Rotate(X, Y, prevPickPoint, pickPoint, vpn); + //printf(" Rotate\n"); + } + else if ( this->State == VISU_PlanesWidget::ChangeDistance ) { + this->PushDistance(prevPickPoint, pickPoint); + //printf(" PushDistance\n"); + } + // Interact, if desired + this->EventCallbackCommand->SetAbortFlag(1); + this->InvokeEvent(vtkCommand::InteractionEvent,NULL); + + this->Interactor->Render(); +} +//================================================================== +// function: Push +// purpose : +//================================================================== +void VISU_PlanesWidget::Push(double *p1, double *p2) +{ + //Get the motion vector + int i; + float v[3]; + // + for (i=0; i<3; ++i){ + v[i] = p2[i] - p1[i]; + } + // + float aOr1[3], aNr1[3], aNr2[3], aD, z1; + // + myPlane1->GetOrigin(aOr1); + myPlane1->GetNormal(aNr1); + myPlane2->GetNormal(aNr2); + // + aD=vtkMath::Dot(v, aNr2); + z1 = aOr1[2]+aD*aNr2[2]; + if( z1 <= myBox->GetOrigin()[2] ){ + return; + } + // + aD=vtkMath::Dot(v, aNr1); + for (i=0; i < 3; ++i) { + aOr1[i]=aOr1[i]+aD*aNr1[i]; + } + SetOriginInternal(aOr1); + this->UpdateRepresentation(); +} +//================================================================== +// function: TranslateOrigin +// purpose : +//================================================================== +void VISU_PlanesWidget::TranslateOrigin(double *p1, double *p2) +{ + //Get the motion vector + int i; + double v[3]; + // + for (i=0; i<3; ++i){ + v[i] = p2[i] - p1[i]; + } + // + //Add to the current point, project back down onto plane + float *o = myPlane1->GetOrigin(); + float *n = myPlane1->GetNormal(); + float newOrigin[3]; + // + for (i=0; i<3; ++i){ + newOrigin[i]=o[i] + v[i]; + } + vtkPlane::ProjectPoint(newOrigin, o, n, newOrigin); + SetOriginInternal(newOrigin); + this->UpdateRepresentation(); +} +//================================================================== +// function: SetOriginInternal +// purpose : Set the origin of the plane.(for Internal calls) +//================================================================== +void VISU_PlanesWidget::SetOriginInternal(float x[3]) +{ + float *bounds = this->myOutline->GetOutput()->GetBounds(); + int i, j; + for (i=0; i<3; ++i) { + j=2*i; + if ( x[i] < bounds[j] ) { + x[i] = bounds[j]; + } + else if ( x[i] > bounds[j+1] ) { + x[i] = bounds[j+1]; + } + } + // + bool bFlag; + float aOr2[3], aNr2[3], aNr1[3]; + vtkPlane *pPx; + // + myPlane1->GetNormal(aNr1); + myPlane2->GetNormal(aNr2); + for (i=0; i<3; ++i) { + aOr2[i]=x[i]+myDistance*aNr1[i]; + } + pPx=vtkPlane::New(); + pPx->SetOrigin(aOr2); + pPx->SetNormal(aNr2); + bFlag=IsValidPlane2Position(pPx, myBox); + if (bFlag){ + myPlane1->SetOrigin(x); + myPlane2->SetOrigin(aOr2); + } + pPx->Delete(); +} +//================================================================== +// function: Rotate +// purpose : +//================================================================== +void VISU_PlanesWidget::Rotate(int X, int Y, + double *p1, double *p2, + double *vpn) +{ + double v[3]; //vector of motion + double axis[3]; //axis of rotation + double theta; //rotation angle + int i; + + // mouse motion vector in world space + for (i=0; i<3; ++i){ + v[i] = p2[i] - p1[i]; + } + // + float *origin = myPlane1->GetOrigin(); + float *normal = myPlane1->GetNormal(); + + // Create axis of rotation and angle of rotation + vtkMath::Cross(vpn,v,axis); + if ( vtkMath::Normalize(axis) == 0.0 ) { + return; + } + + int *size = this->CurrentRenderer->GetSize(); + double l2 = (X-this->Interactor->GetLastEventPosition()[0])* + (X-this->Interactor->GetLastEventPosition()[0]) + + (Y-this->Interactor->GetLastEventPosition()[1])* + (Y-this->Interactor->GetLastEventPosition()[1]); + theta = 360.0 * sqrt(l2/((double)size[0]*size[0]+size[1]*size[1])); + + //Manipulate the transform to reflect the rotation + this->Transform->Identity(); + this->Transform->Translate(origin[0],origin[1],origin[2]); + this->Transform->RotateWXYZ(theta,axis); + this->Transform->Translate(-origin[0],-origin[1],-origin[2]); + + //Set the new normal + float nNew[3], aN2[3], oNew[3]; + this->Transform->TransformNormal(normal,nNew); + // + for (i=0; i<3; ++i){ + aN2[i] = -nNew[i]; + } + vtkMath::Normalize(nNew); + for (i=0; i<3; ++i){ + oNew[i] = origin[i] + myDistance*nNew[i]; + } + // + vtkPlane *pPx=vtkPlane::New(); + pPx->SetNormal(aN2); + pPx->SetOrigin(oNew); + // + bool bFlag=IsValidPlane2Position(pPx, myBox); + if (bFlag) { + myPlane1->SetNormal(nNew); + this->myPlane2->SetNormal(aN2); + this->myPlane2->SetOrigin(oNew); + } + pPx->Delete(); + this->UpdateRepresentation(); +} +//================================================================== +// function: PushDistance +// purpose : +//================================================================== +void VISU_PlanesWidget::PushDistance(double *p1, double *p2) +{ + int i; + float v[3], *anOrigin1, *aN1, *anOrigin2, *aN2, aD; + //Get the motion vector + for (i=0; i<3; ++i){ + v[i] = p2[i] - p1[i]; + } + // + anOrigin1 = myPlane1->GetOrigin(); + aN1 = myPlane1->GetNormal(); + anOrigin2 = myPlane2->GetOrigin(); + aN2 = myPlane2->GetNormal(); + + vtkMath::Normalize(aN1); + + float origin[3]; + double distance = vtkMath::Dot( v, aN2 ); + for(i=0; i<3; ++i) { + origin[i] = anOrigin2[i] + distance * aN2[i]; + } + float d = DistanceToPlane(origin, aN1, anOrigin1); + if( d <= 0.0 ) + return; + // + bool bFlag; + float aOr2[3], aNr2[3]; + vtkPlane *pPx; + // + myPlane2->GetOrigin(aOr2); + myPlane2->GetNormal(aNr2); + pPx=vtkPlane::New(); + pPx->SetNormal(aNr2); + aD=vtkMath::Dot(v, aNr2); + for (i=0; i < 3; ++i) { + aOr2[i]=aOr2[i]+aD*aNr2[i]; + } + pPx->SetOrigin(aOr2); + bFlag=IsValidPlane2Position(pPx, myBox); + if(bFlag) { + myPlane2->SetOrigin(aOr2); + myPlane2->Modified(); + aD=DistanceToPlane(aOr2, aN1, anOrigin1); + // + myDistance=aD; + } + pPx->Delete(); + this->UpdateRepresentation(); +} + +//================================================================== +// function: TranslatePlane +// purpose : Loop through all points and translate them +//================================================================== +void VISU_PlanesWidget::TranslatePlane(double *p1, double *p2) +{ + //Get the motion vector + double v[3]; + v[0] = p2[0] - p1[0]; + v[1] = p2[1] - p1[1]; + v[2] = p2[2] - p1[2]; + + //Translate the plane + float oNew[3]; + float *origin = myPlane1->GetOrigin(); + oNew[0] = origin[0] + v[0]; + oNew[1] = origin[1] + v[1]; + oNew[2] = origin[2] + v[2]; + myPlane1->SetOrigin(oNew); + + origin = this->myPlane2->GetOrigin(); + oNew[0] = origin[0] + v[0]; + oNew[1] = origin[1] + v[1]; + oNew[2] = origin[2] + v[2]; + this->myPlane2->SetOrigin(oNew); + + this->UpdateRepresentation(); +} +//================================================================== +// function: TranslateOutline +// purpose :Loop through all points and translate them +//================================================================== +void VISU_PlanesWidget::TranslateOutline(double *p1, double *p2) +{ + //Get the motion vector + double v[3]; + v[0] = p2[0] - p1[0]; + v[1] = p2[1] - p1[1]; + v[2] = p2[2] - p1[2]; + + //Translate the bounding box + float *origin = myBox->GetOrigin(); + float oNew[3]; + oNew[0] = origin[0] + v[0]; + oNew[1] = origin[1] + v[1]; + oNew[2] = origin[2] + v[2]; + myBox->SetOrigin(oNew); + + //Translate the plane + origin = myPlane1->GetOrigin(); + oNew[0] = origin[0] + v[0]; + oNew[1] = origin[1] + v[1]; + oNew[2] = origin[2] + v[2]; + myPlane1->SetOrigin(oNew); + + origin = this->myPlane2->GetOrigin(); + oNew[0] = origin[0] + v[0]; + oNew[1] = origin[1] + v[1]; + oNew[2] = origin[2] + v[2]; + this->myPlane2->SetOrigin(oNew); + + this->UpdateRepresentation(); +} + +//================================================================== +// function: Scale +// purpose : +//================================================================== +void VISU_PlanesWidget::Scale(double *p1, double *p2, + int vtkNotUsed(X), int Y) +{ + //Get the motion vector + double v[3]; + v[0] = p2[0] - p1[0]; + v[1] = p2[1] - p1[1]; + v[2] = p2[2] - p1[2]; + + //int res = this->PlaneSource->GetXResolution(); + float *o = myPlane1->GetOrigin(); + + // Compute the scale factor + float sf = vtkMath::Norm(v) / this->myOutline->GetOutput()->GetLength(); + if ( Y > this->Interactor->GetLastEventPosition()[1] ) { + sf = 1.0 + sf; + } + else { + sf = 1.0 - sf; + } + + this->Transform->Identity(); + this->Transform->Translate(o[0],o[1],o[2]); + this->Transform->Scale(sf,sf,sf); + this->Transform->Translate(-o[0],-o[1],-o[2]); + + float *origin = myBox->GetOrigin(); + float *spacing = myBox->GetSpacing(); + float oNew[3], p[3], pNew[3]; + p[0] = origin[0] + spacing[0]; + p[1] = origin[1] + spacing[1]; + p[2] = origin[2] + spacing[2]; + + this->Transform->TransformPoint(origin,oNew); + this->Transform->TransformPoint(p,pNew); + + myBox->SetOrigin(oNew); + myBox->SetSpacing( (pNew[0]-oNew[0]), (pNew[1]-oNew[1]), (pNew[2]-oNew[2]) ); + + this->UpdateRepresentation(); +} + + + +//================================================================== +// function: CreateDefaultProperties +// purpose : +//================================================================== +void VISU_PlanesWidget::CreateDefaultProperties() +{ + // Normal properties + this->NormalProperty = vtkProperty::New(); + this->NormalProperty->SetColor(1,1,1); + this->NormalProperty->SetLineWidth(2); + + this->SelectedNormalProperty = vtkProperty::New(); + this->SelectedNormalProperty->SetColor(1,0,0); + this->NormalProperty->SetLineWidth(2); + + // Plane properties + this->PlaneProperty = vtkProperty::New(); + this->PlaneProperty->SetAmbient(1.0); + this->PlaneProperty->SetAmbientColor(1.0,1.0,1.0); + + this->SelectedPlaneProperty = vtkProperty::New(); + this->SelectedPlaneProperty->SetAmbient(1.0); + this->SelectedPlaneProperty->SetAmbientColor(0.0,1.0,0.0); + this->SelectedPlaneProperty->SetOpacity(0.25); + + // Outline properties + this->OutlineProperty = vtkProperty::New(); + this->OutlineProperty->SetAmbient(1.0); + this->OutlineProperty->SetAmbientColor(1.0,1.0,1.0); + + this->SelectedOutlineProperty = vtkProperty::New(); + this->SelectedOutlineProperty->SetAmbient(1.0); + this->SelectedOutlineProperty->SetAmbientColor(0.0,1.0,0.0); + + // Edge property + this->EdgesProperty = vtkProperty::New(); + this->EdgesProperty->SetAmbient(1.0); + this->EdgesProperty->SetAmbientColor(1.0,1.0,1.0); +} +//================================================================== +// function: InitialPlaceWidget +// purpose : +//================================================================== +void VISU_PlanesWidget::InitialPlaceWidget(float bds[6]) +{ + float bounds[6], origin[3]; + + PlaceWidget(bds); + // + this->AdjustBounds(bds, bounds, origin); + this->SetOrigin((bounds[1]+bounds[0])/2.0, + (bounds[3]+bounds[2])/2.0, + (bounds[5]+bounds[4])/2.0); + + static float DIST_COEFF = 0.1; + SetDistance(this->InitialLength*DIST_COEFF); + // + this->UpdateRepresentation(); +} +//================================================================== +// function: PlaceWidget +// purpose : +//================================================================== +void VISU_PlanesWidget::PlaceWidget(float bds[6]) +{ + int i; + float bounds[6], origin[3]; + + this->AdjustBounds(bds, bounds, origin); + + // Set up the bounding box + myBox->SetOrigin(bounds[0],bounds[2],bounds[4]); + myBox->SetSpacing((bounds[1]-bounds[0]),(bounds[3]-bounds[2]), + (bounds[5]-bounds[4])); + this->myOutline->Update(); + + if (this->Input || this->Prop3D) { + this->LineSource->SetPoint1(myPlane1->GetOrigin()); + if ( this->NormalToYAxis ) { + myPlane1->SetNormal(0,1,0); + myPlane2->SetNormal(0,-1,0); + this->LineSource->SetPoint2(0,1,0); + } + else if ( this->NormalToZAxis ) { + myPlane1->SetNormal(0,0,1); + myPlane2->SetNormal(0,0,-1); + this->LineSource->SetPoint2(0,0,1); + } + else{ //default or x-normal + myPlane1->SetNormal(1,0,0); + myPlane2->SetNormal(-1,0,0); + this->LineSource->SetPoint2(1,0,0); + } + } + + for (i=0; i<6; i++) { + this->InitialBounds[i] = bounds[i]; + } + + this->InitialLength = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) + + (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) + + (bounds[5]-bounds[4])*(bounds[5]-bounds[4])); + + this->UpdateRepresentation(); +} +//================================================================== +// function: SetOrigin +// purpose :Set the origin of the plane.(for external calls) +//================================================================== +void VISU_PlanesWidget::SetOrigin(float x, float y, float z) +{ + float origin[3]; + origin[0] = x; + origin[1] = y; + origin[2] = z; + this->SetOrigin(origin); +} +//================================================================== +// function: SetOrigin +// purpose : Set the origin of the plane.(for external calls) +//================================================================== +void VISU_PlanesWidget::SetOrigin(float x[3]) +{ + float *bounds = this->myOutline->GetOutput()->GetBounds(); + for (int i=0; i<3; i++) { + if ( x[i] < bounds[2*i] ) { + x[i] = bounds[2*i]; + } + else if ( x[i] > bounds[2*i+1] ) { + x[i] = bounds[2*i+1]; + } + } + myPlane1->SetOrigin(x); + float *origin, *normal, oNew[3]; + origin = myPlane1->GetOrigin(); + normal = myPlane1->GetNormal(); + vtkMath::Normalize(normal); + oNew[0] = origin[0] + myDistance*normal[0]; + oNew[1] = origin[1] + myDistance*normal[1]; + oNew[2] = origin[2] + myDistance*normal[2]; + this->myPlane2->SetOrigin(oNew); + this->UpdateRepresentation(); +} +//================================================================== +// function: GetOrigin +// purpose :Get the origin of the plane. +//================================================================== +float* VISU_PlanesWidget::GetOrigin() +{ + return myPlane1->GetOrigin(); +} + +void VISU_PlanesWidget::GetOrigin(float xyz[3]) +{ + myPlane1->GetOrigin(xyz); +} +//================================================================== +// function: SetNormal +// purpose :Set the normal to the plane. +//================================================================== +void VISU_PlanesWidget::SetNormal(float x, float y, float z) +{ + float n[3]; + n[0] = x; + n[1] = y; + n[2] = z; + vtkMath::Normalize(n); + myPlane1->SetNormal(n); + n[0] =- x; + n[1] =- y; + n[2] =- z; + this->myPlane2->SetNormal(n); + + this->UpdateRepresentation(); +} + +//================================================================== +// function: SetNormal +// purpose :Set the normal to the plane. +//================================================================== +void VISU_PlanesWidget::SetNormal(float n[3]) +{ + this->SetNormal(n[0], n[1], n[2]); +} +//================================================================== +// function: GetNormal +// purpose :Get the normal to the plane. +//================================================================== +float* VISU_PlanesWidget::GetNormal() +{ + return myPlane1->GetNormal(); +} +//================================================================== +// function: GetNormal +// purpose :Get the normal to the plane. +//================================================================== +void VISU_PlanesWidget::GetNormal(float xyz[3]) +{ + myPlane1->GetNormal(xyz); +} +//================================================================== +// function: SetDrawPlane +// purpose : +//================================================================== +void VISU_PlanesWidget::SetDrawPlane(int drawPlane) +{ + if ( drawPlane == this->myDrawPlane ) { + return; + } + + this->Modified(); + this->myDrawPlane = drawPlane; + if ( this->Enabled ) { + if ( drawPlane ) { + this->CurrentRenderer->AddActor(this->myCutActor1); + this->CurrentRenderer->AddActor(myCutActor2); + } + else { + this->CurrentRenderer->RemoveActor(this->myCutActor1); + this->CurrentRenderer->RemoveActor(myCutActor2); + } + this->Interactor->Render(); + } +} +//================================================================== +// function: SetNormalToXAxis +// purpose : +//================================================================== +void VISU_PlanesWidget::SetNormalToXAxis (int var) +{ + if (this->NormalToXAxis != var) { + this->NormalToXAxis = var; + this->Modified(); + } + if (var) { + this->NormalToYAxisOff(); + this->NormalToZAxisOff(); + } +} +//================================================================== +// function: SetNormalToYAxis +// purpose : +//================================================================== +void VISU_PlanesWidget::SetNormalToYAxis (int var) +{ + if (this->NormalToYAxis != var) { + this->NormalToYAxis = var; + this->Modified(); + } + if (var) { + this->NormalToXAxisOff(); + this->NormalToZAxisOff(); + } +} +//================================================================== +// function: SetNormalToZAxis +// purpose : +//================================================================== +void VISU_PlanesWidget::SetNormalToZAxis (int var) +{ + if (this->NormalToZAxis != var) { + this->NormalToZAxis = var; + this->Modified(); + } + if (var) { + this->NormalToXAxisOff(); + this->NormalToYAxisOff(); + } +} +//================================================================== +// function: GetPolyData +// purpose : +//================================================================== +void VISU_PlanesWidget::GetPolyData(vtkPolyData *pd) +{ + pd->ShallowCopy(this->myCutter1->GetOutput()); +} +//================================================================== +// function: GetPolyDataSource +// purpose : +//================================================================== +/* +vtkPolyDataSource *VISU_PlanesWidget::GetPolyDataSource() +{ + return this->myCutter1; +} +*/ +//================================================================== +// function:GetPlane +// purpose : +//================================================================== +void VISU_PlanesWidget::GetPlane(vtkPlane *plane) +{ + if ( plane == NULL ) { + return; + } + + plane->SetNormal(myPlane1->GetNormal()); + plane->SetOrigin(myPlane1->GetOrigin()); +} +//================================================================== +// function:UpdatePlacement +// purpose : +//================================================================== +void VISU_PlanesWidget::UpdatePlacement(void) +{ + this->myOutline->Update(); + this->myCutter1->Update(); + this->myEdges1->Update(); +} +//================================================================== +// function:UpdateRepresentation +// purpose : +//================================================================== +void VISU_PlanesWidget::UpdateRepresentation() +{ + if ( ! this->CurrentRenderer ) { + return; + } + + float *origin = myPlane1->GetOrigin(); + float *normal = myPlane1->GetNormal(); + float p2[3]; + + // Setup the plane normal + float d = this->myOutline->GetOutput()->GetLength(); + + p2[0] = origin[0] + 0.30 * d * normal[0]; + p2[1] = origin[1] + 0.30 * d * normal[1]; + p2[2] = origin[2] + 0.30 * d * normal[2]; + + this->LineSource->SetPoint1(origin); + this->LineSource->SetPoint2(p2); + this->ConeSource->SetCenter(p2); + this->ConeSource->SetDirection(normal); + ConeActor->SetCenter(p2); + + p2[0] = origin[0] - 0.30 * d * normal[0]; + p2[1] = origin[1] - 0.30 * d * normal[1]; + p2[2] = origin[2] - 0.30 * d * normal[2]; + + this->LineSource2->SetPoint1(origin); + this->LineSource2->SetPoint2(p2); + this->ConeSource2->SetCenter(p2); + this->ConeSource2->SetDirection(normal); + ConeActor2->SetCenter(p2); + + // Set up the position handle + this->Sphere->SetCenter(origin); + SphereActor->SetCenter(origin); + + this->myEdgesMapper1->SetInput(this->myEdges1->GetOutput()); +} + +//================================================================== +// function:PrintSelf +// purpose : +//================================================================== +void VISU_PlanesWidget::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); +} +//================================================================== +// function: IsValidPlane2Position +// purpose : +//================================================================== +bool IsValidPlane2Position(vtkPlane *pPx, + vtkDataSet *pDataSet, + float aTol) +{ + bool bRet; + int i, iFound; + float aD, aDmax, aPnts[24], aDiagonal; + float aTol1, aOr[3], aN[3]; + // + bRet=false; + aDiagonal=pDataSet->GetLength(); + aTol1=aDiagonal*aTol; + // + GetBndPoints(pDataSet, aPnts); + // + pPx->GetOrigin(aOr); + pPx->GetNormal(aN); + vtkMath::Normalize(aN); + // + iFound=0; + aDmax=0.; + for (i=0; i<24; i+=3){ + aD=-DistanceToPlane(aPnts+i, aN, aOr); + if (aD>aDmax){ + aDmax=aD; + iFound=1; + } + } + if (iFound && aDmax>aTol1) { + bRet=!bRet; + } + return bRet; +} +//================================================================== +// function: GetBndPoints +// purpose : +//================================================================== +void GetBndPoints(vtkDataSet *pDataSet, + float aPnts[24]) +{ + int aIndx[24]={ + 0,2,4,1,2,4,1,3,4,0,3,4, + 0,2,5,1,2,5,1,3,5,0,3,5 + }; + int i; + float *pBounds=pDataSet->GetBounds(); + // + for (i=0; i<24; ++i){ + aPnts[i]=pBounds[aIndx[i]]; + } +} +//================================================================== +// function: DistanceToPlane +// purpose : +//================================================================== +float DistanceToPlane(const float x[3], + const float n[3], + const float p0[3]) +{ + return ((float) (n[0]*(x[0]-p0[0]) + + n[1]*(x[1]-p0[1]) + + n[2]*(x[2]-p0[2]))); +} +/* +//================================================================== +// function:SizeHandles +// purpose : +//================================================================== +void VISU_PlanesWidget::SizeHandles() +{ + // float radius = + this->vtk3DWidget::SizeHandles(1.35); +} +*/ diff --git a/src/PIPELINE/VISU_ImplicitFunctionWidget.h b/src/PIPELINE/VISU_PlanesWidget.hxx similarity index 93% rename from src/PIPELINE/VISU_ImplicitFunctionWidget.h rename to src/PIPELINE/VISU_PlanesWidget.hxx index 4930989d..fdf45367 100644 --- a/src/PIPELINE/VISU_ImplicitFunctionWidget.h +++ b/src/PIPELINE/VISU_PlanesWidget.hxx @@ -21,16 +21,15 @@ // // // -// File : VISU_ImplicitFunctionWidget.h +// File : VISU_PlanesWidget.h // Author : Peter KURNEV // Module : SALOME // $Header$ -#ifndef __VISU_ImplicitFunctionWidget_h -#define __VISU_ImplicitFunctionWidget_h - -#include +#ifndef __VISU_PlanesWidget_h +#define __VISU_PlanesWidget_h +#include "VISU_ImplicitFunctionWidget.hxx" class vtkActor; class vtkPolyDataMapper; class vtkCellPicker; @@ -50,27 +49,27 @@ class vtkImplicitFunction; class VISU_UnScaledActor; class vtkDataSet; -class VISU_ImplicitFunctionWidget : public vtkPolyDataSourceWidget +class VISU_PlanesWidget : public VISU_ImplicitFunctionWidget { public: // Description: // Instantiate the object. - static VISU_ImplicitFunctionWidget *New(); + static VISU_PlanesWidget *New(); - vtkTypeRevisionMacro(VISU_ImplicitFunctionWidget,vtkPolyDataSourceWidget); + vtkTypeRevisionMacro(VISU_PlanesWidget,VISU_ImplicitFunctionWidget); void PrintSelf(ostream& os, vtkIndent indent); void SetDistance (const float theDistance); float Distance()const; vtkGetMacro(InitialLength,float); - vtkImplicitFunction* ImplicitFunction(); + + virtual vtkImplicitFunction* ImplicitFunction(); // Description: // Methods that satisfy the superclass' API. virtual void SetEnabled(int); virtual void PlaceWidget(float bounds[6]); - int IsEnabled(); // Description: // Get the origin of the plane. @@ -134,7 +133,7 @@ public: // Description: // Satisfies superclass API. This returns a pointer to the underlying // PolyData (which represents the plane). - vtkPolyDataSource* GetPolyDataSource(); + //vtkPolyDataSource* GetPolyDataSource(); // Description: // Get the implicit function for the plane. The user must provide the @@ -172,8 +171,8 @@ public: void InitialPlaceWidget(float bds[6]); protected: - VISU_ImplicitFunctionWidget(); - ~VISU_ImplicitFunctionWidget(); + VISU_PlanesWidget(); + ~VISU_PlanesWidget(); //BTX - manage the state of the widget int State; @@ -217,7 +216,7 @@ protected: void CreateDefaultProperties(); void GeneratePlane(); - virtual void SizeHandles(); + //virtual void SizeHandles(); void HighlightPlane(int highlight); void HighlightNormal(int highlight); void HighlightOutline(int highlight); @@ -306,7 +305,7 @@ protected: vtkProperty *EdgesProperty; private: - VISU_ImplicitFunctionWidget(const VISU_ImplicitFunctionWidget&); //Not implemented + VISU_PlanesWidget(const VISU_PlanesWidget&); //Not implemented void operator=(const VISU_ImplicitFunctionWidget&); //Not implemented }; diff --git a/src/PIPELINE/VISU_SphereWidget.cxx b/src/PIPELINE/VISU_SphereWidget.cxx new file mode 100755 index 00000000..c2b46a61 --- /dev/null +++ b/src/PIPELINE/VISU_SphereWidget.cxx @@ -0,0 +1,718 @@ +#include "VISU_SphereWidget.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +vtkCxxRevisionMacro(VISU_SphereWidget, "$Revision$"); +vtkStandardNewMacro(VISU_SphereWidget); +//==================================================================== +// function: +// purpose: +//==================================================================== +VISU_SphereWidget::VISU_SphereWidget() +: + VISU_ImplicitFunctionWidget() +{ + int i, j; + // + myState = VISU_SphereWidget::Start; + this->EventCallbackCommand->SetCallback(VISU_SphereWidget::ProcessEvents); + + //Build the representation of the widget + // 1. sphere + mySphereSource = vtkSphereSource::New(); + mySphereSource->SetThetaResolution(16); + mySphereSource->SetPhiResolution(15); + mySphereSource->LatLongTessellationOn(); + mySphereMapper = vtkPolyDataMapper::New(); + mySphereMapper->SetInput(mySphereSource->GetOutput()); + mySphereActor = vtkActor::New(); + mySphereActor->SetMapper(mySphereMapper); + // + // 2. handle + myHandleSource=vtkSphereSource::New(); + myHandleSource->SetThetaResolution(16); + myHandleSource->SetPhiResolution(8); + myHandleMapper=vtkPolyDataMapper::New(); + myHandleMapper->SetInput(myHandleSource->GetOutput()); + myHandleActor=VISU_UnScaledActor::New(); + myHandleActor->SetMapper(myHandleMapper); + myHandleActor->SetSize(24); + myHandleActor->SetCenter(myHandleSource->GetCenter()); + myHandleActor->GetProperty()->SetColor(1.,0.,0.); + // + // Define the point coordinates + float bounds[6]; + for (i=0; i<3; ++i){ + j=2*i; + bounds[j]=-.5; + bounds[j+1]=-bounds[j]; + } + // Initial creation of the widget, serves to initialize it + PlaceWidget(bounds); + + //Manage the picking stuff + myPicker = vtkCellPicker::New(); + myPicker->SetTolerance(0.005); //need some fluff + myPicker->AddPickList(mySphereActor); + //myPicker->AddPickList(myHandleActor); + myPicker->PickFromListOn(); + + // Set up the initial properties + mySphereProperty = NULL; + mySelectedSphereProperty = NULL; + CreateDefaultProperties(); + myRmin=1.e-7; + mySphere=vtkSphere::New(); +} +//==================================================================== +// function: ~ +// purpose: +//==================================================================== +VISU_SphereWidget::~VISU_SphereWidget() +{ + this->SetEnabled(0); + // + mySphereActor->Delete(); + mySphereMapper->Delete(); + mySphereSource->Delete(); + // + myHandleActor->Delete(); + myHandleMapper->Delete(); + myHandleSource->Delete(); + + myPicker->Delete(); + + if ( mySphereProperty ) { + mySphereProperty->Delete(); + } + if ( mySelectedSphereProperty ) { + mySelectedSphereProperty->Delete(); + } + mySphere->Delete(); +} +//==================================================================== +// function: SetThetaResolution +// purpose : +//==================================================================== +void VISU_SphereWidget::SetThetaResolution(int r) +{ + mySphereSource->SetThetaResolution(r); +} +//==================================================================== +// function: GetThetaResolution +// purpose : +//==================================================================== +int VISU_SphereWidget::GetThetaResolution() +{ + return mySphereSource->GetThetaResolution(); +} +//==================================================================== +// function: SetPhiResolution +// purpose : +//==================================================================== +void VISU_SphereWidget::SetPhiResolution(int r) +{ + mySphereSource->SetPhiResolution(r); +} +//==================================================================== +// function: SetPhiResolution +// purpose : +//==================================================================== +int VISU_SphereWidget::GetPhiResolution() +{ + return mySphereSource->GetPhiResolution(); +} +//==================================================================== +// function: SetRadius +// purpose : +//==================================================================== +void VISU_SphereWidget::SetRadius(float aR1) +{ + if ( aR1 <= myRmin ) { + aR1=myRmin; + } + // + int i; + float aC[3], aCH[3], aDir[3]; + // + GetCenter(aC); + myHandleSource->GetCenter(aCH); + // + for (i=0; i<3; ++i){ + aDir[i]=aCH[i]-aC[i]; + } + vtkMath::Normalize(aDir); + for (i=0; i<3; ++i){ + aCH[i]=aC[i]+aDir[i]*aR1; + } + // + mySphereSource->SetRadius(aR1); + myHandleSource->SetCenter(aCH); + myHandleActor->SetCenter(aCH); +} +//==================================================================== +// function: GetRadius +// purpose : +//==================================================================== +float VISU_SphereWidget::GetRadius() +{ + return mySphereSource->GetRadius(); +} +//==================================================================== +// function: SetCenter +// purpose : +//==================================================================== +void VISU_SphereWidget::SetCenter(float aC1[3]) +{ + int i; + float aC[3], aCH[3], aDir[3], aR; + // + GetCenter(aC); + aR=GetRadius(); + // + for (i=0; i<3; ++i){ + aDir[i]=aC1[i]-aC[i]; + } + vtkMath::Normalize(aDir); + for (i=0; i<3; ++i){ + aCH[i]=aC1[i]+aDir[i]*aR; + } + vtkMath::Normalize(aDir); + // + mySphereSource->SetCenter(aC1); + myHandleSource->SetCenter(aCH); + myHandleActor->SetCenter(aCH); +} +//==================================================================== +// function: SetCenter +// purpose : +//==================================================================== +void VISU_SphereWidget::SetCenter(float aX, float aY, float aZ) +{ + float aC1[3]; + // + aC1[0]=aX; + aC1[1]=aY; + aC1[2]=aZ; + SetCenter(aC1); +} + +//==================================================================== +// function: GetCenter +// purpose : +//==================================================================== +float* VISU_SphereWidget::GetCenter() +{ + return mySphereSource->GetCenter(); +} +//==================================================================== +// function: GetCenter +// purpose : +//==================================================================== +void VISU_SphereWidget::GetCenter(float xyz[3]) +{ + mySphereSource->GetCenter(xyz); +} +//==================================================================== +// function: GetSphereProperty +// purpose : +//==================================================================== +vtkProperty* VISU_SphereWidget::GetSphereProperty () +{ + return mySphereProperty; +} +//==================================================================== +// function: GetSelectedSphereProperty +// purpose : +//==================================================================== +vtkProperty* VISU_SphereWidget::GetSelectedSphereProperty () +{ + return mySelectedSphereProperty; +} +//==================================================================== +// function: ImplicitFunction +// purpose : +//==================================================================== +vtkImplicitFunction* VISU_SphereWidget::ImplicitFunction() +{ + return mySphere; +} +//==================================================================== +// function: SetEnabled +// purpose : +//==================================================================== +void VISU_SphereWidget::SetEnabled(int enabling) +{ + if ( !Interactor ) { + vtkErrorMacro(<<"The interactor must be set prior to enabling/disabling widget"); + return; + } + + if ( enabling ) { + vtkDebugMacro(<<"Enabling sphere widget"); + if ( Enabled ) {//already enabled, just return + return; + } + + if ( ! CurrentRenderer ) { + int aPos[2]; + Interactor->GetLastEventPosition(aPos); + CurrentRenderer=Interactor->FindPokedRenderer(aPos[0], aPos[1]); + if (!CurrentRenderer) { + return; + } + } + + Enabled = 1; + + // listen for the following events + //vtkRenderWindowInteractor *i = this->Interactor; + Interactor->AddObserver(vtkCommand::MouseMoveEvent, + EventCallbackCommand, + Priority); + Interactor->AddObserver(vtkCommand::LeftButtonPressEvent, + EventCallbackCommand, + Priority); + Interactor->AddObserver(vtkCommand::LeftButtonReleaseEvent, + EventCallbackCommand, + Priority); + Interactor->AddObserver(vtkCommand::RightButtonPressEvent, + EventCallbackCommand, + Priority); + Interactor->AddObserver(vtkCommand::RightButtonReleaseEvent, + EventCallbackCommand, + Priority); + + // Add the sphere + CurrentRenderer->AddActor(mySphereActor); + mySphereActor->SetProperty(mySphereProperty); + CurrentRenderer->AddActor(myHandleActor); + // + { + int i; + float aC[3], aR, aDir[3]={1.,0.,0.}; + // + aR= mySphereSource->GetRadius(); + mySphereSource->GetCenter(aC); + // + for (i=0; i<3; ++i){ + aC[i]=aC[i]+aR*aDir[i]; + } + myHandleSource->SetCenter(aC); + myHandleActor->SetCenter(aC); + // + mySphere->SetCenter(mySphereSource->GetCenter()); + mySphere->SetRadius(mySphereSource->GetRadius()); + } + + InvokeEvent(vtkCommand::EnableEvent,NULL); //!!!see what will be done + } + //disabling---------------------------------------------------------- + else { + vtkDebugMacro(<<"Disabling sphere widget"); + + if ( !Enabled ){ //already disabled, just return + return; + } + + Enabled = 0; + + // don't listen for events any more + Interactor->RemoveObserver(EventCallbackCommand); + + // turn off the sphere, handle + CurrentRenderer->RemoveActor(mySphereActor); + CurrentRenderer->RemoveActor(myHandleActor); + InvokeEvent(vtkCommand::DisableEvent,NULL); + CurrentRenderer = NULL;//kruto + } + + Interactor->Render(); +} +//==================================================================== +// function:ProcessEvents +// purpose: +//==================================================================== +void VISU_SphereWidget::ProcessEvents(vtkObject* vtkNotUsed(object), + unsigned long event, + void* clientdata, + void* vtkNotUsed(calldata)) +{ + VISU_SphereWidget* self = reinterpret_cast( clientdata ); + + switch(event) { + case vtkCommand::LeftButtonPressEvent: + self->OnLeftButtonDown(); + break; + case vtkCommand::LeftButtonReleaseEvent: + self->OnLeftButtonUp(); + break; + case vtkCommand::RightButtonPressEvent: + self->OnRightButtonDown(); + break; + case vtkCommand::RightButtonReleaseEvent: + self->OnRightButtonUp(); + break; + case vtkCommand::MouseMoveEvent: + self->OnMouseMove(); + break; + default: + break; + } +} +//==================================================================== +// function:OnRightButtonDown +// purpose: +//==================================================================== +void VISU_SphereWidget::OnRightButtonDown() +{ + int X = Interactor->GetEventPosition()[0]; + int Y = Interactor->GetEventPosition()[1]; + + // Okay, make sure that the pick is in the current renderer + vtkRenderer *aRenderer=Interactor->FindPokedRenderer(X,Y); + // + if (aRenderer!=CurrentRenderer) { + myState = VISU_SphereWidget::Outside; + return; + } + // Okay, we can process this. Try to pick handles first; + // if no places picked, then try to pick the sphere. + vtkAssemblyPath *path; + myPicker->Pick(X, Y, 0., CurrentRenderer); + path = myPicker->GetPath(); + if (!path) { + myState = VISU_SphereWidget::Outside; + return; + } + else if (path->GetFirstNode()->GetProp()==mySphereActor ) { + myState = VISU_SphereWidget::Moving; + HighlightSphere(1); + // + int aNb; + float aCH[3]; + // + vtkPoints *pPoints=myPicker->GetPickedPositions(); + aNb=pPoints->GetNumberOfPoints(); + if (aNb){ + pPoints->GetPoint(0, aCH); + myHandleSource->SetCenter(aCH); + myHandleActor->SetCenter(aCH); + } + } + // + EventCallbackCommand->SetAbortFlag(1); + StartInteraction(); + InvokeEvent(vtkCommand::StartInteractionEvent,NULL); + Interactor->Render(); +} +//==================================================================== +// function:OnMouseMove +// purpose: +//==================================================================== +void VISU_SphereWidget::OnMouseMove() +{ + // See whether we're active + if ( myState == VISU_SphereWidget::Outside || + myState == VISU_SphereWidget::Start ) { + return; + } + + int X = Interactor->GetEventPosition()[0]; + int Y = Interactor->GetEventPosition()[1]; + + // Do different things depending on state + // Calculations everybody does + double focalPoint[4], pickPoint[4], prevPickPoint[4], z; + + vtkRenderer *aRenderer=Interactor->FindPokedRenderer(X, Y); + vtkCamera *aCamera=aRenderer->GetActiveCamera(); + if (!aCamera ) { + return; + } + // Compute the two points defining the motion vector + aCamera->GetFocalPoint(focalPoint); + ComputeWorldToDisplay(focalPoint[0], focalPoint[1], + focalPoint[2], focalPoint); + z = focalPoint[2]; + ComputeDisplayToWorld(double(Interactor->GetLastEventPosition()[0]), + double(Interactor->GetLastEventPosition()[1]), + z, + prevPickPoint); + ComputeDisplayToWorld(double(X), double(Y), z, pickPoint); + + // Process the motion + if ( myState == VISU_SphereWidget::Moving ) { + Translate(prevPickPoint, pickPoint); + } + else if ( myState == VISU_SphereWidget::Scaling ) { + Scale(prevPickPoint, pickPoint, X, Y); + } + // Interact, if desired + EventCallbackCommand->SetAbortFlag(1); + InvokeEvent(vtkCommand::InteractionEvent,NULL); + // + Interactor->Render(); +} +//==================================================================== +// function:OnRightButtonUp +// purpose: +//==================================================================== +void VISU_SphereWidget::OnRightButtonUp() +{ + if ( myState == VISU_SphereWidget::Outside ) { + return; + } + + myState = VISU_SphereWidget::Start; + HighlightSphere(0); + + EventCallbackCommand->SetAbortFlag(1); + EndInteraction(); + InvokeEvent(vtkCommand::EndInteractionEvent,NULL); + + Interactor->Render(); +} +//==================================================================== +// function:OnLeftButtonDown +// purpose: +//==================================================================== +void VISU_SphereWidget::OnLeftButtonDown() +{ + myState = VISU_SphereWidget::Scaling; + + int X = Interactor->GetEventPosition()[0]; + int Y = Interactor->GetEventPosition()[1]; + + // Okay, make sure that the pick is in the current renderer + vtkRenderer *aRenderer = Interactor->FindPokedRenderer(X,Y); + if (aRenderer!=CurrentRenderer) { + myState = VISU_SphereWidget::Outside; + return; + } + + // Okay, we can process this. Try to pick handles first; + // if no handles picked, then pick the bounding box. + vtkAssemblyPath *path; + myPicker->Pick(X, Y, 0., CurrentRenderer); + path = myPicker->GetPath(); + if ( !path ) { + myState=VISU_SphereWidget::Outside; + HighlightSphere(0); + return; + } + + HighlightSphere(1); + // + int aNb; + float aCH[3]; + // + vtkPoints *pPoints=myPicker->GetPickedPositions(); + aNb=pPoints->GetNumberOfPoints(); + if (aNb){ + pPoints->GetPoint(0, aCH); + myHandleSource->SetCenter(aCH); + myHandleActor->SetCenter(aCH); + } + // + EventCallbackCommand->SetAbortFlag(1); + StartInteraction(); + InvokeEvent(vtkCommand::StartInteractionEvent,NULL); + // + Interactor->Render(); +} +//==================================================================== +// function:OnLeftButtonUp +// purpose: +//==================================================================== +void VISU_SphereWidget::OnLeftButtonUp() +{ + if ( myState == VISU_SphereWidget::Outside ) { + return; + } + myState = VISU_SphereWidget::Start; + HighlightSphere(0); + + EventCallbackCommand->SetAbortFlag(1); + EndInteraction(); + InvokeEvent(vtkCommand::EndInteractionEvent,NULL); + // + Interactor->Render(); +} +//==================================================================== +// function:Translate +// purpose: +//==================================================================== +void VISU_SphereWidget::Translate(double *p1, double *p2) +{ + float v[3], aC[3], aC1[3]; + // + v[0] = p2[0] - p1[0]; + v[1] = p2[1] - p1[1]; + v[2] = p2[2] - p1[2]; + // + mySphereSource->GetCenter(aC); + aC1[0] = aC[0] + v[0]; + aC1[1] = aC[1] + v[1]; + aC1[2] = aC[2] + v[2]; + mySphereSource->SetCenter(aC1); + mySphere->SetCenter(mySphereSource->GetCenter()); + mySphere->SetRadius(mySphereSource->GetRadius()); + // + myHandleSource->GetCenter(aC); + aC1[0] = aC[0] + v[0]; + aC1[1] = aC[1] + v[1]; + aC1[2] = aC[2] + v[2]; + myHandleSource->SetCenter(aC1); + myHandleActor->SetCenter(aC1); +} +//==================================================================== +// function:Scale +// purpose: +//==================================================================== +void VISU_SphereWidget::Scale(double *p1, double *p2, + int , int ) +{ + float aC[3], aR, d1, d2, sf, aR1; + // + aR=mySphereSource->GetRadius(); + mySphereSource->GetCenter(aC); + d1=sqrt((p1[0]-aC[0])*(p1[0]-aC[0])+ + (p1[1]-aC[1])*(p1[1]-aC[1])+ + (p1[2]-aC[2])*(p1[2]-aC[2])); + + d2=sqrt((p2[0]-aC[0])*(p2[0]-aC[0])+ + (p2[1]-aC[1])*(p2[1]-aC[1])+ + (p2[2]-aC[2])*(p2[2]-aC[2])); + + sf=1.+(d2-d1)/aR; + aR1=sf*aR; + if (aR1SetRadius(aR1); + mySphere->SetCenter(mySphereSource->GetCenter()); + mySphere->SetRadius(mySphereSource->GetRadius()); + // + int i; + float aCH[3]; + // + myHandleSource->GetCenter(aCH); + for (i=0; i<3; ++i){ + aCH[i]=aC[i]+aR1*(aCH[i]-aC[i])/aR; + } + myHandleSource->SetCenter(aCH); + myHandleActor->SetCenter(aCH); +} +//==================================================================== +// function:GetSphere +// purpose: +//==================================================================== +void VISU_SphereWidget::GetSphere(vtkSphere *sphere) +{ + sphere->SetRadius(mySphereSource->GetRadius()); + sphere->SetCenter(mySphereSource->GetCenter()); +} +//==================================================================== +// function:HighlightSphere +// purpose: +//==================================================================== +void VISU_SphereWidget::HighlightSphere(int highlight) +{ + if ( highlight ) { + this->ValidPick = 1; + myPicker->GetPickPosition(this->LastPickPosition);// -> def in vtk3DWidget + mySphereActor->SetProperty(mySelectedSphereProperty); + } + else { + mySphereActor->SetProperty(mySphereProperty); + } +} +//==================================================================== +// function:CreateDefaultProperties +// purpose: +//==================================================================== +void VISU_SphereWidget::CreateDefaultProperties() +{ + if (!mySphereProperty) { + mySphereProperty = vtkProperty::New(); + mySphereProperty->SetColor(0.,.5, .7); + mySphereProperty->SetSpecular(0.5); + mySphereProperty->SetRepresentationToWireframe(); + } + if (!mySelectedSphereProperty) { + mySelectedSphereProperty = vtkProperty::New(); + mySelectedSphereProperty->SetColor(0.5, 0.5, 0.); + mySelectedSphereProperty->SetSpecular(1.); + mySelectedSphereProperty->SetRepresentationToWireframe(); + } +} +//==================================================================== +// function:PlaceWidget +// purpose: +//==================================================================== +void VISU_SphereWidget::PlaceWidget(float bds[6]) +{ + float bounds[6], center[3], radius; + + this->AdjustBounds(bds, bounds, center); + float dX, dY, dZ; + // + dX=bounds[1]-bounds[0]; + dY=bounds[3]-bounds[2]; + dZ=bounds[5]-bounds[4]; + radius = dX; + if (radius>dY){ + radius = dY; + } + if (radius>dZ) { + radius=dZ; + } + radius*=0.5; + + mySphereSource->SetCenter(center); + mySphereSource->SetRadius(radius); + mySphereSource->Update(); + // + for (int i=0; i<6; i++) { + InitialBounds[i]=bounds[i]; + } + InitialLength = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) + + (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) + + (bounds[5]-bounds[4])*(bounds[5]-bounds[4])); + +} +//==================================================================== +// function:GetPolyData +// purpose: +//==================================================================== +void VISU_SphereWidget::GetPolyData(vtkPolyData *pd) +{ + pd->ShallowCopy(mySphereSource->GetOutput()); +} +//==================================================================== +// function:PrintSelf +// purpose: +//==================================================================== +void VISU_SphereWidget::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); +} diff --git a/src/PIPELINE/VISU_SphereWidget.hxx b/src/PIPELINE/VISU_SphereWidget.hxx new file mode 100755 index 00000000..09515a41 --- /dev/null +++ b/src/PIPELINE/VISU_SphereWidget.hxx @@ -0,0 +1,129 @@ +#ifndef __VISU_SphereWidget_h +#define __VISU_SphereWidget_h + +#include "VISU_ImplicitFunctionWidget.hxx" + +class vtkActor; +class vtkPolyDataMapper; +class vtkPoints; +class vtkPolyData; +class vtkSphereSource; +class vtkSphere; +class vtkCellPicker; +class vtkProperty; +class VISU_UnScaledActor; +class vtkSphere; +class vtkImplicitFunction; +// +class VISU_SphereWidget : public VISU_ImplicitFunctionWidget +{ +public: + // Description: + // Instantiate the object. + static VISU_SphereWidget *New(); + vtkTypeRevisionMacro(VISU_SphereWidget,VISU_ImplicitFunctionWidget); + void PrintSelf(ostream& os, vtkIndent indent); + + virtual vtkImplicitFunction* ImplicitFunction(); + + // Description: + // Methods that satisfy the superclass' API. + virtual void SetEnabled(int); + // + //PlaceWidget + virtual void PlaceWidget(float bounds[6]); + // + // Description: + // Set/Get the resolution of the sphere in the Theta direction. + void SetThetaResolution(int r); + int GetThetaResolution(); + // Description: + // Set/Get the resolution of the sphere in the Phi direction. + void SetPhiResolution(int r); + int GetPhiResolution(); + + // Description: + // Set/Get the radius of sphere. Default is .5. + void SetRadius(float r); + float GetRadius(); + + + // Description: + // Set/Get the center of the sphere. + void SetCenter(float x, float y, float z); + void SetCenter(float x[3]); + + float* GetCenter(); + void GetCenter(float xyz[3]); + + + void GetPolyData(vtkPolyData *pd); + + void GetSphere(vtkSphere *sphere); + + + vtkProperty* GetSphereProperty (); + vtkProperty* GetSelectedSphereProperty (); + + +protected: + VISU_SphereWidget(); + ~VISU_SphereWidget(); + + //handles the events + static void ProcessEvents(vtkObject* object, + unsigned long event, + void* clientdata, + void* calldata); + + // ProcessEvents() dispatches to these methods. + void OnLeftButtonDown(); + void OnLeftButtonUp(); + void OnRightButtonDown(); + void OnRightButtonUp(); + void OnMouseMove(); + + void HighlightSphere(int highlight); + + // Methods to manipulate the sphere widget + void Translate(double *p1, double *p2); + void Scale(double *p1, double *p2, int X, int Y); + + //virtual void SizeHandles(); + void CreateDefaultProperties(); + + //BTX - manage the state of the widget + int myState; + enum WidgetState + { + Start=0, + Moving, + Scaling, + Positioning, + Outside + }; + //ETX + // the sphere + vtkActor *mySphereActor; + vtkPolyDataMapper *mySphereMapper; + vtkSphereSource *mySphereSource; + // + // the handle + vtkSphereSource *myHandleSource; + vtkPolyDataMapper *myHandleMapper; + VISU_UnScaledActor *myHandleActor; + // + // the Picker + vtkCellPicker *myPicker; + // Properties used to control the appearance of selected objects and + // the manipulator in general. + vtkProperty *mySphereProperty; + vtkProperty *mySelectedSphereProperty; + float myRmin; + vtkSphere *mySphere; +private: + VISU_SphereWidget(const VISU_SphereWidget&); //Not implemented + void operator=(const VISU_SphereWidget&); //Not implemented +}; + +#endif diff --git a/src/PIPELINE/VISU_WidgetCtrl.cxx b/src/PIPELINE/VISU_WidgetCtrl.cxx new file mode 100644 index 00000000..aab6f639 --- /dev/null +++ b/src/PIPELINE/VISU_WidgetCtrl.cxx @@ -0,0 +1,350 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VVTK_WidgetCtrl.cxx +// Author : Peter KURNEV +// Module : SALOME +// $Header$ + +#include "VISU_WidgetCtrl.hxx" +// +#include +#include +#include +#include +#include +#include +#include +// +#include "VISU_ImplicitFunctionWidget.hxx" +#include "VISU_PlanesWidget.hxx" +#include "VISU_SphereWidget.hxx" +// +vtkCxxRevisionMacro(VISU_WidgetCtrl,"$Revision$"); +vtkStandardNewMacro(VISU_WidgetCtrl); + +//================================================================== +// function: VISU_WidgetCtrl +// purpose : +//================================================================== +VISU_WidgetCtrl::VISU_WidgetCtrl() +: + vtkObject() +{ + myDummyWidget=NULL; + myDisableAll=0; + myImplicitSum=vtkImplicitSum::New(); + myNbWidgets=2; + myActiveIndex=-1;// 0 - PlanesWidget; 1 - SphereWidget + myPriority=0.; + // + myPlanesWidget=VISU_PlanesWidget::New(); + mySphereWidget=VISU_SphereWidget::New(); + // + myWidgets[0]=myPlanesWidget; + myWidgets[1]=mySphereWidget; + // + myEventCallbackCommand=vtkCallbackCommand::New(); + myEventCallbackCommand->SetClientData(this); + myEventCallbackCommand->SetCallback(VISU_WidgetCtrl::ProcessEvents); + // + int i; + for (i=0; iAddObserver(vtkCommand::EnableEvent, + myEventCallbackCommand, + myPriority); + myWidgets[i]->AddObserver(vtkCommand::DisableEvent, + myEventCallbackCommand, + myPriority); + myWidgets[i]->AddObserver(vtkCommand::EndInteractionEvent, + myEventCallbackCommand, + myPriority); + + myWidgets[i]->AddObserver(vtkCommand::InteractionEvent, + myEventCallbackCommand, + myPriority); + // + vtkImplicitFunction *pIF=myWidgets[i]->ImplicitFunction(); + myImplicitSum->AddFunction(pIF, 0.); + } +} +//================================================================== +// function: ~ +// purpose : +//================================================================== +VISU_WidgetCtrl::~VISU_WidgetCtrl() +{ + + myPlanesWidget->Delete(); + mySphereWidget->Delete(); + // + for (int i=0; iRemoveObserver(myEventCallbackCommand); + } + // + myEventCallbackCommand->Delete(); + myImplicitSum->Delete(); +} +//================================================================== +// function: GetEnabled +// purpose : +//================================================================== +int VISU_WidgetCtrl::GetEnabled() +{ + if (HasActiveIndex()) { + return GetActiveWidget()->GetEnabled(); + } + return 0; +} +//================================================================== +// function: SetEnabled +// purpose : +//================================================================== +void VISU_WidgetCtrl::SetEnabled(int theFlag) +{ + int iFlag, i; + // + myDisableAll=0; + // + iFlag=GetEnabled(); + if (iFlag==theFlag) { + return; + } + // + if (theFlag) {//enabling + if (HasActiveIndex()) { + for (i=0; iSetEnabled(iFlag); + } + } + } + else {//disabling + myDisableAll=1; + for (i=0; iSetEnabled(0); + } + } +} +//================================================================== +// function: ProcessEvents +// purpose : +//================================================================== +void VISU_WidgetCtrl::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + VISU_WidgetCtrl *pSelf= + reinterpret_cast(theClientData); + + switch(theEvent){ + case vtkCommand::InteractionEvent: { + pSelf->InvokeEvent(theEvent, NULL); + } + break; + // + case vtkCommand::EndInteractionEvent: { + pSelf->InvokeEvent(theEvent, NULL); + } + break; + // + case vtkCommand::EnableEvent: + pSelf->InvokeEvent(theEvent, NULL); + break; + // + case vtkCommand::DisableEvent: { + int iDisableAll=pSelf->GetDisableAll(); + if (iDisableAll) { + pSelf->InvokeEvent(theEvent, NULL); + } + } + break; + // + default: + break; + } +} +//================================================================== +// function: GetNbWidgets +// purpose : +//================================================================== +int VISU_WidgetCtrl::GetNbWidgets()const +{ + return myNbWidgets; +} +//================================================================== +// function: GetDisableAll +// purpose : +//================================================================== +int VISU_WidgetCtrl::GetDisableAll()const +{ + return myDisableAll; +} +//================================================================== +// function: SetActiveIndex +// purpose : +//================================================================== +void VISU_WidgetCtrl::SetActiveIndex(const int theIndex) +{ + myActiveIndex=-1; + if (theIndex>=0 && theIndex=0 && myActiveIndex=0 && theIndexPlaceWidget(theBounds); + } +} +//================================================================== +// function: SetInteractor +// purpose : +//================================================================== +void VISU_WidgetCtrl::SetInteractor(vtkRenderWindowInteractor* theRWI) +{ + for (int i=0; iSetInteractor(theRWI); + } +} +//================================================================== +// function: GetInteractor +// purpose : +//================================================================== +vtkRenderWindowInteractor* VISU_WidgetCtrl::GetInteractor() +{ + myWidgets[0]->GetInteractor(); +} +//================================================================== +// function: SetPlaceFactor +// purpose : +//================================================================== +void VISU_WidgetCtrl::SetPlaceFactor(float theFactor) +{ + for (int i=0; iSetPlaceFactor(theFactor); + } +} +//================================================================== +// function: GetPlaceFactor +// purpose : +//================================================================== +float VISU_WidgetCtrl::GetPlaceFactor() +{ + return myWidgets[0]->GetPlaceFactor(); +} +//================================================================== +// function: ImplicitFunction +// purpose : +//================================================================== +vtkImplicitFunction* VISU_WidgetCtrl::ImplicitFunction() +{ + int i; + float aWeight; + vtkImplicitFunction *pIF; + // + for (int i=0; iImplicitFunction(); + aWeight=(i==myActiveIndex)? 1. : 0.; + if (i==myActiveIndex && i==1){ + aWeight=-1.; + } + myImplicitSum->SetFunctionWeight(pIF, aWeight); + } + return myImplicitSum; +} diff --git a/src/PIPELINE/VISU_WidgetCtrl.hxx b/src/PIPELINE/VISU_WidgetCtrl.hxx new file mode 100644 index 00000000..d6825324 --- /dev/null +++ b/src/PIPELINE/VISU_WidgetCtrl.hxx @@ -0,0 +1,110 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VISU_WidgetCtrl.hxx +// Author : Peter KURNEV +// Module : SALOME +// $Header$ + +#ifndef __VISU_WidgetCtrl_hxx +#define __VISU_WidgetCtrl_hxx + + +#include + +class vtkImplicitFunction; +class vtkObject; +class vtkRenderWindowInteractor; +class vtkCommand; +class vtkCallbackCommand; +class vtkImplicitSum; + +class VISU_PlanesWidget; +class VISU_SphereWidget; +class VISU_ImplicitFunctionWidget; + +class VISU_WidgetCtrl : public vtkObject +{ +public: + static VISU_WidgetCtrl *New(); + vtkTypeRevisionMacro(VISU_WidgetCtrl,vtkObject); + + vtkImplicitFunction* ImplicitFunction(); + // + void PlaceWidget(float theBounds[6]); + void SetEnabled(int theFlag); + int GetEnabled(); + void On() {SetEnabled(1);} + void Off(){SetEnabled(0);} + + void SetInteractor(vtkRenderWindowInteractor* theRWI); + vtkRenderWindowInteractor* GetInteractor(); + // + void SetPlaceFactor(float theFactor); + float GetPlaceFactor(); + // + void SetActiveIndex(const int theFlag); + int GetActiveIndex()const; + bool HasActiveIndex()const; + bool IsPlanesActive()const; + bool IsSphereActive()const; + + + VISU_ImplicitFunctionWidget* GetActiveWidget(); + VISU_ImplicitFunctionWidget* GetWidget(const int); + + int GetNbWidgets()const; + int GetDisableAll()const; + + // + VISU_PlanesWidget * GetPlanesWidget(); + VISU_SphereWidget * GetSphereWidget(); + // + static void ProcessEvents(vtkObject* theObject, + unsigned long theEvent, + void* theClientData, + void* theCalldata); + // +protected: + VISU_WidgetCtrl(); + ~VISU_WidgetCtrl(); + +protected: + int myNbWidgets; + int myActiveIndex; + int myCounter; + int myDisableAll; + float myPriority; + vtkImplicitSum* myImplicitSum; + VISU_ImplicitFunctionWidget *myWidgets[2]; + VISU_ImplicitFunctionWidget *myDummyWidget; + VISU_PlanesWidget *myPlanesWidget; + VISU_SphereWidget *mySphereWidget; + vtkCallbackCommand *myEventCallbackCommand; + +private: + VISU_WidgetCtrl(const VISU_WidgetCtrl&); //Not implemented + void operator=(const VISU_WidgetCtrl&); //Not implemented +}; + +#endif diff --git a/src/VISUGUI/VisuGUI_Module.cxx b/src/VISUGUI/VisuGUI_Module.cxx index 731993aa..510f6f9d 100644 --- a/src/VISUGUI/VisuGUI_Module.cxx +++ b/src/VISUGUI/VisuGUI_Module.cxx @@ -65,7 +65,10 @@ #include "VisuGUI_Tools.h" #include "VisuGUI_ActionsDef.h" -#include "VISU_ImplicitFunctionWidget.h" +#include "VISU_WidgetCtrl.hxx" +#include "VISU_PlanesWidget.hxx" +#include "VISU_SphereWidget.hxx" + #include "SalomeApp_Study.h" #include "VVTK_MainWindow.h" #include "VISU_View_i.hh" @@ -1038,21 +1041,30 @@ namespace { GetViewParams(theViewWindow,"1",theStr); - VISU_ImplicitFunctionWidget* aWidget = theViewWindow->GetImplicitFunctionWidget(); + VISU_WidgetCtrl* aWidgetCtrl = theViewWindow->GetWidgetCtrl(); + VISU_PlanesWidget *pPlanesWidget=aWidgetCtrl->GetPlanesWidget(); float anOrigin[3]; - aWidget->GetOrigin(anOrigin); + pPlanesWidget->GetOrigin(anOrigin); Storable::DataToStream(theStr,"myCursorOrigin[0]",anOrigin[0]); Storable::DataToStream(theStr,"myCursorOrigin[1]",anOrigin[1]); Storable::DataToStream(theStr,"myCursorOrigin[2]",anOrigin[2]); float aNormal[3]; - aWidget->GetNormal(aNormal); + pPlanesWidget->GetNormal(aNormal); Storable::DataToStream(theStr,"myCursorNormal[0]",aNormal[0]); Storable::DataToStream(theStr,"myCursorNormal[1]",aNormal[1]); Storable::DataToStream(theStr,"myCursorNormal[2]",aNormal[2]); - float aDepth = aWidget->Distance(); + float aDepth = pPlanesWidget->Distance(); Storable::DataToStream(theStr,"myCursorDepth",aDepth); + // + VISU_SphereWidget *pSphereWidget=aWidgetCtrl->GetSphereWidget(); + pSphereWidget->GetCenter(anOrigin); + Storable::DataToStream(theStr,"mySphereCursorCenter[0]",anOrigin[0]); + Storable::DataToStream(theStr,"mySphereCursorCenter[1]",anOrigin[1]); + Storable::DataToStream(theStr,"mySphereCursorCenter[2]",anOrigin[2]); + aDepth=pSphereWidget->GetRadius(); + Storable::DataToStream(theStr,"mySphereCursorRaduis",aDepth); } //--------------------------------------------------------------- @@ -1062,21 +1074,30 @@ namespace { SetViewParams(theViewWindow,"1",theMap); - VISU_ImplicitFunctionWidget* aWidget = theViewWindow->GetImplicitFunctionWidget(); + VISU_WidgetCtrl* aWidgetCtrl = theViewWindow->GetWidgetCtrl(); + VISU_PlanesWidget *pPlanesWidget=aWidgetCtrl->GetPlanesWidget(); float anOrigin[3]; anOrigin[0] = Storable::FindValue(theMap,"myCursorOrigin[0]").toDouble(); anOrigin[1] = Storable::FindValue(theMap,"myCursorOrigin[1]").toDouble(); anOrigin[2] = Storable::FindValue(theMap,"myCursorOrigin[2]").toDouble(); - aWidget->SetOrigin(anOrigin); + pPlanesWidget->SetOrigin(anOrigin); float aNormal[3]; aNormal[0] = Storable::FindValue(theMap,"myCursorNormal[0]").toDouble(); aNormal[1] = Storable::FindValue(theMap,"myCursorNormal[1]").toDouble(); aNormal[2] = Storable::FindValue(theMap,"myCursorNormal[2]").toDouble(); - aWidget->SetNormal(aNormal); + pPlanesWidget->SetNormal(aNormal); float aDepth = Storable::FindValue(theMap,"myCursorDepth").toDouble(); - aWidget->SetDistance(aDepth); + pPlanesWidget->SetDistance(aDepth); + // + VISU_SphereWidget *pSphereWidget=aWidgetCtrl->GetSphereWidget(); + anOrigin[0] = Storable::FindValue(theMap,"mySphereCursorCenter[0]").toDouble(); + anOrigin[1] = Storable::FindValue(theMap,"mySphereCursorCenter[1]").toDouble(); + anOrigin[2] = Storable::FindValue(theMap,"mySphereCursorCenter[2]").toDouble(); + pSphereWidget->SetCenter(anOrigin); + aDepth = Storable::FindValue(theMap,"mySphereCursorRaduis").toDouble(); + pSphereWidget->SetRadius(aDepth); } diff --git a/src/VVTK/Makefile.in b/src/VVTK/Makefile.in index e11d33e8..5f38d378 100755 --- a/src/VVTK/Makefile.in +++ b/src/VVTK/Makefile.in @@ -22,7 +22,10 @@ EXPORT_HEADERS = \ VVTK_PrimitiveBox.h \ VVTK_SizeBox.h \ VVTK_ViewWindow.h \ - VVTK_MainWindow.h + VVTK_MainWindow.h \ + VVTK_ImageWriter.h \ + VVTK_ImageWriterMgr.h \ + VVTK_Recorder.h # Libraries targets LIB = libVVTK.la @@ -37,7 +40,10 @@ LIB_SRC = \ VVTK_SizeBox.cxx \ VVTK_ViewWindow.cxx \ VVTK_Renderer.cxx \ - VVTK_MainWindow.cxx + VVTK_MainWindow.cxx \ + VVTK_ImageWriter.cxx \ + VVTK_ImageWriterMgr.cxx \ + VVTK_Recorder.cxx LIB_MOC = \ VVTK_ViewWindow.h \ @@ -47,7 +53,7 @@ LIB_MOC = \ VVTK_SegmentationCursorDlg.h \ VVTK_PrimitiveBox.h \ VVTK_SizeBox.h \ - VVTK_MainWindow.h + VVTK_MainWindow.h CPPFLAGS += \ $(QT_INCLUDES) \ @@ -67,4 +73,5 @@ LDFLAGS += \ LIBS+= -lsuit -lCAM -lSalomeObject -lSVTK -lOpUtil + @CONCLUDE@ diff --git a/src/VVTK/VVTK_ImageWriter.cxx b/src/VVTK/VVTK_ImageWriter.cxx new file mode 100755 index 00000000..16e8e802 --- /dev/null +++ b/src/VVTK/VVTK_ImageWriter.cxx @@ -0,0 +1,187 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ +#include "VVTK_ImageWriter.h" +#include +#include +#include +// +//=============================================== +// function: VVTK_ImageWriter +// purpose : +//=============================================== +VVTK_ImageWriter::VVTK_ImageWriter() +: QThread() +{ + myName=NULL; + myProgressive=0; + myQuality=0; + myImageData=0; + myConstraint16Flag=true; + myErrorStatus=0; +} +//=============================================== +// function: ~ +// purpose : +//=============================================== +VVTK_ImageWriter::~VVTK_ImageWriter() +{ +} +//=============================================== +// function: SetName +// purpose : +//=============================================== +void VVTK_ImageWriter::SetName(const char *aName) +{ + myName=(char *)aName; +} +//=============================================== +// function: Name +// purpose : +//=============================================== +const char* VVTK_ImageWriter::Name()const +{ + return myName; +} +//=============================================== +// function: SetProgressive +// purpose : +//=============================================== +void VVTK_ImageWriter::SetProgressive(const int aProgressive) +{ + myProgressive=aProgressive; +} +//=============================================== +// function: Progressive +// purpose : +//=============================================== +int VVTK_ImageWriter::Progressive()const +{ + return myProgressive; +} +//=============================================== +// function: SetQuality +// purpose : +//=============================================== +void VVTK_ImageWriter::SetQuality(const int aQuality) +{ + myQuality=aQuality; +} +//=============================================== +// function: Quality +// purpose : +//=============================================== +int VVTK_ImageWriter::Quality()const +{ + return myQuality; +} +//=============================================== +// function: SetImageData +// purpose : +//=============================================== +void VVTK_ImageWriter::SetImageData(vtkImageData* pImageData) +{ + myImageData=pImageData; +} +//=============================================== +// function: ImageData +// purpose : +//=============================================== +vtkImageData* VVTK_ImageWriter::ImageData() +{ + return myImageData; +} +//=============================================== +// function: SetConstraint16Flag +// purpose : +//=============================================== +void VVTK_ImageWriter::SetConstraint16Flag(const bool aFlag) +{ + myConstraint16Flag=aFlag; +} +//=============================================== +// function: Constraint16Flag +// purpose : +//=============================================== +bool VVTK_ImageWriter::Constraint16Flag()const +{ + return myConstraint16Flag; +} +//=============================================== +// function: ErrorStatus +// purpose : +//=============================================== +int VVTK_ImageWriter::ErrorStatus()const +{ + return myErrorStatus; +} +//=============================================== +// function: run +// purpose : +//=============================================== +void VVTK_ImageWriter::run() +{ + vtkJPEGWriter *pWriter=vtkJPEGWriter::New(); + // + vtkImageData *pImageData=myImageData; + vtkImageClip *pImageClip=NULL; + // + if (myConstraint16Flag){ + int uExtent[6]; + unsigned int width, height; + // + myImageData->GetUpdateExtent(uExtent); + width =uExtent[1]-uExtent[0]+1; + height=uExtent[3]-uExtent[2]+1; + width =(width/16)*16; + height=(height/16)*16; + uExtent[1]=uExtent[0]+width -1; + uExtent[3]=uExtent[2]+height-1; + // + pImageClip=vtkImageClip::New(); + pImageClip->SetInput(myImageData); + pImageClip->SetOutputWholeExtent(uExtent); + pImageClip->ClipDataOn(); + pImageData=pImageClip->GetOutput(); + } + // + pWriter->WriteToMemoryOff(); + pWriter->SetFileName(myName); + pWriter->SetQuality(myQuality); + pWriter->SetProgressive(myProgressive); + pWriter->SetInput(pImageData); + // + pWriter->Write(); + // + if (myConstraint16Flag){ + pImageClip->Delete(); + } + pWriter->Delete(); + delete myName; + myImageData->Delete(); +} + diff --git a/src/VVTK/VVTK_ImageWriter.h b/src/VVTK/VVTK_ImageWriter.h new file mode 100755 index 00000000..ade5d3f6 --- /dev/null +++ b/src/VVTK/VVTK_ImageWriter.h @@ -0,0 +1,71 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ +#ifndef _VVTK_ImageWriter_Header_File_ +#define _VVTK_ImageWriter_Header_File_ + +#include + +class vtkImageData; + +class VVTK_ImageWriter : public QThread { +public: + VVTK_ImageWriter(); + ~VVTK_ImageWriter(); + + void SetName(const char *aName); + const char *Name()const; + + void SetProgressive(const int aProgressive); + int Progressive()const; + + void SetQuality(const int aQuality); + int Quality()const; + + void SetImageData(vtkImageData*); + vtkImageData* ImageData(); + + void SetConstraint16Flag(const bool bFlag); + bool Constraint16Flag()const; + + int ErrorStatus()const; + +protected : + virtual void run(); + void WriteSlice(); + +protected : + char *myName; + int myProgressive; + int myQuality; + int myErrorStatus; + bool myConstraint16Flag; + + vtkImageData *myImageData; + +}; +#endif diff --git a/src/VVTK/VVTK_ImageWriterMgr.cxx b/src/VVTK/VVTK_ImageWriterMgr.cxx new file mode 100755 index 00000000..0cf7c4cc --- /dev/null +++ b/src/VVTK/VVTK_ImageWriterMgr.cxx @@ -0,0 +1,175 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ +#include "VVTK_ImageWriterMgr.h" + +#include +#include +#include +#include "VVTK_ImageWriter.h" + +//=============================================== +// function: +// purpose : +//=============================================== +VVTK_ImageWriterMgr::VVTK_ImageWriterMgr() + : QThread() +{ + myStop=0; + myErrorStatus=0; +} +//=============================================== +// function: ~ +// purpose : +//=============================================== +VVTK_ImageWriterMgr::~VVTK_ImageWriterMgr() +{ +} +//=============================================== +// function: Stop +// purpose : +//=============================================== +void VVTK_ImageWriterMgr::Stop() +{ + myStop=1; +} +//=============================================== +// function: StartImageWriter +// purpose : +//=============================================== +void VVTK_ImageWriterMgr::StartImageWriter(const char *aName, + const int aProgressive, + const int aQuality, + vtkImageData *pImageData) +{ + VVTK_ImageWriter *pIW=new VVTK_ImageWriter; + // + myMutex.lock(); + myThreads.push_back(pIW); + myMutex.unlock(); + // + pIW->SetName(aName); + pIW->SetQuality(aQuality); + pIW->SetProgressive(aProgressive); + pIW->SetImageData(pImageData); + pIW->start(); +} +//=============================================== +// function: run +// purpose : +//=============================================== +void VVTK_ImageWriterMgr::run() +{ + while (1) { + if (myErrorStatus){ + return; + } + if(myStop) { + CleanAll(); + break; + } + // + msleep(1000); + CleanPartial(10); + } +} +//=============================================== +// function: CleanPartial +// purpose : +//=============================================== +void VVTK_ImageWriterMgr::CleanPartial(const int aNumber) +{ + void *p; + VVTK_ImageWriter* pIW; + // + std::list aList; + std::list ::iterator aIter; + // + while (myMutex.locked()); + // + myMutex.lock(); + // + aIter=myThreads.begin(); + for (; aIter != myThreads.end() ; aIter++ ){ + void *p=*aIter; + pIW=reinterpret_cast (*aIter); + if (pIW->ErrorStatus()){ + myErrorStatus=10; + return; + } + if (pIW->finished()){ + aList.push_back(pIW); + if(aList.size()>aNumber){ + break; + } + } + } + // + aIter=aList.begin(); + for (; aIter != aList.end(); aIter++ ){ + p=*aIter; + myThreads.remove(p); + pIW=reinterpret_cast (p); + vtkImageData* pImageData=pIW->ImageData(); + delete pIW; + } + myMutex.unlock(); +} +//=============================================== +// function: CleanAll +// purpose : +//=============================================== +void VVTK_ImageWriterMgr::CleanAll() +{ + void *p; + VVTK_ImageWriter* pIW; + // + std::list ::iterator aIter; + // + // clean all + while (myMutex.locked()); + myMutex.lock(); + while (myThreads.size()) { + aIter=myThreads.begin(); + for (; aIter != myThreads.end() ; aIter++ ){ + void *p=*aIter; + pIW=reinterpret_cast (*aIter); + if (pIW->ErrorStatus()){ + myErrorStatus=10; + myStop=0; + return; + } + if (pIW->finished()){ + delete pIW; + myThreads.remove(p); + break; + } + } + } + myMutex.unlock(); + myStop=0; +} diff --git a/src/VVTK/VVTK_ImageWriterMgr.h b/src/VVTK/VVTK_ImageWriterMgr.h new file mode 100755 index 00000000..db0d0415 --- /dev/null +++ b/src/VVTK/VVTK_ImageWriterMgr.h @@ -0,0 +1,62 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ +#ifndef _VVTK_ImageWriterMgr_Header_File_ +#define _VVTK_ImageWriterMgr_Header_File_ + +#include +#include +// +class QString; +class vtkImageData; +class QMutex; +// +class VVTK_ImageWriterMgr : public QThread { +public: + VVTK_ImageWriterMgr(); + ~VVTK_ImageWriterMgr(); + + void Stop(); + void StartImageWriter(const char *aName, + const int aProgressive, + const int aQuality, + vtkImageData *pImageData); + int ErrorStatus()const; + +protected : + virtual void run(); + void CleanAll(); + void CleanPartial(const int aNumber); + +protected : + int myStop; + int myErrorStatus; + std::list myThreads; + QMutex myMutex; +}; +#endif + diff --git a/src/VVTK/VVTK_MainWindow.cxx b/src/VVTK/VVTK_MainWindow.cxx index 4608ec56..d3ee34ca 100644 --- a/src/VVTK/VVTK_MainWindow.cxx +++ b/src/VVTK/VVTK_MainWindow.cxx @@ -28,7 +28,8 @@ #include "VVTK_MainWindow.h" #include "VVTK_InteractorStyle.h" -#include "VISU_ImplicitFunctionWidget.h" +#include "VVTK_Recorder.h" +#include "VISU_WidgetCtrl.hxx" #include "VISU_GaussPtsAct.h" #include "SVTK_RenderWindowInteractor.h" @@ -93,6 +94,8 @@ VVTK_MainWindow myStopAction->setEnabled( false ); myStopAction->addTo( myRecordingToolBar ); connect( myStopAction, SIGNAL( activated() ), this, SLOT( OnStopRecording() ) ); + + myRecorder=VVTK_Recorder::New(); } void @@ -103,9 +106,12 @@ VVTK_MainWindow PushInteractorStyle(myInteractorStyle.GetPointer()); } -VVTK_MainWindow -::~VVTK_MainWindow() -{} +VVTK_MainWindow::~VVTK_MainWindow() +{ + if (myRecorder){ + myRecorder->Delete(); + } +} //---------------------------------------------------------------------------- @@ -128,51 +134,62 @@ VVTK_MainWindow } //---------------------------------------------------------------------------- -void -VVTK_MainWindow -::OnStartRecording() +void VVTK_MainWindow::OnStartRecording() { - QString aFileName = QFileDialog::getOpenFileName( "/data/ouv/SALOME", "*.avi", this ); - if( aFileName.isNull() ) + //QString aFileName = "/data/pkv/IMAGES/TMP/abc"; + QString aFileName=QFileDialog::getOpenFileName( "/", "*.avi", this ); + if( aFileName.isNull() ){ return; - + } + + // myStartAction->setEnabled( false ); myPlayAction->setEnabled( false ); myPauseAction->setEnabled( true ); myStopAction->setEnabled( true ); + // + //==== + SVTK_RenderWindowInteractor* pInteractor=GetInteractor(); + vtkRenderWindow* pRenderWindow=pInteractor->getRenderWindow(); + // + myRecorder->SetName(aFileName.latin1()); + myRecorder->SetNbFPS(10); + myRecorder->SetRenderWindow(pRenderWindow); + // + myRecorder->Record(); } //---------------------------------------------------------------------------- -void -VVTK_MainWindow -::OnPlayRecording() +void VVTK_MainWindow::OnPlayRecording() { myStartAction->setEnabled( false ); myPlayAction->setEnabled( false ); myPauseAction->setEnabled( true ); myStopAction->setEnabled( true ); + // + myRecorder->Pause(); } //---------------------------------------------------------------------------- -void -VVTK_MainWindow -::OnPauseRecording() +void VVTK_MainWindow::OnPauseRecording() { myStartAction->setEnabled( false ); myPlayAction->setEnabled( true ); myPauseAction->setEnabled( false ); myStopAction->setEnabled( true ); + // + myRecorder->Pause(); } //---------------------------------------------------------------------------- -void -VVTK_MainWindow -::OnStopRecording() +void VVTK_MainWindow::OnStopRecording() { myStartAction->setEnabled( true ); myPlayAction->setEnabled( false ); myPauseAction->setEnabled( false ); myStopAction->setEnabled( false ); + // + myRecorder->Stop(); } //---------------------------------------------------------------------------- @@ -254,7 +271,7 @@ VVTK_MainWindow1 myPlaneSegmentationAction->setToggleAction(true); myPlaneSegmentationAction->setStatusTip(tr("DSC_VVTK_PLANE_SEGMENTATION_SWITCH")); myPlaneSegmentationAction->addTo( myPtsToolBar ); - connect( myPlaneSegmentationAction, SIGNAL( toggled( bool ) ), this, SLOT( OnSegmentationSwitch( bool ) ) ); + connect( myPlaneSegmentationAction, SIGNAL( activated() ), this, SLOT( OnSegmentationSwitch() ) ); aPixmap = theResourceMgr->loadPixmap("VISU",tr("ICON_VVTK_SPHERE_SEGMENTATION_SWITCH")); mySphereSegmentationAction = new QtxAction(tr("MNU_VVTK_SPHERE_SEGMENTATION_SWITCH"), @@ -267,11 +284,12 @@ VVTK_MainWindow1 mySphereSegmentationAction->setToggleAction(true); mySphereSegmentationAction->setStatusTip(tr("DSC_VVTK_SPHERE_SEGMENTATION_SWITCH")); mySphereSegmentationAction->addTo( myPtsToolBar ); - connect( mySphereSegmentationAction, SIGNAL( toggled( bool ) ), this, SLOT( OnSegmentationSwitch( bool ) ) ); + connect( mySphereSegmentationAction, SIGNAL( activated() ), this, SLOT( OnSegmentationSwitch() ) ); mySegmentationCursorDlg = new VVTK_SegmentationCursorDlg( this, "SegmentationCursorDlg" ); mySegmentationCursorDlg->SetPlaneAction( myPlaneSegmentationAction ); mySegmentationCursorDlg->SetSphereAction( mySphereSegmentationAction ); + connect( mySegmentationCursorDlg, SIGNAL( scgClose() ), this, SLOT( OnSegmentationSwitch() ) ); } void @@ -282,7 +300,7 @@ VVTK_MainWindow1 myRenderer = theRenderer; VVTK_MainWindow::Initialize(theInteractor); - mySegmentationCursorDlg->SetWidget( theRenderer->GetImplicitFunctionWidget() ); + mySegmentationCursorDlg->SetWidgetCtrl( theRenderer->GetWidgetCtrl() ); myPickingDlg->SetInteractor( GetInteractor() ); } @@ -327,11 +345,9 @@ VVTK_MainWindow1 //---------------------------------------------------------------------------- -VISU_ImplicitFunctionWidget* -VVTK_MainWindow1 -::GetImplicitFunctionWidget() +VISU_WidgetCtrl* VVTK_MainWindow1::GetWidgetCtrl() { - return myRenderer->GetImplicitFunctionWidget(); + return myRenderer->GetWidgetCtrl(); } VISU_InsideCursorSettings* @@ -356,15 +372,23 @@ VVTK_MainWindow1 } //---------------------------------------------------------------------------- -void -VVTK_MainWindow1 -::OnSegmentationSwitch(bool theIsSegmentationOn) +void VVTK_MainWindow1::OnSegmentationSwitch() { + bool theIsSegmentationOn = myPlaneSegmentationAction->isOn() || + mySphereSegmentationAction->isOn(); + QtxAction* anAction = ( QtxAction* )sender(); if( !anAction ) return; - - myRenderer->GetImplicitFunctionWidget()->SetEnabled(theIsSegmentationOn); + + VISU_WidgetCtrl *pWidgetCtrl=myRenderer->GetWidgetCtrl(); + //printf(" \n*OnSegmentationSwitch(%d)\n", theIsSegmentationOn); + + if (theIsSegmentationOn) { + int anIndex= (anAction == myPlaneSegmentationAction) ? 0 : 1; + pWidgetCtrl->SetActiveIndex(anIndex); + } + pWidgetCtrl->SetEnabled(theIsSegmentationOn); if( anAction == myPlaneSegmentationAction && theIsSegmentationOn ) mySphereSegmentationAction->setOn( false ); diff --git a/src/VVTK/VVTK_MainWindow.h b/src/VVTK/VVTK_MainWindow.h index 27b28c29..95454fd5 100644 --- a/src/VVTK/VVTK_MainWindow.h +++ b/src/VVTK/VVTK_MainWindow.h @@ -10,7 +10,7 @@ class QSplitter; -class VISU_ImplicitFunctionWidget; +class VISU_WidgetCtrl; class VVTK_SegmentationCursorDlg; class VISU_InsideCursorSettings; class VISU_OutsideCursorSettings; @@ -20,6 +20,7 @@ class VVTK_PickingDlg; class VVTK_MainWindow2; class VVTK_Renderer1; class VVTK_Renderer2; +class VVTK_Recorder; //---------------------------------------------------------------------------- class VVTK_EXPORT VVTK_MainWindow: public SVTK_MainWindow @@ -42,9 +43,7 @@ public: void OnInteractorStyleSwitch(bool theIsGaussStyleOn); - virtual - void - OnSelectionModeSwitch(bool theIsSelectionOn); + virtual void OnSelectionModeSwitch(bool theIsSelectionOn); virtual void @@ -74,6 +73,8 @@ public: QtxAction* myPlayAction; QtxAction* myPauseAction; QtxAction* myStopAction; + + VVTK_Recorder *myRecorder; }; @@ -101,8 +102,7 @@ public: SUIT_ResourceMgr* theResourceMgr, VISU_PickingSettings* thePickingSettings); - VISU_ImplicitFunctionWidget* - GetImplicitFunctionWidget(); + VISU_WidgetCtrl* GetWidgetCtrl(); VISU_InsideCursorSettings* GetInsideCursorSettings(); @@ -115,7 +115,7 @@ public: public slots: void - OnSegmentationSwitch(bool theIsSegmentationOn); + OnSegmentationSwitch();//bool theIsSegmentationOn); virtual void diff --git a/src/VVTK/VVTK_Recorder.cxx b/src/VVTK/VVTK_Recorder.cxx new file mode 100755 index 00000000..8bdcba16 --- /dev/null +++ b/src/VVTK/VVTK_Recorder.cxx @@ -0,0 +1,362 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : +// $Header$ + +#include "VVTK_Recorder.hxx" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "VVTK_ImageWriter.h" +#include "VVTK_ImageWriterMgr.h" +// +static + void GetNameJPEG(const char *pName, + const int aIndex, + char *pNameJPEG); +// +vtkCxxRevisionMacro(VVTK_Recorder,"$Revision$"); +vtkStandardNewMacro(VVTK_Recorder); +//=============================================== +// function: VVTK_Recorder +// purpose : +//=============================================== +VVTK_Recorder::VVTK_Recorder() + : vtkObject() +{ + myRenderWindow=NULL; + myFilter=NULL; + myState=VVTK_Recorder_Stop; + myNbFPS=10.; + myErrorStatus=0; + myCommand=vtkCallbackCommand::New(); + myCommand->SetClientData(this); + myCommand->SetCallback(VVTK_Recorder::ProcessEvents); + // + myPriority=0.; + myTimeStart=0.; + myFrameIndex=0; + myPaused=0; + // + myFilter=vtkWindowToImageFilter::New(); + myWriterMgr=new VVTK_ImageWriterMgr; + myName=new char [512]; + myName[0]=0; + myNbWrittenFrames=0; +} +//=============================================== +// function: ~ +// purpose : +//=============================================== +VVTK_Recorder::~VVTK_Recorder() +{ + myCommand->Delete(); + myFilter->Delete(); + delete myWriterMgr; + delete myName; +} +//=============================================== +// function: DoPlay +// purpose : +//=============================================== +void VVTK_Recorder::DoPlay() +{ +} +//=============================================== +// function: DoStop +// purpose : +//=============================================== +void VVTK_Recorder::DoStop() +{ +} +//=============================================== +// function: SetName +// purpose : +//=============================================== +void VVTK_Recorder::SetName(const char* theName) +{ + strcpy(myName, theName); +} +//=============================================== +// function: Name +// purpose : +//=============================================== +const char* VVTK_Recorder::Name()const +{ + return myName; +} +//=============================================== +// function: SetNbFPS +// purpose : +//=============================================== +void VVTK_Recorder::SetNbFPS(const double theNb) +{ + myNbFPS=theNb; +} +//=============================================== +// function: NbFPS +// purpose : +//=============================================== +double VVTK_Recorder::NbFPS()const +{ + return myNbFPS; +} +//=============================================== +// function: SetRenderWindow +// purpose : +//=============================================== +void VVTK_Recorder::SetRenderWindow(vtkRenderWindow* pW) +{ + myRenderWindow=pW; +} +//=============================================== +// function: RenderWindow +// purpose : +//=============================================== +vtkRenderWindow* VVTK_Recorder::RenderWindow() +{ + return myRenderWindow; +} +//=============================================== +// function: ErrorStatus +// purpose : +//=============================================== +int VVTK_Recorder::ErrorStatus()const +{ + return myErrorStatus; +} +//=============================================== +// function: State +// purpose : +//=============================================== +int VVTK_Recorder::State()const +{ + return myState; +} +//=============================================== +// function: ProcessEvents +// purpose : +//=============================================== +void VVTK_Recorder::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + if(vtkObject* pObj=reinterpret_cast(theClientData)) { + if(VVTK_Recorder* pSelf=reinterpret_cast(pObj)) { + if(theEvent==vtkCommand::EndEvent){ + if (pSelf->State()==VVTK_Recorder::VVTK_Recorder_Record){ + pSelf->DoRecord(); + } + } + } + } +} +//=============================================== +// function: Record +// purpose : +//=============================================== +void VVTK_Recorder::Record() +{ + if (myState==VVTK_Recorder_Stop){ + if (myRenderWindow){ + myState=VVTK_Recorder_Record; + // + myFilter->SetInput(myRenderWindow); + // + myFrameIndex=-1; + myNbWrittenFrames=0; + // + myRenderWindow->RemoveObserver(myCommand); + myRenderWindow->AddObserver(vtkCommand::EndEvent, + myCommand, + myPriority); + myRenderWindow->Render(); + } + } +} +//=============================================== +// function: Play +// purpose : +//=============================================== +void VVTK_Recorder::Play() +{ + if (myState==VVTK_Recorder_Stop){ + if (myRenderWindow){ + myState=VVTK_Recorder_Play; + } + } +} +//=============================================== +// function: Stop +// purpose : +//=============================================== +void VVTK_Recorder::Stop() +{ + if (myState==VVTK_Recorder_Record) { + myWriterMgr->Stop(); + AddSkippedFrames(); + MakeFileAVI(); + } + if (myState==VVTK_Recorder_Play){ + //... + } + myState=VVTK_Recorder_Stop; +} +//=============================================== +// function: Pause +// purpose : +//=============================================== +void VVTK_Recorder::Pause() +{ + myPaused=myPaused ? 0 : 1; +} +//=============================================== +// function: DoRecord +// purpose : +//=============================================== +void VVTK_Recorder::DoRecord() +{ + if (myPaused){ + return; + } + // + char *buf, aPrefix[512]; + double aTimeNow, dT; + int aFrameIndex, aQuality, aProgressive; + // + if (myFrameIndex<0) { + myFrameIndex=0; + myTimeStart=vtkTimerLog::GetCurrentTime(); + // + myWriterMgr->start(); + // + } + else { + aTimeNow=vtkTimerLog::GetCurrentTime(); + dT=aTimeNow-myTimeStart; + if (dT<0.){ + //printf(" * DoRecord() dT<0 returned\n"); + return; + } + aFrameIndex=(int)(dT*myNbFPS); + if (aFrameIndex==myFrameIndex) { + return; + } + myFrameIndex=aFrameIndex; + } + // + myRenderWindow->RemoveObserver(myCommand); + // + myFilter->Modified(); + // + buf=new char [512]; + GetNameJPEG(myName, myFrameIndex, buf); + //printf(" *buf: %s\n", buf); + // + PreWrite(); + //=============== + // + aQuality=95; + aProgressive=1; + vtkImageData *pC=vtkImageData::New(); + pC->DeepCopy(myFilter->GetOutput()); + // + myWriterMgr->StartImageWriter(buf, aProgressive, aQuality, pC); + ++myNbWrittenFrames; + // + //=============== + myRenderWindow->AddObserver(vtkCommand::EndEvent, + myCommand, + myPriority); +} +//=============================================== +// function: PreWrite +// purpose : +//=============================================== +void VVTK_Recorder::PreWrite() +{ + vtkImageData *pImageData=myFilter->GetOutput(); + // + if (!pImageData){ + myErrorStatus=20; + return; + } + pImageData->UpdateInformation(); + int *wExtent=pImageData->GetWholeExtent(); + pImageData->SetUpdateExtent(wExtent[0], wExtent[1], + wExtent[2], wExtent[3], + 0,0); + pImageData->UpdateData(); +} +//=============================================== +// function: AddSkippedFrames +// purpose : +//=============================================== +void VVTK_Recorder::AddSkippedFrames() +{ + myErrorStatus=0; + // + +} +//=============================================== +// function: MakeFileAVI +// purpose : +//=============================================== +void VVTK_Recorder::MakeFileAVI() +{ + myErrorStatus=0; + // + int iNbFPS; + char aCmd[1024], fmt[]={"_\%06d.jpeg"}; + //"jpeg2yuv -f 10 -I p -n 16 -v 0 -j abcx_1%06d.jpeg | yuv2lav -o z.avi" + // + iNbFPS=(int)myNbFPS; + sprintf(aCmd, "jpeg2yuv -I p -v 0 -f %d -n %d -j %s%s | yuv2lav -o %s.avi", + iNbFPS, myNbWrittenFrames, myName, fmt, myName); + // + myErrorStatus=system(aCmd); +} +//=============================================== +// function: GetNameJPEG +// purpose : +//=============================================== +void GetNameJPEG(const char *pName, + const int aIndex, + char *pNameJPEG) +{ + sprintf(pNameJPEG, "%s_%06d.jpeg", pName, aIndex); +} + diff --git a/src/VVTK/VVTK_Recorder.h b/src/VVTK/VVTK_Recorder.h new file mode 100755 index 00000000..849343e3 --- /dev/null +++ b/src/VVTK/VVTK_Recorder.h @@ -0,0 +1,107 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : +// Author : +// Module : SALOME +// $Header$ + +#ifndef _VVTK_Recorder_Header_File_ +#define _VVTK_Recorder_Header_File_ + +#include +#include + +class vtkRenderWindow; +class vtkCallbackCommand; +class vtkWindowToImageFilter; +class VVTK_ImageWriterMgr; +// +class VVTK_Recorder : public vtkObject { + +protected: + enum State { + VVTK_Recorder_Unknown=0, + VVTK_Recorder_Record, + VVTK_Recorder_Play, + VVTK_Recorder_Stop + }; + +public: + static VVTK_Recorder *New(); + vtkTypeRevisionMacro(VVTK_Recorder,vtkObject); + // + void SetRenderWindow(vtkRenderWindow* pW); + vtkRenderWindow* RenderWindow(); + // + void SetName(const char *theName); + const char* Name()const; + // + void SetNbFPS(const double theNbFPS); + double NbFPS()const; + // + void Record(); + void Play(); + void Pause(); + void Stop(); + // + int State()const; + int ErrorStatus()const; + + static void ProcessEvents(vtkObject* theObject, + unsigned long theEvent, + void* theClientData, + void* theCallData); + + // +protected : + VVTK_Recorder(); + ~VVTK_Recorder(); + void DoRecord(); + void DoPlay(); + void DoStop(); + void MakeFileAVI(); + void AddSkippedFrames(); + void PreWrite(); + // +protected : + int myState; + int myPaused; + double myNbFPS; + int myErrorStatus; + int myFrameIndex; + int myNbWrittenFrames; + float myPriority; + double myTimeStart; + char *myName; + + vtkCallbackCommand *myCommand; + vtkRenderWindow *myRenderWindow; + vtkWindowToImageFilter *myFilter; + VVTK_ImageWriterMgr *myWriterMgr; + +private: + VVTK_Recorder(const VVTK_Recorder&); //Not implemented + void operator=(const VVTK_Recorder&); //Not implemented +}; +#endif diff --git a/src/VVTK/VVTK_Renderer.cxx b/src/VVTK/VVTK_Renderer.cxx index 8ae7add6..eb315b7f 100644 --- a/src/VVTK/VVTK_Renderer.cxx +++ b/src/VVTK/VVTK_Renderer.cxx @@ -30,7 +30,9 @@ #include "VISU_GaussPtsAct.h" #include "VISU_GaussPointsPL.hxx" -#include "VISU_ImplicitFunctionWidget.h" +#include "VISU_WidgetCtrl.hxx" +#include "VISU_PlanesWidget.hxx" +#include "VISU_SphereWidget.hxx" #include #include @@ -213,27 +215,30 @@ VVTK_Renderer vtkStandardNewMacro(VVTK_Renderer1); //---------------------------------------------------------------------------- -VVTK_Renderer1 -::VVTK_Renderer1(): - myImplicitFunctionWidget(VISU_ImplicitFunctionWidget::New()), +VVTK_Renderer1::VVTK_Renderer1(): + //myImplicitFunctionWidget(VISU_ImplicitFunctionWidget::New()), + myWidgetCtrl(VISU_WidgetCtrl::New()), myOutsideCursorSettings(NULL) { if(MYDEBUG) INFOS("VVTK_Renderer1() - "<SetPlaceFactor(1.1); - myImplicitFunctionWidget->SetOutlineTranslation(false); - vtkProperty* aSelectedPlaneProperty = myImplicitFunctionWidget->GetSelectedPlaneProperty(); - vtkProperty* aPlaneProperty = myImplicitFunctionWidget->GetPlaneProperty(); + //myImplicitFunctionWidget->SetPlaceFactor(1.1); + myWidgetCtrl->SetPlaceFactor(1.1); + // + VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget(); + pPlanesWidget->SetOutlineTranslation(false); + vtkProperty* aSelectedPlaneProperty = pPlanesWidget->GetSelectedPlaneProperty(); + vtkProperty* aPlaneProperty = pPlanesWidget->GetPlaneProperty(); aPlaneProperty->SetOpacity(aSelectedPlaneProperty->GetOpacity()*1.5); - - myImplicitFunctionWidget->Delete(); + // + myWidgetCtrl->Delete(); } VVTK_Renderer1 ::~VVTK_Renderer1() { if(MYDEBUG) INFOS("~VVTK_Renderer1() - "<SetInteractor(NULL); + myWidgetCtrl->SetInteractor(NULL); } //---------------------------------------------------------------------------- @@ -242,10 +247,10 @@ VVTK_Renderer1 ::AddActor(VTKViewer_Actor* theActor) { if(VISU_GaussPtsAct1* anActor = dynamic_cast(theActor)){ - anActor->SetImplicitFunctionWidget(GetImplicitFunctionWidget()); + anActor->SetWidgetCtrl(GetWidgetCtrl()); anActor->SetOutsideCursorSettings(myOutsideCursorSettings); Superclass::AddActor(anActor); - AdjustImplicitFunctionWidget(); + AdjustWidgetCtrl(); } } @@ -256,21 +261,34 @@ VVTK_Renderer1 { using namespace VISU; if(VISU_GaussPtsAct1* anActor = dynamic_cast(theActor)){ - anActor->SetImplicitFunctionWidget(NULL); + anActor->SetWidgetCtrl(NULL); anActor->SetOutsideCursorSettings(NULL); Superclass::RemoveActor(theActor); - AdjustImplicitFunctionWidget(); + AdjustWidgetCtrl(); } } //---------------------------------------------------------------------------- -void VVTK_Renderer1::AdjustImplicitFunctionWidget() +void VVTK_Renderer1::AdjustWidgetCtrl() { if(SVTK_Renderer::OnAdjustActors()){ - myImplicitFunctionWidget->InitialPlaceWidget(myBndBox); - myImplicitFunctionWidget->SetOrigin((myBndBox[1] + myBndBox[0]) / 2.0, - (myBndBox[3] + myBndBox[2]) / 2.0, - (myBndBox[5] + myBndBox[4]) / 2.0); - myImplicitFunctionWidget->SetHandleSize(myImplicitFunctionWidget->GetHandleSize()); + VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget(); + pPlanesWidget->InitialPlaceWidget(myBndBox); + pPlanesWidget->SetOrigin(0.5*(myBndBox[1] + myBndBox[0]), + 0.5*(myBndBox[3] + myBndBox[2]), + 0.5*(myBndBox[5] + myBndBox[4])); + // + VISU_SphereWidget *pSphereWidget=myWidgetCtrl->GetSphereWidget(); + pSphereWidget->SetCenter(0.5*(myBndBox[1] + myBndBox[0]), + 0.5*(myBndBox[3] + myBndBox[2]), + 0.5*(myBndBox[5] + myBndBox[4])); + float dX, dXmin=1.e20; + for (int i=0; i<3; ++i) { + dX=myBndBox[2*i+1]-myBndBox[2*i]; + if (dXSetRadius(dXmin); } } //---------------------------------------------------------------------------- @@ -280,7 +298,7 @@ VVTK_Renderer1 SVTK_Selector* theSelector) { SVTK_Renderer::Initialize(theInteractor,theSelector); - myImplicitFunctionWidget->SetInteractor(theInteractor); + myWidgetCtrl->SetInteractor(theInteractor); } //---------------------------------------------------------------------------- @@ -292,11 +310,9 @@ VVTK_Renderer1 } //---------------------------------------------------------------------------- -VISU_ImplicitFunctionWidget* -VVTK_Renderer1 -::GetImplicitFunctionWidget() +VISU_WidgetCtrl* VVTK_Renderer1::GetWidgetCtrl() { - return myImplicitFunctionWidget.GetPointer(); + return myWidgetCtrl.GetPointer(); } //---------------------------------------------------------------------------- @@ -331,20 +347,18 @@ VVTK_Renderer2 } //---------------------------------------------------------------------------- -void -VVTK_Renderer2 -::SetImplicitFunctionWidget(VISU_ImplicitFunctionWidget* theWidget) +void VVTK_Renderer2::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl) { - theWidget->AddObserver(vtkCommand::EndInteractionEvent, - myEventCallbackCommand.GetPointer(), - myPriority); - theWidget->AddObserver(vtkCommand::EnableEvent, - myEventCallbackCommand.GetPointer(), - myPriority); - theWidget->AddObserver(vtkCommand::DisableEvent, - myEventCallbackCommand.GetPointer(), - myPriority); - myWidget = theWidget; + theWidgetCtrl->AddObserver(vtkCommand::EndInteractionEvent, + myEventCallbackCommand.GetPointer(), + myPriority); + theWidgetCtrl->AddObserver(vtkCommand::EnableEvent, + myEventCallbackCommand.GetPointer(), + myPriority); + theWidgetCtrl->AddObserver(vtkCommand::DisableEvent, + myEventCallbackCommand.GetPointer(), + myPriority); + myWidgetCtrl = theWidgetCtrl; } void @@ -373,14 +387,12 @@ VVTK_Renderer2 //---------------------------------------------------------------------------- -void -VVTK_Renderer2 -::AddActor(VTKViewer_Actor* theActor) +void VVTK_Renderer2::AddActor(VTKViewer_Actor* theActor) { if(VISU_GaussPtsAct1* anActor = dynamic_cast(theActor)){ if(VISU::TGaussPtsActorFactory* aFactory = anActor->GetGaussPtsFactory()){ if(VISU_GaussPtsAct2* anActor2 = aFactory->CloneActor(anActor)){ - anActor2->SetImplicitFunctionWidget(myWidget); + anActor2->SetWidgetCtrl(myWidgetCtrl); Superclass::AddActor(anActor2); } } @@ -394,7 +406,7 @@ VVTK_Renderer2 { using namespace VISU; if(VISU_GaussPtsAct2* anActor = dynamic_cast(theActor)){ - anActor->SetImplicitFunctionWidget(NULL); + anActor->SetWidgetCtrl(NULL); Superclass::RemoveActor(theActor); } } diff --git a/src/VVTK/VVTK_Renderer.h b/src/VVTK/VVTK_Renderer.h index c0130a24..5860f4ba 100644 --- a/src/VVTK/VVTK_Renderer.h +++ b/src/VVTK/VVTK_Renderer.h @@ -33,7 +33,7 @@ #include "SVTK_Renderer.h" -class VISU_ImplicitFunctionWidget; +class VISU_WidgetCtrl; class VISU_InsideCursorSettings; class VISU_OutsideCursorSettings; class VISU_PickingSettings; @@ -95,8 +95,7 @@ class VVTK_EXPORT VVTK_Renderer1 : public VVTK_Renderer void SetOutsideCursorSettings(VISU_OutsideCursorSettings* theOutsideCursorSettings); - VISU_ImplicitFunctionWidget* - GetImplicitFunctionWidget(); + VISU_WidgetCtrl* GetWidgetCtrl(); protected: VVTK_Renderer1(); @@ -106,9 +105,9 @@ class VVTK_EXPORT VVTK_Renderer1 : public VVTK_Renderer bool OnAdjustActors(); - void AdjustImplicitFunctionWidget(); + void AdjustWidgetCtrl(); - vtkSmartPointer myImplicitFunctionWidget; + vtkSmartPointer myWidgetCtrl; VISU_OutsideCursorSettings* myOutsideCursorSettings; vtkSmartPointer myTextActor; }; @@ -129,8 +128,7 @@ class VVTK_EXPORT VVTK_Renderer2 : public VVTK_Renderer void RemoveActor(VTKViewer_Actor* theActor); - void - SetImplicitFunctionWidget(VISU_ImplicitFunctionWidget* theWidget); + void SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl); void OnEndInteractionEvent(); @@ -153,7 +151,7 @@ class VVTK_EXPORT VVTK_Renderer2 : public VVTK_Renderer // Priority at which events are processed float myPriority; - VISU_ImplicitFunctionWidget* myWidget; + VISU_WidgetCtrl* myWidgetCtrl; }; diff --git a/src/VVTK/VVTK_SegmentationCursorDlg.cxx b/src/VVTK/VVTK_SegmentationCursorDlg.cxx index 4be07d71..5d4cfe10 100644 --- a/src/VVTK/VVTK_SegmentationCursorDlg.cxx +++ b/src/VVTK/VVTK_SegmentationCursorDlg.cxx @@ -14,7 +14,10 @@ #include "VISU_GaussPtsAct.h" #include "VISU_GaussPtsSettings.h" -#include "VISU_ImplicitFunctionWidget.h" + +#include "VISU_WidgetCtrl.hxx" +#include "VISU_PlanesWidget.hxx" +#include "VISU_SphereWidget.hxx" #include "VISU_GaussPointsPL.hxx" @@ -246,7 +249,7 @@ VVTK_SegmentationCursorDlg::VVTK_SegmentationCursorDlg( QWidget* parent, const c anOutsideGroupLayout->addWidget( myOutsidePrimitiveBox, 0, 0 ); anOutsideGroupLayout->addWidget( myOutsideSizeBox, 1, 0 ); - + // myTabBox->addTab( myGaussPointsBox, tr( "GAUSS_POINTS_TAB" ) ); myTabBox->showPage( myGaussPointsBox ); @@ -282,13 +285,13 @@ VVTK_SegmentationCursorDlg::~VVTK_SegmentationCursorDlg() { } -void VVTK_SegmentationCursorDlg::SetWidget( VISU_ImplicitFunctionWidget* theWidget ) +void VVTK_SegmentationCursorDlg::SetWidgetCtrl( VISU_WidgetCtrl* theWidgetCtrl ) { - myWidget = theWidget; + myWidgetCtrl = theWidgetCtrl; - myWidget->AddObserver(vtkCommand::EndInteractionEvent, - myEventCallbackCommand.GetPointer(), - myPriority); + myWidgetCtrl->AddObserver(vtkCommand::EndInteractionEvent, + myEventCallbackCommand.GetPointer(), + myPriority); } void VVTK_SegmentationCursorDlg::ProcessEvents(vtkObject* vtkNotUsed(theObject), @@ -313,25 +316,35 @@ void VVTK_SegmentationCursorDlg::UpdateSegmentation() myDepthGroup->show(); myRadiusGroup->hide(); + VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget(); float origin[3]; - myWidget->GetOrigin( origin ); + pPlanesWidget->GetOrigin( origin ); myXOriginSpinBox->setValue( origin[0] ); myYOriginSpinBox->setValue( origin[1] ); myZOriginSpinBox->setValue( origin[2] ); float normal[3]; - myWidget->GetNormal( normal ); + pPlanesWidget->GetNormal( normal ); myDXDirectionSpinBox->setValue( normal[0] ); myDYDirectionSpinBox->setValue( normal[1] ); myDZDirectionSpinBox->setValue( normal[2] ); - myDepthSpinBox->setValue( myWidget->Distance() ); + myDepthSpinBox->setValue( pPlanesWidget->Distance() ); } else { myDirectionGroup->hide(); myDepthGroup->hide(); myRadiusGroup->show(); + + VISU_SphereWidget *pSphereWidget=myWidgetCtrl->GetSphereWidget(); + float origin[3], aRadius; + pSphereWidget->GetCenter(origin); + myXOriginSpinBox->setValue( origin[0] ); + myYOriginSpinBox->setValue( origin[1] ); + myZOriginSpinBox->setValue( origin[2] ); + aRadius=pSphereWidget->GetRadius(); + myRadiusSpinBox->setValue(aRadius); } } @@ -525,26 +538,38 @@ void VVTK_SegmentationCursorDlg::ApplySegmentationCursor() { if( myIsPlaneSegmentation ) { + VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget(); float origin[3]; origin[0] = myXOriginSpinBox->value(); origin[1] = myYOriginSpinBox->value(); origin[2] = myZOriginSpinBox->value(); - myWidget->SetOrigin( origin ); + pPlanesWidget->SetOrigin( origin ); float normal[3]; normal[0] = myDXDirectionSpinBox->value(); normal[1] = myDYDirectionSpinBox->value(); normal[2] = myDZDirectionSpinBox->value(); - myWidget->SetNormal( normal ); + pPlanesWidget->SetNormal( normal ); - myWidget->SetDistance( myDepthSpinBox->value() ); + pPlanesWidget->SetDistance( myDepthSpinBox->value() ); - myWidget->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); - myWidget->GetInteractor()->Render(); + myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); + myWidgetCtrl->GetInteractor()->Render(); } else { + VISU_SphereWidget *pSphereWidget=myWidgetCtrl->GetSphereWidget(); + float origin[3], aRadius; + origin[0] = myXOriginSpinBox->value(); + origin[1] = myYOriginSpinBox->value(); + origin[2] = myZOriginSpinBox->value(); + pSphereWidget->SetCenter(origin); + + aRadius=myRadiusSpinBox->value(); + pSphereWidget->SetRadius(aRadius); + myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); + myWidgetCtrl->GetInteractor()->Render(); } } @@ -601,6 +626,9 @@ void VVTK_SegmentationCursorDlg::onClickClose() { myPlaneAction->setOn( false ); mySphereAction->setOn( false ); + + emit scgClose(); + reject(); } @@ -608,5 +636,8 @@ void VVTK_SegmentationCursorDlg::done( int r ) { myPlaneAction->setOn( false ); mySphereAction->setOn( false ); + + emit scgClose(); + QDialog::done( r ); } diff --git a/src/VVTK/VVTK_SegmentationCursorDlg.h b/src/VVTK/VVTK_SegmentationCursorDlg.h index a014eeaa..009278b8 100644 --- a/src/VVTK/VVTK_SegmentationCursorDlg.h +++ b/src/VVTK/VVTK_SegmentationCursorDlg.h @@ -34,7 +34,7 @@ class QtxDblSpinBox; class VISU_GaussPtsAct1; class VISU_InsideCursorSettings; class VISU_OutsideCursorSettings; -class VISU_ImplicitFunctionWidget; +class VISU_WidgetCtrl; class VVTK_PrimitiveBox; class VVTK_SizeBox; @@ -47,7 +47,7 @@ public: VVTK_SegmentationCursorDlg( QWidget* parent = 0, const char* name = 0 ); ~VVTK_SegmentationCursorDlg(); - void SetWidget( VISU_ImplicitFunctionWidget* ); + void SetWidgetCtrl( VISU_WidgetCtrl* ); void SetPlaneAction( QtxAction* theAction ) { myPlaneAction = theAction; } void SetSphereAction( QtxAction* theAction ) { mySphereAction = theAction; } @@ -82,6 +82,9 @@ protected slots: void onClickApply(); void onClickClose(); +signals: + void scgClose(); + private: QTabWidget* myTabBox; @@ -110,7 +113,7 @@ private: float myPriority; vtkSmartPointer myEventCallbackCommand; - VISU_ImplicitFunctionWidget* myWidget; + VISU_WidgetCtrl* myWidgetCtrl; QtxAction* myPlaneAction; QtxAction* mySphereAction; diff --git a/src/VVTK/VVTK_ViewWindow.cxx b/src/VVTK/VVTK_ViewWindow.cxx index d26ba845..7ed40c73 100755 --- a/src/VVTK/VVTK_ViewWindow.cxx +++ b/src/VVTK/VVTK_ViewWindow.cxx @@ -52,9 +52,7 @@ VVTK_ViewWindow {} //---------------------------------------------------------------------------- -void -VVTK_ViewWindow -::Initialize(SVTK_ViewModelBase* theModel) +void VVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel) { if(SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr()){ QWidget* aWidget = new QWidget(this); @@ -65,7 +63,7 @@ VVTK_ViewWindow QSplitter* aSplitter = new QSplitter(Qt::Vertical,aWidget); //aSplitter->setChildrenCollapsible(true); - VISU_ImplicitFunctionWidget* anImplicitFunctionWidget = NULL; + VISU_WidgetCtrl* aWidgetCtrl = NULL; VISU_InsideCursorSettings* anInsideCursorSettings = NULL; VISU_OutsideCursorSettings* anOutsideCursorSettings = NULL; VISU_PickingSettings* aPickingSettings = NULL; @@ -89,7 +87,9 @@ VVTK_ViewWindow VVTK_Renderer1* aRenderer = VVTK_Renderer1::New(); aRenderer->Initialize(aDevice,aSelector); - anImplicitFunctionWidget = aRenderer->GetImplicitFunctionWidget(); + + aWidgetCtrl = aRenderer->GetWidgetCtrl(); + aRenderer->SetInsideCursorSettings(anInsideCursorSettings); aRenderer->SetOutsideCursorSettings(anOutsideCursorSettings); aRenderer->SetPickingSettings(aPickingSettings); @@ -123,7 +123,9 @@ VVTK_ViewWindow VVTK_Renderer2* aRenderer = VVTK_Renderer2::New(); aRenderer->Initialize(aDevice,aSelector); - aRenderer->SetImplicitFunctionWidget(anImplicitFunctionWidget); + + aRenderer->SetWidgetCtrl(aWidgetCtrl); + aRenderer->SetInsideCursorSettings(anInsideCursorSettings); aRenderer->SetPickingSettings(aPickingSettings); -- 2.39.2