1 // Copyright (C) 2007-2015 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 = eSurface;
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);
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 SetStoreClippingMapping(theStoreMapping);
181 ::SetStoreClippingMapping(bool theStoreMapping)
183 myStoreClippingMapping = theStoreMapping;
184 myExtractGeometry->SetStoreMapping(theStoreMapping && myIsImplicitFunctionUsed);
185 SetStoreIDMapping(theStoreMapping);
191 ::SetStoreIDMapping(bool theStoreMapping)
193 myExtractUnstructuredGrid->SetStoreMapping(theStoreMapping);
199 ::Init(TVisualObjPtr theVisualObj,
200 vtkImplicitBoolean* theImplicitBoolean)
202 myVisualObj = theVisualObj;
203 myExtractGeometry->SetImplicitFunction(theImplicitBoolean);
204 SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
210 ::SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed)
213 if(theIsImplicitFunctionUsed)
214 myPassFilter[ anId ]->SetInputConnection( myExtractGeometry->GetOutputPort() );
216 myPassFilter[ anId ]->SetInputConnection( myMergeFilter->GetOutputPort() );
218 myIsImplicitFunctionUsed = theIsImplicitFunctionUsed;
219 SetStoreClippingMapping(myStoreClippingMapping);
225 ::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid)
228 //myIsShrinkable = theGrid->GetNumberOfCells() > 10;
229 myIsShrinkable = true;
231 myExtractUnstructuredGrid->SetInputData(theGrid);
233 myMergeFilter->SetGeometryConnection(myExtractUnstructuredGrid->GetOutputPort());
235 //Pass diameters of the balls
236 if(myMapper->GetBallEnabled()) {
237 myMergeFilter->SetScalarsConnection(myExtractUnstructuredGrid->GetOutputPort());
240 myExtractGeometry->SetInputConnection(myMergeFilter->GetOutputPort());
243 SetImplicitFunctionUsed(myIsImplicitFunctionUsed);
244 myPassFilter[ anId + 1]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
247 myTransformFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
250 myPassFilter[ anId ]->SetInputConnection( myTransformFilter->GetOutputPort() );
251 myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
254 myGeomFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
257 myPassFilter[ anId ]->SetInputConnection( myGeomFilter->GetOutputPort() );
258 myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
261 myMapper->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
262 if( myPlaneCollection->GetNumberOfItems() )
263 myMapper->SetClippingPlanes( myPlaneCollection );
265 vtkLODActor::SetMapper( myMapper );
272 ::SetPlaneCollection( vtkPlaneCollection* theCollection )
274 myPlaneCollection = theCollection;
277 VTKViewer_ExtractUnstructuredGrid*
279 ::GetExtractUnstructuredGrid()
281 return myExtractUnstructuredGrid;
287 ::GetUnstructuredGrid()
289 myExtractUnstructuredGrid->Update();
290 return myExtractUnstructuredGrid->GetOutput();
296 ::SetControlMode(SMESH::Controls::FunctorPtr theFunctor,
297 SMESH_ScalarBarActor* theScalarBarActor,
298 vtkLookupTable* theLookupTable)
300 bool anIsInitialized = theFunctor != NULL;
302 vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
304 SetStoreIDMapping(true);
305 myExtractUnstructuredGrid->Update();
306 vtkUnstructuredGrid* aGrid = myExtractUnstructuredGrid->GetOutput();
308 aDataSet->ShallowCopy(aGrid);
310 vtkDoubleArray *aScalars = vtkDoubleArray::New();
311 vtkIdType aNbCells = aGrid->GetNumberOfCells();
312 aScalars->SetNumberOfComponents(1);
313 aScalars->SetNumberOfTuples(aNbCells);
314 double* range;// = aScalars->GetRange();
316 myVisualObj->UpdateFunctor(theFunctor);
318 using namespace SMESH::Controls;
319 if(NumericalFunctor* aNumericalFunctor = dynamic_cast<NumericalFunctor*>(theFunctor.get()))
321 for(vtkIdType i = 0; i < aNbCells; i++){
322 vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
323 vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
324 double aValue = aNumericalFunctor->GetValue(anObjId);
325 aScalars->SetValue(i,aValue);
327 range = aScalars->GetRange();
328 if ( range[1] - range[0] < ( qMax(qAbs(range[0]),qAbs(range[1])) + 1e-100 ) * 1e-6 )
331 for(vtkIdType i = 0; i < aNbCells; i++)
332 aScalars->SetValue(i,range[0]);
335 else if(Predicate* aPredicate = dynamic_cast<Predicate*>(theFunctor.get()))
337 for(vtkIdType i = 0; i < aNbCells; i++){
338 vtkIdType anId = myExtractUnstructuredGrid->GetInputId(i);
339 vtkIdType anObjId = myVisualObj->GetElemObjId(anId);
340 bool aValue = aPredicate->IsSatisfy(anObjId);
341 aScalars->SetValue(i,aValue);
343 range = aScalars->GetRange();
346 aDataSet->GetCellData()->SetScalars(aScalars);
349 theLookupTable->SetRange( range );
350 theLookupTable->SetNumberOfTableValues(theScalarBarActor->GetMaximumNumberOfColors());
351 theLookupTable->Build();
353 myMergeFilter->SetScalarsData(aDataSet);
356 GetMapper()->SetScalarVisibility(anIsInitialized);
357 theScalarBarActor->SetVisibility(anIsInitialized);
362 ::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor,
363 SMESH_ScalarBarActor* theScalarBarActor,
364 vtkLookupTable* theLookupTable)
366 bool anIsInitialized = theFunctor != NULL;
367 myExtractUnstructuredGrid->ClearRegisteredCells();
368 myExtractUnstructuredGrid->ClearRegisteredCellsWithType();
369 myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::ePassAll);
370 myVisualObj->UpdateFunctor(theFunctor);
372 using namespace SMESH::Controls;
373 if (anIsInitialized){
374 if (Length2D* aLength2D = dynamic_cast<Length2D*>(theFunctor.get())){
375 SMESH::Controls::Length2D::TValues aValues;
377 aLength2D->GetValues(aValues);
378 vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
379 vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
381 aDataSet->SetPoints(aGrid->GetPoints());
383 vtkIdType aNbCells = aValues.size();
385 vtkDoubleArray *aScalars = vtkDoubleArray::New();
386 aScalars->SetNumberOfComponents(1);
387 aScalars->SetNumberOfTuples(aNbCells);
389 vtkIdType aCellsSize = 3*aNbCells;
390 vtkCellArray* aConnectivity = vtkCellArray::New();
391 aConnectivity->Allocate( aCellsSize, 0 );
393 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
394 aCellTypesArray->SetNumberOfComponents( 1 );
395 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
397 vtkIdList *anIdList = vtkIdList::New();
398 anIdList->SetNumberOfIds(2);
400 Length2D::TValues::const_iterator anIter = aValues.begin();
402 for(; anIter != aValues.end(); anIter++){
403 const Length2D::Value& aValue = *anIter;
405 myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
406 myVisualObj->GetNodeVTKId(aValue.myPntId[1])
408 if(aNode[0] >= 0 && aNode[1] >= 0){
409 anIdList->SetId( 0, aNode[0] );
410 anIdList->SetId( 1, aNode[1] );
411 aConnectivity->InsertNextCell( anIdList );
412 aCellTypesArray->InsertNextValue( VTK_LINE );
413 aScalars->SetValue(aNbCells,aValue.myLength);
417 aCellTypesArray->SetNumberOfTuples( aNbCells );
418 aScalars->SetNumberOfTuples( aNbCells );
420 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
421 aCellLocationsArray->SetNumberOfComponents( 1 );
422 aCellLocationsArray->SetNumberOfTuples( aNbCells );
424 aConnectivity->InitTraversal();
425 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
426 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
428 aDataSet->SetCells( aCellTypesArray, aCellLocationsArray, aConnectivity );
429 SetUnstructuredGrid(aDataSet);
431 aDataSet->GetCellData()->SetScalars(aScalars);
434 theLookupTable->SetRange(aScalars->GetRange());
435 theLookupTable->Build();
437 myMergeFilter->SetScalarsData(aDataSet);
440 else if (MultiConnection2D* aMultiConnection2D = dynamic_cast<MultiConnection2D*>(theFunctor.get())){
441 SMESH::Controls::MultiConnection2D::MValues aValues;
443 aMultiConnection2D->GetValues(aValues);
444 vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
445 vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
446 aDataSet->SetPoints(aGrid->GetPoints());
448 vtkIdType aNbCells = aValues.size();
449 vtkDoubleArray *aScalars = vtkDoubleArray::New();
450 aScalars->SetNumberOfComponents(1);
451 aScalars->SetNumberOfTuples(aNbCells);
453 vtkIdType aCellsSize = 3*aNbCells;
454 vtkCellArray* aConnectivity = vtkCellArray::New();
455 aConnectivity->Allocate( aCellsSize, 0 );
457 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
458 aCellTypesArray->SetNumberOfComponents( 1 );
459 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
461 vtkIdList *anIdList = vtkIdList::New();
462 anIdList->SetNumberOfIds(2);
464 MultiConnection2D::MValues::const_iterator anIter = aValues.begin();
466 for(; anIter != aValues.end(); anIter++){
467 const MultiConnection2D::Value& aValue = (*anIter).first;
469 myVisualObj->GetNodeVTKId(aValue.myPntId[0]),
470 myVisualObj->GetNodeVTKId(aValue.myPntId[1])
472 if(aNode[0] >= 0 && aNode[1] >= 0){
473 anIdList->SetId( 0, aNode[0] );
474 anIdList->SetId( 1, aNode[1] );
475 aConnectivity->InsertNextCell( anIdList );
476 aCellTypesArray->InsertNextValue( VTK_LINE );
477 aScalars->SetValue( aNbCells,(*anIter).second);
481 aCellTypesArray->SetNumberOfTuples( aNbCells );
482 aScalars->SetNumberOfTuples( aNbCells );
484 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
485 aCellLocationsArray->SetNumberOfComponents( 1 );
486 aCellLocationsArray->SetNumberOfTuples( aNbCells );
488 aConnectivity->InitTraversal();
489 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
490 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
492 aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
493 SetUnstructuredGrid(aDataSet);
495 aDataSet->GetCellData()->SetScalars(aScalars);
498 theLookupTable->SetRange(aScalars->GetRange());
499 theLookupTable->Build();
501 myMergeFilter->SetScalarsData(aDataSet);
505 GetMapper()->SetScalarVisibility(anIsInitialized);
506 theScalarBarActor->SetVisibility(anIsInitialized);
511 ::SetExtControlMode(SMESH::Controls::FunctorPtr theFunctor)
513 myExtractUnstructuredGrid->ClearRegisteredCells();
514 myExtractUnstructuredGrid->ClearRegisteredCellsWithType();
515 myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::ePassAll);
516 myVisualObj->UpdateFunctor(theFunctor);
518 using namespace SMESH::Controls;
519 Predicate* aPredicate = 0;
520 if (( aPredicate = dynamic_cast<FreeBorders *>(theFunctor.get())) ||
521 ( aPredicate = dynamic_cast<FreeFaces *>(theFunctor.get())) ||
522 ( aPredicate = dynamic_cast<BareBorderVolume *>(theFunctor.get())) ||
523 ( aPredicate = dynamic_cast<BareBorderFace *>(theFunctor.get())) ||
524 ( aPredicate = dynamic_cast<OverConstrainedVolume*>(theFunctor.get())) ||
525 ( aPredicate = dynamic_cast<CoincidentElements1D *>(theFunctor.get())) ||
526 ( aPredicate = dynamic_cast<CoincidentElements2D *>(theFunctor.get())) ||
527 ( aPredicate = dynamic_cast<CoincidentElements3D *>(theFunctor.get())) ||
528 ( aPredicate = dynamic_cast<OverConstrainedFace *>(theFunctor.get())))
530 myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
531 vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
532 vtkIdType aNbCells = aGrid->GetNumberOfCells();
533 for( vtkIdType i = 0; i < aNbCells; i++ ){
534 vtkIdType anObjId = myVisualObj->GetElemObjId(i);
535 if(aPredicate->IsSatisfy(anObjId))
536 myExtractUnstructuredGrid->RegisterCell(i);
538 if(!myExtractUnstructuredGrid->IsCellsRegistered())
539 myExtractUnstructuredGrid->RegisterCell(-1);
540 SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
542 else if(FreeEdges* aFreeEdges = dynamic_cast<FreeEdges*>(theFunctor.get()))
544 SMESH::Controls::FreeEdges::TBorders aBorders;
545 aFreeEdges->GetBoreders(aBorders);
546 vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New();
547 vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid();
548 aDataSet->SetPoints(aGrid->GetPoints());
550 vtkIdType aNbCells = aBorders.size();
551 vtkIdType aCellsSize = 3*aNbCells;
552 vtkCellArray* aConnectivity = vtkCellArray::New();
553 aConnectivity->Allocate( aCellsSize, 0 );
555 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
556 aCellTypesArray->SetNumberOfComponents( 1 );
557 aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() );
559 vtkIdList *anIdList = vtkIdList::New();
560 anIdList->SetNumberOfIds(2);
562 FreeEdges::TBorders::const_iterator anIter = aBorders.begin();
563 for(; anIter != aBorders.end(); anIter++){
564 const FreeEdges::Border& aBorder = *anIter;
566 myVisualObj->GetNodeVTKId(aBorder.myPntId[0]),
567 myVisualObj->GetNodeVTKId(aBorder.myPntId[1])
569 //cout<<"aNode = "<<aBorder.myPntId[0]<<"; "<<aBorder.myPntId[1]<<endl;
570 if(aNode[0] >= 0 && aNode[1] >= 0){
571 anIdList->SetId( 0, aNode[0] );
572 anIdList->SetId( 1, aNode[1] );
573 aConnectivity->InsertNextCell( anIdList );
574 aCellTypesArray->InsertNextValue( VTK_LINE );
578 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
579 aCellLocationsArray->SetNumberOfComponents( 1 );
580 aCellLocationsArray->SetNumberOfTuples( aNbCells );
582 aConnectivity->InitTraversal();
583 for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ )
584 aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) );
586 aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity );
588 SetUnstructuredGrid(aDataSet);
591 else if (( aPredicate = dynamic_cast<FreeNodes *>(theFunctor.get())) ||
592 ( aPredicate = dynamic_cast<CoincidentNodes*>(theFunctor.get())))
594 myExtractUnstructuredGrid->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding);
595 vtkIdType aNbNodes = myVisualObj->GetNbEntities(SMDSAbs_Node);
596 for( vtkIdType i = 0; i < aNbNodes; i++ ){
597 vtkIdType anObjId = myVisualObj->GetNodeObjId(i);
598 if(aPredicate->IsSatisfy(anObjId))
599 myExtractUnstructuredGrid->RegisterCell(i);
601 if(!myExtractUnstructuredGrid->IsCellsRegistered())
602 myExtractUnstructuredGrid->RegisterCell(-1);
603 SetUnstructuredGrid(myVisualObj->GetUnstructuredGrid());
614 unsigned long mTime = this->Superclass::GetMTime();
615 mTime = max(mTime,myExtractGeometry->GetMTime());
616 mTime = max(mTime,myExtractUnstructuredGrid->GetMTime());
617 mTime = max(mTime,myMergeFilter->GetMTime());
618 mTime = max(mTime,myGeomFilter->GetMTime());
619 mTime = max(mTime,myTransformFilter->GetMTime());
620 mTime = max(mTime,myFaceOrientationFilter->GetMTime());
627 ::SetTransform(VTKViewer_Transform* theTransform)
629 myTransformFilter->SetTransform(theTransform);
637 if ( !myIsShrinkable ) return;
638 if ( vtkAlgorithmOutput* aDataSet = myPassFilter[ 0 ]->GetOutputPort() )
640 myShrinkFilter->SetInputConnection( aDataSet );
641 myPassFilter[ 1 ]->SetInputConnection( myShrinkFilter->GetOutputPort() );
650 if ( !myIsShrunk ) return;
651 if ( vtkAlgorithmOutput* aDataSet = myPassFilter[ 0 ]->GetOutputPort() )
653 myPassFilter[ 1 ]->SetInputConnection( aDataSet );
654 myPassFilter[ 1 ]->Modified();
663 ::SetFacesOriented(bool theIsFacesOriented)
665 if ( vtkAlgorithmOutput* aDataSet = myTransformFilter->GetOutputPort() )
667 myIsFacesOriented = theIsFacesOriented;
668 if( theIsFacesOriented )
669 myFaceOrientationFilter->SetInputConnection( aDataSet );
670 UpdateFaceOrientation();
676 ::SetFacesOrientationColor(double r,double g,double b)
678 myFaceOrientation->GetProperty()->SetColor( r, g, b );
683 ::GetFacesOrientationColor(double& r,double& g,double& b)
685 myFaceOrientation->GetProperty()->GetColor( r, g, b );
690 ::SetFacesOrientationScale(double theScale)
692 myFaceOrientationFilter->SetOrientationScale( theScale );
697 ::GetFacesOrientationScale()
699 return myFaceOrientationFilter->GetOrientationScale();
704 ::SetFacesOrientation3DVectors(bool theState)
706 myFaceOrientationFilter->Set3dVectors( theState );
711 ::GetFacesOrientation3DVectors()
713 return myFaceOrientationFilter->Get3dVectors();
718 ::UpdateFaceOrientation()
720 bool aShowFaceOrientation = myIsFacesOriented;
721 aShowFaceOrientation &= GetVisibility();
722 aShowFaceOrientation &= myRepresentation == eSurface;
723 myFaceOrientation->SetVisibility(aShowFaceOrientation);
729 ::SetRepresentation(EReperesent theMode)
733 myGeomFilter->SetInside(true);
734 myGeomFilter->SetWireframeMode(false);
735 GetProperty()->SetRepresentation(0);
738 myGeomFilter->SetInside(false);
739 myGeomFilter->SetWireframeMode(true);
740 GetProperty()->SetRepresentation(theMode);
743 myGeomFilter->SetInside(true);
744 myGeomFilter->SetWireframeMode(true);
745 GetProperty()->SetRepresentation(1);
748 myGeomFilter->SetInside(false);
749 myGeomFilter->SetWireframeMode(false);
750 GetProperty()->SetRepresentation(theMode);
752 SetMarkerEnabled(theMode == ePoint);
753 myRepresentation = theMode;
754 UpdateFaceOrientation();
755 GetProperty()->Modified();
756 myMapper->Modified();
763 ::SetVisibility(int theMode)
765 if(!myExtractUnstructuredGrid->GetInput() ||
766 GetUnstructuredGrid()->GetNumberOfCells())
768 vtkLODActor::SetVisibility(theMode);
770 vtkLODActor::SetVisibility(false);
772 UpdateFaceOrientation();
780 if(!GetUnstructuredGrid()->GetNumberOfCells()){
781 vtkLODActor::SetVisibility(false);
783 return vtkLODActor::GetVisibility();
789 ::AddToRender(vtkRenderer* theRenderer)
791 theRenderer->AddActor(this);
792 theRenderer->AddActor(myFaceOrientation);
797 ::RemoveFromRender(vtkRenderer* theRenderer)
799 theRenderer->RemoveActor(this);
800 theRenderer->RemoveActor(myFaceOrientation);
806 ::GetNodeObjId(int theVtkID)
808 vtkIdType anID = theVtkID;
810 if(IsImplicitFunctionUsed())
811 anID = myExtractGeometry->GetNodeObjId(theVtkID);
813 vtkIdType aRetID = myVisualObj->GetNodeObjId(anID);
814 if(MYDEBUG) MESSAGE("GetNodeObjId - theVtkID = "<<theVtkID<<"; anID = "<<anID<<"; aRetID = "<<aRetID);
820 ::GetNodeCoord(int theObjID)
822 vtkDataSet* aDataSet = myMergeFilter->GetOutput();
823 vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID);
824 double* aCoord = (anID >=0) ? aDataSet->GetPoint(anID) : NULL;
825 if(MYDEBUG) MESSAGE("GetNodeCoord - theObjID = "<<theObjID<<"; anID = "<<anID);
832 ::GetElemObjId(int theVtkID)
834 vtkIdType anId = myGeomFilter->GetElemObjId(theVtkID);
838 vtkIdType anId2 = anId;
839 if(IsImplicitFunctionUsed())
840 anId2 = myExtractGeometry->GetElemObjId(anId);
844 vtkIdType anId3 = myExtractUnstructuredGrid->GetInputId(anId2);
848 vtkIdType aRetID = myVisualObj->GetElemObjId(anId3);
850 MESSAGE("GetElemObjId - theVtkID = "<<theVtkID<<"; anId2 = "<<anId2<<"; anId3 = "<<anId3<<"; aRetID = "<<aRetID);
856 ::GetElemCell(int theObjID)
858 vtkDataSet* aDataSet = myVisualObj->GetUnstructuredGrid();
859 vtkIdType aGridID = myVisualObj->GetElemVTKId(theObjID);
860 vtkCell* aCell = (aGridID >= 0 ) ? aDataSet->GetCell(aGridID) : NULL;
862 MESSAGE("GetElemCell - theObjID = "<<theObjID<<"; aGridID = "<<aGridID);
871 return myShrinkFilter->GetShrinkFactor();
876 ::SetShrinkFactor(double theValue)
878 theValue = theValue > 0.1? theValue: 0.8;
879 myShrinkFilter->SetShrinkFactor(theValue);
886 ::SetHighlited(bool theIsHighlited)
888 if ( myIsHighlited == theIsHighlited )
890 myIsHighlited = theIsHighlited;
896 ::Render(vtkRenderer *ren, vtkMapper* m)
898 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
899 double aStoredFactor, aStoredUnit;
900 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
902 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
903 double aFactor = myPolygonOffsetFactor, aUnits = myPolygonOffsetUnits;
905 static double EPS = .01;
908 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnits);
909 vtkLODActor::Render(ren,m);
911 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aStoredFactor,aStoredUnit);
912 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
918 ::SetPolygonOffsetParameters(double factor,
921 myPolygonOffsetFactor = factor;
922 myPolygonOffsetUnits = units;
926 * On/Off representation 2D quadratic element as arked polygon
928 void SMESH_DeviceActor::SetQuadraticArcMode(bool theFlag){
929 myGeomFilter->SetQuadraticArcMode(theFlag);
933 * Return true if 2D quadratic element displayed as arked polygon
935 bool SMESH_DeviceActor::GetQuadraticArcMode(){
936 return myGeomFilter->GetQuadraticArcMode();
939 * Set Max angle for representation 2D quadratic element as arked polygon
941 void SMESH_DeviceActor::SetQuadraticArcAngle(double theMaxAngle){
942 myGeomFilter->SetQuadraticArcAngle(theMaxAngle);
946 * Return Max angle of the representation 2D quadratic element as arked polygon
948 double SMESH_DeviceActor::GetQuadraticArcAngle(){
949 return myGeomFilter->GetQuadraticArcAngle();
953 * Set point marker enabled
954 * \param theMarkerEnabled flag to enable/disable point marker
956 void SMESH_DeviceActor::SetMarkerEnabled( bool theMarkerEnabled )
958 myMapper->SetMarkerEnabled( theMarkerEnabled );
962 * Set point marker enabled
963 * \param theBallEnabled flag to enable/disable ball drawing
965 void SMESH_DeviceActor::SetBallEnabled( bool theBallEnabled ) {
966 myMapper->SetBallEnabled( theBallEnabled );
970 * Set point marker scale factor
971 * \param theBallScale double value which specifies a scale factor of ball element
973 void SMESH_DeviceActor::SetBallScale( double theBallScale )
975 myMapper->SetBallScale( theBallScale );
976 myMapper->Modified();
980 * Set standard point marker
981 * \param theMarkerType type of the marker
983 void SMESH_DeviceActor::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
985 myMapper->SetMarkerStd( theMarkerType, theMarkerScale );
989 * Set custom point marker
990 * \param theMarkerId id of the marker texture
991 * \param theMarkerTexture marker texture
993 void SMESH_DeviceActor::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
995 myMapper->SetMarkerTexture( theMarkerId, theMarkerTexture );
999 * Get type of the point marker
1000 * \return type of the point marker
1002 VTK::MarkerType SMESH_DeviceActor::GetMarkerType()
1004 return myMapper->GetMarkerType();
1008 Get scale of the point marker
1009 \return scale of the point marker
1011 VTK::MarkerScale SMESH_DeviceActor::GetMarkerScale()
1013 return myMapper->GetMarkerScale();
1017 * Get texture identifier of the point marker
1018 * \return texture identifier of the point marker
1020 int SMESH_DeviceActor::GetMarkerTexture()
1022 return myMapper->GetMarkerTexture();
1026 * Get scale factor of ball element
1027 * \return scale factor of ball element
1029 double SMESH_DeviceActor::GetBallScale()
1031 return myMapper->GetBallScale();
1034 void SMESH_DeviceActor::SetCoincident3DAllowed(bool theFlag) {
1035 myGeomFilter->SetAppendCoincident3D(theFlag);
1038 bool SMESH_DeviceActor::IsCoincident3DAllowed() const {
1039 return myGeomFilter->GetAppendCoincident3D();