1 // Copyright (C) 2007-2014 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 "SVTK_Actor.h"
42 #include <OCC2VTK_Tools.h>
44 #include <vtkObjectFactory.h>
45 #include <vtkRenderer.h>
46 #include <vtkProperty.h>
47 #include <vtkPointPicker.h>
48 #include <vtkCellPicker.h>
50 #include <TopAbs_ShapeEnum.hxx>
51 #include <TopExp_Explorer.hxx>
53 #include <BRep_Tool.hxx>
56 #include <vtkPolyDataWriter.h>
58 #include <vtkAppendPolyData.h>
59 #include <vtkPolyDataMapper.h>
60 #include <vtkPolyData.h>
61 #include <vtkTransform.h>
62 #include <vtkMatrix4x4.h>
64 #include <vtkCamera.h>
66 #include "utilities.h"
68 #include "SALOME_InteractiveObject.hxx"
70 //vtkStandardNewMacro(GEOM_Actor);
76 GEOM_Actor::GEOM_Actor():
82 // myDisplayMode(eWireframe),
85 myVerticesMode(false),
87 myVertexActor(GEOM_DeviceActor::New(),true),
88 myVertexSource(GEOM_VertexSource::New(),true),
90 myIsolatedEdgeActor(GEOM_DeviceActor::New(),true),
91 myIsolatedEdgeSource(GEOM_EdgeSource::New(),true),
93 myOneFaceEdgeActor(GEOM_DeviceActor::New(),true),
94 myOneFaceEdgeSource(GEOM_EdgeSource::New(),true),
96 mySharedEdgeActor(GEOM_DeviceActor::New(),true),
97 mySharedEdgeSource(GEOM_EdgeSource::New(),true),
99 myWireframeFaceActor(GEOM_DeviceActor::New(),true),
100 myWireframeFaceSource(GEOM_WireframeFace::New(),true),
102 myShadingFaceActor(GEOM_DeviceActor::New(),true),
103 myShadingFaceSource(GEOM_ShadingFace::New(),true),
105 myHighlightActor(GEOM_DeviceActor::New(),true),
106 myAppendFilter(vtkAppendPolyData::New(),true),
107 // Use mapper as an instance of GEOM_PainterPolyDataMapper class
108 // to prevent drawing of mappers' content (due to an empty definition
109 // of GEOM_PainterPolyDataMapper::RenderPiece(...)).
110 // !!! Presentation of GEOM_Actor is drawing only with help of actors
111 // defined in this class !!!
112 myPolyDataMapper(GEOM_PainterPolyDataMapper::New(),true),
114 myHighlightProp(vtkProperty::New()),
115 myPreHighlightProp(vtkProperty::New()),
116 myShadingFaceProp(vtkProperty::New()),
117 myShadingBackFaceProp(vtkProperty::New())
120 MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
123 myPolyDataMapper->SetInputConnection(myAppendFilter->GetOutputPort());
124 vtkProperty* aProperty;
126 myHighlightProp->SetAmbient(0.5);
127 myHighlightProp->SetDiffuse(0.3);
128 myHighlightProp->SetSpecular(0.2);
129 myHighlightProp->SetRepresentationToSurface();
130 myHighlightProp->SetAmbientColor(1, 1, 1);
131 myHighlightProp->SetDiffuseColor(1, 1, 1);
132 myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
133 myHighlightProp->SetPointSize(0);
134 myHighlightActor->SetProperty(myHighlightProp.GetPointer());
136 this->myHighlightActor->SetInput(myAppendFilter->GetOutputPort(),false);
138 myPreHighlightProp->SetColor(0,1,1);
139 myPreHighlightProp->SetPointSize(0);
140 myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
141 myPreHighlightProp->SetRepresentationToWireframe();
143 myAppendFilter->AddInputConnection(myVertexSource->GetOutputPort());
144 myVertexActor->SetInput(myVertexSource->GetOutputPort(),false);
145 aProperty = myVertexActor->GetProperty();
146 aProperty->SetRepresentation(VTK_POINTS);
147 aProperty->SetPointSize(3);
148 aProperty->SetColor(1, 1, 0);
150 myAppendFilter->AddInputConnection(myIsolatedEdgeSource->GetOutputPort());
151 myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutputPort(),false);
152 aProperty = myIsolatedEdgeActor->GetProperty();
153 aProperty->SetRepresentation(VTK_WIREFRAME);
154 myIsolatedEdgeColor[0] = 1; myIsolatedEdgeColor[1] = 0; myIsolatedEdgeColor[2] = 0;
155 aProperty->SetColor(myIsolatedEdgeColor[0], myIsolatedEdgeColor[1], myIsolatedEdgeColor[2]);
157 myAppendFilter->AddInputConnection(myOneFaceEdgeSource->GetOutputPort());
158 myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutputPort(),false);
159 aProperty = myOneFaceEdgeActor->GetProperty();
160 aProperty->SetRepresentation(VTK_WIREFRAME);
161 myOneFaceEdgeColor[0] = 0; myOneFaceEdgeColor[1] = 1; myOneFaceEdgeColor[2] = 0;
162 aProperty->SetColor(myOneFaceEdgeColor[0], myOneFaceEdgeColor[1], myOneFaceEdgeColor[2]);
164 myAppendFilter->AddInputConnection(mySharedEdgeSource->GetOutputPort());
165 mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutputPort(),false);
166 aProperty = mySharedEdgeActor->GetProperty();
167 aProperty->SetRepresentation(VTK_WIREFRAME);
168 mySharedEdgeColor[0] = 1; mySharedEdgeColor[1] = 1; mySharedEdgeColor[2] = 0;
169 aProperty->SetColor(mySharedEdgeColor[0], mySharedEdgeColor[1], mySharedEdgeColor[2]);
171 myAppendFilter->AddInputConnection(myWireframeFaceSource->GetOutputPort());
172 myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutputPort(),false);
173 aProperty = myWireframeFaceActor->GetProperty();
174 aProperty->SetRepresentation(VTK_WIREFRAME);
175 aProperty->SetColor(0.5, 0.5, 0.5);
177 myShadingFaceActor->SetInput(myShadingFaceSource->GetOutputPort(),true);
179 myShadingFaceProp->SetRepresentation(VTKViewer::Representation::Surface);
180 myShadingFaceProp->SetInterpolationToGouraud();
181 myShadingFaceProp->SetAmbient(1.0);
182 myShadingFaceProp->SetDiffuse(1.0);
183 myShadingFaceProp->SetSpecular(0.4);
184 myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
185 myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
186 myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
188 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
190 // Toggle display mode
191 setDisplayMode(0); // WIRE FRAME
193 SetVerticesMode(0); //
197 GEOM_Actor::~GEOM_Actor()
200 MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
202 myHighlightProp->Delete();
203 myPreHighlightProp->Delete();
204 myShadingFaceProp->Delete();
205 myShadingBackFaceProp->Delete();
212 GEOM_Actor* anObject = new GEOM_Actor();
213 anObject->SetMapper(anObject->myPolyDataMapper.Get());
218 void Write(vtkPolyData* theDataSet, const char* theFileName){
219 vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
220 MESSAGE ("Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells());
221 aWriter->SetInputData(theDataSet);
222 aWriter->SetFileName(theFileName);
231 this->myVertexSource->Modified();
232 this->myIsolatedEdgeSource->Modified();
233 this->myOneFaceEdgeSource->Modified();
234 this->mySharedEdgeSource->Modified();
235 this->myWireframeFaceSource->Modified();
236 this->myShadingFaceSource->Modified();
241 SetMapper(vtkMapper* theMapper)
243 SALOME_Actor::SetMapper(theMapper);
248 AddToRender(vtkRenderer* theRenderer)
250 //SALOME_Actor::AddToRender(theRenderer);
252 theRenderer->AddActor(this);
254 this->myHighlightActor->AddToRender(theRenderer);
257 myShadingFaceActor->AddToRender(theRenderer);
258 myWireframeFaceActor->AddToRender(theRenderer);
260 mySharedEdgeActor->AddToRender(theRenderer);
261 myOneFaceEdgeActor->AddToRender(theRenderer);
262 myIsolatedEdgeActor->AddToRender(theRenderer);
264 myVertexActor->AddToRender(theRenderer);
269 RemoveFromRender(vtkRenderer* theRenderer)
271 //SALOME_Actor::RemoveFromRender(theRenderer);
274 theRenderer->RemoveActor(this);
276 myHighlightActor->RemoveFromRender(theRenderer);
277 myShadingFaceActor->RemoveFromRender(theRenderer);
278 myWireframeFaceActor->RemoveFromRender(theRenderer);
280 mySharedEdgeActor->RemoveFromRender(theRenderer);
281 myOneFaceEdgeActor->RemoveFromRender(theRenderer);
282 myIsolatedEdgeActor->RemoveFromRender(theRenderer);
284 myVertexActor->RemoveFromRender(theRenderer);
288 SetVisibility(false);
293 setDisplayMode(int theMode)
296 MESSAGE ( "GEOM_Actor::setDisplayMode = "<<theMode );
299 if ( theMode == (int)eShadingWithEdges ) {
301 myIsolatedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
302 myIsolatedEdgeColor[1],
303 myIsolatedEdgeColor[2]);
304 myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
305 myEdgesInShadingColor[1],
306 myEdgesInShadingColor[2]);
307 mySharedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
308 myEdgesInShadingColor[1],
309 myEdgesInShadingColor[2]);
313 myIsolatedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
314 myIsolatedEdgeColor[1],
315 myIsolatedEdgeColor[2]);
316 mySharedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
317 myIsolatedEdgeColor[1],
318 myIsolatedEdgeColor[2]);
319 myOneFaceEdgeActor->GetProperty()->SetColor(myOneFaceEdgeColor[0],
320 myOneFaceEdgeColor[1],
321 myOneFaceEdgeColor[2]);
324 VTKViewer_Actor::setDisplayMode(theMode);
325 SetVisibility(GetVisibility());
330 SetSelected(bool theIsSelected)
333 MESSAGE ( "GEOM_Actor::SetSelected = "<<theIsSelected );
336 myIsSelected = theIsSelected;
337 SetVisibility(GetVisibility());
342 SetVisibility(int theVisibility)
345 MESSAGE ( "GEOM_Actor::SetVisibility = "<<theVisibility <<" myIsSelected="<< myIsSelected
346 << " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected );
349 SALOME_Actor::SetVisibility(theVisibility);
351 this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
353 myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges) && (!myIsSelected || !myIsPreselected));
354 myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe) && !myIsSelected);
356 mySharedEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
357 myOneFaceEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
358 myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
360 myVertexActor->SetVisibility(theVisibility && myVerticesMode && (!myIsSelected && !myIsPreselected));// must be added new mode points
366 ::SetNbIsos(const int theNb[2])
368 myWireframeFaceSource->SetNbIso(theNb);
373 ::GetNbIsos(int &theNbU,int &theNbV)
375 myWireframeFaceSource->GetNbIso(theNbU, theNbV);
380 ::SetVectorMode(bool theMode)
382 myVectorMode = theMode;
383 myIsolatedEdgeSource->SetVectorMode(theMode);
384 myOneFaceEdgeSource->SetVectorMode(theMode);
385 mySharedEdgeSource->SetVectorMode(theMode);
398 ::SetVerticesMode(bool theMode)
400 myVerticesMode = theMode;
401 theMode ? myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2) : myPreHighlightProp->SetPointSize(0);
402 theMode ? myHighlightProp->SetPointSize(SALOME_POINT_SIZE) : myHighlightProp->SetPointSize(0);
410 return myVerticesMode;
415 SetDeflection(float theDeflection)
417 if( myDeflection == theDeflection )
420 myDeflection = theDeflection;
422 GEOM::MeshShape(myShape,myDeflection);
427 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
433 myVertexSource->Clear();
434 myIsolatedEdgeSource->Clear();
435 myOneFaceEdgeSource->Clear();
436 mySharedEdgeSource->Clear();
437 myWireframeFaceSource->Clear();
438 myShadingFaceSource->Clear();
440 TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
441 for (; aVertexExp.More(); aVertexExp.Next())
443 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
444 myVertexSource->AddVertex(aVertex);
447 SetDeflection(theDeflection);
449 // look if edges are free or shared
450 TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
451 TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
453 GEOM::SetShape(theShape,anEdgeMap,theIsVector,
454 myIsolatedEdgeSource.Get(),
455 myOneFaceEdgeSource.Get(),
456 mySharedEdgeSource.Get(),
457 myWireframeFaceSource.Get(),
458 myShadingFaceSource.Get());
460 myIsolatedEdgeSource->IsEmpty() &&
461 myOneFaceEdgeSource->IsEmpty() &&
462 mySharedEdgeSource->IsEmpty() &&
463 myWireframeFaceSource->IsEmpty() &&
464 myShadingFaceSource->IsEmpty();
467 if((bool)myShape.Infinite() || isOnlyVertex ){
468 myVertexActor->GetDeviceActor()->SetInfinitive(true);
469 myHighlightActor->GetDeviceActor()->SetInfinitive(true);
472 // 0051777: TC7.2.0: Element could not be selected in Hypothesis Construction
473 myAppendFilter->Update();
477 void GEOM_Actor::setDeflection(double adef) {
479 MESSAGE ( "GEOM_Actor::setDeflection" );
481 SetDeflection((float)adef);
485 // warning! must be checked!
486 // SetHighlightProperty
487 // SetWireframeProperty
488 // SetShadingProperty
490 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
493 MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
495 this->myHighlightActor->GetProperty()->DeepCopy(Prop);
499 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
502 MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
505 myWireframeFaceActor->SetProperty(Prop);
509 vtkProperty* GEOM_Actor::GetWireframeProperty()
511 return myWireframeFaceActor->GetProperty();
514 vtkProperty* GEOM_Actor::GetIsolatedEdgeProperty()
516 return myIsolatedEdgeActor->GetProperty();
519 vtkProperty* GEOM_Actor::GetVertexProperty()
521 return myVertexActor->GetProperty();
524 vtkProperty* GEOM_Actor::GetSharedEdgeProperty()
526 return mySharedEdgeActor->GetProperty();
529 vtkProperty* GEOM_Actor::GetFaceEdgeProperty()
531 return myOneFaceEdgeActor->GetProperty();
534 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
537 MESSAGE ( "GEOM_Actor::SetShadingProperty" );
539 myShadingFaceProp->DeepCopy(Prop);
543 vtkProperty* GEOM_Actor::GetShadingProperty()
545 return myShadingFaceProp;
549 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
552 MESSAGE ( "GEOM_Actor::Render" );
558 /* render the property */
559 if (!this->Property) {
560 // force creation of a property
562 this->Property->SetInterpolation(1);
563 this->Property->SetRepresentationToSurface();
564 this->Property->SetAmbient(0.3);
565 this->Property->SetAmbientColor(0.88,0.86,0.2);
566 this->Property->SetDiffuseColor(0.99,0.7,0.21);
567 this->Property->SetSpecularColor(0.99,0.98,0.83);
570 switch(myDisplayMode){
571 case eWireframe://wireframe
572 myPreHighlightProp->SetRepresentationToWireframe();
573 myHighlightProp->SetRepresentationToWireframe();
575 case eShading://shading
576 case eShadingWithEdges://shading with edges
577 myPreHighlightProp->SetRepresentationToSurface();
578 myHighlightProp->SetRepresentationToSurface();
579 myShadingFaceProp->SetRepresentationToSurface();
580 myShadingBackFaceProp->SetRepresentationToSurface();
586 this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
587 myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
588 myShadingFaceActor->SetBackfaceProperty(myPreHighlightProp.GetPointer());
590 this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
591 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
592 myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
596 this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
597 myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
598 myShadingFaceActor->SetBackfaceProperty(myHighlightProp.GetPointer());
601 this->Property->Render(this, ren);
602 if (this->BackfaceProperty) {
603 this->BackfaceProperty->BackfaceRender(this, ren);
604 this->Device->SetBackfaceProperty(this->BackfaceProperty);
606 this->Device->SetProperty(this->Property);
607 /* if(myShape.ShapeType() == TopAbs_VERTEX) {
609 //The parameter determine size of vertex actor relate to diagonal of RendererWindow
610 static double delta = 0.01;
611 double X1 = -1, Y1 = -1, Z1 = 0;
612 ren->ViewToWorld(X1,Y1,Z1);
613 double X2 = +1, Y2 = +1, Z2 = 0;
614 ren->ViewToWorld(X2,Y2,Z2);
615 Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
616 this->SetScale(Z2*delta);
618 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
619 this->GetMatrix(ren->GetActiveCamera(), aMatrix);
620 this->Device->SetUserMatrix(aMatrix);
621 this->Device->Render(ren,theMapper);
624 this->Device->Render(ren, theMapper);
627 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
630 MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
636 void GEOM_Actor::ShallowCopy(vtkProp *prop)
639 MESSAGE ( "GEOM_Actor::ShallowCopy" );
641 GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
644 this->SetShape(f->getTopo(),f->GetDeflection());
648 this->SALOME_Actor::ShallowCopy(prop);
651 const TopoDS_Shape& GEOM_Actor::getTopo() {
653 MESSAGE ( "GEOM_Actor::getTopo" );
658 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
659 int imode, bool isVector)
662 MESSAGE ( "GEOM_Actor::setInputShape" );
666 double GEOM_Actor::getDeflection()
669 MESSAGE ( "GEOM_Actor::getDeflection" );
671 return (double) GetDeflection();
675 double GEOM_Actor::isVector()
678 MESSAGE ( "GEOM_Actor::isVector" );
683 void GEOM_Actor::SubShapeOn()
686 MESSAGE ( "GEOM_Actor::SubShapeOn" );
690 void GEOM_Actor::SubShapeOff()
693 MESSAGE ( "GEOM_Actor::SubShapeOff" );
697 void GEOM_Actor::highlight(bool highlight)
700 MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
702 SALOME_Actor::highlight(highlight);
705 void GEOM_Actor::SetOpacity(double opa)
708 myShadingFaceProp->SetOpacity(opa);
709 myShadingBackFaceProp->SetOpacity(opa);
710 myHighlightProp->SetOpacity(opa);
711 myPreHighlightProp->SetOpacity(opa);
712 myVertexActor->GetProperty()->SetOpacity(opa);
715 double GEOM_Actor::GetOpacity()
718 return myShadingFaceProp->GetOpacity();
721 void GEOM_Actor::SetColor(double r,double g,double b)
723 // set the same color to all sub-actors:
725 // - standalone edges
728 // - shading color (front and back faces)
729 SetPointColor(r, g, b);
730 SetIsolatedEdgeColor(r, g, b);
731 SetSharedEdgeColor(r, g, b);
732 SetFreeEdgeColor(r, g, b);
733 myShadingFaceProp->SetColor(r,g,b); // shading color
734 myShadingBackFaceProp->SetColor(r,g,b); // back face shading color
737 void GEOM_Actor::GetColor(double& r,double& g,double& b)
740 myShadingFaceProp->GetColor(aRGB);
747 \brief Set color of points
748 Points actor is shown in Wireframe mode only, see SetVisibility()
750 void GEOM_Actor::SetPointColor(double r, double g, double b)
752 myVertexActor->GetProperty()->SetColor(r, g, b);
756 \brief Set color of standalone edges, wires, vectors
757 This actor is shown in all display mode, see SetVisibility()
758 TODO: check - this color seems to be used not only for standalone edges
760 void GEOM_Actor::SetIsolatedEdgeColor(double r, double g, double b)
762 myIsolatedEdgeColor[0] = r; myIsolatedEdgeColor[1] = g; myIsolatedEdgeColor[2] = b;
763 myIsolatedEdgeActor->GetProperty()->SetColor(r, g, b);
767 \brief Set color of shared edges
768 This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
769 TODO: check - this seems to be not working currently
771 void GEOM_Actor::SetSharedEdgeColor(double r, double g, double b)
773 mySharedEdgeColor[0] = r; mySharedEdgeColor[1] = g; mySharedEdgeColor[2] = b;
774 if ( myDisplayMode != (int)eShadingWithEdges )
775 mySharedEdgeActor->GetProperty()->SetColor(r, g, b);
779 \brief Set color of edges for standalone faces
780 This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
781 TODO: this color should be used not only for faces
783 void GEOM_Actor::SetFreeEdgeColor(double r, double g, double b)
785 myOneFaceEdgeColor[0] = r; myOneFaceEdgeColor[1] = g; myOneFaceEdgeColor[2] = b;
786 if ( myDisplayMode != (int)eShadingWithEdges )
787 myOneFaceEdgeActor->GetProperty()->SetColor(r, g, b);
791 \brief Set color of iso-lines
792 This actor is shown only in wireframe display mode, see SetVisibility()
794 void GEOM_Actor::SetIsosColor(double r, double g, double b)
796 myWireframeFaceActor->GetProperty()->SetColor(r, g, b);
799 void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
801 // we set material properties as back and front material
802 int aSize = theProps.size();
804 if ( aSize < 1 || aSize > 2)
807 // theProps[0] -- front material properties
808 // theProps[1] -- back material properties (if exist)
812 // Set reflection coefficients
813 aCoefnt = theProps[0]->GetAmbient();
814 myShadingFaceProp->SetAmbient(aCoefnt);
815 myVertexActor->GetProperty()->SetAmbient(aCoefnt);
817 aCoefnt = theProps[1]->GetAmbient();
818 myShadingBackFaceProp->SetAmbient(aCoefnt);
820 // Set diffuse coefficients
821 aCoefnt = theProps[0]->GetDiffuse();
822 myShadingFaceProp->SetDiffuse(aCoefnt);
823 myVertexActor->GetProperty()->SetDiffuse(aCoefnt);
825 aCoefnt = theProps[1]->GetDiffuse();
826 myShadingBackFaceProp->SetDiffuse(aCoefnt);
828 // Set specular coefficients
829 aCoefnt = theProps[0]->GetSpecular();
830 myShadingFaceProp->SetSpecular(aCoefnt);
831 myVertexActor->GetProperty()->SetSpecular(aCoefnt);
833 aCoefnt = theProps[1]->GetSpecular();
834 myShadingBackFaceProp->SetSpecular(aCoefnt);
839 // Set reflection colors
840 aColor = theProps[0]->GetAmbientColor();
841 myShadingFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
842 myVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
844 aColor = theProps[1]->GetAmbientColor();
845 myShadingBackFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
847 // Set diffuse colors
848 aColor = theProps[0]->GetDiffuseColor();
849 myShadingFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
850 myVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
852 aColor = theProps[1]->GetDiffuseColor();
853 myShadingBackFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
855 // Set specular colors
856 aColor = theProps[0]->GetSpecularColor();
857 myShadingFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
858 myVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
860 aColor = theProps[1]->GetSpecularColor();
861 myShadingBackFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
864 aCoefnt = theProps[0]->GetSpecularPower();
865 myShadingFaceProp->SetSpecularPower(aCoefnt);
866 myVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
868 aCoefnt = theProps[1]->GetSpecularPower();
869 myShadingBackFaceProp->SetSpecularPower(aCoefnt);
871 // Set back face material property
872 myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
875 vtkProperty* GEOM_Actor::GetFrontMaterial()
877 return myShadingFaceProp;
880 vtkProperty* GEOM_Actor::GetBackMaterial()
882 return myShadingBackFaceProp;
885 bool GEOM_Actor::IsInfinitive()
887 return ((bool)myShape.Infinite() || isOnlyVertex);
891 To map current selection to VTK representation
895 ::Highlight(bool theIsHighlight)
897 myIsSelected = theIsHighlight;
899 MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
902 SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
903 SetVisibility(GetVisibility());
907 To process prehighlight (called from SVTK_InteractorStyle)
911 ::PreHighlight(vtkInteractorStyle *theInteractorStyle,
912 SVTK_SelectionEvent* theSelectionEvent,
916 MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
919 if ( !GetPickable() )
922 myPreHighlightActor->SetVisibility( false );
923 bool anIsPreselected = myIsPreselected;
925 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
926 bool anIsChanged = (mySelectionMode != aSelectionMode);
928 if( !theIsHighlight ) {
929 SetPreSelected( false );
931 switch(aSelectionMode){
932 case ActorSelection :
934 // cout << "=============== " << myIO->getEntry() << endl;
935 // int nbio = mySelector->IObjectCount();
936 // cout << " nbio = " << nbio << endl;
938 if( !mySelector->IsSelected( myIO ) ) {
939 // printf ("!!!!!!!!!!!!!!!!\n");
940 SetPreSelected( true );
948 mySelectionMode = aSelectionMode;
949 anIsChanged |= (anIsPreselected != myIsPreselected);
951 SetVisibility(GetVisibility());
956 To process highlight (called from SVTK_InteractorStyle)
960 ::Highlight(vtkInteractorStyle *theInteractorStyle,
961 SVTK_SelectionEvent* theSelectionEvent,
964 // define the selection of object
966 MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
968 bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
969 SetSelected(theIsHighlight);
971 SetPreSelected(false);
977 // Copy the follower's composite 4x4 matrix into the matrix provided.
978 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
981 double Rx[3], Ry[3], Rz[3], p1[3];
982 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
986 this->GetOrientation();
987 this->Transform->Push();
988 this->Transform->PostMultiply();
989 this->Transform->Identity();
991 // apply user defined matrix last if there is one
992 if (this->UserMatrix)
994 this->Transform->Concatenate(this->UserMatrix);
997 this->Transform->Translate(-this->Origin[0],
1001 this->Transform->Scale(this->Scale[0],
1006 this->Transform->RotateY(this->Orientation[1]);
1007 this->Transform->RotateX(this->Orientation[0]);
1008 this->Transform->RotateZ(this->Orientation[2]);
1014 pos = theCam->GetPosition();
1015 vup = theCam->GetViewUp();
1017 if (theCam->GetParallelProjection())
1019 theCam->GetDirectionOfProjection(Rz);
1024 (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
1025 (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
1026 (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
1027 for (i = 0; i < 3; i++)
1029 Rz[i] = (pos[i] - this->Position[i])/distance;
1033 vtkMath::Cross(vup,Rz,Rx);
1034 vtkMath::Normalize(Rx);
1035 vtkMath::Cross(Rz,Rx,Ry);
1037 matrix->Element[0][0] = Rx[0];
1038 matrix->Element[1][0] = Rx[1];
1039 matrix->Element[2][0] = Rx[2];
1040 matrix->Element[0][1] = Ry[0];
1041 matrix->Element[1][1] = Ry[1];
1042 matrix->Element[2][1] = Ry[2];
1043 matrix->Element[0][2] = Rz[0];
1044 matrix->Element[1][2] = Rz[1];
1045 matrix->Element[2][2] = Rz[2];
1047 this->Transform->Concatenate(matrix);
1050 // translate to projection reference point PRP
1051 // this is the camera's position blasted through
1052 // the current matrix
1053 p1[0] = this->Origin[0] + this->Position[0];
1054 p1[1] = this->Origin[1] + this->Position[1];
1055 p1[2] = this->Origin[2] + this->Position[2];
1057 this->Transform->Translate(p1[0],p1[1],p1[2]);
1058 this->Transform->GetMatrix(result);
1061 this->Transform->Pop();
1064 void GEOM_Actor::SetEdgesInShadingColor(double r,double g,double b)
1066 myEdgesInShadingColor[0] = r;
1067 myEdgesInShadingColor[1] = g;
1068 myEdgesInShadingColor[2] = b;
1071 void GEOM_Actor::SetIsosWidth(const int width) {
1072 myWireframeFaceActor->GetProperty()->SetLineWidth(width);
1075 int GEOM_Actor::GetIsosWidth() const {
1076 return (int)myWireframeFaceActor->GetProperty()->GetLineWidth();
1079 void GEOM_Actor::SetWidth(const int width) {
1080 myIsolatedEdgeActor->GetProperty()->SetLineWidth(width);
1081 myOneFaceEdgeActor->GetProperty()->SetLineWidth(width);
1082 mySharedEdgeActor->GetProperty()->SetLineWidth(width);
1083 myHighlightProp->SetLineWidth(width);
1084 myPreHighlightProp->SetLineWidth(width+1);
1088 int GEOM_Actor::GetWidth() const {
1089 return (int)myIsolatedEdgeActor->GetProperty()->GetLineWidth();