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 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
435 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
437 aDataSet->SetCells( aCellTypesArray, aCellLocationsArray, aConnectivity );
438 SetUnstructuredGrid(aDataSet);
440 aDataSet->GetCellData()->SetScalars(aScalars);
443 theLookupTable->SetRange(aScalars->GetRange());
444 theLookupTable->Build();
446 myMergeFilter->SetScalarsData(aDataSet);
449 else if (MultiConnection2D* aMultiConnection2D = dynamic_cast<MultiConnection2D*>(theFunctor.get())){
450 SMESH::Controls::MultiConnection2D::MValues aValues;
452 aMultiConnection2D->GetValues(aValues);
453 vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
454 vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
455 aDataSet->SetPoints(aGrid->GetPoints());
457 vtkIdType aNbCells = aValues.size();
458 vtkDoubleArray *aScalars = vtkDoubleArray::New();
459 aScalars->SetNumberOfComponents(1);
460 aScalars->SetNumberOfTuples(aNbCells);
462 vtkIdType aCellsSize = 3*aNbCells;
463 vtkCellArray* aConnectivity = vtkCellArray::New();
464 aConnectivity->Allocate( aCellsSize, 0 );
466 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
467 aCellTypesArray->SetNumberOfComponents( 1 );
468 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
470 vtkIdList *anIdList = vtkIdList::New();
471 anIdList->SetNumberOfIds(2);
473 MultiConnection2D::MValues::const_iterator anIter = aValues.begin();
475 for(; anIter != aValues.end(); anIter++){
476 const MultiConnection2D::Value& aValue = (*anIter).first;
478 myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
479 myVisualObj->GetNodeVTKId(aValue.myPntId[1])
481 if(aNode[0] >= 0 && aNode[1] >= 0){
482 anIdList->SetId( 0, aNode[0] );
483 anIdList->SetId( 1, aNode[1] );
484 aConnectivity->InsertNextCell( anIdList );
485 aCellTypesArray->InsertNextValue( VTK_LINE );
486 aScalars->SetValue( aNbCells,(*anIter).second);
490 aCellTypesArray->SetNumberOfTuples( aNbCells );
491 aScalars->SetNumberOfTuples( aNbCells );
493 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
494 aCellLocationsArray->SetNumberOfComponents( 1 );
495 aCellLocationsArray->SetNumberOfTuples( aNbCells );
497 aConnectivity->InitTraversal();
498 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
499 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
501 aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
502 SetUnstructuredGrid(aDataSet);
504 aDataSet->GetCellData()->SetScalars(aScalars);
507 theLookupTable->SetRange(aScalars->GetRange());
508 theLookupTable->Build();
510 myMergeFilter->SetScalarsData(aDataSet);
514 GetMapper()->SetScalarVisibility(anIsInitialized);
515 theScalarBarActor->SetVisibility(anIsInitialized);
520 ::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor)
522 myExtractUnstructuredGrid->ClearRegisteredCells();
523 myExtractUnstructuredGrid->ClearRegisteredCellsWithType();
524 myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::ePassAll);
525 myVisualObj->UpdateFunctor(theFunctor);
527 using namespace SMESH::Controls;
528 Predicate* aPredicate = 0;
529 if (( aPredicate = dynamic_cast<FreeBorders *>(theFunctor.get())) ||
530 ( aPredicate = dynamic_cast<FreeFaces *>(theFunctor.get())) ||
531 ( aPredicate = dynamic_cast<BareBorderVolume *>(theFunctor.get())) ||
532 ( aPredicate = dynamic_cast<BareBorderFace *>(theFunctor.get())) ||
533 ( aPredicate = dynamic_cast<OverConstrainedVolume*>(theFunctor.get())) ||
534 ( aPredicate = dynamic_cast<CoincidentElements1D *>(theFunctor.get())) ||
535 ( aPredicate = dynamic_cast<CoincidentElements2D *>(theFunctor.get())) ||
536 ( aPredicate = dynamic_cast<CoincidentElements3D *>(theFunctor.get())) ||
537 ( aPredicate = dynamic_cast<OverConstrainedFace *>(theFunctor.get())))
539 myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
540 vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
541 vtkIdType aNbCells = aGrid->GetNumberOfCells();
542 for( vtkIdType i = 0; i < aNbCells; i++ ){
543 vtkIdType anObjId = myVisualObj->GetElemObjId(i);
544 if(aPredicate->IsSatisfy(anObjId))
545 myExtractUnstructuredGrid->RegisterCell(i);
547 if(!myExtractUnstructuredGrid->IsCellsRegistered())
548 myExtractUnstructuredGrid->RegisterCell(-1);
549 SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
551 else if(FreeEdges* aFreeEdges = dynamic_cast<FreeEdges*>(theFunctor.get()))
553 SMESH::Controls::FreeEdges::TBorders aBorders;
554 aFreeEdges->GetBoreders(aBorders);
555 vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
556 vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
557 aDataSet->SetPoints(aGrid->GetPoints());
559 vtkIdType aNbCells = aBorders.size();
560 vtkIdType aCellsSize = 3*aNbCells;
561 vtkCellArray* aConnectivity = vtkCellArray::New();
562 aConnectivity->Allocate( aCellsSize, 0 );
564 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
565 aCellTypesArray->SetNumberOfComponents( 1 );
566 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
568 vtkIdList *anIdList = vtkIdList::New();
569 anIdList->SetNumberOfIds(2);
571 FreeEdges::TBorders::const_iterator anIter = aBorders.begin();
572 for(; anIter != aBorders.end(); anIter++){
573 const FreeEdges::Border& aBorder = *anIter;
575 myVisualObj->GetNodeVTKId(aBorder.myPntId[0]),
576 myVisualObj->GetNodeVTKId(aBorder.myPntId[1])
578 //cout<<"aNode = "<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<endl;
579 if(aNode[0] >= 0 && aNode[1] >= 0){
580 anIdList->SetId( 0, aNode[0] );
581 anIdList->SetId( 1, aNode[1] );
582 aConnectivity->InsertNextCell( anIdList );
583 aCellTypesArray->InsertNextValue( VTK_LINE );
587 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
588 aCellLocationsArray->SetNumberOfComponents( 1 );
589 aCellLocationsArray->SetNumberOfTuples( aNbCells );
591 aConnectivity->InitTraversal();
592 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
593 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
595 aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
597 SetUnstructuredGrid(aDataSet);
600 else if (( aPredicate = dynamic_cast<FreeNodes *>(theFunctor.get())) ||
601 ( aPredicate = dynamic_cast<CoincidentNodes*>(theFunctor.get())))
603 myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
604 vtkIdType aNbNodes = myVisualObj->GetNbEntities(SMDSAbs_Node);
605 for( vtkIdType i = 0; i < aNbNodes; i++ ){
606 vtkIdType anObjId = myVisualObj->GetNodeObjId(i);
607 if(aPredicate->IsSatisfy(anObjId))
608 myExtractUnstructuredGrid->RegisterCell(i);
610 if(!myExtractUnstructuredGrid->IsCellsRegistered())
611 myExtractUnstructuredGrid->RegisterCell(-1);
612 SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
623 // cout << "DA " << this
624 // << " GF " << myGeomFilter;
625 // if ( this->Property )
626 // cout << " P " << this->Property->GetMTime();
627 // if ( this->BackfaceProperty != NULL )
628 // cout << " BP " << BackfaceProperty->GetMTime();
629 // if ( this->Texture != NULL )
630 // cout << " T " << this->Texture->GetMTime();
631 // cout << " U " << this->GetUserTransformMatrixMTime()
632 // << " M " << this->MTime.GetMTime() << endl;
634 // cout << "DA " << this
635 // << " GF " << myGeomFilter
636 // << " " << this->Superclass::GetMTime()
637 // << " " << myExtractGeometry->GetMTime()
638 // << " " << myExtractUnstructuredGrid->GetMTime()
639 // << " " << myMergeFilter->GetMTime()
640 // << " " << myGeomFilter->GetMTime()
641 // << " " << myTransformFilter->GetMTime()
642 // << " " << myFaceOrientationFilter->GetMTime() << endl;
644 vtkMTimeType mTime = this->Superclass::GetMTime();
645 mTime = max(mTime,myExtractGeometry->GetMTime());
646 mTime = max(mTime,myExtractUnstructuredGrid->GetMTime());
647 mTime = max(mTime,myMergeFilter->GetMTime());
648 mTime = max(mTime,myGeomFilter->GetMTime());
649 mTime = max(mTime,myTransformFilter->GetMTime());
650 mTime = max(mTime,myFaceOrientationFilter->GetMTime());
657 ::SetTransform(VTKViewer_Transform* theTransform)
659 myTransformFilter->SetTransform(theTransform);
667 if ( !myIsShrinkable ) return;
668 if ( vtkAlgorithmOutput* aDataSet = myPassFilter[ 0 ]->GetOutputPort() )
670 myShrinkFilter->SetInputConnection( aDataSet );
671 myPassFilter[ 1 ]->SetInputConnection( myShrinkFilter->GetOutputPort() );
680 if ( !myIsShrunk ) return;
681 if ( vtkAlgorithmOutput* aDataSet = myPassFilter[ 0 ]->GetOutputPort() )
683 myPassFilter[ 1 ]->SetInputConnection( aDataSet );
684 myPassFilter[ 1 ]->Modified();
693 ::SetFacesOriented(bool theIsFacesOriented)
695 if ( vtkAlgorithmOutput* aDataSet = myTransformFilter->GetOutputPort() )
697 myIsFacesOriented = theIsFacesOriented;
698 if( theIsFacesOriented )
699 myFaceOrientationFilter->SetInputConnection( aDataSet );
700 UpdateFaceOrientation();
706 ::SetFacesOrientationColor(double r,double g,double b)
708 myFaceOrientation->GetProperty()->SetColor( r, g, b );
713 ::GetFacesOrientationColor(double& r,double& g,double& b)
715 myFaceOrientation->GetProperty()->GetColor( r, g, b );
720 ::SetFacesOrientationScale(double theScale)
722 myFaceOrientationFilter->SetOrientationScale( theScale );
727 ::GetFacesOrientationScale()
729 return myFaceOrientationFilter->GetOrientationScale();
734 ::SetFacesOrientation3DVectors(bool theState)
736 myFaceOrientationFilter->Set3dVectors( theState );
741 ::GetFacesOrientation3DVectors()
743 return myFaceOrientationFilter->Get3dVectors();
748 ::UpdateFaceOrientation()
750 bool aShowFaceOrientation = myIsFacesOriented;
751 aShowFaceOrientation &= vtkLODActor::GetVisibility(); //GetVisibility(); -- avoid calling GetUnstructuredGrid()
752 aShowFaceOrientation &= ( myRepresentation != ePoint );
753 myFaceOrientation->SetVisibility(aShowFaceOrientation);
759 ::SetRepresentation(EReperesent theMode)
761 if ( myRepresentation == theMode )
765 myGeomFilter->SetInside(true);
766 myGeomFilter->SetWireframeMode(false);
767 GetProperty()->SetRepresentation(0);
770 myGeomFilter->SetInside(false);
771 myGeomFilter->SetWireframeMode(true);
772 GetProperty()->SetRepresentation(theMode);
775 myGeomFilter->SetInside(true);
776 myGeomFilter->SetWireframeMode(true);
777 GetProperty()->SetRepresentation(1);
780 myGeomFilter->SetInside(false);
781 myGeomFilter->SetWireframeMode(false);
782 GetProperty()->SetRepresentation(theMode);
784 SetMarkerEnabled(theMode == ePoint);
785 myRepresentation = theMode;
786 UpdateFaceOrientation();
787 GetProperty()->Modified();
788 myMapper->Modified();
795 ::SetVisibility(int theMode)
798 ( !myExtractUnstructuredGrid->GetInput() ||
799 GetUnstructuredGrid()->GetNumberOfCells()))
801 vtkLODActor::SetVisibility(theMode);
803 vtkLODActor::SetVisibility(false);
805 UpdateFaceOrientation();
813 int visibi = vtkLODActor::GetVisibility();
814 if(visibi && !GetUnstructuredGrid()->GetNumberOfCells()){
815 vtkLODActor::SetVisibility(false);
824 ::AddToRender(vtkRenderer* theRenderer)
826 theRenderer->AddActor(this);
827 theRenderer->AddActor(myFaceOrientation);
832 ::RemoveFromRender(vtkRenderer* theRenderer)
834 theRenderer->RemoveActor(this);
835 theRenderer->RemoveActor(myFaceOrientation);
841 ::GetNodeObjId(int theVtkID)
843 vtkIdType anID = theVtkID;
845 if(IsImplicitFunctionUsed())
846 anID = myExtractGeometry->GetNodeObjId(theVtkID);
848 vtkIdType aRetID = myVisualObj->GetNodeObjId(anID);
849 if(MYDEBUG) MESSAGE("GetNodeObjId - theVtkID = "<<theVtkID<<"; anID = "<<anID<<"; aRetID = "<<aRetID);
855 ::GetNodeCoord(int theObjID)
857 vtkDataSet* aDataSet = myMergeFilter->GetOutput();
858 vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID);
859 double* aCoord = (anID >=0 && anID < aDataSet->GetNumberOfPoints()) ? aDataSet->GetPoint(anID) : NULL;
860 if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<<theObjID<<"; anID = "<<anID);
866 ::GetNodeVtkId(int theObjID)
868 return myVisualObj->GetNodeVTKId(theObjID);
873 ::GetElemObjId(int theVtkID)
875 vtkIdType anId = myGeomFilter->GetElemObjId(theVtkID);
879 vtkIdType anId2 = anId;
880 if(IsImplicitFunctionUsed())
881 anId2 = myExtractGeometry->GetElemObjId(anId);
885 vtkIdType anId3 = myExtractUnstructuredGrid->GetInputId(anId2);
889 vtkIdType aRetID = myVisualObj->GetElemObjId(anId3);
891 MESSAGE("GetElemObjId - theVtkID = "<<theVtkID<<"; anId2 = "<<anId2<<"; anId3 = "<<anId3<<"; aRetID = "<<aRetID);
897 ::GetElemCell(int theObjID)
899 vtkDataSet* aDataSet = myVisualObj->GetUnstructuredGrid();
900 vtkIdType aGridID = myVisualObj->GetElemVTKId(theObjID);
901 vtkCell* aCell = (aGridID >= 0 ) ? aDataSet->GetCell(aGridID) : NULL;
903 MESSAGE("GetElemCell - theObjID = "<<theObjID<<"; aGridID = "<<aGridID);
912 return myShrinkFilter->GetShrinkFactor();
917 ::SetShrinkFactor(double theValue)
919 theValue = theValue > 0.1? theValue: 0.8;
920 myShrinkFilter->SetShrinkFactor(theValue);
927 ::SetHighlited(bool theIsHighlited)
929 if ( myIsHighlited == theIsHighlited )
931 myIsHighlited = theIsHighlited;
937 ::Render(vtkRenderer *ren, vtkMapper* m)
939 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
940 double aStoredFactor, aStoredUnit;
941 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
943 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
944 double aFactor = myPolygonOffsetFactor, aUnits = myPolygonOffsetUnits;
946 static double EPS = .01;
949 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnits);
950 vtkLODActor::Render(ren,m);
952 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
953 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
959 ::SetPolygonOffsetParameters(double factor,
962 myPolygonOffsetFactor = factor;
963 myPolygonOffsetUnits = units;
967 * On/Off representation 2D quadratic element as arked polygon
969 void SMESH_DeviceActor::SetQuadraticArcMode(bool theFlag){
970 myGeomFilter->SetQuadraticArcMode(theFlag);
974 * Return true if 2D quadratic element displayed as arked polygon
976 bool SMESH_DeviceActor::GetQuadraticArcMode(){
977 return myGeomFilter->GetQuadraticArcMode();
980 * Set Max angle for representation 2D quadratic element as arked polygon
982 void SMESH_DeviceActor::SetQuadraticArcAngle(double theMaxAngle){
983 myGeomFilter->SetQuadraticArcAngle(theMaxAngle);
987 * Return Max angle of the representation 2D quadratic element as arked polygon
989 double SMESH_DeviceActor::GetQuadraticArcAngle(){
990 return myGeomFilter->GetQuadraticArcAngle();
994 * Set point marker enabled
995 * \param theMarkerEnabled flag to enable/disable point marker
997 void SMESH_DeviceActor::SetMarkerEnabled( bool theMarkerEnabled )
999 myMapper->SetMarkerEnabled( theMarkerEnabled );
1003 * Set point marker enabled
1004 * \param theBallEnabled flag to enable/disable ball drawing
1006 void SMESH_DeviceActor::SetBallEnabled( bool theBallEnabled ) {
1007 myMapper->SetBallEnabled( theBallEnabled );
1011 * Set point marker scale factor
1012 * \param theBallScale double value which specifies a scale factor of ball element
1014 void SMESH_DeviceActor::SetBallScale( double theBallScale )
1016 myMapper->SetBallScale( theBallScale );
1017 myMapper->Modified();
1021 * Set standard point marker
1022 * \param theMarkerType type of the marker
1024 void SMESH_DeviceActor::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
1026 myMapper->SetMarkerStd( theMarkerType, theMarkerScale );
1030 * Set custom point marker
1031 * \param theMarkerId id of the marker texture
1032 * \param theMarkerTexture marker texture
1034 void SMESH_DeviceActor::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
1036 myMapper->SetMarkerTexture( theMarkerId, theMarkerTexture );
1040 * Get type of the point marker
1041 * \return type of the point marker
1043 VTK::MarkerType SMESH_DeviceActor::GetMarkerType()
1045 return myMapper->GetMarkerType();
1049 Get scale of the point marker
1050 \return scale of the point marker
1052 VTK::MarkerScale SMESH_DeviceActor::GetMarkerScale()
1054 return myMapper->GetMarkerScale();
1058 * Get texture identifier of the point marker
1059 * \return texture identifier of the point marker
1061 int SMESH_DeviceActor::GetMarkerTexture()
1063 return myMapper->GetMarkerTexture();
1067 * Get scale factor of ball element
1068 * \return scale factor of ball element
1070 double SMESH_DeviceActor::GetBallScale()
1072 return myMapper->GetBallScale();
1075 void SMESH_DeviceActor::SetCoincident3DAllowed(bool theFlag) {
1076 myGeomFilter->SetAppendCoincident3D(theFlag);
1079 bool SMESH_DeviceActor::IsCoincident3DAllowed() const {
1080 return myGeomFilter->GetAppendCoincident3D();