Back to index

salome-geom  6.5.0
GEOM_Actor.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  GEOM OBJECT : interactive object for Geometry entities visualization
00024 //  File   : GEOM_Actor.cxx
00025 //  Author : Christophe ATTANASIO
00026 //  Module : GEOM
00027 //  $Header: /home/server/cvs/GEOM/GEOM_SRC/src/OBJECT/GEOM_Actor.cxx,v 1.13.2.3.6.13.2.2 2012-04-13 11:02:12 ana Exp $
00028 //
00033 #include "GEOM_Actor.h" 
00034  
00035 #include "GEOM_DeviceActor.h" 
00036 #include "GEOM_VertexSource.h" 
00037 #include "GEOM_EdgeSource.h" 
00038 #include "GEOM_WireframeFace.h" 
00039 #include "GEOM_ShadingFace.h"
00040 #include "GEOM_PainterPolyDataMapper.h"
00041 #include "SVTK_Actor.h"
00042 
00043 #include <OCC2VTK_Tools.h>
00044 
00045 #include <vtkObjectFactory.h> 
00046 #include <vtkRenderer.h> 
00047 #include <vtkProperty.h> 
00048 #include <vtkPointPicker.h>
00049 #include <vtkCellPicker.h>
00050  
00051 #include <TopAbs_ShapeEnum.hxx>
00052 #include <TopExp_Explorer.hxx>
00053 #include <TopoDS.hxx>
00054 #include <BRep_Tool.hxx>
00055 #include <TopExp.hxx>
00056  
00057 #include <vtkPolyDataWriter.h> 
00058  
00059 #include <vtkAppendPolyData.h>  
00060 #include <vtkPolyDataMapper.h>  
00061 #include <vtkPolyData.h>  
00062 #include <vtkTransform.h>
00063 #include <vtkMatrix4x4.h>
00064 #include <vtkMath.h>
00065 #include <vtkCamera.h>
00066 
00067 #include "utilities.h"
00068 
00069 #include "SALOME_InteractiveObject.hxx"
00070 
00071 //vtkStandardNewMacro(GEOM_Actor);
00072 
00073 #ifndef MYDEBUG
00074 //#define MYDEBUG
00075 #endif
00076 
00077 GEOM_Actor::GEOM_Actor(): 
00078   isOnlyVertex(false),
00079 
00080   myDeflection(-1),
00081   myIsForced(false),
00082 
00083   //  myDisplayMode(eWireframe), 
00084   myIsSelected(false), 
00085   myVectorMode(false),
00086 
00087   myVertexActor(GEOM_DeviceActor::New(),true), 
00088   myVertexSource(GEOM_VertexSource::New(),true), 
00089  
00090   myIsolatedEdgeActor(GEOM_DeviceActor::New(),true), 
00091   myIsolatedEdgeSource(GEOM_EdgeSource::New(),true), 
00092  
00093   myOneFaceEdgeActor(GEOM_DeviceActor::New(),true), 
00094   myOneFaceEdgeSource(GEOM_EdgeSource::New(),true), 
00095  
00096   mySharedEdgeActor(GEOM_DeviceActor::New(),true), 
00097   mySharedEdgeSource(GEOM_EdgeSource::New(),true), 
00098  
00099   myWireframeFaceActor(GEOM_DeviceActor::New(),true), 
00100   myWireframeFaceSource(GEOM_WireframeFace::New(),true), 
00101  
00102   myShadingFaceActor(GEOM_DeviceActor::New(),true), 
00103   myShadingFaceSource(GEOM_ShadingFace::New(),true), 
00104  
00105   myHighlightActor(GEOM_DeviceActor::New(),true), 
00106   myAppendFilter(vtkAppendPolyData::New(),true), 
00107   // Use mapper as an instance of GEOM_PainterPolyDataMapper class
00108   // to prevent drawing of mappers' content (due to an empty definition
00109   // of GEOM_PainterPolyDataMapper::RenderPiece(...)).
00110   // !!! Presentation of GEOM_Actor is drawing only with help of actors
00111   // defined in this class !!!
00112   myPolyDataMapper(GEOM_PainterPolyDataMapper::New(),true),
00113 
00114   myHighlightProp(vtkProperty::New()),
00115   myPreHighlightProp(vtkProperty::New()),
00116   myShadingFaceProp(vtkProperty::New())
00117 { 
00118 #ifdef MYDEBUG
00119   MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
00120 #endif
00121 
00122   myPolyDataMapper->SetInput(myAppendFilter->GetOutput()); 
00123   vtkProperty* aProperty; 
00124 
00125   myHighlightProp->SetAmbient(0.5);
00126   myHighlightProp->SetDiffuse(0.3);
00127   myHighlightProp->SetSpecular(0.2);
00128   myHighlightProp->SetRepresentationToSurface();
00129   myHighlightProp->SetAmbientColor(1, 1, 1);
00130   myHighlightProp->SetDiffuseColor(1, 1, 1);
00131   myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
00132   myHighlightProp->SetPointSize(SALOME_POINT_SIZE);
00133   myHighlightActor->SetProperty(myHighlightProp.GetPointer());
00134 
00135   this->myHighlightActor->SetInput(myAppendFilter->GetOutput(),false);
00136 
00137   myPreHighlightProp->SetColor(0,1,1);
00138   myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
00139   myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
00140   myPreHighlightProp->SetRepresentationToWireframe();
00141 
00142   myAppendFilter->AddInput(myVertexSource->GetOutput()); 
00143   myVertexActor->SetInput(myVertexSource->GetOutput(),false); 
00144   aProperty = myVertexActor->GetProperty(); 
00145   aProperty->SetRepresentation(VTK_POINTS); 
00146   aProperty->SetPointSize(3); 
00147   aProperty->SetColor(1, 1, 0);
00148  
00149   myAppendFilter->AddInput(myIsolatedEdgeSource->GetOutput());
00150   myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false); 
00151   aProperty = myIsolatedEdgeActor->GetProperty(); 
00152   aProperty->SetRepresentation(VTK_WIREFRAME); 
00153   aProperty->SetColor(1, 0, 0);
00154  
00155   myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput());
00156   myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false); 
00157   aProperty = myOneFaceEdgeActor->GetProperty(); 
00158   aProperty->SetRepresentation(VTK_WIREFRAME); 
00159   aProperty->SetColor(0, 1, 0);
00160  
00161   myAppendFilter->AddInput(mySharedEdgeSource->GetOutput()); 
00162   mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false); 
00163   aProperty = mySharedEdgeActor->GetProperty(); 
00164   aProperty->SetRepresentation(VTK_WIREFRAME); 
00165   aProperty->SetColor(1, 1, 0);
00166  
00167   myAppendFilter->AddInput(myWireframeFaceSource->GetOutput()); 
00168   myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false); 
00169   aProperty = myWireframeFaceActor->GetProperty(); 
00170   aProperty->SetRepresentation(VTK_WIREFRAME); 
00171   aProperty->SetColor(0.5, 0.5, 0.5);
00172 
00173   myShadingFaceActor->SetInput(myShadingFaceSource->GetOutput(),true); 
00174 
00175   myShadingFaceProp->SetRepresentation(VTKViewer::Representation::Surface); 
00176   myShadingFaceProp->SetInterpolationToGouraud(); 
00177   myShadingFaceProp->SetAmbient(1.0);
00178   myShadingFaceProp->SetDiffuse(1.0);
00179   myShadingFaceProp->SetSpecular(0.4);
00180   myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
00181   myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
00182   myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
00183 
00184   myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
00185 
00186   StoreBoundaryColors();
00187 
00188   myNbIsos[0] = -1;
00189   myNbIsos[1] = -1;
00190 
00191   // Toggle display mode 
00192   setDisplayMode(0); // WIRE FRAME
00193   SetVectorMode(0);  //
00194 } 
00195  
00196  
00197 GEOM_Actor::~GEOM_Actor() 
00198 { 
00199 #ifdef MYDEBUG
00200   MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
00201 #endif
00202   myHighlightProp->Delete();
00203   myPreHighlightProp->Delete();
00204   myShadingFaceProp->Delete();
00205 } 
00206  
00207 GEOM_Actor*  
00208 GEOM_Actor:: 
00209 New() 
00210 { 
00211   GEOM_Actor* anObject = new GEOM_Actor(); 
00212   anObject->SetMapper(anObject->myPolyDataMapper.Get()); 
00213   return anObject; 
00214 } 
00215  
00216  
00217 void Write(vtkPolyData* theDataSet, const char* theFileName){ 
00218   vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New(); 
00219   MESSAGE ("Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells()); 
00220   aWriter->SetInput(theDataSet); 
00221   aWriter->SetFileName(theFileName); 
00222   //aWriter->Write(); 
00223   aWriter->Delete(); 
00224 } 
00225  
00226 void 
00227 GEOM_Actor:: 
00228 SetModified() 
00229 { 
00230   this->myVertexSource->Modified(); 
00231   this->myIsolatedEdgeSource->Modified(); 
00232   this->myOneFaceEdgeSource->Modified(); 
00233   this->mySharedEdgeSource->Modified(); 
00234   this->myWireframeFaceSource->Modified(); 
00235   this->myShadingFaceSource->Modified(); 
00236 } 
00237 
00238 void  
00239 GEOM_Actor:: 
00240 SetMapper(vtkMapper* theMapper) 
00241 { 
00242   SALOME_Actor::SetMapper(theMapper); 
00243 } 
00244 
00245 void 
00246 GEOM_Actor:: 
00247 AddToRender(vtkRenderer* theRenderer)
00248 {
00249   //SALOME_Actor::AddToRender(theRenderer);
00250   
00251   theRenderer->AddActor(this); 
00252  
00253   this->myHighlightActor->AddToRender(theRenderer); 
00254   
00255 
00256   myShadingFaceActor->AddToRender(theRenderer); 
00257   myWireframeFaceActor->AddToRender(theRenderer); 
00258  
00259   mySharedEdgeActor->AddToRender(theRenderer); 
00260   myOneFaceEdgeActor->AddToRender(theRenderer); 
00261   myIsolatedEdgeActor->AddToRender(theRenderer); 
00262  
00263   myVertexActor->AddToRender(theRenderer); 
00264 }
00265  
00266 void 
00267 GEOM_Actor:: 
00268 RemoveFromRender(vtkRenderer* theRenderer)
00269 {
00270   //SALOME_Actor::RemoveFromRender(theRenderer);
00271 
00272   
00273   theRenderer->RemoveActor(this);
00274 
00275   myHighlightActor->RemoveFromRender(theRenderer); 
00276   myShadingFaceActor->RemoveFromRender(theRenderer); 
00277   myWireframeFaceActor->RemoveFromRender(theRenderer); 
00278  
00279   mySharedEdgeActor->RemoveFromRender(theRenderer); 
00280   myOneFaceEdgeActor->RemoveFromRender(theRenderer); 
00281   myIsolatedEdgeActor->RemoveFromRender(theRenderer); 
00282  
00283   myVertexActor->RemoveFromRender(theRenderer);
00284 
00285   
00286   SetSelected(false);
00287   SetVisibility(false);
00288 }
00289 
00290 void  
00291 GEOM_Actor:: 
00292 setDisplayMode(int theMode) 
00293 { 
00294 #ifdef MYDEBUG
00295   MESSAGE ( "GEOM_Actor::setDisplayMode = "<<theMode );
00296 #endif
00297   
00298   if ( theMode == (int)eWireframe ) {
00299     RestoreIsoNumbers();
00300     // Restore wireframe edges colors
00301     RestoreBoundaryColors();
00302   }
00303   else if ( theMode == (int)eShading || theMode == (int)eShadingWithEdges ) {
00304     // Temporary store number of iso lines in order to recover its later 
00305     // when display mode is achnged to 'Wirefame' or 'Shading'.
00306     // Iso lines are not displayed in 'Shading with edges' mode.
00307     StoreIsoNumbers();
00308 
00309     // Reset number of iso lines to 0
00310     ResetIsoNumbers();
00311 
00312     if ( theMode == (int)eShadingWithEdges ) {
00313       // Store wireframe edges colors
00314       StoreBoundaryColors();
00315 
00316       // Coloring edges
00317       myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
00318                                              myEdgesInShadingColor[1],
00319                                              myEdgesInShadingColor[2]);
00320       myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
00321                                             myEdgesInShadingColor[1],
00322                                             myEdgesInShadingColor[2]);
00323       mySharedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
00324                                            myEdgesInShadingColor[1],
00325                                            myEdgesInShadingColor[2]);
00326       //SetModified();
00327     } else {
00328       myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
00329                                              myEdgesInWireframeColor[1],
00330                                              myEdgesInWireframeColor[2]);
00331     }
00332   }
00333 
00334   VTKViewer_Actor::setDisplayMode(theMode);
00335   SetVisibility(GetVisibility()); 
00336 } 
00337 
00338 void  
00339 GEOM_Actor:: 
00340 SetSelected(bool theIsSelected) 
00341 { 
00342 #ifdef MYDEBUG
00343   MESSAGE ( "GEOM_Actor::SetSelected = "<<theIsSelected  );
00344 #endif
00345 
00346   myIsSelected = theIsSelected; 
00347   SetVisibility(GetVisibility()); 
00348 } 
00349 
00350 void  
00351 GEOM_Actor:: 
00352 SetVisibility(int theVisibility) 
00353 { 
00354 #ifdef MYDEBUG
00355   MESSAGE ( "GEOM_Actor::SetVisibility = "<<theVisibility <<"  myIsSelected="<< myIsSelected
00356             << " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected );
00357 #endif
00358 
00359   SALOME_Actor::SetVisibility(theVisibility);
00360 
00361   this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
00362   
00363   myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges) && (!myIsSelected || !myIsPreselected)); 
00364   myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe) && !myIsSelected);
00365 
00366   mySharedEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
00367   myOneFaceEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
00368   myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
00369 
00370   myVertexActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);// must be added new mode points
00371 }
00372  
00373 
00374 void
00375 GEOM_Actor
00376 ::SetNbIsos(const int theNb[2])
00377 {
00378   myWireframeFaceSource->SetNbIso(theNb);
00379 }
00380 
00381 void
00382 GEOM_Actor
00383 ::GetNbIsos(int &theNbU,int &theNbV)
00384 {
00385   myWireframeFaceSource->GetNbIso(theNbU, theNbV);
00386 }
00387 
00388 void
00389 GEOM_Actor
00390 ::SetVectorMode(bool theMode)
00391 {
00392   myVectorMode = theMode;
00393   myIsolatedEdgeSource->SetVectorMode(theMode);
00394   myOneFaceEdgeSource->SetVectorMode(theMode);
00395   mySharedEdgeSource->SetVectorMode(theMode);
00396   SetModified();
00397 }
00398 
00399 bool
00400 GEOM_Actor
00401 ::GetVectorMode()
00402 {
00403   return myVectorMode;
00404 }
00405 
00406 void  
00407 GEOM_Actor:: 
00408 SetDeflection(float theDeflection) 
00409 { 
00410   if( myDeflection == theDeflection ) 
00411     return;
00412     
00413   myDeflection = theDeflection; 
00414  
00415   GEOM::MeshShape(myShape,myDeflection);
00416   
00417   SetModified(); 
00418 }
00419 
00420 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
00421                            float theDeflection,
00422                         bool theIsVector)
00423 {
00424   myShape = theShape;
00425 
00426   myVertexSource->Clear();
00427   myIsolatedEdgeSource->Clear();
00428   myOneFaceEdgeSource->Clear();
00429   mySharedEdgeSource->Clear();
00430   myWireframeFaceSource->Clear();
00431   myShadingFaceSource->Clear();
00432 
00433   TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
00434   for (; aVertexExp.More(); aVertexExp.Next())
00435   {
00436      const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
00437      myVertexSource->AddVertex(aVertex);
00438   }
00439   
00440   SetDeflection(theDeflection);
00441 
00442   // look if edges are free or shared
00443   TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
00444   TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
00445   
00446   GEOM::SetShape(theShape,anEdgeMap,theIsVector,
00447                  myIsolatedEdgeSource.Get(),
00448                  myOneFaceEdgeSource.Get(),
00449                  mySharedEdgeSource.Get(),
00450                  myWireframeFaceSource.Get(),
00451                  myShadingFaceSource.Get());
00452   isOnlyVertex =  
00453     myIsolatedEdgeSource->IsEmpty() &&
00454     myOneFaceEdgeSource->IsEmpty() &&
00455     mySharedEdgeSource->IsEmpty() &&
00456     myWireframeFaceSource->IsEmpty() &&
00457     myShadingFaceSource->IsEmpty();
00458 
00459   
00460   if((bool)myShape.Infinite() || isOnlyVertex ){
00461     myVertexActor->GetDeviceActor()->SetInfinitive(true);
00462     myHighlightActor->GetDeviceActor()->SetInfinitive(true);
00463   }
00464 }
00465 
00466 // OLD METHODS
00467 void GEOM_Actor::setDeflection(double adef) {
00468 #ifdef MYDEBUG
00469   MESSAGE ( "GEOM_Actor::setDeflection" );
00470 #endif
00471   SetDeflection((float)adef);
00472 }
00473 
00474 
00475 // warning! must be checked!
00476 // SetHighlightProperty
00477 // SetWireframeProperty
00478 // SetShadingProperty
00479 
00480 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
00481 {
00482 #ifdef MYDEBUG
00483   MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
00484 #endif
00485   this->myHighlightActor->GetProperty()->DeepCopy(Prop);
00486   
00487 }
00488 
00489 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
00490 {
00491 #ifdef MYDEBUG
00492   MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
00493 #endif
00494   // must be filled
00495   myWireframeFaceActor->SetProperty(Prop);
00496 }
00497 
00498 
00499 vtkProperty* GEOM_Actor::GetWireframeProperty()
00500 {
00501   return myWireframeFaceActor->GetProperty();
00502 }
00503 
00504 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
00505 {
00506 #ifdef MYDEBUG
00507   MESSAGE ( "GEOM_Actor::SetShadingProperty" );
00508 #endif
00509   myShadingFaceProp->DeepCopy(Prop);
00510 }
00511 
00512 
00513 vtkProperty* GEOM_Actor::GetShadingProperty()
00514 {
00515   return myShadingFaceProp;
00516 }
00517 
00518 
00519 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
00520 {
00521 #ifdef MYDEBUG
00522   MESSAGE ( "GEOM_Actor::Render" );
00523 #endif
00524 
00525   if(!GetVisibility())
00526     return;
00527 
00528   /* render the property */
00529   if (!this->Property) {
00530     // force creation of a property
00531     this->GetProperty();
00532     this->Property->SetInterpolation(1);
00533     this->Property->SetRepresentationToSurface();
00534     this->Property->SetAmbient(0.3);
00535     this->Property->SetAmbientColor(0.88,0.86,0.2);
00536     this->Property->SetDiffuseColor(0.99,0.7,0.21);
00537     this->Property->SetSpecularColor(0.99,0.98,0.83);
00538   }
00539 
00540   switch(myDisplayMode){
00541   case eWireframe://wireframe
00542     myPreHighlightProp->SetRepresentationToWireframe();
00543     myHighlightProp->SetRepresentationToWireframe();
00544     break;
00545   case eShading://shading
00546   case eShadingWithEdges://shading with edges
00547     myPreHighlightProp->SetRepresentationToSurface();
00548     myHighlightProp->SetRepresentationToSurface();
00549     myShadingFaceProp->SetRepresentationToSurface();
00550     break;
00551   }
00552 
00553   if(!myIsSelected){
00554     if(myIsPreselected){
00555       this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
00556       myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
00557     } else {
00558       this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
00559       myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
00560     }
00561   }
00562   else{
00563     this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
00564     myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
00565   }
00566 
00567   this->Property->Render(this, ren);
00568   if (this->BackfaceProperty) {
00569     this->BackfaceProperty->BackfaceRender(this, ren);
00570     this->Device->SetBackfaceProperty(this->BackfaceProperty);
00571   }
00572   this->Device->SetProperty(this->Property);
00573   /*  if(myShape.ShapeType() == TopAbs_VERTEX) {
00574     if(ren){
00575       //The parameter determine size of vertex actor relate to diagonal of RendererWindow
00576       static vtkFloatingPointType delta = 0.01;
00577       vtkFloatingPointType X1 = -1, Y1 = -1, Z1 = 0;
00578       ren->ViewToWorld(X1,Y1,Z1);
00579       vtkFloatingPointType X2 = +1, Y2 = +1, Z2 = 0;
00580       ren->ViewToWorld(X2,Y2,Z2);
00581       Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
00582       this->SetScale(Z2*delta);
00583     }
00584     vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
00585     this->GetMatrix(ren->GetActiveCamera(), aMatrix);
00586     this->Device->SetUserMatrix(aMatrix);
00587     this->Device->Render(ren,theMapper);
00588     aMatrix->Delete();    
00589     } else*/
00590     this->Device->Render(ren, theMapper);
00591 }
00592 
00593 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
00594 {
00595 #ifdef MYDEBUG
00596   MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
00597 #endif  
00598 }
00599 
00600 
00601 
00602 void GEOM_Actor::ShallowCopy(vtkProp *prop)
00603 {
00604 #ifdef MYDEBUG
00605   MESSAGE ( "GEOM_Actor::ShallowCopy" );
00606 #endif
00607   GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
00608   if ( f != NULL )
00609     {
00610       this->SetShape(f->getTopo(),f->GetDeflection());
00611     }
00612 
00613   // Now do superclass
00614   this->SALOME_Actor::ShallowCopy(prop);
00615 }
00616 
00617 const TopoDS_Shape& GEOM_Actor::getTopo() {
00618 #ifdef MYDEBUG
00619   MESSAGE ( "GEOM_Actor::getTopo" );
00620 #endif
00621   return myShape;
00622 }
00623 
00624 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
00625                                int imode, bool isVector)
00626 {
00627 #ifdef MYDEBUG
00628   MESSAGE ( "GEOM_Actor::setInputShape" );
00629 #endif
00630 }
00631 
00632 double GEOM_Actor::getDeflection()
00633 {
00634 #ifdef MYDEBUG
00635   MESSAGE ( "GEOM_Actor::getDeflection" );
00636 #endif
00637   return (double) GetDeflection();
00638 }
00639 
00640 
00641 double GEOM_Actor::isVector()
00642 {
00643 #ifdef MYDEBUG
00644   MESSAGE ( "GEOM_Actor::isVector" );
00645 #endif  
00646   return 0;
00647 }
00648 
00649 void GEOM_Actor::SubShapeOn()
00650 {
00651 #ifdef MYDEBUG
00652   MESSAGE ( "GEOM_Actor::SubShapeOn" );
00653 #endif  
00654 }
00655 
00656 void GEOM_Actor::SubShapeOff()
00657 {
00658 #ifdef MYDEBUG
00659   MESSAGE ( "GEOM_Actor::SubShapeOff" );
00660 #endif
00661 }
00662 
00663 void GEOM_Actor::highlight(bool highlight)
00664 {
00665 #ifdef MYDEBUG
00666   MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
00667 #endif
00668   SALOME_Actor::highlight(highlight);  
00669 }
00670 
00671 void GEOM_Actor::SetOpacity(vtkFloatingPointType opa)
00672 {
00673   // enk:tested OK
00674   myShadingFaceProp->SetOpacity(opa);
00675   myHighlightProp->SetOpacity(opa);
00676   myPreHighlightProp->SetOpacity(opa);
00677   myVertexActor->GetProperty()->SetOpacity(opa);
00678 }
00679 
00680 vtkFloatingPointType GEOM_Actor::GetOpacity()
00681 {
00682   // enk:tested OK
00683   return myShadingFaceProp->GetOpacity(); 
00684 }
00685 
00686 void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
00687 {
00688   // enk:tested OK
00689   myShadingFaceProp->SetColor(r,g,b);                          // shading color (Shading)
00690   myVertexActor->GetProperty()->SetColor(r,g,b);               // vertex actor (Shading/Wireframe)
00691   if ( myDisplayMode != (int)eShadingWithEdges ) {
00692     myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b);         // standalone edge color (Wireframe)
00693     myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b);          // standalone face edge color (Wireframe)
00694     mySharedEdgeActor->GetProperty()->SetColor(r,g,b);           // share edge color (Wireframe)
00695   }
00696 
00697   StoreBoundaryColors();
00698 }
00699 
00700 void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
00701 {
00702   // enk:tested OK
00703   vtkFloatingPointType aRGB[3];
00704   myShadingFaceProp->GetColor(aRGB);
00705   r = aRGB[0];
00706   g = aRGB[1];
00707   b = aRGB[2];
00708 }
00709 
00710 void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
00711 {
00712   // we set material properties as back and front material
00713   double aCoefnt;
00714 
00715   // Set reflection coefficients
00716   aCoefnt = theProps[0]->GetAmbient();
00717   myShadingFaceProp->SetAmbient(aCoefnt);
00718   myVertexActor->GetProperty()->SetAmbient(aCoefnt);
00719 
00720   // Set diffuse coefficients
00721   aCoefnt = theProps[0]->GetDiffuse();
00722   myShadingFaceProp->SetDiffuse(aCoefnt);
00723   myVertexActor->GetProperty()->SetDiffuse(aCoefnt);
00724   
00725   // Set specular coefficients
00726   aCoefnt = theProps[0]->GetSpecular();
00727   myShadingFaceProp->SetSpecular(aCoefnt);
00728   myVertexActor->GetProperty()->SetSpecular(aCoefnt);
00729 
00730   double* aColor;
00731 
00732   // Set reflection colors
00733   aColor = theProps[0]->GetAmbientColor();
00734   myShadingFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
00735   myVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
00736 
00737   // Set diffuse colors
00738   aColor = theProps[0]->GetDiffuseColor();
00739   myShadingFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
00740   myVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
00741 
00742   // Set specular colors
00743   aColor = theProps[0]->GetSpecularColor();
00744   myShadingFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
00745   myVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
00746 
00747   // Set shininess
00748   aCoefnt = theProps[0]->GetSpecularPower();
00749   myShadingFaceProp->SetSpecularPower(aCoefnt);
00750   myVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
00751 }
00752 
00753 vtkProperty* GEOM_Actor::GetMaterial()
00754 {
00755   return myShadingFaceProp;
00756 }
00757 
00758 bool GEOM_Actor::IsInfinitive()
00759 {
00760   return ((bool)myShape.Infinite() || isOnlyVertex);
00761 }
00762 
00766 void
00767 GEOM_Actor
00768 ::Highlight(bool theIsHighlight)
00769 {
00770   myIsSelected = theIsHighlight;
00771 #ifdef MYDEBUG
00772   MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
00773 #endif
00774 
00775   if ( myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges ) {
00776     if ( theIsHighlight )
00777       RestoreIsoNumbers();
00778     else
00779       // Reset number of iso lines to 0
00780       ResetIsoNumbers();
00781   }
00782 
00783   SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
00784   SetVisibility(GetVisibility());
00785 }
00786 
00790 bool
00791 GEOM_Actor
00792 ::PreHighlight(vtkInteractorStyle *theInteractorStyle, 
00793                SVTK_SelectionEvent* theSelectionEvent,
00794                bool theIsHighlight)
00795 {
00796 #ifdef MYDEBUG
00797   MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
00798 #endif
00799 
00800   if ( !GetPickable() )
00801     return false;  
00802 
00803   if ( myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges ) {
00804     if ( theIsHighlight )
00805       RestoreIsoNumbers();
00806     else
00807       // Reset number of iso lines to 0
00808       ResetIsoNumbers();
00809   }
00810 
00811   myPreHighlightActor->SetVisibility( false );
00812   bool anIsPreselected = myIsPreselected;
00813   
00814   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
00815   bool anIsChanged = (mySelectionMode != aSelectionMode);
00816 
00817   if( !theIsHighlight ) {
00818     SetPreSelected( false );
00819   }else{
00820     switch(aSelectionMode){
00821     case ActorSelection : 
00822     {
00823 //       cout << "=============== " << myIO->getEntry() << endl;
00824 //       int nbio = mySelector->IObjectCount();
00825 //       cout << " nbio = " << nbio << endl;
00826 
00827       if( !mySelector->IsSelected( myIO ) ) {
00828         //      printf ("!!!!!!!!!!!!!!!!\n");
00829         SetPreSelected( true );
00830       }
00831     }
00832     default:
00833       break;
00834     }
00835   }
00836 
00837   mySelectionMode = aSelectionMode;
00838   anIsChanged |= (anIsPreselected != myIsPreselected);
00839 
00840   SetVisibility(GetVisibility());
00841   return anIsChanged;
00842 }
00843 
00847 bool
00848 GEOM_Actor
00849 ::Highlight(vtkInteractorStyle *theInteractorStyle, 
00850             SVTK_SelectionEvent* theSelectionEvent,
00851             bool theIsHighlight)
00852 {
00853   // define the selection of object
00854 #ifdef MYDEBUG
00855   MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
00856 #endif
00857   bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
00858   SetSelected(theIsHighlight);
00859   if(theIsHighlight)
00860     SetPreSelected(false);
00861   
00862  
00863   return aRet;
00864 }
00865 
00866 // Copy the follower's composite 4x4 matrix into the matrix provided.
00867 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
00868 {
00869   double *pos, *vup;
00870   double Rx[3], Ry[3], Rz[3], p1[3];
00871   vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
00872   int i;
00873   double distance;
00874   
00875   this->GetOrientation();
00876   this->Transform->Push();  
00877   this->Transform->PostMultiply();  
00878   this->Transform->Identity();
00879 
00880   // apply user defined matrix last if there is one 
00881   if (this->UserMatrix)
00882     {
00883     this->Transform->Concatenate(this->UserMatrix);
00884     }
00885 
00886   this->Transform->Translate(-this->Origin[0],
00887                              -this->Origin[1],
00888                              -this->Origin[2]);
00889   // scale
00890   this->Transform->Scale(this->Scale[0],
00891                          this->Scale[1],
00892                          this->Scale[2]);
00893   
00894   // rotate
00895   this->Transform->RotateY(this->Orientation[1]);
00896   this->Transform->RotateX(this->Orientation[0]);
00897   this->Transform->RotateZ(this->Orientation[2]);
00898 
00899   if (theCam)
00900     {
00901     // do the rotation
00902     // first rotate y 
00903     pos = theCam->GetPosition();
00904     vup = theCam->GetViewUp();
00905 
00906     if (theCam->GetParallelProjection())
00907       {
00908       theCam->GetDirectionOfProjection(Rz);
00909       }
00910     else
00911       {
00912       distance = sqrt(
00913         (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
00914         (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
00915         (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
00916       for (i = 0; i < 3; i++)
00917         {
00918         Rz[i] = (pos[i] - this->Position[i])/distance;
00919         }
00920       }
00921   
00922     vtkMath::Cross(vup,Rz,Rx);
00923     vtkMath::Normalize(Rx);
00924     vtkMath::Cross(Rz,Rx,Ry);
00925     
00926     matrix->Element[0][0] = Rx[0];
00927     matrix->Element[1][0] = Rx[1];
00928     matrix->Element[2][0] = Rx[2];
00929     matrix->Element[0][1] = Ry[0];
00930     matrix->Element[1][1] = Ry[1];
00931     matrix->Element[2][1] = Ry[2];
00932     matrix->Element[0][2] = Rz[0];
00933     matrix->Element[1][2] = Rz[1];
00934     matrix->Element[2][2] = Rz[2];
00935     
00936     this->Transform->Concatenate(matrix);
00937     }
00938   
00939   // translate to projection reference point PRP
00940   // this is the camera's position blasted through
00941   // the current matrix
00942   p1[0] = this->Origin[0] + this->Position[0];
00943   p1[1] = this->Origin[1] + this->Position[1];
00944   p1[2] = this->Origin[2] + this->Position[2];
00945 
00946   this->Transform->Translate(p1[0],p1[1],p1[2]);
00947   this->Transform->GetMatrix(result);
00948   
00949   matrix->Delete();
00950   this->Transform->Pop();  
00951 }  
00952 
00953 void GEOM_Actor::SetEdgesInShadingColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
00954 {
00955   myEdgesInShadingColor[0] = r;
00956   myEdgesInShadingColor[1] = g;
00957   myEdgesInShadingColor[2] = b;
00958 }
00959 
00960 void GEOM_Actor::StoreIsoNumbers()
00961 {  
00962   myWireframeFaceSource->GetNbIso(myNbIsos[0], myNbIsos[1]);
00963 }
00964 
00965 void GEOM_Actor::SetIsosWidth(const int width) {
00966   myWireframeFaceActor->GetProperty()->SetLineWidth(width);
00967 }
00968 
00969 int GEOM_Actor::GetIsosWidth() const {
00970   return (int)myWireframeFaceActor->GetProperty()->GetLineWidth();
00971 }
00972 
00973 void GEOM_Actor::SetWidth(const int width) {
00974   myIsolatedEdgeActor->GetProperty()->SetLineWidth(width);
00975   myOneFaceEdgeActor->GetProperty()->SetLineWidth(width);
00976   mySharedEdgeActor->GetProperty()->SetLineWidth(width);
00977   myHighlightProp->SetLineWidth(width);
00978   myPreHighlightProp->SetLineWidth(width+1);
00979 
00980 }
00981 
00982 int GEOM_Actor::GetWidth() const {
00983   return (int)myIsolatedEdgeActor->GetProperty()->GetLineWidth();
00984 }
00985     
00986 void GEOM_Actor::RestoreIsoNumbers()
00987 {
00988   if ( myNbIsos[0] > 0 || myNbIsos[1] > 0 )
00989     // Restore number of U and (or) V iso lines
00990     myWireframeFaceSource->SetNbIso(myNbIsos);
00991 }
00992   
00993 void GEOM_Actor::ResetIsoNumbers()
00994 {
00995   int aNb[2] = {0, 0};
00996   myWireframeFaceSource->SetNbIso(aNb);
00997 }
00998 
00999 void GEOM_Actor::StoreBoundaryColors()
01000 {
01001   myShadingFaceProp->GetColor(myEdgesInWireframeColor);
01002 
01003 }
01004  
01005 void GEOM_Actor::RestoreBoundaryColors()
01006 {
01007   myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
01008                                           myEdgesInWireframeColor[1],
01009                                           myEdgesInWireframeColor[2]);
01010   myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
01011                                          myEdgesInWireframeColor[1],
01012                                          myEdgesInWireframeColor[2]);
01013   mySharedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
01014                                         myEdgesInWireframeColor[1],
01015                                         myEdgesInWireframeColor[2]);
01016 }