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);
501 vtkProperty* GEOM_Actor::GetWireframeProperty()
503 return myWireframeFaceActor->GetProperty();
506 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
509 MESSAGE ( "GEOM_Actor::SetShadingProperty" );
511 myShadingFaceProp->DeepCopy(Prop);
515 vtkProperty* GEOM_Actor::GetShadingProperty()
517 return myShadingFaceProp;
521 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
524 MESSAGE ( "GEOM_Actor::Render" );
530 /* render the property */
531 if (!this->Property) {
532 // force creation of a property
534 this->Property->SetInterpolation(1);
535 this->Property->SetRepresentationToSurface();
536 this->Property->SetAmbient(0.3);
537 this->Property->SetAmbientColor(0.88,0.86,0.2);
538 this->Property->SetDiffuseColor(0.99,0.7,0.21);
539 this->Property->SetSpecularColor(0.99,0.98,0.83);
542 switch(myDisplayMode){
543 case eWireframe://wireframe
544 myPreHighlightProp->SetRepresentationToWireframe();
545 myHighlightProp->SetRepresentationToWireframe();
547 case eShading://shading
548 case eShadingWithEdges://shading with edges
549 myPreHighlightProp->SetRepresentationToSurface();
550 myHighlightProp->SetRepresentationToSurface();
556 this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
557 myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
558 myShadingFaceActor->SetBackfaceProperty(myPreHighlightProp.GetPointer());
560 this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
561 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
562 myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
566 this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
567 myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
568 myShadingFaceActor->SetBackfaceProperty(myHighlightProp.GetPointer());
571 this->Property->Render(this, ren);
572 if (this->BackfaceProperty) {
573 this->BackfaceProperty->BackfaceRender(this, ren);
574 this->Device->SetBackfaceProperty(this->BackfaceProperty);
576 this->Device->SetProperty(this->Property);
577 /* if(myShape.ShapeType() == TopAbs_VERTEX) {
579 //The parameter determine size of vertex actor relate to diagonal of RendererWindow
580 static vtkFloatingPointType delta = 0.01;
581 vtkFloatingPointType X1 = -1, Y1 = -1, Z1 = 0;
582 ren->ViewToWorld(X1,Y1,Z1);
583 vtkFloatingPointType X2 = +1, Y2 = +1, Z2 = 0;
584 ren->ViewToWorld(X2,Y2,Z2);
585 Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
586 this->SetScale(Z2*delta);
588 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
589 this->GetMatrix(ren->GetActiveCamera(), aMatrix);
590 this->Device->SetUserMatrix(aMatrix);
591 this->Device->Render(ren,theMapper);
594 this->Device->Render(ren, theMapper);
597 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
600 MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
606 void GEOM_Actor::ShallowCopy(vtkProp *prop)
609 MESSAGE ( "GEOM_Actor::ShallowCopy" );
611 GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
614 this->SetShape(f->getTopo(),f->GetDeflection());
618 this->SALOME_Actor::ShallowCopy(prop);
621 const TopoDS_Shape& GEOM_Actor::getTopo() {
623 MESSAGE ( "GEOM_Actor::getTopo" );
628 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
629 int imode, bool isVector)
632 MESSAGE ( "GEOM_Actor::setInputShape" );
636 double GEOM_Actor::getDeflection()
639 MESSAGE ( "GEOM_Actor::getDeflection" );
641 return (double) GetDeflection();
645 double GEOM_Actor::isVector()
648 MESSAGE ( "GEOM_Actor::isVector" );
653 void GEOM_Actor::SubShapeOn()
656 MESSAGE ( "GEOM_Actor::SubShapeOn" );
660 void GEOM_Actor::SubShapeOff()
663 MESSAGE ( "GEOM_Actor::SubShapeOff" );
667 void GEOM_Actor::highlight(bool highlight)
670 MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
672 SALOME_Actor::highlight(highlight);
675 void GEOM_Actor::SetOpacity(vtkFloatingPointType opa)
678 myShadingFaceProp->SetOpacity(opa);
679 myShadingBackFaceProp->SetOpacity(opa);
680 myHighlightProp->SetOpacity(opa);
681 myPreHighlightProp->SetOpacity(opa);
682 myVertexActor->GetProperty()->SetOpacity(opa);
685 vtkFloatingPointType GEOM_Actor::GetOpacity()
688 return myShadingFaceProp->GetOpacity();
691 void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
694 myShadingFaceProp->SetColor(r,g,b); // shading color (Shading)
695 myShadingBackFaceProp->SetColor(r,g,b); // back face shading color (Shading)
696 myVertexActor->GetProperty()->SetColor(r,g,b); // vertex actor (Shading/Wireframe)
697 if ( myDisplayMode != (int)eShadingWithEdges ) {
698 myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b); // standalone edge color (Wireframe)
699 myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b); // standalone face edge color (Wireframe)
700 mySharedEdgeActor->GetProperty()->SetColor(r,g,b); // share edge color (Wireframe)
703 StoreBoundaryColors();
706 void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
709 vtkFloatingPointType aRGB[3];
710 myShadingFaceProp->GetColor(aRGB);
716 void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
718 int aSize = theProps.size();
720 if ( aSize < 1 || aSize > 2)
723 // theProps[0] -- front material properties
724 // theProps[1] -- back material properties (if exist)
725 // If there are no back material properties,
726 // we get front material properties as back material
730 // Set reflection coefficients
731 aCoefnt = theProps[0]->GetAmbient();
732 myShadingFaceProp->SetAmbient(aCoefnt);
733 myVertexActor->GetProperty()->SetAmbient(aCoefnt);
735 aCoefnt = theProps[1]->GetAmbient();
736 myShadingBackFaceProp->SetAmbient(aCoefnt);
738 // Set diffuse coefficients
739 aCoefnt = theProps[0]->GetDiffuse();
740 myShadingFaceProp->SetDiffuse(aCoefnt);
741 myVertexActor->GetProperty()->SetDiffuse(aCoefnt);
743 aCoefnt = theProps[1]->GetDiffuse();
744 myShadingBackFaceProp->SetDiffuse(aCoefnt);
746 // Set specular coefficients
747 aCoefnt = theProps[0]->GetSpecular();
748 myShadingFaceProp->SetSpecular(aCoefnt);
749 myVertexActor->GetProperty()->SetSpecular(aCoefnt);
751 aCoefnt = theProps[1]->GetSpecular();
752 myShadingBackFaceProp->SetSpecular(aCoefnt);
757 // Set reflection colors
758 aColor = theProps[0]->GetAmbientColor();
759 myShadingFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
760 myVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
762 aColor = theProps[1]->GetAmbientColor();
763 myShadingBackFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
765 // Set diffuse colors
766 aColor = theProps[0]->GetDiffuseColor();
767 myShadingFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
768 myVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
770 aColor = theProps[1]->GetDiffuseColor();
771 myShadingBackFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
773 // Set specular colors
774 aColor = theProps[0]->GetSpecularColor();
775 myShadingFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
776 myVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
778 aColor = theProps[1]->GetSpecularColor();
779 myShadingBackFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
782 aCoefnt = theProps[0]->GetSpecularPower();
783 myShadingFaceProp->SetSpecularPower(aCoefnt);
784 myVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
786 aCoefnt = theProps[1]->GetSpecularPower();
787 myShadingBackFaceProp->SetSpecularPower(aCoefnt);
789 // Set back face material property
790 myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
793 vtkProperty* GEOM_Actor::GetFrontMaterial()
795 return myShadingFaceProp;
798 vtkProperty* GEOM_Actor::GetBackMaterial()
800 return myShadingBackFaceProp;
803 bool GEOM_Actor::IsInfinitive()
805 return ((bool)myShape.Infinite() || isOnlyVertex);
809 To map current selection to VTK representation
813 ::Highlight(bool theIsHighlight)
815 myIsSelected = theIsHighlight;
817 MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
820 if ( myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges ) {
821 if ( theIsHighlight )
824 // Reset number of iso lines to 0
828 SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
829 SetVisibility(GetVisibility());
833 To process prehighlight (called from SVTK_InteractorStyle)
837 ::PreHighlight(vtkInteractorStyle *theInteractorStyle,
838 SVTK_SelectionEvent* theSelectionEvent,
842 MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
845 if ( !GetPickable() )
848 if ( myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges ) {
849 if ( theIsHighlight )
852 // Reset number of iso lines to 0
856 myPreHighlightActor->SetVisibility( false );
857 bool anIsPreselected = myIsPreselected;
859 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
860 bool anIsChanged = (mySelectionMode != aSelectionMode);
862 if( !theIsHighlight ) {
863 SetPreSelected( false );
865 switch(aSelectionMode){
866 case ActorSelection :
868 // cout << "=============== " << myIO->getEntry() << endl;
869 // int nbio = mySelector->IObjectCount();
870 // cout << " nbio = " << nbio << endl;
872 if( !mySelector->IsSelected( myIO ) ) {
873 // printf ("!!!!!!!!!!!!!!!!\n");
874 SetPreSelected( true );
882 mySelectionMode = aSelectionMode;
883 anIsChanged |= (anIsPreselected != myIsPreselected);
885 SetVisibility(GetVisibility());
890 To process highlight (called from SVTK_InteractorStyle)
894 ::Highlight(vtkInteractorStyle *theInteractorStyle,
895 SVTK_SelectionEvent* theSelectionEvent,
898 // define the selection of object
900 MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
902 bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
903 SetSelected(theIsHighlight);
905 SetPreSelected(false);
911 // Copy the follower's composite 4x4 matrix into the matrix provided.
912 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
915 double Rx[3], Ry[3], Rz[3], p1[3];
916 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
920 this->GetOrientation();
921 this->Transform->Push();
922 this->Transform->PostMultiply();
923 this->Transform->Identity();
925 // apply user defined matrix last if there is one
926 if (this->UserMatrix)
928 this->Transform->Concatenate(this->UserMatrix);
931 this->Transform->Translate(-this->Origin[0],
935 this->Transform->Scale(this->Scale[0],
940 this->Transform->RotateY(this->Orientation[1]);
941 this->Transform->RotateX(this->Orientation[0]);
942 this->Transform->RotateZ(this->Orientation[2]);
948 pos = theCam->GetPosition();
949 vup = theCam->GetViewUp();
951 if (theCam->GetParallelProjection())
953 theCam->GetDirectionOfProjection(Rz);
958 (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
959 (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
960 (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
961 for (i = 0; i < 3; i++)
963 Rz[i] = (pos[i] - this->Position[i])/distance;
967 vtkMath::Cross(vup,Rz,Rx);
968 vtkMath::Normalize(Rx);
969 vtkMath::Cross(Rz,Rx,Ry);
971 matrix->Element[0][0] = Rx[0];
972 matrix->Element[1][0] = Rx[1];
973 matrix->Element[2][0] = Rx[2];
974 matrix->Element[0][1] = Ry[0];
975 matrix->Element[1][1] = Ry[1];
976 matrix->Element[2][1] = Ry[2];
977 matrix->Element[0][2] = Rz[0];
978 matrix->Element[1][2] = Rz[1];
979 matrix->Element[2][2] = Rz[2];
981 this->Transform->Concatenate(matrix);
984 // translate to projection reference point PRP
985 // this is the camera's position blasted through
986 // the current matrix
987 p1[0] = this->Origin[0] + this->Position[0];
988 p1[1] = this->Origin[1] + this->Position[1];
989 p1[2] = this->Origin[2] + this->Position[2];
991 this->Transform->Translate(p1[0],p1[1],p1[2]);
992 this->Transform->GetMatrix(result);
995 this->Transform->Pop();
998 void GEOM_Actor::SetEdgesInShadingColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
1000 myEdgesInShadingColor[0] = r;
1001 myEdgesInShadingColor[1] = g;
1002 myEdgesInShadingColor[2] = b;
1005 void GEOM_Actor::StoreIsoNumbers()
1007 myWireframeFaceSource->GetNbIso(myNbIsos[0], myNbIsos[1]);
1010 void GEOM_Actor::SetIsosWidth(const int width) {
1011 myWireframeFaceActor->GetProperty()->SetLineWidth(width);
1014 int GEOM_Actor::GetIsosWidth() const {
1015 return myWireframeFaceActor->GetProperty()->GetLineWidth();
1018 void GEOM_Actor::SetWidth(const int width) {
1019 myIsolatedEdgeActor->GetProperty()->SetLineWidth(width);
1020 myOneFaceEdgeActor->GetProperty()->SetLineWidth(width);
1021 mySharedEdgeActor->GetProperty()->SetLineWidth(width);
1022 myHighlightProp->SetLineWidth(width);
1023 myPreHighlightProp->SetLineWidth(width+1);
1027 int GEOM_Actor::GetWidth() const {
1028 return myIsolatedEdgeActor->GetProperty()->GetLineWidth();
1031 void GEOM_Actor::RestoreIsoNumbers()
1033 if ( myNbIsos[0] > 0 || myNbIsos[1] > 0 )
1034 // Restore number of U and (or) V iso lines
1035 myWireframeFaceSource->SetNbIso(myNbIsos);
1038 void GEOM_Actor::ResetIsoNumbers()
1040 int aNb[2] = {0, 0};
1041 myWireframeFaceSource->SetNbIso(aNb);
1044 void GEOM_Actor::StoreBoundaryColors()
1046 myShadingFaceProp->GetColor(myEdgesInWireframeColor);
1050 void GEOM_Actor::RestoreBoundaryColors()
1052 myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
1053 myEdgesInWireframeColor[1],
1054 myEdgesInWireframeColor[2]);
1055 myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
1056 myEdgesInWireframeColor[1],
1057 myEdgesInWireframeColor[2]);
1058 mySharedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
1059 myEdgesInWireframeColor[1],
1060 myEdgesInWireframeColor[2]);