BUG: runTimePostProcessing - correct the glyph behaviour when dealing with cell data. Fixes #186

This commit is contained in:
Andrew Heather
2016-07-22 15:32:17 +01:00
parent 2d695acf49
commit cd8be89b28

View File

@ -43,6 +43,7 @@ License
#include "vtkSphereSource.h" #include "vtkSphereSource.h"
#include "vtkTextActor.h" #include "vtkTextActor.h"
#include "vtkTextProperty.h" #include "vtkTextProperty.h"
#include "vtkCellDataToPointData.h"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@ -151,6 +152,9 @@ void Foam::fieldVisualisationBase::addScalarBar
const vector textColour = colours_["text"]->value(position); const vector textColour = colours_["text"]->value(position);
// Work-around to supply our own scalarbar title // Work-around to supply our own scalarbar title
// - Default scalar bar title text is scales by the scalar bar box
// dimensions so if the title is a long string, the text is shrunk to fit
// Instead, suppress title and set the title using a vtkTextActor
vtkSmartPointer<vtkTextActor> titleActor = vtkSmartPointer<vtkTextActor> titleActor =
vtkSmartPointer<vtkTextActor>::New(); vtkSmartPointer<vtkTextActor>::New();
sbar->SetTitle(" "); sbar->SetTitle(" ");
@ -170,19 +174,18 @@ void Foam::fieldVisualisationBase::addScalarBar
titleActor->GetPositionCoordinate()-> titleActor->GetPositionCoordinate()->
SetCoordinateSystemToNormalizedViewport(); SetCoordinateSystemToNormalizedViewport();
/* // How to use the standard scalar bar text
sbar->SetTitle(scalarBar_.title_.c_str()); // sbar->SetTitle(scalarBar_.title_.c_str());
sbar->GetTitleTextProperty()->SetColor // sbar->GetTitleTextProperty()->SetColor
( // (
textColour[0], // textColour[0],
textColour[1], // textColour[1],
textColour[2] // textColour[2]
); // );
sbar->GetTitleTextProperty()->SetFontSize(scalarBar_.fontSize_); // sbar->GetTitleTextProperty()->SetFontSize(scalarBar_.fontSize_);
sbar->GetTitleTextProperty()->ShadowOff(); // sbar->GetTitleTextProperty()->ShadowOff();
sbar->GetTitleTextProperty()->BoldOn(); // sbar->GetTitleTextProperty()->BoldOn();
sbar->GetTitleTextProperty()->ItalicOff(); // sbar->GetTitleTextProperty()->ItalicOff();
*/
sbar->GetLabelTextProperty()->SetColor sbar->GetLabelTextProperty()->SetColor
( (
@ -217,8 +220,8 @@ void Foam::fieldVisualisationBase::addScalarBar
sbar->SetWidth(0.75); sbar->SetWidth(0.75);
sbar->SetHeight(0.07); sbar->SetHeight(0.07);
sbar->SetBarRatio(0.5); sbar->SetBarRatio(0.5);
// sbar->SetHeight(0.1); // sbar->SetHeight(0.1);
// sbar->SetTitleRatio(0.01); // sbar->SetTitleRatio(0.01);
sbar->SetTextPositionToPrecedeScalarBar(); sbar->SetTextPositionToPrecedeScalarBar();
} }
@ -228,10 +231,10 @@ void Foam::fieldVisualisationBase::addScalarBar
scalarBar_.position_.second() + sbar->GetHeight() scalarBar_.position_.second() + sbar->GetHeight()
); );
// sbar->DrawFrameOn(); // sbar->DrawFrameOn();
// sbar->DrawBackgroundOn(); // sbar->DrawBackgroundOn();
// sbar->UseOpacityOff(); // sbar->UseOpacityOff();
// sbar->VisibilityOff(); // sbar->VisibilityOff();
sbar->VisibilityOn(); sbar->VisibilityOn();
renderer->AddActor(sbar); renderer->AddActor(sbar);
@ -268,25 +271,7 @@ void Foam::fieldVisualisationBase::setField
// Configure the mapper // Configure the mapper
mapper->SelectColorArray(colourFieldName.c_str()); mapper->SelectColorArray(colourFieldName.c_str());
mapper->SetScalarRange(range_.first(), range_.second()); mapper->SetScalarRange(range_.first(), range_.second());
mapper->SetScalarModeToDefault(); // try points, then cells
// Set to use either cell or point data
const char* fieldName = colourFieldName.c_str();
if (pData->GetCellData()->HasArray(fieldName) == 1)
{
mapper->SetScalarModeToUseCellFieldData();
}
else if (pData->GetPointData()->HasArray(fieldName) == 1)
{
mapper->SetScalarModeToUsePointFieldData();
}
else
{
WarningInFunction
<< "Unable to determine cell or point data type "
<< "- assuming point data";
mapper->SetScalarModeToUsePointFieldData();
}
mapper->SetColorModeToMapScalars(); mapper->SetColorModeToMapScalars();
mapper->SetLookupTable(lut); mapper->SetLookupTable(lut);
mapper->ScalarVisibilityOn(); mapper->ScalarVisibilityOn();
@ -322,9 +307,37 @@ void Foam::fieldVisualisationBase::addGlyphs
glyph->ScalingOn(); glyph->ScalingOn();
bool ok = true; bool ok = true;
label nComponents = // Determine whether we have scalar or vector data
data->GetPointData()->GetArray(scaleFieldName.c_str()) label nComponents = -1;
const char* scaleFieldNameChar = scaleFieldName.c_str();
if (data->GetPointData()->HasArray(scaleFieldNameChar) == 1)
{
nComponents =
data->GetPointData()->GetArray(scaleFieldNameChar)
->GetNumberOfComponents(); ->GetNumberOfComponents();
}
else if (data->GetCellData()->HasArray(scaleFieldNameChar) == 1)
{
// Need to convert cell data to point data
vtkSmartPointer<vtkCellDataToPointData> cellToPoint =
vtkSmartPointer<vtkCellDataToPointData>::New();
cellToPoint->SetInputData(data);
cellToPoint->Update();
vtkDataSet* pds = cellToPoint->GetOutput();
vtkDataArray* pData = pds->GetPointData()->GetArray(scaleFieldNameChar);
// Store in main vtkPolyData
data->GetPointData()->AddArray(pData);
nComponents = pData->GetNumberOfComponents();
}
else
{
WarningInFunction
<< "Glyphs can only be added to scalar or vector data. "
<< "Unable to process field " << scaleFieldName << endl;
return;
}
if (nComponents == 1) if (nComponents == 1)
{ {
@ -332,9 +345,10 @@ void Foam::fieldVisualisationBase::addGlyphs
vtkSmartPointer<vtkSphereSource>::New(); vtkSmartPointer<vtkSphereSource>::New();
sphere->SetCenter(0, 0, 0); sphere->SetCenter(0, 0, 0);
sphere->SetRadius(0.5); sphere->SetRadius(0.5);
// Setting higher resolution slows the rendering significantly
// sphere->SetPhiResolution(20); // Setting higher resolution slows the rendering significantly
// sphere->SetThetaResolution(20); // sphere->SetPhiResolution(20);
// sphere->SetThetaResolution(20);
glyph->SetSourceConnection(sphere->GetOutputPort()); glyph->SetSourceConnection(sphere->GetOutputPort());
@ -342,18 +356,18 @@ void Foam::fieldVisualisationBase::addGlyphs
{ {
double range[2]; double range[2];
// Can use values to find range // Can use values to find range
// vtkDataArray* values = // vtkDataArray* values =
// data->GetPointData()->GetScalars(scaleFieldName.c_str()); // data->GetPointData()->GetScalars(scaleFieldNameChar);
// values->GetRange(range); // values->GetRange(range);
// set range accoding to user-supplied limits // Set range accoding to user-supplied limits
range[0] = range_.first(); range[0] = range_.first();
range[1] = range_.second(); range[1] = range_.second();
glyph->ClampingOn(); glyph->ClampingOn();
glyph->SetRange(range); glyph->SetRange(range);
// if range[0] != min(value), maxGlyphLength behaviour will not // If range[0] != min(value), maxGlyphLength behaviour will not
// be correct... // be correct...
glyph->SetScaleFactor(maxGlyphLength); glyph->SetScaleFactor(maxGlyphLength);
} }
@ -370,7 +384,7 @@ void Foam::fieldVisualisationBase::addGlyphs
0, 0,
0, 0,
vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataObject::FIELD_ASSOCIATION_POINTS,
scaleFieldName.c_str() scaleFieldNameChar
); );
} }
else if (nComponents == 3) else if (nComponents == 3)
@ -388,21 +402,21 @@ void Foam::fieldVisualisationBase::addGlyphs
if (maxGlyphLength > 0) if (maxGlyphLength > 0)
{ {
vtkDataArray* values = vtkDataArray* values =
data->GetPointData()->GetVectors(scaleFieldName.c_str()); data->GetPointData()->GetVectors(scaleFieldNameChar);
double range[6]; double range[6];
values->GetRange(range); values->GetRange(range);
/*
// Attempt to set range for vectors... // Attempt to set range for vectors...
scalar x0 = sqrt(sqr(range_.first())/3.0); // scalar x0 = sqrt(sqr(range_.first())/3.0);
scalar x1 = sqrt(sqr(range_.second())/3.0); // scalar x1 = sqrt(sqr(range_.second())/3.0);
range[0] = x0; // range[0] = x0;
range[1] = x0; // range[1] = x0;
range[2] = x0; // range[2] = x0;
range[3] = x1; // range[3] = x1;
range[4] = x1; // range[4] = x1;
range[5] = x1; // range[5] = x1;
*/
glyph->ClampingOn(); glyph->ClampingOn();
glyph->SetRange(range); glyph->SetRange(range);
glyph->SetScaleFactor(maxGlyphLength); glyph->SetScaleFactor(maxGlyphLength);
@ -421,7 +435,7 @@ void Foam::fieldVisualisationBase::addGlyphs
0, 0,
0, 0,
vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataObject::FIELD_ASSOCIATION_POINTS,
scaleFieldName.c_str() scaleFieldNameChar
); );
} }
else else