Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/gui.git] / src / VTKViewer / VTKViewer_Actor.cxx
index d2f72e2b8e8f40b980fdf32092b66e3fd456e6c0..5181ccd07a2130d3fe9ae5dba2ccb38a133493b4 100755 (executable)
@@ -60,11 +60,11 @@ int VTKViewer_POINT_SIZE = 5;
 int VTKViewer_LINE_WIDTH = 3;
 
 
-//----------------------------------------------------------------------------
 vtkStandardNewMacro(VTKViewer_Actor);
 
-
-//----------------------------------------------------------------------------
+/*!
+  Constructor
+*/
 VTKViewer_Actor
 ::VTKViewer_Actor():
   myIsHighlighted(false),
@@ -86,8 +86,9 @@ VTKViewer_Actor
     myPassFilter.push_back(VTKViewer_PassThroughFilter::New());
 }
 
-
-//----------------------------------------------------------------------------
+/*!
+  Destructor
+*/
 VTKViewer_Actor
 ::~VTKViewer_Actor()
 {
@@ -104,8 +105,9 @@ VTKViewer_Actor
   myProperty->Delete();
 }
 
-
-//----------------------------------------------------------------------------
+/*!
+  \return name
+*/
 const char* 
 VTKViewer_Actor
 ::getName() 
@@ -113,6 +115,10 @@ VTKViewer_Actor
   return myName.c_str(); 
 }
 
+/*!
+  Sets name
+  \param theName - new name
+*/
 void
 VTKViewer_Actor
 ::setName(const char* theName)
@@ -120,8 +126,9 @@ VTKViewer_Actor
   myName = theName;
 }
 
-
-//----------------------------------------------------------------------------
+/*!
+  To publish the actor an all its internal devices
+*/
 void
 VTKViewer_Actor
 ::AddToRender(vtkRenderer* theRenderer)
@@ -129,6 +136,9 @@ VTKViewer_Actor
   theRenderer->AddActor(this);
 }
 
+/*!
+  To remove the actor an all its internal devices
+*/
 void 
 VTKViewer_Actor
 ::RemoveFromRender(vtkRenderer* theRenderer)
@@ -136,13 +146,18 @@ VTKViewer_Actor
   theRenderer->RemoveActor(this);
 }
 
+/*!
+  Used to obtain all dependent actors
+*/
 void
 VTKViewer_Actor
 ::GetChildActors(vtkActorCollection*) 
 {}
 
-
-//----------------------------------------------------------------------------
+/*!
+  Apply view transformation
+  \param theTransform - view transformation
+*/
 void
 VTKViewer_Actor
 ::SetTransform(VTKViewer_Transform* theTransform)
@@ -151,6 +166,9 @@ VTKViewer_Actor
 }
 
 
+/*!
+  To insert some additional filters and then sets the given #vtkMapper
+*/
 void
 VTKViewer_Actor
 ::SetMapper(vtkMapper* theMapper)
@@ -158,6 +176,9 @@ VTKViewer_Actor
   InitPipeLine(theMapper);
 }
 
+/*!
+  Initialization
+*/
 void
 VTKViewer_Actor
 ::InitPipeLine(vtkMapper* theMapper)
@@ -192,15 +213,23 @@ VTKViewer_Actor
   Superclass::SetMapper(theMapper);
 }
 
-
-//----------------------------------------------------------------------------
+/*!
+  Renders actor
+*/
 void
 VTKViewer_Actor
 ::Render(vtkRenderer *ren, vtkMapper* m)
 {
+  if(vtkDataSet* aDataSet = GetInput()){
+    static vtkFloatingPointType PERCENTS_OF_DETAILS = 0.50;
+    vtkIdType aNbOfPoints = vtkIdType(aDataSet->GetNumberOfPoints()*PERCENTS_OF_DETAILS);
+    if(aNbOfPoints > 0)
+      SetNumberOfCloudPoints(aNbOfPoints);
+  }
+
   if(myIsResolveCoincidentTopology){
     int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
-    float aFactor, aUnit; 
+    vtkFloatingPointType aFactor, aUnit; 
     vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
     
     vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
@@ -215,7 +244,10 @@ VTKViewer_Actor
   }
 }
 
-
+/*!
+  Set ResolveCoincidentTopology flag
+  \param theIsResolve - new flag value
+*/
 void
 VTKViewer_Actor
 ::SetResolveCoincidentTopology(bool theIsResolve) 
@@ -223,31 +255,45 @@ VTKViewer_Actor
   myIsResolveCoincidentTopology = theIsResolve;
 }
 
+/*!
+  Set polygon offset parameters
+  \param factor, units  - Opengl polygon offset parameters
+*/
 void
 VTKViewer_Actor
-::SetPolygonOffsetParameters(float factor, float units)
+::SetPolygonOffsetParameters(vtkFloatingPointType factor, 
+                            vtkFloatingPointType units)
 {
   myPolygonOffsetFactor = factor;
   myPolygonOffsetUnits = units;
 }
 
+/*!
+  Get polygon offset parameters
+  \param factor, units  - Opengl polygon offset parameters
+*/
 void
 VTKViewer_Actor
-::GetPolygonOffsetParameters(float& factor, float& units)
+::GetPolygonOffsetParameters(vtkFloatingPointType& factor, 
+                            vtkFloatingPointType& units)
 {
   factor = myPolygonOffsetFactor;
   units = myPolygonOffsetUnits;
 }
 
-
-//----------------------------------------------------------------------------
-float
+/*!
+  \return shrink factor
+*/
+vtkFloatingPointType
 VTKViewer_Actor
 ::GetShrinkFactor() 
 { 
   return 1.0;
 }
 
+/*!
+  \return true if the actor is shrunkable
+*/
 bool
 VTKViewer_Actor
 ::IsShrunkable() 
@@ -255,6 +301,9 @@ VTKViewer_Actor
   return false;
 }
 
+/*!
+  \return true if the actor is shrunk
+*/
 bool
 VTKViewer_Actor
 ::IsShrunk() 
@@ -262,18 +311,25 @@ VTKViewer_Actor
   return false;
 }
 
+/*!
+  Insert shrink filter into pipeline
+*/
 void
 VTKViewer_Actor
 ::SetShrink() 
 {} 
 
+/*!
+  Remove shrink filter from pipeline
+*/
 void
 VTKViewer_Actor
 ::UnShrink() 
 {}
 
-
-//----------------------------------------------------------------------------
+/*!
+  Allows to get initial #vtkDataSet
+*/
 vtkDataSet* 
 VTKViewer_Actor
 ::GetInput()
@@ -281,7 +337,9 @@ VTKViewer_Actor
   return myPassFilter.front()->GetOutput();
 }
 
-
+/*!
+  To calculatate last modified time
+*/
 unsigned long int
 VTKViewer_Actor
 ::GetMTime()
@@ -296,8 +354,10 @@ VTKViewer_Actor
   return mTime;
 }
 
-
-//----------------------------------------------------------------------------
+/*!
+  Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on)
+  param theMode - new mode
+*/
 void
 VTKViewer_Actor
 ::SetRepresentation(int theMode) 
@@ -305,18 +365,25 @@ VTKViewer_Actor
   switch(myRepresentation){
   case VTK_POINTS : 
   case VTK_SURFACE : 
-    myProperty->DeepCopy(GetProperty());
+    myProperty->SetAmbient(GetProperty()->GetAmbient());
+    myProperty->SetDiffuse(GetProperty()->GetDiffuse());
+    myProperty->SetSpecular(GetProperty()->GetSpecular());
+    break;
   }    
+
   switch(theMode){
   case VTK_POINTS : 
   case VTK_SURFACE : 
-    GetProperty()->DeepCopy(myProperty);
+    GetProperty()->SetAmbient(myProperty->GetAmbient());
+    GetProperty()->SetDiffuse(myProperty->GetDiffuse());
+    GetProperty()->SetSpecular(myProperty->GetSpecular());
     break;
   default:
     GetProperty()->SetAmbient(1.0);
     GetProperty()->SetDiffuse(0.0);
     GetProperty()->SetSpecular(0.0);
   }
+
   switch(theMode){
   case 3 : 
     myGeomFilter->SetInside(true);
@@ -340,9 +407,13 @@ VTKViewer_Actor
     myGeomFilter->SetInside(false);
     break;
   }
+
   myRepresentation = theMode;
 }
 
+/*!
+  \return current representation mode
+*/
 int
 VTKViewer_Actor
 ::GetRepresentation()
@@ -350,8 +421,9 @@ VTKViewer_Actor
   return myRepresentation;
 }
 
-
-//----------------------------------------------------------------------------
+/*!
+  Maps VTK index of a node to corresponding object index
+*/
 int 
 VTKViewer_Actor
 ::GetNodeObjId(int theVtkID)
@@ -359,13 +431,19 @@ VTKViewer_Actor
   return theVtkID;
 }
 
-float* 
+/*!
+  Get coordinates of a node for given object index
+*/
+vtkFloatingPointType* 
 VTKViewer_Actor
 ::GetNodeCoord(int theObjID)
 {
   return GetInput()->GetPoint(theObjID);
 }
 
+/*!
+  Get corresponding #vtkCell for given object index
+*/
 vtkCell* 
 VTKViewer_Actor
 ::GetElemCell(int theObjID)
@@ -373,6 +451,9 @@ VTKViewer_Actor
   return GetInput()->GetCell(theObjID);
 }
 
+/*!
+  Maps VTK index of a cell to corresponding object index
+*/
 int
 VTKViewer_Actor
 ::GetElemObjId(int theVtkID) 
@@ -381,11 +462,9 @@ VTKViewer_Actor
 }
 
 
-//=================================================================================
-// function : GetObjDimension
-// purpose  : Return object dimension.
-//            Virtual method shoulb be redifined by derived classes
-//=================================================================================
+/*!
+  \return object dimension. Virtual method should be redifined by derived classes
+*/
 int
 VTKViewer_Actor
 ::GetObjDimension( const int theObjId )
@@ -395,7 +474,10 @@ VTKViewer_Actor
   return 0;
 }
 
-
+/*!
+  Infinitive means actor without size (point for example),
+  which is not taken into account in calculation of boundaries of the scene
+*/
 void
 VTKViewer_Actor
 ::SetInfinitive(bool theIsInfinite)
@@ -403,21 +485,34 @@ VTKViewer_Actor
   myIsInfinite = theIsInfinite;
 }
 
-
+/*!
+  \return infinive flag
+*/
 bool
 VTKViewer_Actor
 ::IsInfinitive()
 { 
-  static float MIN_DISTANCE = 1.0 / VTK_LARGE_FLOAT;
+  if(myIsInfinite)
+    return true;
 
-  if(myIsInfinite || GetLength() < MIN_DISTANCE)
+  static vtkFloatingPointType MAX_DISTANCE = 0.9*VTK_LARGE_FLOAT;
+  vtkFloatingPointType aBounds[6];
+  GetBounds(aBounds);
+  for(int i = 0; i < 6; i++)
+    if(fabs(aBounds[i]) > MAX_DISTANCE)
+      return true;
+  
+  static vtkFloatingPointType MIN_DISTANCE = 1.0/VTK_LARGE_FLOAT;
+  if(GetLength() < MIN_DISTANCE)
     return true;
-  else
-    return false;
+  
+  return false;
 }
 
-
-float* 
+/*!
+  \return current bounding box
+*/
+vtkFloatingPointType* 
 VTKViewer_Actor
 ::GetBounds()
 {
@@ -425,15 +520,17 @@ VTKViewer_Actor
 }
 
 
+/*!
+  \return current bounding box
+*/
 void
 VTKViewer_Actor
-::GetBounds(float theBounds[6])
+::GetBounds(vtkFloatingPointType theBounds[6])
 {
   Superclass::GetBounds(theBounds);
 }
 
 
-//----------------------------------------------------------------------------
 bool
 VTKViewer_Actor
 ::IsSetCamera() const 
@@ -450,7 +547,7 @@ VTKViewer_Actor
 
 void
 VTKViewer_Actor
-::SetSize( const float ) 
+::SetSize( const vtkFloatingPointType ) 
 {}
 
 
@@ -459,16 +556,16 @@ VTKViewer_Actor
 ::SetCamera( vtkCamera* ) 
 {}
 
-//----------------------------------------------------------------------------
+
 void
 VTKViewer_Actor
-::SetOpacity(float theOpacity)
+::SetOpacity(vtkFloatingPointType theOpacity)
 { 
   myOpacity = theOpacity;
   GetProperty()->SetOpacity(theOpacity);
 }
 
-float
+vtkFloatingPointType
 VTKViewer_Actor
 ::GetOpacity()
 {
@@ -476,25 +573,38 @@ VTKViewer_Actor
 }
 
 
+/*!
+  Change color
+*/
 void
 VTKViewer_Actor
-::SetColor(float r,float g,float b)
+::SetColor(vtkFloatingPointType r,
+          vtkFloatingPointType g,
+          vtkFloatingPointType b)
 {
   GetProperty()->SetColor(r,g,b);
 }
 
+/*!
+  Change color
+*/
 void
 VTKViewer_Actor
-::SetColor(const float theRGB[3])
+::SetColor(const vtkFloatingPointType theRGB[3])
 { 
   SetColor(theRGB[0],theRGB[1],theRGB[2]);
 }
 
+/*!
+  Get color
+*/
 void
 VTKViewer_Actor
-::GetColor(float& r,float& g,float& b)
+::GetColor(vtkFloatingPointType& r,
+          vtkFloatingPointType& g,
+          vtkFloatingPointType& b)
 {
-  float aColor[3];
+  vtkFloatingPointType aColor[3];
   GetProperty()->GetColor(aColor);
   r = aColor[0];
   g = aColor[1];
@@ -502,7 +612,9 @@ VTKViewer_Actor
 }
 
 
-//----------------------------------------------------------------------------
+/*!
+  \return display mode
+*/
 int
 VTKViewer_Actor
 ::getDisplayMode()
@@ -510,6 +622,9 @@ VTKViewer_Actor
   return myDisplayMode; 
 }
 
+/*!
+  Change display mode
+*/
 void
 VTKViewer_Actor
 ::setDisplayMode(int theMode)
@@ -519,7 +634,9 @@ VTKViewer_Actor
 }
 
 
-//----------------------------------------------------------------------------
+/*!
+  \return true if the descendant of the VTKViewer_Actor will implement its own highlight or not
+*/
 bool
 VTKViewer_Actor
 ::hasHighlight() 
@@ -527,6 +644,9 @@ VTKViewer_Actor
   return false; 
 } 
 
+/*!
+  \return true if the VTKViewer_Actor is already highlighted
+*/
 bool
 VTKViewer_Actor
 ::isHighlighted() 
@@ -534,6 +654,9 @@ VTKViewer_Actor
   return myIsHighlighted; 
 }
 
+/*!
+  Set preselection mode
+*/
 void
 VTKViewer_Actor
 ::SetPreSelected(bool thePreselect) 
@@ -541,8 +664,9 @@ VTKViewer_Actor
   myIsPreselected = thePreselect;
 }
 
-
-//----------------------------------------------------------------
+/*!
+  Just to update visibility of the highlight devices
+*/
 void
 VTKViewer_Actor
 ::highlight(bool theIsHighlight)