X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FOBJECT%2FSMESH_DeviceActor.cxx;h=d53765d79baf12703c580dad0c702028a1d3c08c;hp=8a7341b4913e6006ae2cd1d7954d49b06d598a02;hb=f5016d85b7b4b88623723027a1585c6414c4dc66;hpb=79b1ac2b6df9117f16f11d444b1f165d477a1813 diff --git a/src/OBJECT/SMESH_DeviceActor.cxx b/src/OBJECT/SMESH_DeviceActor.cxx index 8a7341b49..d53765d79 100644 --- a/src/OBJECT/SMESH_DeviceActor.cxx +++ b/src/OBJECT/SMESH_DeviceActor.cxx @@ -1,37 +1,38 @@ -// SMESH OBJECT : interactive object for SMESH visualization +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE // -// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// 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. +// +// 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 @@ -48,7 +49,6 @@ #include #include -#include #include #include #include @@ -61,6 +61,8 @@ #include #include +#include + #include "utilities.h" #ifdef _DEBUG_ @@ -80,15 +82,17 @@ SMESH_DeviceActor { if(MYDEBUG) MESSAGE("SMESH_DeviceActor - "<UseLookupTableScalarRangeOn(); myMapper->SetColorModeToMapScalars(); @@ -111,6 +115,21 @@ SMESH_DeviceActor for(int i = 0; i < 6; i++) myPassFilter.push_back(vtkPassThroughFilter::New()); + + // Orientation of faces + myIsFacesOriented = false; + + vtkFloatingPointType 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()); + + myFaceOrientation = vtkActor::New(); + myFaceOrientation->SetMapper(myFaceOrientationDataMapper); + myFaceOrientation->GetProperty()->SetColor(anRGB[0], anRGB[1], anRGB[2]); } @@ -138,6 +157,14 @@ SMESH_DeviceActor for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){ myPassFilter[i]->Delete(); } + + // Orientation of faces + myFaceOrientationFilter->Delete(); + + myFaceOrientationDataMapper->RemoveAllInputs(); + myFaceOrientationDataMapper->Delete(); + + myFaceOrientation->Delete(); } @@ -213,25 +240,21 @@ SMESH_DeviceActor myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() ); anId++; // 1 - myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() ); + myTransformFilter->SetInput( myPassFilter[ anId ]->GetOutput() ); anId++; // 2 - myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() ); + myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() ); myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); anId++; // 3 - myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); - myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); + myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() ); anId++; // 4 - myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() ); - myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); - myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() ); + myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() ); myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() ); anId++; // 5 myMapper->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); - myMapper->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() ); vtkLODActor::SetMapper( myMapper ); Modified(); @@ -259,8 +282,8 @@ SMESH_DeviceActor void SMESH_DeviceActor ::SetControlMode(SMESH::Controls::FunctorPtr theFunctor, - vtkScalarBarActor* theScalarBarActor, - vtkLookupTable* theLookupTable) + SMESH_ScalarBarActor* theScalarBarActor, + vtkLookupTable* theLookupTable) { bool anIsInitialized = theFunctor; if(anIsInitialized){ @@ -282,23 +305,23 @@ SMESH_DeviceActor 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); + 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); + 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->SetNumberOfTableValues(theScalarBarActor->GetMaximumNumberOfColors()); theLookupTable->Build(); @@ -313,8 +336,8 @@ SMESH_DeviceActor void SMESH_DeviceActor ::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor, - vtkScalarBarActor* theScalarBarActor, - vtkLookupTable* theLookupTable) + SMESH_ScalarBarActor* theScalarBarActor, + vtkLookupTable* theLookupTable) { bool anIsInitialized = theFunctor; myExtractUnstructuredGrid->ClearRegisteredCells(); @@ -352,18 +375,18 @@ SMESH_DeviceActor 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); - } + 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); + } } VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New(); @@ -372,7 +395,7 @@ SMESH_DeviceActor aConnectivity->InitTraversal(); for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) - aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); + aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity ); SetUnstructuredGrid(aDataSet); @@ -412,18 +435,18 @@ SMESH_DeviceActor 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); - } + 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); + } } VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New(); @@ -432,7 +455,7 @@ SMESH_DeviceActor aConnectivity->InitTraversal(); for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) - aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); + aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity ); SetUnstructuredGrid(aDataSet); @@ -461,19 +484,31 @@ SMESH_DeviceActor myVisualObj->UpdateFunctor(theFunctor); using namespace SMESH::Controls; - if(FreeBorders* aFreeBorders = dynamic_cast(theFunctor.get())){ + 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 = 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(); @@ -496,15 +531,15 @@ SMESH_DeviceActor for(; anIter != aBorders.end(); anIter++){ const FreeEdges::Border& aBorder = *anIter; int aNode[2] = { - myVisualObj->GetNodeVTKId(aBorder.myPntId[0]), - myVisualObj->GetNodeVTKId(aBorder.myPntId[1]) + 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 ); } } @@ -521,6 +556,21 @@ SMESH_DeviceActor SetUnstructuredGrid(aDataSet); aDataSet->Delete(); } + else if(dynamic_cast(theFunctor.get()) || + 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++ ){ + vtkIdType anObjId = myVisualObj->GetNodeObjId(i); + if(aPredicate->IsSatisfy(anObjId)) + myExtractUnstructuredGrid->RegisterCell(i); + } + if(!myExtractUnstructuredGrid->IsCellsRegistered()) + myExtractUnstructuredGrid->RegisterCell(-1); + SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid()); + } } @@ -536,6 +586,7 @@ SMESH_DeviceActor mTime = max(mTime,myMergeFilter->GetMTime()); mTime = max(mTime,myGeomFilter->GetMTime()); mTime = max(mTime,myTransformFilter->GetMTime()); + mTime = max(mTime,myFaceOrientationFilter->GetMTime()); return mTime; } @@ -576,6 +627,72 @@ SMESH_DeviceActor } +void +SMESH_DeviceActor +::SetFacesOriented(bool theIsFacesOriented) +{ + if ( vtkDataSet* aDataSet = myTransformFilter->GetOutput() ) + { + myIsFacesOriented = theIsFacesOriented; + if( theIsFacesOriented ) + myFaceOrientationFilter->SetInput( aDataSet ); + UpdateFaceOrientation(); + } +} + +void +SMESH_DeviceActor +::SetFacesOrientationColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b) +{ + myFaceOrientation->GetProperty()->SetColor( r, g, b ); +} + +void +SMESH_DeviceActor +::GetFacesOrientationColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b) +{ + myFaceOrientation->GetProperty()->GetColor( r, g, b ); +} + +void +SMESH_DeviceActor +::SetFacesOrientationScale(vtkFloatingPointType theScale) +{ + myFaceOrientationFilter->SetOrientationScale( theScale ); +} + +vtkFloatingPointType +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 &= GetVisibility(); + aShowFaceOrientation &= myRepresentation == eSurface; + myFaceOrientation->SetVisibility(aShowFaceOrientation); +} + + void SMESH_DeviceActor ::SetRepresentation(EReperesent theMode) @@ -601,7 +718,9 @@ SMESH_DeviceActor myGeomFilter->SetWireframeMode(false); GetProperty()->SetRepresentation(theMode); } + SetMarkerEnabled(theMode == ePoint); myRepresentation = theMode; + UpdateFaceOrientation(); GetProperty()->Modified(); myMapper->Modified(); Modified(); @@ -619,6 +738,7 @@ SMESH_DeviceActor }else{ vtkLODActor::SetVisibility(false); } + UpdateFaceOrientation(); } @@ -633,6 +753,23 @@ SMESH_DeviceActor } +void +SMESH_DeviceActor +::AddToRender(vtkRenderer* theRenderer) +{ + theRenderer->AddActor(this); + theRenderer->AddActor(myFaceOrientation); +} + +void +SMESH_DeviceActor +::RemoveFromRender(vtkRenderer* theRenderer) +{ + theRenderer->RemoveActor(this); + theRenderer->RemoveActor(myFaceOrientation); +} + + int SMESH_DeviceActor ::GetNodeObjId(int theVtkID) @@ -653,7 +790,7 @@ SMESH_DeviceActor { vtkDataSet* aDataSet = myMergeFilter->GetOutput(); vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID); - vtkFloatingPointType* aCoord = aDataSet->GetPoint(anID); + vtkFloatingPointType* aCoord = (anID >=0) ? aDataSet->GetPoint(anID) : NULL; if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<