]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkIsoSurfaceExtractor.cxx
6db46979d3377815d00da38eb6d1d1ae7725ff6b
[bbtk.git] / packages / vtk / src / bbvtkIsoSurfaceExtractor.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbvtkIsoSurfaceExtractor.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/11/21 12:25:42 $
6   Version:   $Revision: 1.9 $
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::bbUserConstructor() 
51    { 
52      Init();
53      std::vector<double> colour;
54      colour.push_back(1.0);
55      colour.push_back(1.0);
56      colour.push_back(0.5);
57      bbSetInputColour(colour);
58          bbSetInputTransform(NULL);
59    }
60    void IsoSurfaceExtractor::bbUserCopyConstructor() 
61    { 
62      Init();
63    }
64
65    void IsoSurfaceExtractor::bbUserDestructor() 
66    { 
67      marchingcubes->Delete();
68      polydatamapper->Delete();
69      vtkactor->Delete();
70   }
71
72    void IsoSurfaceExtractor::Init() 
73    { 
74      firsttime=true;
75
76      bbSetInputIn(NULL);
77      //     bbSetInputInVtkObject(NULL);
78      bbSetInputRenderer(NULL);
79      bbSetInputIsovalue(400);
80      bbSetInputOpacity(1);
81          
82      marchingcubes      = vtkMarchingCubes::New();
83      polydatamapper     = vtkPolyDataMapper::New();
84      vtkactor           = vtkActor::New();
85
86      polydatamapper->SetInput(marchingcubes->GetOutput());
87      vtkactor->SetMapper(polydatamapper);
88
89      polydatamapper->ScalarVisibilityOff();
90      polydatamapper->ImmediateModeRenderingOn();
91 }
92
93 //---------------------------------------------------------------------
94
95    void IsoSurfaceExtractor::DoProcess()
96    {
97      //   bbGetInputIn()->Print(std::cout);
98      // Visualisation - result volume
99      marchingcubes->SetInput( bbGetInputIn() );
100      marchingcubes->SetValue(0,  bbGetInputIsovalue() );
101      marchingcubes->Update();
102      
103      vtkactor->GetProperty()->SetColor( bbGetInputColour()[0],  
104                                         bbGetInputColour()[1], 
105                                         bbGetInputColour()[2] );
106      
107      
108      vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
109         
110          if ( bbGetInputTransform()!=NULL )
111          {
112                  vtkactor->SetUserTransform( bbGetInputTransform() );
113          }
114
115      bbSetOutputOut( vtkactor );
116      
117      // Interface Update
118      if ((firsttime==true) && (bbGetInputRenderer()!=NULL ))
119      {
120                 firsttime=false;
121             bbGetInputRenderer()->AddActor( vtkactor );
122      }
123    }
124 } // EO namespace bbtk
125
126 #endif //_USE_VTK_