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