//============================================================================ // 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 2016 Sandia Corporation. // Copyright 2016 UT-Battelle, LLC. // Copyright 2016 Los Alamos National Security. // // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, // 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 #include #include #include #include #include #include #include #include namespace vtkm { namespace rendering { struct MapperVolume::InternalsType { vtkm::rendering::CanvasRayTracer *Canvas; vtkm::Float32 SampleDistance; bool CompositeBackground; vtkm::cont::RuntimeDeviceTracker DeviceTracker; std::shared_ptr RayTracerContainer; VTKM_CONT InternalsType() : Canvas(nullptr), SampleDistance(-1.f), CompositeBackground(true) { } template VTKM_CONT vtkm::rendering::raytracing::VolumeRendererStructured * GetRayTracer(Device) { VTKM_IS_DEVICE_ADAPTER_TAG(Device); typedef vtkm::rendering::raytracing::VolumeRendererStructured RayTracerType; typedef vtkm::cont::internal::SimplePolymorphicContainer ContainerType; RayTracerType *tracer = NULL; if (this->RayTracerContainer) { ContainerType *container = dynamic_cast(this->RayTracerContainer.get()); if (container) { tracer = &container->Item; } } if (tracer == NULL) { ContainerType *container = new vtkm::cont::internal::SimplePolymorphicContainer; tracer = &container->Item; this->RayTracerContainer.reset(container); } return tracer; } }; MapperVolume::MapperVolume() : Internals(new InternalsType) { } MapperVolume::~MapperVolume() { } void MapperVolume::SetCanvas(vtkm::rendering::Canvas *canvas) { if(canvas != nullptr) { this->Internals->Canvas = dynamic_cast(canvas); if(this->Internals->Canvas == nullptr) { throw vtkm::cont::ErrorBadValue( "Ray Tracer: bad canvas type. Must be CanvasRayTracer"); } } else { this->Internals->Canvas = nullptr; } } vtkm::rendering::Canvas * MapperVolume::GetCanvas() const { return this->Internals->Canvas; } struct MapperVolume::RenderFunctor { vtkm::rendering::MapperVolume *Self; vtkm::cont::CellSetStructured<3> CellSet; vtkm::cont::CoordinateSystem Coordinates; vtkm::cont::Field ScalarField; vtkm::rendering::Camera Camera; vtkm::Range ScalarRange; VTKM_CONT RenderFunctor(vtkm::rendering::MapperVolume *self, const vtkm::cont::CellSetStructured<3> cellSet, const vtkm::cont::CoordinateSystem &coordinates, const vtkm::cont::Field &scalarField, const vtkm::rendering::Camera &camera, const vtkm::Range &scalarRange) : Self(self), CellSet(cellSet), Coordinates(coordinates), ScalarField(scalarField), Camera(camera), ScalarRange(scalarRange) { } template bool operator()(Device) { VTKM_IS_DEVICE_ADAPTER_TAG(Device); vtkm::rendering::raytracing::VolumeRendererStructured *tracer = this->Self->Internals->GetRayTracer(Device()); tracer->GetCamera().SetParameters(this->Camera, *this->Self->Internals->Canvas); tracer->SetSampleDistance(this->Self->Internals->SampleDistance); tracer->SetCompositeBackground(this->Self->Internals->CompositeBackground); vtkm::Bounds dataBounds = this->Coordinates.GetBounds(Device()); tracer->SetData(this->Coordinates, this->ScalarField, dataBounds, this->CellSet, this->ScalarRange); tracer->SetColorMap(this->Self->ColorMap); tracer->SetBackgroundColor( this->Self->Internals->Canvas->GetBackgroundColor().Components); tracer->Render(this->Self->Internals->Canvas); return true; } }; void MapperVolume::RenderCells( const vtkm::cont::DynamicCellSet &cellset, const vtkm::cont::CoordinateSystem &coords, const vtkm::cont::Field &scalarField, const vtkm::rendering::ColorTable &vtkmNotUsed(colorTable), const vtkm::rendering::Camera &camera, const vtkm::Range &scalarRange) { if(!cellset.IsSameType(vtkm::cont::CellSetStructured<3>())) { std::cerr<<"ERROR cell set type not currently supported\n"; std::string theType = typeid(cellset).name(); std::cerr<<"Type : "< >(), coords, scalarField, camera, scalarRange); vtkm::cont::TryExecute(functor, this->Internals->DeviceTracker, VTKM_DEFAULT_DEVICE_ADAPTER_LIST_TAG()); } } void MapperVolume::StartScene() { // Nothing needs to be done. } void MapperVolume::EndScene() { // Nothing needs to be done. } vtkm::rendering::Mapper *MapperVolume::NewCopy() const { return new vtkm::rendering::MapperVolume(*this); } void MapperVolume::SetSampleDistance(const vtkm::Float32 sampleDistance) { this->Internals->SampleDistance = sampleDistance; } void MapperVolume::SetCompositeBackground(const bool compositeBackground) { this->Internals->CompositeBackground = compositeBackground; } } } // namespace vtkm::rendering