X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FOBJECT%2FSMESH_DeviceActor.cxx;h=882326963314396aa3ab25a17d6c9a902d13d1bc;hp=bf094ba9b9910361ebe7ca9cf5b5364ebb21d37b;hb=cb55604f37e3d2583272fd436bb6557b041948b5;hpb=57b43b4d010e2d0a1529d3c131bbb9d416e63258 diff --git a/src/OBJECT/SMESH_DeviceActor.cxx b/src/OBJECT/SMESH_DeviceActor.cxx index bf094ba9b..882326963 100644 --- a/src/OBJECT/SMESH_DeviceActor.cxx +++ b/src/OBJECT/SMESH_DeviceActor.cxx @@ -1,42 +1,43 @@ -// SMESH OBJECT : interactive object for SMESH visualization +// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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, or (at your option) any later version. // -// 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 +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com // + +// SMESH OBJECT : interactive object for SMESH visualization // File : SMESH_DeviceActor.cxx // Author : // Module : SMESH -// $Header$ - - +// #include "SMESH_DeviceActor.h" +#include "SMESH_ScalarBarActor.h" #include "SMESH_ExtractGeometry.h" #include "SMESH_ControlsDef.hxx" #include "SMESH_ActorUtils.h" +#include "SMESH_FaceOrientationFilter.h" #include "VTKViewer_CellLocationsArray.h" +#include "VTKViewer_PolyDataMapper.h" #include #include -#include #include +#include // VTK Includes #include @@ -49,7 +50,6 @@ #include #include -#include #include #include #include @@ -60,6 +60,11 @@ #include #include +#include + +#include + +#include #include "utilities.h" @@ -72,7 +77,7 @@ static int MYDEBUG = 0; using namespace std; -vtkStandardNewMacro(SMESH_DeviceActor); +vtkStandardNewMacro(SMESH_DeviceActor) SMESH_DeviceActor @@ -80,15 +85,18 @@ SMESH_DeviceActor { if(MYDEBUG) MESSAGE("SMESH_DeviceActor - "<UseLookupTableScalarRangeOn(); myMapper->SetColorModeToMapScalars(); @@ -110,7 +118,22 @@ SMESH_DeviceActor myTransformFilter = VTKViewer_TransformFilter::New(); for(int i = 0; i < 6; i++) - myPassFilter.push_back(VTKViewer_PassThroughFilter::New()); + myPassFilter.push_back(vtkPassThroughFilter::New()); + + // Orientation of faces + myIsFacesOriented = false; + + double anRGB[3] = { 1, 1, 1 }; + SMESH::GetColor( "SMESH", "orientation_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) ); + + myFaceOrientationFilter = SMESH_FaceOrientationFilter::New(); + + myFaceOrientationDataMapper = vtkPolyDataMapper::New(); + myFaceOrientationDataMapper->SetInputConnection(myFaceOrientationFilter->GetOutputPort()); + + myFaceOrientation = vtkActor::New(); + myFaceOrientation->SetMapper(myFaceOrientationDataMapper); + myFaceOrientation->GetProperty()->SetColor(anRGB[0], anRGB[1], anRGB[2]); } @@ -119,25 +142,29 @@ SMESH_DeviceActor { if(MYDEBUG) MESSAGE("~SMESH_DeviceActor - "<Delete(); - myMapper->Delete(); + // myPlaneCollection->Delete(); -- it is vtkSmartPointer + myProperty->Delete(); - myShrinkFilter->Delete(); + myExtractGeometry->Delete(); + myMergeFilter->Delete(); myExtractUnstructuredGrid->Delete(); - myMergeFilter->Delete(); + // Orientation of faces + myFaceOrientationFilter->Delete(); + myFaceOrientationDataMapper->RemoveAllInputs(); + myFaceOrientationDataMapper->Delete(); + myFaceOrientation->Delete(); myGeomFilter->Delete(); - myExtractGeometry->Delete(); - myTransformFilter->Delete(); - for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){ + for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++) myPassFilter[i]->Delete(); - } + + myShrinkFilter->Delete(); } @@ -146,7 +173,8 @@ SMESH_DeviceActor ::SetStoreGemetryMapping(bool theStoreMapping) { myGeomFilter->SetStoreMapping(theStoreMapping); - SetStoreClippingMapping(theStoreMapping); + // for optimization, switch the mapping explicitly in each filter/algorithm + //SetStoreClippingMapping(theStoreMapping); } @@ -156,7 +184,10 @@ SMESH_DeviceActor { myStoreClippingMapping = theStoreMapping; myExtractGeometry->SetStoreMapping(theStoreMapping && myIsImplicitFunctionUsed); - SetStoreIDMapping(theStoreMapping); + // EAP, 23315 + // Mapping in myExtractUnstructuredGrid and myGeomFilter is ON in the pickable DeviceActor only. + // To show labels, the mapping is computed explicitly via myExtractUnstructuredGrid->BuildOut2InMap(); + //SetStoreIDMapping(theStoreMapping); } @@ -178,16 +209,15 @@ SMESH_DeviceActor SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid()); } - void SMESH_DeviceActor ::SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed) { int anId = 0; if(theIsImplicitFunctionUsed) - myPassFilter[ anId ]->SetInput( myExtractGeometry->GetOutput() ); + myPassFilter[ anId ]->SetInputConnection( myExtractGeometry->GetOutputPort() ); else - myPassFilter[ anId ]->SetInput( myMergeFilter->GetOutput() ); + myPassFilter[ anId ]->SetInputConnection( myMergeFilter->GetOutputPort() ); myIsImplicitFunctionUsed = theIsImplicitFunctionUsed; SetStoreClippingMapping(myStoreClippingMapping); @@ -198,46 +228,55 @@ void SMESH_DeviceActor ::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid) { - if(theGrid){ - //myIsShrinkable = theGrid->GetNumberOfCells() > 10; + myExtractUnstructuredGrid->SetInputData(theGrid); + + if ( theGrid ) + { myIsShrinkable = true; - myExtractUnstructuredGrid->SetInput(theGrid); + myMergeFilter->SetGeometryConnection(myExtractUnstructuredGrid->GetOutputPort()); - myMergeFilter->SetGeometry(myExtractUnstructuredGrid->GetOutput()); + //Pass diameters of the balls + if(myMapper->GetBallEnabled()) { + myMergeFilter->SetScalarsConnection(myExtractUnstructuredGrid->GetOutputPort()); + } - myExtractGeometry->SetInput(myMergeFilter->GetOutput()); + myExtractGeometry->SetInputConnection(myMergeFilter->GetOutputPort()); int anId = 0; SetImplicitFunctionUsed(myIsImplicitFunctionUsed); - myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() ); - + myPassFilter[ anId + 1]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); + anId++; // 1 - myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() ); + myTransformFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); anId++; // 2 - myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() ); - myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); + myPassFilter[ anId ]->SetInputConnection( myTransformFilter->GetOutputPort() ); + myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); anId++; // 3 - myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); - myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); + myGeomFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); anId++; // 4 - myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() ); - myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); - myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() ); - myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); + myPassFilter[ anId ]->SetInputConnection( myGeomFilter->GetOutputPort() ); + myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); anId++; // 5 - myMapper->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); - myMapper->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); + myMapper->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); + if( myPlaneCollection->GetNumberOfItems() ) + myMapper->SetClippingPlanes( myPlaneCollection ); vtkLODActor::SetMapper( myMapper ); - Modified(); } + Modified(); } +void +SMESH_DeviceActor +::SetPlaneCollection( vtkPlaneCollection* theCollection ) +{ + myPlaneCollection = theCollection; +} VTKViewer_ExtractUnstructuredGrid* SMESH_DeviceActor @@ -246,6 +285,7 @@ SMESH_DeviceActor return myExtractUnstructuredGrid; } +#include "SMDS_Mesh.hxx" vtkUnstructuredGrid* SMESH_DeviceActor @@ -259,14 +299,14 @@ SMESH_DeviceActor void SMESH_DeviceActor ::SetControlMode(SMESH::Controls::FunctorPtr theFunctor, - vtkScalarBarActor* theScalarBarActor, - vtkLookupTable* theLookupTable) + SMESH_ScalarBarActor* theScalarBarActor, + vtkLookupTable* theLookupTable) { - bool anIsInitialized = theFunctor; + bool anIsInitialized = theFunctor != NULL; if(anIsInitialized){ vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New(); - SetStoreIDMapping(true); + // SetStoreIDMapping(true); myExtractUnstructuredGrid->Update(); vtkUnstructuredGrid* aGrid = myExtractUnstructuredGrid->GetOutput(); @@ -276,34 +316,50 @@ SMESH_DeviceActor vtkIdType aNbCells = aGrid->GetNumberOfCells(); aScalars->SetNumberOfComponents(1); aScalars->SetNumberOfTuples(aNbCells); + double* range = 0;// = aScalars->GetRange(); 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); + if(NumericalFunctor* aNumericalFunctor = dynamic_cast(theFunctor.get())) + { + myExtractUnstructuredGrid->BuildOut2InMap(); + 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); + range = aScalars->GetRange(); + if ( range[1] - range[0] < ( qMax(qAbs(range[0]),qAbs(range[1])) + 1e-100 ) * 1e-6 ) + { + range[1] = range[0]; + for(vtkIdType i = 0; i < aNbCells; i++) + aScalars->SetValue(i,range[0]); } } + else if(Predicate* aPredicate = dynamic_cast(theFunctor.get())) + { + myExtractUnstructuredGrid->BuildOut2InMap(); + 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); + } + range = aScalars->GetRange(); + } aDataSet->GetCellData()->SetScalars(aScalars); aScalars->Delete(); - - theLookupTable->SetRange(aScalars->GetRange()); + + theLookupTable->SetRange( range ); theLookupTable->SetNumberOfTableValues(theScalarBarActor->GetMaximumNumberOfColors()); theLookupTable->Build(); - myMergeFilter->SetScalars(aDataSet); + myMergeFilter->SetScalarsData(aDataSet); aDataSet->Delete(); } GetMapper()->SetScalarVisibility(anIsInitialized); @@ -313,10 +369,10 @@ SMESH_DeviceActor void SMESH_DeviceActor ::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor, - vtkScalarBarActor* theScalarBarActor, - vtkLookupTable* theLookupTable) + SMESH_ScalarBarActor* theScalarBarActor, + vtkLookupTable* theLookupTable) { - bool anIsInitialized = theFunctor; + bool anIsInitialized = theFunctor != NULL; myExtractUnstructuredGrid->ClearRegisteredCells(); myExtractUnstructuredGrid->ClearRegisteredCellsWithType(); myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::ePassAll); @@ -346,44 +402,49 @@ SMESH_DeviceActor 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); - } + aNbCells = 0; + for(; anIter != aValues.end(); anIter++){ + const Length2D::Value& aValue = *anIter; + vtkIdType 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(aNbCells,aValue.myLength); + aNbCells++; + } } - + aCellTypesArray->SetNumberOfTuples( aNbCells ); + aScalars->SetNumberOfTuples( aNbCells ); + VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::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 ); + vtkIdType const *pts(nullptr); + for( vtkIdType idType = 0, 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); + + myMergeFilter->SetScalarsData(aDataSet); aDataSet->Delete(); } else if (MultiConnection2D* aMultiConnection2D = dynamic_cast(theFunctor.get())){ @@ -402,48 +463,53 @@ SMESH_DeviceActor 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); - } + aNbCells = 0; + for(; anIter != aValues.end(); anIter++){ + const MultiConnection2D::Value& aValue = (*anIter).first; + vtkIdType 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( aNbCells,(*anIter).second); + aNbCells++; + } } - + aCellTypesArray->SetNumberOfTuples( aNbCells ); + aScalars->SetNumberOfTuples( aNbCells ); + VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::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 ) ); - + vtkIdType const *pts(nullptr); + for( vtkIdType idType = 0, 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); + + myMergeFilter->SetScalarsData(aDataSet); aDataSet->Delete(); } } @@ -461,19 +527,31 @@ SMESH_DeviceActor myVisualObj->UpdateFunctor(theFunctor); using namespace SMESH::Controls; - if(FreeBorders* aFreeBorders = dynamic_cast(theFunctor.get())){ + Predicate* aPredicate = 0; + if (( aPredicate = dynamic_cast(theFunctor.get())) || + ( aPredicate = dynamic_cast(theFunctor.get())) || + ( aPredicate = dynamic_cast(theFunctor.get())) || + ( aPredicate = dynamic_cast(theFunctor.get())) || + ( aPredicate = dynamic_cast(theFunctor.get())) || + ( aPredicate = dynamic_cast(theFunctor.get())) || + ( aPredicate = dynamic_cast(theFunctor.get())) || + ( aPredicate = dynamic_cast(theFunctor.get())) || + ( aPredicate = 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(aPredicate->IsSatisfy(anObjId)) + myExtractUnstructuredGrid->RegisterCell(i); } if(!myExtractUnstructuredGrid->IsCellsRegistered()) myExtractUnstructuredGrid->RegisterCell(-1); SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid()); - }else if(FreeEdges* aFreeEdges = dynamic_cast(theFunctor.get())){ + } + else if(FreeEdges* aFreeEdges = dynamic_cast(theFunctor.get())) + { SMESH::Controls::FreeEdges::TBorders aBorders; aFreeEdges->GetBoreders(aBorders); vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New(); @@ -495,16 +573,16 @@ SMESH_DeviceActor 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]) + vtkIdType 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 ); + anIdList->SetId( 0, aNode[0] ); + anIdList->SetId( 1, aNode[1] ); + aConnectivity->InsertNextCell( anIdList ); + aCellTypesArray->InsertNextValue( VTK_LINE ); } } @@ -513,7 +591,8 @@ SMESH_DeviceActor aCellLocationsArray->SetNumberOfTuples( aNbCells ); aConnectivity->InitTraversal(); - for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) + vtkIdType const *pts(nullptr); + for( vtkIdType idType = 0, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity ); @@ -521,21 +600,57 @@ SMESH_DeviceActor SetUnstructuredGrid(aDataSet); aDataSet->Delete(); } + else if (( aPredicate = dynamic_cast(theFunctor.get())) || + ( aPredicate = dynamic_cast(theFunctor.get()))) + { + myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding); + vtkIdType aNbNodes = myVisualObj->GetNbEntities(SMDSAbs_Node); + for( vtkIdType i = 0; i < aNbNodes; i++ ){ + vtkIdType anObjId = myVisualObj->GetNodeObjId(i); + if(aPredicate->IsSatisfy(anObjId)) + myExtractUnstructuredGrid->RegisterCell(i); + } + if(!myExtractUnstructuredGrid->IsCellsRegistered()) + myExtractUnstructuredGrid->RegisterCell(-1); + SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid()); + } } -unsigned long int +vtkMTimeType SMESH_DeviceActor ::GetMTime() { - unsigned long mTime = this->Superclass::GetMTime(); + // cout << "DA " << this + // << " GF " << myGeomFilter; + // if ( this->Property ) + // cout << " P " << this->Property->GetMTime(); + // if ( this->BackfaceProperty != NULL ) + // cout << " BP " << BackfaceProperty->GetMTime(); + // if ( this->Texture != NULL ) + // cout << " T " << this->Texture->GetMTime(); + // cout << " U " << this->GetUserTransformMatrixMTime() + // << " M " << this->MTime.GetMTime() << endl; + + // cout << "DA " << this + // << " GF " << myGeomFilter + // << " " << this->Superclass::GetMTime() + // << " " << myExtractGeometry->GetMTime() + // << " " << myExtractUnstructuredGrid->GetMTime() + // << " " << myMergeFilter->GetMTime() + // << " " << myGeomFilter->GetMTime() + // << " " << myTransformFilter->GetMTime() + // << " " << myFaceOrientationFilter->GetMTime() << endl; + + vtkMTimeType mTime = this->Superclass::GetMTime(); mTime = max(mTime,myExtractGeometry->GetMTime()); mTime = max(mTime,myExtractUnstructuredGrid->GetMTime()); mTime = max(mTime,myMergeFilter->GetMTime()); mTime = max(mTime,myGeomFilter->GetMTime()); mTime = max(mTime,myTransformFilter->GetMTime()); + mTime = max(mTime,myFaceOrientationFilter->GetMTime()); return mTime; } @@ -553,10 +668,10 @@ SMESH_DeviceActor ::SetShrink() { if ( !myIsShrinkable ) return; - if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() ) + if ( vtkAlgorithmOutput* aDataSet = myPassFilter[ 0 ]->GetOutputPort() ) { - myShrinkFilter->SetInput( aDataSet ); - myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() ); + myShrinkFilter->SetInputConnection( aDataSet ); + myPassFilter[ 1 ]->SetInputConnection( myShrinkFilter->GetOutputPort() ); myIsShrunk = true; } } @@ -566,9 +681,9 @@ SMESH_DeviceActor ::UnShrink() { if ( !myIsShrunk ) return; - if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() ) + if ( vtkAlgorithmOutput* aDataSet = myPassFilter[ 0 ]->GetOutputPort() ) { - myPassFilter[ 1 ]->SetInput( aDataSet ); + myPassFilter[ 1 ]->SetInputConnection( aDataSet ); myPassFilter[ 1 ]->Modified(); myIsShrunk = false; Modified(); @@ -576,10 +691,78 @@ SMESH_DeviceActor } +void +SMESH_DeviceActor +::SetFacesOriented(bool theIsFacesOriented) +{ + if ( vtkAlgorithmOutput* aDataSet = myTransformFilter->GetOutputPort() ) + { + myIsFacesOriented = theIsFacesOriented; + if( theIsFacesOriented ) + myFaceOrientationFilter->SetInputConnection( aDataSet ); + UpdateFaceOrientation(); + } +} + +void +SMESH_DeviceActor +::SetFacesOrientationColor(double r,double g,double b) +{ + myFaceOrientation->GetProperty()->SetColor( r, g, b ); +} + +void +SMESH_DeviceActor +::GetFacesOrientationColor(double& r,double& g,double& b) +{ + myFaceOrientation->GetProperty()->GetColor( r, g, b ); +} + +void +SMESH_DeviceActor +::SetFacesOrientationScale(double theScale) +{ + myFaceOrientationFilter->SetOrientationScale( theScale ); +} + +double +SMESH_DeviceActor +::GetFacesOrientationScale() +{ + return myFaceOrientationFilter->GetOrientationScale(); +} + +void +SMESH_DeviceActor +::SetFacesOrientation3DVectors(bool theState) +{ + myFaceOrientationFilter->Set3dVectors( theState ); +} + +bool +SMESH_DeviceActor +::GetFacesOrientation3DVectors() +{ + return myFaceOrientationFilter->Get3dVectors(); +} + +void +SMESH_DeviceActor +::UpdateFaceOrientation() +{ + bool aShowFaceOrientation = myIsFacesOriented; + aShowFaceOrientation &= vtkLODActor::GetVisibility(); //GetVisibility(); -- avoid calling GetUnstructuredGrid() + aShowFaceOrientation &= ( myRepresentation != ePoint ); + myFaceOrientation->SetVisibility(aShowFaceOrientation); +} + + void SMESH_DeviceActor ::SetRepresentation(EReperesent theMode) { + if ( myRepresentation == theMode ) + return; switch(theMode){ case ePoint: myGeomFilter->SetInside(true); @@ -601,7 +784,9 @@ SMESH_DeviceActor myGeomFilter->SetWireframeMode(false); GetProperty()->SetRepresentation(theMode); } + SetMarkerEnabled(theMode == ePoint); myRepresentation = theMode; + UpdateFaceOrientation(); GetProperty()->Modified(); myMapper->Modified(); Modified(); @@ -612,13 +797,15 @@ void SMESH_DeviceActor ::SetVisibility(int theMode) { - if(!myExtractUnstructuredGrid->GetInput() || - GetUnstructuredGrid()->GetNumberOfCells()) + if(( theMode ) && + ( !myExtractUnstructuredGrid->GetInput() || + GetUnstructuredGrid()->GetNumberOfCells())) { vtkLODActor::SetVisibility(theMode); }else{ vtkLODActor::SetVisibility(false); } + UpdateFaceOrientation(); } @@ -626,10 +813,29 @@ int SMESH_DeviceActor ::GetVisibility() { - if(!GetUnstructuredGrid()->GetNumberOfCells()){ + int visibi = vtkLODActor::GetVisibility(); + if(visibi && !GetUnstructuredGrid()->GetNumberOfCells()){ vtkLODActor::SetVisibility(false); + visibi = 0; } - return vtkLODActor::GetVisibility(); + return visibi; +} + + +void +SMESH_DeviceActor +::AddToRender(vtkRenderer* theRenderer) +{ + theRenderer->AddActor(this); + theRenderer->AddActor(myFaceOrientation); +} + +void +SMESH_DeviceActor +::RemoveFromRender(vtkRenderer* theRenderer) +{ + theRenderer->RemoveActor(this); + theRenderer->RemoveActor(myFaceOrientation); } @@ -647,17 +853,23 @@ SMESH_DeviceActor return aRetID; } -vtkFloatingPointType* +double* SMESH_DeviceActor ::GetNodeCoord(int theObjID) { vtkDataSet* aDataSet = myMergeFilter->GetOutput(); vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID); - vtkFloatingPointType* aCoord = aDataSet->GetPoint(anID); + double* aCoord = (anID >=0 && anID < aDataSet->GetNumberOfPoints()) ? aDataSet->GetPoint(anID) : NULL; if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<