/*========================================================================= 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 "vtkActor.h" #include "vtkCamera.h" #include "vtkNamedColors.h" #include "vtkPNMReader.h" #include "vtkPolyDataMapper.h" #include "vtkRIBExporter.h" #include "vtkRIBProperty.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkRenderer.h" #include "vtkSphereSource.h" #include "vtkTestUtilities.h" #include "vtkTexture.h" #include "vtkTexturedSphereSource.h" static vtkSmartPointer cloth(const char* freq, const char* depth); static vtkSmartPointer dented(const char* Km); static vtkSmartPointer stippled(const char* grainsize, const char* stippling); static vtkSmartPointer spatter( const char* sizes, const char* specksize, const char* spattercolor, const char* basecolor); static vtkSmartPointer cmarble(const char* veining); static vtkSmartPointer stone( const char* scale, const char* nshades, const char* exponent, const char* graincolor); static vtkSmartPointer wood( const char* grain, const char* swirl, const char* swirlfreq); static vtkSmartPointer bozo(const char* k); int TestRIBExporter(int argc, char* argv[]) { const char* _prefix = vtkTestUtilities::GetArgOrEnvOrDefault("-T", argc, argv, "VTK_TEMP_DIR", "Testing/Temporary"); std::string prefix = _prefix; delete[] _prefix; if (prefix.empty()) { std::cout << argv[0] << " Could not determine temporary directory.\n"; return EXIT_FAILURE; } prefix += "/TestRIBExporter"; vtkSmartPointer renWin = vtkSmartPointer::New(); vtkSmartPointer ren1 = vtkSmartPointer::New(); vtkSmartPointer iren = vtkSmartPointer::New(); char* textureFile = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/earth.ppm"); vtkSmartPointer textureReader = vtkSmartPointer::New(); textureReader->SetFileName(textureFile); delete[] textureFile; vtkSmartPointer texturedSphere = vtkSmartPointer::New(); texturedSphere->SetPhiResolution(20); texturedSphere->SetThetaResolution(20); vtkSmartPointer texture = vtkSmartPointer::New(); texture->SetInputConnection(textureReader->GetOutputPort()); vtkSmartPointer texturedSphereMapper = vtkSmartPointer::New(); texturedSphereMapper->SetInputConnection(texturedSphere->GetOutputPort()); vtkSmartPointer sphere = vtkSmartPointer::New(); sphere->SetPhiResolution(20); sphere->SetThetaResolution(20); vtkSmartPointer sphereMapper = vtkSmartPointer::New(); sphereMapper->SetInputConnection(sphere->GetOutputPort()); vtkSmartPointer sphere1 = vtkSmartPointer::New(); sphere1->SetMapper(sphereMapper); sphere1->SetPosition(-1.5, 1.5, 0); vtkSmartPointer sphere2 = vtkSmartPointer::New(); sphere2->SetMapper(sphereMapper); sphere2->SetPosition(0, 1.5, 0); vtkSmartPointer sphere3 = vtkSmartPointer::New(); sphere3->SetMapper(sphereMapper); sphere3->SetPosition(1.5, 1.5, 0); vtkSmartPointer sphere4 = vtkSmartPointer::New(); sphere4->SetMapper(sphereMapper); sphere4->SetPosition(-1.5, 0, 0); vtkSmartPointer sphere5 = vtkSmartPointer::New(); sphere5->SetMapper(sphereMapper); sphere5->SetPosition(0, 0, 0); vtkSmartPointer sphere6 = vtkSmartPointer::New(); sphere6->SetMapper(sphereMapper); sphere6->SetPosition(1.5, 0, 0); vtkSmartPointer sphere7 = vtkSmartPointer::New(); sphere7->SetMapper(sphereMapper); sphere7->SetPosition(-1.5, -1.5, 0); vtkSmartPointer sphere8 = vtkSmartPointer::New(); sphere8->SetMapper(sphereMapper); sphere8->SetPosition(0, -1.5, 0); vtkSmartPointer sphere9 = vtkSmartPointer::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 colors = vtkSmartPointer::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 aRib = vtkSmartPointer::New(); aRib->SetInput(renWin); aRib->SetFilePrefix(prefix.c_str()); aRib->SetTexturePrefix(prefix.c_str()); aRib->BackgroundOn(); aRib->Write(); return EXIT_SUCCESS; } vtkSmartPointer cloth(const char* freq, const char* depth) { vtkSmartPointer clothProp = vtkSmartPointer::New(); clothProp->SetVariable("freq", "float"); clothProp->AddVariable("depth", "float"); clothProp->SetDisplacementShaderParameter("freq", freq); clothProp->AddDisplacementShaderParameter("depth", depth); clothProp->SetDisplacementShader("cloth"); return clothProp; } vtkSmartPointer dented(const char* Km) { vtkSmartPointer dentedProp = vtkSmartPointer::New(); dentedProp->SetVariable("Km", "float"); dentedProp->SetDisplacementShaderParameter("Km", Km); dentedProp->SetDisplacementShader("dented"); return dentedProp; } vtkSmartPointer stippled(const char* grainsize, const char* stippling) { vtkSmartPointer stippledProp = vtkSmartPointer::New(); stippledProp->SetVariable("grainsize", "float"); stippledProp->AddVariable("stippling", "float"); stippledProp->SetSurfaceShaderParameter("grainsize", grainsize); stippledProp->AddSurfaceShaderParameter("stippling", stippling); stippledProp->SetSurfaceShader("stippled"); return stippledProp; } vtkSmartPointer bozo(const char* k) { vtkSmartPointer bozoProp = vtkSmartPointer::New(); bozoProp->SetSurfaceShader("bozo"); bozoProp->SetVariable("k", "float"); bozoProp->SetSurfaceShaderParameter("k", k); return bozoProp; } vtkSmartPointer spatter( const char* sizes, const char* specksize, const char* spattercolor, const char* basecolor) { vtkSmartPointer spatterProp = vtkSmartPointer::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 cmarble(const char* veining) { vtkSmartPointer cmarbleProp = vtkSmartPointer::New(); cmarbleProp->SetVariable("veining", "float"); cmarbleProp->SetSurfaceShaderParameter("veining", veining); cmarbleProp->SetSurfaceShader("cmarble"); return cmarbleProp; } vtkSmartPointer stone( const char* scale, const char* nshades, const char* exponent, const char* graincolor) { vtkSmartPointer stoneProp = vtkSmartPointer::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 wood(const char* grain, const char* swirl, const char* swirlfreq) { vtkSmartPointer woodProp = vtkSmartPointer::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; }