1 // Copyright (C) 2007-2011 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()),
117 myShadingBackFaceProp(vtkProperty::New())
120 MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
123 myPolyDataMapper->SetInput(myAppendFilter->GetOutput());
124 vtkProperty* aProperty;
126 myHighlightProp->SetAmbient(0.5);
127 myHighlightProp->SetDiffuse(0.3);
128 myHighlightProp->SetSpecular(0.2);
129 myHighlightProp->SetRepresentationToSurface();
130 myHighlightProp->SetAmbientColor(1, 1, 1);
131 myHighlightProp->SetDiffuseColor(1, 1, 1);
132 myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
133 myHighlightProp->SetPointSize(SALOME_POINT_SIZE);
134 myHighlightActor->SetProperty(myHighlightProp.GetPointer());
136 this->myHighlightActor->SetInput(myAppendFilter->GetOutput(),false);
138 myPreHighlightProp->SetColor(0,1,1);
139 myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
140 myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
141 myPreHighlightProp->SetRepresentationToWireframe();
143 myAppendFilter->AddInput(myVertexSource->GetOutput());
144 myVertexActor->SetInput(myVertexSource->GetOutput(),false);
145 aProperty = myVertexActor->GetProperty();
146 aProperty->SetRepresentation(VTK_POINTS);
147 aProperty->SetPointSize(3);
148 aProperty->SetColor(1, 1, 0);
150 myAppendFilter->AddInput(myIsolatedEdgeSource->GetOutput());
151 myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false);
152 aProperty = myIsolatedEdgeActor->GetProperty();
153 aProperty->SetRepresentation(VTK_WIREFRAME);
154 aProperty->SetColor(1, 0, 0);
156 myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput());
157 myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false);
158 aProperty = myOneFaceEdgeActor->GetProperty();
159 aProperty->SetRepresentation(VTK_WIREFRAME);
160 aProperty->SetColor(0, 1, 0);
162 myAppendFilter->AddInput(mySharedEdgeSource->GetOutput());
163 mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false);
164 aProperty = mySharedEdgeActor->GetProperty();
165 aProperty->SetRepresentation(VTK_WIREFRAME);
166 aProperty->SetColor(1, 1, 0);
168 myAppendFilter->AddInput(myWireframeFaceSource->GetOutput());
169 myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false);
170 aProperty = myWireframeFaceActor->GetProperty();
171 aProperty->SetRepresentation(VTK_WIREFRAME);
172 aProperty->SetColor(0.5, 0.5, 0.5);
174 myShadingFaceActor->SetInput(myShadingFaceSource->GetOutput(),true);
176 myShadingFaceProp->SetRepresentation(VTKViewer::Representation::Surface);
177 myShadingFaceProp->SetInterpolationToGouraud();
178 myShadingFaceProp->SetAmbient(1.0);
179 myShadingFaceProp->SetDiffuse(1.0);
180 myShadingFaceProp->SetSpecular(0.4);
181 myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
182 myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
183 myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
185 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
187 StoreBoundaryColors();
192 // Toggle display mode
193 setDisplayMode(0); // WIRE FRAME
198 GEOM_Actor::~GEOM_Actor()
201 MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
203 myHighlightProp->Delete();
204 myPreHighlightProp->Delete();
205 myShadingFaceProp->Delete();
206 myShadingBackFaceProp->Delete();
213 GEOM_Actor* anObject = new GEOM_Actor();
214 anObject->SetMapper(anObject->myPolyDataMapper.Get());
219 void Write(vtkPolyData* theDataSet, const char* theFileName){
220 vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
221 MESSAGE ("Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells());
222 aWriter->SetInput(theDataSet);
223 aWriter->SetFileName(theFileName);
232 this->myVertexSource->Modified();
233 this->myIsolatedEdgeSource->Modified();
234 this->myOneFaceEdgeSource->Modified();
235 this->mySharedEdgeSource->Modified();
236 this->myWireframeFaceSource->Modified();
237 this->myShadingFaceSource->Modified();
242 SetMapper(vtkMapper* theMapper)
244 SALOME_Actor::SetMapper(theMapper);
249 AddToRender(vtkRenderer* theRenderer)
251 //SALOME_Actor::AddToRender(theRenderer);
253 theRenderer->AddActor(this);
255 this->myHighlightActor->AddToRender(theRenderer);
258 myShadingFaceActor->AddToRender(theRenderer);
259 myWireframeFaceActor->AddToRender(theRenderer);
261 mySharedEdgeActor->AddToRender(theRenderer);
262 myOneFaceEdgeActor->AddToRender(theRenderer);
263 myIsolatedEdgeActor->AddToRender(theRenderer);
265 myVertexActor->AddToRender(theRenderer);
270 RemoveFromRender(vtkRenderer* theRenderer)
272 //SALOME_Actor::RemoveFromRender(theRenderer);
275 theRenderer->RemoveActor(this);
277 myHighlightActor->RemoveFromRender(theRenderer);
278 myShadingFaceActor->RemoveFromRender(theRenderer);
279 myWireframeFaceActor->RemoveFromRender(theRenderer);
281 mySharedEdgeActor->RemoveFromRender(theRenderer);
282 myOneFaceEdgeActor->RemoveFromRender(theRenderer);
283 myIsolatedEdgeActor->RemoveFromRender(theRenderer);
285 myVertexActor->RemoveFromRender(theRenderer);
289 SetVisibility(false);
294 setDisplayMode(int theMode)
297 MESSAGE ( "GEOM_Actor::setDisplayMode = "<<theMode );
300 if ( theMode == (int)eWireframe ) {
302 // Restore wireframe edges colors
303 RestoreBoundaryColors();
305 else if ( theMode == (int)eShading || theMode == (int)eShadingWithEdges ) {
306 // Temporary store number of iso lines in order to recover its later
307 // when display mode is achnged to 'Wirefame' or 'Shading'.
308 // Iso lines are not displayed in 'Shading with edges' mode.
311 // Reset number of iso lines to 0
314 if ( theMode == (int)eShadingWithEdges ) {
315 // Store wireframe edges colors
316 StoreBoundaryColors();
319 myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
320 myEdgesInShadingColor[1],
321 myEdgesInShadingColor[2]);
322 myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
323 myEdgesInShadingColor[1],
324 myEdgesInShadingColor[2]);
325 mySharedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
326 myEdgesInShadingColor[1],
327 myEdgesInShadingColor[2]);
330 myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
331 myEdgesInWireframeColor[1],
332 myEdgesInWireframeColor[2]);
336 VTKViewer_Actor::setDisplayMode(theMode);
337 SetVisibility(GetVisibility());
342 SetSelected(bool theIsSelected)
345 MESSAGE ( "GEOM_Actor::SetSelected = "<<theIsSelected );
348 myIsSelected = theIsSelected;
349 SetVisibility(GetVisibility());
354 SetVisibility(int theVisibility)
357 MESSAGE ( "GEOM_Actor::SetVisibility = "<<theVisibility <<" myIsSelected="<< myIsSelected
358 << " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected );
361 SALOME_Actor::SetVisibility(theVisibility);
363 this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
365 myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges) && (!myIsSelected || !myIsPreselected));
366 myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe) && !myIsSelected);
368 mySharedEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
369 myOneFaceEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
370 myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
372 myVertexActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);// must be added new mode points
378 ::SetNbIsos(const int theNb[2])
380 myWireframeFaceSource->SetNbIso(theNb);
385 ::GetNbIsos(int &theNbU,int &theNbV)
387 myWireframeFaceSource->GetNbIso(theNbU, theNbV);
392 ::SetVectorMode(bool theMode)
394 myVectorMode = theMode;
395 myIsolatedEdgeSource->SetVectorMode(theMode);
396 myOneFaceEdgeSource->SetVectorMode(theMode);
397 mySharedEdgeSource->SetVectorMode(theMode);
410 SetDeflection(float theDeflection)
412 if( myDeflection == theDeflection )
415 myDeflection = theDeflection;
417 GEOM::MeshShape(myShape,myDeflection);
422 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
428 myVertexSource->Clear();
429 myIsolatedEdgeSource->Clear();
430 myOneFaceEdgeSource->Clear();
431 mySharedEdgeSource->Clear();
432 myWireframeFaceSource->Clear();
433 myShadingFaceSource->Clear();
435 TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
436 for (; aVertexExp.More(); aVertexExp.Next())
438 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
439 myVertexSource->AddVertex(aVertex);
442 SetDeflection(theDeflection);
444 // look if edges are free or shared
445 TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
446 TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
448 GEOM::SetShape(theShape,anEdgeMap,theIsVector,
449 myIsolatedEdgeSource.Get(),
450 myOneFaceEdgeSource.Get(),
451 mySharedEdgeSource.Get(),
452 myWireframeFaceSource.Get(),
453 myShadingFaceSource.Get());
455 myIsolatedEdgeSource->IsEmpty() &&
456 myOneFaceEdgeSource->IsEmpty() &&
457 mySharedEdgeSource->IsEmpty() &&
458 myWireframeFaceSource->IsEmpty() &&
459 myShadingFaceSource->IsEmpty();
462 if((bool)myShape.Infinite() || isOnlyVertex ){
463 myVertexActor->GetDeviceActor()->SetInfinitive(true);
464 myHighlightActor->GetDeviceActor()->SetInfinitive(true);
469 void GEOM_Actor::setDeflection(double adef) {
471 MESSAGE ( "GEOM_Actor::setDeflection" );
473 SetDeflection((float)adef);
477 // warning! must be checked!
478 // SetHighlightProperty
479 // SetWireframeProperty
480 // SetShadingProperty
482 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
485 MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
487 this->myHighlightActor->GetProperty()->DeepCopy(Prop);
491 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
494 MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
497 myWireframeFaceActor->SetProperty(Prop);
500 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
503 MESSAGE ( "GEOM_Actor::SetShadingProperty" );
505 myShadingFaceProp->DeepCopy(Prop);
509 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
512 MESSAGE ( "GEOM_Actor::Render" );
518 /* render the property */
519 if (!this->Property) {
520 // force creation of a property
522 this->Property->SetInterpolation(1);
523 this->Property->SetRepresentationToSurface();
524 this->Property->SetAmbient(0.3);
525 this->Property->SetAmbientColor(0.88,0.86,0.2);
526 this->Property->SetDiffuseColor(0.99,0.7,0.21);
527 this->Property->SetSpecularColor(0.99,0.98,0.83);
530 switch(myDisplayMode){
531 case eWireframe://wireframe
532 myPreHighlightProp->SetRepresentationToWireframe();
533 myHighlightProp->SetRepresentationToWireframe();
535 case eShading://shading
536 case eShadingWithEdges://shading with edges
537 myPreHighlightProp->SetRepresentationToSurface();
538 myHighlightProp->SetRepresentationToSurface();
544 this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
545 myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
546 myShadingFaceActor->SetBackfaceProperty(myPreHighlightProp.GetPointer());
548 this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
549 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
550 myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
554 this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
555 myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
556 myShadingFaceActor->SetBackfaceProperty(myHighlightProp.GetPointer());
559 this->Property->Render(this, ren);
560 if (this->BackfaceProperty) {
561 this->BackfaceProperty->BackfaceRender(this, ren);
562 this->Device->SetBackfaceProperty(this->BackfaceProperty);
564 this->Device->SetProperty(this->Property);
565 /* if(myShape.ShapeType() == TopAbs_VERTEX) {
567 //The parameter determine size of vertex actor relate to diagonal of RendererWindow
568 static vtkFloatingPointType delta = 0.01;
569 vtkFloatingPointType X1 = -1, Y1 = -1, Z1 = 0;
570 ren->ViewToWorld(X1,Y1,Z1);
571 vtkFloatingPointType X2 = +1, Y2 = +1, Z2 = 0;
572 ren->ViewToWorld(X2,Y2,Z2);
573 Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
574 this->SetScale(Z2*delta);
576 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
577 this->GetMatrix(ren->GetActiveCamera(), aMatrix);
578 this->Device->SetUserMatrix(aMatrix);
579 this->Device->Render(ren,theMapper);
582 this->Device->Render(ren, theMapper);
585 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
588 MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
594 void GEOM_Actor::ShallowCopy(vtkProp *prop)
597 MESSAGE ( "GEOM_Actor::ShallowCopy" );
599 GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
602 this->SetShape(f->getTopo(),f->GetDeflection());
606 this->SALOME_Actor::ShallowCopy(prop);
609 const TopoDS_Shape& GEOM_Actor::getTopo() {
611 MESSAGE ( "GEOM_Actor::getTopo" );
616 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
617 int imode, bool isVector)
620 MESSAGE ( "GEOM_Actor::setInputShape" );
624 double GEOM_Actor::getDeflection()
627 MESSAGE ( "GEOM_Actor::getDeflection" );
629 return (double) GetDeflection();
633 double GEOM_Actor::isVector()
636 MESSAGE ( "GEOM_Actor::isVector" );
641 void GEOM_Actor::SubShapeOn()
644 MESSAGE ( "GEOM_Actor::SubShapeOn" );
648 void GEOM_Actor::SubShapeOff()
651 MESSAGE ( "GEOM_Actor::SubShapeOff" );
655 void GEOM_Actor::highlight(bool highlight)
658 MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
660 SALOME_Actor::highlight(highlight);
663 void GEOM_Actor::SetOpacity(vtkFloatingPointType opa)
666 myShadingFaceProp->SetOpacity(opa);
667 myShadingBackFaceProp->SetOpacity(opa);
668 myHighlightProp->SetOpacity(opa);
669 myPreHighlightProp->SetOpacity(opa);
670 myVertexActor->GetProperty()->SetOpacity(opa);
673 vtkFloatingPointType GEOM_Actor::GetOpacity()
676 return myShadingFaceProp->GetOpacity();
679 void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
682 myShadingFaceProp->SetColor(r,g,b); // shading color (Shading)
683 myShadingBackFaceProp->SetColor(r,g,b); // back face shading color (Shading)
684 myVertexActor->GetProperty()->SetColor(r,g,b); // vertex actor (Shading/Wireframe)
685 if ( myDisplayMode != (int)eShadingWithEdges ) {
686 myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b); // standalone edge color (Wireframe)
687 myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b); // standalone face edge color (Wireframe)
688 mySharedEdgeActor->GetProperty()->SetColor(r,g,b); // share edge color (Wireframe)
692 void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
695 vtkFloatingPointType aRGB[3];
696 myShadingFaceProp->GetColor(aRGB);
702 void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
704 int aSize = theProps.size();
706 if ( aSize < 1 || aSize > 2)
709 // theProps[0] -- front material properties
710 // theProps[1] -- back material properties (if exist)
711 // If there are no back material properties,
712 // we get front material properties as back material
716 // Set reflection coefficients
717 aCoefnt = theProps[0]->GetAmbient();
718 myShadingFaceProp->SetAmbient(aCoefnt);
719 myVertexActor->GetProperty()->SetAmbient(aCoefnt);
721 aCoefnt = theProps[1]->GetAmbient();
722 myShadingBackFaceProp->SetAmbient(aCoefnt);
724 // Set diffuse coefficients
725 aCoefnt = theProps[0]->GetDiffuse();
726 myShadingFaceProp->SetDiffuse(aCoefnt);
727 myVertexActor->GetProperty()->SetDiffuse(aCoefnt);
729 aCoefnt = theProps[1]->GetDiffuse();
730 myShadingBackFaceProp->SetDiffuse(aCoefnt);
732 // Set specular coefficients
733 aCoefnt = theProps[0]->GetSpecular();
734 myShadingFaceProp->SetSpecular(aCoefnt);
735 myVertexActor->GetProperty()->SetSpecular(aCoefnt);
737 aCoefnt = theProps[1]->GetSpecular();
738 myShadingBackFaceProp->SetSpecular(aCoefnt);
743 // Set reflection colors
744 aColor = theProps[0]->GetAmbientColor();
745 myShadingFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
746 myVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
748 aColor = theProps[1]->GetAmbientColor();
749 myShadingBackFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
751 // Set diffuse colors
752 aColor = theProps[0]->GetDiffuseColor();
753 myShadingFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
754 myVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
756 aColor = theProps[1]->GetDiffuseColor();
757 myShadingBackFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
759 // Set specular colors
760 aColor = theProps[0]->GetSpecularColor();
761 myShadingFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
762 myVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
764 aColor = theProps[1]->GetSpecularColor();
765 myShadingBackFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
768 aCoefnt = theProps[0]->GetSpecularPower();
769 myShadingFaceProp->SetSpecularPower(aCoefnt);
770 myVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
772 aCoefnt = theProps[1]->GetSpecularPower();
773 myShadingBackFaceProp->SetSpecularPower(aCoefnt);
775 // Set back face material property
776 myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
779 vtkProperty* GEOM_Actor::GetFrontMaterial()
781 return myShadingFaceProp;
784 vtkProperty* GEOM_Actor::GetBackMaterial()
786 return myShadingBackFaceProp;
789 bool GEOM_Actor::IsInfinitive()
791 return ((bool)myShape.Infinite() || isOnlyVertex);
795 To map current selection to VTK representation
799 ::Highlight(bool theIsHighlight)
801 myIsSelected = theIsHighlight;
803 MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
806 if ( myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges ) {
807 if ( theIsHighlight )
810 // Reset number of iso lines to 0
814 SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
815 SetVisibility(GetVisibility());
819 To process prehighlight (called from SVTK_InteractorStyle)
823 ::PreHighlight(vtkInteractorStyle *theInteractorStyle,
824 SVTK_SelectionEvent* theSelectionEvent,
828 MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
831 if ( !GetPickable() )
834 if ( myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges ) {
835 if ( theIsHighlight )
838 // Reset number of iso lines to 0
842 myPreHighlightActor->SetVisibility( false );
843 bool anIsPreselected = myIsPreselected;
845 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
846 bool anIsChanged = (mySelectionMode != aSelectionMode);
848 if( !theIsHighlight ) {
849 SetPreSelected( false );
851 switch(aSelectionMode){
852 case ActorSelection :
854 // cout << "=============== " << myIO->getEntry() << endl;
855 // int nbio = mySelector->IObjectCount();
856 // cout << " nbio = " << nbio << endl;
858 if( !mySelector->IsSelected( myIO ) ) {
859 // printf ("!!!!!!!!!!!!!!!!\n");
860 SetPreSelected( true );
868 mySelectionMode = aSelectionMode;
869 anIsChanged |= (anIsPreselected != myIsPreselected);
871 SetVisibility(GetVisibility());
876 To process highlight (called from SVTK_InteractorStyle)
880 ::Highlight(vtkInteractorStyle *theInteractorStyle,
881 SVTK_SelectionEvent* theSelectionEvent,
884 // define the selection of object
886 MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
888 bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
889 SetSelected(theIsHighlight);
891 SetPreSelected(false);
897 // Copy the follower's composite 4x4 matrix into the matrix provided.
898 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
901 double Rx[3], Ry[3], Rz[3], p1[3];
902 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
906 this->GetOrientation();
907 this->Transform->Push();
908 this->Transform->PostMultiply();
909 this->Transform->Identity();
911 // apply user defined matrix last if there is one
912 if (this->UserMatrix)
914 this->Transform->Concatenate(this->UserMatrix);
917 this->Transform->Translate(-this->Origin[0],
921 this->Transform->Scale(this->Scale[0],
926 this->Transform->RotateY(this->Orientation[1]);
927 this->Transform->RotateX(this->Orientation[0]);
928 this->Transform->RotateZ(this->Orientation[2]);
934 pos = theCam->GetPosition();
935 vup = theCam->GetViewUp();
937 if (theCam->GetParallelProjection())
939 theCam->GetDirectionOfProjection(Rz);
944 (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
945 (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
946 (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
947 for (i = 0; i < 3; i++)
949 Rz[i] = (pos[i] - this->Position[i])/distance;
953 vtkMath::Cross(vup,Rz,Rx);
954 vtkMath::Normalize(Rx);
955 vtkMath::Cross(Rz,Rx,Ry);
957 matrix->Element[0][0] = Rx[0];
958 matrix->Element[1][0] = Rx[1];
959 matrix->Element[2][0] = Rx[2];
960 matrix->Element[0][1] = Ry[0];
961 matrix->Element[1][1] = Ry[1];
962 matrix->Element[2][1] = Ry[2];
963 matrix->Element[0][2] = Rz[0];
964 matrix->Element[1][2] = Rz[1];
965 matrix->Element[2][2] = Rz[2];
967 this->Transform->Concatenate(matrix);
970 // translate to projection reference point PRP
971 // this is the camera's position blasted through
972 // the current matrix
973 p1[0] = this->Origin[0] + this->Position[0];
974 p1[1] = this->Origin[1] + this->Position[1];
975 p1[2] = this->Origin[2] + this->Position[2];
977 this->Transform->Translate(p1[0],p1[1],p1[2]);
978 this->Transform->GetMatrix(result);
981 this->Transform->Pop();
984 void GEOM_Actor::SetEdgesInShadingColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
986 myEdgesInShadingColor[0] = r;
987 myEdgesInShadingColor[1] = g;
988 myEdgesInShadingColor[2] = b;
991 void GEOM_Actor::StoreIsoNumbers()
993 myWireframeFaceSource->GetNbIso(myNbIsos[0], myNbIsos[1]);
996 void GEOM_Actor::RestoreIsoNumbers()
998 if ( myNbIsos[0] > 0 || myNbIsos[1] > 0 )
999 // Restore number of U and (or) V iso lines
1000 myWireframeFaceSource->SetNbIso(myNbIsos);
1003 void GEOM_Actor::ResetIsoNumbers()
1005 int aNb[2] = {0, 0};
1006 myWireframeFaceSource->SetNbIso(aNb);
1009 void GEOM_Actor::StoreBoundaryColors()
1011 mySharedEdgeActor->GetProperty()->GetColor(myEdgesInWireframeColor);
1014 void GEOM_Actor::RestoreBoundaryColors()
1016 myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
1017 myEdgesInWireframeColor[1],
1018 myEdgesInWireframeColor[2]);
1019 myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
1020 myEdgesInWireframeColor[1],
1021 myEdgesInWireframeColor[2]);
1022 mySharedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
1023 myEdgesInWireframeColor[1],
1024 myEdgesInWireframeColor[2]);