-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
511 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ea2b6b5ad1516f65684eff0972a198af873ca1c1 | ||
7ae47ffa119c6feaea43ef021fb48a3056abbec2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
library/VTKExtensions/Rendering/Testing/TestF3DCachedTextures.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <vtkNew.h> | ||
#include <vtkRenderer.h> | ||
|
||
#include "vtkF3DCachedLUTTexture.h" | ||
#include "vtkF3DCachedSpecularTexture.h" | ||
|
||
int TestF3DCachedTextures(int argc, char* argv[]) | ||
{ | ||
vtkNew<vtkF3DCachedLUTTexture> lut; | ||
vtkNew<vtkF3DCachedSpecularTexture> specular; | ||
|
||
lut->Print(cout); | ||
specular->Print(cout); | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
library/VTKExtensions/Rendering/vtkF3DCachedLUTTexture.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "vtkF3DCachedLUTTexture.h" | ||
|
||
#include "vtkImageData.h" | ||
#include "vtkObjectFactory.h" | ||
#include "vtkOpenGLRenderWindow.h" | ||
#include "vtkRenderer.h" | ||
#include "vtkTextureObject.h" | ||
#include "vtkXMLImageDataReader.h" | ||
|
||
#include <vtk_glew.h> | ||
|
||
vtkStandardNewMacro(vtkF3DCachedLUTTexture); | ||
|
||
//------------------------------------------------------------------------------ | ||
void vtkF3DCachedLUTTexture::PrintSelf(ostream& os, vtkIndent indent) | ||
{ | ||
this->Superclass::PrintSelf(os, indent); | ||
os << indent << "FileName: " << this->FileName << endl; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
void vtkF3DCachedLUTTexture::Load(vtkRenderer* ren) | ||
{ | ||
if (this->GetMTime() > this->LoadTime.GetMTime()) | ||
{ | ||
vtkOpenGLRenderWindow* renWin = vtkOpenGLRenderWindow::SafeDownCast(ren->GetRenderWindow()); | ||
|
||
if (this->TextureObject == nullptr) | ||
{ | ||
this->TextureObject = vtkTextureObject::New(); | ||
} | ||
|
||
this->TextureObject->SetContext(renWin); | ||
this->TextureObject->SetFormat(GL_RG); | ||
#ifdef GL_ES_VERSION_3_0 | ||
this->TextureObject->SetInternalFormat(GL_RG8); | ||
this->TextureObject->SetDataType(GL_UNSIGNED_BYTE); | ||
#else | ||
this->TextureObject->SetInternalFormat(GL_RG16); | ||
this->TextureObject->SetDataType(GL_UNSIGNED_SHORT); | ||
#endif | ||
this->TextureObject->SetWrapS(vtkTextureObject::ClampToEdge); | ||
this->TextureObject->SetWrapT(vtkTextureObject::ClampToEdge); | ||
this->TextureObject->SetMinificationFilter(vtkTextureObject::Linear); | ||
this->TextureObject->SetMagnificationFilter(vtkTextureObject::Linear); | ||
|
||
vtkNew<vtkXMLImageDataReader> reader; | ||
reader->SetFileName(this->FileName.c_str()); | ||
reader->Update(); | ||
|
||
vtkImageData* img = reader->GetOutput(); | ||
int dims[3]; | ||
img->GetDimensions(dims); | ||
|
||
#ifdef GL_ES_VERSION_3_0 | ||
this->TextureObject->Create2DFromRaw( | ||
dims[0], dims[1], 2, VTK_UNSIGNED_CHAR, img->GetScalarPointer()); | ||
#else | ||
this->TextureObject->Create2DFromRaw( | ||
dims[0], dims[1], 2, VTK_UNSIGNED_SHORT, img->GetScalarPointer()); | ||
#endif | ||
|
||
this->RenderWindow = renWin; | ||
this->LoadTime.Modified(); | ||
} | ||
|
||
this->TextureObject->Activate(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @class vtkF3DCachedLUTTexture | ||
* @brief create a LUT texture from a vti file | ||
*/ | ||
|
||
#ifndef vtkF3DCachedLUTTexture_h | ||
#define vtkF3DCachedLUTTexture_h | ||
|
||
#include "vtkPBRLUTTexture.h" | ||
|
||
class vtkF3DCachedLUTTexture : public vtkPBRLUTTexture | ||
{ | ||
public: | ||
static vtkF3DCachedLUTTexture* New(); | ||
vtkTypeMacro(vtkF3DCachedLUTTexture, vtkPBRLUTTexture); | ||
void PrintSelf(ostream& os, vtkIndent indent) override; | ||
|
||
///@{ | ||
/** | ||
* Set/Get the image file name. | ||
*/ | ||
vtkGetMacro(FileName, std::string); | ||
vtkSetMacro(FileName, std::string); | ||
///@} | ||
|
||
/** | ||
* Implement base class method. | ||
*/ | ||
void Load(vtkRenderer*) override; | ||
|
||
protected: | ||
vtkF3DCachedLUTTexture() = default; | ||
~vtkF3DCachedLUTTexture() override = default; | ||
|
||
std::string FileName; | ||
|
||
private: | ||
vtkF3DCachedLUTTexture(const vtkF3DCachedLUTTexture&) = delete; | ||
void operator=(const vtkF3DCachedLUTTexture&) = delete; | ||
}; | ||
|
||
#endif |
87 changes: 87 additions & 0 deletions
87
library/VTKExtensions/Rendering/vtkF3DCachedSpecularTexture.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#include "vtkF3DCachedSpecularTexture.h" | ||
|
||
#include "vtkImageData.h" | ||
#include "vtkMultiBlockDataSet.h" | ||
#include "vtkObjectFactory.h" | ||
#include "vtkOpenGLRenderWindow.h" | ||
#include "vtkRenderer.h" | ||
#include "vtkTextureObject.h" | ||
#include "vtkXMLMultiBlockDataReader.h" | ||
|
||
#include <vtk_glew.h> | ||
|
||
vtkStandardNewMacro(vtkF3DCachedSpecularTexture); | ||
|
||
//------------------------------------------------------------------------------ | ||
void vtkF3DCachedSpecularTexture::PrintSelf(ostream& os, vtkIndent indent) | ||
{ | ||
this->Superclass::PrintSelf(os, indent); | ||
os << indent << "FileName: " << this->FileName << endl; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
void vtkF3DCachedSpecularTexture::Load(vtkRenderer* ren) | ||
{ | ||
if (this->GetMTime() > this->LoadTime.GetMTime()) | ||
{ | ||
vtkOpenGLRenderWindow* renWin = vtkOpenGLRenderWindow::SafeDownCast(ren->GetRenderWindow()); | ||
|
||
if (this->TextureObject == nullptr) | ||
{ | ||
this->TextureObject = vtkTextureObject::New(); | ||
} | ||
|
||
this->TextureObject->SetContext(renWin); | ||
this->TextureObject->SetFormat(GL_RGB); | ||
this->TextureObject->SetInternalFormat(GL_RGB32F); | ||
this->TextureObject->SetDataType(GL_FLOAT); | ||
this->TextureObject->SetWrapS(vtkTextureObject::ClampToEdge); | ||
this->TextureObject->SetWrapT(vtkTextureObject::ClampToEdge); | ||
this->TextureObject->SetWrapR(vtkTextureObject::ClampToEdge); | ||
this->TextureObject->SetMinificationFilter(vtkTextureObject::LinearMipmapLinear); | ||
this->TextureObject->SetMagnificationFilter(vtkTextureObject::Linear); | ||
this->TextureObject->SetGenerateMipmap(true); | ||
|
||
this->RenderWindow = renWin; | ||
|
||
vtkNew<vtkXMLMultiBlockDataReader> reader; | ||
reader->SetFileName(this->FileName.c_str()); | ||
reader->Update(); | ||
|
||
vtkMultiBlockDataSet* mb = vtkMultiBlockDataSet::SafeDownCast(reader->GetOutput()); | ||
|
||
unsigned int nbLevels = mb->GetNumberOfBlocks(); | ||
|
||
this->TextureObject->SetMaxLevel(nbLevels - 1); | ||
|
||
vtkImageData* firstImg = vtkImageData::SafeDownCast(mb->GetBlock(0)); | ||
|
||
void* data[6]; | ||
for (int i = 0; i < 6; i++) | ||
{ | ||
data[i] = firstImg->GetScalarPointer(0, 0, i); | ||
} | ||
|
||
int* firstDims = firstImg->GetDimensions(); | ||
this->TextureObject->CreateCubeFromRaw(firstDims[0], firstDims[1], 3, VTK_FLOAT, data); | ||
|
||
// the mip levels are manually uploaded because there is no abstraction in VTK | ||
for (unsigned int i = 1; i < nbLevels; i++) | ||
{ | ||
vtkImageData* img = vtkImageData::SafeDownCast(mb->GetBlock(i)); | ||
int* dims = img->GetDimensions(); | ||
|
||
for (int j = 0; j < 6; j++) | ||
{ | ||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + j, i, | ||
this->TextureObject->GetInternalFormat(VTK_FLOAT, 3, false), dims[0], dims[1], 0, | ||
this->TextureObject->GetFormat(VTK_FLOAT, 3, false), | ||
this->TextureObject->GetDataType(VTK_FLOAT), img->GetScalarPointer(0, 0, j)); | ||
} | ||
} | ||
|
||
this->LoadTime.Modified(); | ||
} | ||
|
||
this->TextureObject->Activate(); | ||
} |
39 changes: 39 additions & 0 deletions
39
library/VTKExtensions/Rendering/vtkF3DCachedSpecularTexture.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @class vtkF3DCachedSpecularTexture | ||
* @brief create a prefiltered specular texture from a vtm file | ||
*/ | ||
|
||
#ifndef vtkF3DCachedSpecularTexture_h | ||
#define vtkF3DCachedSpecularTexture_h | ||
|
||
#include "vtkPBRPrefilterTexture.h" | ||
|
||
class vtkF3DCachedSpecularTexture : public vtkPBRPrefilterTexture | ||
{ | ||
public: | ||
static vtkF3DCachedSpecularTexture* New(); | ||
vtkTypeMacro(vtkF3DCachedSpecularTexture, vtkPBRPrefilterTexture); | ||
void PrintSelf(ostream& os, vtkIndent indent) override; | ||
|
||
/** | ||
* Set the image file name. | ||
*/ | ||
vtkSetMacro(FileName, std::string); | ||
|
||
/** | ||
* Implement base class method. | ||
*/ | ||
void Load(vtkRenderer*) override; | ||
|
||
protected: | ||
vtkF3DCachedSpecularTexture() = default; | ||
~vtkF3DCachedSpecularTexture() override = default; | ||
|
||
std::string FileName; | ||
|
||
private: | ||
vtkF3DCachedSpecularTexture(const vtkF3DCachedSpecularTexture&) = delete; | ||
void operator=(const vtkF3DCachedSpecularTexture&) = delete; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.