X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FOBJECT%2FSMESH_DeviceActor.cxx;h=3548aaefe33244b272a83704f958bab77908bf22;hp=b838f4fe7f69fdc3f0a72c84a55939c1c42269df;hb=7ba3124c8a4ba32308bbc40957ee9246374aa590;hpb=51569f091c2d18be76ea9bd3e68ca0247cc731c3 diff --git a/src/OBJECT/SMESH_DeviceActor.cxx b/src/OBJECT/SMESH_DeviceActor.cxx index b838f4fe7..3548aaefe 100644 --- a/src/OBJECT/SMESH_DeviceActor.cxx +++ b/src/OBJECT/SMESH_DeviceActor.cxx @@ -21,20 +21,21 @@ // // // -// File : SMESH_Actor.cxx -// Author : Nicolas REJNERI +// File : SMESH_DeviceActor.cxx +// Author : // Module : SMESH // $Header$ #include "SMESH_DeviceActor.h" +#include "SMESH_ExtractGeometry.h" +#include "SMESH_ControlsDef.hxx" +#include "SMESH_ActorUtils.h" -#include "SALOME_Transform.h" -#include "SALOME_TransformFilter.h" -#include "SALOME_PassThroughFilter.h" -#include "SALOME_ExtractUnstructuredGrid.h" - -#include "utilities.h" +#include +#include +#include +#include // VTK Includes #include @@ -47,12 +48,25 @@ #include #include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "utilities.h" + #ifdef _DEBUG_ static int MYDEBUG = 0; -static int MYDEBUGWITHFILES = 0; #else static int MYDEBUG = 0; -static int MYDEBUGWITHFILES = 0; #endif using namespace std; @@ -61,8 +75,10 @@ using namespace std; vtkStandardNewMacro(SMESH_DeviceActor); -SMESH_DeviceActor::SMESH_DeviceActor(){ - if(MYDEBUG) MESSAGE("SMESH_DeviceActor"); +SMESH_DeviceActor::SMESH_DeviceActor() +{ + if(MYDEBUG) MESSAGE("SMESH_DeviceActor - "<SetResolveCoincidentTopologyToShiftZBuffer(); - //myMapper->SetResolveCoincidentTopologyZShift(0.02); - + myMapper->UseLookupTableScalarRangeOn(); myMapper->SetColorModeToMapScalars(); myShrinkFilter = vtkShrinkFilter::New(); - myExtractUnstructuredGrid = SALOME_ExtractUnstructuredGrid::New(); - myExtractUnstructuredGrid->SetStoreMapping(true); + myStoreClippingMapping = false; + myExtractGeometry = SMESH_ExtractGeometry::New(); + myExtractGeometry->SetReleaseDataFlag(true); + myIsImplicitFunctionUsed = false; + + myExtractUnstructuredGrid = VTKViewer_ExtractUnstructuredGrid::New(); + myMergeFilter = vtkMergeFilter::New(); - myStoreMapping = false; - myGeomFilter = SALOME_GeometryFilter::New(); + myGeomFilter = VTKViewer_GeometryFilter::New(); - myTransformFilter = SALOME_TransformFilter::New(); + myTransformFilter = VTKViewer_TransformFilter::New(); for(int i = 0; i < 6; i++) - myPassFilter.push_back(SALOME_PassThroughFilter::New()); + myPassFilter.push_back(VTKViewer_PassThroughFilter::New()); } SMESH_DeviceActor::~SMESH_DeviceActor(){ - if(MYDEBUG) MESSAGE("~SMESH_DeviceActor"); + if(MYDEBUG) MESSAGE("~SMESH_DeviceActor - "<Delete(); - myMapper->RemoveAllInputs(); myMapper->Delete(); - myShrinkFilter->UnRegisterAllOutputs(); myShrinkFilter->Delete(); - myExtractUnstructuredGrid->UnRegisterAllOutputs(); myExtractUnstructuredGrid->Delete(); - myMergeFilter->UnRegisterAllOutputs(); myMergeFilter->Delete(); - myGeomFilter->UnRegisterAllOutputs(); myGeomFilter->Delete(); - myTransformFilter->UnRegisterAllOutputs(); + myExtractGeometry->Delete(); + myTransformFilter->Delete(); for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){ - myPassFilter[i]->UnRegisterAllOutputs(); myPassFilter[i]->Delete(); } } -void SMESH_DeviceActor::SetStoreMapping(int theStoreMapping){ - myStoreMapping = theStoreMapping; - Modified(); +void +SMESH_DeviceActor:: +SetStoreGemetryMapping(bool theStoreMapping) +{ + myGeomFilter->SetStoreMapping(theStoreMapping); + SetStoreClippingMapping(theStoreMapping); +} + + +void +SMESH_DeviceActor:: +SetStoreClippingMapping(bool theStoreMapping) +{ + myStoreClippingMapping = theStoreMapping; + myExtractGeometry->SetStoreMapping(theStoreMapping && myIsImplicitFunctionUsed); + SetStoreIDMapping(theStoreMapping); +} + + +void +SMESH_DeviceActor:: +SetStoreIDMapping(bool theStoreMapping) +{ + myExtractUnstructuredGrid->SetStoreMapping(theStoreMapping); +} + + +void SMESH_DeviceActor::Init(TVisualObjPtr theVisualObj, + vtkImplicitBoolean* theImplicitBoolean) +{ + myVisualObj = theVisualObj; + myExtractGeometry->SetImplicitFunction(theImplicitBoolean); + SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid()); +} + + +void +SMESH_DeviceActor:: +SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed) +{ + int anId = 0; + if(theIsImplicitFunctionUsed) + myPassFilter[ anId ]->SetInput( myExtractGeometry->GetOutput() ); + else + myPassFilter[ anId ]->SetInput( myMergeFilter->GetOutput() ); + + myIsImplicitFunctionUsed = theIsImplicitFunctionUsed; + SetStoreClippingMapping(myStoreClippingMapping); } @@ -136,16 +195,16 @@ void SMESH_DeviceActor::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid){ myIsShrinkable = true; myExtractUnstructuredGrid->SetInput(theGrid); + myMergeFilter->SetGeometry(myExtractUnstructuredGrid->GetOutput()); - theGrid = static_cast(myMergeFilter->GetOutput()); + myExtractGeometry->SetInput(myMergeFilter->GetOutput()); int anId = 0; - myPassFilter[ anId ]->SetInput( theGrid ); + SetImplicitFunctionUsed(myIsImplicitFunctionUsed); myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() ); anId++; // 1 - myGeomFilter->SetStoreMapping( myStoreMapping ); myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() ); anId++; // 2 @@ -172,7 +231,7 @@ void SMESH_DeviceActor::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid){ } -SALOME_ExtractUnstructuredGrid* SMESH_DeviceActor::GetExtractUnstructuredGrid(){ +VTKViewer_ExtractUnstructuredGrid* SMESH_DeviceActor::GetExtractUnstructuredGrid(){ return myExtractUnstructuredGrid; } @@ -183,18 +242,272 @@ vtkUnstructuredGrid* SMESH_DeviceActor::GetUnstructuredGrid(){ } -vtkMergeFilter* SMESH_DeviceActor::GetMergeFilter(){ - return myMergeFilter; +void SMESH_DeviceActor::SetControlMode(SMESH::Controls::FunctorPtr theFunctor, + vtkScalarBarActor* theScalarBarActor, + vtkLookupTable* theLookupTable) +{ + bool anIsInitialized = theFunctor; + if(anIsInitialized){ + vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New(); + + SetStoreIDMapping(true); + myExtractUnstructuredGrid->Update(); + vtkUnstructuredGrid* aGrid = myExtractUnstructuredGrid->GetOutput(); + + aDataSet->ShallowCopy(aGrid); + + vtkDoubleArray *aScalars = vtkDoubleArray::New(); + vtkIdType aNbCells = aGrid->GetNumberOfCells(); + aScalars->SetNumberOfComponents(1); + aScalars->SetNumberOfTuples(aNbCells); + + myVisualObj->UpdateFunctor(theFunctor); + + using namespace SMESH::Controls; + if(NumericalFunctor* aNumericalFunctor = dynamic_cast(theFunctor.get())){ + for(vtkIdType i = 0; i < aNbCells; i++){ + vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i); + vtkIdType anObjId = myVisualObj->GetElemObjId(anId); + double aValue = aNumericalFunctor->GetValue(anObjId); + aScalars->SetValue(i,aValue); + } + }else if(Predicate* aPredicate = dynamic_cast(theFunctor.get())){ + for(vtkIdType i = 0; i < aNbCells; i++){ + vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i); + vtkIdType anObjId = myVisualObj->GetElemObjId(anId); + bool aValue = aPredicate->IsSatisfy(anObjId); + aScalars->SetValue(i,aValue); + } + } + + aDataSet->GetCellData()->SetScalars(aScalars); + aScalars->Delete(); + + theLookupTable->SetRange(aScalars->GetRange()); + theLookupTable->Build(); + + myMergeFilter->SetScalars(aDataSet); + aDataSet->Delete(); + } + GetMapper()->SetScalarVisibility(anIsInitialized); + theScalarBarActor->SetVisibility(anIsInitialized); +} + +void SMESH_DeviceActor::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor, + vtkScalarBarActor* theScalarBarActor, + vtkLookupTable* theLookupTable) +{ + bool anIsInitialized = theFunctor; + myExtractUnstructuredGrid->ClearRegisteredCells(); + myExtractUnstructuredGrid->ClearRegisteredCellsWithType(); + myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::ePassAll); + myVisualObj->UpdateFunctor(theFunctor); + + using namespace SMESH::Controls; + if (anIsInitialized){ + if (Length2D* aLength2D = dynamic_cast(theFunctor.get())){ + SMESH::Controls::Length2D::TValues aValues; + + aLength2D->GetValues(aValues); + vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New(); + vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid(); + + aDataSet->SetPoints(aGrid->GetPoints()); + + vtkIdType aNbCells = aValues.size(); + + vtkDoubleArray *aScalars = vtkDoubleArray::New(); + aScalars->SetNumberOfComponents(1); + aScalars->SetNumberOfTuples(aNbCells); + + vtkIdType aCellsSize = 3*aNbCells; + vtkCellArray* aConnectivity = vtkCellArray::New(); + aConnectivity->Allocate( aCellsSize, 0 ); + + vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); + aCellTypesArray->SetNumberOfComponents( 1 ); + aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() ); + + vtkIdList *anIdList = vtkIdList::New(); + anIdList->SetNumberOfIds(2); + + Length2D::TValues::const_iterator anIter = aValues.begin(); + for(vtkIdType aVtkId = 0; anIter != aValues.end(); anIter++,aVtkId++){ + const Length2D::Value& aValue = *anIter; + int aNode[2] = { + myVisualObj->GetNodeVTKId(aValue.myPntId[0]), + myVisualObj->GetNodeVTKId(aValue.myPntId[1]) + }; + if(aNode[0] >= 0 && aNode[1] >= 0){ + anIdList->SetId( 0, aNode[0] ); + anIdList->SetId( 1, aNode[1] ); + aConnectivity->InsertNextCell( anIdList ); + aCellTypesArray->InsertNextValue( VTK_LINE ); + aScalars->SetValue(aVtkId,aValue.myLength); + } + } + + vtkIntArray* aCellLocationsArray = vtkIntArray::New(); + aCellLocationsArray->SetNumberOfComponents( 1 ); + aCellLocationsArray->SetNumberOfTuples( aNbCells ); + + aConnectivity->InitTraversal(); + for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) + aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); + + aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity ); + SetUnstructuredGrid(aDataSet); + + aDataSet->GetCellData()->SetScalars(aScalars); + aScalars->Delete(); + + theLookupTable->SetRange(aScalars->GetRange()); + theLookupTable->Build(); + + myMergeFilter->SetScalars(aDataSet); + aDataSet->Delete(); + } + else if (MultiConnection2D* aMultiConnection2D = dynamic_cast(theFunctor.get())){ + SMESH::Controls::MultiConnection2D::MValues aValues; + + aMultiConnection2D->GetValues(aValues); + vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New(); + vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid(); + aDataSet->SetPoints(aGrid->GetPoints()); + + vtkIdType aNbCells = aValues.size(); + vtkDoubleArray *aScalars = vtkDoubleArray::New(); + aScalars->SetNumberOfComponents(1); + aScalars->SetNumberOfTuples(aNbCells); + + vtkIdType aCellsSize = 3*aNbCells; + vtkCellArray* aConnectivity = vtkCellArray::New(); + aConnectivity->Allocate( aCellsSize, 0 ); + + vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); + aCellTypesArray->SetNumberOfComponents( 1 ); + aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() ); + + vtkIdList *anIdList = vtkIdList::New(); + anIdList->SetNumberOfIds(2); + + MultiConnection2D::MValues::const_iterator anIter = aValues.begin(); + for(vtkIdType aVtkId = 0; anIter != aValues.end(); anIter++,aVtkId++){ + const MultiConnection2D::Value& aValue = (*anIter).first; + int aNode[2] = { + myVisualObj->GetNodeVTKId(aValue.myPntId[0]), + myVisualObj->GetNodeVTKId(aValue.myPntId[1]) + }; + if(aNode[0] >= 0 && aNode[1] >= 0){ + anIdList->SetId( 0, aNode[0] ); + anIdList->SetId( 1, aNode[1] ); + aConnectivity->InsertNextCell( anIdList ); + aCellTypesArray->InsertNextValue( VTK_LINE ); + aScalars->SetValue(aVtkId,(*anIter).second); + } + } + + vtkIntArray* aCellLocationsArray = vtkIntArray::New(); + aCellLocationsArray->SetNumberOfComponents( 1 ); + aCellLocationsArray->SetNumberOfTuples( aNbCells ); + + aConnectivity->InitTraversal(); + for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) + aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); + + aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity ); + SetUnstructuredGrid(aDataSet); + + aDataSet->GetCellData()->SetScalars(aScalars); + aScalars->Delete(); + + theLookupTable->SetRange(aScalars->GetRange()); + theLookupTable->Build(); + + myMergeFilter->SetScalars(aDataSet); + aDataSet->Delete(); + } + } + GetMapper()->SetScalarVisibility(anIsInitialized); + theScalarBarActor->SetVisibility(anIsInitialized); } +void SMESH_DeviceActor::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor) +{ + myExtractUnstructuredGrid->ClearRegisteredCells(); + myExtractUnstructuredGrid->ClearRegisteredCellsWithType(); + myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::ePassAll); + myVisualObj->UpdateFunctor(theFunctor); + + using namespace SMESH::Controls; + if(FreeBorders* aFreeBorders = dynamic_cast(theFunctor.get())){ + myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding); + vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid(); + vtkIdType aNbCells = aGrid->GetNumberOfCells(); + for( vtkIdType i = 0; i < aNbCells; i++ ){ + vtkIdType anObjId = myVisualObj->GetElemObjId(i); + if(aFreeBorders->IsSatisfy(anObjId)) + myExtractUnstructuredGrid->RegisterCell(i); + } + if(!myExtractUnstructuredGrid->IsCellsRegistered()) + myExtractUnstructuredGrid->RegisterCell(-1); + SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid()); + }else if(FreeEdges* aFreeEdges = dynamic_cast(theFunctor.get())){ + SMESH::Controls::FreeEdges::TBorders aBorders; + aFreeEdges->GetBoreders(aBorders); + vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New(); + vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid(); + aDataSet->SetPoints(aGrid->GetPoints()); + + vtkIdType aNbCells = aBorders.size(); + vtkIdType aCellsSize = 3*aNbCells; + vtkCellArray* aConnectivity = vtkCellArray::New(); + aConnectivity->Allocate( aCellsSize, 0 ); + + vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); + aCellTypesArray->SetNumberOfComponents( 1 ); + aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() ); + + vtkIdList *anIdList = vtkIdList::New(); + anIdList->SetNumberOfIds(2); + + FreeEdges::TBorders::const_iterator anIter = aBorders.begin(); + for(; anIter != aBorders.end(); anIter++){ + const FreeEdges::Border& aBorder = *anIter; + int aNode[2] = { + myVisualObj->GetNodeVTKId(aBorder.myPntId[0]), + myVisualObj->GetNodeVTKId(aBorder.myPntId[1]) + }; + //cout<<"aNode = "<= 0 && aNode[1] >= 0){ + anIdList->SetId( 0, aNode[0] ); + anIdList->SetId( 1, aNode[1] ); + aConnectivity->InsertNextCell( anIdList ); + aCellTypesArray->InsertNextValue( VTK_LINE ); + } + } + + vtkIntArray* aCellLocationsArray = vtkIntArray::New(); + aCellLocationsArray->SetNumberOfComponents( 1 ); + aCellLocationsArray->SetNumberOfTuples( aNbCells ); + + aConnectivity->InitTraversal(); + for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) + aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); + + aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity ); -vtkPolyData* SMESH_DeviceActor::GetPolyDataInput(){ - return myPassFilter.back()->GetPolyDataOutput(); + SetUnstructuredGrid(aDataSet); + aDataSet->Delete(); + } } + + unsigned long int SMESH_DeviceActor::GetMTime(){ unsigned long mTime = this->Superclass::GetMTime(); + mTime = max(mTime,myExtractGeometry->GetMTime()); mTime = max(mTime,myExtractUnstructuredGrid->GetMTime()); mTime = max(mTime,myMergeFilter->GetMTime()); mTime = max(mTime,myGeomFilter->GetMTime()); @@ -203,13 +516,12 @@ unsigned long int SMESH_DeviceActor::GetMTime(){ } -void SMESH_DeviceActor::SetTransform(SALOME_Transform* theTransform){ +void SMESH_DeviceActor::SetTransform(VTKViewer_Transform* theTransform){ myTransformFilter->SetTransform(theTransform); } -void SMESH_DeviceActor::SetShrink() -{ +void SMESH_DeviceActor::SetShrink() { if ( !myIsShrinkable ) return; if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() ) { @@ -219,8 +531,7 @@ void SMESH_DeviceActor::SetShrink() } } -void SMESH_DeviceActor::UnShrink() -{ +void SMESH_DeviceActor::UnShrink() { if ( !myIsShrunk ) return; if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() ) { @@ -232,28 +543,31 @@ void SMESH_DeviceActor::UnShrink() } -void SMESH_DeviceActor::SetRepresentation(EReperesent theMode){ +void SMESH_DeviceActor::SetRepresentation(EReperesent theMode){ switch(theMode){ - case ePoint: + case ePoint: myGeomFilter->SetInside(true); GetProperty()->SetRepresentation(0); break; - case eInsideframe: + case eInsideframe: myGeomFilter->SetInside(true); GetProperty()->SetRepresentation(1); break; default : - GetProperty()->SetRepresentation(theMode); myGeomFilter->SetInside(false); + GetProperty()->SetRepresentation(theMode); } myRepresentation = theMode; + GetProperty()->Modified(); myMapper->Modified(); Modified(); } void SMESH_DeviceActor::SetVisibility(int theMode){ - if(!myExtractUnstructuredGrid->GetInput() || GetUnstructuredGrid()->GetNumberOfCells()){ + if(!myExtractUnstructuredGrid->GetInput() || + GetUnstructuredGrid()->GetNumberOfCells()) + { vtkLODActor::SetVisibility(theMode); }else{ vtkLODActor::SetVisibility(false); @@ -269,62 +583,54 @@ int SMESH_DeviceActor::GetVisibility(){ } -int SMESH_DeviceActor::GetObjId(int theVtkID){ - if (GetRepresentation() == ePoint){ - return GetNodeObjId(theVtkID); - }else{ - return GetElemObjId(theVtkID); - } -} - - -SMESH_DeviceActor::TVectorId SMESH_DeviceActor::GetVtkId(int theObjID){ - if (GetRepresentation() == ePoint){ - return GetNodeVtkId(theObjID); - }else{ - return GetElemVtkId(theObjID); - } -} +int SMESH_DeviceActor::GetNodeObjId(int theVtkID){ + vtkIdType anID = theVtkID; + if(IsImplicitFunctionUsed()) + anID = myExtractGeometry->GetNodeObjId(theVtkID); -int SMESH_DeviceActor::GetNodeObjId(int theVtkID){ - vtkIdType aRetID = myVisualObj->GetNodeObjId(theVtkID); - if(MYDEBUG) MESSAGE("GetNodeObjId - theVtkID = "<