]> Creatis software - creaMaracasVisu.git/blobdiff - lib/Kernel/VTKObjects/VolumeRenderer/volumerenderermanagerdata.cxx
2108 Bug Volume Rendering widget options are not stable
[creaMaracasVisu.git] / lib / Kernel / VTKObjects / VolumeRenderer / volumerenderermanagerdata.cxx
index 97527c12a3b1b64963794aad3ee65bb7c65afc82..00d115b0bc25ab3b531f42af412fb8dd40c615e2 100644 (file)
 
 #include <vtkVolumeRayCastMapper.h>
 
-#if VTK_MAJOR_VERSION >= 5
-    #if VTK_MINOR_VERSION >= 6
-        #include "vtkGPUVolumeRayCastMapper.h"
-    #endif
+// EED This is code for Juan Carlos Prieto TESTES
+//#if VTK_MAJOR_VERSION >= 5
+//    #if VTK_MINOR_VERSION >= 6
+//        #include "vtkGPUVolumeRayCastMapper.h"
+//    #endif
+//#endif
+
+#if VTK_MAJOR_VERSION >= 6
+        #include "vtkSmartVolumeMapper.h"
 #endif
 
+
+
 using namespace std;
 
 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, bool usegpu){
@@ -71,11 +78,11 @@ void VolumeRendererManagerData::Initialize(vtkImageData* vol, std::string datana
 
     _volumeProperty = vtkVolumeProperty::New();
     _volumeProperty->SetInterpolationTypeToLinear();
-    _volumeProperty->ShadeOn();
+    _volumeProperty->ShadeOff();
     _volumeProperty->SetAmbient(3);
     _volumeProperty->SetDiffuse(0.2);
     _volumeProperty->SetSpecular(0.5);
-    //_volumeProperty->DisableGradientOpacityOn();
+    _volumeProperty->DisableGradientOpacityOn();
     _tfun = vtkPiecewiseFunction::New();    
     _volumeProperty->SetScalarOpacity(_tfun );
     _ctfun = vtkColorTransferFunction::New();
@@ -123,37 +130,48 @@ void VolumeRendererManagerData::Initialize(vtkImageData* vol, std::string datana
     }
 */
 
-       VolumeMapper = 0;
-#if VTK_MAJOR_VERSION >= 5
-    #if VTK_MINOR_VERSION >= 6
-       cout<<"using volume render GPU"<<endl;
-       vtkGPUVolumeRayCastMapper * volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
-       volumeMappergpu->AutoAdjustSampleDistancesOn();       
-       VolumeMapper = volumeMappergpu;
-    #endif
+       VolumeMapper = NULL;
+
+// EED This is code for Juan Carlos Prieto TESTES
+//#if VTK_MAJOR_VERSION >= 5
+//    #if VTK_MINOR_VERSION >= 6
+//       cout<<"using volume render GPU"<<endl;
+//       vtkGPUVolumeRayCastMapper * volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
+//       volumeMappergpu->AutoAdjustSampleDistancesOn();
+//       VolumeMapper = volumeMappergpu;
+//    #endif
+//#else
+//       _compositeFunction                                            = vtkVolumeRayCastCompositeFunction::New();
+//       _MIPFunction                                                  = vtkVolumeRayCastMIPFunction::New();
+//       vtkVolumeRayCastMapper* volumeMapper                          = vtkVolumeRayCastMapper::New();
+//       volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
+//       volumeMapper->AutoAdjustSampleDistancesOn();
+//       VolumeMapper                                                  = volumeMapper;
+//#endif
+
+#if VTK_MAJOR_VERSION >= 6
+       cout<<"using SmartVolumeRenderingMapper render GPU"<<endl;
+       vtkSmartVolumeMapper * smartvolumemapper                        = vtkSmartVolumeMapper::New();
+       VolumeMapper                                                    = smartvolumemapper;
+       smartvolumemapper->AutoAdjustSampleDistancesOn();
 #else
-
-
-       _compositeFunction                                                              = vtkVolumeRayCastCompositeFunction::New();
-       _MIPFunction                                                                    = vtkVolumeRayCastMIPFunction::New();
-       vtkVolumeRayCastMapper* volumeMapper                                                                    = vtkVolumeRayCastMapper::New();
+       _compositeFunction                                              = vtkVolumeRayCastCompositeFunction::New();
+       _MIPFunction                                                    = vtkVolumeRayCastMIPFunction::New();
+       vtkVolumeRayCastMapper* volumeMapper                            = vtkVolumeRayCastMapper::New();
+       VolumeMapper                                                    = volumeMapper;
        volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
-               volumeMapper->AutoAdjustSampleDistancesOn();
-               VolumeMapper                                                                    = volumeMapper;
+       volumeMapper->AutoAdjustSampleDistancesOn();
 #endif
-
-
-        VolumeMapper->SetClippingPlanes( _volumePlanes );
-        _newvol->SetMapper(VolumeMapper );
-        VolumeMapper->SetInput( _vol );
-        VolumeMapper->Update();
-    _newvol->Update();
+       VolumeMapper->SetClippingPlanes( _volumePlanes );
+       _newvol->SetMapper(VolumeMapper );
+       VolumeMapper->SetInput( _vol );
+       VolumeMapper->Update();
+       _newvol->Update();
 }
 
 
 VolumeRendererManagerData::~VolumeRendererManagerData()
 {
-
         _tfun->Delete();
         _ctfun->Delete();
         _volumePlanes->Delete();
@@ -170,22 +188,26 @@ VolumeRendererManagerData::~VolumeRendererManagerData()
         if(BoxWidget){
             DisableBoundingBox();
         }
-
 }
-void VolumeRendererManagerData::SetIndependentComponents(bool independent){
 
-    if(independent){
+
+void VolumeRendererManagerData::SetIndependentComponents(bool independent)
+{
+    if(independent)
+    {
         _volumeProperty->IndependentComponentsOn();
     }else{
         _volumeProperty->IndependentComponentsOff();
     }
 }
 
+
 void VolumeRendererManagerData::EnableBoundingBox(vtkRenderWindowInteractor* interactor)
 {
 //EED9Juin2011    if(_volumeMappergpu){
 
-    if(!BoxWidget){
+    if(!BoxWidget)
+    {
         BoxWidget = vtkBoxWidget::New();
         BoxWidget->SetInteractor( interactor );
         BoxWidget->SetPlaceFactor(1.01);
@@ -219,16 +241,14 @@ void VolumeRendererManagerData::EnableBoundingBox(vtkRenderWindowInteractor* int
 //EED9Juin2011  }
 }
 
-void VolumeRendererManagerData::DisableBoundingBox(){
-
-    if(BoxWidget){
+void VolumeRendererManagerData::DisableBoundingBox()
+{
+    if(BoxWidget)
+    {
         BoxWidget->EnabledOff();
         //BoxWidget->Delete();
         //BoxWidget = 0;
-
         cout<<"JPRG::VolumeRendererManagerData::DisableBoundingBox"<<endl;
-
-
     }
 }
 
@@ -249,19 +269,23 @@ void VolumeRendererManagerData::setVolumeColor(std::vector<double>& greylevelcol
         _newvol->Update();
 }
 
+
+
 /**
 **     Volume Opacity
 **/
-void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value){
-
+void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value)
+{
         _tfun->RemoveAllPoints();
-        for(unsigned int i = 0; i < greylevel.size();i++){
+        for(unsigned int i = 0; i < greylevel.size();i++)
+        {
                 _tfun->AddPoint(greylevel[i], value[i]);
                 //std::cout<<"VolumeRendererManagerData::setVolumeOpacity "<<greylevel[i]<<" "<< value[i]<<std::endl;
-        }
+        } // for i
     _newvol->Update();
 }
 
+
 /**
 **     Volume Opacity
 **/
@@ -273,6 +297,7 @@ void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,d
     setVolumeOpacity(greylevel, valuevector);
 }
 
+
 /**
 **     Check if the variables are setted correctly
 **/
@@ -288,50 +313,67 @@ void VolumeRendererManagerData::checkInvariant()throw (char *){
         }
 }
 
+
 /**
 **     Check if the variables are setted correctly
 **/
-void VolumeRendererManagerData::Update(){
+void VolumeRendererManagerData::Update()
+{
          _newvol->Update();
 }
+
+
 /**
 **     get the prop3D
 **/
-vtkProp3D* VolumeRendererManagerData::getProp3D(){
+vtkProp3D* VolumeRendererManagerData::getProp3D()
+{
         return this->_newvol;
 }
+
 /**
 **     return the id from the daat
 **/
-int VolumeRendererManagerData::getId(){
+int VolumeRendererManagerData::getId()
+{
         return _id;
 }
+
+
 /**
 **     set data id
 **/
-void VolumeRendererManagerData::setId(int propid){
+void VolumeRendererManagerData::setId(int propid)
+{
         _id = propid;
 }
 
+
 /**
 **     Get the filanme
 **/
-std::string VolumeRendererManagerData::getDataname(){
+std::string VolumeRendererManagerData::getDataname()
+{
         return _dataname;
 }
+
+
 /**
 ** Set the filanme
 **/
-void VolumeRendererManagerData::setDataname(std::string dataname){
+void VolumeRendererManagerData::setDataname(std::string dataname)
+{
         _dataname = dataname;
 }
 
-void VolumeRendererManagerData::changeCompositeMIPFunction(int function){
+
+void VolumeRendererManagerData::changeCompositeMIPFunction(int function)
+{
         //checkInvariant();
-        if(VolumeMapper){
-#if VTK_MAJOR_VERSION >= 5
-    #if VTK_MINOR_VERSION >= 6
-            if(dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper)){
+        if(VolumeMapper!=NULL){
+#if VTK_MAJOR_VERSION >= 6
+           if(dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper))
+           {
                 vtkVolumeRayCastMapper* volumemapper = dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper);
                 if(function == 0){
                         volumemapper->SetVolumeRayCastFunction(_compositeFunction);
@@ -348,9 +390,8 @@ void VolumeRendererManagerData::changeCompositeMIPFunction(int function){
                     volumemapper->SetBlendModeToMinimumIntensity();
                 }
             }
-    #endif
 #else
-            vtkGPUVolumeRayCastMapper* volumemapper = dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper);
+            vtkVolumeRayCastMapper* volumemapper = dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper);
             if(function == 0){
                 volumemapper->SetBlendModeToComposite();
             }else if(function == 1){
@@ -363,7 +404,8 @@ void VolumeRendererManagerData::changeCompositeMIPFunction(int function){
 
 }
 
-void VolumeRendererManagerData::SetLookupTable(vtkLookupTable* lookuptable){
+void VolumeRendererManagerData::SetLookupTable(vtkLookupTable* lookuptable)
+{
     if(lookuptable){
          _ctfun->RemoveAllPoints();
          vtkColorTransferFunction* colort = (vtkColorTransferFunction*)lookuptable;
@@ -378,7 +420,8 @@ void VolumeRendererManagerData::SetLookupTable(vtkLookupTable* lookuptable){
 
 }
 
-void VolumeRendererManagerData::changeInterpolationType(int type){
+void VolumeRendererManagerData::changeInterpolationType(int type)
+{
     //checkInvariant();
     if(type == 0){
         _volumeProperty->SetInterpolationTypeToLinear();