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