//============================================================================= // // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt 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. // // Copyright 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS). // Copyright 2015 UT-Battelle, LLC. // Copyright 2015 Los Alamos National Security. // // Under the terms of Contract DE-NA0003525 with NTESS, // the U.S. Government retains certain rights in this software. // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National // Laboratory (LANL), the U.S. Government retains certain rights in // this software. // //============================================================================= #include namespace vtkm { namespace rendering { namespace raytracing { template struct MapCanvasFunctor { const vtkm::Matrix Inverse; const vtkm::Id Width; const vtkm::Id Height; const vtkm::cont::ArrayHandle& DepthBuffer; Ray& Rays; vtkm::Vec Origin; MapCanvasFunctor(Ray& rays, const vtkm::Matrix inverse, const vtkm::Id width, const vtkm::Id height, const vtkm::cont::ArrayHandle& depthBuffer, const vtkm::Vec& origin) : Inverse(inverse) , Width(width) , Height(height) , DepthBuffer(depthBuffer) , Rays(rays) , Origin(origin) { } template bool operator()(Device) { vtkm::worklet::DispatcherMapField( detail::RayMapCanvas(Inverse, Width, Height, Origin)) .Invoke(Rays.PixelIdx, Rays.MaxDistance, DepthBuffer); return true; } }; void RayOperations::MapCanvasToRays(Ray& rays, const vtkm::rendering::Camera& camera, const vtkm::rendering::CanvasRayTracer& canvas) { vtkm::Id width = canvas.GetWidth(); vtkm::Id height = canvas.GetHeight(); vtkm::Matrix projview = vtkm::MatrixMultiply(camera.CreateProjectionMatrix(width, height), camera.CreateViewMatrix()); bool valid; vtkm::Matrix inverse = vtkm::MatrixInverse(projview, valid); if (!valid) throw vtkm::cont::ErrorBadValue("Inverse Invalid"); MapCanvasFunctor functor( rays, inverse, width, height, canvas.GetDepthBuffer(), camera.GetPosition()); vtkm::cont::TryExecute(functor); } } } } // vtkm::rendering::raytacing