Commit f7106e4f authored by Bill Lorensen's avatar Bill Lorensen
Browse files

ENH: Modernize RIBExporter and RIBProperty

The original RIB classes were created to work with BMRT, a free
Renderman implementation written by Larry Gritz.

This patch updates the RIB classes to conform to the latest Renderman
RIB syntax. Motivated by the Pixar release of a no cost Renderman:
http://renderman.pixar.com/view/renderman

Adds two new tests:

TestRIBExporter generates a valid rib file that should work with
Renderman. This is meant to be a regression test for a Renderman
rendered image.

UnitTestRIB attempts to cover all of the RIB code including errors and
warnings.

If Renderman is detected on the system, the RIB file generated by
TestRIBExporter is processed and the resulting image is checked for
changes from a baseline.
parent efe387d5
......@@ -14,17 +14,66 @@ if(VTK_GHOSTSCRIPT_EXECUTABLE AND (VTK_RENDERING_BACKEND STREQUAL "OpenGL"))
TestGL2PSLabeledDataMapper.cxx
TestLinePlotGL2PS.cxx
TestStackedPlotGL2PS.cxx
)
)
endif()
vtk_add_test_cxx(${vtk-module}CxxTests tests
X3DTest.cxx,NO_DATA,NO_VALID
${GL2PSTests}
TestRIBExporter.cxx,NO_VALID
UnitTestRIB.cxx,NO_DATA,NO_VALID
)
vtk_test_cxx_executable(${vtk-module}CxxTests tests
RENDERING_FACTORY
)
# See if Pixar's Renderman is available
find_path(RMANTREE bin/prman HINTS
/Applications/Pixar/RenderManProServer-19.0
/opt/pixar/RenderManProServer-19.0
)
# Tests to run if Renderman is present
if(RMANTREE)
# write a Renderman ini file to specify the shaderpath
write_file(${${vtk-module}_BINARY_DIR}/Testing/Cxx/rendermn.ini
"/shaderpath &:${${vtk-module}_SOURCE_DIR}/Testing/Cxx")
add_test(NAME ${vtk-module}-RIBExporterShaderCompile
COMMAND ${RMANTREE}/bin/shader
${${vtk-module}_SOURCE_DIR}/Testing/Data/Input/bozo.sl
${${vtk-module}_SOURCE_DIR}/Testing/Data/Input/dented.sl
WORKING_DIRECTORY ${${vtk-module}_BINARY_DIR}/Testing/Cxx
)
add_test(NAME ${vtk-module}-RIBExporterPrman
COMMAND ${RMANTREE}/bin/prman
${VTK_TEST_OUTPUT_DIR}/TestRIBExporter.rib
WORKING_DIRECTORY ${${vtk-module}_BINARY_DIR}/Testing/Cxx
)
# Image diff rman generated tif with baseline
set(baseline_dir ${${vtk-module}_SOURCE_DIR}/Testing/Data/Baseline)
ExternalData_add_test(VTKData
NAME ${vtk-module}Cxx-ComparePrmanImage
COMMAND ${RMANTREE}/bin/cmptiff -d 100
DATA{${baseline_dir}/TestRIBExporter.tif}
${VTK_TEST_OUTPUT_DIR}/TestRIBExporter.tif
)
set_tests_properties(${vtk-module}-RIBExporterPrman
PROPERTIES
DEPENDS
"${vtk-module}-TestRIBExporter"
DEPENDS
"${vtk-module}-RIBExporterShaderCompile"
ENVIRONMENT
"RMANTREE=${RMANTREE}"
)
set_tests_properties("${vtk-module}Cxx-ComparePrmanImage"
PROPERTIES
DEPENDS "${vtk-module}Cxx-TestRIBExporter"
REQUIRED_FILES
"${VTK_TEST_OUTPUT_DIR}/TestRIBExporter.tif"
)
endif()
# The GL2PS tests produce postscript output, which cannot be compared using
# the built-in image regression framework. The tests added above will create the
# postscript, while the following tests will convert the postscript to a PNG and
......
/*=========================================================================
Program: Visualization Toolkit
Module: UnitTestRIB.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkSmartPointer.h"
#include "vtkTestUtilities.h"
#include "vtkNamedColors.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkTexture.h"
#include "vtkPNMReader.h"
#include "vtkSphereSource.h"
#include "vtkTexturedSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkRIBExporter.h"
#include "vtkRIBProperty.h"
static vtkSmartPointer<vtkRIBProperty> cloth(const char *freq,
const char *depth);
static vtkSmartPointer<vtkRIBProperty> dented(const char *Km);
static vtkSmartPointer<vtkRIBProperty> stippled(const char *grainsize,
const char *stippling);
static vtkSmartPointer<vtkRIBProperty> spatter(const char *sizes,
const char *specksize,
const char *spattercolor,
const char *basecolor);
static vtkSmartPointer<vtkRIBProperty> cmarble(const char *veining);
static vtkSmartPointer<vtkRIBProperty> stone(const char *scale,
const char *nshades,
const char *exponent,
const char *graincolor);
static vtkSmartPointer<vtkRIBProperty> wood(const char *grain,
const char *swirl,
const char *swirlfreq);
static vtkSmartPointer<vtkRIBProperty> bozo(const char *k);
int TestRIBExporter (int argc, char *argv[])
{
std::string prefix = vtkTestUtilities::GetArgOrEnvOrDefault(
"-T", argc, argv, "VTK_TEMP_DIR", "Testing/Temporary");
if (prefix == "")
{
std::cout << argv[0] << " Could not determine temporary directory.\n";
return EXIT_FAILURE;
}
prefix += "/TestRIBExporter";
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New ();
vtkSmartPointer<vtkRenderer> ren1 =
vtkSmartPointer<vtkRenderer>::New ();
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New ();
char *textureFile = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/earth.ppm");
vtkSmartPointer<vtkPNMReader> textureReader =
vtkSmartPointer<vtkPNMReader>::New ();
textureReader->SetFileName(textureFile);
delete []textureFile;
vtkSmartPointer<vtkTexturedSphereSource> texturedSphere =
vtkSmartPointer<vtkTexturedSphereSource>::New ();
texturedSphere->SetPhiResolution(20);
texturedSphere->SetThetaResolution(20);
vtkSmartPointer<vtkTexture> texture =
vtkSmartPointer<vtkTexture>::New ();
texture->SetInputConnection(textureReader->GetOutputPort());
vtkSmartPointer<vtkPolyDataMapper> texturedSphereMapper =
vtkSmartPointer<vtkPolyDataMapper>::New ();
texturedSphereMapper->SetInputConnection(texturedSphere->GetOutputPort());
vtkSmartPointer<vtkSphereSource> sphere =
vtkSmartPointer<vtkSphereSource>::New ();
sphere->SetPhiResolution(20);
sphere->SetThetaResolution(20);
vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
vtkSmartPointer<vtkPolyDataMapper>::New ();
sphereMapper->SetInputConnection(sphere->GetOutputPort());
vtkSmartPointer<vtkActor> sphere1 =
vtkSmartPointer<vtkActor>::New ();
sphere1->SetMapper(sphereMapper);
sphere1->SetPosition( -1.5, 1.5, 0);
vtkSmartPointer<vtkActor> sphere2 =
vtkSmartPointer<vtkActor>::New ();
sphere2->SetMapper(sphereMapper);
sphere2->SetPosition( 0, 1.5, 0);
vtkSmartPointer<vtkActor> sphere3 =
vtkSmartPointer<vtkActor>::New ();
sphere3->SetMapper(sphereMapper);
sphere3->SetPosition(1.5, 1.5, 0);
vtkSmartPointer<vtkActor> sphere4 =
vtkSmartPointer<vtkActor>::New ();
sphere4->SetMapper(sphereMapper);
sphere4->SetPosition(-1.5, 0, 0);
vtkSmartPointer<vtkActor> sphere5 =
vtkSmartPointer<vtkActor>::New ();
sphere5->SetMapper(sphereMapper);
sphere5->SetPosition(0, 0, 0);
vtkSmartPointer<vtkActor> sphere6 =
vtkSmartPointer<vtkActor>::New ();
sphere6->SetMapper(sphereMapper);
sphere6->SetPosition(1.5, 0, 0);
vtkSmartPointer<vtkActor> sphere7 =
vtkSmartPointer<vtkActor>::New ();
sphere7->SetMapper(sphereMapper);
sphere7->SetPosition(-1.5, -1.5, 0);
vtkSmartPointer<vtkActor> sphere8 =
vtkSmartPointer<vtkActor>::New ();
sphere8->SetMapper(sphereMapper);
sphere8->SetPosition(0, -1.5, 0);
vtkSmartPointer<vtkActor> sphere9 =
vtkSmartPointer<vtkActor>::New ();
sphere9->SetMapper(texturedSphereMapper);
sphere9->SetTexture(texture);
sphere9->SetPosition(1.5,-1.5, 0);
sphere9->SetOrientation(90, 0, 0);
renWin->AddRenderer(ren1);
iren->SetRenderWindow(renWin);
ren1->AddActor(sphere1);
ren1->AddActor(sphere2);
ren1->AddActor(sphere3);
ren1->AddActor(sphere4);
ren1->AddActor(sphere5);
ren1->AddActor(sphere6);
ren1->AddActor(sphere7);
ren1->AddActor(sphere8);
ren1->AddActor(sphere9);
ren1->SetBackground(0.10, 0.2, 0.4);
renWin->SetSize(640, 480);
vtkSmartPointer<vtkNamedColors> colors =
vtkSmartPointer<vtkNamedColors>::New();
double color[4];
sphere1->SetProperty(cloth("500", ".02"));
colors->GetColor("gold", color);
sphere1->GetProperty()->SetDiffuseColor(color);
sphere2->SetProperty(stippled(".1", "1"));
colors->GetColor("ivory", color);
sphere2->GetProperty()->SetDiffuseColor(color);
sphere3->SetProperty(spatter("5", ".5", "0 0 0", "1 1 1"));
sphere4->SetProperty(cmarble("4"));
sphere5->SetProperty(stone(".07", "2", "2", ".2 .3 .4"));
sphere6->SetProperty(wood("5", ".25", "1"));
sphere7->SetProperty(bozo("5"));
sphere8->SetProperty(dented("5"));
colors->GetColor("tomato", color);
sphere8->GetProperty()->SetDiffuse(.7);
sphere8->GetProperty()->SetDiffuseColor(color);
sphere8->GetProperty()->SetSpecular(.5);
sphere8->GetProperty()->SetSpecularPower(5);
vtkCamera *cam1 = ren1->GetActiveCamera();
ren1->ResetCamera();
cam1->Zoom(1.5);
renWin->Render();
vtkSmartPointer<vtkRIBExporter> aRib =
vtkSmartPointer<vtkRIBExporter>::New ();
aRib->SetInput(renWin);
aRib->SetFilePrefix(prefix.c_str());
aRib->SetTexturePrefix(prefix.c_str());
aRib->BackgroundOn();
aRib->Write();
return EXIT_SUCCESS;
}
vtkSmartPointer<vtkRIBProperty> cloth(const char *freq, const char *depth)
{
vtkSmartPointer<vtkRIBProperty> clothProp =
vtkSmartPointer<vtkRIBProperty>::New ();
clothProp->SetVariable("freq", "float");
clothProp->AddVariable("depth", "float");
clothProp->SetDisplacementShaderParameter("freq", freq);
clothProp->AddDisplacementShaderParameter("depth", depth);
clothProp->SetDisplacementShader("cloth");
return clothProp;
}
vtkSmartPointer<vtkRIBProperty> dented(const char *Km)
{
vtkSmartPointer<vtkRIBProperty> dentedProp =
vtkSmartPointer<vtkRIBProperty>::New ();
dentedProp->SetVariable("Km", "float");
dentedProp->SetDisplacementShaderParameter("Km", Km);
dentedProp->SetDisplacementShader("dented");
return dentedProp;
}
vtkSmartPointer<vtkRIBProperty> stippled(const char *grainsize, const char *stippling)
{
vtkSmartPointer<vtkRIBProperty> stippledProp =
vtkSmartPointer<vtkRIBProperty>::New ();
stippledProp->SetVariable("grainsize", "float");
stippledProp->AddVariable("stippling", "float");
stippledProp->SetSurfaceShaderParameter("grainsize", grainsize);
stippledProp->AddSurfaceShaderParameter("stippling", stippling);
stippledProp->SetSurfaceShader("stippled");
return stippledProp;
}
vtkSmartPointer<vtkRIBProperty> bozo(const char *k)
{
vtkSmartPointer<vtkRIBProperty> bozoProp =
vtkSmartPointer<vtkRIBProperty>::New ();
bozoProp->SetSurfaceShader("bozo");
bozoProp->SetVariable("k", "float");
bozoProp->SetSurfaceShaderParameter("k", k);
return bozoProp;
}
vtkSmartPointer<vtkRIBProperty> spatter(const char *sizes,
const char *specksize,
const char *spattercolor,
const char *basecolor)
{
vtkSmartPointer<vtkRIBProperty> spatterProp =
vtkSmartPointer<vtkRIBProperty>::New ();
spatterProp->SetVariable("sizes", "float");
spatterProp->AddVariable("specksize", "float");
spatterProp->AddVariable("spattercolor", "color");
spatterProp->AddVariable("basecolor", "color");
spatterProp->SetSurfaceShaderParameter("sizes", sizes);
spatterProp->AddSurfaceShaderParameter("specksize", specksize);
spatterProp->AddSurfaceShaderParameter("spattercolor", spattercolor);
spatterProp->AddSurfaceShaderParameter("basecolor", basecolor);
spatterProp->SetSurfaceShader("spatter");
return spatterProp;
}
vtkSmartPointer<vtkRIBProperty> cmarble(const char *veining)
{
vtkSmartPointer<vtkRIBProperty> cmarbleProp =
vtkSmartPointer<vtkRIBProperty>::New ();
cmarbleProp->SetVariable("veining", "float");
cmarbleProp->SetSurfaceShaderParameter("veining", veining);
cmarbleProp->SetSurfaceShader("cmarble");
return cmarbleProp;
}
vtkSmartPointer<vtkRIBProperty> stone(const char *scale,
const char *nshades,
const char *exponent,
const char *graincolor)
{
vtkSmartPointer<vtkRIBProperty> stoneProp =
vtkSmartPointer<vtkRIBProperty>::New ();
stoneProp->SetVariable("scale", "float");
stoneProp->AddVariable("nshades", "float");
stoneProp->AddVariable("exponent", "float");
stoneProp->AddVariable("graincolor", "color");
stoneProp->SetSurfaceShaderParameter("scale", scale);
stoneProp->AddSurfaceShaderParameter("nshades", nshades);
stoneProp->AddSurfaceShaderParameter("exponent", exponent);
stoneProp->AddSurfaceShaderParameter("graincolor", graincolor);
stoneProp->SetSurfaceShader("stone");
return stoneProp;
}
vtkSmartPointer<vtkRIBProperty> wood(const char *grain,
const char *swirl,
const char *swirlfreq)
{
vtkSmartPointer<vtkRIBProperty> woodProp =
vtkSmartPointer<vtkRIBProperty>::New ();
woodProp->SetVariable("grain", "float");
woodProp->AddVariable("swirl", "float");
woodProp->AddVariable("swirlfreq", "float");
woodProp->SetSurfaceShaderParameter("grain", grain);
woodProp->AddSurfaceShaderParameter("swirl", swirl);
woodProp->AddSurfaceShaderParameter("swirlfreq", swirlfreq);
woodProp->SetSurfaceShader("wood");
return woodProp;
}
/*=========================================================================
Program: Visualization Toolkit
Module: UnitTestRIB.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkSmartPointer.h"
#include "vtkRIBProperty.h"
#include "vtkRIBLight.h"
#include "vtkRIBExporter.h"
#include "vtkProperty.h"
#include "vtkTestUtilities.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include "vtkStripper.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkTestErrorObserver.h"
#include <sstream>
#define CHECK_ERROR_MSG(msg) \
{ \
std::string expectedMsg(msg); \
if (!errorObserver->GetError()) \
{ \
std::cout << "Failed to catch any error. Expected the error message to contain \"" << expectedMsg << "\"" << std::endl; \
status++; \
} \
else \
{ \
std::string gotMsg(errorObserver->GetErrorMessage()); \
if (gotMsg.find(expectedMsg) == std::string::npos) \
{ \
std::cout << "Error message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \
status++; \
} \
} \
} \
errorObserver->Clear()
#define CHECK_WARNING_MSG(msg) \
{ \
std::string expectedMsg(msg); \
if (!warningObserver->GetWarning()) \
{ \
std::cout << "Failed to catch any warning. Expected the warning message to contain \"" << expectedMsg << "\"" << std::endl; \
status++; \
} \
else \
{ \
std::string gotMsg(warningObserver->GetWarningMessage()); \
if (gotMsg.find(expectedMsg) == std::string::npos) \
{ \
std::cout << "Warning message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \
status++; \
} \
} \
} \
warningObserver->Clear()
#define TEST_SET_GET_VALUE( variable, command ) \
if( variable != command ) \
{ \
std::cout << "Error in " << #command << std::endl; \
std::cout << " In " __FILE__ ", line " << __LINE__ << std::endl; \
std::cout << "Expected |" << variable << "|" << std::endl; \
std::cout << "but got |" << command << "|" << std::endl; \
status += 1; \
}
static int TestRIBProperty();
static int TestRIBLight();
static int TestRIBExporter();
int UnitTestRIB (int, char *[])
{
int status = 0;
status += TestRIBProperty();
status += TestRIBLight();
status += TestRIBExporter();
if (status != 0)
{
return EXIT_FAILURE;
}
else
{
return EXIT_SUCCESS;
}
}
int TestRIBProperty()
{
int status = 0;
{
std::cout << "RIBProperty empty Print..";
std::ostringstream propPrint;
vtkSmartPointer<vtkRIBProperty> prop =
vtkSmartPointer<vtkRIBProperty>::New();
prop->Print(propPrint);
std::cout << ".PASSED" << std::endl;
}
{
std::cout << "RIBProperty Set/Get..";
vtkSmartPointer<vtkRIBProperty> prop =
vtkSmartPointer<vtkRIBProperty>::New();
prop->SetSurfaceShader("surfaceshader");
TEST_SET_GET_VALUE(std::string("surfaceshader"),
std::string(prop->GetSurfaceShader()));
prop->SetDisplacementShader("displacementshader");
TEST_SET_GET_VALUE(std::string("displacementshader"),
std::string(prop->GetDisplacementShader()));
prop->SetVariable("floatVar", "float");
TEST_SET_GET_VALUE(std::string("Declare \"floatVar\" \"float\"\n"),
std::string(prop->GetDeclarations()));
prop->AddVariable("colorVar", "color");
TEST_SET_GET_VALUE(std::string(
"Declare \"floatVar\" \"float\"\n"
"Declare \"colorVar\" \"color\"\n"),
std::string(prop->GetDeclarations()));
prop->SetVariable("vectorVar", "vector");
TEST_SET_GET_VALUE(std::string("Declare \"vectorVar\" \"vector\"\n"),
std::string(prop->GetDeclarations()));
prop->SetSurfaceShaderParameter("floatVar", "5.678");
TEST_SET_GET_VALUE(std::string(
" \"floatVar\" [5.678]"),
std::string(prop->GetSurfaceShaderParameters()));
prop->SetSurfaceShaderParameter("floatVar", "1.234");
prop->AddSurfaceShaderParameter("colorVar", "1 .5 .1");
TEST_SET_GET_VALUE(std::string(
" \"floatVar\" [1.234] \"colorVar\" [1 .5 .1]"),
std::string(prop->GetSurfaceShaderParameters()));
prop->SetDisplacementShaderParameter("floatVar", "5.678");
TEST_SET_GET_VALUE(std::string(
" \"floatVar\" [5.678]"),
std::string(prop->GetDisplacementShaderParameters()));
prop->SetDisplacementShaderParameter("floatVar", "1.234");
prop->AddDisplacementShaderParameter("colorVar", "1 .5 .1");
TEST_SET_GET_VALUE(std::string(
" \"floatVar\" [1.234] \"colorVar\" [1 .5 .1]"),
std::string(prop->GetDisplacementShaderParameters()));
prop->SurfaceShaderUsesDefaultParametersOn();
TEST_SET_GET_VALUE(1,
prop->GetSurfaceShaderUsesDefaultParameters());
prop->SurfaceShaderUsesDefaultParametersOff();
TEST_SET_GET_VALUE(0,
prop->GetSurfaceShaderUsesDefaultParameters());
std::cout << ".PASSED" << std::endl;
std::cout << "RIBProperty Print..";
std::ostringstream propPrint;
prop->Print(propPrint);
std::cout << ".PASSED" << std::endl;
}
{
std::cout << "RIBProperty Deprecated Set/Get..";
vtkSmartPointer<vtkRIBProperty> prop =
vtkSmartPointer<vtkRIBProperty>::New();
vtkSmartPointer<vtkTest::ErrorObserver> warningObserver =
vtkSmartPointer<vtkTest::ErrorObserver>::New();
prop->AddObserver(vtkCommand::WarningEvent, warningObserver);
prop->SetParameter("floatVar", "5.678");
CHECK_WARNING_MSG("SetParameter is deprecated");
TEST_SET_GET_VALUE(std::string(
" \"floatVar\" [5.678]"),
std::string(prop->GetParameters()));
CHECK_WARNING_MSG("GetParameters is deprecated");
prop->AddParameter("colorVar", "1 .5 .1");
CHECK_WARNING_MSG("AddParameter is deprecated");
TEST_SET_GET_VALUE(std::string(
" \"floatVar\" [5.678] \"colorVar\" [1 .5 .1]"),
std::string(prop->GetSurfaceShaderParameters()));
std::cout << ".PASSED" << std::endl;
}
return status;
}
int TestRIBLight()
{
int status = 0;
{
std::cout << "RIBLight empty Print..";
std::ostringstream lightPrint;
vtkSmartPointer<vtkRIBLight> light =
vtkSmartPointer<vtkRIBLight>::New();
light->Print(lightPrint);
light->ShadowsOff();
TEST_SET_GET_VALUE(0,
light->GetShadows());
light->ShadowsOn();
TEST_SET_GET_VALUE(1,