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 && (isOnlyVertex || (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 if ( theMode || isOnlyVertex ) {
402 myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
403 myHighlightProp->SetPointSize(SALOME_POINT_SIZE);
405 myPreHighlightProp->SetPointSize(0);
406 myHighlightProp->SetPointSize(0);
415 return myVerticesMode;
420 SetDeflection(float theDeflection)
422 if( myDeflection == theDeflection )
425 myDeflection = theDeflection;
427 GEOM::MeshShape(myShape,myDeflection);
432 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
438 myVertexSource->Clear();
439 myIsolatedEdgeSource->Clear();
440 myOneFaceEdgeSource->Clear();
441 mySharedEdgeSource->Clear();
442 myWireframeFaceSource->Clear();
443 myShadingFaceSource->Clear();
445 TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
446 for (; aVertexExp.More(); aVertexExp.Next())
448 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
449 myVertexSource->AddVertex(aVertex);
452 SetDeflection(theDeflection);
454 // look if edges are free or shared
455 TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
456 TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
458 GEOM::SetShape(theShape,anEdgeMap,theIsVector,
459 myIsolatedEdgeSource.Get(),
460 myOneFaceEdgeSource.Get(),
461 mySharedEdgeSource.Get(),
462 myWireframeFaceSource.Get(),
463 myShadingFaceSource.Get());
465 myIsolatedEdgeSource->IsEmpty() &&
466 myOneFaceEdgeSource->IsEmpty() &&
467 mySharedEdgeSource->IsEmpty() &&
468 myWireframeFaceSource->IsEmpty() &&
469 myShadingFaceSource->IsEmpty();
472 if((bool)myShape.Infinite() || isOnlyVertex ){
473 myVertexActor->GetDeviceActor()->SetInfinitive(true);
474 myHighlightActor->GetDeviceActor()->SetInfinitive(true);
477 // 0051777: TC7.2.0: Element could not be selected in Hypothesis Construction
478 myAppendFilter->Update();
482 void GEOM_Actor::setDeflection(double adef) {
484 MESSAGE ( "GEOM_Actor::setDeflection" );
486 SetDeflection((float)adef);
490 // warning! must be checked!
491 // SetHighlightProperty
492 // SetWireframeProperty
493 // SetShadingProperty
495 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
498 MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
500 this->myHighlightActor->GetProperty()->DeepCopy(Prop);
504 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
507 MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
510 myWireframeFaceActor->SetProperty(Prop);
514 vtkProperty* GEOM_Actor::GetWireframeProperty()
516 return myWireframeFaceActor->GetProperty();
519 vtkProperty* GEOM_Actor::GetIsolatedEdgeProperty()
521 return myIsolatedEdgeActor->GetProperty();
524 vtkProperty* GEOM_Actor::GetVertexProperty()
526 return myVertexActor->GetProperty();
529 vtkProperty* GEOM_Actor::GetSharedEdgeProperty()
531 return mySharedEdgeActor->GetProperty();
534 vtkProperty* GEOM_Actor::GetFaceEdgeProperty()
536 return myOneFaceEdgeActor->GetProperty();
539 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
542 MESSAGE ( "GEOM_Actor::SetShadingProperty" );
544 myShadingFaceProp->DeepCopy(Prop);
548 vtkProperty* GEOM_Actor::GetShadingProperty()
550 return myShadingFaceProp;
554 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
557 MESSAGE ( "GEOM_Actor::Render" );
563 /* render the property */
564 if (!this->Property) {
565 // force creation of a property
567 this->Property->SetInterpolation(1);
568 this->Property->SetRepresentationToSurface();
569 this->Property->SetAmbient(0.3);
570 this->Property->SetAmbientColor(0.88,0.86,0.2);
571 this->Property->SetDiffuseColor(0.99,0.7,0.21);
572 this->Property->SetSpecularColor(0.99,0.98,0.83);
575 switch(myDisplayMode){
576 case eWireframe://wireframe
577 myPreHighlightProp->SetRepresentationToWireframe();
578 myHighlightProp->SetRepresentationToWireframe();
580 case eShading://shading
581 case eShadingWithEdges://shading with edges
582 myPreHighlightProp->SetRepresentationToSurface();
583 myHighlightProp->SetRepresentationToSurface();
584 myShadingFaceProp->SetRepresentationToSurface();
585 myShadingBackFaceProp->SetRepresentationToSurface();
591 this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
592 myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
593 myShadingFaceActor->SetBackfaceProperty(myPreHighlightProp.GetPointer());
595 this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
596 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
597 myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
601 this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
602 myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
603 myShadingFaceActor->SetBackfaceProperty(myHighlightProp.GetPointer());
606 this->Property->Render(this, ren);
607 if (this->BackfaceProperty) {
608 this->BackfaceProperty->BackfaceRender(this, ren);
609 this->Device->SetBackfaceProperty(this->BackfaceProperty);
611 this->Device->SetProperty(this->Property);
612 /* if(myShape.ShapeType() == TopAbs_VERTEX) {
614 //The parameter determine size of vertex actor relate to diagonal of RendererWindow
615 static double delta = 0.01;
616 double X1 = -1, Y1 = -1, Z1 = 0;
617 ren->ViewToWorld(X1,Y1,Z1);
618 double X2 = +1, Y2 = +1, Z2 = 0;
619 ren->ViewToWorld(X2,Y2,Z2);
620 Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
621 this->SetScale(Z2*delta);
623 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
624 this->GetMatrix(ren->GetActiveCamera(), aMatrix);
625 this->Device->SetUserMatrix(aMatrix);
626 this->Device->Render(ren,theMapper);
629 this->Device->Render(ren, theMapper);
632 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
635 MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
641 void GEOM_Actor::ShallowCopy(vtkProp *prop)
644 MESSAGE ( "GEOM_Actor::ShallowCopy" );
646 GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
649 this->SetShape(f->getTopo(),f->GetDeflection());
653 this->SALOME_Actor::ShallowCopy(prop);
656 const TopoDS_Shape& GEOM_Actor::getTopo() {
658 MESSAGE ( "GEOM_Actor::getTopo" );
663 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
664 int imode, bool isVector)
667 MESSAGE ( "GEOM_Actor::setInputShape" );
671 double GEOM_Actor::getDeflection()
674 MESSAGE ( "GEOM_Actor::getDeflection" );
676 return (double) GetDeflection();
680 double GEOM_Actor::isVector()
683 MESSAGE ( "GEOM_Actor::isVector" );
688 void GEOM_Actor::SubShapeOn()
691 MESSAGE ( "GEOM_Actor::SubShapeOn" );
695 void GEOM_Actor::SubShapeOff()
698 MESSAGE ( "GEOM_Actor::SubShapeOff" );
702 void GEOM_Actor::highlight(bool highlight)
705 MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
707 SALOME_Actor::highlight(highlight);
710 void GEOM_Actor::SetOpacity(double opa)
713 myShadingFaceProp->SetOpacity(opa);
714 myShadingBackFaceProp->SetOpacity(opa);
715 myHighlightProp->SetOpacity(opa);
716 myPreHighlightProp->SetOpacity(opa);
717 myVertexActor->GetProperty()->SetOpacity(opa);
720 double GEOM_Actor::GetOpacity()
723 return myShadingFaceProp->GetOpacity();
726 void GEOM_Actor::SetColor(double r,double g,double b)
728 // set the same color to all sub-actors:
730 // - standalone edges
733 // - shading color (front and back faces)
734 SetPointColor(r, g, b);
735 SetIsolatedEdgeColor(r, g, b);
736 SetSharedEdgeColor(r, g, b);
737 SetFreeEdgeColor(r, g, b);
738 myShadingFaceProp->SetColor(r,g,b); // shading color
739 myShadingBackFaceProp->SetColor(r,g,b); // back face shading color
742 void GEOM_Actor::GetColor(double& r,double& g,double& b)
745 myShadingFaceProp->GetColor(aRGB);
752 \brief Set color of points
753 Points actor is shown in Wireframe mode only, see SetVisibility()
755 void GEOM_Actor::SetPointColor(double r, double g, double b)
757 myVertexActor->GetProperty()->SetColor(r, g, b);
761 \brief Set color of standalone edges, wires, vectors
762 This actor is shown in all display mode, see SetVisibility()
763 TODO: check - this color seems to be used not only for standalone edges
765 void GEOM_Actor::SetIsolatedEdgeColor(double r, double g, double b)
767 myIsolatedEdgeColor[0] = r; myIsolatedEdgeColor[1] = g; myIsolatedEdgeColor[2] = b;
768 myIsolatedEdgeActor->GetProperty()->SetColor(r, g, b);
772 \brief Set color of shared edges
773 This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
774 TODO: check - this seems to be not working currently
776 void GEOM_Actor::SetSharedEdgeColor(double r, double g, double b)
778 mySharedEdgeColor[0] = r; mySharedEdgeColor[1] = g; mySharedEdgeColor[2] = b;
779 if ( myDisplayMode != (int)eShadingWithEdges )
780 mySharedEdgeActor->GetProperty()->SetColor(r, g, b);
784 \brief Set color of edges for standalone faces
785 This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
786 TODO: this color should be used not only for faces
788 void GEOM_Actor::SetFreeEdgeColor(double r, double g, double b)
790 myOneFaceEdgeColor[0] = r; myOneFaceEdgeColor[1] = g; myOneFaceEdgeColor[2] = b;
791 if ( myDisplayMode != (int)eShadingWithEdges )
792 myOneFaceEdgeActor->GetProperty()->SetColor(r, g, b);
796 \brief Set color of iso-lines
797 This actor is shown only in wireframe display mode, see SetVisibility()
799 void GEOM_Actor::SetIsosColor(double r, double g, double b)
801 myWireframeFaceActor->GetProperty()->SetColor(r, g, b);
804 void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
806 // we set material properties as back and front material
807 int aSize = theProps.size();
809 if ( aSize < 1 || aSize > 2)
812 // theProps[0] -- front material properties
813 // theProps[1] -- back material properties (if exist)
817 // Set reflection coefficients
818 aCoefnt = theProps[0]->GetAmbient();
819 myShadingFaceProp->SetAmbient(aCoefnt);
820 myVertexActor->GetProperty()->SetAmbient(aCoefnt);
822 aCoefnt = theProps[1]->GetAmbient();
823 myShadingBackFaceProp->SetAmbient(aCoefnt);
825 // Set diffuse coefficients
826 aCoefnt = theProps[0]->GetDiffuse();
827 myShadingFaceProp->SetDiffuse(aCoefnt);
828 myVertexActor->GetProperty()->SetDiffuse(aCoefnt);
830 aCoefnt = theProps[1]->GetDiffuse();
831 myShadingBackFaceProp->SetDiffuse(aCoefnt);
833 // Set specular coefficients
834 aCoefnt = theProps[0]->GetSpecular();
835 myShadingFaceProp->SetSpecular(aCoefnt);
836 myVertexActor->GetProperty()->SetSpecular(aCoefnt);
838 aCoefnt = theProps[1]->GetSpecular();
839 myShadingBackFaceProp->SetSpecular(aCoefnt);
844 // Set reflection colors
845 aColor = theProps[0]->GetAmbientColor();
846 myShadingFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
847 myVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
849 aColor = theProps[1]->GetAmbientColor();
850 myShadingBackFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
852 // Set diffuse colors
853 aColor = theProps[0]->GetDiffuseColor();
854 myShadingFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
855 myVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
857 aColor = theProps[1]->GetDiffuseColor();
858 myShadingBackFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
860 // Set specular colors
861 aColor = theProps[0]->GetSpecularColor();
862 myShadingFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
863 myVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
865 aColor = theProps[1]->GetSpecularColor();
866 myShadingBackFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
869 aCoefnt = theProps[0]->GetSpecularPower();
870 myShadingFaceProp->SetSpecularPower(aCoefnt);
871 myVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
873 aCoefnt = theProps[1]->GetSpecularPower();
874 myShadingBackFaceProp->SetSpecularPower(aCoefnt);
876 // Set back face material property
877 myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
880 vtkProperty* GEOM_Actor::GetFrontMaterial()
882 return myShadingFaceProp;
885 vtkProperty* GEOM_Actor::GetBackMaterial()
887 return myShadingBackFaceProp;
890 bool GEOM_Actor::IsInfinitive()
892 return ((bool)myShape.Infinite() || isOnlyVertex);
896 To map current selection to VTK representation
900 ::Highlight(bool theIsHighlight)
902 myIsSelected = theIsHighlight;
904 MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
907 SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
908 SetVisibility(GetVisibility());
912 To process prehighlight (called from SVTK_InteractorStyle)
916 ::PreHighlight(vtkInteractorStyle *theInteractorStyle,
917 SVTK_SelectionEvent* theSelectionEvent,
921 MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
924 if ( !GetPickable() )
927 myPreHighlightActor->SetVisibility( false );
928 bool anIsPreselected = myIsPreselected;
930 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
931 bool anIsChanged = (mySelectionMode != aSelectionMode);
933 if( !theIsHighlight ) {
934 SetPreSelected( false );
936 switch(aSelectionMode){
937 case ActorSelection :
939 // cout << "=============== " << myIO->getEntry() << endl;
940 // int nbio = mySelector->IObjectCount();
941 // cout << " nbio = " << nbio << endl;
943 if( !mySelector->IsSelected( myIO ) ) {
944 // printf ("!!!!!!!!!!!!!!!!\n");
945 SetPreSelected( true );
953 mySelectionMode = aSelectionMode;
954 anIsChanged |= (anIsPreselected != myIsPreselected);
956 SetVisibility(GetVisibility());
961 To process highlight (called from SVTK_InteractorStyle)
965 ::Highlight(vtkInteractorStyle *theInteractorStyle,
966 SVTK_SelectionEvent* theSelectionEvent,
969 // define the selection of object
971 MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
973 bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
974 SetSelected(theIsHighlight);
976 SetPreSelected(false);
982 // Copy the follower's composite 4x4 matrix into the matrix provided.
983 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
986 double Rx[3], Ry[3], Rz[3], p1[3];
987 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
991 this->GetOrientation();
992 this->Transform->Push();
993 this->Transform->PostMultiply();
994 this->Transform->Identity();
996 // apply user defined matrix last if there is one
997 if (this->UserMatrix)
999 this->Transform->Concatenate(this->UserMatrix);
1002 this->Transform->Translate(-this->Origin[0],
1006 this->Transform->Scale(this->Scale[0],
1011 this->Transform->RotateY(this->Orientation[1]);
1012 this->Transform->RotateX(this->Orientation[0]);
1013 this->Transform->RotateZ(this->Orientation[2]);
1019 pos = theCam->GetPosition();
1020 vup = theCam->GetViewUp();
1022 if (theCam->GetParallelProjection())
1024 theCam->GetDirectionOfProjection(Rz);
1029 (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
1030 (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
1031 (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
1032 for (i = 0; i < 3; i++)
1034 Rz[i] = (pos[i] - this->Position[i])/distance;
1038 vtkMath::Cross(vup,Rz,Rx);
1039 vtkMath::Normalize(Rx);
1040 vtkMath::Cross(Rz,Rx,Ry);
1042 matrix->Element[0][0] = Rx[0];
1043 matrix->Element[1][0] = Rx[1];
1044 matrix->Element[2][0] = Rx[2];
1045 matrix->Element[0][1] = Ry[0];
1046 matrix->Element[1][1] = Ry[1];
1047 matrix->Element[2][1] = Ry[2];
1048 matrix->Element[0][2] = Rz[0];
1049 matrix->Element[1][2] = Rz[1];
1050 matrix->Element[2][2] = Rz[2];
1052 this->Transform->Concatenate(matrix);
1055 // translate to projection reference point PRP
1056 // this is the camera's position blasted through
1057 // the current matrix
1058 p1[0] = this->Origin[0] + this->Position[0];
1059 p1[1] = this->Origin[1] + this->Position[1];
1060 p1[2] = this->Origin[2] + this->Position[2];
1062 this->Transform->Translate(p1[0],p1[1],p1[2]);
1063 this->Transform->GetMatrix(result);
1066 this->Transform->Pop();
1069 void GEOM_Actor::SetEdgesInShadingColor(double r,double g,double b)
1071 myEdgesInShadingColor[0] = r;
1072 myEdgesInShadingColor[1] = g;
1073 myEdgesInShadingColor[2] = b;
1076 void GEOM_Actor::SetIsosWidth(const int width) {
1077 myWireframeFaceActor->GetProperty()->SetLineWidth(width);
1080 int GEOM_Actor::GetIsosWidth() const {
1081 return (int)myWireframeFaceActor->GetProperty()->GetLineWidth();
1084 void GEOM_Actor::SetWidth(const int width) {
1085 myIsolatedEdgeActor->GetProperty()->SetLineWidth(width);
1086 myOneFaceEdgeActor->GetProperty()->SetLineWidth(width);
1087 mySharedEdgeActor->GetProperty()->SetLineWidth(width);
1088 myHighlightProp->SetLineWidth(width);
1089 myPreHighlightProp->SetLineWidth(width+1);
1093 int GEOM_Actor::GetWidth() const {
1094 return (int)myIsolatedEdgeActor->GetProperty()->GetLineWidth();