1 // Copyright (C) 2007-2012 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 "GEOM_PainterPolyDataMapper.h"
41 #include "SVTK_Actor.h"
43 #include <OCC2VTK_Tools.h>
45 #include <vtkObjectFactory.h>
46 #include <vtkRenderer.h>
47 #include <vtkProperty.h>
48 #include <vtkPointPicker.h>
49 #include <vtkCellPicker.h>
51 #include <TopAbs_ShapeEnum.hxx>
52 #include <TopExp_Explorer.hxx>
54 #include <BRep_Tool.hxx>
57 #include <vtkPolyDataWriter.h>
59 #include <vtkAppendPolyData.h>
60 #include <vtkPolyDataMapper.h>
61 #include <vtkPolyData.h>
62 #include <vtkTransform.h>
63 #include <vtkMatrix4x4.h>
65 #include <vtkCamera.h>
67 #include "utilities.h"
69 #include "SALOME_InteractiveObject.hxx"
71 //vtkStandardNewMacro(GEOM_Actor);
77 GEOM_Actor::GEOM_Actor():
83 // myDisplayMode(eWireframe),
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())
119 MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
122 myPolyDataMapper->SetInput(myAppendFilter->GetOutput());
123 vtkProperty* aProperty;
125 myHighlightProp->SetAmbient(0.5);
126 myHighlightProp->SetDiffuse(0.3);
127 myHighlightProp->SetSpecular(0.2);
128 myHighlightProp->SetRepresentationToSurface();
129 myHighlightProp->SetAmbientColor(1, 1, 1);
130 myHighlightProp->SetDiffuseColor(1, 1, 1);
131 myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
132 myHighlightProp->SetPointSize(SALOME_POINT_SIZE);
133 myHighlightActor->SetProperty(myHighlightProp.GetPointer());
135 this->myHighlightActor->SetInput(myAppendFilter->GetOutput(),false);
137 myPreHighlightProp->SetColor(0,1,1);
138 myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
139 myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
140 myPreHighlightProp->SetRepresentationToWireframe();
142 myAppendFilter->AddInput(myVertexSource->GetOutput());
143 myVertexActor->SetInput(myVertexSource->GetOutput(),false);
144 aProperty = myVertexActor->GetProperty();
145 aProperty->SetRepresentation(VTK_POINTS);
146 aProperty->SetPointSize(3);
147 aProperty->SetColor(1, 1, 0);
149 myAppendFilter->AddInput(myIsolatedEdgeSource->GetOutput());
150 myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false);
151 aProperty = myIsolatedEdgeActor->GetProperty();
152 aProperty->SetRepresentation(VTK_WIREFRAME);
153 aProperty->SetColor(1, 0, 0);
155 myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput());
156 myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false);
157 aProperty = myOneFaceEdgeActor->GetProperty();
158 aProperty->SetRepresentation(VTK_WIREFRAME);
159 aProperty->SetColor(0, 1, 0);
161 myAppendFilter->AddInput(mySharedEdgeSource->GetOutput());
162 mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false);
163 aProperty = mySharedEdgeActor->GetProperty();
164 aProperty->SetRepresentation(VTK_WIREFRAME);
165 aProperty->SetColor(1, 1, 0);
167 myAppendFilter->AddInput(myWireframeFaceSource->GetOutput());
168 myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false);
169 aProperty = myWireframeFaceActor->GetProperty();
170 aProperty->SetRepresentation(VTK_WIREFRAME);
171 aProperty->SetColor(0.5, 0.5, 0.5);
173 myShadingFaceActor->SetInput(myShadingFaceSource->GetOutput(),true);
175 myShadingFaceProp->SetRepresentation(VTKViewer::Representation::Surface);
176 myShadingFaceProp->SetInterpolationToGouraud();
177 myShadingFaceProp->SetAmbient(1.0);
178 myShadingFaceProp->SetDiffuse(1.0);
179 myShadingFaceProp->SetSpecular(0.4);
180 myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
181 myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
182 myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
184 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
186 StoreBoundaryColors();
191 // Toggle display mode
192 setDisplayMode(0); // WIRE FRAME
197 GEOM_Actor::~GEOM_Actor()
200 MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
202 myHighlightProp->Delete();
203 myPreHighlightProp->Delete();
204 myShadingFaceProp->Delete();
211 GEOM_Actor* anObject = new GEOM_Actor();
212 anObject->SetMapper(anObject->myPolyDataMapper.Get());
217 void Write(vtkPolyData* theDataSet, const char* theFileName){
218 vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
219 MESSAGE ("Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells());
220 aWriter->SetInput(theDataSet);
221 aWriter->SetFileName(theFileName);
230 this->myVertexSource->Modified();
231 this->myIsolatedEdgeSource->Modified();
232 this->myOneFaceEdgeSource->Modified();
233 this->mySharedEdgeSource->Modified();
234 this->myWireframeFaceSource->Modified();
235 this->myShadingFaceSource->Modified();
240 SetMapper(vtkMapper* theMapper)
242 SALOME_Actor::SetMapper(theMapper);
247 AddToRender(vtkRenderer* theRenderer)
249 //SALOME_Actor::AddToRender(theRenderer);
251 theRenderer->AddActor(this);
253 this->myHighlightActor->AddToRender(theRenderer);
256 myShadingFaceActor->AddToRender(theRenderer);
257 myWireframeFaceActor->AddToRender(theRenderer);
259 mySharedEdgeActor->AddToRender(theRenderer);
260 myOneFaceEdgeActor->AddToRender(theRenderer);
261 myIsolatedEdgeActor->AddToRender(theRenderer);
263 myVertexActor->AddToRender(theRenderer);
268 RemoveFromRender(vtkRenderer* theRenderer)
270 //SALOME_Actor::RemoveFromRender(theRenderer);
273 theRenderer->RemoveActor(this);
275 myHighlightActor->RemoveFromRender(theRenderer);
276 myShadingFaceActor->RemoveFromRender(theRenderer);
277 myWireframeFaceActor->RemoveFromRender(theRenderer);
279 mySharedEdgeActor->RemoveFromRender(theRenderer);
280 myOneFaceEdgeActor->RemoveFromRender(theRenderer);
281 myIsolatedEdgeActor->RemoveFromRender(theRenderer);
283 myVertexActor->RemoveFromRender(theRenderer);
287 SetVisibility(false);
292 setDisplayMode(int theMode)
295 MESSAGE ( "GEOM_Actor::setDisplayMode = "<<theMode );
298 if ( theMode == (int)eWireframe ) {
300 // Restore wireframe edges colors
301 RestoreBoundaryColors();
303 else if ( theMode == (int)eShading || theMode == (int)eShadingWithEdges ) {
304 // Temporary store number of iso lines in order to recover its later
305 // when display mode is achnged to 'Wirefame' or 'Shading'.
306 // Iso lines are not displayed in 'Shading with edges' mode.
309 // Reset number of iso lines to 0
312 if ( theMode == (int)eShadingWithEdges ) {
313 // Store wireframe edges colors
314 StoreBoundaryColors();
317 myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
318 myEdgesInShadingColor[1],
319 myEdgesInShadingColor[2]);
320 myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
321 myEdgesInShadingColor[1],
322 myEdgesInShadingColor[2]);
323 mySharedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
324 myEdgesInShadingColor[1],
325 myEdgesInShadingColor[2]);
328 myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
329 myEdgesInWireframeColor[1],
330 myEdgesInWireframeColor[2]);
334 VTKViewer_Actor::setDisplayMode(theMode);
335 SetVisibility(GetVisibility());
340 SetSelected(bool theIsSelected)
343 MESSAGE ( "GEOM_Actor::SetSelected = "<<theIsSelected );
346 myIsSelected = theIsSelected;
347 SetVisibility(GetVisibility());
352 SetVisibility(int theVisibility)
355 MESSAGE ( "GEOM_Actor::SetVisibility = "<<theVisibility <<" myIsSelected="<< myIsSelected
356 << " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected );
359 SALOME_Actor::SetVisibility(theVisibility);
361 this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
363 myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges) && (!myIsSelected || !myIsPreselected));
364 myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe) && !myIsSelected);
366 mySharedEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
367 myOneFaceEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
368 myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
370 myVertexActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);// must be added new mode points
376 ::SetNbIsos(const int theNb[2])
378 myWireframeFaceSource->SetNbIso(theNb);
383 ::GetNbIsos(int &theNbU,int &theNbV)
385 myWireframeFaceSource->GetNbIso(theNbU, theNbV);
390 ::SetVectorMode(bool theMode)
392 myVectorMode = theMode;
393 myIsolatedEdgeSource->SetVectorMode(theMode);
394 myOneFaceEdgeSource->SetVectorMode(theMode);
395 mySharedEdgeSource->SetVectorMode(theMode);
408 SetDeflection(float theDeflection)
410 if( myDeflection == theDeflection )
413 myDeflection = theDeflection;
415 GEOM::MeshShape(myShape,myDeflection);
420 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
426 myVertexSource->Clear();
427 myIsolatedEdgeSource->Clear();
428 myOneFaceEdgeSource->Clear();
429 mySharedEdgeSource->Clear();
430 myWireframeFaceSource->Clear();
431 myShadingFaceSource->Clear();
433 TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
434 for (; aVertexExp.More(); aVertexExp.Next())
436 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
437 myVertexSource->AddVertex(aVertex);
440 SetDeflection(theDeflection);
442 // look if edges are free or shared
443 TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
444 TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
446 GEOM::SetShape(theShape,anEdgeMap,theIsVector,
447 myIsolatedEdgeSource.Get(),
448 myOneFaceEdgeSource.Get(),
449 mySharedEdgeSource.Get(),
450 myWireframeFaceSource.Get(),
451 myShadingFaceSource.Get());
453 myIsolatedEdgeSource->IsEmpty() &&
454 myOneFaceEdgeSource->IsEmpty() &&
455 mySharedEdgeSource->IsEmpty() &&
456 myWireframeFaceSource->IsEmpty() &&
457 myShadingFaceSource->IsEmpty();
460 if((bool)myShape.Infinite() || isOnlyVertex ){
461 myVertexActor->GetDeviceActor()->SetInfinitive(true);
462 myHighlightActor->GetDeviceActor()->SetInfinitive(true);
467 void GEOM_Actor::setDeflection(double adef) {
469 MESSAGE ( "GEOM_Actor::setDeflection" );
471 SetDeflection((float)adef);
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);
499 vtkProperty* GEOM_Actor::GetWireframeProperty()
501 return myWireframeFaceActor->GetProperty();
504 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
507 MESSAGE ( "GEOM_Actor::SetShadingProperty" );
509 myShadingFaceProp->DeepCopy(Prop);
513 vtkProperty* GEOM_Actor::GetShadingProperty()
515 return myShadingFaceProp;
519 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
522 MESSAGE ( "GEOM_Actor::Render" );
528 /* render the property */
529 if (!this->Property) {
530 // force creation of a property
532 this->Property->SetInterpolation(1);
533 this->Property->SetRepresentationToSurface();
534 this->Property->SetAmbient(0.3);
535 this->Property->SetAmbientColor(0.88,0.86,0.2);
536 this->Property->SetDiffuseColor(0.99,0.7,0.21);
537 this->Property->SetSpecularColor(0.99,0.98,0.83);
540 switch(myDisplayMode){
541 case eWireframe://wireframe
542 myPreHighlightProp->SetRepresentationToWireframe();
543 myHighlightProp->SetRepresentationToWireframe();
545 case eShading://shading
546 case eShadingWithEdges://shading with edges
547 myPreHighlightProp->SetRepresentationToSurface();
548 myHighlightProp->SetRepresentationToSurface();
549 myShadingFaceProp->SetRepresentationToSurface();
555 this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
556 myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
558 this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
559 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
563 this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
564 myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
567 this->Property->Render(this, ren);
568 if (this->BackfaceProperty) {
569 this->BackfaceProperty->BackfaceRender(this, ren);
570 this->Device->SetBackfaceProperty(this->BackfaceProperty);
572 this->Device->SetProperty(this->Property);
573 /* if(myShape.ShapeType() == TopAbs_VERTEX) {
575 //The parameter determine size of vertex actor relate to diagonal of RendererWindow
576 static vtkFloatingPointType delta = 0.01;
577 vtkFloatingPointType X1 = -1, Y1 = -1, Z1 = 0;
578 ren->ViewToWorld(X1,Y1,Z1);
579 vtkFloatingPointType X2 = +1, Y2 = +1, Z2 = 0;
580 ren->ViewToWorld(X2,Y2,Z2);
581 Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
582 this->SetScale(Z2*delta);
584 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
585 this->GetMatrix(ren->GetActiveCamera(), aMatrix);
586 this->Device->SetUserMatrix(aMatrix);
587 this->Device->Render(ren,theMapper);
590 this->Device->Render(ren, theMapper);
593 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
596 MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
602 void GEOM_Actor::ShallowCopy(vtkProp *prop)
605 MESSAGE ( "GEOM_Actor::ShallowCopy" );
607 GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
610 this->SetShape(f->getTopo(),f->GetDeflection());
614 this->SALOME_Actor::ShallowCopy(prop);
617 const TopoDS_Shape& GEOM_Actor::getTopo() {
619 MESSAGE ( "GEOM_Actor::getTopo" );
624 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
625 int imode, bool isVector)
628 MESSAGE ( "GEOM_Actor::setInputShape" );
632 double GEOM_Actor::getDeflection()
635 MESSAGE ( "GEOM_Actor::getDeflection" );
637 return (double) GetDeflection();
641 double GEOM_Actor::isVector()
644 MESSAGE ( "GEOM_Actor::isVector" );
649 void GEOM_Actor::SubShapeOn()
652 MESSAGE ( "GEOM_Actor::SubShapeOn" );
656 void GEOM_Actor::SubShapeOff()
659 MESSAGE ( "GEOM_Actor::SubShapeOff" );
663 void GEOM_Actor::highlight(bool highlight)
666 MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
668 SALOME_Actor::highlight(highlight);
671 void GEOM_Actor::SetOpacity(vtkFloatingPointType opa)
674 myShadingFaceProp->SetOpacity(opa);
675 myHighlightProp->SetOpacity(opa);
676 myPreHighlightProp->SetOpacity(opa);
677 myVertexActor->GetProperty()->SetOpacity(opa);
680 vtkFloatingPointType GEOM_Actor::GetOpacity()
683 return myShadingFaceProp->GetOpacity();
686 void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
689 myShadingFaceProp->SetColor(r,g,b); // shading color (Shading)
690 myVertexActor->GetProperty()->SetColor(r,g,b); // vertex actor (Shading/Wireframe)
691 if ( myDisplayMode != (int)eShadingWithEdges ) {
692 myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b); // standalone edge color (Wireframe)
693 myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b); // standalone face edge color (Wireframe)
694 mySharedEdgeActor->GetProperty()->SetColor(r,g,b); // share edge color (Wireframe)
697 StoreBoundaryColors();
700 void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
703 vtkFloatingPointType aRGB[3];
704 myShadingFaceProp->GetColor(aRGB);
710 void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
712 // we set material properties as back and front material
715 // Set reflection coefficients
716 aCoefnt = theProps[0]->GetAmbient();
717 myShadingFaceProp->SetAmbient(aCoefnt);
718 myVertexActor->GetProperty()->SetAmbient(aCoefnt);
720 // Set diffuse coefficients
721 aCoefnt = theProps[0]->GetDiffuse();
722 myShadingFaceProp->SetDiffuse(aCoefnt);
723 myVertexActor->GetProperty()->SetDiffuse(aCoefnt);
725 // Set specular coefficients
726 aCoefnt = theProps[0]->GetSpecular();
727 myShadingFaceProp->SetSpecular(aCoefnt);
728 myVertexActor->GetProperty()->SetSpecular(aCoefnt);
732 // Set reflection colors
733 aColor = theProps[0]->GetAmbientColor();
734 myShadingFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
735 myVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
737 // Set diffuse colors
738 aColor = theProps[0]->GetDiffuseColor();
739 myShadingFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
740 myVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
742 // Set specular colors
743 aColor = theProps[0]->GetSpecularColor();
744 myShadingFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
745 myVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
748 aCoefnt = theProps[0]->GetSpecularPower();
749 myShadingFaceProp->SetSpecularPower(aCoefnt);
750 myVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
753 vtkProperty* GEOM_Actor::GetMaterial()
755 return myShadingFaceProp;
758 bool GEOM_Actor::IsInfinitive()
760 return ((bool)myShape.Infinite() || isOnlyVertex);
764 To map current selection to VTK representation
768 ::Highlight(bool theIsHighlight)
770 myIsSelected = theIsHighlight;
772 MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
775 if ( myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges ) {
776 if ( theIsHighlight )
779 // Reset number of iso lines to 0
783 SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
784 SetVisibility(GetVisibility());
788 To process prehighlight (called from SVTK_InteractorStyle)
792 ::PreHighlight(vtkInteractorStyle *theInteractorStyle,
793 SVTK_SelectionEvent* theSelectionEvent,
797 MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
800 if ( !GetPickable() )
803 if ( myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges ) {
804 if ( theIsHighlight )
807 // Reset number of iso lines to 0
811 myPreHighlightActor->SetVisibility( false );
812 bool anIsPreselected = myIsPreselected;
814 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
815 bool anIsChanged = (mySelectionMode != aSelectionMode);
817 if( !theIsHighlight ) {
818 SetPreSelected( false );
820 switch(aSelectionMode){
821 case ActorSelection :
823 // cout << "=============== " << myIO->getEntry() << endl;
824 // int nbio = mySelector->IObjectCount();
825 // cout << " nbio = " << nbio << endl;
827 if( !mySelector->IsSelected( myIO ) ) {
828 // printf ("!!!!!!!!!!!!!!!!\n");
829 SetPreSelected( true );
837 mySelectionMode = aSelectionMode;
838 anIsChanged |= (anIsPreselected != myIsPreselected);
840 SetVisibility(GetVisibility());
845 To process highlight (called from SVTK_InteractorStyle)
849 ::Highlight(vtkInteractorStyle *theInteractorStyle,
850 SVTK_SelectionEvent* theSelectionEvent,
853 // define the selection of object
855 MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
857 bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
858 SetSelected(theIsHighlight);
860 SetPreSelected(false);
866 // Copy the follower's composite 4x4 matrix into the matrix provided.
867 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
870 double Rx[3], Ry[3], Rz[3], p1[3];
871 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
875 this->GetOrientation();
876 this->Transform->Push();
877 this->Transform->PostMultiply();
878 this->Transform->Identity();
880 // apply user defined matrix last if there is one
881 if (this->UserMatrix)
883 this->Transform->Concatenate(this->UserMatrix);
886 this->Transform->Translate(-this->Origin[0],
890 this->Transform->Scale(this->Scale[0],
895 this->Transform->RotateY(this->Orientation[1]);
896 this->Transform->RotateX(this->Orientation[0]);
897 this->Transform->RotateZ(this->Orientation[2]);
903 pos = theCam->GetPosition();
904 vup = theCam->GetViewUp();
906 if (theCam->GetParallelProjection())
908 theCam->GetDirectionOfProjection(Rz);
913 (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
914 (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
915 (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
916 for (i = 0; i < 3; i++)
918 Rz[i] = (pos[i] - this->Position[i])/distance;
922 vtkMath::Cross(vup,Rz,Rx);
923 vtkMath::Normalize(Rx);
924 vtkMath::Cross(Rz,Rx,Ry);
926 matrix->Element[0][0] = Rx[0];
927 matrix->Element[1][0] = Rx[1];
928 matrix->Element[2][0] = Rx[2];
929 matrix->Element[0][1] = Ry[0];
930 matrix->Element[1][1] = Ry[1];
931 matrix->Element[2][1] = Ry[2];
932 matrix->Element[0][2] = Rz[0];
933 matrix->Element[1][2] = Rz[1];
934 matrix->Element[2][2] = Rz[2];
936 this->Transform->Concatenate(matrix);
939 // translate to projection reference point PRP
940 // this is the camera's position blasted through
941 // the current matrix
942 p1[0] = this->Origin[0] + this->Position[0];
943 p1[1] = this->Origin[1] + this->Position[1];
944 p1[2] = this->Origin[2] + this->Position[2];
946 this->Transform->Translate(p1[0],p1[1],p1[2]);
947 this->Transform->GetMatrix(result);
950 this->Transform->Pop();
953 void GEOM_Actor::SetEdgesInShadingColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
955 myEdgesInShadingColor[0] = r;
956 myEdgesInShadingColor[1] = g;
957 myEdgesInShadingColor[2] = b;
960 void GEOM_Actor::StoreIsoNumbers()
962 myWireframeFaceSource->GetNbIso(myNbIsos[0], myNbIsos[1]);
965 void GEOM_Actor::SetIsosWidth(const int width) {
966 myWireframeFaceActor->GetProperty()->SetLineWidth(width);
969 int GEOM_Actor::GetIsosWidth() const {
970 return (int)myWireframeFaceActor->GetProperty()->GetLineWidth();
973 void GEOM_Actor::SetWidth(const int width) {
974 myIsolatedEdgeActor->GetProperty()->SetLineWidth(width);
975 myOneFaceEdgeActor->GetProperty()->SetLineWidth(width);
976 mySharedEdgeActor->GetProperty()->SetLineWidth(width);
977 myHighlightProp->SetLineWidth(width);
978 myPreHighlightProp->SetLineWidth(width+1);
982 int GEOM_Actor::GetWidth() const {
983 return (int)myIsolatedEdgeActor->GetProperty()->GetLineWidth();
986 void GEOM_Actor::RestoreIsoNumbers()
988 if ( myNbIsos[0] > 0 || myNbIsos[1] > 0 )
989 // Restore number of U and (or) V iso lines
990 myWireframeFaceSource->SetNbIso(myNbIsos);
993 void GEOM_Actor::ResetIsoNumbers()
996 myWireframeFaceSource->SetNbIso(aNb);
999 void GEOM_Actor::StoreBoundaryColors()
1001 myShadingFaceProp->GetColor(myEdgesInWireframeColor);
1005 void GEOM_Actor::RestoreBoundaryColors()
1007 myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
1008 myEdgesInWireframeColor[1],
1009 myEdgesInWireframeColor[2]);
1010 myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
1011 myEdgesInWireframeColor[1],
1012 myEdgesInWireframeColor[2]);
1013 mySharedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
1014 myEdgesInWireframeColor[1],
1015 myEdgesInWireframeColor[2]);