]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkVolumeRenderer.cxx
2886 BBTK Bug New Normal - Refresh vtk:VolumeRenderer box
[bbtk.git] / packages / vtk / src / bbvtkVolumeRenderer.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
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 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbvtkVolumeRenderer.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:51:58 $
33   Version:   $Revision: 1.6 $
34 =========================================================================*/
35
36 /**
37  *  \file 
38  *  \brief 
39  */
40
41
42
43 #ifdef _USE_VTK_
44
45
46 #include "bbvtkVolumeRenderer.h"
47 #include "bbvtkPackage.h"
48
49 namespace bbvtk
50 {
51
52
53    BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,VolumeRenderer)
54    BBTK_BLACK_BOX_IMPLEMENTATION(VolumeRenderer,bbtk::AtomicBlackBox);
55
56
57
58
59
60    void VolumeRenderer::bbUserSetDefaultValues() 
61    { 
62            mRayCastFunction = NULL;
63            mMapper                      = NULL;
64            mVolume                      = NULL;
65            bbSetInputColorFunction(0);
66                 bbSetInputColorFunction1(0);
67            bbSetInputOpacityFunction(0);
68    }
69         
70    void VolumeRenderer::bbUserInitializeProcessing() 
71    { 
72
73     // Create the pipeline
74      //    mCast = vtkImageShiftScale::New();
75      //    mCast->SetOutputScalarTypeToUnsignedChar();
76      //    mCast->ClampOverflowOn();
77     
78     //    mMIP = vtkVolumeRayCastMIPFunction::New();
79     //    mMIP->SetMaximizeMethodToScalarValue();
80
81     mRayCastFunction = vtkVolumeRayCastCompositeFunction::New();
82     mMapper = vtkVolumeRayCastMapper::New();
83            mMapper->SetVolumeRayCastFunction(mRayCastFunction);
84            mMapper->AutoAdjustSampleDistancesOn();
85
86            _volumeProperty = vtkVolumeProperty::New();  
87         _volumeProperty->SetInterpolationTypeToLinear();
88         _volumeProperty->ShadeOn();
89         _volumeProperty->DisableGradientOpacityOn();    
90         //_volumeProperty->SetColor(_ctfun);
91         //_volumeProperty->SetScalarOpacity(_tfun );
92
93     mVolume = vtkVolume::New();
94            mVolume->SetMapper(mMapper);
95            mVolume->SetProperty(_volumeProperty );
96
97     //  mMapper->ScalarVisibilityOff();
98     //    mMapper->ImmediateModeRenderingOn();
99
100 }
101
102         //---------------------------------------------------------------------
103    void VolumeRenderer::bbUserFinalizeProcessing() 
104    { 
105            if (mRayCastFunction!=NULL)
106            {
107                    mRayCastFunction->Delete();
108                    mRayCastFunction=NULL;
109            }      
110            if (mMapper!=NULL)
111            {
112                    mMapper->Delete();
113                    mMapper=NULL;
114            }      
115            if (mVolume!=NULL)
116            {
117                    mVolume->Delete();
118                    mVolume=NULL;
119            }      
120
121    }
122 //---------------------------------------------------------------------
123
124 void VolumeRenderer::Process()
125 {
126     bool changed = false;
127     if ( bbGetInputStatus("In") != bbtk::UPTODATE )
128         {
129                 mMapper->SetInput( bbGetInputIn() );
130                 changed = true;
131     }
132
133         if ( ( bbGetInputStatus("ColorFunction") != bbtk::UPTODATE ) &&
134           ( bbGetInputColorFunction() != 0 ) )
135     {
136                 mVolume->GetProperty()->SetColor( bbGetInputColorFunction() );
137                 changed = true;
138     }
139
140      if ( ( bbGetInputStatus("ColorFunction1") != bbtk::UPTODATE ) &&
141           ( bbGetInputColorFunction1() != 0 ) )
142      {
143                 mVolume->GetProperty()->SetColor( bbGetInputColorFunction1() );
144                 changed = true;
145      }
146
147      if ( ( bbGetInputStatus("OpacityFunction") != bbtk::UPTODATE ) &&
148           ( bbGetInputOpacityFunction() != 0 ) )
149      {
150                 mVolume->GetProperty()->SetScalarOpacity(bbGetInputOpacityFunction());
151                 changed = true;
152      }
153
154         if (changed)
155         { 
156                 mMapper->Update();
157         }
158         bbSetOutputOut(mVolume); 
159 }
160
161
162 }//namespace bbtk
163
164 #endif // _USE_VTK_
165