]> 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/10/16 08:52:13 $
6   Version:   $Revision: 1.5 $
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                 bbSetInputColorFunction1(0);
62            bbSetInputOpacityFunction(0);
63    }
64         
65    void VolumeRenderer::bbUserInitializeProcessing() 
66    { 
67
68     // Create the pipeline
69      //    mCast = vtkImageShiftScale::New();
70      //    mCast->SetOutputScalarTypeToUnsignedChar();
71      //    mCast->ClampOverflowOn();
72     
73     //    mMIP = vtkVolumeRayCastMIPFunction::New();
74     //    mMIP->SetMaximizeMethodToScalarValue();
75
76     mRayCastFunction = vtkVolumeRayCastCompositeFunction::New();
77     mMapper = vtkVolumeRayCastMapper::New();
78            mMapper->SetVolumeRayCastFunction(mRayCastFunction);
79            mMapper->AutoAdjustSampleDistancesOn();
80
81            _volumeProperty = vtkVolumeProperty::New();  
82         _volumeProperty->SetInterpolationTypeToLinear();
83         _volumeProperty->ShadeOn();
84         _volumeProperty->DisableGradientOpacityOn();    
85         //_volumeProperty->SetColor(_ctfun);
86         //_volumeProperty->SetScalarOpacity(_tfun );
87
88     mVolume = vtkVolume::New();
89            mVolume->SetMapper(mMapper);
90            mVolume->SetProperty(_volumeProperty );
91
92     //  mMapper->ScalarVisibilityOff();
93     //    mMapper->ImmediateModeRenderingOn();
94
95 }
96
97         //---------------------------------------------------------------------
98    void VolumeRenderer::bbUserFinalizeProcessing() 
99    { 
100            if (mRayCastFunction!=NULL)
101            {
102                    mRayCastFunction->Delete();
103                    mRayCastFunction=NULL;
104            }      
105            if (mMapper!=NULL)
106            {
107                    mMapper->Delete();
108                    mMapper=NULL;
109            }      
110            if (mVolume!=NULL)
111            {
112                    mVolume->Delete();
113                    mVolume=NULL;
114            }      
115
116    }
117 //---------------------------------------------------------------------
118
119    void VolumeRenderer::Process()
120    {
121      bool changed = false;
122      if ( bbGetInputStatus("In") != bbtk::UPTODATE )
123        {
124          mMapper->SetInput( bbGetInputIn() );
125          changed = true;
126        }
127
128            if ( ( bbGetInputStatus("ColorFunction") != bbtk::UPTODATE ) &&
129           ( bbGetInputColorFunction() != 0 ) )
130        {
131          mVolume->GetProperty()->SetColor( bbGetInputColorFunction() );
132          changed = true;
133        }
134
135      if ( ( bbGetInputStatus("ColorFunction1") != bbtk::UPTODATE ) &&
136           ( bbGetInputColorFunction1() != 0 ) )
137        {
138          mVolume->GetProperty()->SetColor( bbGetInputColorFunction1() );
139          changed = true;
140        }
141
142      if ( ( bbGetInputStatus("OpacityFunction") != bbtk::UPTODATE ) &&
143           ( bbGetInputOpacityFunction() != 0 ) )
144        {
145          mVolume->GetProperty()->SetScalarOpacity(bbGetInputOpacityFunction());
146          changed = true;
147        }
148     
149      if (changed) mMapper->Update();
150
151          bbSetOutputOut(mVolume);
152            
153    }
154
155 }//namespace bbtk
156
157 #endif // _USE_VTK_
158