1 // Copyright (C) 2007-2010 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.
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
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 #include "SALOME_InteractiveObject.hxx"
74 //vtkStandardNewMacro(GEOM_Actor);
80 GEOM_Actor::GEOM_Actor():
81 // myDisplayMode(eWireframe),
84 myVertexActor(GEOM_DeviceActor::New(),true),
85 myVertexSource(GEOM_VertexSource::New(),true),
87 myIsolatedEdgeActor(GEOM_DeviceActor::New(),true),
88 myIsolatedEdgeSource(GEOM_EdgeSource::New(),true),
90 myOneFaceEdgeActor(GEOM_DeviceActor::New(),true),
91 myOneFaceEdgeSource(GEOM_EdgeSource::New(),true),
93 mySharedEdgeActor(GEOM_DeviceActor::New(),true),
94 mySharedEdgeSource(GEOM_EdgeSource::New(),true),
96 myWireframeFaceActor(GEOM_DeviceActor::New(),true),
97 myWireframeFaceSource(GEOM_WireframeFace::New(),true),
99 myShadingFaceActor(GEOM_DeviceActor::New(),true),
100 myShadingFaceSource(GEOM_ShadingFace::New(),true),
102 myHighlightActor(GEOM_DeviceActor::New(),true),
103 myAppendFilter(vtkAppendPolyData::New(),true),
104 myPolyDataMapper(vtkPolyDataMapper::New(),true),
106 myHighlightProp(vtkProperty::New()),
107 myPreHighlightProp(vtkProperty::New()),
108 myShadingFaceProp(vtkProperty::New()),
110 // Making deflection relative similarly to GEOM_AISShape
111 myDeflection( .001 ),
115 MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
118 myPolyDataMapper->SetInput(myAppendFilter->GetOutput());
119 vtkProperty* aProperty;
121 myHighlightProp->SetAmbient(0.5);
122 myHighlightProp->SetDiffuse(0.3);
123 myHighlightProp->SetSpecular(0.2);
124 myHighlightProp->SetRepresentationToSurface();
125 myHighlightProp->SetAmbientColor(1, 1, 1);
126 myHighlightProp->SetDiffuseColor(1, 1, 1);
127 myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
128 myHighlightProp->SetPointSize(SALOME_POINT_SIZE);
129 myHighlightActor->SetProperty(myHighlightProp.GetPointer());
131 this->myHighlightActor->SetInput(myAppendFilter->GetOutput(),false);
133 myPreHighlightProp->SetColor(0,1,1);
134 myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
135 myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
136 myPreHighlightProp->SetRepresentationToWireframe();
138 myAppendFilter->AddInput(myVertexSource->GetOutput());
139 myVertexActor->SetInput(myVertexSource->GetOutput(),false);
140 aProperty = myVertexActor->GetProperty();
141 aProperty->SetRepresentation(VTK_POINTS);
142 aProperty->SetPointSize(3);
143 aProperty->SetColor(1, 1, 0);
145 myAppendFilter->AddInput(myIsolatedEdgeSource->GetOutput());
146 myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false);
147 aProperty = myIsolatedEdgeActor->GetProperty();
148 aProperty->SetRepresentation(VTK_WIREFRAME);
149 aProperty->SetColor(1, 0, 0);
151 myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput());
152 myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false);
153 aProperty = myOneFaceEdgeActor->GetProperty();
154 aProperty->SetRepresentation(VTK_WIREFRAME);
155 aProperty->SetColor(0, 1, 0);
157 myAppendFilter->AddInput(mySharedEdgeSource->GetOutput());
158 mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false);
159 aProperty = mySharedEdgeActor->GetProperty();
160 aProperty->SetRepresentation(VTK_WIREFRAME);
161 aProperty->SetColor(1, 1, 0);
163 myAppendFilter->AddInput(myWireframeFaceSource->GetOutput());
164 myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false);
165 aProperty = myWireframeFaceActor->GetProperty();
166 aProperty->SetRepresentation(VTK_WIREFRAME);
167 aProperty->SetColor(0.5, 0.5, 0.5);
169 myShadingFaceActor->SetInput(myShadingFaceSource->GetOutput(),true);
171 myShadingFaceProp->SetRepresentation(VTK_SURFACE);
172 myShadingFaceProp->SetInterpolationToGouraud();
173 myShadingFaceProp->SetAmbient(1.0);
174 myShadingFaceProp->SetDiffuse(1.0);
175 myShadingFaceProp->SetSpecular(0.4);
176 myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
177 myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
178 myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
180 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
182 // Toggle display mode
183 setDisplayMode(0); // WIRE FRAME
188 GEOM_Actor::~GEOM_Actor()
191 MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
193 myHighlightProp->Delete();
194 myPreHighlightProp->Delete();
195 myShadingFaceProp->Delete();
202 GEOM_Actor* anObject = new GEOM_Actor();
203 anObject->SetMapper(anObject->myPolyDataMapper.Get());
208 void Write(vtkPolyData* theDataSet, const char* theFileName){
209 vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
210 MESSAGE ("Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells());
211 aWriter->SetInput(theDataSet);
212 aWriter->SetFileName(theFileName);
221 this->myVertexSource->Modified();
222 this->myIsolatedEdgeSource->Modified();
223 this->myOneFaceEdgeSource->Modified();
224 this->mySharedEdgeSource->Modified();
225 this->myWireframeFaceSource->Modified();
226 this->myShadingFaceSource->Modified();
231 SetMapper(vtkMapper* theMapper)
233 SALOME_Actor::SetMapper(theMapper);
238 AddToRender(vtkRenderer* theRenderer)
240 //SALOME_Actor::AddToRender(theRenderer);
242 theRenderer->AddActor(this);
244 this->myHighlightActor->AddToRender(theRenderer);
247 myShadingFaceActor->AddToRender(theRenderer);
248 myWireframeFaceActor->AddToRender(theRenderer);
250 mySharedEdgeActor->AddToRender(theRenderer);
251 myOneFaceEdgeActor->AddToRender(theRenderer);
252 myIsolatedEdgeActor->AddToRender(theRenderer);
254 myVertexActor->AddToRender(theRenderer);
259 RemoveFromRender(vtkRenderer* theRenderer)
261 //SALOME_Actor::RemoveFromRender(theRenderer);
264 theRenderer->RemoveActor(this);
266 myHighlightActor->RemoveFromRender(theRenderer);
267 myShadingFaceActor->RemoveFromRender(theRenderer);
268 myWireframeFaceActor->RemoveFromRender(theRenderer);
270 mySharedEdgeActor->RemoveFromRender(theRenderer);
271 myOneFaceEdgeActor->RemoveFromRender(theRenderer);
272 myIsolatedEdgeActor->RemoveFromRender(theRenderer);
274 myVertexActor->RemoveFromRender(theRenderer);
278 SetVisibility(false);
283 setDisplayMode(int theMode)
286 MESSAGE ( "GEOM_Actor::SetDisplayMode = "<<theMode );
288 VTKViewer_Actor::setDisplayMode(theMode);
289 SetVisibility(GetVisibility());
294 SetSelected(bool theIsSelected)
297 MESSAGE ( "GEOM_Actor::SetSelected = "<<theIsSelected );
300 myIsSelected = theIsSelected;
301 SetVisibility(GetVisibility());
306 SetVisibility(int theVisibility)
309 MESSAGE ( "GEOM_Actor::SetVisibility = "<<theVisibility <<" myIsSelected="<< myIsSelected
310 << " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected );
313 SALOME_Actor::SetVisibility(theVisibility);
315 this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
317 myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading) && (!myIsSelected || !myIsPreselected));
318 myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode ==(int)eWireframe) && !myIsSelected);
320 mySharedEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
321 myOneFaceEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
322 myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
324 myVertexActor->SetVisibility(theVisibility && !myIsSelected);// must be added new mode points
330 ::SetNbIsos(const int theNb[2])
332 myWireframeFaceSource->SetNbIso(theNb);
337 ::GetNbIsos(int &theNbU,int &theNbV)
339 myWireframeFaceSource->GetNbIso(theNbU, theNbV);
344 ::SetVectorMode(bool theMode)
346 myVectorMode = theMode;
347 myIsolatedEdgeSource->SetVectorMode(theMode);
348 myOneFaceEdgeSource->SetVectorMode(theMode);
349 mySharedEdgeSource->SetVectorMode(theMode);
362 MeshShape(const TopoDS_Shape& theShape,
363 float& theDeflection,
366 static Standard_Real RELATIVE_DEFLECTION = 0.0001;
367 Standard_Real aDeflection = theDeflection <= 0 ? RELATIVE_DEFLECTION : theDeflection;
369 // theDeflection <= 0 -> Compute default theDeflection
370 // Otherwise compute the absolute deflection on the basis of relative
371 if(theDeflection <= 0 || theIsRelative ){
373 BRepBndLib::Add(theShape, B);
375 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
\r
376 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
\r
378 // This magic line comes from Prs3d_ShadedShape.gxx in OCCT
\r
379 aDeflection = std::max( aXmax-aXmin , std::max(aYmax-aYmin , aZmax-aZmin))
\r
383 // Just to assign some value, because a void bnd box is not a good case
384 aDeflection = RELATIVE_DEFLECTION;
386 if(theDeflection <= 0)
387 theDeflection = theIsRelative ? RELATIVE_DEFLECTION : aDeflection;
390 BRepMesh_IncrementalMesh aMesh(theShape,aDeflection);
395 SetDeflection(float theDeflection, bool theIsRelative)
397 myDeflection = theDeflection;
398 myIsRelative = theIsRelative;
400 MeshShape(myShape,myDeflection,myIsRelative);
405 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
412 myVertexSource->Clear();
413 myIsolatedEdgeSource->Clear();
414 myOneFaceEdgeSource->Clear();
415 mySharedEdgeSource->Clear();
416 myWireframeFaceSource->Clear();
417 myShadingFaceSource->Clear();
419 TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
420 for (; aVertexExp.More(); aVertexExp.Next())
422 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
423 myVertexSource->AddVertex(aVertex);
425 SetDeflection(theDeflection, theIsRelative);
427 // look if edges are free or shared
428 TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
429 TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
431 SetShape(theShape,anEdgeMap,theIsVector);
433 myIsolatedEdgeSource->IsEmpty() &&
434 myOneFaceEdgeSource->IsEmpty() &&
435 mySharedEdgeSource->IsEmpty() &&
436 myWireframeFaceSource->IsEmpty() &&
437 myShadingFaceSource->IsEmpty();
440 if((bool)myShape.Infinite() || isOnlyVertex ){
441 myVertexActor->GetDeviceActor()->SetInfinitive(true);
442 myHighlightActor->GetDeviceActor()->SetInfinitive(true);
446 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
447 const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap,
450 if (theShape.ShapeType() == TopAbs_COMPOUND) {
451 TopoDS_Iterator anItr(theShape);
452 for (; anItr.More(); anItr.Next()) {
453 SetShape(anItr.Value(),theEdgeMap,theIsVector);
457 switch (theShape.ShapeType()) {
459 TopExp_Explorer anEdgeExp(theShape,TopAbs_EDGE);
460 for (; anEdgeExp.More(); anEdgeExp.Next()){
461 const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
462 if (!BRep_Tool::Degenerated(anEdge))
463 myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
468 const TopoDS_Edge& anEdge = TopoDS::Edge(theShape);
469 if (!BRep_Tool::Degenerated(anEdge))
470 myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
473 case TopAbs_VERTEX: {
477 TopExp_Explorer aFaceExp (theShape,TopAbs_FACE);
478 for(; aFaceExp.More(); aFaceExp.Next()) {
479 const TopoDS_Face& aFace = TopoDS::Face(aFaceExp.Current());
480 myWireframeFaceSource->AddFace(aFace);
481 myShadingFaceSource->AddFace(aFace);
482 TopExp_Explorer anEdgeExp(aFaceExp.Current(), TopAbs_EDGE);
483 for(; anEdgeExp.More(); anEdgeExp.Next()) {
484 const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
485 if(!BRep_Tool::Degenerated(anEdge)){
486 // compute the number of faces
487 int aNbOfFaces = theEdgeMap.FindFromKey(anEdge).Extent();
489 case 0: // isolated edge
490 myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
492 case 1: // edge in only one face
493 myOneFaceEdgeSource->AddEdge(anEdge,theIsVector);
495 default: // edge shared by at least two faces
496 mySharedEdgeSource->AddEdge(anEdge,theIsVector);
506 void GEOM_Actor::setDeflection(double adef) {
508 MESSAGE ( "GEOM_Actor::setDeflection" );
510 SetDeflection((float)adef,GetIsRelative());
514 // warning! must be checked!
515 // SetHighlightProperty
516 // SetWireframeProperty
517 // SetShadingProperty
519 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
522 MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
524 this->myHighlightActor->GetProperty()->DeepCopy(Prop);
528 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
531 MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
534 myWireframeFaceActor->SetProperty(Prop);
537 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
540 MESSAGE ( "GEOM_Actor::SetShadingProperty" );
542 myShadingFaceProp->DeepCopy(Prop);
546 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
549 MESSAGE ( "GEOM_Actor::Render" );
555 /* render the property */
556 if (!this->Property) {
557 // force creation of a property
559 this->Property->SetInterpolation(1);
560 this->Property->SetRepresentationToSurface();
561 this->Property->SetAmbient(0.3);
562 this->Property->SetAmbientColor(0.88,0.86,0.2);
563 this->Property->SetDiffuseColor(0.99,0.7,0.21);
564 this->Property->SetSpecularColor(0.99,0.98,0.83);
567 switch(myDisplayMode){
569 myPreHighlightProp->SetRepresentationToWireframe();
570 myHighlightProp->SetRepresentationToWireframe();
573 myPreHighlightProp->SetRepresentationToSurface();
574 myHighlightProp->SetRepresentationToSurface();
580 this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
581 myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
583 this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
584 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
588 this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
589 myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
592 this->Property->Render(this, ren);
593 if (this->BackfaceProperty) {
594 this->BackfaceProperty->BackfaceRender(this, ren);
595 this->Device->SetBackfaceProperty(this->BackfaceProperty);
597 this->Device->SetProperty(this->Property);
598 /* if(myShape.ShapeType() == TopAbs_VERTEX) {
600 //The parameter determine size of vertex actor relate to diagonal of RendererWindow
601 static vtkFloatingPointType delta = 0.01;
602 vtkFloatingPointType X1 = -1, Y1 = -1, Z1 = 0;
603 ren->ViewToWorld(X1,Y1,Z1);
604 vtkFloatingPointType X2 = +1, Y2 = +1, Z2 = 0;
605 ren->ViewToWorld(X2,Y2,Z2);
606 Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
607 this->SetScale(Z2*delta);
609 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
610 this->GetMatrix(ren->GetActiveCamera(), aMatrix);
611 this->Device->SetUserMatrix(aMatrix);
612 this->Device->Render(ren,theMapper);
615 this->Device->Render(ren, theMapper);
618 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
621 MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
627 void GEOM_Actor::ShallowCopy(vtkProp *prop)
630 MESSAGE ( "GEOM_Actor::ShallowCopy" );
632 GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
635 this->SetShape(f->getTopo(),f->GetDeflection(),f->GetIsRelative());
639 this->SALOME_Actor::ShallowCopy(prop);
642 const TopoDS_Shape& GEOM_Actor::getTopo() {
644 MESSAGE ( "GEOM_Actor::getTopo" );
649 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
650 int imode, bool isVector)
653 MESSAGE ( "GEOM_Actor::setInputShape" );
657 double GEOM_Actor::getDeflection()
660 MESSAGE ( "GEOM_Actor::getDeflection" );
662 return (double) GetDeflection();
666 double GEOM_Actor::isVector()
669 MESSAGE ( "GEOM_Actor::isVector" );
674 void GEOM_Actor::SubShapeOn()
677 MESSAGE ( "GEOM_Actor::SubShapeOn" );
681 void GEOM_Actor::SubShapeOff()
684 MESSAGE ( "GEOM_Actor::SubShapeOff" );
688 void GEOM_Actor::highlight(bool highlight)
691 MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
693 SALOME_Actor::highlight(highlight);
696 void GEOM_Actor::SetOpacity(vtkFloatingPointType opa)
699 myShadingFaceProp->SetOpacity(opa);
700 myHighlightProp->SetOpacity(opa);
701 myPreHighlightProp->SetOpacity(opa);
702 myVertexActor->GetProperty()->SetOpacity(opa);
705 vtkFloatingPointType GEOM_Actor::GetOpacity()
708 return myShadingFaceProp->GetOpacity();
711 void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
714 myShadingFaceProp->SetColor(r,g,b); // shading color (Shading)
715 myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b); // standalone edge color (Wireframe)
716 myVertexActor->GetProperty()->SetColor(r,g,b); // vertex actor (Shading/Wireframe)
717 myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b); // standalone face edge color (Wireframe)
718 mySharedEdgeActor->GetProperty()->SetColor(r,g,b); // share edge color (Wireframe)
721 void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
724 vtkFloatingPointType aRGB[3];
725 myShadingFaceProp->GetColor(aRGB);
731 bool GEOM_Actor::IsInfinitive()
733 return ((bool)myShape.Infinite() || isOnlyVertex);
737 To map current selection to VTK representation
741 ::Highlight(bool theIsHighlight)
743 myIsSelected = theIsHighlight;
745 MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
748 SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
749 SetVisibility(GetVisibility());
753 To process prehighlight (called from SVTK_InteractorStyle)
757 ::PreHighlight(vtkInteractorStyle *theInteractorStyle,
758 SVTK_SelectionEvent* theSelectionEvent,
762 MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
765 if ( !GetPickable() )
768 myPreHighlightActor->SetVisibility( false );
769 bool anIsPreselected = myIsPreselected;
771 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
772 bool anIsChanged = (mySelectionMode != aSelectionMode);
774 if( !theIsHighlight ) {
775 SetPreSelected( false );
777 switch(aSelectionMode){
778 case ActorSelection :
780 // cout << "=============== " << myIO->getEntry() << endl;
781 int nbio = mySelector->IObjectCount();
782 // cout << " nbio = " << nbio << endl;
784 if( !mySelector->IsSelected( myIO ) ) {
785 // printf ("!!!!!!!!!!!!!!!!\n");
786 SetPreSelected( true );
794 mySelectionMode = aSelectionMode;
795 anIsChanged |= (anIsPreselected != myIsPreselected);
797 SetVisibility(GetVisibility());
802 To process highlight (called from SVTK_InteractorStyle)
806 ::Highlight(vtkInteractorStyle *theInteractorStyle,
807 SVTK_SelectionEvent* theSelectionEvent,
810 // define the selection of object
812 MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
814 bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
815 SetSelected(theIsHighlight);
817 SetPreSelected(false);
823 // Copy the follower's composite 4x4 matrix into the matrix provided.
824 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
827 double Rx[3], Ry[3], Rz[3], p1[3];
828 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
832 this->GetOrientation();
833 this->Transform->Push();
834 this->Transform->PostMultiply();
835 this->Transform->Identity();
837 // apply user defined matrix last if there is one
838 if (this->UserMatrix)
840 this->Transform->Concatenate(this->UserMatrix);
843 this->Transform->Translate(-this->Origin[0],
847 this->Transform->Scale(this->Scale[0],
852 this->Transform->RotateY(this->Orientation[1]);
853 this->Transform->RotateX(this->Orientation[0]);
854 this->Transform->RotateZ(this->Orientation[2]);
860 pos = theCam->GetPosition();
861 vup = theCam->GetViewUp();
863 if (theCam->GetParallelProjection())
865 theCam->GetDirectionOfProjection(Rz);
870 (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
871 (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
872 (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
873 for (i = 0; i < 3; i++)
875 Rz[i] = (pos[i] - this->Position[i])/distance;
879 vtkMath::Cross(vup,Rz,Rx);
880 vtkMath::Normalize(Rx);
881 vtkMath::Cross(Rz,Rx,Ry);
883 matrix->Element[0][0] = Rx[0];
884 matrix->Element[1][0] = Rx[1];
885 matrix->Element[2][0] = Rx[2];
886 matrix->Element[0][1] = Ry[0];
887 matrix->Element[1][1] = Ry[1];
888 matrix->Element[2][1] = Ry[2];
889 matrix->Element[0][2] = Rz[0];
890 matrix->Element[1][2] = Rz[1];
891 matrix->Element[2][2] = Rz[2];
893 this->Transform->Concatenate(matrix);
896 // translate to projection reference point PRP
897 // this is the camera's position blasted through
898 // the current matrix
899 p1[0] = this->Origin[0] + this->Position[0];
900 p1[1] = this->Origin[1] + this->Position[1];
901 p1[2] = this->Origin[2] + this->Position[2];
903 this->Transform->Translate(p1[0],p1[1],p1[2]);
904 this->Transform->GetMatrix(result);
907 this->Transform->Pop();