#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"
myEventCallbackCommand(vtkCallbackCommand::New()),
myPriority(0.0),
myDeviceActor(VISU_GaussPtsDeviceActor::New()),
- myWidget(NULL),
+ myWidgetCtrl(NULL),
myGaussPointsPL(NULL),
myLastObjPointID(-1),
myTextActor(VISU_FramedTextActor::New()),
::~VISU_GaussPtsAct()
{
if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::~VISU_GaussPtsAct - this = "<<this);
- SetImplicitFunctionWidget(NULL);
+ SetWidgetCtrl(NULL);
SetInteractor(NULL);
SetPickingSettings(NULL);
}
//----------------------------------------------------------------------------
void
VISU_GaussPtsAct
-::SetImplicitFunctionWidget(VISU_ImplicitFunctionWidget* theWidget)
+::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
{
- if(myWidget == theWidget)
+ if(myWidgetCtrl == theWidgetCtrl)
return;
- if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::SetImplicitFunctionWidget - this = "<<this<<"; theWidget = "<<theWidget);
-
- if(myWidget)
- myWidget->RemoveObserver(myEventCallbackCommand.GetPointer());
-
- if(theWidget){
- theWidget->AddObserver(vtkCommand::EnableEvent,
- myEventCallbackCommand.GetPointer(),
- myPriority);
- theWidget->AddObserver(vtkCommand::DisableEvent,
- myEventCallbackCommand.GetPointer(),
- myPriority);
- theWidget->AddObserver(vtkCommand::EndInteractionEvent,
- myEventCallbackCommand.GetPointer(),
- myPriority);
+ if(MYDEBUG)
+ MESSAGE("VISU_GaussPtsAct::SetWidgetCtrl - this = "<<this<<"; theWidget = "<<theWidgetCtrl);
+
+ if(myWidgetCtrl)
+ myWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
+
+ if(theWidgetCtrl){
+ theWidgetCtrl->AddObserver(vtkCommand::EnableEvent,
+ myEventCallbackCommand.GetPointer(),
+ myPriority);
+ theWidgetCtrl->AddObserver(vtkCommand::DisableEvent,
+ myEventCallbackCommand.GetPointer(),
+ myPriority);
+ theWidgetCtrl->AddObserver(vtkCommand::EndInteractionEvent,
+ myEventCallbackCommand.GetPointer(),
+ myPriority);
}
- myWidget = theWidget;
+ myWidgetCtrl = theWidgetCtrl;
}
bool
myDeviceActor->ShallowCopyPL(aPipeLine);
// Restore implicit function
- if(myWidget){
- vtkImplicitFunction* aFunction = myWidget->ImplicitFunction();
+ if(myWidgetCtrl){
+ vtkImplicitFunction* aFunction = myWidgetCtrl->ImplicitFunction();
myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(aFunction);
}
}
//----------------------------------------------------------------------------
void
VISU_GaussPtsAct1
-::SetImplicitFunctionWidget(VISU_ImplicitFunctionWidget* theWidget)
+::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
{
- if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetImplicitFunctionWidget - this = "<<this);
+ if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetWidgetCtrl - this = "<<this);
- if(myWidget == theWidget)
+ if(myWidgetCtrl == theWidgetCtrl){
return;
+ }
- if(myWidget){
+ if(myWidgetCtrl){
myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
myInsideDeviceActor->SetVisibility(false);
myCurrentPL = myDeviceActor->GetPipeLine();
}
- if(theWidget){
- myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidget->ImplicitFunction());
- myInsideDeviceActor->SetVisibility(GetVisibility() && theWidget->IsEnabled());
-
- myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidget->ImplicitFunction());
- myOutsideDeviceActor->SetVisibility(GetVisibility() && theWidget->IsEnabled());
+ if(theWidgetCtrl){
+ myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
+ myInsideDeviceActor->SetVisibility(GetVisibility() && theWidgetCtrl->GetEnabled());
- myCurrentPL = myInsideDeviceActor->GetPipeLine();
+ myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
+ myOutsideDeviceActor->SetVisibility(GetVisibility() && theWidgetCtrl->GetEnabled());
+
+ //note
+ if (theWidgetCtrl->GetEnabled()) {
+ myCurrentPL = myInsideDeviceActor->GetPipeLine();
+ }
+ //
}
- Superclass::SetImplicitFunctionWidget(theWidget);
+ Superclass::SetWidgetCtrl(theWidgetCtrl);
}
Superclass::SetVisibility(theMode);
- myDeviceActor->SetVisibility(GetVisibility() && !myWidget->IsEnabled());
+ myDeviceActor->SetVisibility(GetVisibility() && !myWidgetCtrl->GetEnabled());
- myInsideDeviceActor->SetVisibility(GetVisibility() && myWidget->IsEnabled());
- myOutsideDeviceActor->SetVisibility(GetVisibility() && myWidget->IsEnabled());
+ myInsideDeviceActor->SetVisibility(GetVisibility() && myWidgetCtrl->GetEnabled());
+ myOutsideDeviceActor->SetVisibility(GetVisibility() && myWidgetCtrl->GetEnabled());
mySetVisibilitySignal(GetVisibility());
}
switch(theEvent){
case vtkCommand::EnableEvent:
case vtkCommand::DisableEvent:
- myDeviceActor->SetVisibility(GetVisibility() && !myWidget->IsEnabled());
- myInsideDeviceActor->SetVisibility(GetVisibility() && myWidget->IsEnabled());
- myOutsideDeviceActor->SetVisibility(GetVisibility() && myWidget->IsEnabled());
+ myDeviceActor->SetVisibility(GetVisibility() && !myWidgetCtrl->GetEnabled());
+ myInsideDeviceActor->SetVisibility(GetVisibility() && myWidgetCtrl->GetEnabled());
+ myOutsideDeviceActor->SetVisibility(GetVisibility() && myWidgetCtrl->GetEnabled());
break;
default:
break;
Superclass::ShallowCopyPL(thePipeLine);
// Restore implicit function
- if(myWidget){
- vtkImplicitFunction* aFunction = myWidget->ImplicitFunction();
+ if(myWidgetCtrl){
+ vtkImplicitFunction* aFunction = myWidgetCtrl->ImplicitFunction();
myDeviceActor->GetPipeLine()->SetImplicitFunction(aFunction);
}
}
//----------------------------------------------------------------------------
void
VISU_GaussPtsAct2
-::SetImplicitFunctionWidget(VISU_ImplicitFunctionWidget* theWidget)
+::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
{
- if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetImplicitFunctionWidget - this = "<<this);
+ if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetWidgetCtrl - this = "<<this);
- if(myWidget == theWidget)
+ if(myWidgetCtrl == theWidgetCtrl)
return;
- if(myWidget){
- theWidget->RemoveObserver(myEventCallbackCommand.GetPointer());
+ if(myWidgetCtrl){
+ theWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
myDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
myDeviceActor->SetVisibility(false);
}
- if(theWidget){
- myDeviceActor->GetPipeLine()->SetImplicitFunction(theWidget->ImplicitFunction());
- myDeviceActor->SetVisibility(Superclass::GetVisibility() && theWidget->IsEnabled());
+ if(theWidgetCtrl){
+ myDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
+ myDeviceActor->SetVisibility(Superclass::GetVisibility() && theWidgetCtrl->GetEnabled());
}
- Superclass::SetImplicitFunctionWidget(theWidget);
+ Superclass::SetWidgetCtrl(theWidgetCtrl);
}
Superclass::SetVisibility(theMode);
- myDeviceActor->SetVisibility(Superclass::GetVisibility() && myWidget->IsEnabled());
+ myDeviceActor->SetVisibility(Superclass::GetVisibility() && myWidgetCtrl->GetEnabled());
}
int
VISU_GaussPtsAct2
::GetVisibility()
{
- return Superclass::GetVisibility() && myWidget->IsEnabled();
+ return Superclass::GetVisibility() && myWidgetCtrl->GetEnabled();
}
void
switch(theEvent){
case vtkCommand::EnableEvent:
case vtkCommand::DisableEvent:
- myDeviceActor->SetVisibility(Superclass::GetVisibility() && myWidget->IsEnabled());
+ myDeviceActor->SetVisibility(Superclass::GetVisibility() && myWidgetCtrl->GetEnabled());
if (theEvent==vtkCommand::EnableEvent){
Update();
}
#include <vtkSmartPointer.h>
class VISU_GaussPointsPL;
-class VISU_ImplicitFunctionWidget;
+class VISU_WidgetCtrl;
class VISU_OpenGLPointSpriteMapper;
class vtkTextMapper;
bool
GetBarVisibility();
- virtual
- void
- SetImplicitFunctionWidget(VISU_ImplicitFunctionWidget* theWidget);
+ virtual void SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl);
bool
ChangeMagnification();
//----------------------------------------------------------------------------
PDeviceActor myDeviceActor;
- VISU_ImplicitFunctionWidget* myWidget;
+ VISU_WidgetCtrl* myWidgetCtrl;
VISU_GaussPointsPL* myCurrentPL;
vtkSmartPointer<VISU_GaussPointsPL> myGaussPointsPL;
void
SetTransform(VTKViewer_Transform* theTransform);
- virtual
- void
- SetImplicitFunctionWidget(VISU_ImplicitFunctionWidget* theWidget);
+ virtual void SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl);
protected:
//----------------------------------------------------------------------------
int
GetVisibility();
- virtual
- void
- SetImplicitFunctionWidget(VISU_ImplicitFunctionWidget* theWidget);
+ virtual void SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl);
protected:
//----------------------------------------------------------------------------
VISU_GaussPointsPL.hxx \
VISU_Plot3DPL.hxx \
VISU_OpenGLPointSpriteMapper.hxx \
- VISU_ImplicitFunctionWidget.h \
- VISU_ScalarBarCtrl.hxx
+ VISU_ImplicitFunctionWidget.hxx \
+ VISU_ScalarBarCtrl.hxx \
+ VISU_PlanesWidget.hxx \
+ VISU_SphereWidget.hxx \
+ VISU_WidgetCtrl.hxx
# Libraries targets
SALOME_ExtractGeometry.cxx \
VISU_OpenGLPointSpriteMapper.cxx \
VISU_ImplicitFunctionWidget.cxx \
+ VISU_PlanesWidget.cxx \
+ VISU_SphereWidget.cxx \
+ VISU_WidgetCtrl.cxx \
VISU_ScalarBarCtrl.cxx
# Executables targets
-// VISU OBJECT : interactive object for VISU entities implementation
-//
-// 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_PipeLine.hxx
-// Author: Alexey PETROV
-// Module : VISU
-
-#include "VISU_Convertor.hxx"
-#include "VISU_MeshPL.hxx"
-#include "VISU_ScalarMapPL.hxx"
-#include "VISU_IsoSurfacesPL.hxx"
-#include "VISU_CutPlanesPL.hxx"
-#include "VISU_CutLinesPL.hxx"
-#include "VISU_DeformedShapePL.hxx"
-#include "VISU_VectorsPL.hxx"
-#include "VISU_StreamLinesPL.hxx"
-#include "VISU_GaussPointsPL.hxx"
-#include "VISU_Plot3DPL.hxx"
-
-typedef VISU_GaussPointsPL TPresent;
-
-#include <vtkUnstructuredGrid.h>
-#include <vtkDataSetMapper.h>
-
-#include <vtkRenderWindowInteractor.h>
-#include <vtkRenderWindow.h>
-#include <vtkRenderer.h>
-#include <vtkCamera.h>
-#include <vtkActor.h>
-
-#include <vtkProperty.h>
-
-#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<<aPresent->GetPointSize(i)<<endl;
- //}
- //aPresent->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"<<exc.what());
- }catch(...){
- MESSAGE("Unknown exception was occured in VISU_Convertor_impl");
- }
- return 1;
+////////////////////////////////////////////////////////////////////
+#include<stdio.h>
+//
+//====================================================================
+// function: main
+// purpose:
+//====================================================================
+int main( int argc, char *argv[] )
+{
+ return 0;
}
// Module : SALOME
// $Header$
-#include "VISU_ImplicitFunctionWidget.h"
-
-#include <vtkActor.h>
-#include <vtkAssemblyNode.h>
-#include <vtkAssemblyPath.h>
-#include <vtkCallbackCommand.h>
-#include <vtkCamera.h>
-#include <vtkCellPicker.h>
-#include <vtkConeSource.h>
-#include <vtkCutter.h>
-#include <vtkFeatureEdges.h>
-#include <vtkImageData.h>
-#include <vtkLineSource.h>
-#include <vtkMath.h>
-#include <vtkObjectFactory.h>
-#include <vtkOutlineFilter.h>
-#include <vtkPlane.h>
-#include <vtkPolyData.h>
-#include <vtkPolyDataMapper.h>
-#include <vtkProperty.h>
-#include <vtkRenderWindowInteractor.h>
-#include <vtkRenderer.h>
-#include <vtkSphereSource.h>
-#include <vtkTransform.h>
-#include <vtkTubeFilter.h>
-#include <vtkImplicitBoolean.h>
-#include <vtkImplicitFunctionCollection.h>
-////
+#include "VISU_ImplicitFunctionWidget.hxx"
+//
#include <vtkFollower.h>
#include <vtkObjectFactory.h>
#include <vtkDataSet.h>
#include <vtkRenderWindow.h>
-////
-//==================================================================
-// 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 <vtkRenderer.h>
+#include <vtkDataSet.h>
+#include <vtkImplicitFunction.h>
+#include <vtkMapper.h>
+//
vtkStandardNewMacro(VISU_UnScaledActor);
//====================================================================
{
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: ~
//==================================================================
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<VISU_ImplicitFunctionWidget *>( 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])));
}
+++ /dev/null
-// 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_ImplicitFunctionWidget.h
-// Author : Peter KURNEV
-// Module : SALOME
-// $Header$
-
-#ifndef __VISU_ImplicitFunctionWidget_h
-#define __VISU_ImplicitFunctionWidget_h
-
-#include <vtkPolyDataSourceWidget.h>
-
-class vtkActor;
-class vtkPolyDataMapper;
-class vtkCellPicker;
-class vtkConeSource;
-class vtkLineSource;
-class vtkSphereSource;
-class vtkPlane;
-class vtkCutter;
-class vtkProperty;
-class vtkImageData;
-class vtkOutlineFilter;
-class vtkFeatureEdges;
-class vtkPolyData;
-class vtkTransform;
-class vtkImplicitBoolean;
-class vtkImplicitFunction;
-class VISU_UnScaledActor;
-class vtkDataSet;
-
-class VISU_ImplicitFunctionWidget : public vtkPolyDataSourceWidget
-{
-public:
- // Description:
- // Instantiate the object.
- static VISU_ImplicitFunctionWidget *New();
-
- vtkTypeRevisionMacro(VISU_ImplicitFunctionWidget,vtkPolyDataSourceWidget);
- void PrintSelf(ostream& os, vtkIndent indent);
-
- void SetDistance (const float theDistance);
- float Distance()const;
-
- vtkGetMacro(InitialLength,float);
- 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.
- void SetOrigin(float x, float y, float z);
- void SetOrigin(float x[3]);
- float* GetOrigin();
- void GetOrigin(float xyz[3]);
-
- // Description:
- // Get the normal to the plane.
- void SetNormal(float x, float y, float z);
- void SetNormal(float x[3]);
- float* GetNormal();
- void GetNormal(float xyz[3]);
-
- // Description:
- // Force the plane widget to be aligned with one of the x-y-z axes.
- // If one axis is set on, the other two will be set off.
- // Remember that when the state changes, a ModifiedEvent is invoked.
- // This can be used to snap the plane to the axes if it is orginally
- // not aligned.
- void SetNormalToXAxis(int);
- vtkGetMacro(NormalToXAxis,int);
- vtkBooleanMacro(NormalToXAxis,int);
- void SetNormalToYAxis(int);
- vtkGetMacro(NormalToYAxis,int);
- vtkBooleanMacro(NormalToYAxis,int);
- void SetNormalToZAxis(int);
- vtkGetMacro(NormalToZAxis,int);
- vtkBooleanMacro(NormalToZAxis,int);
-
- // Description:
- // Turn on/off tubing of the wire outline of the plane. The tube thickens
- // the line by wrapping with a vtkTubeFilter.
- //vtkSetMacro(Tubing,int);
- //vtkGetMacro(Tubing,int);
- //vtkBooleanMacro(Tubing,int);
-
- // Description:
- // Enable/disable the drawing of the plane. In some cases the plane
- // interferes with the object that it is operating on (i.e., the
- // plane interferes with the cut surface it produces producing
- // z-buffer artifacts.)
- void SetDrawPlane(int plane);
- int GetDrawPlane(){
- return myDrawPlane;
- }
-
- // Description:
- // Turn on/off the ability to translate the bounding box by grabbing it
- // with the left mouse button.
- vtkSetMacro(OutlineTranslation,int);
- vtkGetMacro(OutlineTranslation,int);
- vtkBooleanMacro(OutlineTranslation,int);
-
- // Description:
- // Grab the polydata that defines the plane. The polydata contains a single
- // polygon that is clipped by the bounding box.
- void GetPolyData(vtkPolyData *pd);
-
- // Description:
- // Satisfies superclass API. This returns a pointer to the underlying
- // PolyData (which represents the plane).
- vtkPolyDataSource* GetPolyDataSource();
-
- // Description:
- // Get the implicit function for the plane. The user must provide the
- // instance of the class vtkPlane. Note that vtkPlane is a subclass of
- // vtkImplicitFunction, meaning that it can be used by a variety of filters
- // to perform clipping, cutting, and selection of data.
- void GetPlane(vtkPlane *plane);
-
- // Description:
- // Satisfies the superclass API. This will change the state of the widget
- // to match changes that have been made to the underlying PolyDataSource
- void UpdatePlacement(void);
-
- // Description:
- // Get the properties on the normal (line and cone).
- vtkGetObjectMacro(NormalProperty,vtkProperty);
- vtkGetObjectMacro(SelectedNormalProperty,vtkProperty);
-
- // Description:
- // Get the plane properties. The properties of the plane when selected
- // and unselected can be manipulated.
- vtkGetObjectMacro(PlaneProperty,vtkProperty);
- vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty);
-
- // Description:
- // Get the property of the outline.
- vtkGetObjectMacro(OutlineProperty,vtkProperty);
- vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty);
-
- // Description:
- // Get the property of the intersection edges. (This property also
- // applies to the edges when tubed.)
- vtkGetObjectMacro(EdgesProperty,vtkProperty);
-
- void InitialPlaceWidget(float bds[6]);
-
-protected:
- VISU_ImplicitFunctionWidget();
- ~VISU_ImplicitFunctionWidget();
-
-//BTX - manage the state of the widget
- int State;
- enum WidgetState
- {
- Start=0,
- MovingPlane,
- MovingOutline,
- MovingOrigin,
- Scaling,
- Pushing,
- Rotating,
- Outside,
- ChangeDistance
- };
-//ETX
-
- //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 OnMiddleButtonDown();
- void OnMiddleButtonUp();
- void OnRightButtonDown();
- void OnRightButtonUp();
- void OnMouseMove();
- //
- // Methods to manipulate the plane
- void ConstrainOrigin(float x[3]);
- void Rotate(int X, int Y, double *p1, double *p2, double *vpn);
- void TranslatePlane(double *p1, double *p2);
- void TranslateOutline(double *p1, double *p2);
- void TranslateOrigin(double *p1, double *p2);
- void Push(double *p1, double *p2);
- void Scale(double *p1, double *p2, int X, int Y);
- void PushDistance(double *p1, double *p2);
-
- void CreateDefaultProperties();
-
- void GeneratePlane();
- virtual void SizeHandles();
- void HighlightPlane(int highlight);
- void HighlightNormal(int highlight);
- void HighlightOutline(int highlight);
- void UpdateRepresentation();
- void SetOriginInternal(float x[3]);
-
- // Controlling ivars
- int NormalToXAxis;
- int NormalToYAxis;
- int NormalToZAxis;
-
-
- // Flags to handle mouse events
- bool HandleMoveEvent;
- bool HandleLeftButtonEvent;
- bool HandleMiddleButtonEvent;
- bool HandleRightButtonEvent;
- // The actual plane which is being manipulated
- vtkPlane *myPlane1;
- vtkPlane *myPlane2;
-
- float myDistance;
- vtkImplicitBoolean *myImplicitFunction;
-
- // The bounding box is represented by a single voxel image data
- vtkImageData *myBox;
- vtkOutlineFilter *myOutline;
- vtkPolyDataMapper *myOutlineMapper;
- vtkActor *myOutlineActor;
-
- int OutlineTranslation; //whether the outline can be moved
-
- // The cut plane is produced with a vtkCutter
- vtkCutter *myCutter1;
- vtkPolyDataMapper *myCutMapper1;
- vtkActor *myCutActor1;
-
- vtkCutter *myCutter2;
- vtkPolyDataMapper *myCutMapper2;
- vtkActor *myCutActor2;
-
- vtkFeatureEdges *myEdges2;
- vtkPolyDataMapper *myEdgesMapper2;
- vtkActor *myEdgesActor2;
-
- int myDrawPlane;
-
- vtkFeatureEdges *myEdges1;
- vtkPolyDataMapper *myEdgesMapper1;
- vtkActor *myEdgesActor1;
-
- // The + normal cone
- vtkConeSource *ConeSource;
- vtkPolyDataMapper *ConeMapper;
- VISU_UnScaledActor *ConeActor;
- // The + normal line
- vtkLineSource *LineSource;
- vtkPolyDataMapper *LineMapper;
- vtkActor *LineActor;
- // The - normal cone
- vtkConeSource *ConeSource2;
- vtkPolyDataMapper *ConeMapper2;
- VISU_UnScaledActor *ConeActor2;
- // The - normal line
- vtkLineSource *LineSource2;
- vtkPolyDataMapper *LineMapper2;
- vtkActor *LineActor2;
- // The origin positioning handle
- vtkSphereSource *Sphere;
- vtkPolyDataMapper *SphereMapper;
- VISU_UnScaledActor *SphereActor;
-
- // Do the picking
- vtkCellPicker *Picker;
-
- // Transform the normal (used for rotation)
- vtkTransform *Transform;
- // Properties used to control the appearance of selected objects and
- // the manipulator in general.
- vtkProperty *NormalProperty;
- vtkProperty *SelectedNormalProperty;
- vtkProperty *PlaneProperty;
- vtkProperty *SelectedPlaneProperty;
- vtkProperty *OutlineProperty;
- vtkProperty *SelectedOutlineProperty;
- vtkProperty *EdgesProperty;
-
-private:
- VISU_ImplicitFunctionWidget(const VISU_ImplicitFunctionWidget&); //Not implemented
- void operator=(const VISU_ImplicitFunctionWidget&); //Not implemented
-};
-
-#endif
--- /dev/null
+// 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 <vtkFollower.h>
+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 <vtk3DWidget.h>
+
+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
--- /dev/null
+// 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 <vtkActor.h>
+#include <vtkAssemblyNode.h>
+#include <vtkAssemblyPath.h>
+#include <vtkCallbackCommand.h>
+#include <vtkCamera.h>
+#include <vtkCellPicker.h>
+#include <vtkConeSource.h>
+#include <vtkCutter.h>
+#include <vtkFeatureEdges.h>
+#include <vtkImageData.h>
+#include <vtkLineSource.h>
+#include <vtkMath.h>
+#include <vtkObjectFactory.h>
+#include <vtkOutlineFilter.h>
+#include <vtkPlane.h>
+#include <vtkPolyData.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkProperty.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkRenderer.h>
+#include <vtkSphereSource.h>
+#include <vtkTransform.h>
+#include <vtkTubeFilter.h>
+#include <vtkImplicitBoolean.h>
+#include <vtkImplicitFunctionCollection.h>
+////
+#include <vtkFollower.h>
+#include <vtkObjectFactory.h>
+#include <vtkDataSet.h>
+#include <vtkRenderWindow.h>
+
+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<VISU_PlanesWidget *>( 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);
+}
+*/
--- /dev/null
+// 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_PlanesWidget_h
+#define __VISU_PlanesWidget_h
+
+#include "VISU_ImplicitFunctionWidget.hxx"
+class vtkActor;
+class vtkPolyDataMapper;
+class vtkCellPicker;
+class vtkConeSource;
+class vtkLineSource;
+class vtkSphereSource;
+class vtkPlane;
+class vtkCutter;
+class vtkProperty;
+class vtkImageData;
+class vtkOutlineFilter;
+class vtkFeatureEdges;
+class vtkPolyData;
+class vtkTransform;
+class vtkImplicitBoolean;
+class vtkImplicitFunction;
+class VISU_UnScaledActor;
+class vtkDataSet;
+
+class VISU_PlanesWidget : public VISU_ImplicitFunctionWidget
+{
+public:
+ // Description:
+ // Instantiate the object.
+ static VISU_PlanesWidget *New();
+
+ vtkTypeRevisionMacro(VISU_PlanesWidget,VISU_ImplicitFunctionWidget);
+ void PrintSelf(ostream& os, vtkIndent indent);
+
+ void SetDistance (const float theDistance);
+ float Distance()const;
+
+ vtkGetMacro(InitialLength,float);
+
+ virtual vtkImplicitFunction* ImplicitFunction();
+
+ // Description:
+ // Methods that satisfy the superclass' API.
+ virtual void SetEnabled(int);
+ virtual void PlaceWidget(float bounds[6]);
+
+ // Description:
+ // Get the origin of the plane.
+ void SetOrigin(float x, float y, float z);
+ void SetOrigin(float x[3]);
+ float* GetOrigin();
+ void GetOrigin(float xyz[3]);
+
+ // Description:
+ // Get the normal to the plane.
+ void SetNormal(float x, float y, float z);
+ void SetNormal(float x[3]);
+ float* GetNormal();
+ void GetNormal(float xyz[3]);
+
+ // Description:
+ // Force the plane widget to be aligned with one of the x-y-z axes.
+ // If one axis is set on, the other two will be set off.
+ // Remember that when the state changes, a ModifiedEvent is invoked.
+ // This can be used to snap the plane to the axes if it is orginally
+ // not aligned.
+ void SetNormalToXAxis(int);
+ vtkGetMacro(NormalToXAxis,int);
+ vtkBooleanMacro(NormalToXAxis,int);
+ void SetNormalToYAxis(int);
+ vtkGetMacro(NormalToYAxis,int);
+ vtkBooleanMacro(NormalToYAxis,int);
+ void SetNormalToZAxis(int);
+ vtkGetMacro(NormalToZAxis,int);
+ vtkBooleanMacro(NormalToZAxis,int);
+
+ // Description:
+ // Turn on/off tubing of the wire outline of the plane. The tube thickens
+ // the line by wrapping with a vtkTubeFilter.
+ //vtkSetMacro(Tubing,int);
+ //vtkGetMacro(Tubing,int);
+ //vtkBooleanMacro(Tubing,int);
+
+ // Description:
+ // Enable/disable the drawing of the plane. In some cases the plane
+ // interferes with the object that it is operating on (i.e., the
+ // plane interferes with the cut surface it produces producing
+ // z-buffer artifacts.)
+ void SetDrawPlane(int plane);
+ int GetDrawPlane(){
+ return myDrawPlane;
+ }
+
+ // Description:
+ // Turn on/off the ability to translate the bounding box by grabbing it
+ // with the left mouse button.
+ vtkSetMacro(OutlineTranslation,int);
+ vtkGetMacro(OutlineTranslation,int);
+ vtkBooleanMacro(OutlineTranslation,int);
+
+ // Description:
+ // Grab the polydata that defines the plane. The polydata contains a single
+ // polygon that is clipped by the bounding box.
+ void GetPolyData(vtkPolyData *pd);
+
+ // Description:
+ // Satisfies superclass API. This returns a pointer to the underlying
+ // PolyData (which represents the plane).
+ //vtkPolyDataSource* GetPolyDataSource();
+
+ // Description:
+ // Get the implicit function for the plane. The user must provide the
+ // instance of the class vtkPlane. Note that vtkPlane is a subclass of
+ // vtkImplicitFunction, meaning that it can be used by a variety of filters
+ // to perform clipping, cutting, and selection of data.
+ void GetPlane(vtkPlane *plane);
+
+ // Description:
+ // Satisfies the superclass API. This will change the state of the widget
+ // to match changes that have been made to the underlying PolyDataSource
+ void UpdatePlacement(void);
+
+ // Description:
+ // Get the properties on the normal (line and cone).
+ vtkGetObjectMacro(NormalProperty,vtkProperty);
+ vtkGetObjectMacro(SelectedNormalProperty,vtkProperty);
+
+ // Description:
+ // Get the plane properties. The properties of the plane when selected
+ // and unselected can be manipulated.
+ vtkGetObjectMacro(PlaneProperty,vtkProperty);
+ vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty);
+
+ // Description:
+ // Get the property of the outline.
+ vtkGetObjectMacro(OutlineProperty,vtkProperty);
+ vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty);
+
+ // Description:
+ // Get the property of the intersection edges. (This property also
+ // applies to the edges when tubed.)
+ vtkGetObjectMacro(EdgesProperty,vtkProperty);
+
+ void InitialPlaceWidget(float bds[6]);
+
+protected:
+ VISU_PlanesWidget();
+ ~VISU_PlanesWidget();
+
+//BTX - manage the state of the widget
+ int State;
+ enum WidgetState
+ {
+ Start=0,
+ MovingPlane,
+ MovingOutline,
+ MovingOrigin,
+ Scaling,
+ Pushing,
+ Rotating,
+ Outside,
+ ChangeDistance
+ };
+//ETX
+
+ //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 OnMiddleButtonDown();
+ void OnMiddleButtonUp();
+ void OnRightButtonDown();
+ void OnRightButtonUp();
+ void OnMouseMove();
+ //
+ // Methods to manipulate the plane
+ void ConstrainOrigin(float x[3]);
+ void Rotate(int X, int Y, double *p1, double *p2, double *vpn);
+ void TranslatePlane(double *p1, double *p2);
+ void TranslateOutline(double *p1, double *p2);
+ void TranslateOrigin(double *p1, double *p2);
+ void Push(double *p1, double *p2);
+ void Scale(double *p1, double *p2, int X, int Y);
+ void PushDistance(double *p1, double *p2);
+
+ void CreateDefaultProperties();
+
+ void GeneratePlane();
+ //virtual void SizeHandles();
+ void HighlightPlane(int highlight);
+ void HighlightNormal(int highlight);
+ void HighlightOutline(int highlight);
+ void UpdateRepresentation();
+ void SetOriginInternal(float x[3]);
+
+ // Controlling ivars
+ int NormalToXAxis;
+ int NormalToYAxis;
+ int NormalToZAxis;
+
+
+ // Flags to handle mouse events
+ bool HandleMoveEvent;
+ bool HandleLeftButtonEvent;
+ bool HandleMiddleButtonEvent;
+ bool HandleRightButtonEvent;
+ // The actual plane which is being manipulated
+ vtkPlane *myPlane1;
+ vtkPlane *myPlane2;
+
+ float myDistance;
+ vtkImplicitBoolean *myImplicitFunction;
+
+ // The bounding box is represented by a single voxel image data
+ vtkImageData *myBox;
+ vtkOutlineFilter *myOutline;
+ vtkPolyDataMapper *myOutlineMapper;
+ vtkActor *myOutlineActor;
+
+ int OutlineTranslation; //whether the outline can be moved
+
+ // The cut plane is produced with a vtkCutter
+ vtkCutter *myCutter1;
+ vtkPolyDataMapper *myCutMapper1;
+ vtkActor *myCutActor1;
+
+ vtkCutter *myCutter2;
+ vtkPolyDataMapper *myCutMapper2;
+ vtkActor *myCutActor2;
+
+ vtkFeatureEdges *myEdges2;
+ vtkPolyDataMapper *myEdgesMapper2;
+ vtkActor *myEdgesActor2;
+
+ int myDrawPlane;
+
+ vtkFeatureEdges *myEdges1;
+ vtkPolyDataMapper *myEdgesMapper1;
+ vtkActor *myEdgesActor1;
+
+ // The + normal cone
+ vtkConeSource *ConeSource;
+ vtkPolyDataMapper *ConeMapper;
+ VISU_UnScaledActor *ConeActor;
+ // The + normal line
+ vtkLineSource *LineSource;
+ vtkPolyDataMapper *LineMapper;
+ vtkActor *LineActor;
+ // The - normal cone
+ vtkConeSource *ConeSource2;
+ vtkPolyDataMapper *ConeMapper2;
+ VISU_UnScaledActor *ConeActor2;
+ // The - normal line
+ vtkLineSource *LineSource2;
+ vtkPolyDataMapper *LineMapper2;
+ vtkActor *LineActor2;
+ // The origin positioning handle
+ vtkSphereSource *Sphere;
+ vtkPolyDataMapper *SphereMapper;
+ VISU_UnScaledActor *SphereActor;
+
+ // Do the picking
+ vtkCellPicker *Picker;
+
+ // Transform the normal (used for rotation)
+ vtkTransform *Transform;
+ // Properties used to control the appearance of selected objects and
+ // the manipulator in general.
+ vtkProperty *NormalProperty;
+ vtkProperty *SelectedNormalProperty;
+ vtkProperty *PlaneProperty;
+ vtkProperty *SelectedPlaneProperty;
+ vtkProperty *OutlineProperty;
+ vtkProperty *SelectedOutlineProperty;
+ vtkProperty *EdgesProperty;
+
+private:
+ VISU_PlanesWidget(const VISU_PlanesWidget&); //Not implemented
+ void operator=(const VISU_ImplicitFunctionWidget&); //Not implemented
+};
+
+#endif
--- /dev/null
+#include "VISU_SphereWidget.hxx"
+
+#include <vtkActor.h>
+#include <vtkAssemblyNode.h>
+#include <vtkAssemblyPath.h>
+#include <vtkCallbackCommand.h>
+#include <vtkCamera.h>
+#include <vtkCellPicker.h>
+#include <vtkDoubleArray.h>
+#include <vtkMath.h>
+#include <vtkObjectFactory.h>
+#include <vtkPolyData.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkProperty.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkRenderer.h>
+#include <vtkSphere.h>
+#include <vtkSphereSource.h>
+#include <vtkPoints.h>
+#include <vtkSphere.h>
+#include <vtkImplicitFunction.h>
+
+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<VISU_SphereWidget *>( 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 (aR1<myRmin){
+ aR1=myRmin;
+ }
+ mySphereSource->SetRadius(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);
+}
--- /dev/null
+#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
--- /dev/null
+// 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 <vtkObject.h>
+#include <vtkImplicitFunction.h>
+#include <vtkImplicitSum.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkObjectFactory.h>
+#include <vtkCallbackCommand.h>
+#include <vtkCommand.h>
+//
+#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; i<myNbWidgets; ++i){
+ myWidgets[i]->AddObserver(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; i<myNbWidgets; ++i){
+ myWidgets[i]->RemoveObserver(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; i<myNbWidgets; ++i) {
+ iFlag=(i==myActiveIndex) ? 1 : 0;
+ myWidgets[i]->SetEnabled(iFlag);
+ }
+ }
+ }
+ else {//disabling
+ myDisableAll=1;
+ for (i=0; i<myNbWidgets; ++i) {
+ myWidgets[i]->SetEnabled(0);
+ }
+ }
+}
+//==================================================================
+// function: ProcessEvents
+// purpose :
+//==================================================================
+void VISU_WidgetCtrl::ProcessEvents(vtkObject* vtkNotUsed(theObject),
+ unsigned long theEvent,
+ void* theClientData,
+ void* vtkNotUsed(theCallData))
+{
+ VISU_WidgetCtrl *pSelf=
+ reinterpret_cast<VISU_WidgetCtrl*>(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<myNbWidgets){
+ myActiveIndex=theIndex;
+ }
+}
+//==================================================================
+// function: GetActiveIndex
+// purpose :
+//==================================================================
+int VISU_WidgetCtrl::GetActiveIndex()const
+{
+ return myActiveIndex;
+}
+//==================================================================
+// function: HasActiveIndex
+// purpose :
+//==================================================================
+bool VISU_WidgetCtrl::HasActiveIndex()const
+{
+ return (myActiveIndex>=0 && myActiveIndex<myNbWidgets);
+}
+//==================================================================
+// function: IsPlanesActive
+// purpose :
+//==================================================================
+bool VISU_WidgetCtrl::IsPlanesActive()const
+{
+ return (myActiveIndex==0);
+}
+//==================================================================
+// function: IsSphereActive
+// purpose :
+//==================================================================
+bool VISU_WidgetCtrl::IsSphereActive()const
+{
+ return (myActiveIndex==1);
+}
+//==================================================================
+// function: GetActiveWidget
+// purpose :
+//==================================================================
+VISU_ImplicitFunctionWidget* VISU_WidgetCtrl::GetActiveWidget()
+{
+ if (HasActiveIndex()){
+ return myWidgets[myActiveIndex];
+ }
+ return myDummyWidget;
+}
+//==================================================================
+// function: GetWidget
+// purpose :
+//==================================================================
+VISU_ImplicitFunctionWidget* VISU_WidgetCtrl::GetWidget(const int theIndex)
+{
+ if (theIndex>=0 && theIndex<myNbWidgets) {
+ return myWidgets[theIndex];
+ }
+ return myDummyWidget;
+}
+//==================================================================
+// function: GetPlanesWidget
+// purpose :
+//==================================================================
+VISU_PlanesWidget* VISU_WidgetCtrl::GetPlanesWidget()
+{
+ return myPlanesWidget;
+}
+//==================================================================
+// function: GetSphereWidget
+// purpose :
+//==================================================================
+VISU_SphereWidget* VISU_WidgetCtrl::GetSphereWidget()
+{
+ return mySphereWidget;
+}
+//==================================================================
+// function: PlaceWidget
+// purpose :
+//==================================================================
+void VISU_WidgetCtrl::PlaceWidget(float theBounds[6])
+{
+ for (int i=0; i<myNbWidgets; ++i) {
+ myWidgets[i]->PlaceWidget(theBounds);
+ }
+}
+//==================================================================
+// function: SetInteractor
+// purpose :
+//==================================================================
+void VISU_WidgetCtrl::SetInteractor(vtkRenderWindowInteractor* theRWI)
+{
+ for (int i=0; i<myNbWidgets; ++i) {
+ myWidgets[i]->SetInteractor(theRWI);
+ }
+}
+//==================================================================
+// function: GetInteractor
+// purpose :
+//==================================================================
+vtkRenderWindowInteractor* VISU_WidgetCtrl::GetInteractor()
+{
+ myWidgets[0]->GetInteractor();
+}
+//==================================================================
+// function: SetPlaceFactor
+// purpose :
+//==================================================================
+void VISU_WidgetCtrl::SetPlaceFactor(float theFactor)
+{
+ for (int i=0; i<myNbWidgets; ++i) {
+ myWidgets[i]->SetPlaceFactor(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; i<myNbWidgets; ++i) {
+ pIF=myWidgets[i]->ImplicitFunction();
+ aWeight=(i==myActiveIndex)? 1. : 0.;
+ if (i==myActiveIndex && i==1){
+ aWeight=-1.;
+ }
+ myImplicitSum->SetFunctionWeight(pIF, aWeight);
+ }
+ return myImplicitSum;
+}
--- /dev/null
+// 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 <vtkObject.h>
+
+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
#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"
{
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);
}
//---------------------------------------------------------------
{
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);
}
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
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 \
VVTK_SegmentationCursorDlg.h \
VVTK_PrimitiveBox.h \
VVTK_SizeBox.h \
- VVTK_MainWindow.h
+ VVTK_MainWindow.h
CPPFLAGS += \
$(QT_INCLUDES) \
LIBS+= -lsuit -lCAM -lSalomeObject -lSVTK -lOpUtil
+
@CONCLUDE@
--- /dev/null
+// SALOME VTKViewer : build VTK viewer into Salome desktop\r
+//\r
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS \r
+// \r
+// This library is free software; you can redistribute it and/or \r
+// modify it under the terms of the GNU Lesser General Public \r
+// License as published by the Free Software Foundation; either \r
+// version 2.1 of the License. \r
+// \r
+// This library is distributed in the hope that it will be useful, \r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of \r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU \r
+// Lesser General Public License for more details. \r
+// \r
+// You should have received a copy of the GNU Lesser General Public \r
+// License along with this library; if not, write to the Free Software \r
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA \r
+// \r
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org \r
+//\r
+//\r
+//\r
+// File :\r
+// Author :\r
+// Module :\r
+// $Header$\r
+#include "VVTK_ImageWriter.h"\r
+#include <vtkImageData.h>\r
+#include <vtkJPEGWriter.h>\r
+#include <vtkImageClip.h>\r
+//\r
+//===============================================\r
+// function: VVTK_ImageWriter\r
+// purpose :\r
+//===============================================\r
+VVTK_ImageWriter::VVTK_ImageWriter()\r
+: QThread()\r
+{\r
+ myName=NULL;\r
+ myProgressive=0;\r
+ myQuality=0;\r
+ myImageData=0;\r
+ myConstraint16Flag=true;\r
+ myErrorStatus=0;\r
+}\r
+//===============================================\r
+// function: ~\r
+// purpose :\r
+//===============================================\r
+VVTK_ImageWriter::~VVTK_ImageWriter()\r
+{\r
+}\r
+//===============================================\r
+// function: SetName\r
+// purpose :\r
+//===============================================\r
+void VVTK_ImageWriter::SetName(const char *aName)\r
+{\r
+ myName=(char *)aName;\r
+}\r
+//===============================================\r
+// function: Name\r
+// purpose :\r
+//===============================================\r
+const char* VVTK_ImageWriter::Name()const\r
+{\r
+ return myName;\r
+}\r
+//===============================================\r
+// function: SetProgressive\r
+// purpose :\r
+//===============================================\r
+void VVTK_ImageWriter::SetProgressive(const int aProgressive)\r
+{\r
+ myProgressive=aProgressive;\r
+}\r
+//===============================================\r
+// function: Progressive\r
+// purpose :\r
+//===============================================\r
+int VVTK_ImageWriter::Progressive()const\r
+{\r
+ return myProgressive;\r
+}\r
+//===============================================\r
+// function: SetQuality\r
+// purpose :\r
+//===============================================\r
+void VVTK_ImageWriter::SetQuality(const int aQuality)\r
+{\r
+ myQuality=aQuality;\r
+}\r
+//===============================================\r
+// function: Quality\r
+// purpose :\r
+//===============================================\r
+int VVTK_ImageWriter::Quality()const\r
+{\r
+ return myQuality;\r
+}\r
+//===============================================\r
+// function: SetImageData\r
+// purpose :\r
+//===============================================\r
+void VVTK_ImageWriter::SetImageData(vtkImageData* pImageData)\r
+{\r
+ myImageData=pImageData;\r
+}\r
+//===============================================\r
+// function: ImageData\r
+// purpose :\r
+//===============================================\r
+vtkImageData* VVTK_ImageWriter::ImageData()\r
+{\r
+ return myImageData;\r
+}\r
+//===============================================\r
+// function: SetConstraint16Flag\r
+// purpose :\r
+//===============================================\r
+void VVTK_ImageWriter::SetConstraint16Flag(const bool aFlag)\r
+{\r
+ myConstraint16Flag=aFlag;\r
+}\r
+//===============================================\r
+// function: Constraint16Flag\r
+// purpose :\r
+//===============================================\r
+bool VVTK_ImageWriter::Constraint16Flag()const\r
+{\r
+ return myConstraint16Flag;\r
+}\r
+//===============================================\r
+// function: ErrorStatus\r
+// purpose :\r
+//===============================================\r
+int VVTK_ImageWriter::ErrorStatus()const\r
+{\r
+ return myErrorStatus;\r
+}\r
+//===============================================\r
+// function: run\r
+// purpose :\r
+//===============================================\r
+void VVTK_ImageWriter::run()\r
+{\r
+ vtkJPEGWriter *pWriter=vtkJPEGWriter::New();\r
+ //\r
+ vtkImageData *pImageData=myImageData;\r
+ vtkImageClip *pImageClip=NULL;\r
+ //\r
+ if (myConstraint16Flag){ \r
+ int uExtent[6];\r
+ unsigned int width, height;\r
+ //\r
+ myImageData->GetUpdateExtent(uExtent);\r
+ width =uExtent[1]-uExtent[0]+1;\r
+ height=uExtent[3]-uExtent[2]+1;\r
+ width =(width/16)*16;\r
+ height=(height/16)*16;\r
+ uExtent[1]=uExtent[0]+width -1;\r
+ uExtent[3]=uExtent[2]+height-1;\r
+ //\r
+ pImageClip=vtkImageClip::New();\r
+ pImageClip->SetInput(myImageData);\r
+ pImageClip->SetOutputWholeExtent(uExtent);\r
+ pImageClip->ClipDataOn();\r
+ pImageData=pImageClip->GetOutput();\r
+ }\r
+ //\r
+ pWriter->WriteToMemoryOff();\r
+ pWriter->SetFileName(myName);\r
+ pWriter->SetQuality(myQuality);\r
+ pWriter->SetProgressive(myProgressive);\r
+ pWriter->SetInput(pImageData);\r
+ //\r
+ pWriter->Write();\r
+ //\r
+ if (myConstraint16Flag){\r
+ pImageClip->Delete();\r
+ }\r
+ pWriter->Delete();\r
+ delete myName;\r
+ myImageData->Delete();\r
+}\r
+\r
--- /dev/null
+// SALOME VTKViewer : build VTK viewer into Salome desktop\r
+//\r
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS \r
+// \r
+// This library is free software; you can redistribute it and/or \r
+// modify it under the terms of the GNU Lesser General Public \r
+// License as published by the Free Software Foundation; either \r
+// version 2.1 of the License. \r
+// \r
+// This library is distributed in the hope that it will be useful, \r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of \r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU \r
+// Lesser General Public License for more details. \r
+// \r
+// You should have received a copy of the GNU Lesser General Public \r
+// License along with this library; if not, write to the Free Software \r
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA \r
+// \r
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org \r
+//\r
+//\r
+//\r
+// File :\r
+// Author :\r
+// Module :\r
+// $Header$\r
+#ifndef _VVTK_ImageWriter_Header_File_\r
+#define _VVTK_ImageWriter_Header_File_\r
+\r
+#include <qthread.h>\r
+\r
+class vtkImageData;\r
+\r
+class VVTK_ImageWriter : public QThread {\r
+public:\r
+ VVTK_ImageWriter();\r
+ ~VVTK_ImageWriter();\r
+ \r
+ void SetName(const char *aName);\r
+ const char *Name()const;\r
+\r
+ void SetProgressive(const int aProgressive);\r
+ int Progressive()const;\r
+\r
+ void SetQuality(const int aQuality);\r
+ int Quality()const;\r
+\r
+ void SetImageData(vtkImageData*);\r
+ vtkImageData* ImageData();\r
+\r
+ void SetConstraint16Flag(const bool bFlag);\r
+ bool Constraint16Flag()const;\r
+ \r
+ int ErrorStatus()const;\r
+\r
+protected :\r
+ virtual void run();\r
+ void WriteSlice();\r
+ \r
+protected :\r
+ char *myName;\r
+ int myProgressive;\r
+ int myQuality;\r
+ int myErrorStatus;\r
+ bool myConstraint16Flag;\r
+ \r
+ vtkImageData *myImageData;\r
+ \r
+};\r
+#endif\r
--- /dev/null
+// SALOME VTKViewer : build VTK viewer into Salome desktop\r
+//\r
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS \r
+// \r
+// This library is free software; you can redistribute it and/or \r
+// modify it under the terms of the GNU Lesser General Public \r
+// License as published by the Free Software Foundation; either \r
+// version 2.1 of the License. \r
+// \r
+// This library is distributed in the hope that it will be useful, \r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of \r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU \r
+// Lesser General Public License for more details. \r
+// \r
+// You should have received a copy of the GNU Lesser General Public \r
+// License along with this library; if not, write to the Free Software \r
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA \r
+// \r
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org \r
+//\r
+//\r
+//\r
+// File :\r
+// Author :\r
+// Module :\r
+// $Header$\r
+#include "VVTK_ImageWriterMgr.h"\r
+\r
+#include <qstring.h>\r
+#include <qthread.h>\r
+#include <vtkImageData.h>\r
+#include "VVTK_ImageWriter.h"\r
+\r
+//===============================================\r
+// function: \r
+// purpose :\r
+//===============================================\r
+VVTK_ImageWriterMgr::VVTK_ImageWriterMgr()\r
+ : QThread()\r
+{\r
+ myStop=0;\r
+ myErrorStatus=0;\r
+}\r
+//===============================================\r
+// function: ~\r
+// purpose :\r
+//===============================================\r
+VVTK_ImageWriterMgr::~VVTK_ImageWriterMgr()\r
+{\r
+}\r
+//===============================================\r
+// function: Stop\r
+// purpose :\r
+//===============================================\r
+void VVTK_ImageWriterMgr::Stop()\r
+{\r
+ myStop=1;\r
+}\r
+//===============================================\r
+// function: StartImageWriter\r
+// purpose :\r
+//===============================================\r
+void VVTK_ImageWriterMgr::StartImageWriter(const char *aName,\r
+ const int aProgressive,\r
+ const int aQuality,\r
+ vtkImageData *pImageData)\r
+{\r
+ VVTK_ImageWriter *pIW=new VVTK_ImageWriter; \r
+ //\r
+ myMutex.lock();\r
+ myThreads.push_back(pIW);\r
+ myMutex.unlock();\r
+ //\r
+ pIW->SetName(aName);\r
+ pIW->SetQuality(aQuality);\r
+ pIW->SetProgressive(aProgressive);\r
+ pIW->SetImageData(pImageData);\r
+ pIW->start();\r
+}\r
+//===============================================\r
+// function: run\r
+// purpose :\r
+//===============================================\r
+void VVTK_ImageWriterMgr::run()\r
+{\r
+ while (1) {\r
+ if (myErrorStatus){\r
+ return;\r
+ }\r
+ if(myStop) {\r
+ CleanAll();\r
+ break;\r
+ }\r
+ //\r
+ msleep(1000);\r
+ CleanPartial(10);\r
+ }\r
+}\r
+//===============================================\r
+// function: CleanPartial\r
+// purpose :\r
+//===============================================\r
+void VVTK_ImageWriterMgr::CleanPartial(const int aNumber)\r
+{\r
+ void *p;\r
+ VVTK_ImageWriter* pIW;\r
+ //\r
+ std::list <void *> aList;\r
+ std::list <void *>::iterator aIter;\r
+ //\r
+ while (myMutex.locked());\r
+ //\r
+ myMutex.lock();\r
+ //\r
+ aIter=myThreads.begin();\r
+ for (; aIter != myThreads.end() ; aIter++ ){\r
+ void *p=*aIter;\r
+ pIW=reinterpret_cast <VVTK_ImageWriter*>(*aIter);\r
+ if (pIW->ErrorStatus()){\r
+ myErrorStatus=10;\r
+ return;\r
+ }\r
+ if (pIW->finished()){ \r
+ aList.push_back(pIW);\r
+ if(aList.size()>aNumber){\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ //\r
+ aIter=aList.begin();\r
+ for (; aIter != aList.end(); aIter++ ){\r
+ p=*aIter;\r
+ myThreads.remove(p);\r
+ pIW=reinterpret_cast <VVTK_ImageWriter*>(p);\r
+ vtkImageData* pImageData=pIW->ImageData();\r
+ delete pIW;\r
+ }\r
+ myMutex.unlock();\r
+}\r
+//===============================================\r
+// function: CleanAll\r
+// purpose :\r
+//===============================================\r
+void VVTK_ImageWriterMgr::CleanAll()\r
+{\r
+ void *p;\r
+ VVTK_ImageWriter* pIW;\r
+ //\r
+ std::list <void *>::iterator aIter;\r
+ //\r
+ // clean all\r
+ while (myMutex.locked());\r
+ myMutex.lock();\r
+ while (myThreads.size()) {\r
+ aIter=myThreads.begin();\r
+ for (; aIter != myThreads.end() ; aIter++ ){\r
+ void *p=*aIter;\r
+ pIW=reinterpret_cast <VVTK_ImageWriter*>(*aIter);\r
+ if (pIW->ErrorStatus()){\r
+ myErrorStatus=10;\r
+ myStop=0;\r
+ return;\r
+ }\r
+ if (pIW->finished()){ \r
+ delete pIW;\r
+ myThreads.remove(p);\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ myMutex.unlock();\r
+ myStop=0;\r
+}\r
--- /dev/null
+// SALOME VTKViewer : build VTK viewer into Salome desktop\r
+//\r
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS \r
+// \r
+// This library is free software; you can redistribute it and/or \r
+// modify it under the terms of the GNU Lesser General Public \r
+// License as published by the Free Software Foundation; either \r
+// version 2.1 of the License. \r
+// \r
+// This library is distributed in the hope that it will be useful, \r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of \r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU \r
+// Lesser General Public License for more details. \r
+// \r
+// You should have received a copy of the GNU Lesser General Public \r
+// License along with this library; if not, write to the Free Software \r
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA \r
+// \r
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org \r
+//\r
+//\r
+//\r
+// File :\r
+// Author :\r
+// Module :\r
+// $Header$\r
+#ifndef _VVTK_ImageWriterMgr_Header_File_\r
+#define _VVTK_ImageWriterMgr_Header_File_\r
+\r
+#include <qthread.h>\r
+#include <list>\r
+//\r
+class QString;\r
+class vtkImageData;\r
+class QMutex;\r
+//\r
+class VVTK_ImageWriterMgr : public QThread {\r
+public:\r
+ VVTK_ImageWriterMgr();\r
+ ~VVTK_ImageWriterMgr();\r
+ \r
+ void Stop();\r
+ void StartImageWriter(const char *aName,\r
+ const int aProgressive,\r
+ const int aQuality,\r
+ vtkImageData *pImageData);\r
+ int ErrorStatus()const;\r
+\r
+protected :\r
+ virtual void run();\r
+ void CleanAll();\r
+ void CleanPartial(const int aNumber);\r
+\r
+protected :\r
+ int myStop;\r
+ int myErrorStatus;\r
+ std::list <void *> myThreads;\r
+ QMutex myMutex;\r
+};\r
+#endif\r
+\r
#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"
myStopAction->setEnabled( false );
myStopAction->addTo( myRecordingToolBar );
connect( myStopAction, SIGNAL( activated() ), this, SLOT( OnStopRecording() ) );
+
+ myRecorder=VVTK_Recorder::New();
}
void
PushInteractorStyle(myInteractorStyle.GetPointer());
}
-VVTK_MainWindow
-::~VVTK_MainWindow()
-{}
+VVTK_MainWindow::~VVTK_MainWindow()
+{
+ if (myRecorder){
+ myRecorder->Delete();
+ }
+}
//----------------------------------------------------------------------------
}
//----------------------------------------------------------------------------
-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();
}
//----------------------------------------------------------------------------
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"),
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
myRenderer = theRenderer;
VVTK_MainWindow::Initialize(theInteractor);
- mySegmentationCursorDlg->SetWidget( theRenderer->GetImplicitFunctionWidget() );
+ mySegmentationCursorDlg->SetWidgetCtrl( theRenderer->GetWidgetCtrl() );
myPickingDlg->SetInteractor( GetInteractor() );
}
//----------------------------------------------------------------------------
-VISU_ImplicitFunctionWidget*
-VVTK_MainWindow1
-::GetImplicitFunctionWidget()
+VISU_WidgetCtrl* VVTK_MainWindow1::GetWidgetCtrl()
{
- return myRenderer->GetImplicitFunctionWidget();
+ return myRenderer->GetWidgetCtrl();
}
VISU_InsideCursorSettings*
}
//----------------------------------------------------------------------------
-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 );
class QSplitter;
-class VISU_ImplicitFunctionWidget;
+class VISU_WidgetCtrl;
class VVTK_SegmentationCursorDlg;
class VISU_InsideCursorSettings;
class VISU_OutsideCursorSettings;
class VVTK_MainWindow2;
class VVTK_Renderer1;
class VVTK_Renderer2;
+class VVTK_Recorder;
//----------------------------------------------------------------------------
class VVTK_EXPORT VVTK_MainWindow: public SVTK_MainWindow
void
OnInteractorStyleSwitch(bool theIsGaussStyleOn);
- virtual
- void
- OnSelectionModeSwitch(bool theIsSelectionOn);
+ virtual void OnSelectionModeSwitch(bool theIsSelectionOn);
virtual
void
QtxAction* myPlayAction;
QtxAction* myPauseAction;
QtxAction* myStopAction;
+
+ VVTK_Recorder *myRecorder;
};
SUIT_ResourceMgr* theResourceMgr,
VISU_PickingSettings* thePickingSettings);
- VISU_ImplicitFunctionWidget*
- GetImplicitFunctionWidget();
+ VISU_WidgetCtrl* GetWidgetCtrl();
VISU_InsideCursorSettings*
GetInsideCursorSettings();
public slots:
void
- OnSegmentationSwitch(bool theIsSegmentationOn);
+ OnSegmentationSwitch();//bool theIsSegmentationOn);
virtual
void
--- /dev/null
+// SALOME VTKViewer : build VTK viewer into Salome desktop\r
+//\r
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS \r
+// \r
+// This library is free software; you can redistribute it and/or \r
+// modify it under the terms of the GNU Lesser General Public \r
+// License as published by the Free Software Foundation; either \r
+// version 2.1 of the License. \r
+// \r
+// This library is distributed in the hope that it will be useful, \r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of \r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU \r
+// Lesser General Public License for more details. \r
+// \r
+// You should have received a copy of the GNU Lesser General Public \r
+// License along with this library; if not, write to the Free Software \r
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA \r
+// \r
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org \r
+//\r
+//\r
+//\r
+// File :\r
+// Author :\r
+// Module :\r
+// $Header$\r
+\r
+#include "VVTK_Recorder.hxx"\r
+\r
+#include <unistd.h>\r
+\r
+#include <vtkObjectFactory.h>\r
+#include <vtkObject.h>\r
+#include <vtkCallbackCommand.h>\r
+#include <vtkRenderWindow.h>\r
+#include <vtkTimerLog.h>\r
+#include <vtkWindowToImageFilter.h>\r
+#include <vtkJPEGWriter.h>\r
+#include <vtkImageData.h>\r
+\r
+#include "VVTK_ImageWriter.h"\r
+#include "VVTK_ImageWriterMgr.h"\r
+//\r
+static \r
+ void GetNameJPEG(const char *pName, \r
+ const int aIndex,\r
+ char *pNameJPEG);\r
+//\r
+vtkCxxRevisionMacro(VVTK_Recorder,"$Revision$");\r
+vtkStandardNewMacro(VVTK_Recorder);\r
+//===============================================\r
+// function: VVTK_Recorder\r
+// purpose :\r
+//=============================================== \r
+VVTK_Recorder::VVTK_Recorder()\r
+ : vtkObject()\r
+{\r
+ myRenderWindow=NULL;\r
+ myFilter=NULL;\r
+ myState=VVTK_Recorder_Stop;\r
+ myNbFPS=10.;\r
+ myErrorStatus=0;\r
+ myCommand=vtkCallbackCommand::New();\r
+ myCommand->SetClientData(this); \r
+ myCommand->SetCallback(VVTK_Recorder::ProcessEvents);\r
+ //\r
+ myPriority=0.;\r
+ myTimeStart=0.;\r
+ myFrameIndex=0;\r
+ myPaused=0;\r
+ //\r
+ myFilter=vtkWindowToImageFilter::New();\r
+ myWriterMgr=new VVTK_ImageWriterMgr;\r
+ myName=new char [512];\r
+ myName[0]=0;\r
+ myNbWrittenFrames=0;\r
+}\r
+//===============================================\r
+// function: ~\r
+// purpose :\r
+//=============================================== \r
+VVTK_Recorder::~VVTK_Recorder()\r
+{\r
+ myCommand->Delete();\r
+ myFilter->Delete();\r
+ delete myWriterMgr;\r
+ delete myName;\r
+}\r
+//===============================================\r
+// function: DoPlay\r
+// purpose :\r
+//===============================================\r
+void VVTK_Recorder::DoPlay()\r
+{\r
+}\r
+//===============================================\r
+// function: DoStop\r
+// purpose :\r
+//===============================================\r
+void VVTK_Recorder::DoStop()\r
+{\r
+}\r
+//===============================================\r
+// function: SetName\r
+// purpose :\r
+//===============================================\r
+void VVTK_Recorder::SetName(const char* theName)\r
+{\r
+ strcpy(myName, theName);\r
+}\r
+//===============================================\r
+// function: Name\r
+// purpose :\r
+//===============================================\r
+const char* VVTK_Recorder::Name()const\r
+{\r
+ return myName;\r
+}\r
+//===============================================\r
+// function: SetNbFPS\r
+// purpose :\r
+//=============================================== \r
+void VVTK_Recorder::SetNbFPS(const double theNb)\r
+{\r
+ myNbFPS=theNb;\r
+}\r
+//===============================================\r
+// function: NbFPS\r
+// purpose :\r
+//=============================================== \r
+double VVTK_Recorder::NbFPS()const\r
+{\r
+ return myNbFPS;\r
+}\r
+//===============================================\r
+// function: SetRenderWindow\r
+// purpose :\r
+//=============================================== \r
+void VVTK_Recorder::SetRenderWindow(vtkRenderWindow* pW)\r
+{\r
+ myRenderWindow=pW;\r
+}\r
+//===============================================\r
+// function: RenderWindow\r
+// purpose :\r
+//=============================================== \r
+vtkRenderWindow* VVTK_Recorder::RenderWindow()\r
+{\r
+ return myRenderWindow;\r
+}\r
+//===============================================\r
+// function: ErrorStatus\r
+// purpose :\r
+//=============================================== \r
+int VVTK_Recorder::ErrorStatus()const\r
+{\r
+ return myErrorStatus;\r
+}\r
+//===============================================\r
+// function: State\r
+// purpose :\r
+//=============================================== \r
+int VVTK_Recorder::State()const\r
+{\r
+ return myState;\r
+}\r
+//===============================================\r
+// function: ProcessEvents\r
+// purpose :\r
+//===============================================\r
+void VVTK_Recorder::ProcessEvents(vtkObject* vtkNotUsed(theObject), \r
+ unsigned long theEvent,\r
+ void* theClientData, \r
+ void* vtkNotUsed(theCallData))\r
+{\r
+ if(vtkObject* pObj=reinterpret_cast<vtkObject*>(theClientData)) { \r
+ if(VVTK_Recorder* pSelf=reinterpret_cast<VVTK_Recorder*>(pObj)) {\r
+ if(theEvent==vtkCommand::EndEvent){\r
+ if (pSelf->State()==VVTK_Recorder::VVTK_Recorder_Record){\r
+ pSelf->DoRecord();\r
+ }\r
+ }\r
+ }\r
+ }\r
+}\r
+//===============================================\r
+// function: Record\r
+// purpose :\r
+//=============================================== \r
+void VVTK_Recorder::Record()\r
+{\r
+ if (myState==VVTK_Recorder_Stop){\r
+ if (myRenderWindow){\r
+ myState=VVTK_Recorder_Record;\r
+ //\r
+ myFilter->SetInput(myRenderWindow);\r
+ //\r
+ myFrameIndex=-1;\r
+ myNbWrittenFrames=0;\r
+ //\r
+ myRenderWindow->RemoveObserver(myCommand);\r
+ myRenderWindow->AddObserver(vtkCommand::EndEvent,\r
+ myCommand,\r
+ myPriority);\r
+ myRenderWindow->Render();\r
+ }\r
+ }\r
+}\r
+//===============================================\r
+// function: Play\r
+// purpose :\r
+//=============================================== \r
+void VVTK_Recorder::Play()\r
+{\r
+ if (myState==VVTK_Recorder_Stop){\r
+ if (myRenderWindow){\r
+ myState=VVTK_Recorder_Play;\r
+ }\r
+ }\r
+}\r
+//===============================================\r
+// function: Stop\r
+// purpose :\r
+//=============================================== \r
+void VVTK_Recorder::Stop()\r
+{\r
+ if (myState==VVTK_Recorder_Record) { \r
+ myWriterMgr->Stop();\r
+ AddSkippedFrames();\r
+ MakeFileAVI();\r
+ }\r
+ if (myState==VVTK_Recorder_Play){\r
+ //...\r
+ }\r
+ myState=VVTK_Recorder_Stop;\r
+}\r
+//===============================================\r
+// function: Pause\r
+// purpose :\r
+//=============================================== \r
+void VVTK_Recorder::Pause()\r
+{\r
+ myPaused=myPaused ? 0 : 1;\r
+}\r
+//===============================================\r
+// function: DoRecord\r
+// purpose :\r
+//===============================================\r
+void VVTK_Recorder::DoRecord()\r
+{\r
+ if (myPaused){\r
+ return;\r
+ }\r
+ //\r
+ char *buf, aPrefix[512];\r
+ double aTimeNow, dT;\r
+ int aFrameIndex, aQuality, aProgressive;\r
+ //\r
+ if (myFrameIndex<0) {\r
+ myFrameIndex=0;\r
+ myTimeStart=vtkTimerLog::GetCurrentTime();\r
+ //\r
+ myWriterMgr->start();\r
+ //\r
+ }\r
+ else {\r
+ aTimeNow=vtkTimerLog::GetCurrentTime();\r
+ dT=aTimeNow-myTimeStart;\r
+ if (dT<0.){\r
+ //printf(" * DoRecord() dT<0 returned\n");\r
+ return;\r
+ }\r
+ aFrameIndex=(int)(dT*myNbFPS);\r
+ if (aFrameIndex==myFrameIndex) {\r
+ return;\r
+ }\r
+ myFrameIndex=aFrameIndex;\r
+ }\r
+ //\r
+ myRenderWindow->RemoveObserver(myCommand);\r
+ //\r
+ myFilter->Modified();\r
+ //\r
+ buf=new char [512];\r
+ GetNameJPEG(myName, myFrameIndex, buf);\r
+ //printf(" *buf: %s\n", buf);\r
+ //\r
+ PreWrite();\r
+ //===============\r
+ //\r
+ aQuality=95;\r
+ aProgressive=1;\r
+ vtkImageData *pC=vtkImageData::New(); \r
+ pC->DeepCopy(myFilter->GetOutput());\r
+ //\r
+ myWriterMgr->StartImageWriter(buf, aProgressive, aQuality, pC);\r
+ ++myNbWrittenFrames;\r
+ //\r
+ //===============\r
+ myRenderWindow->AddObserver(vtkCommand::EndEvent,\r
+ myCommand,\r
+ myPriority);\r
+}\r
+//===============================================\r
+// function: PreWrite\r
+// purpose :\r
+//===============================================\r
+void VVTK_Recorder::PreWrite()\r
+{\r
+ vtkImageData *pImageData=myFilter->GetOutput();\r
+ //\r
+ if (!pImageData){\r
+ myErrorStatus=20;\r
+ return;\r
+ }\r
+ pImageData->UpdateInformation();\r
+ int *wExtent=pImageData->GetWholeExtent();\r
+ pImageData->SetUpdateExtent(wExtent[0], wExtent[1],\r
+ wExtent[2], wExtent[3],\r
+ 0,0);\r
+ pImageData->UpdateData();\r
+}\r
+//===============================================\r
+// function: AddSkippedFrames\r
+// purpose :\r
+//===============================================\r
+void VVTK_Recorder::AddSkippedFrames()\r
+{\r
+ myErrorStatus=0;\r
+ //\r
+ \r
+}\r
+//===============================================\r
+// function: MakeFileAVI\r
+// purpose :\r
+//===============================================\r
+void VVTK_Recorder::MakeFileAVI()\r
+{\r
+ myErrorStatus=0;\r
+ //\r
+ int iNbFPS;\r
+ char aCmd[1024], fmt[]={"_\%06d.jpeg"};\r
+ //"jpeg2yuv -f 10 -I p -n 16 -v 0 -j abcx_1%06d.jpeg | yuv2lav -o z.avi" \r
+ //\r
+ iNbFPS=(int)myNbFPS;\r
+ sprintf(aCmd, "jpeg2yuv -I p -v 0 -f %d -n %d -j %s%s | yuv2lav -o %s.avi",\r
+ iNbFPS, myNbWrittenFrames, myName, fmt, myName);\r
+ //\r
+ myErrorStatus=system(aCmd);\r
+}\r
+//===============================================\r
+// function: GetNameJPEG\r
+// purpose :\r
+//===============================================\r
+void GetNameJPEG(const char *pName, \r
+ const int aIndex,\r
+ char *pNameJPEG)\r
+{\r
+ sprintf(pNameJPEG, "%s_%06d.jpeg", pName, aIndex);\r
+}\r
+\r
--- /dev/null
+// SALOME VTKViewer : build VTK viewer into Salome desktop\r
+//\r
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS \r
+// \r
+// This library is free software; you can redistribute it and/or \r
+// modify it under the terms of the GNU Lesser General Public \r
+// License as published by the Free Software Foundation; either \r
+// version 2.1 of the License. \r
+// \r
+// This library is distributed in the hope that it will be useful, \r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of \r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU \r
+// Lesser General Public License for more details. \r
+// \r
+// You should have received a copy of the GNU Lesser General Public \r
+// License along with this library; if not, write to the Free Software \r
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA \r
+// \r
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org \r
+//\r
+//\r
+//\r
+// File : \r
+// Author : \r
+// Module : SALOME\r
+// $Header$\r
+\r
+#ifndef _VVTK_Recorder_Header_File_\r
+#define _VVTK_Recorder_Header_File_\r
+\r
+#include <list>\r
+#include <vtkObject.h>\r
+\r
+class vtkRenderWindow;\r
+class vtkCallbackCommand;\r
+class vtkWindowToImageFilter;\r
+class VVTK_ImageWriterMgr;\r
+//\r
+class VVTK_Recorder : public vtkObject {\r
+\r
+protected:\r
+ enum State {\r
+ VVTK_Recorder_Unknown=0,\r
+ VVTK_Recorder_Record,\r
+ VVTK_Recorder_Play,\r
+ VVTK_Recorder_Stop\r
+ };\r
+\r
+public:\r
+ static VVTK_Recorder *New();\r
+ vtkTypeRevisionMacro(VVTK_Recorder,vtkObject);\r
+ //\r
+ void SetRenderWindow(vtkRenderWindow* pW);\r
+ vtkRenderWindow* RenderWindow();\r
+ //\r
+ void SetName(const char *theName);\r
+ const char* Name()const;\r
+ //\r
+ void SetNbFPS(const double theNbFPS);\r
+ double NbFPS()const;\r
+ //\r
+ void Record();\r
+ void Play();\r
+ void Pause();\r
+ void Stop();\r
+ //\r
+ int State()const;\r
+ int ErrorStatus()const;\r
+\r
+ static void ProcessEvents(vtkObject* theObject, \r
+ unsigned long theEvent,\r
+ void* theClientData, \r
+ void* theCallData);\r
+\r
+ //\r
+protected :\r
+ VVTK_Recorder();\r
+ ~VVTK_Recorder();\r
+ void DoRecord();\r
+ void DoPlay();\r
+ void DoStop();\r
+ void MakeFileAVI();\r
+ void AddSkippedFrames();\r
+ void PreWrite();\r
+ //\r
+protected :\r
+ int myState;\r
+ int myPaused;\r
+ double myNbFPS;\r
+ int myErrorStatus;\r
+ int myFrameIndex;\r
+ int myNbWrittenFrames;\r
+ float myPriority;\r
+ double myTimeStart;\r
+ char *myName;\r
+\r
+ vtkCallbackCommand *myCommand;\r
+ vtkRenderWindow *myRenderWindow;\r
+ vtkWindowToImageFilter *myFilter;\r
+ VVTK_ImageWriterMgr *myWriterMgr;\r
+\r
+private:\r
+ VVTK_Recorder(const VVTK_Recorder&); //Not implemented\r
+ void operator=(const VVTK_Recorder&); //Not implemented\r
+};\r
+#endif\r
#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 <vtkObjectFactory.h>
#include <vtkProperty.h>
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() - "<<this);
- myImplicitFunctionWidget->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() - "<<this);
- myImplicitFunctionWidget->SetInteractor(NULL);
+ myWidgetCtrl->SetInteractor(NULL);
}
//----------------------------------------------------------------------------
::AddActor(VTKViewer_Actor* theActor)
{
if(VISU_GaussPtsAct1* anActor = dynamic_cast<VISU_GaussPtsAct1*>(theActor)){
- anActor->SetImplicitFunctionWidget(GetImplicitFunctionWidget());
+ anActor->SetWidgetCtrl(GetWidgetCtrl());
anActor->SetOutsideCursorSettings(myOutsideCursorSettings);
Superclass::AddActor(anActor);
- AdjustImplicitFunctionWidget();
+ AdjustWidgetCtrl();
}
}
{
using namespace VISU;
if(VISU_GaussPtsAct1* anActor = dynamic_cast<VISU_GaussPtsAct1*>(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 (dX<dXmin){
+ dXmin=dX;
+ }
+ }
+ pSphereWidget->SetRadius(dXmin);
}
}
//----------------------------------------------------------------------------
SVTK_Selector* theSelector)
{
SVTK_Renderer::Initialize(theInteractor,theSelector);
- myImplicitFunctionWidget->SetInteractor(theInteractor);
+ myWidgetCtrl->SetInteractor(theInteractor);
}
//----------------------------------------------------------------------------
}
//----------------------------------------------------------------------------
-VISU_ImplicitFunctionWidget*
-VVTK_Renderer1
-::GetImplicitFunctionWidget()
+VISU_WidgetCtrl* VVTK_Renderer1::GetWidgetCtrl()
{
- return myImplicitFunctionWidget.GetPointer();
+ return myWidgetCtrl.GetPointer();
}
//----------------------------------------------------------------------------
}
//----------------------------------------------------------------------------
-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
//----------------------------------------------------------------------------
-void
-VVTK_Renderer2
-::AddActor(VTKViewer_Actor* theActor)
+void VVTK_Renderer2::AddActor(VTKViewer_Actor* theActor)
{
if(VISU_GaussPtsAct1* anActor = dynamic_cast<VISU_GaussPtsAct1*>(theActor)){
if(VISU::TGaussPtsActorFactory* aFactory = anActor->GetGaussPtsFactory()){
if(VISU_GaussPtsAct2* anActor2 = aFactory->CloneActor(anActor)){
- anActor2->SetImplicitFunctionWidget(myWidget);
+ anActor2->SetWidgetCtrl(myWidgetCtrl);
Superclass::AddActor(anActor2);
}
}
{
using namespace VISU;
if(VISU_GaussPtsAct2* anActor = dynamic_cast<VISU_GaussPtsAct2*>(theActor)){
- anActor->SetImplicitFunctionWidget(NULL);
+ anActor->SetWidgetCtrl(NULL);
Superclass::RemoveActor(theActor);
}
}
#include "SVTK_Renderer.h"
-class VISU_ImplicitFunctionWidget;
+class VISU_WidgetCtrl;
class VISU_InsideCursorSettings;
class VISU_OutsideCursorSettings;
class VISU_PickingSettings;
void
SetOutsideCursorSettings(VISU_OutsideCursorSettings* theOutsideCursorSettings);
- VISU_ImplicitFunctionWidget*
- GetImplicitFunctionWidget();
+ VISU_WidgetCtrl* GetWidgetCtrl();
protected:
VVTK_Renderer1();
bool
OnAdjustActors();
- void AdjustImplicitFunctionWidget();
+ void AdjustWidgetCtrl();
- vtkSmartPointer<VISU_ImplicitFunctionWidget> myImplicitFunctionWidget;
+ vtkSmartPointer<VISU_WidgetCtrl> myWidgetCtrl;
VISU_OutsideCursorSettings* myOutsideCursorSettings;
vtkSmartPointer<VISU_FPSActor> myTextActor;
};
void
RemoveActor(VTKViewer_Actor* theActor);
- void
- SetImplicitFunctionWidget(VISU_ImplicitFunctionWidget* theWidget);
+ void SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl);
void
OnEndInteractionEvent();
// Priority at which events are processed
float myPriority;
- VISU_ImplicitFunctionWidget* myWidget;
+ VISU_WidgetCtrl* myWidgetCtrl;
};
#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"
anOutsideGroupLayout->addWidget( myOutsidePrimitiveBox, 0, 0 );
anOutsideGroupLayout->addWidget( myOutsideSizeBox, 1, 0 );
-
+ //
myTabBox->addTab( myGaussPointsBox, tr( "GAUSS_POINTS_TAB" ) );
myTabBox->showPage( myGaussPointsBox );
{
}
-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),
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);
}
}
{
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();
}
}
{
myPlaneAction->setOn( false );
mySphereAction->setOn( false );
+
+ emit scgClose();
+
reject();
}
{
myPlaneAction->setOn( false );
mySphereAction->setOn( false );
+
+ emit scgClose();
+
QDialog::done( r );
}
class VISU_GaussPtsAct1;
class VISU_InsideCursorSettings;
class VISU_OutsideCursorSettings;
-class VISU_ImplicitFunctionWidget;
+class VISU_WidgetCtrl;
class VVTK_PrimitiveBox;
class VVTK_SizeBox;
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; }
void onClickApply();
void onClickClose();
+signals:
+ void scgClose();
+
private:
QTabWidget* myTabBox;
float myPriority;
vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
- VISU_ImplicitFunctionWidget* myWidget;
+ VISU_WidgetCtrl* myWidgetCtrl;
QtxAction* myPlaneAction;
QtxAction* mySphereAction;
{}
//----------------------------------------------------------------------------
-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);
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;
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);
VVTK_Renderer2* aRenderer = VVTK_Renderer2::New();
aRenderer->Initialize(aDevice,aSelector);
- aRenderer->SetImplicitFunctionWidget(anImplicitFunctionWidget);
+
+ aRenderer->SetWidgetCtrl(aWidgetCtrl);
+
aRenderer->SetInsideCursorSettings(anInsideCursorSettings);
aRenderer->SetPickingSettings(aPickingSettings);