X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FOBJECT%2FSMESH_DeviceActor.cxx;h=6f9e3e44cab8a2a4e818e4c6da0fb3bebddd397b;hp=c82bbf30524a34ebea0025dc4c3737ebc80775b0;hb=cd8f63e177668f374f675a3163750e31abf2c4b6;hpb=9a54694a0ab1e5cbc558a35c4606ceea4f7af2ef diff --git a/src/OBJECT/SMESH_DeviceActor.cxx b/src/OBJECT/SMESH_DeviceActor.cxx index c82bbf305..6f9e3e44c 100644 --- a/src/OBJECT/SMESH_DeviceActor.cxx +++ b/src/OBJECT/SMESH_DeviceActor.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2015 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 @@ -6,7 +6,7 @@ // 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. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -63,6 +63,8 @@ #include +#include + #include "utilities.h" #ifdef _DEBUG_ @@ -90,6 +92,7 @@ SMESH_DeviceActor myProperty = vtkProperty::New(); myMapper = VTKViewer_PolyDataMapper::New(); + myPlaneCollection = vtkPlaneCollection::New(); vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor, myPolygonOffsetUnits); @@ -119,13 +122,13 @@ SMESH_DeviceActor // Orientation of faces myIsFacesOriented = false; - vtkFloatingPointType anRGB[3] = { 1, 1, 1 }; + 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->SetInput(myFaceOrientationFilter->GetOutput()); + myFaceOrientationDataMapper->SetInputConnection(myFaceOrientationFilter->GetOutputPort()); myFaceOrientation = vtkActor::New(); myFaceOrientation->SetMapper(myFaceOrientationDataMapper); @@ -208,9 +211,9 @@ SMESH_DeviceActor { 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); @@ -225,38 +228,51 @@ SMESH_DeviceActor //myIsShrinkable = theGrid->GetNumberOfCells() > 10; myIsShrinkable = true; - myExtractUnstructuredGrid->SetInput(theGrid); + myExtractUnstructuredGrid->SetInputData(theGrid); - myMergeFilter->SetGeometry(myExtractUnstructuredGrid->GetOutput()); + myMergeFilter->SetGeometryConnection(myExtractUnstructuredGrid->GetOutputPort()); + + //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 - myTransformFilter->SetInput( myPassFilter[ anId ]->GetOutput() ); + myTransformFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); anId++; // 2 - myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() ); - myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); + myPassFilter[ anId ]->SetInputConnection( myTransformFilter->GetOutputPort() ); + myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); anId++; // 3 - myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() ); + myGeomFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); anId++; // 4 - myPassFilter[ anId ]->SetInput( myGeomFilter->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->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); + if( myPlaneCollection->GetNumberOfItems() ) + myMapper->SetClippingPlanes( myPlaneCollection ); vtkLODActor::SetMapper( myMapper ); Modified(); } } +void +SMESH_DeviceActor +::SetPlaneCollection( vtkPlaneCollection* theCollection ) +{ + myPlaneCollection = theCollection; +} VTKViewer_ExtractUnstructuredGrid* SMESH_DeviceActor @@ -281,7 +297,7 @@ SMESH_DeviceActor SMESH_ScalarBarActor* theScalarBarActor, vtkLookupTable* theLookupTable) { - bool anIsInitialized = theFunctor; + bool anIsInitialized = theFunctor != NULL; if(anIsInitialized){ vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New(); @@ -295,34 +311,46 @@ SMESH_DeviceActor vtkIdType aNbCells = aGrid->GetNumberOfCells(); aScalars->SetNumberOfComponents(1); aScalars->SetNumberOfTuples(aNbCells); + double* range;// = aScalars->GetRange(); myVisualObj->UpdateFunctor(theFunctor); using namespace SMESH::Controls; - if(NumericalFunctor* aNumericalFunctor = dynamic_cast(theFunctor.get())){ + 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())){ + 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())) + { 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); @@ -365,12 +393,13 @@ 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++){ + aNbCells = 0; + for(; anIter != aValues.end(); anIter++){ const Length2D::Value& aValue = *anIter; int aNode[2] = { myVisualObj->GetNodeVTKId(aValue.myPntId[0]), @@ -381,28 +410,31 @@ SMESH_DeviceActor anIdList->SetId( 1, aNode[1] ); aConnectivity->InsertNextCell( anIdList ); aCellTypesArray->InsertNextValue( VTK_LINE ); - aScalars->SetValue(aVtkId,aValue.myLength); + 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 ); + + 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())){ @@ -421,16 +453,17 @@ 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++){ + aNbCells = 0; + for(; anIter != aValues.end(); anIter++){ const MultiConnection2D::Value& aValue = (*anIter).first; int aNode[2] = { myVisualObj->GetNodeVTKId(aValue.myPntId[0]), @@ -441,28 +474,31 @@ SMESH_DeviceActor anIdList->SetId( 1, aNode[1] ); aConnectivity->InsertNextCell( anIdList ); aCellTypesArray->InsertNextValue( VTK_LINE ); - aScalars->SetValue(aVtkId,(*anIter).second); + 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 ) ); - + 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(); } } @@ -480,17 +516,17 @@ SMESH_DeviceActor myVisualObj->UpdateFunctor(theFunctor); using namespace SMESH::Controls; - if ( dynamic_cast(theFunctor.get()) || - dynamic_cast(theFunctor.get()) || - dynamic_cast(theFunctor.get()) || - dynamic_cast(theFunctor.get()) || - dynamic_cast(theFunctor.get()) || - dynamic_cast(theFunctor.get()) || - dynamic_cast(theFunctor.get()) || - dynamic_cast(theFunctor.get()) || - 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()))) { - Predicate* aPredicate = dynamic_cast(theFunctor.get()); myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding); vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid(); vtkIdType aNbCells = aGrid->GetNumberOfCells(); @@ -552,10 +588,9 @@ SMESH_DeviceActor SetUnstructuredGrid(aDataSet); aDataSet->Delete(); } - else if(dynamic_cast(theFunctor.get()) || - dynamic_cast(theFunctor.get())) + else if (( aPredicate = dynamic_cast(theFunctor.get())) || + ( aPredicate = dynamic_cast(theFunctor.get()))) { - Predicate* aPredicate = dynamic_cast(theFunctor.get()); myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding); vtkIdType aNbNodes = myVisualObj->GetNbEntities(SMDSAbs_Node); for( vtkIdType i = 0; i < aNbNodes; i++ ){ @@ -600,10 +635,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; } } @@ -613,9 +648,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(); @@ -627,37 +662,37 @@ void SMESH_DeviceActor ::SetFacesOriented(bool theIsFacesOriented) { - if ( vtkDataSet* aDataSet = myTransformFilter->GetOutput() ) + if ( vtkAlgorithmOutput* aDataSet = myTransformFilter->GetOutputPort() ) { myIsFacesOriented = theIsFacesOriented; if( theIsFacesOriented ) - myFaceOrientationFilter->SetInput( aDataSet ); + myFaceOrientationFilter->SetInputConnection( aDataSet ); UpdateFaceOrientation(); } } void SMESH_DeviceActor -::SetFacesOrientationColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b) +::SetFacesOrientationColor(double r,double g,double b) { myFaceOrientation->GetProperty()->SetColor( r, g, b ); } void SMESH_DeviceActor -::GetFacesOrientationColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b) +::GetFacesOrientationColor(double& r,double& g,double& b) { myFaceOrientation->GetProperty()->GetColor( r, g, b ); } void SMESH_DeviceActor -::SetFacesOrientationScale(vtkFloatingPointType theScale) +::SetFacesOrientationScale(double theScale) { myFaceOrientationFilter->SetOrientationScale( theScale ); } -vtkFloatingPointType +double SMESH_DeviceActor ::GetFacesOrientationScale() { @@ -780,13 +815,13 @@ SMESH_DeviceActor return aRetID; } -vtkFloatingPointType* +double* SMESH_DeviceActor ::GetNodeCoord(int theObjID) { vtkDataSet* aDataSet = myMergeFilter->GetOutput(); vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID); - vtkFloatingPointType* aCoord = (anID >=0) ? aDataSet->GetPoint(anID) : NULL; + double* aCoord = (anID >=0) ? aDataSet->GetPoint(anID) : NULL; if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<