vtkThresholdTextureCoords.cxx 5.11 KB
Newer Older
Will Schroeder's avatar
Will Schroeder committed
1 2
/*=========================================================================

Ken Martin's avatar
Ken Martin committed
3
  Program:   Visualization Toolkit
Ken Martin's avatar
Ken Martin committed
4
  Module:    vtkThresholdTextureCoords.cxx
Will Schroeder's avatar
Will Schroeder committed
5

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
Ken Martin's avatar
Ken Martin committed
9

10 11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
Will Schroeder's avatar
Will Schroeder committed
13 14

=========================================================================*/
Ken Martin's avatar
Ken Martin committed
15
#include "vtkThresholdTextureCoords.h"
16 17

#include "vtkDataSet.h"
18
#include "vtkFloatArray.h"
19 20
#include "vtkInformation.h"
#include "vtkInformationVector.h"
21
#include "vtkObjectFactory.h"
22
#include "vtkPointData.h"
23

Brad King's avatar
Brad King committed
24
vtkStandardNewMacro(vtkThresholdTextureCoords);
25

26
// Construct with lower threshold=0, upper threshold=1, threshold
Will Schroeder's avatar
Will Schroeder committed
27 28
// function=upper, and texture dimension = 2. The "out" texture coordinate
// is (0.25,0,0); the "in" texture coordinate is (0.75,0,0).
Ken Martin's avatar
Ken Martin committed
29
vtkThresholdTextureCoords::vtkThresholdTextureCoords()
Will Schroeder's avatar
Will Schroeder committed
30 31 32
{
  this->LowerThreshold = 0.0;
  this->UpperThreshold = 1.0;
Will Schroeder's avatar
Will Schroeder committed
33
  this->TextureDimension = 2;
Will Schroeder's avatar
Will Schroeder committed
34

Ken Martin's avatar
Ken Martin committed
35
  this->ThresholdFunction = &vtkThresholdTextureCoords::Upper;
Will Schroeder's avatar
Will Schroeder committed
36 37 38 39 40 41 42 43

  this->OutTextureCoord[0] = 0.25;
  this->OutTextureCoord[1] = 0.0;
  this->OutTextureCoord[2] = 0.0;

  this->InTextureCoord[0] = 0.75;
  this->InTextureCoord[1] = 0.0;
  this->InTextureCoord[2] = 0.0;
Will Schroeder's avatar
Will Schroeder committed
44 45 46
}

// Criterion is cells whose scalars are less than lower threshold.
47
void vtkThresholdTextureCoords::ThresholdByLower(double lower)
Will Schroeder's avatar
Will Schroeder committed
48 49
{
  if ( this->LowerThreshold != lower )
50
  {
51
    this->LowerThreshold = lower;
Ken Martin's avatar
Ken Martin committed
52
    this->ThresholdFunction = &vtkThresholdTextureCoords::Lower;
Will Schroeder's avatar
Will Schroeder committed
53
    this->Modified();
54
  }
Will Schroeder's avatar
Will Schroeder committed
55
}
56

Will Schroeder's avatar
Will Schroeder committed
57
// Criterion is cells whose scalars are less than upper threshold.
Ken Martin's avatar
Ken Martin committed
58
void vtkThresholdTextureCoords::ThresholdByUpper(double upper)
Will Schroeder's avatar
Will Schroeder committed
59 60
{
  if ( this->UpperThreshold != upper )
61
  {
62
    this->UpperThreshold = upper;
Ken Martin's avatar
Ken Martin committed
63
    this->ThresholdFunction = &vtkThresholdTextureCoords::Upper;
Will Schroeder's avatar
Will Schroeder committed
64
    this->Modified();
65
  }
Will Schroeder's avatar
Will Schroeder committed
66
}
67

Will Schroeder's avatar
Will Schroeder committed
68
// Criterion is cells whose scalars are between lower and upper thresholds.
Ken Martin's avatar
Ken Martin committed
69
void vtkThresholdTextureCoords::ThresholdBetween(double lower, double upper)
Will Schroeder's avatar
Will Schroeder committed
70 71
{
  if ( this->LowerThreshold != lower || this->UpperThreshold != upper )
72
  {
73
    this->LowerThreshold = lower;
Will Schroeder's avatar
Will Schroeder committed
74
    this->UpperThreshold = upper;
Ken Martin's avatar
Ken Martin committed
75
    this->ThresholdFunction = &vtkThresholdTextureCoords::Between;
Will Schroeder's avatar
Will Schroeder committed
76
    this->Modified();
77
  }
Will Schroeder's avatar
Will Schroeder committed
78
}
79

80 81 82 83
int vtkThresholdTextureCoords::RequestData(
  vtkInformation *vtkNotUsed(request),
  vtkInformationVector **inputVector,
  vtkInformationVector *outputVector)
Will Schroeder's avatar
Will Schroeder committed
84
{
85 86 87 88
  // get the info objects
  vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
  vtkInformation *outInfo = outputVector->GetInformationObject(0);

89
  // get the input and output
90 91 92 93 94
  vtkDataSet *input = vtkDataSet::SafeDownCast(
    inInfo->Get(vtkDataObject::DATA_OBJECT()));
  vtkDataSet *output = vtkDataSet::SafeDownCast(
    outInfo->Get(vtkDataObject::DATA_OBJECT()));

Amy Squillacote's avatar
Amy Squillacote committed
95
  vtkIdType numPts;
96
  vtkFloatArray *newTCoords;
Amy Squillacote's avatar
Amy Squillacote committed
97
  vtkIdType ptId;
98
  vtkDataArray *inScalars;
Will Schroeder's avatar
Will Schroeder committed
99

Ken Martin's avatar
Ken Martin committed
100
  vtkDebugMacro(<< "Executing texture threshold filter");
Will Schroeder's avatar
Will Schroeder committed
101

102 103 104
  // First, copy the input to the output as a starting point
  output->CopyStructure( input );

105
  if ( ! (inScalars = input->GetPointData()->GetScalars()) )
106
  {
Ken Martin's avatar
Ken Martin committed
107
    vtkErrorMacro(<<"No scalar data to texture threshold");
108
    return 1;
109
  }
110

Will Schroeder's avatar
Will Schroeder committed
111
  numPts = input->GetNumberOfPoints();
112 113 114
  newTCoords = vtkFloatArray::New();
  newTCoords->SetNumberOfComponents(2);
  newTCoords->Allocate(2*this->TextureDimension);
Will Schroeder's avatar
Will Schroeder committed
115

Will Schroeder's avatar
Will Schroeder committed
116 117
  // Check that the scalars of each point satisfy the threshold criterion
  for (ptId=0; ptId < numPts; ptId++)
118
  {
119
    if ( (this->*(this->ThresholdFunction))(inScalars->GetComponent(ptId,0)) )
120
    {
121
      newTCoords->InsertTuple(ptId,this->InTextureCoord);
122
    }
Will Schroeder's avatar
Will Schroeder committed
123
    else //doesn't satisfy criterion
124
    {
125
      newTCoords->InsertTuple(ptId,this->OutTextureCoord);
126
    }
Will Schroeder's avatar
Will Schroeder committed
127

128
  } //for all points
Will Schroeder's avatar
Will Schroeder committed
129

Will Schroeder's avatar
Will Schroeder committed
130 131 132
  output->GetPointData()->CopyTCoordsOff();
  output->GetPointData()->PassData(input->GetPointData());

Ken Martin's avatar
Ken Martin committed
133
  output->GetPointData()->SetTCoords(newTCoords);
Will Schroeder's avatar
Will Schroeder committed
134
  newTCoords->Delete();
135 136

  return 1;
Will Schroeder's avatar
Will Schroeder committed
137 138
}

139
void vtkThresholdTextureCoords::PrintSelf(ostream& os, vtkIndent indent)
Will Schroeder's avatar
Will Schroeder committed
140
{
Brad King's avatar
Brad King committed
141
  this->Superclass::PrintSelf(os,indent);
Will Schroeder's avatar
Will Schroeder committed
142

Ken Martin's avatar
Ken Martin committed
143
  if ( this->ThresholdFunction == &vtkThresholdTextureCoords::Upper )
144
  {
Will Schroeder's avatar
Will Schroeder committed
145
    os << indent << "Threshold By Upper\n";
146
  }
Will Schroeder's avatar
Will Schroeder committed
147

Ken Martin's avatar
Ken Martin committed
148
  else if ( this->ThresholdFunction == &vtkThresholdTextureCoords::Lower )
149
  {
Will Schroeder's avatar
Will Schroeder committed
150
    os << indent << "Threshold By Lower\n";
151
  }
Will Schroeder's avatar
Will Schroeder committed
152

Ken Martin's avatar
Ken Martin committed
153
  else if ( this->ThresholdFunction == &vtkThresholdTextureCoords::Between )
154
  {
Will Schroeder's avatar
Will Schroeder committed
155
    os << indent << "Threshold Between\n";
156
  }
Will Schroeder's avatar
Will Schroeder committed
157 158 159 160

  os << indent << "Lower Threshold: " << this->LowerThreshold << "\n";;
  os << indent << "Upper Threshold: " << this->UpperThreshold << "\n";;
  os << indent << "Texture Dimension: " << this->TextureDimension << "\n";;
Will Schroeder's avatar
Will Schroeder committed
161

162
  os << indent << "Out Texture Coordinate: (" << this->OutTextureCoord[0]
Will Schroeder's avatar
Will Schroeder committed
163 164 165
     << ", " << this->OutTextureCoord[1]
     << ", " << this->OutTextureCoord[2] << ")\n";

166
  os << indent << "In Texture Coordinate: (" << this->InTextureCoord[0]
Will Schroeder's avatar
Will Schroeder committed
167 168
     << ", " << this->InTextureCoord[1]
     << ", " << this->InTextureCoord[2] << ")\n";
Will Schroeder's avatar
Will Schroeder committed
169
}