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 myStandaloneVertexActor(GEOM_DeviceActor::New(),true),
91 myStandaloneVertexSource(GEOM_VertexSource::New(),true),
93 myIsolatedEdgeActor(GEOM_DeviceActor::New(),true),
94 myIsolatedEdgeSource(GEOM_EdgeSource::New(),true),
96 myOneFaceEdgeActor(GEOM_DeviceActor::New(),true),
97 myOneFaceEdgeSource(GEOM_EdgeSource::New(),true),
99 mySharedEdgeActor(GEOM_DeviceActor::New(),true),
100 mySharedEdgeSource(GEOM_EdgeSource::New(),true),
102 myWireframeFaceActor(GEOM_DeviceActor::New(),true),
103 myWireframeFaceSource(GEOM_WireframeFace::New(),true),
105 myShadingFaceActor(GEOM_DeviceActor::New(),true),
106 myShadingFaceSource(GEOM_ShadingFace::New(),true),
108 myHighlightActor(GEOM_DeviceActor::New(),true),
109 myAppendFilter(vtkAppendPolyData::New(),true),
110 // Use mapper as an instance of GEOM_PainterPolyDataMapper class
111 // to prevent drawing of mappers' content (due to an empty definition
112 // of GEOM_PainterPolyDataMapper::RenderPiece(...)).
113 // !!! Presentation of GEOM_Actor is drawing only with help of actors
114 // defined in this class !!!
115 myPolyDataMapper(GEOM_PainterPolyDataMapper::New(),true),
117 myHighlightProp(vtkProperty::New()),
118 myPreHighlightProp(vtkProperty::New()),
119 myShadingFaceProp(vtkProperty::New()),
120 myShadingBackFaceProp(vtkProperty::New())
123 MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
126 myPolyDataMapper->SetInputConnection(myAppendFilter->GetOutputPort());
127 vtkProperty* aProperty;
129 myHighlightProp->SetAmbient(0.5);
130 myHighlightProp->SetDiffuse(0.3);
131 myHighlightProp->SetSpecular(0.2);
132 myHighlightProp->SetRepresentationToSurface();
133 myHighlightProp->SetAmbientColor(1, 1, 1);
134 myHighlightProp->SetDiffuseColor(1, 1, 1);
135 myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
136 myHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
137 myHighlightActor->SetProperty(myHighlightProp.GetPointer());
139 this->myHighlightActor->SetInput(myAppendFilter->GetOutputPort(),false);
141 myPreHighlightProp->SetColor(0,1,1);
142 myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE);
143 myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
144 myPreHighlightProp->SetRepresentationToWireframe();
146 myAppendFilter->AddInputConnection(myVertexSource->GetOutputPort());
147 myVertexActor->SetInput(myVertexSource->GetOutputPort(),false);
148 aProperty = myVertexActor->GetProperty();
149 aProperty->SetRepresentation(VTK_POINTS);
150 aProperty->SetPointSize(3);
151 aProperty->SetColor(1, 1, 0);
153 myAppendFilter->AddInputConnection(myStandaloneVertexSource->GetOutputPort());
154 myStandaloneVertexActor->SetInput(myStandaloneVertexSource->GetOutputPort(),false);
155 aProperty = myStandaloneVertexActor->GetProperty();
156 aProperty->SetRepresentation(VTK_POINTS);
157 aProperty->SetPointSize(3);
158 aProperty->SetColor(1, 1, 0);
160 myAppendFilter->AddInputConnection(myIsolatedEdgeSource->GetOutputPort());
161 myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutputPort(),false);
162 aProperty = myIsolatedEdgeActor->GetProperty();
163 aProperty->SetRepresentation(VTK_WIREFRAME);
164 myIsolatedEdgeColor[0] = 1; myIsolatedEdgeColor[1] = 0; myIsolatedEdgeColor[2] = 0;
165 aProperty->SetColor(myIsolatedEdgeColor[0], myIsolatedEdgeColor[1], myIsolatedEdgeColor[2]);
167 myAppendFilter->AddInputConnection(myOneFaceEdgeSource->GetOutputPort());
168 myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutputPort(),false);
169 aProperty = myOneFaceEdgeActor->GetProperty();
170 aProperty->SetRepresentation(VTK_WIREFRAME);
171 myOneFaceEdgeColor[0] = 0; myOneFaceEdgeColor[1] = 1; myOneFaceEdgeColor[2] = 0;
172 aProperty->SetColor(myOneFaceEdgeColor[0], myOneFaceEdgeColor[1], myOneFaceEdgeColor[2]);
174 myAppendFilter->AddInputConnection(mySharedEdgeSource->GetOutputPort());
175 mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutputPort(),false);
176 aProperty = mySharedEdgeActor->GetProperty();
177 aProperty->SetRepresentation(VTK_WIREFRAME);
178 mySharedEdgeColor[0] = 1; mySharedEdgeColor[1] = 1; mySharedEdgeColor[2] = 0;
179 aProperty->SetColor(mySharedEdgeColor[0], mySharedEdgeColor[1], mySharedEdgeColor[2]);
181 myAppendFilter->AddInputConnection(myWireframeFaceSource->GetOutputPort());
182 myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutputPort(),false);
183 aProperty = myWireframeFaceActor->GetProperty();
184 aProperty->SetRepresentation(VTK_WIREFRAME);
185 aProperty->SetColor(0.5, 0.5, 0.5);
187 myShadingFaceActor->SetInput(myShadingFaceSource->GetOutputPort(),true);
189 myShadingFaceProp->SetRepresentation(VTKViewer::Representation::Surface);
190 myShadingFaceProp->SetInterpolationToGouraud();
191 myShadingFaceProp->SetAmbient(1.0);
192 myShadingFaceProp->SetDiffuse(1.0);
193 myShadingFaceProp->SetSpecular(0.4);
194 myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
195 myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
196 myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
198 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
200 // Toggle display mode
201 setDisplayMode(0); // WIRE FRAME
203 SetVerticesMode(0); //
207 GEOM_Actor::~GEOM_Actor()
210 MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
212 myHighlightProp->Delete();
213 myPreHighlightProp->Delete();
214 myShadingFaceProp->Delete();
215 myShadingBackFaceProp->Delete();
222 GEOM_Actor* anObject = new GEOM_Actor();
223 anObject->SetMapper(anObject->myPolyDataMapper.Get());
228 void Write(vtkPolyData* theDataSet, const char* theFileName){
229 vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
230 MESSAGE ("Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells());
231 aWriter->SetInputData(theDataSet);
232 aWriter->SetFileName(theFileName);
241 this->myVertexSource->Modified();
242 this->myStandaloneVertexSource->Modified();
243 this->myIsolatedEdgeSource->Modified();
244 this->myOneFaceEdgeSource->Modified();
245 this->mySharedEdgeSource->Modified();
246 this->myWireframeFaceSource->Modified();
247 this->myShadingFaceSource->Modified();
252 SetMapper(vtkMapper* theMapper)
254 SALOME_Actor::SetMapper(theMapper);
259 AddToRender(vtkRenderer* theRenderer)
261 //SALOME_Actor::AddToRender(theRenderer);
263 theRenderer->AddActor(this);
265 this->myHighlightActor->AddToRender(theRenderer);
268 myShadingFaceActor->AddToRender(theRenderer);
269 myWireframeFaceActor->AddToRender(theRenderer);
271 mySharedEdgeActor->AddToRender(theRenderer);
272 myOneFaceEdgeActor->AddToRender(theRenderer);
273 myIsolatedEdgeActor->AddToRender(theRenderer);
275 myVertexActor->AddToRender(theRenderer);
276 myStandaloneVertexActor->AddToRender(theRenderer);
281 RemoveFromRender(vtkRenderer* theRenderer)
283 //SALOME_Actor::RemoveFromRender(theRenderer);
286 theRenderer->RemoveActor(this);
288 myHighlightActor->RemoveFromRender(theRenderer);
289 myShadingFaceActor->RemoveFromRender(theRenderer);
290 myWireframeFaceActor->RemoveFromRender(theRenderer);
292 mySharedEdgeActor->RemoveFromRender(theRenderer);
293 myOneFaceEdgeActor->RemoveFromRender(theRenderer);
294 myIsolatedEdgeActor->RemoveFromRender(theRenderer);
296 myVertexActor->RemoveFromRender(theRenderer);
297 myStandaloneVertexActor->RemoveFromRender(theRenderer);
301 SetVisibility(false);
306 setDisplayMode(int theMode)
309 MESSAGE ( "GEOM_Actor::setDisplayMode = "<<theMode );
312 if ( theMode == (int)eShadingWithEdges ) {
314 myIsolatedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
315 myIsolatedEdgeColor[1],
316 myIsolatedEdgeColor[2]);
317 myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
318 myEdgesInShadingColor[1],
319 myEdgesInShadingColor[2]);
320 mySharedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
321 myEdgesInShadingColor[1],
322 myEdgesInShadingColor[2]);
326 myIsolatedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
327 myIsolatedEdgeColor[1],
328 myIsolatedEdgeColor[2]);
329 mySharedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
330 myIsolatedEdgeColor[1],
331 myIsolatedEdgeColor[2]);
332 myOneFaceEdgeActor->GetProperty()->SetColor(myOneFaceEdgeColor[0],
333 myOneFaceEdgeColor[1],
334 myOneFaceEdgeColor[2]);
337 VTKViewer_Actor::setDisplayMode(theMode);
338 SetVisibility(GetVisibility());
343 SetSelected(bool theIsSelected)
346 MESSAGE ( "GEOM_Actor::SetSelected = "<<theIsSelected );
349 myIsSelected = theIsSelected;
350 SetVisibility(GetVisibility());
355 SetVisibility(int theVisibility)
358 MESSAGE ( "GEOM_Actor::SetVisibility = "<<theVisibility <<" myIsSelected="<< myIsSelected
359 << " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected );
362 SALOME_Actor::SetVisibility(theVisibility);
364 this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
366 myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges) && (!myIsSelected || !myIsPreselected));
367 myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe) && !myIsSelected);
369 mySharedEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
370 myOneFaceEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
371 myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
373 myVertexActor->SetVisibility(theVisibility && (isOnlyVertex || (myVerticesMode && (!myIsSelected && !myIsPreselected))));// must be added new mode points
375 myStandaloneVertexActor->SetVisibility(theVisibility);
381 ::SetNbIsos(const int theNb[2])
383 myWireframeFaceSource->SetNbIso(theNb);
388 ::GetNbIsos(int &theNbU,int &theNbV)
390 myWireframeFaceSource->GetNbIso(theNbU, theNbV);
395 ::SetVectorMode(bool theMode)
397 myVectorMode = theMode;
398 myIsolatedEdgeSource->SetVectorMode(theMode);
399 myOneFaceEdgeSource->SetVectorMode(theMode);
400 mySharedEdgeSource->SetVectorMode(theMode);
413 ::SetVerticesMode(bool theMode)
415 myVerticesMode = theMode;
416 if ( theMode || isOnlyVertex ) {
417 myAppendFilter->AddInputConnection(myVertexSource->GetOutputPort());
419 myAppendFilter->RemoveInputConnection(0, myVertexSource->GetOutputPort());
428 return myVerticesMode;
433 SetDeflection(float theDeflection)
435 if( myDeflection == theDeflection )
438 myDeflection = theDeflection;
440 GEOM::MeshShape(myShape,myDeflection);
445 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
451 myVertexSource->Clear();
452 myStandaloneVertexSource->Clear();
453 myIsolatedEdgeSource->Clear();
454 myOneFaceEdgeSource->Clear();
455 mySharedEdgeSource->Clear();
456 myWireframeFaceSource->Clear();
457 myShadingFaceSource->Clear();
459 TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
460 for (; aVertexExp.More(); aVertexExp.Next())
462 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
463 myVertexSource->AddVertex(aVertex);
466 SetDeflection(theDeflection);
468 // look if edges are free or shared
469 TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
470 TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
472 GEOM::SetShape(theShape,anEdgeMap,theIsVector,
473 myStandaloneVertexSource.Get(),
474 myIsolatedEdgeSource.Get(),
475 myOneFaceEdgeSource.Get(),
476 mySharedEdgeSource.Get(),
477 myWireframeFaceSource.Get(),
478 myShadingFaceSource.Get());
480 myIsolatedEdgeSource->IsEmpty() &&
481 myOneFaceEdgeSource->IsEmpty() &&
482 mySharedEdgeSource->IsEmpty() &&
483 myWireframeFaceSource->IsEmpty() &&
484 myShadingFaceSource->IsEmpty();
487 if((bool)myShape.Infinite() || isOnlyVertex ){
488 myVertexActor->GetDeviceActor()->SetInfinitive(true);
489 myStandaloneVertexActor->GetDeviceActor()->SetInfinitive(true);
490 myHighlightActor->GetDeviceActor()->SetInfinitive(true);
493 // 0051777: TC7.2.0: Element could not be selected in Hypothesis Construction
494 myAppendFilter->Update();
498 void GEOM_Actor::setDeflection(double adef) {
500 MESSAGE ( "GEOM_Actor::setDeflection" );
502 SetDeflection((float)adef);
506 // warning! must be checked!
507 // SetHighlightProperty
508 // SetWireframeProperty
509 // SetShadingProperty
511 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
514 MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
516 this->myHighlightActor->GetProperty()->DeepCopy(Prop);
520 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
523 MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
526 myWireframeFaceActor->SetProperty(Prop);
530 vtkProperty* GEOM_Actor::GetWireframeProperty()
532 return myWireframeFaceActor->GetProperty();
535 vtkProperty* GEOM_Actor::GetIsolatedEdgeProperty()
537 return myIsolatedEdgeActor->GetProperty();
540 vtkProperty* GEOM_Actor::GetVertexProperty()
542 return myVertexActor->GetProperty();
545 vtkProperty* GEOM_Actor::GetStandaloneVertexProperty()
547 return myStandaloneVertexActor->GetProperty();
550 vtkProperty* GEOM_Actor::GetSharedEdgeProperty()
552 return mySharedEdgeActor->GetProperty();
555 vtkProperty* GEOM_Actor::GetFaceEdgeProperty()
557 return myOneFaceEdgeActor->GetProperty();
560 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
563 MESSAGE ( "GEOM_Actor::SetShadingProperty" );
565 myShadingFaceProp->DeepCopy(Prop);
569 vtkProperty* GEOM_Actor::GetShadingProperty()
571 return myShadingFaceProp;
575 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
578 MESSAGE ( "GEOM_Actor::Render" );
584 /* render the property */
585 if (!this->Property) {
586 // force creation of a property
588 this->Property->SetInterpolation(1);
589 this->Property->SetRepresentationToSurface();
590 this->Property->SetAmbient(0.3);
591 this->Property->SetAmbientColor(0.88,0.86,0.2);
592 this->Property->SetDiffuseColor(0.99,0.7,0.21);
593 this->Property->SetSpecularColor(0.99,0.98,0.83);
596 switch(myDisplayMode){
597 case eWireframe://wireframe
598 myPreHighlightProp->SetRepresentationToWireframe();
599 myHighlightProp->SetRepresentationToWireframe();
601 case eShading://shading
602 case eShadingWithEdges://shading with edges
603 myPreHighlightProp->SetRepresentationToSurface();
604 myHighlightProp->SetRepresentationToSurface();
605 myShadingFaceProp->SetRepresentationToSurface();
606 myShadingBackFaceProp->SetRepresentationToSurface();
612 this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
613 myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
614 myShadingFaceActor->SetBackfaceProperty(myPreHighlightProp.GetPointer());
616 this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
617 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
618 myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
622 this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
623 myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
624 myShadingFaceActor->SetBackfaceProperty(myHighlightProp.GetPointer());
627 this->Property->Render(this, ren);
628 if (this->BackfaceProperty) {
629 this->BackfaceProperty->BackfaceRender(this, ren);
630 this->Device->SetBackfaceProperty(this->BackfaceProperty);
632 this->Device->SetProperty(this->Property);
633 /* if(myShape.ShapeType() == TopAbs_VERTEX) {
635 //The parameter determine size of vertex actor relate to diagonal of RendererWindow
636 static double delta = 0.01;
637 double X1 = -1, Y1 = -1, Z1 = 0;
638 ren->ViewToWorld(X1,Y1,Z1);
639 double X2 = +1, Y2 = +1, Z2 = 0;
640 ren->ViewToWorld(X2,Y2,Z2);
641 Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
642 this->SetScale(Z2*delta);
644 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
645 this->GetMatrix(ren->GetActiveCamera(), aMatrix);
646 this->Device->SetUserMatrix(aMatrix);
647 this->Device->Render(ren,theMapper);
650 this->Device->Render(ren, theMapper);
653 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
656 MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
662 void GEOM_Actor::ShallowCopy(vtkProp *prop)
665 MESSAGE ( "GEOM_Actor::ShallowCopy" );
667 GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
670 this->SetShape(f->getTopo(),f->GetDeflection());
674 this->SALOME_Actor::ShallowCopy(prop);
677 const TopoDS_Shape& GEOM_Actor::getTopo() {
679 MESSAGE ( "GEOM_Actor::getTopo" );
684 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
685 int imode, bool isVector)
688 MESSAGE ( "GEOM_Actor::setInputShape" );
692 double GEOM_Actor::getDeflection()
695 MESSAGE ( "GEOM_Actor::getDeflection" );
697 return (double) GetDeflection();
701 double GEOM_Actor::isVector()
704 MESSAGE ( "GEOM_Actor::isVector" );
709 void GEOM_Actor::SubShapeOn()
712 MESSAGE ( "GEOM_Actor::SubShapeOn" );
716 void GEOM_Actor::SubShapeOff()
719 MESSAGE ( "GEOM_Actor::SubShapeOff" );
723 void GEOM_Actor::highlight(bool highlight)
726 MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
728 SALOME_Actor::highlight(highlight);
731 void GEOM_Actor::SetOpacity(double opa)
734 myShadingFaceProp->SetOpacity(opa);
735 myShadingBackFaceProp->SetOpacity(opa);
736 myHighlightProp->SetOpacity(opa);
737 myPreHighlightProp->SetOpacity(opa);
738 myVertexActor->GetProperty()->SetOpacity(opa);
739 myStandaloneVertexActor->GetProperty()->SetOpacity(opa);
742 double GEOM_Actor::GetOpacity()
745 return myShadingFaceProp->GetOpacity();
748 void GEOM_Actor::SetColor(double r,double g,double b)
750 // set the same color to all sub-actors:
752 // - standalone edges
755 // - shading color (front and back faces)
756 SetPointColor(r, g, b);
757 SetIsolatedEdgeColor(r, g, b);
758 SetSharedEdgeColor(r, g, b);
759 SetFreeEdgeColor(r, g, b);
760 myShadingFaceProp->SetColor(r,g,b); // shading color
761 myShadingBackFaceProp->SetColor(r,g,b); // back face shading color
764 void GEOM_Actor::GetColor(double& r,double& g,double& b)
767 myShadingFaceProp->GetColor(aRGB);
774 \brief Set color of points
775 Points actor is shown in Wireframe mode only, see SetVisibility()
777 void GEOM_Actor::SetPointColor(double r, double g, double b)
779 myVertexActor->GetProperty()->SetColor(r, g, b);
780 myStandaloneVertexActor->GetProperty()->SetColor(r, g, b);
784 \brief Set color of standalone edges, wires, vectors
785 This actor is shown in all display mode, see SetVisibility()
786 TODO: check - this color seems to be used not only for standalone edges
788 void GEOM_Actor::SetIsolatedEdgeColor(double r, double g, double b)
790 myIsolatedEdgeColor[0] = r; myIsolatedEdgeColor[1] = g; myIsolatedEdgeColor[2] = b;
791 myIsolatedEdgeActor->GetProperty()->SetColor(r, g, b);
795 \brief Set color of shared edges
796 This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
797 TODO: check - this seems to be not working currently
799 void GEOM_Actor::SetSharedEdgeColor(double r, double g, double b)
801 mySharedEdgeColor[0] = r; mySharedEdgeColor[1] = g; mySharedEdgeColor[2] = b;
802 if ( myDisplayMode != (int)eShadingWithEdges )
803 mySharedEdgeActor->GetProperty()->SetColor(r, g, b);
807 \brief Set color of edges for standalone faces
808 This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
809 TODO: this color should be used not only for faces
811 void GEOM_Actor::SetFreeEdgeColor(double r, double g, double b)
813 myOneFaceEdgeColor[0] = r; myOneFaceEdgeColor[1] = g; myOneFaceEdgeColor[2] = b;
814 if ( myDisplayMode != (int)eShadingWithEdges )
815 myOneFaceEdgeActor->GetProperty()->SetColor(r, g, b);
819 \brief Set color of iso-lines
820 This actor is shown only in wireframe display mode, see SetVisibility()
822 void GEOM_Actor::SetIsosColor(double r, double g, double b)
824 myWireframeFaceActor->GetProperty()->SetColor(r, g, b);
827 void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
829 // we set material properties as back and front material
830 int aSize = theProps.size();
832 if ( aSize < 1 || aSize > 2)
835 // theProps[0] -- front material properties
836 // theProps[1] -- back material properties (if exist)
840 // Set reflection coefficients
841 aCoefnt = theProps[0]->GetAmbient();
842 myShadingFaceProp->SetAmbient(aCoefnt);
843 myVertexActor->GetProperty()->SetAmbient(aCoefnt);
844 myStandaloneVertexActor->GetProperty()->SetAmbient(aCoefnt);
846 aCoefnt = theProps[1]->GetAmbient();
847 myShadingBackFaceProp->SetAmbient(aCoefnt);
849 // Set diffuse coefficients
850 aCoefnt = theProps[0]->GetDiffuse();
851 myShadingFaceProp->SetDiffuse(aCoefnt);
852 myVertexActor->GetProperty()->SetDiffuse(aCoefnt);
853 myStandaloneVertexActor->GetProperty()->SetDiffuse(aCoefnt);
855 aCoefnt = theProps[1]->GetDiffuse();
856 myShadingBackFaceProp->SetDiffuse(aCoefnt);
858 // Set specular coefficients
859 aCoefnt = theProps[0]->GetSpecular();
860 myShadingFaceProp->SetSpecular(aCoefnt);
861 myVertexActor->GetProperty()->SetSpecular(aCoefnt);
862 myStandaloneVertexActor->GetProperty()->SetSpecular(aCoefnt);
864 aCoefnt = theProps[1]->GetSpecular();
865 myShadingBackFaceProp->SetSpecular(aCoefnt);
870 // Set reflection colors
871 aColor = theProps[0]->GetAmbientColor();
872 myShadingFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
873 myVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
874 myStandaloneVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
876 aColor = theProps[1]->GetAmbientColor();
877 myShadingBackFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
879 // Set diffuse colors
880 aColor = theProps[0]->GetDiffuseColor();
881 myShadingFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
882 myVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
883 myStandaloneVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
885 aColor = theProps[1]->GetDiffuseColor();
886 myShadingBackFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
888 // Set specular colors
889 aColor = theProps[0]->GetSpecularColor();
890 myShadingFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
891 myVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
892 myStandaloneVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
894 aColor = theProps[1]->GetSpecularColor();
895 myShadingBackFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
898 aCoefnt = theProps[0]->GetSpecularPower();
899 myShadingFaceProp->SetSpecularPower(aCoefnt);
900 myVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
901 myStandaloneVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
903 aCoefnt = theProps[1]->GetSpecularPower();
904 myShadingBackFaceProp->SetSpecularPower(aCoefnt);
906 // Set back face material property
907 myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
910 vtkProperty* GEOM_Actor::GetFrontMaterial()
912 return myShadingFaceProp;
915 vtkProperty* GEOM_Actor::GetBackMaterial()
917 return myShadingBackFaceProp;
920 bool GEOM_Actor::IsInfinitive()
922 return ((bool)myShape.Infinite() || isOnlyVertex);
926 To map current selection to VTK representation
930 ::Highlight(bool theIsHighlight)
932 myIsSelected = theIsHighlight;
934 MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
937 SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
938 SetVisibility(GetVisibility());
942 To process prehighlight (called from SVTK_InteractorStyle)
946 ::PreHighlight(vtkInteractorStyle *theInteractorStyle,
947 SVTK_SelectionEvent* theSelectionEvent,
951 MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
954 if ( !GetPickable() )
957 myPreHighlightActor->SetVisibility( false );
958 bool anIsPreselected = myIsPreselected;
960 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
961 bool anIsChanged = (mySelectionMode != aSelectionMode);
963 if( !theIsHighlight ) {
964 SetPreSelected( false );
966 switch(aSelectionMode){
967 case ActorSelection :
969 // cout << "=============== " << myIO->getEntry() << endl;
970 // int nbio = mySelector->IObjectCount();
971 // cout << " nbio = " << nbio << endl;
973 if( !mySelector->IsSelected( myIO ) ) {
974 // printf ("!!!!!!!!!!!!!!!!\n");
975 SetPreSelected( true );
983 mySelectionMode = aSelectionMode;
984 anIsChanged |= (anIsPreselected != myIsPreselected);
986 SetVisibility(GetVisibility());
991 To process highlight (called from SVTK_InteractorStyle)
995 ::Highlight(vtkInteractorStyle *theInteractorStyle,
996 SVTK_SelectionEvent* theSelectionEvent,
999 // define the selection of object
1001 MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
1003 bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
1004 SetSelected(theIsHighlight);
1006 SetPreSelected(false);
1012 // Copy the follower's composite 4x4 matrix into the matrix provided.
1013 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
1016 double Rx[3], Ry[3], Rz[3], p1[3];
1017 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
1021 this->GetOrientation();
1022 this->Transform->Push();
1023 this->Transform->PostMultiply();
1024 this->Transform->Identity();
1026 // apply user defined matrix last if there is one
1027 if (this->UserMatrix)
1029 this->Transform->Concatenate(this->UserMatrix);
1032 this->Transform->Translate(-this->Origin[0],
1036 this->Transform->Scale(this->Scale[0],
1041 this->Transform->RotateY(this->Orientation[1]);
1042 this->Transform->RotateX(this->Orientation[0]);
1043 this->Transform->RotateZ(this->Orientation[2]);
1049 pos = theCam->GetPosition();
1050 vup = theCam->GetViewUp();
1052 if (theCam->GetParallelProjection())
1054 theCam->GetDirectionOfProjection(Rz);
1059 (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
1060 (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
1061 (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
1062 for (i = 0; i < 3; i++)
1064 Rz[i] = (pos[i] - this->Position[i])/distance;
1068 vtkMath::Cross(vup,Rz,Rx);
1069 vtkMath::Normalize(Rx);
1070 vtkMath::Cross(Rz,Rx,Ry);
1072 matrix->Element[0][0] = Rx[0];
1073 matrix->Element[1][0] = Rx[1];
1074 matrix->Element[2][0] = Rx[2];
1075 matrix->Element[0][1] = Ry[0];
1076 matrix->Element[1][1] = Ry[1];
1077 matrix->Element[2][1] = Ry[2];
1078 matrix->Element[0][2] = Rz[0];
1079 matrix->Element[1][2] = Rz[1];
1080 matrix->Element[2][2] = Rz[2];
1082 this->Transform->Concatenate(matrix);
1085 // translate to projection reference point PRP
1086 // this is the camera's position blasted through
1087 // the current matrix
1088 p1[0] = this->Origin[0] + this->Position[0];
1089 p1[1] = this->Origin[1] + this->Position[1];
1090 p1[2] = this->Origin[2] + this->Position[2];
1092 this->Transform->Translate(p1[0],p1[1],p1[2]);
1093 this->Transform->GetMatrix(result);
1096 this->Transform->Pop();
1099 void GEOM_Actor::SetEdgesInShadingColor(double r,double g,double b)
1101 myEdgesInShadingColor[0] = r;
1102 myEdgesInShadingColor[1] = g;
1103 myEdgesInShadingColor[2] = b;
1106 void GEOM_Actor::SetIsosWidth(const int width) {
1107 myWireframeFaceActor->GetProperty()->SetLineWidth(width);
1110 int GEOM_Actor::GetIsosWidth() const {
1111 return (int)myWireframeFaceActor->GetProperty()->GetLineWidth();
1114 void GEOM_Actor::SetWidth(const int width) {
1115 myIsolatedEdgeActor->GetProperty()->SetLineWidth(width);
1116 myOneFaceEdgeActor->GetProperty()->SetLineWidth(width);
1117 mySharedEdgeActor->GetProperty()->SetLineWidth(width);
1118 myHighlightProp->SetLineWidth(width);
1119 myPreHighlightProp->SetLineWidth(width+1);
1123 int GEOM_Actor::GetWidth() const {
1124 return (int)myIsolatedEdgeActor->GetProperty()->GetLineWidth();