1 // Copyright (C) 2007-2016 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>
42 #include <vtkObjectFactory.h>
43 #include <vtkShrinkFilter.h>
44 #include <vtkShrinkPolyData.h>
46 #include <vtkProperty.h>
47 #include <vtkPolyData.h>
48 #include <vtkMergeFilter.h>
49 #include <vtkPolyDataMapper.h>
50 #include <vtkUnstructuredGrid.h>
52 #include <vtkLookupTable.h>
53 #include <vtkDoubleArray.h>
54 #include <vtkCellData.h>
57 #include <vtkIdList.h>
58 #include <vtkCellArray.h>
59 #include <vtkUnsignedCharArray.h>
61 #include <vtkImplicitBoolean.h>
62 #include <vtkPassThroughFilter.h>
64 #include <vtkRenderer.h>
66 #include <vtkPlaneCollection.h>
68 #include "utilities.h"
71 static int MYDEBUG = 0;
73 static int MYDEBUG = 0;
79 vtkStandardNewMacro(SMESH_DeviceActor);
85 if(MYDEBUG) MESSAGE("SMESH_DeviceActor - "<<this);
87 myIsShrinkable = false;
89 myIsHighlited = false;
91 myRepresentation = SMESH_DeviceActor::EReperesent(-1);
93 myProperty = vtkProperty::New();
94 myMapper = VTKViewer_PolyDataMapper::New();
95 myPlaneCollection = vtkPlaneCollection::New();
97 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
98 myPolygonOffsetUnits);
100 myMapper->UseLookupTableScalarRangeOn();
101 myMapper->SetColorModeToMapScalars();
103 myShrinkFilter = vtkShrinkFilter::New();
105 myStoreClippingMapping = false;
107 myExtractGeometry = SMESH_ExtractGeometry::New();
108 myExtractGeometry->SetReleaseDataFlag(true);
109 myIsImplicitFunctionUsed = false;
111 myExtractUnstructuredGrid = VTKViewer_ExtractUnstructuredGrid::New();
113 myMergeFilter = vtkMergeFilter::New();
115 myGeomFilter = VTKViewer_GeometryFilter::New();
117 myTransformFilter = VTKViewer_TransformFilter::New();
119 for(int i = 0; i < 6; i++)
120 myPassFilter.push_back(vtkPassThroughFilter::New());
122 // Orientation of faces
123 myIsFacesOriented = false;
125 double anRGB[3] = { 1, 1, 1 };
126 SMESH::GetColor( "SMESH", "orientation_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
128 myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
130 myFaceOrientationDataMapper = vtkPolyDataMapper::New();
131 myFaceOrientationDataMapper->SetInputConnection(myFaceOrientationFilter->GetOutputPort());
133 myFaceOrientation = vtkActor::New();
134 myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
135 myFaceOrientation->GetProperty()->SetColor(anRGB[0], anRGB[1], anRGB[2]);
140 ::~SMESH_DeviceActor()
142 if(MYDEBUG) MESSAGE("~SMESH_DeviceActor - "<<this);
145 // myPlaneCollection->Delete(); -- it is vtkSmartPointer
146 myProperty->Delete();
148 myExtractGeometry->Delete();
150 myMergeFilter->Delete();
151 myExtractUnstructuredGrid->Delete();
153 // Orientation of faces
154 myFaceOrientationFilter->Delete();
155 myFaceOrientationDataMapper->RemoveAllInputs();
156 myFaceOrientationDataMapper->Delete();
157 myFaceOrientation->Delete();
159 myGeomFilter->Delete();
161 myTransformFilter->Delete();
163 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
164 myPassFilter[i]->Delete();
166 myShrinkFilter->Delete();
172 ::SetStoreGemetryMapping(bool theStoreMapping)
174 myGeomFilter->SetStoreMapping(theStoreMapping);
175 // for optimization, switch the mapping explicitly in each filter/algorithm
176 //SetStoreClippingMapping(theStoreMapping);
182 ::SetStoreClippingMapping(bool theStoreMapping)
184 myStoreClippingMapping = theStoreMapping;
185 myExtractGeometry->SetStoreMapping(theStoreMapping && myIsImplicitFunctionUsed);
187 // Mapping in myExtractUnstructuredGrid and myGeomFilter is ON in the pickable DeviceActor only.
188 // To show labels, the mapping is computed explicitly via myExtractUnstructuredGrid->BuildOut2InMap();
189 //SetStoreIDMapping(theStoreMapping);
195 ::SetStoreIDMapping(bool theStoreMapping)
197 myExtractUnstructuredGrid->SetStoreMapping(theStoreMapping);
203 ::Init(TVisualObjPtr theVisualObj,
204 vtkImplicitBoolean* theImplicitBoolean)
206 myVisualObj = theVisualObj;
207 myExtractGeometry->SetImplicitFunction(theImplicitBoolean);
208 SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
213 ::SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
216 if(theIsImplicitFunctionUsed)
217 myPassFilter[ anId ]->SetInputConnection( myExtractGeometry->GetOutputPort() );
219 myPassFilter[ anId ]->SetInputConnection( myMergeFilter->GetOutputPort() );
221 myIsImplicitFunctionUsed = theIsImplicitFunctionUsed;
222 SetStoreClippingMapping(myStoreClippingMapping);
228 ::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid)
230 myExtractUnstructuredGrid->SetInputData(theGrid);
234 myIsShrinkable = true;
236 myMergeFilter->SetGeometryConnection(myExtractUnstructuredGrid->GetOutputPort());
238 //Pass diameters of the balls
239 if(myMapper->GetBallEnabled()) {
240 myMergeFilter->SetScalarsConnection(myExtractUnstructuredGrid->GetOutputPort());
243 myExtractGeometry->SetInputConnection(myMergeFilter->GetOutputPort());
246 SetImplicitFunctionUsed(myIsImplicitFunctionUsed);
247 myPassFilter[ anId + 1]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
250 myTransformFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
253 myPassFilter[ anId ]->SetInputConnection( myTransformFilter->GetOutputPort() );
254 myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
257 myGeomFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
260 myPassFilter[ anId ]->SetInputConnection( myGeomFilter->GetOutputPort() );
261 myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
264 myMapper->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
265 if( myPlaneCollection->GetNumberOfItems() )
266 myMapper->SetClippingPlanes( myPlaneCollection );
268 vtkLODActor::SetMapper( myMapper );
275 ::SetPlaneCollection( vtkPlaneCollection* theCollection )
277 myPlaneCollection = theCollection;
280 VTKViewer_ExtractUnstructuredGrid*
282 ::GetExtractUnstructuredGrid()
284 return myExtractUnstructuredGrid;
287 #include "SMDS_Mesh.hxx"
291 ::GetUnstructuredGrid()
293 myExtractUnstructuredGrid->Update();
294 return myExtractUnstructuredGrid->GetOutput();
300 ::SetControlMode(SMESH::Controls::FunctorPtr theFunctor,
301 SMESH_ScalarBarActor* theScalarBarActor,
302 vtkLookupTable* theLookupTable)
304 bool anIsInitialized = theFunctor != NULL;
306 vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
308 // SetStoreIDMapping(true);
309 myExtractUnstructuredGrid->Update();
310 vtkUnstructuredGrid* aGrid = myExtractUnstructuredGrid->GetOutput();
312 aDataSet->ShallowCopy(aGrid);
314 vtkDoubleArray *aScalars = vtkDoubleArray::New();
315 vtkIdType aNbCells = aGrid->GetNumberOfCells();
316 aScalars->SetNumberOfComponents(1);
317 aScalars->SetNumberOfTuples(aNbCells);
318 double* range = 0;// = aScalars->GetRange();
320 myVisualObj->UpdateFunctor(theFunctor);
322 using namespace SMESH::Controls;
323 if(NumericalFunctor* aNumericalFunctor = dynamic_cast<NumericalFunctor*>(theFunctor.get()))
325 myExtractUnstructuredGrid->BuildOut2InMap();
326 for(vtkIdType i = 0; i < aNbCells; i++)
328 vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
329 vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
330 double aValue = aNumericalFunctor->GetValue(anObjId);
331 aScalars->SetValue(i,aValue);
333 range = aScalars->GetRange();
334 if ( range[1] - range[0] < ( qMax(qAbs(range[0]),qAbs(range[1])) + 1e-100 ) * 1e-6 )
337 for(vtkIdType i = 0; i < aNbCells; i++)
338 aScalars->SetValue(i,range[0]);
341 else if(Predicate* aPredicate = dynamic_cast<Predicate*>(theFunctor.get()))
343 myExtractUnstructuredGrid->BuildOut2InMap();
344 for(vtkIdType i = 0; i < aNbCells; i++)
346 vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
347 vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
348 bool aValue = aPredicate->IsSatisfy(anObjId);
349 aScalars->SetValue(i,aValue);
351 range = aScalars->GetRange();
354 aDataSet->GetCellData()->SetScalars(aScalars);
357 theLookupTable->SetRange( range );
358 theLookupTable->SetNumberOfTableValues(theScalarBarActor->GetMaximumNumberOfColors());
359 theLookupTable->Build();
361 myMergeFilter->SetScalarsData(aDataSet);
364 GetMapper()->SetScalarVisibility(anIsInitialized);
365 theScalarBarActor->SetVisibility(anIsInitialized);
370 ::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor,
371 SMESH_ScalarBarActor* theScalarBarActor,
372 vtkLookupTable* theLookupTable)
374 bool anIsInitialized = theFunctor != NULL;
375 myExtractUnstructuredGrid->ClearRegisteredCells();
376 myExtractUnstructuredGrid->ClearRegisteredCellsWithType();
377 myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::ePassAll);
378 myVisualObj->UpdateFunctor(theFunctor);
380 using namespace SMESH::Controls;
381 if (anIsInitialized){
382 if (Length2D* aLength2D = dynamic_cast<Length2D*>(theFunctor.get())){
383 SMESH::Controls::Length2D::TValues aValues;
385 aLength2D->GetValues(aValues);
386 vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
387 vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
389 aDataSet->SetPoints(aGrid->GetPoints());
391 vtkIdType aNbCells = aValues.size();
393 vtkDoubleArray *aScalars = vtkDoubleArray::New();
394 aScalars->SetNumberOfComponents(1);
395 aScalars->SetNumberOfTuples(aNbCells);
397 vtkIdType aCellsSize = 3*aNbCells;
398 vtkCellArray* aConnectivity = vtkCellArray::New();
399 aConnectivity->Allocate( aCellsSize, 0 );
401 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
402 aCellTypesArray->SetNumberOfComponents( 1 );
403 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
405 vtkIdList *anIdList = vtkIdList::New();
406 anIdList->SetNumberOfIds(2);
408 Length2D::TValues::const_iterator anIter = aValues.begin();
410 for(; anIter != aValues.end(); anIter++){
411 const Length2D::Value& aValue = *anIter;
413 myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
414 myVisualObj->GetNodeVTKId(aValue.myPntId[1])
416 if(aNode[0] >= 0 && aNode[1] >= 0){
417 anIdList->SetId( 0, aNode[0] );
418 anIdList->SetId( 1, aNode[1] );
419 aConnectivity->InsertNextCell( anIdList );
420 aCellTypesArray->InsertNextValue( VTK_LINE );
421 aScalars->SetValue(aNbCells,aValue.myLength);
425 aCellTypesArray->SetNumberOfTuples( aNbCells );
426 aScalars->SetNumberOfTuples( aNbCells );
428 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
429 aCellLocationsArray->SetNumberOfComponents( 1 );
430 aCellLocationsArray->SetNumberOfTuples( aNbCells );
432 aConnectivity->InitTraversal();
433 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
434 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
436 aDataSet->SetCells( aCellTypesArray, aCellLocationsArray, aConnectivity );
437 SetUnstructuredGrid(aDataSet);
439 aDataSet->GetCellData()->SetScalars(aScalars);
442 theLookupTable->SetRange(aScalars->GetRange());
443 theLookupTable->Build();
445 myMergeFilter->SetScalarsData(aDataSet);
448 else if (MultiConnection2D* aMultiConnection2D = dynamic_cast<MultiConnection2D*>(theFunctor.get())){
449 SMESH::Controls::MultiConnection2D::MValues aValues;
451 aMultiConnection2D->GetValues(aValues);
452 vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
453 vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
454 aDataSet->SetPoints(aGrid->GetPoints());
456 vtkIdType aNbCells = aValues.size();
457 vtkDoubleArray *aScalars = vtkDoubleArray::New();
458 aScalars->SetNumberOfComponents(1);
459 aScalars->SetNumberOfTuples(aNbCells);
461 vtkIdType aCellsSize = 3*aNbCells;
462 vtkCellArray* aConnectivity = vtkCellArray::New();
463 aConnectivity->Allocate( aCellsSize, 0 );
465 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
466 aCellTypesArray->SetNumberOfComponents( 1 );
467 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
469 vtkIdList *anIdList = vtkIdList::New();
470 anIdList->SetNumberOfIds(2);
472 MultiConnection2D::MValues::const_iterator anIter = aValues.begin();
474 for(; anIter != aValues.end(); anIter++){
475 const MultiConnection2D::Value& aValue = (*anIter).first;
477 myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
478 myVisualObj->GetNodeVTKId(aValue.myPntId[1])
480 if(aNode[0] >= 0 && aNode[1] >= 0){
481 anIdList->SetId( 0, aNode[0] );
482 anIdList->SetId( 1, aNode[1] );
483 aConnectivity->InsertNextCell( anIdList );
484 aCellTypesArray->InsertNextValue( VTK_LINE );
485 aScalars->SetValue( aNbCells,(*anIter).second);
489 aCellTypesArray->SetNumberOfTuples( aNbCells );
490 aScalars->SetNumberOfTuples( aNbCells );
492 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
493 aCellLocationsArray->SetNumberOfComponents( 1 );
494 aCellLocationsArray->SetNumberOfTuples( aNbCells );
496 aConnectivity->InitTraversal();
497 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
498 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
500 aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
501 SetUnstructuredGrid(aDataSet);
503 aDataSet->GetCellData()->SetScalars(aScalars);
506 theLookupTable->SetRange(aScalars->GetRange());
507 theLookupTable->Build();
509 myMergeFilter->SetScalarsData(aDataSet);
513 GetMapper()->SetScalarVisibility(anIsInitialized);
514 theScalarBarActor->SetVisibility(anIsInitialized);
519 ::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor)
521 myExtractUnstructuredGrid->ClearRegisteredCells();
522 myExtractUnstructuredGrid->ClearRegisteredCellsWithType();
523 myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::ePassAll);
524 myVisualObj->UpdateFunctor(theFunctor);
526 using namespace SMESH::Controls;
527 Predicate* aPredicate = 0;
528 if (( aPredicate = dynamic_cast<FreeBorders *>(theFunctor.get())) ||
529 ( aPredicate = dynamic_cast<FreeFaces *>(theFunctor.get())) ||
530 ( aPredicate = dynamic_cast<BareBorderVolume *>(theFunctor.get())) ||
531 ( aPredicate = dynamic_cast<BareBorderFace *>(theFunctor.get())) ||
532 ( aPredicate = dynamic_cast<OverConstrainedVolume*>(theFunctor.get())) ||
533 ( aPredicate = dynamic_cast<CoincidentElements1D *>(theFunctor.get())) ||
534 ( aPredicate = dynamic_cast<CoincidentElements2D *>(theFunctor.get())) ||
535 ( aPredicate = dynamic_cast<CoincidentElements3D *>(theFunctor.get())) ||
536 ( aPredicate = dynamic_cast<OverConstrainedFace *>(theFunctor.get())))
538 myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
539 vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
540 vtkIdType aNbCells = aGrid->GetNumberOfCells();
541 for( vtkIdType i = 0; i < aNbCells; i++ ){
542 vtkIdType anObjId = myVisualObj->GetElemObjId(i);
543 if(aPredicate->IsSatisfy(anObjId))
544 myExtractUnstructuredGrid->RegisterCell(i);
546 if(!myExtractUnstructuredGrid->IsCellsRegistered())
547 myExtractUnstructuredGrid->RegisterCell(-1);
548 SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
550 else if(FreeEdges* aFreeEdges = dynamic_cast<FreeEdges*>(theFunctor.get()))
552 SMESH::Controls::FreeEdges::TBorders aBorders;
553 aFreeEdges->GetBoreders(aBorders);
554 vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
555 vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
556 aDataSet->SetPoints(aGrid->GetPoints());
558 vtkIdType aNbCells = aBorders.size();
559 vtkIdType aCellsSize = 3*aNbCells;
560 vtkCellArray* aConnectivity = vtkCellArray::New();
561 aConnectivity->Allocate( aCellsSize, 0 );
563 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
564 aCellTypesArray->SetNumberOfComponents( 1 );
565 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
567 vtkIdList *anIdList = vtkIdList::New();
568 anIdList->SetNumberOfIds(2);
570 FreeEdges::TBorders::const_iterator anIter = aBorders.begin();
571 for(; anIter != aBorders.end(); anIter++){
572 const FreeEdges::Border& aBorder = *anIter;
574 myVisualObj->GetNodeVTKId(aBorder.myPntId[0]),
575 myVisualObj->GetNodeVTKId(aBorder.myPntId[1])
577 //cout<<"aNode = "<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<endl;
578 if(aNode[0] >= 0 && aNode[1] >= 0){
579 anIdList->SetId( 0, aNode[0] );
580 anIdList->SetId( 1, aNode[1] );
581 aConnectivity->InsertNextCell( anIdList );
582 aCellTypesArray->InsertNextValue( VTK_LINE );
586 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
587 aCellLocationsArray->SetNumberOfComponents( 1 );
588 aCellLocationsArray->SetNumberOfTuples( aNbCells );
590 aConnectivity->InitTraversal();
591 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
592 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
594 aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
596 SetUnstructuredGrid(aDataSet);
599 else if (( aPredicate = dynamic_cast<FreeNodes *>(theFunctor.get())) ||
600 ( aPredicate = dynamic_cast<CoincidentNodes*>(theFunctor.get())))
602 myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
603 vtkIdType aNbNodes = myVisualObj->GetNbEntities(SMDSAbs_Node);
604 for( vtkIdType i = 0; i < aNbNodes; i++ ){
605 vtkIdType anObjId = myVisualObj->GetNodeObjId(i);
606 if(aPredicate->IsSatisfy(anObjId))
607 myExtractUnstructuredGrid->RegisterCell(i);
609 if(!myExtractUnstructuredGrid->IsCellsRegistered())
610 myExtractUnstructuredGrid->RegisterCell(-1);
611 SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
622 // cout << "DA " << this
623 // << " GF " << myGeomFilter;
624 // if ( this->Property )
625 // cout << " P " << this->Property->GetMTime();
626 // if ( this->BackfaceProperty != NULL )
627 // cout << " BP " << BackfaceProperty->GetMTime();
628 // if ( this->Texture != NULL )
629 // cout << " T " << this->Texture->GetMTime();
630 // cout << " U " << this->GetUserTransformMatrixMTime()
631 // << " M " << this->MTime.GetMTime() << endl;
633 // cout << "DA " << this
634 // << " GF " << myGeomFilter
635 // << " " << this->Superclass::GetMTime()
636 // << " " << myExtractGeometry->GetMTime()
637 // << " " << myExtractUnstructuredGrid->GetMTime()
638 // << " " << myMergeFilter->GetMTime()
639 // << " " << myGeomFilter->GetMTime()
640 // << " " << myTransformFilter->GetMTime()
641 // << " " << myFaceOrientationFilter->GetMTime() << endl;
643 vtkMTimeType mTime = this->Superclass::GetMTime();
644 mTime = max(mTime,myExtractGeometry->GetMTime());
645 mTime = max(mTime,myExtractUnstructuredGrid->GetMTime());
646 mTime = max(mTime,myMergeFilter->GetMTime());
647 mTime = max(mTime,myGeomFilter->GetMTime());
648 mTime = max(mTime,myTransformFilter->GetMTime());
649 mTime = max(mTime,myFaceOrientationFilter->GetMTime());
656 ::SetTransform(VTKViewer_Transform* theTransform)
658 myTransformFilter->SetTransform(theTransform);
666 if ( !myIsShrinkable ) return;
667 if ( vtkAlgorithmOutput* aDataSet = myPassFilter[ 0 ]->GetOutputPort() )
669 myShrinkFilter->SetInputConnection( aDataSet );
670 myPassFilter[ 1 ]->SetInputConnection( myShrinkFilter->GetOutputPort() );
679 if ( !myIsShrunk ) return;
680 if ( vtkAlgorithmOutput* aDataSet = myPassFilter[ 0 ]->GetOutputPort() )
682 myPassFilter[ 1 ]->SetInputConnection( aDataSet );
683 myPassFilter[ 1 ]->Modified();
692 ::SetFacesOriented(bool theIsFacesOriented)
694 if ( vtkAlgorithmOutput* aDataSet = myTransformFilter->GetOutputPort() )
696 myIsFacesOriented = theIsFacesOriented;
697 if( theIsFacesOriented )
698 myFaceOrientationFilter->SetInputConnection( aDataSet );
699 UpdateFaceOrientation();
705 ::SetFacesOrientationColor(double r,double g,double b)
707 myFaceOrientation->GetProperty()->SetColor( r, g, b );
712 ::GetFacesOrientationColor(double& r,double& g,double& b)
714 myFaceOrientation->GetProperty()->GetColor( r, g, b );
719 ::SetFacesOrientationScale(double theScale)
721 myFaceOrientationFilter->SetOrientationScale( theScale );
726 ::GetFacesOrientationScale()
728 return myFaceOrientationFilter->GetOrientationScale();
733 ::SetFacesOrientation3DVectors(bool theState)
735 myFaceOrientationFilter->Set3dVectors( theState );
740 ::GetFacesOrientation3DVectors()
742 return myFaceOrientationFilter->Get3dVectors();
747 ::UpdateFaceOrientation()
749 bool aShowFaceOrientation = myIsFacesOriented;
750 aShowFaceOrientation &= vtkLODActor::GetVisibility(); //GetVisibility(); -- avoid calling GetUnstructuredGrid()
751 aShowFaceOrientation &= myRepresentation == eSurface;
752 myFaceOrientation->SetVisibility(aShowFaceOrientation);
758 ::SetRepresentation(EReperesent theMode)
760 if ( myRepresentation == theMode )
764 myGeomFilter->SetInside(true);
765 myGeomFilter->SetWireframeMode(false);
766 GetProperty()->SetRepresentation(0);
769 myGeomFilter->SetInside(false);
770 myGeomFilter->SetWireframeMode(true);
771 GetProperty()->SetRepresentation(theMode);
774 myGeomFilter->SetInside(true);
775 myGeomFilter->SetWireframeMode(true);
776 GetProperty()->SetRepresentation(1);
779 myGeomFilter->SetInside(false);
780 myGeomFilter->SetWireframeMode(false);
781 GetProperty()->SetRepresentation(theMode);
783 SetMarkerEnabled(theMode == ePoint);
784 myRepresentation = theMode;
785 UpdateFaceOrientation();
786 GetProperty()->Modified();
787 myMapper->Modified();
794 ::SetVisibility(int theMode)
797 ( !myExtractUnstructuredGrid->GetInput() ||
798 GetUnstructuredGrid()->GetNumberOfCells()))
800 vtkLODActor::SetVisibility(theMode);
802 vtkLODActor::SetVisibility(false);
804 UpdateFaceOrientation();
812 int visibi = vtkLODActor::GetVisibility();
813 if(visibi && !GetUnstructuredGrid()->GetNumberOfCells()){
814 vtkLODActor::SetVisibility(false);
823 ::AddToRender(vtkRenderer* theRenderer)
825 theRenderer->AddActor(this);
826 theRenderer->AddActor(myFaceOrientation);
831 ::RemoveFromRender(vtkRenderer* theRenderer)
833 theRenderer->RemoveActor(this);
834 theRenderer->RemoveActor(myFaceOrientation);
840 ::GetNodeObjId(int theVtkID)
842 vtkIdType anID = theVtkID;
844 if(IsImplicitFunctionUsed())
845 anID = myExtractGeometry->GetNodeObjId(theVtkID);
847 vtkIdType aRetID = myVisualObj->GetNodeObjId(anID);
848 if(MYDEBUG) MESSAGE("GetNodeObjId - theVtkID = "<<theVtkID<<"; anID = "<<anID<<"; aRetID = "<<aRetID);
854 ::GetNodeCoord(int theObjID)
856 vtkDataSet* aDataSet = myMergeFilter->GetOutput();
857 vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID);
858 double* aCoord = (anID >=0 && anID < aDataSet->GetNumberOfPoints()) ? aDataSet->GetPoint(anID) : NULL;
859 if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<<theObjID<<"; anID = "<<anID);
866 ::GetElemObjId(int theVtkID)
868 vtkIdType anId = myGeomFilter->GetElemObjId(theVtkID);
872 vtkIdType anId2 = anId;
873 if(IsImplicitFunctionUsed())
874 anId2 = myExtractGeometry->GetElemObjId(anId);
878 vtkIdType anId3 = myExtractUnstructuredGrid->GetInputId(anId2);
882 vtkIdType aRetID = myVisualObj->GetElemObjId(anId3);
884 MESSAGE("GetElemObjId - theVtkID = "<<theVtkID<<"; anId2 = "<<anId2<<"; anId3 = "<<anId3<<"; aRetID = "<<aRetID);
890 ::GetElemCell(int theObjID)
892 vtkDataSet* aDataSet = myVisualObj->GetUnstructuredGrid();
893 vtkIdType aGridID = myVisualObj->GetElemVTKId(theObjID);
894 vtkCell* aCell = (aGridID >= 0 ) ? aDataSet->GetCell(aGridID) : NULL;
896 MESSAGE("GetElemCell - theObjID = "<<theObjID<<"; aGridID = "<<aGridID);
905 return myShrinkFilter->GetShrinkFactor();
910 ::SetShrinkFactor(double theValue)
912 theValue = theValue > 0.1? theValue: 0.8;
913 myShrinkFilter->SetShrinkFactor(theValue);
920 ::SetHighlited(bool theIsHighlited)
922 if ( myIsHighlited == theIsHighlited )
924 myIsHighlited = theIsHighlited;
930 ::Render(vtkRenderer *ren, vtkMapper* m)
932 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
933 double aStoredFactor, aStoredUnit;
934 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
936 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
937 double aFactor = myPolygonOffsetFactor, aUnits = myPolygonOffsetUnits;
939 static double EPS = .01;
942 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnits);
943 vtkLODActor::Render(ren,m);
945 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
946 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
952 ::SetPolygonOffsetParameters(double factor,
955 myPolygonOffsetFactor = factor;
956 myPolygonOffsetUnits = units;
960 * On/Off representation 2D quadratic element as arked polygon
962 void SMESH_DeviceActor::SetQuadraticArcMode(bool theFlag){
963 myGeomFilter->SetQuadraticArcMode(theFlag);
967 * Return true if 2D quadratic element displayed as arked polygon
969 bool SMESH_DeviceActor::GetQuadraticArcMode(){
970 return myGeomFilter->GetQuadraticArcMode();
973 * Set Max angle for representation 2D quadratic element as arked polygon
975 void SMESH_DeviceActor::SetQuadraticArcAngle(double theMaxAngle){
976 myGeomFilter->SetQuadraticArcAngle(theMaxAngle);
980 * Return Max angle of the representation 2D quadratic element as arked polygon
982 double SMESH_DeviceActor::GetQuadraticArcAngle(){
983 return myGeomFilter->GetQuadraticArcAngle();
987 * Set point marker enabled
988 * \param theMarkerEnabled flag to enable/disable point marker
990 void SMESH_DeviceActor::SetMarkerEnabled( bool theMarkerEnabled )
992 myMapper->SetMarkerEnabled( theMarkerEnabled );
996 * Set point marker enabled
997 * \param theBallEnabled flag to enable/disable ball drawing
999 void SMESH_DeviceActor::SetBallEnabled( bool theBallEnabled ) {
1000 myMapper->SetBallEnabled( theBallEnabled );
1004 * Set point marker scale factor
1005 * \param theBallScale double value which specifies a scale factor of ball element
1007 void SMESH_DeviceActor::SetBallScale( double theBallScale )
1009 myMapper->SetBallScale( theBallScale );
1010 myMapper->Modified();
1014 * Set standard point marker
1015 * \param theMarkerType type of the marker
1017 void SMESH_DeviceActor::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
1019 myMapper->SetMarkerStd( theMarkerType, theMarkerScale );
1023 * Set custom point marker
1024 * \param theMarkerId id of the marker texture
1025 * \param theMarkerTexture marker texture
1027 void SMESH_DeviceActor::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
1029 myMapper->SetMarkerTexture( theMarkerId, theMarkerTexture );
1033 * Get type of the point marker
1034 * \return type of the point marker
1036 VTK::MarkerType SMESH_DeviceActor::GetMarkerType()
1038 return myMapper->GetMarkerType();
1042 Get scale of the point marker
1043 \return scale of the point marker
1045 VTK::MarkerScale SMESH_DeviceActor::GetMarkerScale()
1047 return myMapper->GetMarkerScale();
1051 * Get texture identifier of the point marker
1052 * \return texture identifier of the point marker
1054 int SMESH_DeviceActor::GetMarkerTexture()
1056 return myMapper->GetMarkerTexture();
1060 * Get scale factor of ball element
1061 * \return scale factor of ball element
1063 double SMESH_DeviceActor::GetBallScale()
1065 return myMapper->GetBallScale();
1068 void SMESH_DeviceActor::SetCoincident3DAllowed(bool theFlag) {
1069 myGeomFilter->SetAppendCoincident3D(theFlag);
1072 bool SMESH_DeviceActor::IsCoincident3DAllowed() const {
1073 return myGeomFilter->GetAppendCoincident3D();