]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkSphereList.cxx
In SphereList box : added the possibility to use a vector of colors defining the...
[bbtk.git] / packages / vtk / src / bbvtkSphereList.cxx
1 #include "bbvtkSphereList.h"
2 #include "bbvtkPackage.h"
3
4 #include <vtkPolyDataMapper.h>
5 #include <vtkProperty.h>
6 #include <vtkRenderWindow.h>
7
8 namespace bbvtk
9 {
10
11 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,SphereList)
12 BBTK_BLACK_BOX_IMPLEMENTATION(SphereList,bbtk::AtomicBlackBox);
13
14 void SphereList::Process()
15 {
16
17         int iMin, iMax;
18         double px = 0.0;
19         double py = 0.0;
20         double pz = 0.0;
21         double radio;
22         double spc[3];
23  
24         int last_valid_color_index = 0;
25
26         if (bbGetInputRenderer()!=NULL)
27         {
28                 spc[0]=spc[1]=spc[2]=1;
29
30                 iMin=0;
31                 iMax=bbGetInputlstPointX().size();
32                 printf("EED SphereList::Process   iMax=%d \n", iMax);
33                 // 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.
34                 for ( int i=iMin ; i<iMax ; i=i+1 )
35                 {
36                         px = bbGetInputlstPointX()[i]*spc[0];
37                         if (bbGetInputlstPointY().size() == bbGetInputlstPointX().size() )
38                           {
39                             py = bbGetInputlstPointY()[i]*spc[1];
40                           }
41                         if (bbGetInputlstPointZ().size() == bbGetInputlstPointX().size() )
42                           {                     
43                             pz = bbGetInputlstPointZ()[i]*spc[2];
44                           }
45
46                         // If the number of elements in the radio list is different from the number of X coordinates, the radio value is set to 1.
47                         if (bbGetInputlstRadio().size() == bbGetInputlstPointX().size() )
48                           {
49                             radio = bbGetInputlstRadio()[i];
50                           }
51                         else
52                           {
53                             if  (bbGetInputlstRadio().size()>=1){
54                                radio = bbGetInputlstRadio()[ bbGetInputlstRadio().size() - 1 ];
55                                 } else {
56                                         radio = 1.0;
57                                 }
58                           }
59
60                         // Sphere
61                         vtkSphereSource * newSphere =  vtkSphereSource::New();
62                         vtkSphere.push_back(newSphere);
63
64                         newSphere -> SetThetaResolution(20);
65                         newSphere -> SetPhiResolution(20);
66                         newSphere -> SetRadius(radio); 
67
68                         vtkPolyDataMapper * newMapper = vtkPolyDataMapper::New();
69                         sphereMapper.push_back(newMapper);
70                         newMapper -> SetInput( newSphere -> GetOutput() );
71         
72                         vtkActor * newActor = vtkActor::New();
73                         sphereActor.push_back(newActor);
74                         newActor -> SetMapper(newMapper);
75                         newActor -> SetOrigin(0, 0, 0);
76                         
77                         unsigned int j = 3*i +2;
78                         if (j < bbGetInputColour().size() )
79                           {
80                             newActor -> GetProperty() -> SetColor( bbGetInputColour()[3*i] , bbGetInputColour()[3*i + 1] , bbGetInputColour()[3*i + 2] );
81                             last_valid_color_index = 3*i;
82                           }
83                         else
84                           newActor -> GetProperty() -> SetColor( bbGetInputColour()[last_valid_color_index] , bbGetInputColour()[last_valid_color_index + 1] , bbGetInputColour()[last_valid_color_index + 2] );
85
86                         newActor -> GetProperty() -> SetOpacity( bbGetInputOpacity() );
87                         newActor -> SetPosition( px,py,pz );
88         
89                         if ( bbGetInputTransform()!=NULL )
90                         {
91                                 newActor->SetUserTransform( bbGetInputTransform() );
92                         }
93         
94
95                         if (bbGetInputRenderer()!=NULL)
96                           {
97                             bbGetInputRenderer() -> AddActor( newActor );
98                           }
99
100                 } // for
101
102                 if (sphereActor.size() != 0)
103                   {
104                     // Sets the output.
105                     bbSetOutputActorList(sphereActor);
106                   }
107
108         } // if (bbGetInputRenderer()!=NULL)
109
110
111 }
112
113 void SphereList::bbUserSetDefaultValues()
114 {
115  
116   bbSetInputRenderer(NULL);
117   bbSetInputTransform(NULL);
118  
119   // Sets default radio to 1.
120   std::vector<double> radio;
121   radio.push_back(1.0);
122   bbSetInputlstRadio(radio);
123
124   // Sets default colour to red.
125   std::vector<double> colour;
126   colour.push_back(1.0);
127   colour.push_back(0.0);
128   colour.push_back(0.0);
129   bbSetInputColour(colour);
130   
131   bbSetInputOpacity(1.0);
132
133 }
134
135 void SphereList::bbUserInitializeProcessing()
136 {
137  
138 }
139
140 void SphereList::bbUserFinalizeProcessing()
141 {
142   
143 }
144 }
145 // EO namespace bbvtk
146
147