vtkBivariateLinearTableThreshold.h 7.47 KB
Newer Older
1
/*=========================================================================
2

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Program:   Visualization Toolkit
Module:    vtkBivariateLinearTableThreshold.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.

=========================================================================*/
/*-------------------------------------------------------------------------
  Copyright 2009 Sandia Corporation.
  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/
20
// .NAME vtkBivariateLinearTableThreshold - performs line-based thresholding
21
// for vtkTable data.
22 23 24 25 26
//
// .SECTION Description
// Class for filtering the rows of a two numeric columns of a vtkTable.  The
// columns are treated as the two variables of a line.  This filter will
// then iterate through the rows of the table determining if X,Y values pairs
27
// are above/below/between/near one or more lines.
28
//
29
// The "between" mode checks to see if a row is contained within the convex
30 31 32
// hull of all of the specified lines.  The "near" mode checks if a row is
// within a distance threshold two one of the specified lines.  This class
// is used in conjunction with various plotting classes, so it is useful
33
// to rescale the X,Y axes to a particular range of values.  Distance
34 35 36
// comparisons can be performed in the scaled space by setting the CustomRanges
// ivar and enabling UseNormalizedDistance.

37 38
#ifndef vtkBivariateLinearTableThreshold__h
#define vtkBivariateLinearTableThreshold__h
39

40
#include "vtkFiltersStatisticsModule.h" // For export macro
41 42 43 44 45 46 47 48
#include "vtkTableAlgorithm.h"
#include "vtkSmartPointer.h"  //Required for smart pointer internal ivars

class vtkDataArrayCollection;
class vtkDoubleArray;
class vtkIdTypeArray;
class vtkTable;

49
class VTKFILTERSSTATISTICS_EXPORT vtkBivariateLinearTableThreshold : public vtkTableAlgorithm
50 51 52
{
public:
  static vtkBivariateLinearTableThreshold* New();
53
  vtkTypeMacro(vtkBivariateLinearTableThreshold, vtkTableAlgorithm);
54 55
  void PrintSelf(ostream& os, vtkIndent indent);

56 57 58
  // Description:
  // Include the line in the threshold.  Essentially whether the threshold operation
  // uses > versus >=.
59 60 61
  vtkSetMacro(Inclusive,int);
  vtkGetMacro(Inclusive,int);

62 63
  // Description:
  // Add a numeric column to the pair of columns to be thresholded.  Call twice.
64
  void AddColumnToThreshold(vtkIdType column, vtkIdType component);
65

66 67
  // Description:
  // Return how many columns have been added.  Hopefully 2.
68
  int GetNumberOfColumnsToThreshold();
69 70 71

  // Description:
  // Return the column number from the input table for the idx'th added column.
72
  void GetColumnToThreshold(vtkIdType idx, vtkIdType& column, vtkIdType& component);
73 74 75

  // Description:
  // Reset the columns to be thresholded.
76 77
  void ClearColumnsToThreshold();

78 79
  // Description:
  // Get the output as a table of row ids.
80 81 82 83 84 85 86 87 88 89
  vtkIdTypeArray* GetSelectedRowIds(int selection=0);

  //BTX
  enum OutputPorts
  {
    OUTPUT_ROW_IDS=0,
    OUTPUT_ROW_DATA
  };
  enum LinearThresholdType
  {
90 91 92 93
    BLT_ABOVE=0,
    BLT_BELOW,
    BLT_NEAR,
    BLT_BETWEEN
94 95
  };
  //ETX
96

97 98
  // Description:
  // Reset the columns to threshold, column ranges, etc.
99 100
  void Initialize();

101 102
  // Description:
  // Add a line for thresholding from two x,y points.
103
  void AddLineEquation(double* p1, double* p2);
104 105 106

  // Description:
  // Add a line for thresholding in point-slope form.
107
  void AddLineEquation(double* p, double slope);
108 109 110

  // Description:
  // Add a line for thresholding in implicit form (ax + by + c = 0)
111
  void AddLineEquation(double a, double b, double c);
112 113 114

  // Description:
  // Reset the list of line equations.
115 116
  void ClearLineEquations();

117 118 119 120 121
  // Description:
  // Set the threshold type.  Above: find all rows that are above the specified
  // lines.  Below: find all rows that are below the specified lines.  Near:
  // find all rows that are near the specified lines.  Between: find all rows
  // that are between the specified lines.
122 123
  vtkGetMacro(LinearThresholdType,int);
  vtkSetMacro(LinearThresholdType,int);
124 125 126 127
  void SetLinearThresholdTypeToAbove() { this->SetLinearThresholdType(vtkBivariateLinearTableThreshold::BLT_ABOVE); }
  void SetLinearThresholdTypeToBelow() { this->SetLinearThresholdType(vtkBivariateLinearTableThreshold::BLT_BELOW); }
  void SetLinearThresholdTypeToNear() { this->SetLinearThresholdType(vtkBivariateLinearTableThreshold::BLT_NEAR); }
  void SetLinearThresholdTypeToBetween() { this->SetLinearThresholdType(vtkBivariateLinearTableThreshold::BLT_BETWEEN); }
128

129
  // Description:
130
  // Manually access the maximum/minimum x,y values.  This is used in
131 132
  // conjunction with UseNormalizedDistance when determining if a row
  // passes the threshold.
133 134 135
  vtkSetVector2Macro(ColumnRanges,double);
  vtkGetVector2Macro(ColumnRanges,double);

136 137
  // Description:
  // The Cartesian distance within which a point will pass the near threshold.
138 139 140
  vtkSetMacro(DistanceThreshold,double);
  vtkGetMacro(DistanceThreshold,double);

141 142 143
  // Description:
  // Renormalize the space of the data such that the X and Y axes are
  // "square" over the specified ColumnRanges.  This essentially scales
144
  // the data space so that ColumnRanges[1]-ColumnRanges[0] = 1.0 and
145 146
  // ColumnRanges[3]-ColumnRanges[2] = 1.0.  Used for scatter plot distance
  // calculations.  Be sure to set DistanceThreshold accordingly, when used.
147 148 149 150
  vtkSetMacro(UseNormalizedDistance,int);
  vtkGetMacro(UseNormalizedDistance,int);
  vtkBooleanMacro(UseNormalizedDistance,int);

151 152
  // Description:
  // Convert the two-point line formula to implicit form.
153
  static void ComputeImplicitLineFunction(double* p1, double* p2, double* abc);
154 155 156

  // Description:
  // Convert the point-slope line formula to implicit form.
157
  static void ComputeImplicitLineFunction(double* p, double slope, double* abc);
158

159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
protected:
  vtkBivariateLinearTableThreshold();
  virtual ~vtkBivariateLinearTableThreshold();

  double ColumnRanges[2];
  double DistanceThreshold;
  int Inclusive;
  int LinearThresholdType;
  int NumberOfLineEquations;
  int UseNormalizedDistance;

  //BTX
  vtkSmartPointer<vtkDoubleArray> LineEquations;
  class Internals;
  Internals* Implementation;
  //ETX

  virtual int RequestData(
    vtkInformation*,
    vtkInformationVector**,
    vtkInformationVector*);

  virtual int FillInputPortInformation( int port, vtkInformation* info );
  virtual int FillOutputPortInformation( int port, vtkInformation* info );

184 185
  // Description:
  // Apply the current threshold to a vtkTable.  Fills acceptedIds on success.
186 187
  virtual int ApplyThreshold(vtkTable* tableToThreshold, vtkIdTypeArray* acceptedIds);

188 189
  // Description:
  // Determine if x,y is above all specified lines.
190
  int ThresholdAbove(double x, double y);
191 192 193

  // Description:
  // Determine if x,y is below all specified lines.
194
  int ThresholdBelow(double x, double y);
195 196 197

  // Description:
  // Determine if x,y is near ONE specified line (not all).
198
  int ThresholdNear(double x, double y);
199 200

  // Description:
201
  // Determine if x,y is between ANY TWO of the specified lines.
202 203 204 205 206 207 208
  int ThresholdBetween(double x, double y);
private:
  vtkBivariateLinearTableThreshold(const vtkBivariateLinearTableThreshold&); // Not implemented
  void operator=(const vtkBivariateLinearTableThreshold&); // Not implemented
};

#endif