]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkIsoSurfaceExtractor.cxx
d48505ad01848a39520ee72853a933186a755923
[bbtk.git] / packages / vtk / src / bbvtkIsoSurfaceExtractor.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbvtkIsoSurfaceExtractor.cxx,v $
4   Language:  C++
5   Date:      $Date: 2009/05/15 14:58:01 $
6   Version:   $Revision: 1.14 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *  \file 
33  *  \brief 
34  */
35
36
37 #ifdef _USE_VTK_
38
39 #include "vtkProperty.h"
40 #include "vtkLinearTransform.h"
41
42 #include "bbvtkIsoSurfaceExtractor.h"
43 #include "bbvtkPackage.h"
44
45 namespace bbvtk
46 {
47    BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,IsoSurfaceExtractor)
48    BBTK_BLACK_BOX_IMPLEMENTATION(IsoSurfaceExtractor,bbtk::AtomicBlackBox);
49
50    void IsoSurfaceExtractor::bbUserSetDefaultValues() 
51    { 
52            printf("EED %p IsoSurfaceExtractor::bbUserConstructor \n", this);
53            firsttime=true;
54            std::vector<double> colour;
55            colour.push_back(1.0);
56            colour.push_back(1.0);
57            colour.push_back(0.5);
58            bbSetInputColour(colour);
59
60            bbSetInputIn(NULL);
61            //     bbSetInputInVtkObject(NULL);
62            bbSetInputRenderer(NULL);
63            bbSetInputTransform(NULL);
64            bbSetInputIsovalue(400);
65            bbSetInputOpacity(1);
66
67            marchingcubes        = NULL;
68            polydatamapper       = NULL;
69            vtkactor         = NULL;
70    }
71
72
73         //---------------------------------------------------------------------
74    void IsoSurfaceExtractor::bbUserInitializeProcessing() 
75    {     
76      marchingcubes      = vtkMarchingCubes::New();
77      polydatamapper     = vtkPolyDataMapper::New();
78      vtkactor           = vtkActor::New();
79
80      polydatamapper->SetInput(marchingcubes->GetOutput());
81      vtkactor->SetMapper(polydatamapper);
82
83      polydatamapper->ScalarVisibilityOff();
84      polydatamapper->ImmediateModeRenderingOn();
85    }
86
87         //---------------------------------------------------------------------
88         void IsoSurfaceExtractor::bbUserFinalizeProcessing() 
89         { 
90                 if (marchingcubes!=NULL)
91                 {
92                         marchingcubes->Delete();
93                         marchingcubes=NULL;
94                 }
95
96                 
97                 if (polydatamapper!=NULL)
98                 {
99                         polydatamapper->Delete();
100                         polydatamapper=NULL;
101                 }
102
103                 if (vtkactor!=NULL)
104                 {
105                         vtkactor->Delete();
106                         vtkactor=NULL;
107                 }
108                 
109                 
110                 
111                 
112         }
113         
114         
115 //---------------------------------------------------------------------
116
117    void IsoSurfaceExtractor::DoProcess()
118    {
119 printf("EED %p IsoSurfaceExtractor::DoProcess \n", this);
120      marchingcubes->SetInput( bbGetInputIn() );
121      marchingcubes->SetValue(0,  bbGetInputIsovalue() );
122      marchingcubes->Update();
123      
124      vtkactor->GetProperty()->SetColor( bbGetInputColour()[0],  
125                                         bbGetInputColour()[1], 
126                                         bbGetInputColour()[2] );
127      
128      
129      vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
130      
131      if ( bbGetInputTransform()!=NULL )
132        {
133          vtkactor->SetUserTransform( bbGetInputTransform() );
134        }
135
136      bbSetOutputOut( vtkactor );
137
138      // Interface Update
139      if ((firsttime==true) && (bbGetInputRenderer()!=NULL ))
140      {
141        firsttime=false;
142        bbGetInputRenderer()->AddActor( vtkactor );
143      } 
144    }
145 } // EO namespace bbtk
146
147 #endif //_USE_VTK_