X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FOBJECT%2FSMESH_DeviceActor.cxx;h=2d632782db5c1fce6ee104e5c18d72eeed2fb0b6;hp=562eaed739f011ba16d605f1288819fb8f18352c;hb=20d9e162bd67182cbfa841bbfc9319919f4703e3;hpb=bd8f1aee7c78f7d2eb82bd4fec5e08c9e3d280ce diff --git a/src/OBJECT/SMESH_DeviceActor.cxx b/src/OBJECT/SMESH_DeviceActor.cxx index 562eaed73..2d632782d 100644 --- a/src/OBJECT/SMESH_DeviceActor.cxx +++ b/src/OBJECT/SMESH_DeviceActor.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 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); @@ -139,7 +142,7 @@ SMESH_DeviceActor if(MYDEBUG) MESSAGE("~SMESH_DeviceActor - "<Delete(); - + myPlaneCollection->Delete(); myProperty->Delete(); myExtractGeometry->Delete(); @@ -201,7 +204,6 @@ SMESH_DeviceActor SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid()); } - void SMESH_DeviceActor ::SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed) @@ -221,20 +223,25 @@ void SMESH_DeviceActor ::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid) { - if(theGrid){ - //myIsShrinkable = theGrid->GetNumberOfCells() > 10; - myIsShrinkable = true; + myExtractUnstructuredGrid->SetInputData(theGrid); - myExtractUnstructuredGrid->SetInputData(theGrid); + if ( theGrid ) + { + myIsShrinkable = true; myMergeFilter->SetGeometryConnection(myExtractUnstructuredGrid->GetOutputPort()); + //Pass diameters of the balls + if(myMapper->GetBallEnabled()) { + myMergeFilter->SetScalarsConnection(myExtractUnstructuredGrid->GetOutputPort()); + } + myExtractGeometry->SetInputConnection(myMergeFilter->GetOutputPort()); int anId = 0; SetImplicitFunctionUsed(myIsImplicitFunctionUsed); myPassFilter[ anId + 1]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); - + anId++; // 1 myTransformFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); @@ -246,17 +253,25 @@ SMESH_DeviceActor myGeomFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); anId++; // 4 - myPassFilter[ anId ]->SetInputConnection( myGeomFilter->GetOutputPort() ); + myPassFilter[ anId ]->SetInputConnection( myGeomFilter->GetOutputPort() ); myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() ); anId++; // 5 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 @@ -265,6 +280,7 @@ SMESH_DeviceActor return myExtractUnstructuredGrid; } +#include "SMDS_Mesh.hxx" vtkUnstructuredGrid* 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,7 +311,7 @@ SMESH_DeviceActor vtkIdType aNbCells = aGrid->GetNumberOfCells(); aScalars->SetNumberOfComponents(1); aScalars->SetNumberOfTuples(aNbCells); - double* range;// = aScalars->GetRange(); + double* range = 0;// = aScalars->GetRange(); myVisualObj->UpdateFunctor(theFunctor); @@ -347,7 +363,7 @@ SMESH_DeviceActor SMESH_ScalarBarActor* theScalarBarActor, vtkLookupTable* theLookupTable) { - bool anIsInitialized = theFunctor; + bool anIsInitialized = theFunctor != NULL; myExtractUnstructuredGrid->ClearRegisteredCells(); myExtractUnstructuredGrid->ClearRegisteredCellsWithType(); myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::ePassAll); @@ -377,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]), @@ -393,27 +410,30 @@ 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->SetScalarsData(aDataSet); aDataSet->Delete(); } @@ -433,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]), @@ -453,27 +474,30 @@ 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->SetScalarsData(aDataSet); aDataSet->Delete(); } @@ -492,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(); @@ -564,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++ ){ @@ -584,10 +607,19 @@ SMESH_DeviceActor -unsigned long int +unsigned long int SMESH_DeviceActor ::GetMTime() { + // cout << this->myExtractUnstructuredGrid + // << " " << this->Superclass::GetMTime() + // << " " << myExtractGeometry->GetMTime() + // << " " << myExtractUnstructuredGrid->GetMTime() + // << " " << myMergeFilter->GetMTime() + // << " " << myGeomFilter->GetMTime() + // << " " << myTransformFilter->GetMTime() + // << " " << myFaceOrientationFilter->GetMTime() << endl; + unsigned long mTime = this->Superclass::GetMTime(); mTime = max(mTime,myExtractGeometry->GetMTime()); mTime = max(mTime,myExtractUnstructuredGrid->GetMTime()); @@ -695,7 +727,7 @@ SMESH_DeviceActor ::UpdateFaceOrientation() { bool aShowFaceOrientation = myIsFacesOriented; - aShowFaceOrientation &= GetVisibility(); + aShowFaceOrientation &= vtkLODActor::GetVisibility(); //GetVisibility(); -- avoid calling GetUnstructuredGrid() aShowFaceOrientation &= myRepresentation == eSurface; myFaceOrientation->SetVisibility(aShowFaceOrientation); } @@ -739,8 +771,9 @@ void SMESH_DeviceActor ::SetVisibility(int theMode) { - if(!myExtractUnstructuredGrid->GetInput() || - GetUnstructuredGrid()->GetNumberOfCells()) + if(( theMode ) && + ( !myExtractUnstructuredGrid->GetInput() || + GetUnstructuredGrid()->GetNumberOfCells())) { vtkLODActor::SetVisibility(theMode); }else{ @@ -754,10 +787,12 @@ 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; } @@ -798,7 +833,7 @@ SMESH_DeviceActor { vtkDataSet* aDataSet = myMergeFilter->GetOutput(); vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID); - double* aCoord = (anID >=0) ? aDataSet->GetPoint(anID) : NULL; + double* aCoord = (anID >=0 && anID < aDataSet->GetNumberOfPoints()) ? aDataSet->GetPoint(anID) : NULL; if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<