1 // GEOM OBJECT : interactive object for Geometry entities visualization
3 // Copyright (C) 2003 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.
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
24 // File : GEOM_Actor.cxx
25 // Author : Christophe ATTANASIO
30 \class GEOM_Actor GEOM_Actor.h
31 \brief This class allows to display an OpenCASCADE CAD model in a VTK viewer.
33 #include "GEOM_Actor.h"
35 #include "GEOM_DeviceActor.h"
36 #include "GEOM_VertexSource.h"
37 #include "GEOM_EdgeSource.h"
38 #include "GEOM_WireframeFace.h"
39 #include "GEOM_ShadingFace.h"
40 #include "SVTK_Actor.h"
42 #include <vtkObjectFactory.h>
43 #include <vtkRenderer.h>
44 #include <vtkProperty.h>
45 #include <vtkPointPicker.h>
46 #include <vtkCellPicker.h>
48 #include <TopAbs_ShapeEnum.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <Poly_Triangulation.hxx>
51 #include <BRepMesh_IncrementalMesh.hxx>
52 #include <Bnd_Box.hxx>
54 #include <BRep_Tool.hxx>
55 #include <BRepBndLib.hxx>
56 #include <TopTools_ListOfShape.hxx>
57 #include <TopoDS_Iterator.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 //vtkStandardNewMacro(GEOM_Actor);
78 GEOM_Actor::GEOM_Actor():
79 // myDisplayMode(eWireframe),
82 myVertexActor(GEOM_DeviceActor::New(),true),
83 myVertexSource(GEOM_VertexSource::New(),true),
85 myIsolatedEdgeActor(GEOM_DeviceActor::New(),true),
86 myIsolatedEdgeSource(GEOM_EdgeSource::New(),true),
88 myOneFaceEdgeActor(GEOM_DeviceActor::New(),true),
89 myOneFaceEdgeSource(GEOM_EdgeSource::New(),true),
91 mySharedEdgeActor(GEOM_DeviceActor::New(),true),
92 mySharedEdgeSource(GEOM_EdgeSource::New(),true),
94 myWireframeFaceActor(GEOM_DeviceActor::New(),true),
95 myWireframeFaceSource(GEOM_WireframeFace::New(),true),
97 myShadingFaceActor(GEOM_DeviceActor::New(),true),
98 myShadingFaceSource(GEOM_ShadingFace::New(),true),
100 myHighlightActor(GEOM_DeviceActor::New(),true),
101 myAppendFilter(vtkAppendPolyData::New(),true),
102 myPolyDataMapper(vtkPolyDataMapper::New(),true),
104 myHighlightProp(vtkProperty::New()),
105 myPreHighlightProp(vtkProperty::New()),
106 myShadingFaceProp(vtkProperty::New())
110 MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
113 myPolyDataMapper->SetInput(myAppendFilter->GetOutput());
114 vtkProperty* aProperty;
116 myHighlightProp->SetAmbient(0.5);
117 myHighlightProp->SetDiffuse(0.3);
118 myHighlightProp->SetSpecular(0.2);
119 myHighlightProp->SetRepresentationToSurface();
120 myHighlightProp->SetAmbientColor(1, 1, 1);
121 myHighlightProp->SetDiffuseColor(1, 1, 1);
122 myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
123 myHighlightActor->SetProperty(myHighlightProp.GetPointer());
125 this->myHighlightActor->SetInput(myAppendFilter->GetOutput(),false);
127 myPreHighlightProp->SetColor(0,1,1);
128 myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
129 myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
130 myPreHighlightProp->SetRepresentationToWireframe();
132 myAppendFilter->AddInput(myVertexSource->GetOutput());
133 myVertexActor->SetInput(myVertexSource->GetOutput(),false);
134 aProperty = myVertexActor->GetProperty();
135 aProperty->SetRepresentation(VTK_POINTS);
136 aProperty->SetPointSize(3);
137 aProperty->SetColor(1, 1, 0);
139 myAppendFilter->AddInput(myIsolatedEdgeSource->GetOutput());
140 myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false);
141 aProperty = myIsolatedEdgeActor->GetProperty();
142 aProperty->SetRepresentation(VTK_WIREFRAME);
143 aProperty->SetColor(1, 0, 0);
145 myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput());
146 myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false);
147 aProperty = myOneFaceEdgeActor->GetProperty();
148 aProperty->SetRepresentation(VTK_WIREFRAME);
149 aProperty->SetColor(0, 1, 0);
151 myAppendFilter->AddInput(mySharedEdgeSource->GetOutput());
152 mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false);
153 aProperty = mySharedEdgeActor->GetProperty();
154 aProperty->SetRepresentation(VTK_WIREFRAME);
155 aProperty->SetColor(1, 1, 0);
157 myAppendFilter->AddInput(myWireframeFaceSource->GetOutput());
158 myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false);
159 aProperty = myWireframeFaceActor->GetProperty();
160 aProperty->SetRepresentation(VTK_WIREFRAME);
161 aProperty->SetColor(0.5, 0.5, 0.5);
163 myShadingFaceActor->SetInput(myShadingFaceSource->GetOutput(),true);
165 myShadingFaceProp->SetRepresentation(VTK_SURFACE);
166 myShadingFaceProp->SetInterpolationToGouraud();
167 myShadingFaceProp->SetAmbient(1.0);
168 myShadingFaceProp->SetDiffuse(1.0);
169 myShadingFaceProp->SetSpecular(0.4);
170 myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
171 myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
172 myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
174 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
176 // Toggle display mode
177 setDisplayMode(0); // WIRE FRAME
182 GEOM_Actor::~GEOM_Actor()
185 MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
187 myHighlightProp->Delete();
188 myPreHighlightProp->Delete();
189 myShadingFaceProp->Delete();
196 GEOM_Actor* anObject = new GEOM_Actor();
197 anObject->SetMapper(anObject->myPolyDataMapper.Get());
202 void Write(vtkPolyData* theDataSet, const char* theFileName){
203 vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
204 MESSAGE ("Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells());
205 aWriter->SetInput(theDataSet);
206 aWriter->SetFileName(theFileName);
215 this->myVertexSource->Modified();
216 this->myIsolatedEdgeSource->Modified();
217 this->myOneFaceEdgeSource->Modified();
218 this->mySharedEdgeSource->Modified();
219 this->myWireframeFaceSource->Modified();
220 this->myShadingFaceSource->Modified();
225 SetMapper(vtkMapper* theMapper)
227 SALOME_Actor::SetMapper(theMapper);
232 AddToRender(vtkRenderer* theRenderer)
234 //SALOME_Actor::AddToRender(theRenderer);
236 theRenderer->AddActor(this);
238 this->myHighlightActor->AddToRender(theRenderer);
241 myShadingFaceActor->AddToRender(theRenderer);
242 myWireframeFaceActor->AddToRender(theRenderer);
244 mySharedEdgeActor->AddToRender(theRenderer);
245 myOneFaceEdgeActor->AddToRender(theRenderer);
246 myIsolatedEdgeActor->AddToRender(theRenderer);
248 myVertexActor->AddToRender(theRenderer);
253 RemoveFromRender(vtkRenderer* theRenderer)
255 //SALOME_Actor::RemoveFromRender(theRenderer);
258 theRenderer->RemoveActor(this);
260 myHighlightActor->RemoveFromRender(theRenderer);
261 myShadingFaceActor->RemoveFromRender(theRenderer);
262 myWireframeFaceActor->RemoveFromRender(theRenderer);
264 mySharedEdgeActor->RemoveFromRender(theRenderer);
265 myOneFaceEdgeActor->RemoveFromRender(theRenderer);
266 myIsolatedEdgeActor->RemoveFromRender(theRenderer);
268 myVertexActor->RemoveFromRender(theRenderer);
272 SetVisibility(false);
277 setDisplayMode(int theMode)
280 MESSAGE ( "GEOM_Actor::SetDisplayMode = "<<theMode );
282 VTKViewer_Actor::setDisplayMode(theMode);
283 SetVisibility(GetVisibility());
288 SetSelected(bool theIsSelected)
291 MESSAGE ( "GEOM_Actor::SetSelected = "<<theIsSelected );
294 myIsSelected = theIsSelected;
295 SetVisibility(GetVisibility());
300 SetVisibility(int theVisibility)
303 MESSAGE ( "GEOM_Actor::SetVisibility = "<<theVisibility <<" myIsSelected="<< myIsSelected
304 << " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected );
307 SALOME_Actor::SetVisibility(theVisibility);
309 this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
311 myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading) && (!myIsSelected || !myIsPreselected));
312 myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode ==(int)eWireframe) && !myIsSelected);
314 mySharedEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
315 myOneFaceEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
316 myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
318 // myVertexActor->SetVisibility(false);// must be added new mode points
319 myVertexActor->SetVisibility(theVisibility);
325 ::SetNbIsos(const int theNb[2])
327 myWireframeFaceSource->SetNbIso(theNb);
332 ::GetNbIsos(int &theNbU,int &theNbV)
334 myWireframeFaceSource->GetNbIso(theNbU, theNbV);
339 MeshShape(const TopoDS_Shape& theShape,
340 float& theDeflection,
343 static Standard_Real RELATIVE_DEFLECTION = 0.0001;
344 Standard_Real aDeflection = theDeflection;
346 if(theDeflection <= 0) { // Compute default theDeflection
348 BRepBndLib::Add(theShape, B);
349 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
350 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
351 Standard_Real aDiagonal = (aXmax-aXmin)*(aXmax-aXmin) +
352 (aYmax-aYmin)*(aYmax-aYmin) +
353 (aZmax-aZmin)*(aZmax-aZmin);
354 aDiagonal = sqrt(aDiagonal);
355 aDeflection = aDiagonal*RELATIVE_DEFLECTION;
358 theDeflection = RELATIVE_DEFLECTION;
360 theDeflection = aDeflection;
363 BRepMesh_IncrementalMesh aMesh(theShape,aDeflection);
368 SetDeflection(float theDeflection, bool theIsRelative)
370 myDeflection = theDeflection;
371 myIsRelative = theIsRelative;
373 MeshShape(myShape,myDeflection,myIsRelative);
378 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
385 myVertexSource->Clear();
386 myIsolatedEdgeSource->Clear();
387 myOneFaceEdgeSource->Clear();
388 mySharedEdgeSource->Clear();
389 myWireframeFaceSource->Clear();
390 myShadingFaceSource->Clear();
392 TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
393 for (; aVertexExp.More(); aVertexExp.Next())
395 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
396 myVertexSource->AddVertex(aVertex);
398 SetDeflection(theDeflection, theIsRelative);
400 // look if edges are free or shared
401 TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
402 TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
404 SetShape(theShape,anEdgeMap,theIsVector);
407 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
408 const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap,
411 if (theShape.ShapeType() == TopAbs_COMPOUND) {
412 TopoDS_Iterator anItr(theShape);
413 for (; anItr.More(); anItr.Next()) {
414 SetShape(anItr.Value(),theEdgeMap,theIsVector);
418 switch (theShape.ShapeType()) {
420 TopExp_Explorer anEdgeExp(theShape,TopAbs_EDGE);
421 for (; anEdgeExp.More(); anEdgeExp.Next()){
422 const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
423 if (!BRep_Tool::Degenerated(anEdge))
424 myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
429 const TopoDS_Edge& anEdge = TopoDS::Edge(theShape);
430 if (!BRep_Tool::Degenerated(anEdge))
431 myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
434 case TopAbs_VERTEX: {
438 TopExp_Explorer aFaceExp (theShape,TopAbs_FACE);
439 for(; aFaceExp.More(); aFaceExp.Next()) {
440 const TopoDS_Face& aFace = TopoDS::Face(aFaceExp.Current());
441 myWireframeFaceSource->AddFace(aFace);
442 myShadingFaceSource->AddFace(aFace);
443 TopExp_Explorer anEdgeExp(aFaceExp.Current(), TopAbs_EDGE);
444 for(; anEdgeExp.More(); anEdgeExp.Next()) {
445 const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
446 if(!BRep_Tool::Degenerated(anEdge)){
447 // compute the number of faces
448 int aNbOfFaces = theEdgeMap.FindFromKey(anEdge).Extent();
450 case 0: // isolated edge
451 myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
453 case 1: // edge in only one face
454 myOneFaceEdgeSource->AddEdge(anEdge,theIsVector);
456 default: // edge shared by at least two faces
457 mySharedEdgeSource->AddEdge(anEdge,theIsVector);
467 void GEOM_Actor::setDeflection(double adef) {
469 MESSAGE ( "GEOM_Actor::setDeflection" );
471 SetDeflection((float)adef,GetIsRelative());
475 // warning! must be checked!
476 // SetHighlightProperty
477 // SetWireframeProperty
478 // SetShadingProperty
480 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
483 MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
485 this->myHighlightActor->GetProperty()->DeepCopy(Prop);
489 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
492 MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
495 myWireframeFaceActor->SetProperty(Prop);
498 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
501 MESSAGE ( "GEOM_Actor::SetShadingProperty" );
503 myShadingFaceProp->DeepCopy(Prop);
507 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
510 MESSAGE ( "GEOM_Actor::Render" );
516 /* render the property */
517 if (!this->Property) {
518 // force creation of a property
520 this->Property->SetInterpolation(1);
521 this->Property->SetRepresentationToSurface();
522 this->Property->SetAmbient(0.3);
523 this->Property->SetAmbientColor(0.88,0.86,0.2);
524 this->Property->SetDiffuseColor(0.99,0.7,0.21);
525 this->Property->SetSpecularColor(0.99,0.98,0.83);
528 switch(myDisplayMode){
530 myPreHighlightProp->SetRepresentationToWireframe();
531 myHighlightProp->SetRepresentationToWireframe();
534 myPreHighlightProp->SetRepresentationToSurface();
535 myHighlightProp->SetRepresentationToSurface();
541 this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
542 myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
544 this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
545 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
549 this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
550 myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
553 this->Property->Render(this, ren);
554 if (this->BackfaceProperty) {
555 this->BackfaceProperty->BackfaceRender(this, ren);
556 this->Device->SetBackfaceProperty(this->BackfaceProperty);
558 this->Device->SetProperty(this->Property);
559 if(myShape.ShapeType() == TopAbs_VERTEX) {
561 //The parameter determine size of vertex actor relate to diagonal of RendererWindow
562 static vtkFloatingPointType delta = 0.01;
563 vtkFloatingPointType X1 = -1, Y1 = -1, Z1 = 0;
564 ren->ViewToWorld(X1,Y1,Z1);
565 vtkFloatingPointType X2 = +1, Y2 = +1, Z2 = 0;
566 ren->ViewToWorld(X2,Y2,Z2);
567 Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
568 this->SetScale(Z2*delta);
570 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
571 this->GetMatrix(ren->GetActiveCamera(), aMatrix);
572 this->Device->SetUserMatrix(aMatrix);
573 this->Device->Render(ren,theMapper);
576 this->Device->Render(ren, theMapper);
579 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
582 MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
588 void GEOM_Actor::ShallowCopy(vtkProp *prop)
591 MESSAGE ( "GEOM_Actor::ShallowCopy" );
593 GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
596 this->SetShape(f->getTopo(),f->GetDeflection(),f->GetIsRelative());
600 this->SALOME_Actor::ShallowCopy(prop);
603 const TopoDS_Shape& GEOM_Actor::getTopo() {
605 MESSAGE ( "GEOM_Actor::getTopo" );
610 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
611 int imode, bool isVector)
614 MESSAGE ( "GEOM_Actor::setInputShape" );
618 double GEOM_Actor::getDeflection()
621 MESSAGE ( "GEOM_Actor::getDeflection" );
623 return (double) GetDeflection();
627 double GEOM_Actor::isVector()
630 MESSAGE ( "GEOM_Actor::isVector" );
635 void GEOM_Actor::SubShapeOn()
638 MESSAGE ( "GEOM_Actor::SubShapeOn" );
642 void GEOM_Actor::SubShapeOff()
645 MESSAGE ( "GEOM_Actor::SubShapeOff" );
649 void GEOM_Actor::highlight(bool highlight)
652 MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
654 SALOME_Actor::highlight(highlight);
657 void GEOM_Actor::SetOpacity(vtkFloatingPointType opa)
660 myShadingFaceProp->SetOpacity(opa);
661 myHighlightProp->SetOpacity(opa);
662 myPreHighlightProp->SetOpacity(opa);
665 vtkFloatingPointType GEOM_Actor::GetOpacity()
668 return myShadingFaceProp->GetOpacity();
671 void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
674 myShadingFaceProp->SetColor(r,g,b); // shading color (Shading)
675 myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b); // standalone edge color (Wireframe)
676 myVertexActor->GetProperty()->SetColor(r,g,b); // vertex actor (Shading/Wireframe)
677 myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b); // standalone face edge color (Wireframe)
678 mySharedEdgeActor->GetProperty()->SetColor(r,g,b); // share edge color (Wireframe)
681 void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
684 vtkFloatingPointType aRGB[3];
685 myShadingFaceProp->GetColor(aRGB);
691 bool GEOM_Actor::IsInfinitive()
693 return (bool)(myShape.Infinite());
697 To map current selection to VTK representation
701 ::Highlight(bool theIsHighlight)
703 myIsSelected = theIsHighlight;
705 MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
708 SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
709 SetVisibility(GetVisibility());
713 To process prehighlight (called from SVTK_InteractorStyle)
717 ::PreHighlight(vtkInteractorStyle *theInteractorStyle,
718 SVTK_SelectionEvent* theSelectionEvent,
722 MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
725 if ( !GetPickable() )
728 myPreHighlightActor->SetVisibility( false );
729 bool anIsPreselected = myIsPreselected;
731 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
732 bool anIsChanged = (mySelectionMode != aSelectionMode);
734 if( !theIsHighlight ) {
735 SetPreSelected( false );
737 switch(aSelectionMode){
738 case ActorSelection :
740 if( !mySelector->IsSelected( myIO ) ) {
741 SetPreSelected( true );
749 mySelectionMode = aSelectionMode;
750 anIsChanged |= (anIsPreselected != myIsPreselected);
752 SetVisibility(GetVisibility());
757 To process highlight (called from SVTK_InteractorStyle)
761 ::Highlight(vtkInteractorStyle *theInteractorStyle,
762 SVTK_SelectionEvent* theSelectionEvent,
765 // define the selection of object
767 MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
769 bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
770 SetSelected(theIsHighlight);
772 SetPreSelected(false);
778 // Copy the follower's composite 4x4 matrix into the matrix provided.
779 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
782 double Rx[3], Ry[3], Rz[3], p1[3];
783 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
787 this->GetOrientation();
788 this->Transform->Push();
789 this->Transform->PostMultiply();
790 this->Transform->Identity();
792 // apply user defined matrix last if there is one
793 if (this->UserMatrix)
795 this->Transform->Concatenate(this->UserMatrix);
798 this->Transform->Translate(-this->Origin[0],
802 this->Transform->Scale(this->Scale[0],
807 this->Transform->RotateY(this->Orientation[1]);
808 this->Transform->RotateX(this->Orientation[0]);
809 this->Transform->RotateZ(this->Orientation[2]);
815 pos = theCam->GetPosition();
816 vup = theCam->GetViewUp();
818 if (theCam->GetParallelProjection())
820 theCam->GetDirectionOfProjection(Rz);
825 (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
826 (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
827 (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
828 for (i = 0; i < 3; i++)
830 Rz[i] = (pos[i] - this->Position[i])/distance;
834 vtkMath::Cross(vup,Rz,Rx);
835 vtkMath::Normalize(Rx);
836 vtkMath::Cross(Rz,Rx,Ry);
838 matrix->Element[0][0] = Rx[0];
839 matrix->Element[1][0] = Rx[1];
840 matrix->Element[2][0] = Rx[2];
841 matrix->Element[0][1] = Ry[0];
842 matrix->Element[1][1] = Ry[1];
843 matrix->Element[2][1] = Ry[2];
844 matrix->Element[0][2] = Rz[0];
845 matrix->Element[1][2] = Rz[1];
846 matrix->Element[2][2] = Rz[2];
848 this->Transform->Concatenate(matrix);
851 // translate to projection reference point PRP
852 // this is the camera's position blasted through
853 // the current matrix
854 p1[0] = this->Origin[0] + this->Position[0];
855 p1[1] = this->Origin[1] + this->Position[1];
856 p1[2] = this->Origin[2] + this->Position[2];
858 this->Transform->Translate(p1[0],p1[1],p1[2]);
859 this->Transform->GetMatrix(result);
862 this->Transform->Pop();