Commit eaf68626 authored by loring's avatar loring

depth sort update

this patch modernizes VTK's depth sorting code. The following improvements
were made:

* transfrom GetCell to GetCellPoints. Building the cells one by one
  is expensive and we only need points to determine the depth. We
  can also then access the points in place.

* transform qsort to std::sort. Comparisons in std::sort get inlined
  so std::sort is much faster. I also reduced the overhead of swaps
  by using a functor so that only cell id is swapped.

* use templates to deal with point types instead of going through
  virtual GetValue API that converts them to double.

* restructure depth computations so that they can be vectorized by
  the compiler.

* I added a Cxx test to improve test coverage of the various sorting
  modes supported by this class.

In tests the improved class is 2 x faster when sorting by first point
and cell bounds, and 1.5 x faster when sorting by parametric center.
The tests made use of a 900M cell iso-surface computed from a cosmology
simulation, and gcc 4.9.2 with -DNDEBUG -Ofast -march=native -mavx


git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@27619 18c085ea-50e0-402c-830e-de6fd14e8384
parent 36a5ef79
......@@ -57,7 +57,7 @@
#include <vtkDataSet.h>
#include <vtkDataSetMapper.h>
#include <vtkDataSetRemoveGhostCells.h>
#include <vtkDepthSortPolyData.h>
#include <vtkDepthSortPolyData2.h>
#include <vtkDoubleArray.h>
#include <vtkGeometryFilter.h>
#include <vtkMatrix4x4.h>
......@@ -573,7 +573,7 @@ avtTransparencyActor::avtTransparencyActor() :
axisSort = vtkAxisDepthSort::New();
axisSort->SetInputConnection(appender->GetOutputPort());
depthSort = vtkDepthSortPolyData::New();
depthSort = vtkDepthSortPolyData2::New();
depthSort->SetDepthSortModeToBoundsCenter();
depthSort->SetInputConnection(appender->GetOutputPort());
......@@ -583,7 +583,7 @@ avtTransparencyActor::avtTransparencyActor() :
distribute->SetCommunicator(VISIT_MPI_COMM);
distribute->SetInputConnection(appender->GetOutputPort());
distributeDepthSort = vtkDepthSortPolyData::New();
distributeDepthSort = vtkDepthSortPolyData2::New();
distributeDepthSort->SetDepthSortModeToBoundsCenter();
distributeDepthSort->SetInputConnection(distribute->GetOutputPort());
#endif
......
......@@ -56,7 +56,7 @@ class vtkAxisDepthSort;
class vtkCamera;
class vtkDataSet;
class vtkDataSetMapper;
class vtkDepthSortPolyData;
class vtkDepthSortPolyData2;
class vtkMatrix4x4;
class vtkPolyData;
class vtkPolyDataMapper;
......@@ -219,8 +219,8 @@ class PLOTTER_API avtTransparencyActor
vtkPolyDataMapper *myMapper;
vtkAxisDepthSort *axisSort;
vtkDepthSortPolyData *distributeDepthSort;
vtkDepthSortPolyData *depthSort;
vtkDepthSortPolyData2 *distributeDepthSort;
vtkDepthSortPolyData2 *depthSort;
bool usePerfectSort;
bool is2Dimensional;
vtkMatrix4x4 *lastCamera;
......
......@@ -37,13 +37,16 @@
# Modifications:
# Cyrus Harrison, Tue Mar 9 08:28:53 PST 2010
# Define __USE_ISOC99 if we are using the boost interval lib to make sure
# a rounding scheme is available.
# a rounding scheme is available.
#
# Eric Brugger, Wed Jul 25 08:30:40 PDT 2012
# I added the classes vtkMultiSplitter and vtkVolumeFromCSGVolume.
#
# Kathleen Biagas, Wed Aug 8 08:15:26 PDT 2012
# Removed vtkDisjointCubesFacelistFilter.
# Kathleen Biagas, Wed Aug 8 08:15:26 PDT 2012
# Removed vtkDisjointCubesFacelistFilter.
#
# Burlen Loring, Sun Oct 18 00:47:57 PDT 2015
# Added vtkDepthSortPolyData2
#
#****************************************************************************/
......@@ -55,6 +58,7 @@ vtkCSGCell.C
vtkCSGGrid.C
vtkConnectedTubeFilter.C
vtkDataSetRemoveGhostCells.C
vtkDepthSortPolyData2.C
vtkLineoutFilter.C
vtkLinesFromOriginalCells.C
vtkMultiSplitter.C
......
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkDepthSortPolyData2.h
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.
=========================================================================*/
// .NAME vtkDepthSortPolyData2 - sort poly data along camera view direction
// .SECTION Description
// vtkDepthSortPolyData2 rearranges the order of cells so that certain
// rendering operations (e.g., transparency or Painter's algorithms)
// generate correct results. To use this filter you must specify the
// direction vector along which to sort the cells. You can do this by
// specifying a camera and/or prop to define a view direction; or
// explicitly set a view direction.
// .SECTION Caveats
// The sort operation will not work well for long, thin primitives, or cells
// that intersect, overlap, or interpenetrate each other.
#ifndef vtkDepthSortPolyData2_h
#define vtkDepthSortPolyData2_h
#include <visit_vtk_exports.h> // For visit export macro
//#include "vtkFiltersHybridModule.h" // For vtk export macro
#include "vtkPolyDataAlgorithm.h"
#define VTK_DIRECTION_BACK_TO_FRONT 0
#define VTK_DIRECTION_FRONT_TO_BACK 1
#define VTK_DIRECTION_SPECIFIED_VECTOR 2
#define VTK_SORT_FIRST_POINT 0
#define VTK_SORT_BOUNDS_CENTER 1
#define VTK_SORT_PARAMETRIC_CENTER 2
class vtkCamera;
class vtkProp3D;
class vtkTransform;
class VISIT_VTK_API vtkDepthSortPolyData2 : public vtkPolyDataAlgorithm
{
public:
// Description:
// Instantiate object.
static vtkDepthSortPolyData2 *New();
vtkTypeMacro(vtkDepthSortPolyData2,vtkPolyDataAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Specify the sort method for the polygonal primitives. By default, the
// poly data is sorted from back to front.
vtkSetMacro(Direction,int);
vtkGetMacro(Direction,int);
void SetDirectionToFrontToBack()
{this->SetDirection(VTK_DIRECTION_FRONT_TO_BACK);}
void SetDirectionToBackToFront()
{this->SetDirection(VTK_DIRECTION_BACK_TO_FRONT);}
void SetDirectionToSpecifiedVector()
{this->SetDirection(VTK_DIRECTION_SPECIFIED_VECTOR);}
// Description:
// Specify the point to use when sorting. The fastest is to just
// take the first cell point. Other options are to take the bounding
// box center or the parametric center of the cell. By default, the
// first cell point is used.
vtkSetMacro(DepthSortMode,int);
vtkGetMacro(DepthSortMode,int);
void SetDepthSortModeToFirstPoint()
{this->SetDepthSortMode(VTK_SORT_FIRST_POINT);}
void SetDepthSortModeToBoundsCenter()
{this->SetDepthSortMode(VTK_SORT_BOUNDS_CENTER);}
void SetDepthSortModeToParametricCenter()
{this->SetDepthSortMode(VTK_SORT_PARAMETRIC_CENTER);}
// Description:
// Specify a camera that is used to define a view direction along which
// the cells are sorted. This ivar only has effect if the direction is set
// to front-to-back or back-to-front, and a camera is specified.
virtual void SetCamera(vtkCamera*);
vtkGetObjectMacro(Camera,vtkCamera);
// Description:
// Specify a transformation matrix (via the vtkProp3D::GetMatrix() method)
// that is used to include the effects of transformation. This ivar only
// has effect if the direction is set to front-to-back or back-to-front,
// and a camera is specified. Specifying the vtkProp3D is optional.
void SetProp3D(vtkProp3D *);
vtkProp3D *GetProp3D()
{ return this->Prop3D; }
// Description:
// Set/Get the sort direction. This ivar only has effect if the sort
// direction is set to SetDirectionToSpecifiedVector(). The sort occurs
// in the direction of the vector.
vtkSetVector3Macro(Vector,double);
vtkGetVectorMacro(Vector,double,3);
// Description:
// Set/Get the sort origin. This ivar only has effect if the sort
// direction is set to SetDirectionToSpecifiedVector(). The sort occurs
// in the direction of the vector, with this point specifying the
// origin.
vtkSetVector3Macro(Origin,double);
vtkGetVectorMacro(Origin,double,3);
// Description:
// Set/Get a flag that controls the generation of scalar values
// corresponding to the sort order. If enabled, the output of this
// filter will include scalar values that range from 0 to (ncells-1),
// where 0 is closest to the sort direction.
vtkSetMacro(SortScalars, int);
vtkGetMacro(SortScalars, int);
vtkBooleanMacro(SortScalars, int);
// Description:
// Return MTime also considering the dependent objects: the camera
// and/or the prop3D.
unsigned long GetMTime();
protected:
vtkDepthSortPolyData2();
~vtkDepthSortPolyData2();
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
void ComputeProjectionVector(double vector[3], double origin[3]);
int Direction;
int DepthSortMode;
vtkCamera *Camera;
vtkProp3D *Prop3D;
vtkTransform *Transform;
double Vector[3];
double Origin[3];
int SortScalars;
private:
vtkDepthSortPolyData2(const vtkDepthSortPolyData2&); // Not implemented.
void operator=(const vtkDepthSortPolyData2&); // Not implemented.
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment