1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #include "bbmaracasvisuDrawAxisTree3D.h"
27 #include "bbcreaMaracasVisuPackage.h"
28 #include "vtkLinearTransform.h"
30 namespace bbcreaMaracasVisu
33 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,DrawAxisTree3D)
34 BBTK_BLACK_BOX_IMPLEMENTATION(DrawAxisTree3D,bbtk::AtomicBlackBox);
38 void DrawAxisTree3D::DrawOneAxis(int iGeneral,int numPoints, int iAxis)
40 vtkPolyData *polydata = vtkPolyData::New( );
41 vtkPolyDataMapper *polydatamapper = vtkPolyDataMapper::New();
42 vtkActor *vtkactor = vtkActor::New();
44 polydatamapper->SetInput(polydata);
45 vtkactor->SetMapper(polydatamapper);
47 vecVtkPolyData.push_back( polydata );
48 vecVtkPolyDataMaper.push_back( polydatamapper );
49 vecVtkActors.push_back( vtkactor );
51 // vtkImageData* img = bbGetInputImage();
54 // img->GetSpacing(spc);
59 int lstpointsXsize =bbGetInputlstPointX().size();
61 if( lstpointsXsize>0 ){
62 vtkPoints* allPoints = vtkPoints::New( );
63 vtkCellArray* allTopology = vtkCellArray::New( );
64 allTopology->InsertNextCell( numPoints );
66 size=iGeneral+numPoints;
67 for (i=iGeneral;i<size;i++)
69 //multiplicar ver parametros spacing, en maracas cuando se toca la imagen y se ve dycom
70 //hay par·metro dycom, vtkImagedata valor spacing y esos datos hay que multiplicar al polydata
71 allPoints->InsertNextPoint( bbGetInputlstPointX()[i]*spc[0],
72 bbGetInputlstPointY()[i]*spc[1],
73 bbGetInputlstPointZ()[i]*spc[2] );
74 // printf("DrawAxisTree3D::DrawOneAxis point %d -> %f, %f, %f \n", i, bbGetInputlstPointX()[i], bbGetInputlstPointY()[i], bbGetInputlstPointZ()[i] );
75 allTopology->InsertCellPoint( i-iGeneral );
77 polydata->SetPoints( allPoints );
78 polydata->SetLines( allTopology );
80 allTopology->Delete();
86 if ( (iAxis*3+1) < (int)(bbGetInputColour().size()) )
88 r = bbGetInputColour()[0+iAxis*3];
89 g = bbGetInputColour()[1+iAxis*3];
90 b = bbGetInputColour()[2+iAxis*3];
92 r = (rand() % 100) / 100.0;
93 g = (rand() % 100) / 100.0;
94 b = (rand() % 100) / 100.0;
97 vtkactor->GetProperty()->SetColor( r,g,b );
98 vtkactor->GetProperty()->SetLineWidth( bbGetInputLineWidth() );
99 vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
101 if ( bbGetInputTransform()!=NULL )
103 vtkactor->SetUserTransform( bbGetInputTransform() );
107 if (bbGetInputRenderer()!=NULL )
109 bbGetInputRenderer()->AddActor( vtkactor );
114 void DrawAxisTree3D::Process()
116 printf("EED DrawAxisTree3D::Process start \n");
119 int iAxis,sizeLstAxis=bbGetInputlstIndexs().size();
120 int iActor,sizeActors = vecVtkActors.size();
123 if (oldLstSize!=sizeLstAxis)
125 oldLstSize=sizeLstAxis;
126 for (iActor=0 ; iActor<sizeActors; iActor++)
128 if (bbGetInputRenderer()!=NULL )
130 bbGetInputRenderer()->RemoveActor( vecVtkActors[iActor] );
131 vecVtkPolyData[iActor]->Delete();
132 vecVtkPolyDataMaper[iActor]->Delete();
133 vecVtkActors[iActor]->Delete();
136 vecVtkPolyData.clear();
137 vecVtkPolyDataMaper.clear();
138 vecVtkActors.clear();
140 for ( iAxis=0 ; iAxis<sizeLstAxis ; iAxis++)
142 numPoints = bbGetInputlstIndexs()[iAxis];
143 DrawOneAxis(iGeneral,numPoints,iAxis);
144 iGeneral = iGeneral+numPoints;
146 // if ((iAxis % 1)==0)
148 // printf("EED DrawAxisTree3D::Process %d/%d\n", iAxis,sizeLstAxis );
153 if ( bbGetInputiAxis() < (int)(vecVtkActors.size()-1) )
155 bbSetOutputOutAxis( vecVtkActors[ bbGetInputiAxis() ] );
157 printf("TubeTreeFilter .ERROR. missing index vector...\n");
160 } else {// if oldLstSize
161 for (iActor=0 ; iActor<sizeActors; iActor++)
163 vecVtkActors[iActor]->GetProperty()->SetOpacity( bbGetInputOpacity() );
167 printf("EED DrawAxisTree3D::Process end \n");
171 void DrawAxisTree3D::bbUserSetDefaultValues()
175 std::vector<double> colour;
177 colour.push_back(1.0);
178 colour.push_back(0.0);
179 colour.push_back(0.0);
181 colour.push_back(0.0);
182 colour.push_back(0.0);
183 colour.push_back(1.0);
185 colour.push_back(1.0);
186 colour.push_back(1.0);
187 colour.push_back(0.0);
189 colour.push_back(0.0);
190 colour.push_back(1.0);
191 colour.push_back(0.0);
193 colour.push_back(0.0);
194 colour.push_back(1.0);
195 colour.push_back(1.0);
198 colour.push_back(0.5);
199 colour.push_back(0.5);
200 colour.push_back(0.5);
202 bbSetInputColour(colour);
203 bbSetInputOpacity(1);
204 bbSetInputLineWidth(0.5);
205 bbSetInputColourLaw(1);
210 //-----------------------------------------------------------------
211 void DrawAxisTree3D::bbUserInitializeProcessing()
215 //-----------------------------------------------------------------
216 void DrawAxisTree3D::bbUserFinalizeProcessing()
220 //-----------------------------------------------------------------
223 // EO namespace bbcreaMaracasVisu