]> Creatis software - creaVtk.git/blob - lib/creaVtk/vtkTensorsVisu.cpp
#2446 creaVtk Feature New Normal - Stream Tracer, Stream Line (interface, widget)
[creaVtk.git] / lib / creaVtk / vtkTensorsVisu.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la Sante)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and
11 #  abiding by the rules of distribution of free software. You can  use,
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B
13 #  license as circulated by CEA, CNRS and INRIA at the following URL
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability.
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26 */
27
28 #include "vtkTensorsVisu.h"
29
30 #include "vtkProperty.h"
31
32 //------------------------------------------------------------------------
33 vtkTensorsVisu::vtkTensorsVisu() : vtkVectorsTensorsVisuBase()
34 {
35         ss              = vtkSphereSource::New();
36         superquadratic  = vtkSuperquadricSource::New();
37         cs              = vtkCubeSource::New(); 
38         tg              = vtkTensorGlyph::New();
39         pdn             = vtkPolyDataNormals::New();
40         pd              = vtkPolyData::New();
41         pod             = vtkPointData::New();
42 }
43
44 //------------------------------------------------------------------------
45 vtkTensorsVisu::~vtkTensorsVisu()
46 {
47 }
48
49
50 //------------------------------------------------------------------------
51 void vtkTensorsVisu::Process()
52 {
53 printf("EED vtkTensorsVisu::Process Start\n");
54
55
56   if (_active==true){
57 //        std::string source="sphere";
58         std::string source="superquadratic";
59         if(source=="sphere")
60         {
61                 tg->SetSource(ss->GetOutput());
62         } else if(source=="cube") {
63                 tg->SetSource(cs->GetOutput());
64         }else if(source=="superquadratic") {
65                 superquadratic->SetThetaResolution(20);
66                 superquadratic->SetPhiResolution(20);
67                 tg->SetSource(superquadratic->GetOutput());
68         } else {
69         }
70
71
72         tg->SetInput( GetDataObject() );
73         //              tg->ScalingOn();
74         //              tg->SetScaling(25);
75         //if(isfromcal)
76         tg->SetScaleFactor( GetScaleFactor() );
77         tg->ScalingOn(  );      
78         //else
79         //      //tg->SetScaleFactor(2);
80         //      tg->SetScaleFactor(scale_factor);
81 //EED   tg->Update();
82
83         //The normals are needed to generate the right colors and if
84         // not used some of the glyphs are black.
85         pdn->SetInput(tg->GetOutput());
86 //EED   pdn->Update();
87
88
89         //EED================================
90         //pdm->SetInput( tg->GetOutput());
91         //pdm->SetScalarRange( range );
92
93         //vtkPolyData           *pd                     = tg->GetOutput();
94         //vtkPointData  *pointdata      = pd->GetPointData();
95         //vtkDataArray  *da                     = pointdata->GetVectors();
96
97         //vtkDataArray *nda = vtkFloatArray::New();
98         //nda->DeepCopy(da);
99
100         //pointdata->AddArray( nda );
101         //reader->GetOutput()->GetPointData()->AddArray( nda );
102
103         //pdm->SetInput(pdn->GetOutput());
104         //pdm->ScalarVisibilityOn();
105         //pdm->SetLookupTable(vLutEED);
106         //pdm->SetColorModeToMapScalars();
107         //pdm->SelectColorArray("color");
108         //pdm->SetScalarModeToUsePointFieldData();
109         //pdm->ImmediateModeRenderingOn();
110         //=====================================
111
112         _pdm->SetInput( pdn->GetOutput() );
113         _pdm->ImmediateModeRenderingOn();
114
115    _pdm->ScalarVisibilityOn();
116    _pdm->SetScalarModeToUsePointFieldData();
117
118
119 //EED   _pdm->Update();
120
121         _actor->SetMapper( _pdm );
122    _actor->GetProperty()->SetOpacity( GetOpacity() );
123
124         tg->ColorGlyphsOn();
125 //      tg->ExtractEigenvaluesOn();
126         tg->SetColorModeToEigenvalues();
127
128         _pdm->SetLookupTable( _LutEED );
129    _pdm->SelectColorArray( "Normals" );
130
131
132         //int tcg = tg->GetColorGlyphs();
133 //      tg->SetColorGlyphs(10);
134 //      tg->SetColorModeToScalars();
135         //tg->ThreeGlyphsOn();
136
137
138         //vtkDataArray* da = vtkDataArray::New();
139         pd = tg->GetOutput();
140         pd->Update();
141         pod = pd->GetPointData();
142         pod->Update();
143 //EED1  if(pod->GetScalars())
144 //EED1  {
145 //EED1          _pdm->SetScalarRange(pod->GetScalars()->GetRange());
146 //EED1  }
147         //pdm->SelectColorArray("GlyphVector");
148
149 //EED   _pdm->Update(); 
150
151
152
153                         tg->Print( std::cout );
154                 printf("EED vtkTensorsVisu::Process  ------------------------------------------\n");
155                         pd->Print( std::cout );
156
157
158         tg->Update();
159                         vtkPolyData     *pd             = pdn->GetOutput();
160                         vtkPointData    *pointdata      = pd->GetPointData();
161
162
163                 printf("EED vtkTensorsVisu::Process  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx\n");
164                         pointdata->Print( std::cout );
165                         
166
167                         int aa = pd->GetNumberOfPieces ();
168                         int bb = pd->GetNumberOfVerts ();
169                         int cc = pd->GetNumberOfLines ();
170                         int dd = pd->GetNumberOfPolys ();
171                         int ee = pd->GetNumberOfStrips ();
172                         int ff = pd->GetNumberOfCells();
173
174                 printf("EED vtkTensorsVisu::Process  %d %d %d %d %d %d \n", aa,bb,cc,dd,ee,ff);
175
176                         vtkPolyData *ttt = (vtkPolyData *)GetDataObject();
177                         int numPnts = ttt->GetNumberOfPoints();
178                         printf("EED vtkTensorsVisu::Process  numPnts %d \n", numPnts );
179
180
181                         vtkIdType numSourcePts, numSourceCells;
182                         vtkPoints *sourcePts;
183                         sourcePts = tg->GetSource()->GetPoints();
184                         numSourcePts = sourcePts->GetNumberOfPoints();
185                         numSourceCells = tg->GetSource()->GetNumberOfCells();
186                         printf("EED vtkTensorsVisu::Process  numSourcePts %d   numSourceCells %d\n", numSourcePts, numSourceCells);
187
188
189
190                         int i,sizeDa = pointdata->GetNumberOfArrays();
191                         printf("EED vtkTensorsVisu::Process  sizeDa %d \n", sizeDa );
192                         for (i=0;i<sizeDa;i++)
193                         {
194                                 int faces = pointdata->GetArray(i)->GetSize() / numPnts;
195                                 printf("EED vtkTensorsVisu::Process-name %d, %s, size=%d   %d \n", i, pointdata->GetArrayName(i) , pointdata->GetArray(i)->GetSize(), faces );
196                         }
197
198
199
200
201   } // _active
202
203     VisibilityActor(); 
204
205 printf("EED vtkTensorsVisu::Process End.\n");
206 }
207