Commit 4a6b8d79 authored by Will Schroeder's avatar Will Schroeder Committed by Cory Quammen

Fix random cell data generation

Point arrays were being used when cell attributes were generated.
Fixed that and updated some tests.
parent 0a467f5b
......@@ -75,7 +75,9 @@ void CreateInputDataSet(vtkMultiBlockDataSet* dataset, int numberOfBlocks)
vtkNew<vtkRandomAttributeGenerator> randomAttrs;
randomAttrs->SetInputConnection(transFilter->GetOutputPort());
randomAttrs->GenerateAllPointDataOn();
randomAttrs->GeneratePointArrayOff();
randomAttrs->GenerateAllCellDataOn();
randomAttrs->GenerateCellArrayOff();
randomAttrs->GenerateFieldArrayOn();
randomAttrs->SetNumberOfTuples(100);
......
......@@ -35,6 +35,8 @@ ss.SetThetaResolution(32)
tg = vtk.vtkTensorGlyph()
tg.SetInputConnection(ag.GetOutputPort())
tg.SetSourceConnection(ss.GetOutputPort())
tg.SetInputArrayToProcess(1,0,0,0,"RandomPointArray")
tg.SetScaleFactor(0.1)
tg.SetMaxScaleFactor(10)
tg.ClampScalingOn()
......
......@@ -467,14 +467,14 @@ int vtkRandomAttributeGenerator::RequestData(
}
if ( this->GeneratePointArray)
{
vtkDataArray *ptScalars = this->GenerateData(this->DataType,numPts,
this->NumberOfComponents,0,
this->NumberOfComponents-1,
this->MinimumComponentValue,
this->MaximumComponentValue);
ptScalars->SetName("RandomPointArray");
output->GetPointData()->SetScalars(ptScalars);
ptScalars->Delete();
vtkDataArray *ptData = this->GenerateData(this->DataType,numPts,
this->NumberOfComponents,0,
this->NumberOfComponents-1,
this->MinimumComponentValue,
this->MaximumComponentValue);
ptData->SetName("RandomPointArray");
output->GetPointData()->AddArray(ptData);
ptData->Delete();
}
......@@ -488,79 +488,79 @@ int vtkRandomAttributeGenerator::RequestData(
// Now the cell data
if ( this->GenerateCellScalars)
{
vtkDataArray *ptScalars = this->GenerateData(this->DataType,numCells,
this->NumberOfComponents,0,
this->NumberOfComponents-1,
this->MinimumComponentValue,
this->MaximumComponentValue);
ptScalars->SetName("RandomCellScalars");
output->GetCellData()->SetScalars(ptScalars);
ptScalars->Delete();
vtkDataArray *cellScalars = this->GenerateData(this->DataType,numCells,
this->NumberOfComponents,0,
this->NumberOfComponents-1,
this->MinimumComponentValue,
this->MaximumComponentValue);
cellScalars->SetName("RandomCellScalars");
output->GetCellData()->SetScalars(cellScalars);
cellScalars->Delete();
}
if ( this->GenerateCellVectors)
{
vtkDataArray *ptVectors = this->GenerateData(this->DataType,numCells,3,0,2,
this->MinimumComponentValue,
this->MaximumComponentValue);
ptVectors->SetName("RandomCellVectors");
output->GetCellData()->SetVectors(ptVectors);
ptVectors->Delete();
vtkDataArray *cellVectors = this->GenerateData(this->DataType,numCells,3,0,2,
this->MinimumComponentValue,
this->MaximumComponentValue);
cellVectors->SetName("RandomCellVectors");
output->GetCellData()->SetVectors(cellVectors);
cellVectors->Delete();
}
if ( this->GenerateCellNormals)
{
vtkDataArray *ptNormals = this->GenerateData(this->DataType,numCells,3,0,2,
this->MinimumComponentValue,
this->MaximumComponentValue);
vtkDataArray *cellNormals = this->GenerateData(this->DataType,numCells,3,0,2,
this->MinimumComponentValue,
this->MaximumComponentValue);
double v[3];
for ( vtkIdType id=0; id < numCells; id++ )
{
ptNormals->GetTuple(id,v);
cellNormals->GetTuple(id,v);
vtkMath::Normalize(v);
ptNormals->SetTuple(id,v);
cellNormals->SetTuple(id,v);
}
output->GetCellData()->SetNormals(ptNormals);
ptNormals->Delete();
output->GetCellData()->SetNormals(cellNormals);
cellNormals->Delete();
}
if ( this->GenerateCellTensors)
{
vtkDataArray *ptTensors = this->GenerateData(this->DataType,numCells,9,0,5,
this->MinimumComponentValue,
this->MaximumComponentValue);
ptTensors->SetName("RandomCellTensors");
vtkDataArray *cellTensors = this->GenerateData(this->DataType,numCells,9,0,5,
this->MinimumComponentValue,
this->MaximumComponentValue);
cellTensors->SetName("RandomCellTensors");
double t[9];
for ( vtkIdType id=0; id < numCells; id++ )
{
ptTensors->GetTuple(id,t);
cellTensors->GetTuple(id,t);
t[6] = t[1];//make sure the tensor is symmetric
t[7] = t[2];
t[8] = t[4];
ptTensors->SetTuple(id,t);
cellTensors->SetTuple(id,t);
}
output->GetCellData()->SetTensors(ptTensors);
ptTensors->Delete();
output->GetCellData()->SetTensors(cellTensors);
cellTensors->Delete();
}
if ( this->GenerateCellTCoords)
{
int numComp = this->NumberOfComponents < 1 ? 1
: (this->NumberOfComponents > 3 ? 3 : this->NumberOfComponents);
vtkDataArray *ptTCoords = this->GenerateData(this->DataType,numCells,
numComp,0,
this->NumberOfComponents-1,
this->MinimumComponentValue,
this->MaximumComponentValue);
output->GetCellData()->SetTCoords(ptTCoords);
ptTCoords->Delete();
vtkDataArray *cellTCoords = this->GenerateData(this->DataType,numCells,
numComp,0,
this->NumberOfComponents-1,
this->MinimumComponentValue,
this->MaximumComponentValue);
output->GetCellData()->SetTCoords(cellTCoords);
cellTCoords->Delete();
}
if ( this->GenerateCellArray)
{
vtkDataArray *ptScalars = this->GenerateData(this->DataType,numCells,
vtkDataArray *cellArray = this->GenerateData(this->DataType,numCells,
this->NumberOfComponents,0,
this->NumberOfComponents-1,
this->MinimumComponentValue,
this->MaximumComponentValue);
ptScalars->SetName("RandomCellArray");
output->GetCellData()->SetScalars(ptScalars);
ptScalars->Delete();
cellArray->SetName("RandomCellArray");
output->GetCellData()->AddArray(cellArray);
cellArray->Delete();
}
// Finally any field data
......
......@@ -59,13 +59,14 @@ class vtkCompositeDataSet;
class VTKFILTERSGENERAL_EXPORT vtkRandomAttributeGenerator : public vtkPassInputTypeAlgorithm
{
public:
//@{
/**
* Create instance with minimum speed 0.0, maximum speed 1.0.
* Standard methods for construction, type info, and printing.
*/
static vtkRandomAttributeGenerator *New();
vtkTypeMacro(vtkRandomAttributeGenerator,vtkPassInputTypeAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent) override;
//@}
//@{
/**
......@@ -189,8 +190,11 @@ public:
//@{
/**
* Indicate that an arbitrary point array is to be generated. Note that the
* specified number of components is used to create the array.
* Indicate that an arbitrary point array is to be generated. The array is
* added to the points data but is not labeled as one of scalars, vectors,
* normals, tensors, or texture coordinates (i.e., AddArray() is
* used). Note that the specified number of components is used to create
* the array.
*/
vtkSetMacro(GeneratePointArray,vtkTypeBool);
vtkGetMacro(GeneratePointArray,vtkTypeBool);
......@@ -250,8 +254,11 @@ public:
//@{
/**
* Indicate that an arbitrary cell array is to be generated. Note that the
* specified number of components is used to create the array.
* Indicate that an arbitrary cell array is to be generated. The array is
* added to the cell data but is not labeled as one of scalars, vectors,
* normals, tensors, or texture coordinates array (i.e., AddArray() is
* used). Note that the specified number of components is used to create
* the array.
*/
vtkSetMacro(GenerateCellArray,vtkTypeBool);
vtkGetMacro(GenerateCellArray,vtkTypeBool);
......
......@@ -38,6 +38,7 @@
#include "vtkPointSource.h"
#include "vtkProperty.h"
#include "vtkRandomAttributeGenerator.h"
#include "vtkPointData.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
......@@ -79,6 +80,8 @@ int TestPointGaussianMapperOpacity(int argc, char *argv[])
randomAttr->GeneratePointVectorsOn();
randomAttr->GeneratePointArrayOn();
randomAttr->Update();
vtkDataSet *output = static_cast<vtkDataSet*>(randomAttr->GetOutput());
output->GetPointData()->SetScalars(output->GetPointData()->GetArray("RandomPointArray"));
mapper->SetInputConnection(randomAttr->GetOutputPort());
mapper->SetColorModeToMapScalars();
......@@ -86,7 +89,7 @@ int TestPointGaussianMapperOpacity(int argc, char *argv[])
mapper->SelectColorArray("RandomPointVectors");
mapper->SetInterpolateScalarsBeforeMapping(0);
mapper->SetScaleArray("RandomPointScalars");
mapper->SetScaleArrayComponent(1);
mapper->SetScaleArrayComponent(1); //tests clamping to zero-th component
mapper->SetOpacityArray("RandomPointArray");
mapper->SetOpacityArrayComponent(0);
mapper->EmissiveOff();
......
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