1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkOpenGLVolumeTransferFunction2D.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10   This software is distributed WITHOUT ANY WARRANTY; without even
11   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12   PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
16 #include "vtkOpenGLVolumeTransferFunction2D.h"
17 
18 #include "vtkDataArray.h"
19 #include "vtkImageData.h"
20 #include "vtkImageResize.h"
21 #include "vtkObjectFactory.h"
22 #include "vtkOpenGLRenderWindow.h"
23 #include "vtkPointData.h"
24 #include "vtkTextureObject.h"
25 
26 vtkStandardNewMacro(vtkOpenGLVolumeTransferFunction2D);
27 
28 //------------------------------------------------------------------------------
vtkOpenGLVolumeTransferFunction2D()29 vtkOpenGLVolumeTransferFunction2D::vtkOpenGLVolumeTransferFunction2D()
30 {
31   this->NumberOfColorComponents = 4;
32 }
33 
34 //------------------------------------------------------------------------------
InternalUpdate(vtkObject * func,int vtkNotUsed (blendMode),double vtkNotUsed (sampleDistance),double vtkNotUsed (unitDistance),int filterValue)35 void vtkOpenGLVolumeTransferFunction2D::InternalUpdate(vtkObject* func, int vtkNotUsed(blendMode),
36   double vtkNotUsed(sampleDistance), double vtkNotUsed(unitDistance), int filterValue)
37 {
38   vtkImageData* transfer2D = vtkImageData::SafeDownCast(func);
39   if (!transfer2D)
40   {
41     return;
42   }
43   int* dims = transfer2D->GetDimensions();
44   // Resample if there is a size restriction
45   void* data = transfer2D->GetPointData()->GetScalars()->GetVoidPointer(0);
46   if (dims[0] != this->TextureWidth || dims[1] != this->TextureHeight)
47   {
48     this->ResizeFilter->SetInputData(transfer2D);
49     this->ResizeFilter->SetResizeMethodToOutputDimensions();
50     this->ResizeFilter->SetOutputDimensions(this->TextureWidth, this->TextureHeight, 1);
51     this->ResizeFilter->Update();
52     data = this->ResizeFilter->GetOutput()->GetPointData()->GetScalars()->GetVoidPointer(0);
53   }
54 
55   this->TextureObject->SetWrapS(vtkTextureObject::ClampToEdge);
56   this->TextureObject->SetWrapT(vtkTextureObject::ClampToEdge);
57   this->TextureObject->SetMagnificationFilter(filterValue);
58   this->TextureObject->SetMinificationFilter(filterValue);
59   this->TextureObject->Create2DFromRaw(
60     this->TextureWidth, this->TextureHeight, this->NumberOfColorComponents, VTK_FLOAT, data);
61 }
62 
63 //------------------------------------------------------------------------------
NeedsUpdate(vtkObject * func,double[2]vtkNotUsed (scalarRange),int vtkNotUsed (blendMode),double vtkNotUsed (sampleDistance))64 bool vtkOpenGLVolumeTransferFunction2D::NeedsUpdate(vtkObject* func,
65   double[2] vtkNotUsed(scalarRange), int vtkNotUsed(blendMode), double vtkNotUsed(sampleDistance))
66 {
67   if (!func)
68   {
69     return false;
70   }
71   if (func->GetMTime() > this->BuildTime || this->TextureObject->GetMTime() > this->BuildTime ||
72     !this->TextureObject->GetHandle())
73   {
74     return true;
75   }
76   return false;
77 }
78 
79 //------------------------------------------------------------------------------
AllocateTable()80 void vtkOpenGLVolumeTransferFunction2D::AllocateTable() {}
81 
82 //------------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)83 void vtkOpenGLVolumeTransferFunction2D::PrintSelf(ostream& os, vtkIndent indent)
84 {
85   this->Superclass::PrintSelf(os, indent);
86 }
87