]> Creatis software - bbtk.git/commitdiff
Enabled dynamic modification of opacity in vtkShereList
authorClaire Mouton <claire.mouton@creatis.insa-lyon.fr>
Wed, 16 Jan 2013 10:36:07 +0000 (11:36 +0100)
committerClaire Mouton <claire.mouton@creatis.insa-lyon.fr>
Wed, 16 Jan 2013 10:36:07 +0000 (11:36 +0100)
Feature #1888

packages/vtk/src/bbvtkSphereList.cxx
packages/vtk/src/bbvtkSphereList.h

index 7577a0a7ed47a6d1c5e980a03102507a2b5c235d..8d5cfe7069f7604a2069db6f0957d108a9daa25a 100644 (file)
@@ -41,7 +41,7 @@ BBTK_BLACK_BOX_IMPLEMENTATION(SphereList,bbtk::AtomicBlackBox);
 void SphereList::Process()
 {
 
-    int iMin, iMax;
+        int iMin, iMax;
        double px = 0.0;
        double py = 0.0;
        double pz = 0.0;
@@ -50,23 +50,41 @@ void SphereList::Process()
  
        int last_valid_color_index = 0;
 
+
        if (bbGetInputRenderer()!=NULL)
        {
-               if (bbGetInputSpacing().size()==3)
-               {
+                // If it is not the first time Process is executed, the actors have already been created. The only thing to do is to update the opacity. 
+               if (sphereActor.size() != 0)
+                {
+                  for (int i = 0; i < sphereActor.size(); i++)
+                    sphereActor[i] -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
+               }
+                else
+                {
+                    if (bbGetInputSpacing().size()==3)
+                    {
                        spc[0]=bbGetInputSpacing()[0];
                        spc[1]=bbGetInputSpacing()[1];
                        spc[2]=bbGetInputSpacing()[2];
-               } else {
+                    }
+                    else
+                    {
                        spc[0]=spc[1]=spc[2]=1;
-               }
-
-               iMin=0;
-               iMax=bbGetInputlstPointX().size();
-               printf("EED SphereList::Process   iMax=%d \n", iMax);
-               // If the vector Y or respectively the vector Z has a different size from the vector X, the position value py or respectively pz is set to 0.
-               for ( int i=iMin ; i<iMax ; i=i+1 )
-               {
+                    }
+
+                    iMin=0;
+                    iMax=bbGetInputlstPointX().size();
+                    printf("EED SphereList::Process   iMax=%d \n", iMax);
+                    for (int i = 0; i < iMax; i++)
+                      {
+                        std::cout << "CM SphereList::Process i=" <<  i  << " bbGetInputlstPointX()[i]=" << bbGetInputlstPointX()[i] << std::endl;
+                        std::cout << "CM SphereList::Process i=" <<  i  << " bbGetInputlstPointY()[i]=" << bbGetInputlstPointY()[i] << std::endl;
+                        std::cout << "CM SphereList::Process i=" <<  i  << " bbGetInputlstPointZ()[i]=" << bbGetInputlstPointZ()[i] << std::endl;
+                      }
+                    // If the vector Y or respectively the vector Z has a different size from the vector X, the position value py or respectively pz is set to 0.
+                    // Stops at iMax - 1 because of a bug of the box stdReadColumnsDouble creating an extra line at the end of the file.
+                    for ( int i=iMin ; i<iMax-1; i=i+1 )
+                    {
                        px = bbGetInputlstPointX()[i]*spc[0];
                        if (bbGetInputlstPointY().size() == bbGetInputlstPointX().size() )
                        {
@@ -79,28 +97,29 @@ void SphereList::Process()
 
                        // If the number of elements in the radio list is different from the number of X coordinates, the radio value is set to 1.
                        if (bbGetInputlstRadio().size() == bbGetInputlstPointX().size() )
-                         {
+                       {
                            radio = bbGetInputlstRadio()[i];
-                         }
+                        }
                        else
-                         {
-                           if  (bbGetInputlstRadio().size()>=1){
-                              radio = bbGetInputlstRadio()[ bbGetInputlstRadio().size() - 1 ];
-                               } else {
-                                       radio = 1.0;
-                               }
-                         }
+                       {
+                            if (bbGetInputlstRadio().size()>=1)
+                            {
+                                radio = bbGetInputlstRadio()[ bbGetInputlstRadio().size() - 1 ];
+                            } 
+                            else 
+                            {
+                                radio = 1.0;
+                            }
+                       }
 
                        // Sphere
                        vtkSphereSource * newSphere =  vtkSphereSource::New();
-                       vtkSphere.push_back(newSphere);
 
                        newSphere -> SetThetaResolution(20);
                        newSphere -> SetPhiResolution(20);
                        newSphere -> SetRadius(radio); 
 
                        vtkPolyDataMapper * newMapper = vtkPolyDataMapper::New();
-                       sphereMapper.push_back(newMapper);
                        newMapper -> SetInput( newSphere -> GetOutput() );
        
                        vtkActor * newActor = vtkActor::New();
@@ -110,10 +129,10 @@ void SphereList::Process()
                        
                        unsigned int j = 3*i +2;
                        if (j < bbGetInputColour().size() )
-                         {
+                       {
                            newActor -> GetProperty() -> SetColor( bbGetInputColour()[3*i] , bbGetInputColour()[3*i + 1] , bbGetInputColour()[3*i + 2] );
                            last_valid_color_index = 3*i;
-                         }
+                       }
                        else
                          newActor -> GetProperty() -> SetColor( bbGetInputColour()[last_valid_color_index] , bbGetInputColour()[last_valid_color_index + 1] , bbGetInputColour()[last_valid_color_index + 2] );
 
@@ -127,21 +146,21 @@ void SphereList::Process()
        
 
                        if (bbGetInputRenderer()!=NULL)
-                         {
+                       {
                            bbGetInputRenderer() -> AddActor( newActor );
-                         }
-
-               } // for
-
-               if (sphereActor.size() != 0)
-                 {
-                   // Sets the output.
-                   bbSetOutputActorList(sphereActor);
-                 }
+                       }
 
-       } // if (bbGetInputRenderer()!=NULL)
+                    } // for
 
+                    if (sphereActor.size() != 0)
+                    {
+                        // Sets the output.
+                        bbSetOutputActorList(sphereActor);
+                    }
+                    
+                } // if (bbGetInputRenderer()!=NULL)
 
+        } // if (sphereActor.size() != 0)
 }
 
 void SphereList::bbUserSetDefaultValues()
index edb397103263c3fc6dff5b035602cd25e12e9b9d..ac45d5ed087e0ff95a789996cebe5ab60bca89e1 100644 (file)
@@ -62,8 +62,6 @@ class bbvtk_EXPORT SphereList
   void Process();
 
   std::vector<vtkActor *> sphereActor;
-  std::vector<vtkPolyDataMapper *> sphereMapper;
-  std::vector<vtkSphereSource *> vtkSphere;
 
 };