36 #include "vtkArrowSource.h"
37 #include "vtkCellDataToPointData.h"
38 #include "vtkCellData.h"
39 #include "vtkColorTransferFunction.h"
40 #include "vtkCompositeDataSet.h"
41 #include "vtkDataObjectTreeIterator.h"
42 #include "vtkFieldData.h"
43 #include "vtkGlyph3D.h"
44 #include "vtkLookupTable.h"
45 #include "vtkPointData.h"
46 #include "vtkPolyData.h"
47 #include "vtkPolyDataMapper.h"
48 #include "vtkRenderer.h"
49 #include "vtkSmartPointer.h"
50 #include "vtkSphereSource.h"
56 Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
62 { colourByType::cbColour,
"colour" },
63 { colourByType::cbField,
"field" },
68 Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
74 { colourMapType::cmCoolToWarm,
"coolToWarm" },
75 { colourMapType::cmCoolToWarm,
"blueWhiteRed" },
76 { colourMapType::cmColdAndHot,
"coldAndHot" },
77 { colourMapType::cmFire,
"fire" },
78 { colourMapType::cmRainbow,
"rainbow" },
79 { colourMapType::cmGreyscale,
"greyscale" },
80 { colourMapType::cmGreyscale,
"grayscale" },
81 { colourMapType::cmXray,
"xray" },
91 const word& fieldName,
101 array = vtkDataArray::SafeDownCast
103 dataset->GetCellData()->GetAbstractArray(fieldName.c_str())
113 array = vtkDataArray::SafeDownCast
115 dataset->GetPointData()->GetAbstractArray(fieldName.c_str())
134 const word& fieldName,
135 vtkCompositeDataSet*
data
142 iter->SetDataSet(
data);
143 iter->VisitOnlyLeavesOn();
144 iter->SkipEmptyNodesOn();
148 iter->InitTraversal();
149 !iter->IsDoneWithTraversal();
153 vtkDataSet* dataset = vtkDataSet::SafeDownCast
155 iter->GetCurrentDataObject()
160 fieldSummary local(queryFieldSummary(fieldName, dataset));
180 const word& fieldName,
188 if (dataset->GetCellData()->HasArray(fieldName.c_str()))
190 where |= FieldAssociation::CELL_DATA;
192 if (dataset->GetPointData()->HasArray(fieldName.c_str()))
206 const word& fieldName,
207 vtkCompositeDataSet*
data
214 iter->SetDataSet(
data);
215 iter->VisitOnlyLeavesOn();
216 iter->SkipEmptyNodesOn();
220 iter->InitTraversal();
221 !iter->IsDoneWithTraversal();
225 vtkDataSet* dataset = vtkDataSet::SafeDownCast
227 iter->GetCurrentDataObject()
230 where |= queryFieldAssociation(fieldName, dataset);
239 const word& fieldName,
248 vtkDataArray* input = vtkDataArray::SafeDownCast
250 fieldData->GetAbstractArray(fieldName.c_str())
258 const word magFieldName =
"mag(" + fieldName +
")";
260 vtkDataArray* output = vtkDataArray::SafeDownCast
262 fieldData->GetAbstractArray(magFieldName.c_str())
273 const int nCmpt = input->GetNumberOfComponents();
274 const vtkIdType len = input->GetNumberOfTuples();
280 data->SetName(magFieldName.c_str());
281 data->SetNumberOfComponents(1);
282 data->SetNumberOfTuples(len);
285 for (vtkIdType i=0; i < len; ++i)
287 input->GetTuple(i, &scratch);
290 data->SetTuple(i, &scratch);
299 data->SetName(magFieldName.c_str());
300 data->SetNumberOfComponents(1);
301 data->SetNumberOfTuples(len);
304 for (vtkIdType i=0; i < len; ++i)
306 input->GetTuple(i, scratch.
v_);
310 data->SetTuple(i, scratch.
v_);
320 const word& fieldName,
326 addMagField(fieldName, dataset->GetCellData());
327 addMagField(fieldName, dataset->GetPointData());
334 const word& fieldName,
335 vtkCompositeDataSet*
data
340 iter->SetDataSet(
data);
341 iter->VisitOnlyLeavesOn();
342 iter->SkipEmptyNodesOn();
346 iter->InitTraversal();
347 !iter->IsDoneWithTraversal();
351 vtkDataSet* dataset = vtkDataSet::SafeDownCast
353 iter->GetCurrentDataObject()
355 addMagField(fieldName, dataset);
383 os <<
"nComponents:" << proxy.t_.nComponents_
384 <<
" association:" <<
label(proxy.t_.association_)
385 <<
" min/max:" << proxy.t_.range_;
399 constexpr
label nColours = 256;
401 lut->SetNumberOfColors(nColours);
409 ctf->SetColorSpaceToDiverging();
410 ctf->AddRGBPoint(0.0, 0.231372, 0.298039, 0.752941);
411 ctf->AddRGBPoint(0.5, 0.865003, 0.865003, 0.865003);
412 ctf->AddRGBPoint(1.0, 0.705882, 0.0156863, 0.14902);
419 ctf->SetColorSpaceToRGB();
420 ctf->AddRGBPoint(0, 0, 1, 1);
421 ctf->AddRGBPoint(0.45, 0, 0, 1);
422 ctf->AddRGBPoint(0.5, 0, 0, 0.5019608);
423 ctf->AddRGBPoint(0.55, 1, 0, 0);
424 ctf->AddRGBPoint(1, 1, 1, 0);
430 ctf->SetColorSpaceToRGB();
431 ctf->AddRGBPoint(0, 0, 0, 0);
432 ctf->AddRGBPoint(0.4, 0.901961, 0, 0);
433 ctf->AddRGBPoint(0.8, 0.901961, 0.901961, 0);
434 ctf->AddRGBPoint(1, 1, 1, 1);
441 ctf->SetColorSpaceToHSV();
442 ctf->AddRGBPoint(0, 0, 0, 1);
443 ctf->AddRGBPoint(0.5, 0, 1, 0);
444 ctf->AddRGBPoint(1, 1, 0, 0);
451 ctf->SetColorSpaceToRGB();
452 ctf->AddRGBPoint(0, 0, 0, 0);
453 ctf->AddRGBPoint(1, 1, 1, 1);
460 ctf->SetColorSpaceToRGB();
461 ctf->AddRGBPoint(0, 1, 1, 1);
462 ctf->AddRGBPoint(1, 0, 0, 0);
469 double rgba[4] = { 0, 0, 0, 1 };
470 for (
label i = 0; i < nColours; ++i)
472 ctf->GetColor(scalar(i)/scalar(nColours), rgba);
473 lut->SetTableValue(i, rgba);
481 const scalar position,
482 vtkRenderer* renderer,
489 scalarBar_.add(colours_[
"text"]->value(position), renderer, lut);
497 const scalar position,
498 const word& colourFieldName,
501 vtkRenderer* renderer
504 mapper->InterpolateScalarsBeforeMappingOn();
510 mapper->ScalarVisibilityOff();
519 lut->SetVectorMode(vtkScalarsToColors::MAGNITUDE);
520 lut->SetTableRange(range_.first(), range_.second());
523 const char* fieldName = colourFieldName.c_str();
524 mapper->SelectColorArray(fieldName);
532 mapper->SetScalarModeToUsePointFieldData();
534 else if (fieldAssociation & FieldAssociation::CELL_DATA)
536 mapper->SetScalarModeToUseCellFieldData();
541 <<
"Unable to determine cell or point data type "
542 <<
"- assuming point data";
543 mapper->SetScalarModeToUsePointFieldData();
545 mapper->SetScalarRange(range_.first(), range_.second());
546 mapper->SetColorModeToMapScalars();
547 mapper->SetLookupTable(lut);
548 mapper->ScalarVisibilityOn();
551 addScalarBar(position, renderer, lut);
563 const scalar position,
564 const word& scaleFieldName,
566 const word& colourFieldName,
568 const scalar maxGlyphLength,
572 vtkRenderer* renderer
578 if (!scaleFieldInfo.
exists())
581 <<
"Cannot add glyphs. No such cell or point field: "
582 << scaleFieldName <<
endl;
589 <<
"Glyphs can only be added to scalar or vector data. "
590 <<
"Unable to process field " << scaleFieldName <<
endl;
606 glyphMapper->SetInputConnection(glyph->GetOutputPort());
617 glyph->SetInputConnection(
cellToPoint->GetOutputPort());
621 glyph->SetInputData(
data);
628 sphere->SetCenter(0, 0, 0);
635 glyph->SetSourceConnection(
sphere->GetOutputPort());
637 if (maxGlyphLength > 0)
648 glyph->SetRange(range_.first(), range_.second());
652 glyph->SetScaleFactor(maxGlyphLength);
656 glyph->SetScaleFactor(1);
658 glyph->SetScaleModeToScaleByScalar();
660 glyph->SetColorModeToColorByScalar();
661 glyph->SetInputArrayToProcess
666 vtkDataObject::FIELD_ASSOCIATION_POINTS,
667 scaleFieldName.c_str()
673 arrow->SetTipResolution(10);
674 arrow->SetTipRadius(0.1);
675 arrow->SetTipLength(0.35);
676 arrow->SetShaftResolution(10);
677 arrow->SetShaftRadius(0.03);
679 glyph->SetSourceConnection(arrow->GetOutputPort());
681 if (maxGlyphLength > 0)
687 scaleFieldInfo.
range_.first(),
688 scaleFieldInfo.
range_.second()
690 glyph->SetScaleFactor(maxGlyphLength);
694 glyph->SetScaleFactor(1);
696 glyph->SetScaleModeToScaleByVector();
698 glyph->SetVectorModeToUseVector();
699 glyph->SetColorModeToColorByVector();
700 glyph->SetInputArrayToProcess
705 vtkDataObject::FIELD_ASSOCIATION_POINTS,
706 scaleFieldName.c_str()
727 glyphMapper->Update();
729 actor->SetMapper(glyphMapper);
731 renderer->AddActor(actor);
746 fieldName_(
dict.get<
word>(
"field")),
747 smooth_(
dict.getOrDefault(
"smooth",
false)),
749 colourMap_(cmRainbow),
753 colourByTypeNames.readEntry(
"colourBy",
dict, colourBy_);
765 dict.readEntry(
"range", range_);
766 colourMapTypeNames.readIfPresent(
"colourMap",
dict, colourMap_);
772 scalarBar_.read(*sbar);