31 #include "vtkArrowSource.h"
32 #include "vtkColorTransferFunction.h"
33 #include "vtkFloatArray.h"
34 #include "vtkGlyph3D.h"
35 #include "vtkLookupTable.h"
36 #include "vtkPointData.h"
37 #include "vtkPolyData.h"
38 #include "vtkPolyDataMapper.h"
39 #include "vtkRenderer.h"
40 #include "vtkScalarBarActor.h"
41 #include "vtkSmartPointer.h"
42 #include "vtkSphereSource.h"
43 #include "vtkTextActor.h"
44 #include "vtkTextProperty.h"
80 lut->SetNumberOfColors(nColours);
82 vtkSmartPointer<vtkColorTransferFunction> ctf =
89 ctf->SetColorSpaceToHSV();
90 ctf->AddRGBPoint(0, 0, 0, 1);
91 ctf->AddRGBPoint(0.5, 0, 1, 0);
92 ctf->AddRGBPoint(1, 1, 0, 0);
98 ctf->SetColorSpaceToDiverging();
99 ctf->AddRGBPoint(0.0, 0.231373, 0.298039, 0.752941);
100 ctf->AddRGBPoint(0.5, 0.865003, 0.865003, 0.865003);
101 ctf->AddRGBPoint(1.0, 0.705882, 0.0156863, 0.14902);
107 ctf->SetColorSpaceToRGB();
108 ctf->AddRGBPoint(0, 0, 0, 0);
109 ctf->AddRGBPoint(0.4, 0.901961, 0, 0);
110 ctf->AddRGBPoint(0.8, 0.901961, 0.901961, 0);
111 ctf->AddRGBPoint(1, 1, 1, 1);
116 ctf->SetColorSpaceToRGB();
117 ctf->AddRGBPoint(0, 0, 0, 0);
118 ctf->AddRGBPoint(1, 1, 1, 1);
124 for (
label i = 0; i < nColours; i++)
126 double*
c = ctf->GetColor(scalar(i)/scalar(nColours));
127 lut->SetTableValue(i,
c[0],
c[1],
c[2], 1.0);
134 const scalar position,
135 vtkRenderer* renderer,
140 if (!scalarBar_.visible_)
145 vtkSmartPointer<vtkScalarBarActor> sbar =
147 sbar->SetLookupTable(lut);
148 sbar->SetNumberOfLabels(scalarBar_.numberOfLabels_);
150 const vector textColour = colours_[
"text"]->value(position);
153 vtkSmartPointer<vtkTextActor> titleActor =
156 titleActor->SetInput(scalarBar_.title_.c_str());
157 titleActor->GetTextProperty()->SetFontFamilyToArial();
158 titleActor->GetTextProperty()->SetFontSize(3*scalarBar_.fontSize_);
159 titleActor->GetTextProperty()->SetJustificationToCentered();
160 titleActor->GetTextProperty()->SetVerticalJustificationToBottom();
161 titleActor->GetTextProperty()->BoldOn();
162 titleActor->GetTextProperty()->ItalicOff();
163 titleActor->GetTextProperty()->SetColor
169 titleActor->GetPositionCoordinate()->
170 SetCoordinateSystemToNormalizedViewport();
186 sbar->GetLabelTextProperty()->SetColor
192 sbar->GetLabelTextProperty()->SetFontSize(scalarBar_.fontSize_);
193 sbar->GetLabelTextProperty()->ShadowOff();
194 sbar->GetLabelTextProperty()->BoldOff();
195 sbar->GetLabelTextProperty()->ItalicOff();
196 sbar->SetLabelFormat(scalarBar_.labelFormat_.c_str());
198 sbar->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
199 sbar->GetPositionCoordinate()->SetValue
201 scalarBar_.position_.first(),
202 scalarBar_.position_.second()
204 if (scalarBar_.vertical_)
206 sbar->SetOrientationToVertical();
208 sbar->SetHeight(0.75);
209 sbar->SetTextPositionToSucceedScalarBar();
213 sbar->SetOrientationToHorizontal();
216 sbar->SetWidth(0.75);
217 sbar->SetHeight(0.07);
218 sbar->SetBarRatio(0.5);
221 sbar->SetTextPositionToPrecedeScalarBar();
224 titleActor->GetPositionCoordinate()->SetValue
226 scalarBar_.position_.first() + 0.5*sbar->GetWidth(),
227 scalarBar_.position_.second() + sbar->GetHeight()
234 sbar->VisibilityOn();
236 renderer->AddActor(sbar);
237 renderer->AddActor2D(titleActor);
243 const scalar position,
244 const word& colourFieldName,
245 vtkPolyDataMapper* mapper,
246 vtkRenderer* renderer
249 mapper->InterpolateScalarsBeforeMappingOn();
255 mapper->ScalarVisibilityOff();
261 vtkSmartPointer<vtkLookupTable> lut =
264 lut->SetVectorMode(vtkScalarsToColors::MAGNITUDE);
267 mapper->SelectColorArray(colourFieldName.c_str());
268 mapper->SetScalarRange(range_.first(), range_.second());
269 mapper->SetScalarModeToUsePointFieldData();
271 mapper->SetColorModeToMapScalars();
272 mapper->SetLookupTable(lut);
273 mapper->ScalarVisibilityOn();
276 addScalarBar(position, renderer, lut);
288 const scalar position,
289 const word& scaleFieldName,
290 const word& colourFieldName,
291 const scalar maxGlyphLength,
294 vtkRenderer* renderer
298 vtkSmartPointer<vtkPolyDataMapper> glyphMapper =
300 glyphMapper->SetInputConnection(glyph->GetOutputPort());
302 glyph->SetInputData(
data);
307 data->GetPointData()->GetArray(scaleFieldName.c_str())
308 ->GetNumberOfComponents();
310 if (nComponents == 1)
312 vtkSmartPointer<vtkSphereSource> sphere =
314 sphere->SetCenter(0, 0, 0);
315 sphere->SetRadius(0.5);
320 glyph->SetSourceConnection(sphere->GetOutputPort());
322 if (maxGlyphLength > 0)
332 range[0] = range_.first();
333 range[1] = range_.second();
335 glyph->SetRange(
range);
339 glyph->SetScaleFactor(maxGlyphLength);
343 glyph->SetScaleFactor(1);
345 glyph->SetScaleModeToScaleByScalar();
347 glyph->SetColorModeToColorByScalar();
348 glyph->SetInputArrayToProcess
353 vtkDataObject::FIELD_ASSOCIATION_POINTS,
354 scaleFieldName.c_str()
357 else if (nComponents == 3)
359 vtkSmartPointer<vtkArrowSource> arrow =
361 arrow->SetTipResolution(10);
362 arrow->SetTipRadius(0.1);
363 arrow->SetTipLength(0.35);
364 arrow->SetShaftResolution(10);
365 arrow->SetShaftRadius(0.03);
367 glyph->SetSourceConnection(arrow->GetOutputPort());
369 if (maxGlyphLength > 0)
371 vtkDataArray* values =
372 data->GetPointData()->GetVectors(scaleFieldName.c_str());
374 values->GetRange(
range);
388 glyph->SetRange(
range);
389 glyph->SetScaleFactor(maxGlyphLength);
393 glyph->SetScaleFactor(1);
395 glyph->SetScaleModeToScaleByVector();
397 glyph->SetVectorModeToUseVector();
398 glyph->SetColorModeToColorByVector();
399 glyph->SetInputArrayToProcess
404 vtkDataObject::FIELD_ASSOCIATION_POINTS,
405 scaleFieldName.c_str()
413 <<
" Field " << scaleFieldName <<
" has " << nComponents
414 <<
" components" <<
endl;
423 setField(position, colourFieldName, glyphMapper, renderer);
425 glyphMapper->Update();
427 actor->SetMapper(glyphMapper);
429 renderer->AddActor(actor);
447 colourMap_(cmRainbow),
450 colourBy_ = colourByTypeNames.read(
dict.
lookup(
"colourBy"));
471 sbarDict.
lookup(
"visible") >> scalarBar_.visible_;
472 if (scalarBar_.visible_)
474 sbarDict.
lookup(
"vertical") >> scalarBar_.vertical_;
475 sbarDict.
lookup(
"position") >> scalarBar_.position_;
476 sbarDict.
lookup(
"title") >> scalarBar_.title_;
477 sbarDict.
lookup(
"fontSize") >> scalarBar_.fontSize_;
478 sbarDict.
lookup(
"labelFormat") >> scalarBar_.labelFormat_;
479 sbarDict.
lookup(
"numberOfLabels") >> scalarBar_.numberOfLabels_;