1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH OBJECT : interactive object for SMESH visualization
24 // File : SMESH_DeviceActor.cxx
28 #include "SMESH_DeviceActor.h"
29 #include "SMESH_ScalarBarActor.h"
30 #include "SMESH_ExtractGeometry.h"
31 #include "SMESH_ControlsDef.hxx"
32 #include "SMESH_ActorUtils.h"
33 #include "SMESH_FaceOrientationFilter.h"
34 #include "VTKViewer_CellLocationsArray.h"
35 #include "VTKViewer_PolyDataMapper.h"
37 #include <VTKViewer_Transform.h>
38 #include <VTKViewer_TransformFilter.h>
39 #include <VTKViewer_ExtractUnstructuredGrid.h>
40 #include <VTKViewer_Actor.h>
43 #include <vtkObjectFactory.h>
44 #include <vtkShrinkFilter.h>
45 #include <vtkShrinkPolyData.h>
47 #include <vtkProperty.h>
48 #include <vtkPolyData.h>
49 #include <vtkMergeFilter.h>
50 #include <vtkPolyDataMapper.h>
51 #include <vtkUnstructuredGrid.h>
53 #include <vtkLookupTable.h>
54 #include <vtkDoubleArray.h>
55 #include <vtkCellData.h>
58 #include <vtkIdList.h>
59 #include <vtkCellArray.h>
60 #include <vtkUnsignedCharArray.h>
62 #include <vtkImplicitBoolean.h>
63 #include <vtkPassThroughFilter.h>
65 #include <vtkRenderer.h>
67 #include <vtkPlaneCollection.h>
69 #include "utilities.h"
72 static int MYDEBUG = 0;
74 static int MYDEBUG = 0;
80 vtkStandardNewMacro(SMESH_DeviceActor);
86 if(MYDEBUG) MESSAGE("SMESH_DeviceActor - "<<this);
88 myIsShrinkable = false;
90 myIsHighlited = false;
92 myRepresentation = SMESH_DeviceActor::EReperesent(-1);
94 myProperty = vtkProperty::New();
95 myMapper = VTKViewer_PolyDataMapper::New();
96 myPlaneCollection = vtkPlaneCollection::New();
98 VTKViewer_Actor::GetDefaultPolygonOffsetParameters(myPolygonOffsetFactor,
99 myPolygonOffsetUnits);
101 myMapper->UseLookupTableScalarRangeOn();
102 myMapper->SetColorModeToMapScalars();
104 myShrinkFilter = vtkShrinkFilter::New();
106 myStoreClippingMapping = false;
108 myExtractGeometry = SMESH_ExtractGeometry::New();
109 myExtractGeometry->SetReleaseDataFlag(true);
110 myIsImplicitFunctionUsed = false;
112 myExtractUnstructuredGrid = VTKViewer_ExtractUnstructuredGrid::New();
114 myMergeFilter = vtkMergeFilter::New();
116 myGeomFilter = VTKViewer_GeometryFilter::New();
118 myTransformFilter = VTKViewer_TransformFilter::New();
120 for(int i = 0; i < 6; i++)
121 myPassFilter.push_back(vtkPassThroughFilter::New());
123 // Orientation of faces
124 myIsFacesOriented = false;
126 double anRGB[3] = { 1, 1, 1 };
127 SMESH::GetColor( "SMESH", "orientation_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
129 myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
131 myFaceOrientationDataMapper = vtkPolyDataMapper::New();
132 myFaceOrientationDataMapper->SetInputConnection(myFaceOrientationFilter->GetOutputPort());
134 myFaceOrientation = vtkActor::New();
135 myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
136 myFaceOrientation->GetProperty()->SetColor(anRGB[0], anRGB[1], anRGB[2]);
141 ::~SMESH_DeviceActor()
143 if(MYDEBUG) MESSAGE("~SMESH_DeviceActor - "<<this);
146 // myPlaneCollection->Delete(); -- it is vtkSmartPointer
147 myProperty->Delete();
149 myExtractGeometry->Delete();
151 myMergeFilter->Delete();
152 myExtractUnstructuredGrid->Delete();
154 // Orientation of faces
155 myFaceOrientationFilter->Delete();
156 myFaceOrientationDataMapper->RemoveAllInputs();
157 myFaceOrientationDataMapper->Delete();
158 myFaceOrientation->Delete();
160 myGeomFilter->Delete();
162 myTransformFilter->Delete();
164 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
165 myPassFilter[i]->Delete();
167 myShrinkFilter->Delete();
173 ::SetStoreGemetryMapping(bool theStoreMapping)
175 myGeomFilter->SetStoreMapping(theStoreMapping);
176 // for optimization, switch the mapping explicitly in each filter/algorithm
177 //SetStoreClippingMapping(theStoreMapping);
183 ::SetStoreClippingMapping(bool theStoreMapping)
185 myStoreClippingMapping = theStoreMapping;
186 myExtractGeometry->SetStoreMapping(theStoreMapping && myIsImplicitFunctionUsed);
188 // Mapping in myExtractUnstructuredGrid and myGeomFilter is ON in the pickable DeviceActor only.
189 // To show labels, the mapping is computed explicitly via myExtractUnstructuredGrid->BuildOut2InMap();
190 //SetStoreIDMapping(theStoreMapping);
196 ::SetStoreIDMapping(bool theStoreMapping)
198 myExtractUnstructuredGrid->SetStoreMapping(theStoreMapping);
204 ::Init(TVisualObjPtr theVisualObj,
205 vtkImplicitBoolean* theImplicitBoolean)
207 myVisualObj = theVisualObj;
208 myExtractGeometry->SetImplicitFunction(theImplicitBoolean);
209 SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
214 ::SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
217 if(theIsImplicitFunctionUsed)
218 myPassFilter[ anId ]->SetInputConnection( myExtractGeometry->GetOutputPort() );
220 myPassFilter[ anId ]->SetInputConnection( myMergeFilter->GetOutputPort() );
222 myIsImplicitFunctionUsed = theIsImplicitFunctionUsed;
223 SetStoreClippingMapping(myStoreClippingMapping);
229 ::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid)
231 myExtractUnstructuredGrid->SetInputData(theGrid);
235 myIsShrinkable = true;
237 myMergeFilter->SetGeometryConnection(myExtractUnstructuredGrid->GetOutputPort());
239 //Pass diameters of the balls
240 if(myMapper->GetBallEnabled()) {
241 myMergeFilter->SetScalarsConnection(myExtractUnstructuredGrid->GetOutputPort());
244 myExtractGeometry->SetInputConnection(myMergeFilter->GetOutputPort());
247 SetImplicitFunctionUsed(myIsImplicitFunctionUsed);
248 myPassFilter[ anId + 1]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
251 myTransformFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
254 myPassFilter[ anId ]->SetInputConnection( myTransformFilter->GetOutputPort() );
255 myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
258 myGeomFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
261 myPassFilter[ anId ]->SetInputConnection( myGeomFilter->GetOutputPort() );
262 myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
265 myMapper->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
266 if( myPlaneCollection->GetNumberOfItems() )
267 myMapper->SetClippingPlanes( myPlaneCollection );
269 vtkLODActor::SetMapper( myMapper );
276 ::SetPlaneCollection( vtkPlaneCollection* theCollection )
278 myPlaneCollection = theCollection;
281 VTKViewer_ExtractUnstructuredGrid*
283 ::GetExtractUnstructuredGrid()
285 return myExtractUnstructuredGrid;
288 #include "SMDS_Mesh.hxx"
292 ::GetUnstructuredGrid()
294 myExtractUnstructuredGrid->Update();
295 return myExtractUnstructuredGrid->GetOutput();
301 ::SetControlMode(SMESH::Controls::FunctorPtr theFunctor,
302 SMESH_ScalarBarActor* theScalarBarActor,
303 vtkLookupTable* theLookupTable)
305 bool anIsInitialized = theFunctor != NULL;
307 vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
309 // SetStoreIDMapping(true);
310 myExtractUnstructuredGrid->Update();
311 vtkUnstructuredGrid* aGrid = myExtractUnstructuredGrid->GetOutput();
313 aDataSet->ShallowCopy(aGrid);
315 vtkDoubleArray *aScalars = vtkDoubleArray::New();
316 vtkIdType aNbCells = aGrid->GetNumberOfCells();
317 aScalars->SetNumberOfComponents(1);
318 aScalars->SetNumberOfTuples(aNbCells);
319 double* range = 0;// = aScalars->GetRange();
321 myVisualObj->UpdateFunctor(theFunctor);
323 using namespace SMESH::Controls;
324 if(NumericalFunctor* aNumericalFunctor = dynamic_cast<NumericalFunctor*>(theFunctor.get()))
326 myExtractUnstructuredGrid->BuildOut2InMap();
327 for(vtkIdType i = 0; i < aNbCells; i++)
329 vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
330 vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
331 double aValue = aNumericalFunctor->GetValue(anObjId);
332 aScalars->SetValue(i,aValue);
334 range = aScalars->GetRange();
335 if ( range[1] - range[0] < ( qMax(qAbs(range[0]),qAbs(range[1])) + 1e-100 ) * 1e-6 )
338 for(vtkIdType i = 0; i < aNbCells; i++)
339 aScalars->SetValue(i,range[0]);
342 else if(Predicate* aPredicate = dynamic_cast<Predicate*>(theFunctor.get()))
344 myExtractUnstructuredGrid->BuildOut2InMap();
345 for(vtkIdType i = 0; i < aNbCells; i++)
347 vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
348 vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
349 bool aValue = aPredicate->IsSatisfy(anObjId);
350 aScalars->SetValue(i,aValue);
352 range = aScalars->GetRange();
355 aDataSet->GetCellData()->SetScalars(aScalars);
358 theLookupTable->SetRange( range );
359 theLookupTable->SetNumberOfTableValues(theScalarBarActor->GetMaximumNumberOfColors());
360 theLookupTable->Build();
362 myMergeFilter->SetScalarsData(aDataSet);
365 GetMapper()->SetScalarVisibility(anIsInitialized);
366 theScalarBarActor->SetVisibility(anIsInitialized);
371 ::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor,
372 SMESH_ScalarBarActor* theScalarBarActor,
373 vtkLookupTable* theLookupTable)
375 bool anIsInitialized = theFunctor != NULL;
376 myExtractUnstructuredGrid->ClearRegisteredCells();
377 myExtractUnstructuredGrid->ClearRegisteredCellsWithType();
378 myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::ePassAll);
379 myVisualObj->UpdateFunctor(theFunctor);
381 using namespace SMESH::Controls;
382 if (anIsInitialized){
383 if (Length2D* aLength2D = dynamic_cast<Length2D*>(theFunctor.get())){
384 SMESH::Controls::Length2D::TValues aValues;
386 aLength2D->GetValues(aValues);
387 vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
388 vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
390 aDataSet->SetPoints(aGrid->GetPoints());
392 vtkIdType aNbCells = aValues.size();
394 vtkDoubleArray *aScalars = vtkDoubleArray::New();
395 aScalars->SetNumberOfComponents(1);
396 aScalars->SetNumberOfTuples(aNbCells);
398 vtkIdType aCellsSize = 3*aNbCells;
399 vtkCellArray* aConnectivity = vtkCellArray::New();
400 aConnectivity->Allocate( aCellsSize, 0 );
402 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
403 aCellTypesArray->SetNumberOfComponents( 1 );
404 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
406 vtkIdList *anIdList = vtkIdList::New();
407 anIdList->SetNumberOfIds(2);
409 Length2D::TValues::const_iterator anIter = aValues.begin();
411 for(; anIter != aValues.end(); anIter++){
412 const Length2D::Value& aValue = *anIter;
414 myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
415 myVisualObj->GetNodeVTKId(aValue.myPntId[1])
417 if(aNode[0] >= 0 && aNode[1] >= 0){
418 anIdList->SetId( 0, aNode[0] );
419 anIdList->SetId( 1, aNode[1] );
420 aConnectivity->InsertNextCell( anIdList );
421 aCellTypesArray->InsertNextValue( VTK_LINE );
422 aScalars->SetValue(aNbCells,aValue.myLength);
426 aCellTypesArray->SetNumberOfTuples( aNbCells );
427 aScalars->SetNumberOfTuples( aNbCells );
429 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
430 aCellLocationsArray->SetNumberOfComponents( 1 );
431 aCellLocationsArray->SetNumberOfTuples( aNbCells );
433 aConnectivity->InitTraversal();
434 vtkIdType const *pts(nullptr);
435 for( vtkIdType idType = 0, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
436 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
438 aDataSet->SetCells( aCellTypesArray, aCellLocationsArray, aConnectivity );
439 SetUnstructuredGrid(aDataSet);
441 aDataSet->GetCellData()->SetScalars(aScalars);
444 theLookupTable->SetRange(aScalars->GetRange());
445 theLookupTable->Build();
447 myMergeFilter->SetScalarsData(aDataSet);
450 else if (MultiConnection2D* aMultiConnection2D = dynamic_cast<MultiConnection2D*>(theFunctor.get())){
451 SMESH::Controls::MultiConnection2D::MValues aValues;
453 aMultiConnection2D->GetValues(aValues);
454 vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
455 vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
456 aDataSet->SetPoints(aGrid->GetPoints());
458 vtkIdType aNbCells = aValues.size();
459 vtkDoubleArray *aScalars = vtkDoubleArray::New();
460 aScalars->SetNumberOfComponents(1);
461 aScalars->SetNumberOfTuples(aNbCells);
463 vtkIdType aCellsSize = 3*aNbCells;
464 vtkCellArray* aConnectivity = vtkCellArray::New();
465 aConnectivity->Allocate( aCellsSize, 0 );
467 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
468 aCellTypesArray->SetNumberOfComponents( 1 );
469 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
471 vtkIdList *anIdList = vtkIdList::New();
472 anIdList->SetNumberOfIds(2);
474 MultiConnection2D::MValues::const_iterator anIter = aValues.begin();
476 for(; anIter != aValues.end(); anIter++){
477 const MultiConnection2D::Value& aValue = (*anIter).first;
479 myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
480 myVisualObj->GetNodeVTKId(aValue.myPntId[1])
482 if(aNode[0] >= 0 && aNode[1] >= 0){
483 anIdList->SetId( 0, aNode[0] );
484 anIdList->SetId( 1, aNode[1] );
485 aConnectivity->InsertNextCell( anIdList );
486 aCellTypesArray->InsertNextValue( VTK_LINE );
487 aScalars->SetValue( aNbCells,(*anIter).second);
491 aCellTypesArray->SetNumberOfTuples( aNbCells );
492 aScalars->SetNumberOfTuples( aNbCells );
494 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
495 aCellLocationsArray->SetNumberOfComponents( 1 );
496 aCellLocationsArray->SetNumberOfTuples( aNbCells );
498 aConnectivity->InitTraversal();
499 vtkIdType const *pts(nullptr);
500 for( vtkIdType idType = 0, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
501 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
503 aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
504 SetUnstructuredGrid(aDataSet);
506 aDataSet->GetCellData()->SetScalars(aScalars);
509 theLookupTable->SetRange(aScalars->GetRange());
510 theLookupTable->Build();
512 myMergeFilter->SetScalarsData(aDataSet);
516 GetMapper()->SetScalarVisibility(anIsInitialized);
517 theScalarBarActor->SetVisibility(anIsInitialized);
522 ::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor)
524 myExtractUnstructuredGrid->ClearRegisteredCells();
525 myExtractUnstructuredGrid->ClearRegisteredCellsWithType();
526 myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::ePassAll);
527 myVisualObj->UpdateFunctor(theFunctor);
529 using namespace SMESH::Controls;
530 Predicate* aPredicate = 0;
531 if (( aPredicate = dynamic_cast<FreeBorders *>(theFunctor.get())) ||
532 ( aPredicate = dynamic_cast<FreeFaces *>(theFunctor.get())) ||
533 ( aPredicate = dynamic_cast<BareBorderVolume *>(theFunctor.get())) ||
534 ( aPredicate = dynamic_cast<BareBorderFace *>(theFunctor.get())) ||
535 ( aPredicate = dynamic_cast<OverConstrainedVolume*>(theFunctor.get())) ||
536 ( aPredicate = dynamic_cast<CoincidentElements1D *>(theFunctor.get())) ||
537 ( aPredicate = dynamic_cast<CoincidentElements2D *>(theFunctor.get())) ||
538 ( aPredicate = dynamic_cast<CoincidentElements3D *>(theFunctor.get())) ||
539 ( aPredicate = dynamic_cast<OverConstrainedFace *>(theFunctor.get())))
541 myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
542 vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
543 vtkIdType aNbCells = aGrid->GetNumberOfCells();
544 for( vtkIdType i = 0; i < aNbCells; i++ ){
545 vtkIdType anObjId = myVisualObj->GetElemObjId(i);
546 if(aPredicate->IsSatisfy(anObjId))
547 myExtractUnstructuredGrid->RegisterCell(i);
549 if(!myExtractUnstructuredGrid->IsCellsRegistered())
550 myExtractUnstructuredGrid->RegisterCell(-1);
551 SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
553 else if(FreeEdges* aFreeEdges = dynamic_cast<FreeEdges*>(theFunctor.get()))
555 SMESH::Controls::FreeEdges::TBorders aBorders;
556 aFreeEdges->GetBoreders(aBorders);
557 vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
558 vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
559 aDataSet->SetPoints(aGrid->GetPoints());
561 vtkIdType aNbCells = aBorders.size();
562 vtkIdType aCellsSize = 3*aNbCells;
563 vtkCellArray* aConnectivity = vtkCellArray::New();
564 aConnectivity->Allocate( aCellsSize, 0 );
566 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
567 aCellTypesArray->SetNumberOfComponents( 1 );
568 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
570 vtkIdList *anIdList = vtkIdList::New();
571 anIdList->SetNumberOfIds(2);
573 FreeEdges::TBorders::const_iterator anIter = aBorders.begin();
574 for(; anIter != aBorders.end(); anIter++){
575 const FreeEdges::Border& aBorder = *anIter;
577 myVisualObj->GetNodeVTKId(aBorder.myPntId[0]),
578 myVisualObj->GetNodeVTKId(aBorder.myPntId[1])
580 //cout<<"aNode = "<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<endl;
581 if(aNode[0] >= 0 && aNode[1] >= 0){
582 anIdList->SetId( 0, aNode[0] );
583 anIdList->SetId( 1, aNode[1] );
584 aConnectivity->InsertNextCell( anIdList );
585 aCellTypesArray->InsertNextValue( VTK_LINE );
589 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
590 aCellLocationsArray->SetNumberOfComponents( 1 );
591 aCellLocationsArray->SetNumberOfTuples( aNbCells );
593 aConnectivity->InitTraversal();
594 vtkIdType const *pts(nullptr);
595 for( vtkIdType idType = 0, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
596 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
598 aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
600 SetUnstructuredGrid(aDataSet);
603 else if (( aPredicate = dynamic_cast<FreeNodes *>(theFunctor.get())) ||
604 ( aPredicate = dynamic_cast<CoincidentNodes*>(theFunctor.get())))
606 myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
607 vtkIdType aNbNodes = myVisualObj->GetNbEntities(SMDSAbs_Node);
608 for( vtkIdType i = 0; i < aNbNodes; i++ ){
609 vtkIdType anObjId = myVisualObj->GetNodeObjId(i);
610 if(aPredicate->IsSatisfy(anObjId))
611 myExtractUnstructuredGrid->RegisterCell(i);
613 if(!myExtractUnstructuredGrid->IsCellsRegistered())
614 myExtractUnstructuredGrid->RegisterCell(-1);
615 SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
626 // cout << "DA " << this
627 // << " GF " << myGeomFilter;
628 // if ( this->Property )
629 // cout << " P " << this->Property->GetMTime();
630 // if ( this->BackfaceProperty != NULL )
631 // cout << " BP " << BackfaceProperty->GetMTime();
632 // if ( this->Texture != NULL )
633 // cout << " T " << this->Texture->GetMTime();
634 // cout << " U " << this->GetUserTransformMatrixMTime()
635 // << " M " << this->MTime.GetMTime() << endl;
637 // cout << "DA " << this
638 // << " GF " << myGeomFilter
639 // << " " << this->Superclass::GetMTime()
640 // << " " << myExtractGeometry->GetMTime()
641 // << " " << myExtractUnstructuredGrid->GetMTime()
642 // << " " << myMergeFilter->GetMTime()
643 // << " " << myGeomFilter->GetMTime()
644 // << " " << myTransformFilter->GetMTime()
645 // << " " << myFaceOrientationFilter->GetMTime() << endl;
647 vtkMTimeType mTime = this->Superclass::GetMTime();
648 mTime = max(mTime,myExtractGeometry->GetMTime());
649 mTime = max(mTime,myExtractUnstructuredGrid->GetMTime());
650 mTime = max(mTime,myMergeFilter->GetMTime());
651 mTime = max(mTime,myGeomFilter->GetMTime());
652 mTime = max(mTime,myTransformFilter->GetMTime());
653 mTime = max(mTime,myFaceOrientationFilter->GetMTime());
660 ::SetTransform(VTKViewer_Transform* theTransform)
662 myTransformFilter->SetTransform(theTransform);
670 if ( !myIsShrinkable ) return;
671 if ( vtkAlgorithmOutput* aDataSet = myPassFilter[ 0 ]->GetOutputPort() )
673 myShrinkFilter->SetInputConnection( aDataSet );
674 myPassFilter[ 1 ]->SetInputConnection( myShrinkFilter->GetOutputPort() );
683 if ( !myIsShrunk ) return;
684 if ( vtkAlgorithmOutput* aDataSet = myPassFilter[ 0 ]->GetOutputPort() )
686 myPassFilter[ 1 ]->SetInputConnection( aDataSet );
687 myPassFilter[ 1 ]->Modified();
696 ::SetFacesOriented(bool theIsFacesOriented)
698 if ( vtkAlgorithmOutput* aDataSet = myTransformFilter->GetOutputPort() )
700 myIsFacesOriented = theIsFacesOriented;
701 if( theIsFacesOriented )
702 myFaceOrientationFilter->SetInputConnection( aDataSet );
703 UpdateFaceOrientation();
709 ::SetFacesOrientationColor(double r,double g,double b)
711 myFaceOrientation->GetProperty()->SetColor( r, g, b );
716 ::GetFacesOrientationColor(double& r,double& g,double& b)
718 myFaceOrientation->GetProperty()->GetColor( r, g, b );
723 ::SetFacesOrientationScale(double theScale)
725 myFaceOrientationFilter->SetOrientationScale( theScale );
730 ::GetFacesOrientationScale()
732 return myFaceOrientationFilter->GetOrientationScale();
737 ::SetFacesOrientation3DVectors(bool theState)
739 myFaceOrientationFilter->Set3dVectors( theState );
744 ::GetFacesOrientation3DVectors()
746 return myFaceOrientationFilter->Get3dVectors();
751 ::UpdateFaceOrientation()
753 bool aShowFaceOrientation = myIsFacesOriented;
754 aShowFaceOrientation &= vtkLODActor::GetVisibility(); //GetVisibility(); -- avoid calling GetUnstructuredGrid()
755 aShowFaceOrientation &= ( myRepresentation != ePoint );
756 myFaceOrientation->SetVisibility(aShowFaceOrientation);
762 ::SetRepresentation(EReperesent theMode)
764 if ( myRepresentation == theMode )
768 myGeomFilter->SetInside(true);
769 myGeomFilter->SetWireframeMode(false);
770 GetProperty()->SetRepresentation(0);
773 myGeomFilter->SetInside(false);
774 myGeomFilter->SetWireframeMode(true);
775 GetProperty()->SetRepresentation(theMode);
778 myGeomFilter->SetInside(true);
779 myGeomFilter->SetWireframeMode(true);
780 GetProperty()->SetRepresentation(1);
783 myGeomFilter->SetInside(false);
784 myGeomFilter->SetWireframeMode(false);
785 GetProperty()->SetRepresentation(theMode);
787 SetMarkerEnabled(theMode == ePoint);
788 myRepresentation = theMode;
789 UpdateFaceOrientation();
790 GetProperty()->Modified();
791 myMapper->Modified();
798 ::SetVisibility(int theMode)
801 ( !myExtractUnstructuredGrid->GetInput() ||
802 GetUnstructuredGrid()->GetNumberOfCells()))
804 vtkLODActor::SetVisibility(theMode);
806 vtkLODActor::SetVisibility(false);
808 UpdateFaceOrientation();
816 int visibi = vtkLODActor::GetVisibility();
817 if(visibi && !GetUnstructuredGrid()->GetNumberOfCells()){
818 vtkLODActor::SetVisibility(false);
827 ::AddToRender(vtkRenderer* theRenderer)
829 theRenderer->AddActor(this);
830 theRenderer->AddActor(myFaceOrientation);
835 ::RemoveFromRender(vtkRenderer* theRenderer)
837 theRenderer->RemoveActor(this);
838 theRenderer->RemoveActor(myFaceOrientation);
844 ::GetNodeObjId(int theVtkID)
846 vtkIdType anID = theVtkID;
848 if(IsImplicitFunctionUsed())
849 anID = myExtractGeometry->GetNodeObjId(theVtkID);
851 vtkIdType aRetID = myVisualObj->GetNodeObjId(anID);
852 if(MYDEBUG) MESSAGE("GetNodeObjId - theVtkID = "<<theVtkID<<"; anID = "<<anID<<"; aRetID = "<<aRetID);
858 ::GetNodeCoord(int theObjID)
860 vtkDataSet* aDataSet = myMergeFilter->GetOutput();
861 vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID);
862 double* aCoord = (anID >=0 && anID < aDataSet->GetNumberOfPoints()) ? aDataSet->GetPoint(anID) : NULL;
863 if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<<theObjID<<"; anID = "<<anID);
869 ::GetNodeVtkId(int theObjID)
871 return myVisualObj->GetNodeVTKId(theObjID);
876 ::GetElemObjId(int theVtkID)
878 vtkIdType anId = myGeomFilter->GetElemObjId(theVtkID);
882 vtkIdType anId2 = anId;
883 if(IsImplicitFunctionUsed())
884 anId2 = myExtractGeometry->GetElemObjId(anId);
888 vtkIdType anId3 = myExtractUnstructuredGrid->GetInputId(anId2);
892 vtkIdType aRetID = myVisualObj->GetElemObjId(anId3);
894 MESSAGE("GetElemObjId - theVtkID = "<<theVtkID<<"; anId2 = "<<anId2<<"; anId3 = "<<anId3<<"; aRetID = "<<aRetID);
900 ::GetElemCell(int theObjID)
902 vtkDataSet* aDataSet = myVisualObj->GetUnstructuredGrid();
903 vtkIdType aGridID = myVisualObj->GetElemVTKId(theObjID);
904 vtkCell* aCell = (aGridID >= 0 ) ? aDataSet->GetCell(aGridID) : NULL;
906 MESSAGE("GetElemCell - theObjID = "<<theObjID<<"; aGridID = "<<aGridID);
915 return myShrinkFilter->GetShrinkFactor();
920 ::SetShrinkFactor(double theValue)
922 theValue = theValue > 0.1? theValue: 0.8;
923 myShrinkFilter->SetShrinkFactor(theValue);
930 ::SetHighlited(bool theIsHighlited)
932 if ( myIsHighlited == theIsHighlited )
934 myIsHighlited = theIsHighlited;
940 ::Render(vtkRenderer *ren, vtkMapper* m)
942 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
943 double aStoredFactor, aStoredUnit;
944 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
946 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
947 double aFactor = myPolygonOffsetFactor, aUnits = myPolygonOffsetUnits;
949 static double EPS = .01;
952 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnits);
953 vtkLODActor::Render(ren,m);
955 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
956 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
962 ::SetPolygonOffsetParameters(double factor,
965 myPolygonOffsetFactor = factor;
966 myPolygonOffsetUnits = units;
970 * On/Off representation 2D quadratic element as arked polygon
972 void SMESH_DeviceActor::SetQuadraticArcMode(bool theFlag){
973 myGeomFilter->SetQuadraticArcMode(theFlag);
977 * Return true if 2D quadratic element displayed as arked polygon
979 bool SMESH_DeviceActor::GetQuadraticArcMode(){
980 return myGeomFilter->GetQuadraticArcMode();
983 * Set Max angle for representation 2D quadratic element as arked polygon
985 void SMESH_DeviceActor::SetQuadraticArcAngle(double theMaxAngle){
986 myGeomFilter->SetQuadraticArcAngle(theMaxAngle);
990 * Return Max angle of the representation 2D quadratic element as arked polygon
992 double SMESH_DeviceActor::GetQuadraticArcAngle(){
993 return myGeomFilter->GetQuadraticArcAngle();
997 * Set point marker enabled
998 * \param theMarkerEnabled flag to enable/disable point marker
1000 void SMESH_DeviceActor::SetMarkerEnabled( bool theMarkerEnabled )
1002 myMapper->SetMarkerEnabled( theMarkerEnabled );
1006 * Set point marker enabled
1007 * \param theBallEnabled flag to enable/disable ball drawing
1009 void SMESH_DeviceActor::SetBallEnabled( bool theBallEnabled ) {
1010 myMapper->SetBallEnabled( theBallEnabled );
1014 * Set point marker scale factor
1015 * \param theBallScale double value which specifies a scale factor of ball element
1017 void SMESH_DeviceActor::SetBallScale( double theBallScale )
1019 myMapper->SetBallScale( theBallScale );
1020 myMapper->Modified();
1024 * Set standard point marker
1025 * \param theMarkerType type of the marker
1027 void SMESH_DeviceActor::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
1029 myMapper->SetMarkerStd( theMarkerType, theMarkerScale );
1033 * Set custom point marker
1034 * \param theMarkerId id of the marker texture
1035 * \param theMarkerTexture marker texture
1037 void SMESH_DeviceActor::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
1039 myMapper->SetMarkerTexture( theMarkerId, theMarkerTexture );
1043 * Get type of the point marker
1044 * \return type of the point marker
1046 VTK::MarkerType SMESH_DeviceActor::GetMarkerType()
1048 return myMapper->GetMarkerType();
1052 Get scale of the point marker
1053 \return scale of the point marker
1055 VTK::MarkerScale SMESH_DeviceActor::GetMarkerScale()
1057 return myMapper->GetMarkerScale();
1061 * Get texture identifier of the point marker
1062 * \return texture identifier of the point marker
1064 int SMESH_DeviceActor::GetMarkerTexture()
1066 return myMapper->GetMarkerTexture();
1070 * Get scale factor of ball element
1071 * \return scale factor of ball element
1073 double SMESH_DeviceActor::GetBallScale()
1075 return myMapper->GetBallScale();
1078 void SMESH_DeviceActor::SetCoincident3DAllowed(bool theFlag) {
1079 myGeomFilter->SetAppendCoincident3D(theFlag);
1082 bool SMESH_DeviceActor::IsCoincident3DAllowed() const {
1083 return myGeomFilter->GetAppendCoincident3D();