1 // Copyright (C) 2007-2022 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 // GEOM OBJECT : interactive object for Geometry entities visualization
24 // File : GEOM_Actor.cxx
25 // Author : Christophe ATTANASIO
29 \class GEOM_Actor GEOM_Actor.h
30 \brief This class allows to display an OpenCASCADE CAD model in a VTK viewer.
32 #include "GEOM_Actor.h"
34 #include "GEOM_DeviceActor.h"
35 #include "GEOM_VertexSource.h"
36 #include "GEOM_EdgeSource.h"
37 #include "GEOM_WireframeFace.h"
38 #include "GEOM_ShadingFace.h"
39 #include "GEOM_PainterPolyDataMapper.h"
40 #include "GEOMUtils.hxx"
41 #include "SVTK_Actor.h"
43 #include <OCC2VTK_Tools.h>
44 #include <GEOMUtils.hxx>
46 #include <vtkObjectFactory.h>
47 #include <vtkRenderer.h>
48 #include <vtkTextActor.h>
49 #include <vtkTextProperty.h>
50 #include <vtkProperty.h>
51 #include <vtkPointPicker.h>
52 #include <vtkCellPicker.h>
54 #include <TopAbs_ShapeEnum.hxx>
55 #include <TopExp_Explorer.hxx>
57 #include <BRep_Tool.hxx>
60 #include <vtkPolyDataWriter.h>
62 #include <vtkAppendPolyData.h>
63 #include <vtkPolyDataMapper.h>
64 #include <vtkPolyData.h>
65 #include <vtkTransform.h>
66 #include <vtkMatrix4x4.h>
68 #include <vtkCamera.h>
70 #include "utilities.h"
72 #include "SALOME_InteractiveObject.hxx"
74 //vtkStandardNewMacro(GEOM_Actor)
76 GEOM_Actor::GEOM_Actor():
82 // myDisplayMode(eWireframe),
85 myVerticesMode(false),
88 myVertexActor(GEOM_DeviceActor::New(),true),
89 myVertexSource(GEOM_VertexSource::New(),true),
91 myStandaloneVertexActor(GEOM_DeviceActor::New(),true),
92 myStandaloneVertexSource(GEOM_VertexSource::New(),true),
94 myIsolatedEdgeActor(GEOM_DeviceActor::New(),true),
95 myIsolatedEdgeSource(GEOM_EdgeSource::New(),true),
97 myOneFaceEdgeActor(GEOM_DeviceActor::New(),true),
98 myOneFaceEdgeSource(GEOM_EdgeSource::New(),true),
100 mySharedEdgeActor(GEOM_DeviceActor::New(),true),
101 mySharedEdgeSource(GEOM_EdgeSource::New(),true),
103 myWireframeFaceActor(GEOM_DeviceActor::New(),true),
104 myWireframeFaceSource(GEOM_WireframeFace::New(),true),
106 myShadingFaceActor(GEOM_DeviceActor::New(),true),
107 myShadingFaceSource(GEOM_ShadingFace::New(),true),
109 myHighlightActor(GEOM_DeviceActor::New(),true),
111 myTextActor( vtkTextActor::New() ),
113 myHighlightProp(vtkProperty::New()),
114 myPreHighlightProp(vtkProperty::New()),
115 myShadingFaceProp(vtkProperty::New()),
116 myShadingBackFaceProp(vtkProperty::New()),
118 myAppendFilter(vtkAppendPolyData::New(),true),
119 // Use mapper as an instance of GEOM_PainterPolyDataMapper class
120 // to prevent drawing of mappers' content (due to an empty definition
121 // of GEOM_PainterPolyDataMapper::RenderPiece(...)).
122 // !!! Presentation of GEOM_Actor is drawing only with help of actors
123 // defined in this class !!!
124 myPolyDataMapper(GEOM_PainterPolyDataMapper::New(),true)
127 MESSAGE(this<< " GEOM_Actor::GEOM_Actor");
129 myPolyDataMapper->SetInputConnection(myAppendFilter->GetOutputPort());
130 vtkProperty* aProperty;
132 myHighlightProp->SetAmbient(0.5);
133 myHighlightProp->SetDiffuse(0.3);
134 myHighlightProp->SetSpecular(0.2);
135 myHighlightProp->SetRepresentationToSurface();
136 myHighlightProp->SetAmbientColor(1, 1, 1);
137 myHighlightProp->SetDiffuseColor(1, 1, 1);
138 myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
139 myHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
140 myHighlightActor->SetProperty(myHighlightProp.GetPointer());
142 this->myHighlightActor->SetInput(myAppendFilter->GetOutputPort(),false);
144 myPreHighlightProp->SetColor(0,1,1);
145 myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE);
146 myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
147 myPreHighlightProp->SetRepresentationToWireframe();
149 myAppendFilter->AddInputConnection(myVertexSource->GetOutputPort());
150 myVertexActor->SetInput(myVertexSource->GetOutputPort(),false);
151 aProperty = myVertexActor->GetProperty();
152 aProperty->SetRepresentation(VTK_POINTS);
153 aProperty->SetPointSize(3);
154 aProperty->SetColor(1, 1, 0);
156 myAppendFilter->AddInputConnection(myStandaloneVertexSource->GetOutputPort());
157 myStandaloneVertexActor->SetInput(myStandaloneVertexSource->GetOutputPort(),false);
158 aProperty = myStandaloneVertexActor->GetProperty();
159 aProperty->SetRepresentation(VTK_POINTS);
160 aProperty->SetPointSize(3);
161 aProperty->SetColor(1, 1, 0);
163 myAppendFilter->AddInputConnection(myIsolatedEdgeSource->GetOutputPort());
164 myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutputPort(),false);
165 aProperty = myIsolatedEdgeActor->GetProperty();
166 aProperty->SetRepresentation(VTK_WIREFRAME);
167 myIsolatedEdgeColor[0] = 1; myIsolatedEdgeColor[1] = 0; myIsolatedEdgeColor[2] = 0;
168 aProperty->SetColor(myIsolatedEdgeColor[0], myIsolatedEdgeColor[1], myIsolatedEdgeColor[2]);
170 myAppendFilter->AddInputConnection(myOneFaceEdgeSource->GetOutputPort());
171 myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutputPort(),false);
172 aProperty = myOneFaceEdgeActor->GetProperty();
173 aProperty->SetRepresentation(VTK_WIREFRAME);
174 myOneFaceEdgeColor[0] = 0; myOneFaceEdgeColor[1] = 1; myOneFaceEdgeColor[2] = 0;
175 aProperty->SetColor(myOneFaceEdgeColor[0], myOneFaceEdgeColor[1], myOneFaceEdgeColor[2]);
177 myAppendFilter->AddInputConnection(mySharedEdgeSource->GetOutputPort());
178 mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutputPort(),false);
179 aProperty = mySharedEdgeActor->GetProperty();
180 aProperty->SetRepresentation(VTK_WIREFRAME);
181 mySharedEdgeColor[0] = 1; mySharedEdgeColor[1] = 1; mySharedEdgeColor[2] = 0;
182 aProperty->SetColor(mySharedEdgeColor[0], mySharedEdgeColor[1], mySharedEdgeColor[2]);
184 myAppendFilter->AddInputConnection(myWireframeFaceSource->GetOutputPort());
185 myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutputPort(),false);
186 aProperty = myWireframeFaceActor->GetProperty();
187 aProperty->SetRepresentation(VTK_WIREFRAME);
188 aProperty->SetColor(0.5, 0.5, 0.5);
190 myShadingFaceActor->SetInput(myShadingFaceSource->GetOutputPort(),true);
192 myShadingFaceProp->SetRepresentation(VTKViewer::Representation::Surface);
193 myShadingFaceProp->SetInterpolationToGouraud();
194 myShadingFaceProp->SetAmbient(1.0);
195 myShadingFaceProp->SetDiffuse(1.0);
196 myShadingFaceProp->SetSpecular(0.4);
197 myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
198 myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
199 myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
201 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
203 // Toggle display mode
204 setDisplayMode(0); // WIRE FRAME
206 SetVerticesMode(0); //
211 GEOM_Actor::~GEOM_Actor()
213 MESSAGE(this << " ~GEOM_Actor::GEOM_Actor");
215 myTextActor->Delete();
216 myHighlightProp->Delete();
217 myPreHighlightProp->Delete();
218 myShadingFaceProp->Delete();
219 myShadingBackFaceProp->Delete();
226 GEOM_Actor* anObject = new GEOM_Actor();
227 anObject->SetMapper(anObject->myPolyDataMapper.Get());
232 void Write(vtkPolyData* theDataSet, const char* theFileName){
233 vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
234 MESSAGE ("Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells());
235 aWriter->SetInputData(theDataSet);
236 aWriter->SetFileName(theFileName);
245 this->myVertexSource->Modified();
246 this->myStandaloneVertexSource->Modified();
247 this->myIsolatedEdgeSource->Modified();
248 this->myOneFaceEdgeSource->Modified();
249 this->mySharedEdgeSource->Modified();
250 this->myWireframeFaceSource->Modified();
251 this->myShadingFaceSource->Modified();
252 this->myTextActor->Modified();
257 SetMapper(vtkMapper* theMapper)
259 SALOME_Actor::SetMapper(theMapper);
264 AddToRender(vtkRenderer* theRenderer)
266 //SALOME_Actor::AddToRender(theRenderer);
268 theRenderer->AddActor(this);
270 this->myHighlightActor->AddToRender(theRenderer);
273 myShadingFaceActor->AddToRender(theRenderer);
274 myWireframeFaceActor->AddToRender(theRenderer);
276 mySharedEdgeActor->AddToRender(theRenderer);
277 myOneFaceEdgeActor->AddToRender(theRenderer);
278 myIsolatedEdgeActor->AddToRender(theRenderer);
280 myVertexActor->AddToRender(theRenderer);
281 myStandaloneVertexActor->AddToRender(theRenderer);
283 theRenderer->AddActor( myTextActor );
288 RemoveFromRender(vtkRenderer* theRenderer)
290 //SALOME_Actor::RemoveFromRender(theRenderer);
293 theRenderer->RemoveActor(this);
295 myHighlightActor->RemoveFromRender(theRenderer);
296 myShadingFaceActor->RemoveFromRender(theRenderer);
297 myWireframeFaceActor->RemoveFromRender(theRenderer);
299 mySharedEdgeActor->RemoveFromRender(theRenderer);
300 myOneFaceEdgeActor->RemoveFromRender(theRenderer);
301 myIsolatedEdgeActor->RemoveFromRender(theRenderer);
303 myVertexActor->RemoveFromRender(theRenderer);
304 myStandaloneVertexActor->RemoveFromRender(theRenderer);
306 theRenderer->RemoveActor( myTextActor );
309 SetVisibility(false);
314 setDisplayMode(int theMode)
316 MESSAGE("GEOM_Actor::setDisplayMode = " << theMode);
318 if ( theMode == (int)eShadingWithEdges ) {
320 myIsolatedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
321 myIsolatedEdgeColor[1],
322 myIsolatedEdgeColor[2]);
323 myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
324 myEdgesInShadingColor[1],
325 myEdgesInShadingColor[2]);
326 mySharedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
327 myEdgesInShadingColor[1],
328 myEdgesInShadingColor[2]);
332 myIsolatedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
333 myIsolatedEdgeColor[1],
334 myIsolatedEdgeColor[2]);
335 mySharedEdgeActor->GetProperty()->SetColor(mySharedEdgeColor[0],
336 mySharedEdgeColor[1],
337 mySharedEdgeColor[2]);
338 myOneFaceEdgeActor->GetProperty()->SetColor(myOneFaceEdgeColor[0],
339 myOneFaceEdgeColor[1],
340 myOneFaceEdgeColor[2]);
343 VTKViewer_Actor::setDisplayMode(theMode);
344 SetVisibility(GetVisibility());
349 SetSelected(bool theIsSelected)
351 MESSAGE("GEOM_Actor::SetSelected = " << theIsSelected);
353 myIsSelected = theIsSelected;
354 SetVisibility(GetVisibility());
359 SetVisibility(int theVisibility)
361 MESSAGE("GEOM_Actor::SetVisibility = " << theVisibility << " myIsSelected=" << myIsSelected
362 << " theVisibility=" << theVisibility << " myIsPreselected=" << myIsPreselected);
364 SALOME_Actor::SetVisibility(theVisibility);
366 this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
368 myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges) && (!myIsSelected || !myIsPreselected));
369 myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe) && !myIsSelected);
371 mySharedEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
372 myOneFaceEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
373 myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
375 myVertexActor->SetVisibility(theVisibility && (isOnlyVertex || (myVerticesMode && (!myIsSelected && !myIsPreselected))));// must be added new mode points
377 myStandaloneVertexActor->SetVisibility(theVisibility);
379 myTextActor->SetVisibility( theVisibility && myNameMode );
385 ::SetNbIsos(const int theNb[2])
387 myWireframeFaceSource->SetNbIso(theNb);
392 ::GetNbIsos(int &theNbU,int &theNbV)
394 myWireframeFaceSource->GetNbIso(theNbU, theNbV);
399 ::SetVectorMode(bool theMode)
401 myVectorMode = theMode;
402 myIsolatedEdgeSource->SetVectorMode(theMode);
403 myOneFaceEdgeSource->SetVectorMode(theMode);
404 mySharedEdgeSource->SetVectorMode(theMode);
417 ::SetVerticesMode(bool theMode)
419 myVerticesMode = theMode;
420 if ( theMode || isOnlyVertex ) {
421 myAppendFilter->AddInputConnection(myVertexSource->GetOutputPort());
423 myAppendFilter->RemoveInputConnection(0, myVertexSource->GetOutputPort());
432 return myVerticesMode;
439 if( !getIO() || myShape.IsNull() )
442 gp_Ax3 anAx3 = GEOMUtils::GetPosition(myShape);
443 double center[3] = { anAx3.Location().X(),
444 anAx3.Location().Y(),
445 anAx3.Location().Z() };
446 double* pos = center;
447 myTextActor->GetTextProperty()->SetFontSize( 16 );
448 myTextActor->GetTextProperty()->ShadowOn();
449 myTextActor->GetPositionCoordinate()->SetCoordinateSystemToWorld();
450 myTextActor->GetPositionCoordinate()->SetValue(pos);
451 myTextActor->SetInput( getIO()->getName() );
456 ::SetNameMode(bool theMode)
458 myNameMode = theMode;
459 myTextActor->SetVisibility(theMode);
472 SetDeflection(double theDeflection)
474 double aDeflection = ( theDeflection <= 0 ) ? GEOMUtils::DefaultDeflection() : theDeflection;
476 if ( myDeflection != aDeflection ) {
477 myDeflection = aDeflection;
478 GEOMUtils::MeshShape( myShape, myDeflection );
483 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
484 double theDeflection,
489 myVertexSource->Clear();
490 myStandaloneVertexSource->Clear();
491 myIsolatedEdgeSource->Clear();
492 myOneFaceEdgeSource->Clear();
493 mySharedEdgeSource->Clear();
494 myWireframeFaceSource->Clear();
495 myShadingFaceSource->Clear();
497 TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
498 for (; aVertexExp.More(); aVertexExp.Next())
500 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
501 myVertexSource->AddVertex(aVertex);
504 SetDeflection(theDeflection);
506 // look if edges are free or shared
507 TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
508 TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
510 GEOM::ShapeToVTK(theShape,anEdgeMap,theIsVector,
511 myStandaloneVertexSource.Get(),
512 myIsolatedEdgeSource.Get(),
513 myOneFaceEdgeSource.Get(),
514 mySharedEdgeSource.Get(),
515 myWireframeFaceSource.Get(),
516 myShadingFaceSource.Get());
518 myIsolatedEdgeSource->IsEmpty() &&
519 myOneFaceEdgeSource->IsEmpty() &&
520 mySharedEdgeSource->IsEmpty() &&
521 myWireframeFaceSource->IsEmpty() &&
522 myShadingFaceSource->IsEmpty();
525 if((bool)myShape.Infinite() || isOnlyVertex ){
526 myVertexActor->GetDeviceActor()->SetInfinitive(true);
527 myStandaloneVertexActor->GetDeviceActor()->SetInfinitive(true);
528 myHighlightActor->GetDeviceActor()->SetInfinitive(true);
533 // 0051777: TC7.2.0: Element could not be selected in Hypothesis Construction
534 myAppendFilter->Update();
537 // warning! must be checked!
538 // SetHighlightProperty
539 // SetWireframeProperty
540 // SetShadingProperty
542 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
544 MESSAGE("GEOM_Actor::SetHighlightProperty");
546 this->myHighlightActor->GetProperty()->DeepCopy(Prop);
550 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
552 MESSAGE(this << " GEOM_Actor::SetWireframeProperty");
555 myWireframeFaceActor->SetProperty(Prop);
559 vtkProperty* GEOM_Actor::GetWireframeProperty()
561 return myWireframeFaceActor->GetProperty();
564 vtkProperty* GEOM_Actor::GetIsolatedEdgeProperty()
566 return myIsolatedEdgeActor->GetProperty();
569 vtkProperty* GEOM_Actor::GetVertexProperty()
571 return myVertexActor->GetProperty();
574 vtkProperty* GEOM_Actor::GetStandaloneVertexProperty()
576 return myStandaloneVertexActor->GetProperty();
579 vtkProperty* GEOM_Actor::GetSharedEdgeProperty()
581 return mySharedEdgeActor->GetProperty();
584 vtkProperty* GEOM_Actor::GetFaceEdgeProperty()
586 return myOneFaceEdgeActor->GetProperty();
589 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
591 MESSAGE("GEOM_Actor::SetShadingProperty");
593 myShadingFaceProp->DeepCopy(Prop);
597 vtkProperty* GEOM_Actor::GetShadingProperty()
599 return myShadingFaceProp;
603 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
605 MESSAGE("GEOM_Actor::Render");
610 /* render the property */
611 if (!this->Property) {
612 // force creation of a property
614 this->Property->SetInterpolation(1);
615 this->Property->SetRepresentationToSurface();
616 this->Property->SetAmbient(0.3);
617 this->Property->SetAmbientColor(0.88,0.86,0.2);
618 this->Property->SetDiffuseColor(0.99,0.7,0.21);
619 this->Property->SetSpecularColor(0.99,0.98,0.83);
622 switch(myDisplayMode){
623 case eWireframe://wireframe
624 myPreHighlightProp->SetRepresentationToWireframe();
625 myHighlightProp->SetRepresentationToWireframe();
627 case eShading://shading
628 case eShadingWithEdges://shading with edges
629 myPreHighlightProp->SetRepresentationToSurface();
630 myHighlightProp->SetRepresentationToSurface();
631 myShadingFaceProp->SetRepresentationToSurface();
632 myShadingBackFaceProp->SetRepresentationToSurface();
638 this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
639 myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
640 myShadingFaceActor->SetBackfaceProperty(myPreHighlightProp.GetPointer());
642 this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
643 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
644 myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
648 this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
649 myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
650 myShadingFaceActor->SetBackfaceProperty(myHighlightProp.GetPointer());
653 this->Property->Render(this, ren);
654 if (this->BackfaceProperty) {
655 this->BackfaceProperty->BackfaceRender(this, ren);
656 this->Device->SetBackfaceProperty(this->BackfaceProperty);
658 this->Device->SetProperty(this->Property);
659 /* if(myShape.ShapeType() == TopAbs_VERTEX) {
661 //The parameter determine size of vertex actor relate to diagonal of RendererWindow
662 static double delta = 0.01;
663 double X1 = -1, Y1 = -1, Z1 = 0;
664 ren->ViewToWorld(X1,Y1,Z1);
665 double X2 = +1, Y2 = +1, Z2 = 0;
666 ren->ViewToWorld(X2,Y2,Z2);
667 Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
668 this->SetScale(Z2*delta);
670 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
671 this->GetMatrix(ren->GetActiveCamera(), aMatrix);
672 this->Device->SetUserMatrix(aMatrix);
673 this->Device->Render(ren,theMapper);
676 this->Device->Render(ren, theMapper);
679 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
681 MESSAGE("GEOM_Actor::ReleaseGraphicsResources");
684 void GEOM_Actor::ShallowCopy(vtkProp *prop)
686 MESSAGE("GEOM_Actor::ShallowCopy");
688 GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
691 this->SetShape(f->getTopo(),f->GetDeflection());
695 this->SALOME_Actor::ShallowCopy(prop);
698 const TopoDS_Shape& GEOM_Actor::getTopo()
700 MESSAGE("GEOM_Actor::getTopo");
705 void GEOM_Actor::setInputShape(const TopoDS_Shape& /*ashape*/, double /*adef1*/,
706 int /*imode*/, bool /*isVector*/)
708 MESSAGE("GEOM_Actor::setInputShape");
711 double GEOM_Actor::isVector()
713 MESSAGE("GEOM_Actor::isVector");
718 void GEOM_Actor::SubShapeOn()
720 MESSAGE("GEOM_Actor::SubShapeOn");
723 void GEOM_Actor::SubShapeOff()
725 MESSAGE("GEOM_Actor::SubShapeOff");
728 void GEOM_Actor::highlight(bool highlight)
730 MESSAGE(this << " GEOM_Actor::highlight highlight=" << highlight);
732 SALOME_Actor::highlight(highlight);
735 void GEOM_Actor::SetOpacity(double opa)
738 myShadingFaceProp->SetOpacity(opa);
739 myShadingBackFaceProp->SetOpacity(opa);
740 myHighlightProp->SetOpacity(opa);
741 myPreHighlightProp->SetOpacity(opa);
742 myVertexActor->GetProperty()->SetOpacity(opa);
743 myStandaloneVertexActor->GetProperty()->SetOpacity(opa);
746 double GEOM_Actor::GetOpacity()
749 return myShadingFaceProp->GetOpacity();
752 void GEOM_Actor::SetColor(double r,double g,double b)
754 // set the same color to all sub-actors:
756 // - standalone edges
759 // - shading color (front and back faces)
760 SetPointColor(r, g, b);
761 SetIsolatedEdgeColor(r, g, b);
762 SetSharedEdgeColor(r, g, b);
763 SetFreeEdgeColor(r, g, b);
764 myShadingFaceProp->SetColor(r,g,b); // shading color
765 myShadingBackFaceProp->SetColor(r,g,b); // back face shading color
768 void GEOM_Actor::GetColor(double& r,double& g,double& b)
771 myShadingFaceProp->GetColor(aRGB);
778 \brief Set color of points
779 Points actor is shown in Wireframe mode only, see SetVisibility()
781 void GEOM_Actor::SetPointColor(double r, double g, double b)
783 myVertexActor->GetProperty()->SetColor(r, g, b);
784 myStandaloneVertexActor->GetProperty()->SetColor(r, g, b);
788 \brief Set color of standalone edges, wires, vectors
789 This actor is shown in all display mode, see SetVisibility()
790 TODO: check - this color seems to be used not only for standalone edges
792 void GEOM_Actor::SetIsolatedEdgeColor(double r, double g, double b)
794 myIsolatedEdgeColor[0] = r; myIsolatedEdgeColor[1] = g; myIsolatedEdgeColor[2] = b;
795 myIsolatedEdgeActor->GetProperty()->SetColor(r, g, b);
799 \brief Set color of shared edges
800 This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
801 TODO: check - this seems to be not working currently
803 void GEOM_Actor::SetSharedEdgeColor(double r, double g, double b)
805 mySharedEdgeColor[0] = r; mySharedEdgeColor[1] = g; mySharedEdgeColor[2] = b;
806 if ( myDisplayMode != (int)eShadingWithEdges )
807 mySharedEdgeActor->GetProperty()->SetColor(r, g, b);
811 \brief Set color of edges for standalone faces
812 This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
813 TODO: this color should be used not only for faces
815 void GEOM_Actor::SetFreeEdgeColor(double r, double g, double b)
817 myOneFaceEdgeColor[0] = r; myOneFaceEdgeColor[1] = g; myOneFaceEdgeColor[2] = b;
818 if ( myDisplayMode != (int)eShadingWithEdges )
819 myOneFaceEdgeActor->GetProperty()->SetColor(r, g, b);
823 \brief Set color of iso-lines
824 This actor is shown only in wireframe display mode, see SetVisibility()
826 void GEOM_Actor::SetIsosColor(double r, double g, double b)
828 myWireframeFaceActor->GetProperty()->SetColor(r, g, b);
832 \brief Set color of labels
833 This actor is shown only if 'Show name' is switched-on, see SetVisibility()
835 void GEOM_Actor::SetLabelColor(double r, double g, double b)
837 myTextActor->GetTextProperty()->SetColor(r, g, b);
840 void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
842 // we set material properties as back and front material
843 int aSize = theProps.size();
845 if ( aSize < 1 || aSize > 2)
848 // theProps[0] -- front material properties
849 // theProps[1] -- back material properties (if exist)
853 // Set reflection coefficients
854 aCoefnt = theProps[0]->GetAmbient();
855 myShadingFaceProp->SetAmbient(aCoefnt);
856 myVertexActor->GetProperty()->SetAmbient(aCoefnt);
857 myStandaloneVertexActor->GetProperty()->SetAmbient(aCoefnt);
859 aCoefnt = theProps[1]->GetAmbient();
860 myShadingBackFaceProp->SetAmbient(aCoefnt);
862 // Set diffuse coefficients
863 aCoefnt = theProps[0]->GetDiffuse();
864 myShadingFaceProp->SetDiffuse(aCoefnt);
865 myVertexActor->GetProperty()->SetDiffuse(aCoefnt);
866 myStandaloneVertexActor->GetProperty()->SetDiffuse(aCoefnt);
868 aCoefnt = theProps[1]->GetDiffuse();
869 myShadingBackFaceProp->SetDiffuse(aCoefnt);
871 // Set specular coefficients
872 aCoefnt = theProps[0]->GetSpecular();
873 myShadingFaceProp->SetSpecular(aCoefnt);
874 myVertexActor->GetProperty()->SetSpecular(aCoefnt);
875 myStandaloneVertexActor->GetProperty()->SetSpecular(aCoefnt);
877 aCoefnt = theProps[1]->GetSpecular();
878 myShadingBackFaceProp->SetSpecular(aCoefnt);
883 // Set reflection colors
884 aColor = theProps[0]->GetAmbientColor();
885 myShadingFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
886 myVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
887 myStandaloneVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
889 aColor = theProps[1]->GetAmbientColor();
890 myShadingBackFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
892 // Set diffuse colors
893 aColor = theProps[0]->GetDiffuseColor();
894 myShadingFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
895 myVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
896 myStandaloneVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
898 aColor = theProps[1]->GetDiffuseColor();
899 myShadingBackFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
901 // Set specular colors
902 aColor = theProps[0]->GetSpecularColor();
903 myShadingFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
904 myVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
905 myStandaloneVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
907 aColor = theProps[1]->GetSpecularColor();
908 myShadingBackFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
911 aCoefnt = theProps[0]->GetSpecularPower();
912 myShadingFaceProp->SetSpecularPower(aCoefnt);
913 myVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
914 myStandaloneVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
916 aCoefnt = theProps[1]->GetSpecularPower();
917 myShadingBackFaceProp->SetSpecularPower(aCoefnt);
919 // Set back face material property
920 myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
923 vtkProperty* GEOM_Actor::GetFrontMaterial()
925 return myShadingFaceProp;
928 vtkProperty* GEOM_Actor::GetBackMaterial()
930 return myShadingBackFaceProp;
933 bool GEOM_Actor::IsInfinitive()
935 return ((bool)myShape.Infinite() || isOnlyVertex);
939 To map current selection to VTK representation
943 ::Highlight(bool theIsHighlight)
945 myIsSelected = theIsHighlight;
947 MESSAGE(this << " GEOM_Actor::Highlight myIsSelected=" << myIsSelected);
949 SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
950 SetVisibility(GetVisibility());
954 To process prehighlight (called from SVTK_InteractorStyle)
958 ::PreHighlight(vtkInteractorStyle* /*theInteractorStyle*/,
959 SVTK_SelectionEvent* theSelectionEvent,
962 MESSAGE(this << " GEOM_Actor::PreHighlight (3) theIsHighlight=" << theIsHighlight);
964 if ( !GetPickable() )
967 myPreHighlightActor->SetVisibility( false );
968 bool anIsPreselected = myIsPreselected;
970 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
971 bool anIsChanged = (mySelectionMode != aSelectionMode);
973 if( !theIsHighlight ) {
974 SetPreSelected( false );
976 switch(aSelectionMode){
977 case ActorSelection :
979 // cout << "=============== " << myIO->getEntry() << endl;
980 // int nbio = mySelector->IObjectCount();
981 // cout << " nbio = " << nbio << endl;
983 if( !mySelector->IsSelected( myIO ) ) {
984 // printf ("!!!!!!!!!!!!!!!!\n");
985 SetPreSelected( true );
993 mySelectionMode = aSelectionMode;
994 anIsChanged |= (anIsPreselected != myIsPreselected);
996 SetVisibility(GetVisibility());
1001 To process highlight (called from SVTK_InteractorStyle)
1005 ::Highlight(vtkInteractorStyle *theInteractorStyle,
1006 SVTK_SelectionEvent* theSelectionEvent,
1007 bool theIsHighlight)
1009 // define the selection of object
1010 MESSAGE(std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected=" << myIsSelected);
1012 bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
1013 SetSelected(theIsHighlight);
1015 SetPreSelected(false);
1020 // Copy the follower's composite 4x4 matrix into the matrix provided.
1021 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
1024 double Rx[3], Ry[3], Rz[3], p1[3];
1025 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
1029 this->GetOrientation();
1030 this->Transform->Push();
1031 this->Transform->PostMultiply();
1032 this->Transform->Identity();
1034 // apply user defined matrix last if there is one
1035 if (this->UserMatrix)
1037 this->Transform->Concatenate(this->UserMatrix);
1040 this->Transform->Translate(-this->Origin[0],
1044 this->Transform->Scale(this->Scale[0],
1049 this->Transform->RotateY(this->Orientation[1]);
1050 this->Transform->RotateX(this->Orientation[0]);
1051 this->Transform->RotateZ(this->Orientation[2]);
1057 pos = theCam->GetPosition();
1058 vup = theCam->GetViewUp();
1060 if (theCam->GetParallelProjection())
1062 theCam->GetDirectionOfProjection(Rz);
1067 (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
1068 (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
1069 (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
1070 for (i = 0; i < 3; i++)
1072 Rz[i] = (pos[i] - this->Position[i])/distance;
1076 vtkMath::Cross(vup,Rz,Rx);
1077 vtkMath::Normalize(Rx);
1078 vtkMath::Cross(Rz,Rx,Ry);
1080 matrix->Element[0][0] = Rx[0];
1081 matrix->Element[1][0] = Rx[1];
1082 matrix->Element[2][0] = Rx[2];
1083 matrix->Element[0][1] = Ry[0];
1084 matrix->Element[1][1] = Ry[1];
1085 matrix->Element[2][1] = Ry[2];
1086 matrix->Element[0][2] = Rz[0];
1087 matrix->Element[1][2] = Rz[1];
1088 matrix->Element[2][2] = Rz[2];
1090 this->Transform->Concatenate(matrix);
1093 // translate to projection reference point PRP
1094 // this is the camera's position blasted through
1095 // the current matrix
1096 p1[0] = this->Origin[0] + this->Position[0];
1097 p1[1] = this->Origin[1] + this->Position[1];
1098 p1[2] = this->Origin[2] + this->Position[2];
1100 this->Transform->Translate(p1[0],p1[1],p1[2]);
1101 this->Transform->GetMatrix(result);
1104 this->Transform->Pop();
1107 void GEOM_Actor::SetEdgesInShadingColor(double r,double g,double b)
1109 myEdgesInShadingColor[0] = r;
1110 myEdgesInShadingColor[1] = g;
1111 myEdgesInShadingColor[2] = b;
1114 void GEOM_Actor::SetIsosWidth(const int width) {
1115 myWireframeFaceActor->GetProperty()->SetLineWidth(width);
1118 int GEOM_Actor::GetIsosWidth() const {
1119 return (int)myWireframeFaceActor->GetProperty()->GetLineWidth();
1122 void GEOM_Actor::SetWidth(const int width) {
1123 myIsolatedEdgeActor->GetProperty()->SetLineWidth(width);
1124 myOneFaceEdgeActor->GetProperty()->SetLineWidth(width);
1125 mySharedEdgeActor->GetProperty()->SetLineWidth(width);
1126 myHighlightProp->SetLineWidth(width);
1127 myPreHighlightProp->SetLineWidth(width+1);
1131 int GEOM_Actor::GetWidth() const {
1132 return (int)myIsolatedEdgeActor->GetProperty()->GetLineWidth();
1135 void GEOM_Actor::SetTransform(VTKViewer_Transform* theTransform)
1137 Superclass::SetTransform(theTransform);
1139 myStandaloneVertexActor->SetTransform(theTransform);
1140 myStandaloneVertexActor->SetTransform(theTransform);
1141 myIsolatedEdgeActor->SetTransform(theTransform);
1142 myOneFaceEdgeActor->SetTransform(theTransform);
1143 mySharedEdgeActor->SetTransform(theTransform);
1144 myWireframeFaceActor->SetTransform(theTransform);
1145 myShadingFaceActor->SetTransform(theTransform);
1146 myHighlightActor->SetTransform(theTransform);