Commit 5ecf2d11 authored by Robert Maynard's avatar Robert Maynard
Browse files

vtkm::rendering has more compilation units to help out 32bit compilers

Visual Studio default toolset uses 32bit executables for compiling which
means that if it uses more than 4GB of memory per instance it crashes.
By moving the ConnectivityTracer into a separate compilation unit we
can help out the compiler.

This also improved compilation times and library size:

Old:
build time (j8): 48.62 real
lib size: 6.2MB

New:
build time (j8): 41.31 real
lib size: 5.0MB
parent 548e9467
......@@ -65,25 +65,19 @@ set(sources
BitmapFontFactory.cxx
BoundingBoxAnnotation.cxx
Camera.cxx
Canvas.cxx
CanvasRayTracer.cxx
Color.cxx
ColorBarAnnotation.cxx
ColorLegendAnnotation.cxx
ColorTable.cxx
ConnectivityProxy.cxx
DecodePNG.cxx
LineRenderer.cxx
Mapper.cxx
MapperConnectivity.cxx
MapperRayTracer.cxx
MapperVolume.cxx
MapperConnectivity.cxx
MapperWireframer.cxx
Scene.cxx
TextAnnotation.cxx
TextAnnotationBillboard.cxx
TextAnnotationScreen.cxx
TextRenderer.cxx
View.cxx
View1D.cxx
View2D.cxx
......@@ -91,13 +85,10 @@ set(sources
WorldAnnotator.cxx
internal/RunTriangulator.cxx
raytracing/BoundingVolumeHierarchy.cxx
raytracing/Camera.cxx
raytracing/ChannelBuffer.cxx
raytracing/ConnectivityBase.cxx
raytracing/ConnectivityTracerBase.cxx
raytracing/ConnectivityTracerFactory.cxx
raytracing/Logger.cxx
raytracing/RayTracer.cxx
raytracing/RayOperations.cxx
raytracing/VolumeRendererStructured.cxx
)
set(opengl_headers
......@@ -133,18 +124,20 @@ set(osmesa_sources
# This list of sources has code that uses devices and so might need to be
# compiled with a device-specific compiler (like CUDA).
set(device_sources
Mapper.cxx
MapperWireframer.cxx
Canvas.cxx
CanvasRayTracer.cxx
ConnectivityProxy.cxx
Mapper.cxx
MapperWireframer.cxx
TextRenderer.cxx
raytracing/BoundingVolumeHierarchy.cxx
raytracing/Camera.cxx
raytracing/ChannelBuffer.cxx
raytracing/VolumeRendererStructured.cxx
raytracing/ConnectivityTracer.cxx
raytracing/RayOperations.cxx
raytracing/RayTracer.cxx
raytracing/VolumeRendererStructured.cxx
)
#-----------------------------------------------------------------------------
......
......@@ -25,6 +25,8 @@
#include <vtkm/rendering/Mapper.h>
#include <vtkm/rendering/raytracing/ConnectivityTracerFactory.h>
#include <vtkm/rendering/raytracing/Logger.h>
#include <vtkm/rendering/raytracing/RayOperations.h>
namespace vtkm
{
......
......@@ -21,14 +21,15 @@
set(headers
BoundingVolumeHierarchy.h
Camera.h
CellIntersector.h
CellSampler.h
CellTables.h
ChannelBuffer.h
ChannelBufferOperations.h
ConnectivityBase.h
ConnectivityTracer.h
ConnectivityTracerBase.h
ConnectivityTracerFactory.h
CellIntersector.h
CellSampler.h
CellTables.h
Logger.h
MeshConnectivityBuilder.h
MeshConnectivityStructures.h
......@@ -38,8 +39,8 @@ set(headers
RayTracer.h
RayTracingTypeDefs.h
TriangleIntersector.h
Worklets.h
VolumeRendererStructured.h
Worklets.h
)
set_source_files_properties(CellTables.h
......
//============================================================================
// 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 2018 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2018 UT-Battelle, LLC.
// Copyright 2018 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 <vtkm/rendering/raytracing/ConnectivityBase.h>
namespace vtkm
{
namespace rendering
{
namespace raytracing
{
ConnectivityBase::ConnectivityBase()
{
}
ConnectivityBase::~ConnectivityBase()
{
}
}
}
}
......@@ -20,7 +20,8 @@
#ifndef vtk_m_rendering_raytracing_Connectivity_Base_h
#define vtk_m_rendering_raytracing_Connectivity_Base_h
#include <vtkm/rendering/raytracing/Logger.h>
#include <vtkm/rendering/vtkm_rendering_export.h>
#include <vtkm/rendering/raytracing/Ray.h>
namespace vtkm
......@@ -30,7 +31,7 @@ namespace rendering
namespace raytracing
{
class ConnectivityBase
class VTKM_RENDERING_EXPORT ConnectivityBase
{
public:
enum IntegrationMode
......@@ -39,8 +40,8 @@ public:
Energy
};
ConnectivityBase() {}
virtual ~ConnectivityBase() {}
ConnectivityBase();
virtual ~ConnectivityBase();
virtual void Trace(Ray<vtkm::Float64>& rays) = 0;
......@@ -59,6 +60,7 @@ public:
virtual void SetColorMap(
const vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32, 4>>& colorMap) = 0;
}; // class ConnectivityBase
}
}
......
//============================================================================
// 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.
//============================================================================
#define vtk_m_rendering_raytracing_ConnectivityTracer_cxx
#include <vtkm/rendering/raytracing/ConnectivityTracer.h>
#include <vtkm/rendering/raytracing/ConnectivityTracer.hxx>
namespace vtkm
{
namespace rendering
{
namespace raytracing
{
namespace detail
{
struct RenderFunctor
{
template <typename Device, typename Tracer, typename Rays>
bool operator()(Device device, Tracer&& tracer, Rays&& rays) const
{
tracer.RenderOnDevice(rays, device);
return true;
}
};
} //namespace detail
template <vtkm::Int32 CellType, typename ConnectivityType>
void ConnectivityTracer<CellType, ConnectivityType>::Trace(Ray<vtkm::Float32>& rays)
{
detail::RenderFunctor functor;
vtkm::cont::TryExecute(functor, *this, rays);
}
template <vtkm::Int32 CellType, typename ConnectivityType>
void ConnectivityTracer<CellType, ConnectivityType>::Trace(Ray<vtkm::Float64>& rays)
{
detail::RenderFunctor functor;
vtkm::cont::TryExecute(functor, *this, rays);
}
//explicit construct all valid forms ofConnectivityTracer
template class detail::RayTracking<float>;
template class detail::RayTracking<double>;
template class VTKM_RENDERING_TEMPLATE_EXPORT
ConnectivityTracer<CELL_SHAPE_ZOO, UnstructuredMeshConn>;
template class VTKM_RENDERING_TEMPLATE_EXPORT
ConnectivityTracer<CELL_SHAPE_HEXAHEDRON, UnstructuredMeshConnSingleType>;
template class VTKM_RENDERING_TEMPLATE_EXPORT
ConnectivityTracer<CELL_SHAPE_WEDGE, UnstructuredMeshConnSingleType>;
template class VTKM_RENDERING_TEMPLATE_EXPORT
ConnectivityTracer<CELL_SHAPE_TETRA, UnstructuredMeshConnSingleType>;
template class VTKM_RENDERING_TEMPLATE_EXPORT
ConnectivityTracer<CELL_SHAPE_STRUCTURED, StructuredMeshConn>;
}
}
} // namespace vtkm::rendering::raytracing
......@@ -20,41 +20,19 @@
#ifndef vtk_m_rendering_raytracing_ConnectivityTracer_h
#define vtk_m_rendering_raytracing_ConnectivityTracer_h
#include <fstream>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vtkm/rendering/vtkm_rendering_export.h>
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/ErrorBadValue.h>
#include <vtkm/cont/Timer.h>
#include <vtkm/cont/TryExecute.h>
#include <vtkm/rendering/ColorTable.h>
#include <vtkm/rendering/raytracing/Camera.h>
#include <vtkm/rendering/raytracing/CellIntersector.h>
#include <vtkm/rendering/raytracing/CellSampler.h>
#include <vtkm/rendering/raytracing/CellTables.h>
#include <vtkm/rendering/raytracing/ConnectivityBase.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/rendering/raytracing/ConnectivityTracerBase.h>
#include <vtkm/rendering/raytracing/MeshConnectivityStructures.h>
#include <vtkm/rendering/raytracing/Ray.h>
#include <vtkm/rendering/raytracing/RayOperations.h>
#include <vtkm/rendering/raytracing/RayTracingTypeDefs.h>
#include <vtkm/rendering/raytracing/Worklets.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#ifndef CELL_SHAPE_ZOO
#define CELL_SHAPE_ZOO 255
#endif
#ifndef CELL_SHAPE_STRUCTURED
#define CELL_SHAPE_STRUCTURED 254
#endif
namespace vtkm
{
......@@ -62,37 +40,12 @@ namespace rendering
{
namespace raytracing
{
//
// Advance Ray
// After a ray leaves the mesh, we need to check to see
// of the ray re-enters the mesh within this domain. This
// function moves the ray forward some offset to prevent
// "shadowing" and hitting the same exit point.
//
template <typename FloatType>
class AdvanceRay : public vtkm::worklet::WorkletMapField
{
FloatType Offset;
public:
VTKM_CONT
AdvanceRay(const FloatType offset = 0.00001)
: Offset(offset)
{
}
typedef void ControlSignature(FieldIn<>, FieldInOut<>);
typedef void ExecutionSignature(_1, _2);
VTKM_EXEC inline void operator()(const vtkm::UInt8& status, FloatType& distance) const
{
if (status == RAY_EXITED_MESH)
distance += Offset;
}
}; //class MemSet
namespace detail
{
//forward declare so we can be friends
struct RenderFunctor;
//
// Ray tracker manages memory and pointer
// swaping for current cell intersection data
......@@ -117,904 +70,25 @@ public:
template <typename Device>
void Compact(vtkm::cont::ArrayHandle<FloatType>& compactedDistances,
vtkm::cont::ArrayHandle<UInt8>& masks,
Device)
{
//
// These distances are stored in the rays, and it has
// already been compacted.
//
CurrentDistance = compactedDistances;
vtkm::cont::ArrayHandleCast<vtkm::Id, vtkm::cont::ArrayHandle<vtkm::UInt8>> castedMasks(masks);
bool distance1IsEnter = EnterDist == &Distance1;
vtkm::cont::ArrayHandle<FloatType> compactedDistance1;
vtkm::cont::DeviceAdapterAlgorithm<Device>::CopyIf(Distance1, masks, compactedDistance1);
Distance1 = compactedDistance1;
vtkm::cont::ArrayHandle<FloatType> compactedDistance2;
vtkm::cont::DeviceAdapterAlgorithm<Device>::CopyIf(Distance2, masks, compactedDistance2);
Distance2 = compactedDistance2;
vtkm::cont::ArrayHandle<vtkm::Int32> compactedExitFace;
vtkm::cont::DeviceAdapterAlgorithm<Device>::CopyIf(ExitFace, masks, compactedExitFace);
ExitFace = compactedExitFace;
if (distance1IsEnter)
{
EnterDist = &Distance1;
ExitDist = &Distance2;
}
else
{
EnterDist = &Distance2;
ExitDist = &Distance1;
}
}
Device);
template <typename Device>
void Init(const vtkm::Id size, vtkm::cont::ArrayHandle<FloatType>& distances, Device)
{
void Init(const vtkm::Id size, vtkm::cont::ArrayHandle<FloatType>& distances, Device);
ExitFace.PrepareForOutput(size, Device());
Distance1.PrepareForOutput(size, Device());
Distance2.PrepareForOutput(size, Device());
CurrentDistance = distances;
//
// Set the initial Distances
//
vtkm::worklet::DispatcherMapField<CopyAndOffset<FloatType>, Device>(
CopyAndOffset<FloatType>(0.0f))
.Invoke(distances, *EnterDist);
//
// Init the exit faces. This value is used to load the next cell
// base on the cell and face it left
//
vtkm::worklet::DispatcherMapField<MemSet<vtkm::Int32>, Device>(MemSet<vtkm::Int32>(-1))
.Invoke(ExitFace);
vtkm::worklet::DispatcherMapField<MemSet<FloatType>, Device>(MemSet<FloatType>(-1))
.Invoke(*ExitDist);
}
void Swap()
{
vtkm::cont::ArrayHandle<FloatType>* tmpPtr;
tmpPtr = EnterDist;
EnterDist = ExitDist;
ExitDist = tmpPtr;
}
void Swap();
};
} //namespace detail
template <typename FloatType>
VTKM_EXEC_CONT inline void PrintDistances(const vtkm::Id& pixelIndex,
vtkm::Int32& minFace,
vtkm::Int32& maxFace,
FloatType distances[6],
vtkm::Id& cell,
FloatType& enterDistance,
FloatType& minDistance,
FloatType& maxDistance)
{
printf("Pixel at %d in cell %d\n", (int)pixelIndex, (int)cell);
printf("Near %f min %f max %f \n", enterDistance, minDistance, maxDistance);
printf("Min Face %d Max Face %d\n", minFace, maxFace);
printf("** Enter Dis Diff %1.30f\n", enterDistance);
printf("** Distance 0 Diff %1.30f\n", distances[0]);
printf("** Distance 1 Diff %1.30f\n", distances[1]);
printf("** Distance 2 Diff %1.30f\n", distances[2]);
printf("** Distance 3 Diff %1.30f\n", distances[3]);
printf("** Distance 4 Diff %1.30f\n", distances[4]);
printf("** Distance 5 Diff %1.30f\n", distances[5]);
}
template <vtkm::Int32 CellType, typename ConnectivityType>
class ConnectivityTracer : public ConnectivityBase
class ConnectivityTracer : public ConnectivityTracerBase
{
public:
template <typename FloatType, typename Device, template <typename, typename> class MeshType>
class LocateCell : public vtkm::worklet::WorkletMapField
{
private:
MeshType<ConnectivityType, Device> MeshConn;
CellIntersector<CellType> Intersector;
public:
VTKM_CONT
LocateCell(ConnectivityType& meshConn)
: MeshConn(meshConn)
{
}
typedef void ControlSignature(FieldInOut<>,
WholeArrayIn<>,
FieldIn<>,
FieldInOut<>,
FieldInOut<>,
FieldInOut<>,
FieldInOut<>,
FieldIn<>);
typedef void ExecutionSignature(_1, _2, _3, _4, _5, _6, _7, _8);
template <typename PointPortalType>
VTKM_EXEC inline void operator()(vtkm::Id& currentCell,
PointPortalType& vertices,
const vtkm::Vec<FloatType, 3>& dir,
FloatType& enterDistance,
FloatType& exitDistance,
vtkm::Int32& enterFace,
vtkm::UInt8& rayStatus,
const vtkm::Vec<FloatType, 3>& origin) const
{
if (enterFace != -1 && rayStatus == RAY_ACTIVE)
{
currentCell = MeshConn.GetConnectingCell(currentCell, enterFace);
if (currentCell == -1)
rayStatus = RAY_EXITED_MESH;
enterFace = -1;
}
//This ray is dead or exited the mesh and needs re-entry
if (rayStatus != RAY_ACTIVE)
{
return;
}
FloatType xpoints[8];
FloatType ypoints[8];
FloatType zpoints[8];
vtkm::Id cellConn[8];
FloatType distances[6];
const vtkm::Int32 numIndices = MeshConn.GetCellIndices(cellConn, currentCell);
//load local cell data
for (int i = 0; i < numIndices; ++i)
{
BOUNDS_CHECK(vertices, cellConn[i]);
vtkm::Vec<FloatType, 3> point = vtkm::Vec<FloatType, 3>(vertices.Get(cellConn[i]));
xpoints[i] = point[0];
ypoints[i] = point[1];
zpoints[i] = point[2];
}
const vtkm::UInt8 cellShape = MeshConn.GetCellShape(currentCell);
Intersector.IntersectCell(xpoints, ypoints, zpoints, dir, origin, distances, cellShape);
const vtkm::Int32 numFaces =
CellTables::Get().FaceLookUp[CellTables::Get().CellTypeLookUp[cellShape]][1];
//vtkm::Int32 minFace = 6;
vtkm::Int32 maxFace = -1;
FloatType minDistance = static_cast<FloatType>(1e32);
FloatType maxDistance = static_cast<FloatType>(-1);
int hitCount = 0;
for (vtkm::Int32 i = 0; i < numFaces; ++i)
{
FloatType dist = distances[i];
if (dist != -1)
{
hitCount++;
if (dist < minDistance)
{
minDistance = dist;
//minFace = i;
}
if (dist > maxDistance)
{
maxDistance = dist;
maxFace = i;
}
}
}
if (maxDistance <= enterDistance || minDistance == maxDistance)
{
rayStatus = RAY_LOST;
}
else
{
enterDistance = minDistance;
exitDistance = maxDistance;
enterFace = maxFace;
}
} //operator
}; //class LocateCell
template <typename FloatType, typename Device, template <typename, typename> class MeshType>
class RayBumper : public vtkm::worklet::WorkletMapField
{
private:
typedef typename vtkm::cont::ArrayHandle<FloatType> FloatTypeHandle;
typedef typename FloatTypeHandle::template ExecutionTypes<Device>::Portal FloatTypePortal;
FloatTypePortal DirectionsX;
FloatTypePortal DirectionsY;
FloatTypePortal DirectionsZ;
MeshType<ConnectivityType, Device> MeshConn;
CellIntersector<CellType> Intersector;
const vtkm::UInt8 FailureStatus; // the status to assign ray if we fail to find the intersection
public:
VTKM_CONT
RayBumper(FloatTypeHandle dirsx,
FloatTypeHandle dirsy,
FloatTypeHandle dirsz,
ConnectivityType meshConn,
vtkm::UInt8 failureStatus = RAY_ABANDONED)
: DirectionsX(dirsx.PrepareForInPlace(Device()))
, DirectionsY(dirsy.PrepareForInPlace(Device()))
, DirectionsZ(dirsz.PrepareForInPlace(Device()))
, MeshConn(meshConn)
, FailureStatus(failureStatus)
{
}
typedef void ControlSignature(FieldInOut<>,
WholeArrayIn<>,
FieldInOut<>,
FieldInOut<>,
FieldInOut<>,
FieldInOut<>,
FieldIn<>);
typedef void ExecutionSignature(_1, _2, _3, _4, _5, WorkIndex, _6, _7);
template <typename PointPortalType>
VTKM_EXEC inline void operator()(vtkm::Id& currentCell,
PointPortalType& vertices,
FloatType& enterDistance,
FloatType& exitDistance,
vtkm::Int32& enterFace,
const vtkm::Id& pixelIndex,
vtkm::UInt8& rayStatus,
const vtkm::Vec<FloatType, 3>& origin) const