VTK  9.0.20210616
vtkWordCloud.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkWordCloud.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 #ifndef vtkWordCloud_h
16 #define vtkWordCloud_h
17 
18 #include "vtkImageAlgorithm.h"
19 #include "vtkImageData.h" // For ImageData
20 #include "vtkInfovisCoreModule.h" // For export macro
21 #include "vtkSmartPointer.h" // For SmartPointer
22 
23 #include <array> // For stl array
24 #include <functional> // for function
25 #include <set> // for stl multiset
26 #include <string> // For stl string
27 #include <vector> // For stl vector
28 
184 class VTKINFOVISCORE_EXPORT vtkWordCloud : public vtkImageAlgorithm
185 {
186 public:
188  void PrintSelf(ostream& os, vtkIndent indent) override;
189 
193  static vtkWordCloud* New();
194 
195  // Typedefs
196  using ColorDistributionContainer = std::array<double, 2>;
197  using OffsetDistributionContainer = std::array<int, 2>;
198  using OrientationDistributionContainer = std::array<double, 2>;
199  using OrientationsContainer = std::vector<double>;
200  using PairType = std::tuple<std::string, std::string>;
201  using ReplacementPairsContainer = std::vector<PairType>;
202  using SizesContainer = std::array<int, 2>;
203  using StopWordsContainer = std::set<std::string>;
204  using StringContainer = std::vector<std::string>;
205 
207 
210  virtual SizesContainer GetAdjustedSizes() { return AdjustedSizes; }
212 
213 #define SetStdContainerMacro(name, container) \
214  virtual void Set##name(container arg) \
215  { \
216  bool changed = false; \
217  if (arg.size() != name.size()) \
218  { \
219  changed = true; \
220  } \
221  else \
222  { \
223  auto a = arg.begin(); \
224  for (auto r : name) \
225  { \
226  if (*a != r) \
227  { \
228  changed = true; \
229  } \
230  a++; \
231  } \
232  } \
233  if (changed) \
234  { \
235  name = arg; \
236  this->Modified(); \
237  } \
238  }
239 
241 
244  virtual void SetBackgroundColorName(std::string arg)
246  {
247  if (arg != BackgroundColorName)
248  {
249  this->Modified();
250  BackgroundColorName = arg;
251  }
252  }
253  virtual std::string GetBackgroundColorName() { return BackgroundColorName; }
254 
256 
260  virtual void SetBWMask(bool arg)
262  {
263  if (BWMask != arg)
264  {
265  this->Modified();
266  BWMask = arg;
267  }
268  }
269  virtual bool GetBWMask() { return BWMask; }
270 
272 
278  virtual void SetColorSchemeName(std::string arg)
280  {
281  if (ColorSchemeName != arg)
282  {
283  this->Modified();
284  ColorSchemeName = arg;
285  }
286  }
287  virtual std::string GetColorSchemeName() { return ColorSchemeName; }
288 
290 
296  vtkSetMacro(DPI, int);
298  vtkGetMacro(DPI, int);
299 
301 
305  virtual void SetFileName(std::string arg)
307  {
308  if (FileName != arg)
309  {
310  this->Modified();
311  FileName = arg;
312  }
313  }
314  virtual std::string GetFileName() { return FileName; }
315 
317 
322  virtual void SetFontFileName(std::string arg)
324  {
325  if (FontFileName != arg)
326  {
327  this->Modified();
328  FontFileName = arg;
329  }
330  }
331  virtual std::string GetFontFileName() { return FontFileName; }
332 
334 
338  vtkSetMacro(Gap, int);
340  vtkGetMacro(Gap, int);
341 
343 
348  virtual void SetMaskColorName(std::string arg)
350  {
351  if (MaskColorName != arg)
352  {
353  this->Modified();
354  MaskColorName = arg;
355  }
356  }
357  virtual std::string GetMaskColorName() { return MaskColorName; }
358 
360 
369  virtual void SetMaskFileName(std::string arg)
371  {
372  if (MaskFileName != arg)
373  {
374  this->Modified();
375  MaskFileName = arg;
376  }
377  }
378  virtual std::string GetMaskFileName() { return MaskFileName; }
379 
381 
384  vtkSetMacro(MaxFontSize, int);
386  vtkGetMacro(MaxFontSize, int);
387 
389 
392  vtkSetMacro(MinFontSize, int);
394  vtkGetMacro(MinFontSize, int);
395 
397 
402  vtkSetMacro(MinFrequency, int);
404  vtkGetMacro(MinFrequency, int);
405 
407 
411  vtkSetMacro(FontMultiplier, int);
413  vtkGetMacro(FontMultiplier, int);
414 
416 
422  virtual ColorDistributionContainer GetColorDistribution() { return ColorDistribution; }
423 
425 
430  SetStdContainerMacro(OffsetDistribution, OffsetDistributionContainer);
432  virtual OffsetDistributionContainer GetOffsetDistribution() { return OffsetDistribution; }
433 
435 
440  SetStdContainerMacro(OrientationDistribution, OrientationDistributionContainer);
443  {
444  return OrientationDistribution;
445  }
446 
448 
453  SetStdContainerMacro(Orientations, OrientationsContainer);
455  void AddOrientation(double arg)
456  {
457  Orientations.push_back(arg);
458  this->Modified();
459  }
460  virtual OrientationsContainer GetOrientations() { return Orientations; }
461 
463 
468  SetStdContainerMacro(ReplacementPairs, ReplacementPairsContainer);
471  {
472  ReplacementPairs.push_back(arg);
473  this->Modified();
474  }
475 
476  virtual ReplacementPairsContainer GetReplacementPairs() { return ReplacementPairs; }
477 
479 
482  SetStdContainerMacro(Sizes, SizesContainer);
484  virtual SizesContainer GetSizes() { return Sizes; }
485 
487 
492  SetStdContainerMacro(StopWords, StopWordsContainer);
495  {
496  StopWords.insert(word);
497  this->Modified();
498  }
500  {
501  StopWords.clear();
502  this->Modified();
503  }
504  virtual StopWordsContainer GetStopWords() { return StopWords; }
505 
507 
511  virtual void SetStopListFileName(std::string arg)
513  {
514  if (StopListFileName != arg)
515  {
516  this->Modified();
517  StopListFileName = arg;
518  }
519  }
520  virtual std::string GetStopListFileName() { return StopListFileName; }
521 
523 
527  virtual void SetTitle(std::string arg)
529  {
530  if (Title != arg)
531  {
532  this->Modified();
533  Title = arg;
534  }
535  }
536  virtual std::string GetTitle() { return Title; }
537 
539 
544  virtual void SetWordColorName(std::string arg)
546  {
547  if (WordColorName != arg)
548  {
549  this->Modified();
550  WordColorName = arg;
551  }
552  }
553  virtual std::string GetWordColorName() { return WordColorName; }
555 
558  virtual std::vector<std::string>& GetKeptWords() { return KeptWords; }
560 
562 
566  virtual std::vector<std::string>& GetSkippedWords() { return SkippedWords; }
568 
570 
573  virtual std::vector<std::string>& GetStoppedWords() { return StoppedWords; }
575 
576 protected:
578  ~vtkWordCloud() override = default;
579 
581 
583 
585  int WholeExtent[6];
586 
589  bool BWMask;
592  int DPI;
596  int Gap;
611 
612  std::vector<std::string> KeptWords;
613  std::vector<std::string> SkippedWords;
614  std::vector<std::string> StoppedWords;
615 
616 private:
617  vtkWordCloud(const vtkWordCloud&) = delete;
618  void operator=(const vtkWordCloud&) = delete;
619 
620  // Declaring the type of Predicate that accepts 2 pairs and returns a bool
621  typedef std::function<bool(std::pair<std::string, int>, std::pair<std::string, int>)> Comparator;
622 
623  std::multiset<std::pair<std::string, int>, Comparator> FindWordsSortedByFrequency(
625  struct ExtentOffset
626  {
627  ExtentOffset(int _x = 0.0, int _y = 0.0)
628  : x(_x)
629  , y(_y)
630  {
631  }
632  int x, y;
633  };
634 };
635 #endif
636 
637 // LocalWords: vtkNamedColors SetMaskColorName
vtkWordCloud::Gap
int Gap
Definition: vtkWordCloud.h:596
vtkImageData.h
vtkX3D::function
@ function
Definition: vtkX3D.h:255
vtkWordCloud::ColorSchemeName
std::string ColorSchemeName
Definition: vtkWordCloud.h:591
vtkWordCloud::New
static vtkWordCloud * New()
Construct object with vertex cell generation turned off.
vtkWordCloud::Title
std::string Title
Definition: vtkWordCloud.h:609
vtkWordCloud::RequestData
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called in response to a REQUEST_DATA request from the executive.
vtkWordCloud::OffsetDistribution
OffsetDistributionContainer OffsetDistribution
Definition: vtkWordCloud.h:602
vtkWordCloud::ClearStopWords
void ClearStopWords()
Definition: vtkWordCloud.h:499
vtkWordCloud::FontFileName
std::string FontFileName
Definition: vtkWordCloud.h:594
vtkWordCloud::MaskFileName
std::string MaskFileName
Definition: vtkWordCloud.h:598
vtkWordCloud::OffsetDistributionContainer
std::array< int, 2 > OffsetDistributionContainer
Definition: vtkWordCloud.h:197
vtkWordCloud::Sizes
SizesContainer Sizes
Definition: vtkWordCloud.h:606
vtkWordCloud::PairType
std::tuple< std::string, std::string > PairType
Definition: vtkWordCloud.h:200
vtkWordCloud::ColorDistribution
ColorDistributionContainer ColorDistribution
Definition: vtkWordCloud.h:590
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:36
vtkWordCloud::ColorDistributionContainer
std::array< double, 2 > ColorDistributionContainer
Definition: vtkWordCloud.h:196
vtkWordCloud::GetStopWords
virtual StopWordsContainer GetStopWords()
Definition: vtkWordCloud.h:504
vtkObject::Modified
virtual void Modified()
Update the modification time for this object.
vtkWordCloud::OrientationsContainer
std::vector< double > OrientationsContainer
Definition: vtkWordCloud.h:199
vtkWordCloud::BWMask
bool BWMask
Definition: vtkWordCloud.h:589
vtkImageAlgorithm.h
vtkSmartPointer< vtkImageData >
vtkWordCloud::StringContainer
std::vector< std::string > StringContainer
Definition: vtkWordCloud.h:204
vtkWordCloud::MinFrequency
int MinFrequency
Definition: vtkWordCloud.h:601
vtkWordCloud::GetBWMask
virtual bool GetBWMask()
Definition: vtkWordCloud.h:269
vtkImageAlgorithm
Generic algorithm superclass for image algs.
Definition: vtkImageAlgorithm.h:38
vtkWordCloud::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkWordCloud::Orientations
OrientationsContainer Orientations
Definition: vtkWordCloud.h:604
vtkWordCloud::MaskColorName
std::string MaskColorName
Definition: vtkWordCloud.h:597
vtkWordCloud::GetTitle
virtual std::string GetTitle()
Definition: vtkWordCloud.h:536
vtkWordCloud::SkippedWords
std::vector< std::string > SkippedWords
Definition: vtkWordCloud.h:613
vtkWordCloud::GetSizes
virtual SizesContainer GetSizes()
Definition: vtkWordCloud.h:484
vtkWordCloud::GetWordColorName
virtual std::string GetWordColorName()
Definition: vtkWordCloud.h:553
vtkWordCloud::ReplacementPairsContainer
std::vector< PairType > ReplacementPairsContainer
Definition: vtkWordCloud.h:201
vtkWordCloud
generate a word cloud visualization of a text document
Definition: vtkWordCloud.h:185
vtkWordCloud::StopListFileName
std::string StopListFileName
Definition: vtkWordCloud.h:608
vtkWordCloud::AdjustedSizes
SizesContainer AdjustedSizes
Definition: vtkWordCloud.h:587
vtkWordCloud::GetOrientationDistribution
virtual OrientationDistributionContainer GetOrientationDistribution()
Definition: vtkWordCloud.h:442
vtkWordCloud::GetStopListFileName
virtual std::string GetStopListFileName()
Definition: vtkWordCloud.h:520
vtkWordCloud::GetOffsetDistribution
virtual OffsetDistributionContainer GetOffsetDistribution()
Definition: vtkWordCloud.h:432
vtkWordCloud::ImageData
vtkSmartPointer< vtkImageData > ImageData
Definition: vtkWordCloud.h:584
vtkWordCloud::GetOrientations
virtual OrientationsContainer GetOrientations()
Definition: vtkWordCloud.h:460
vtkWordCloud::StopWordsContainer
std::set< std::string > StopWordsContainer
Definition: vtkWordCloud.h:203
vtkWordCloud::MinFontSize
int MinFontSize
Definition: vtkWordCloud.h:600
vtkWordCloud::AddReplacementPair
void AddReplacementPair(PairType arg)
Definition: vtkWordCloud.h:470
vtkWordCloud::OrientationDistribution
OrientationDistributionContainer OrientationDistribution
Definition: vtkWordCloud.h:603
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:34
vtkWordCloud::GetFileName
virtual std::string GetFileName()
Definition: vtkWordCloud.h:314
vtkWordCloud::GetMaskFileName
virtual std::string GetMaskFileName()
Definition: vtkWordCloud.h:378
vtkSmartPointer.h
vtkWordCloud::GetBackgroundColorName
virtual std::string GetBackgroundColorName()
Definition: vtkWordCloud.h:253
vtkWordCloud::KeptWords
std::vector< std::string > KeptWords
Definition: vtkWordCloud.h:612
vtkWordCloud::FontMultiplier
int FontMultiplier
Definition: vtkWordCloud.h:595
vtkWordCloud::MaxFontSize
int MaxFontSize
Definition: vtkWordCloud.h:599
vtkWordCloud::RequestInformation
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
Subclasses can reimplement this method to collect information from their inputs and set information f...
vtkWordCloud::AddOrientation
void AddOrientation(double arg)
Definition: vtkWordCloud.h:455
vtkWordCloud::StopWords
StopWordsContainer StopWords
Definition: vtkWordCloud.h:607
vtkWordCloud::GetColorSchemeName
virtual std::string GetColorSchemeName()
Definition: vtkWordCloud.h:287
SetStdContainerMacro
#define SetStdContainerMacro(name, container)
Definition: vtkWordCloud.h:213
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:74
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtkWordCloud::StoppedWords
std::vector< std::string > StoppedWords
Definition: vtkWordCloud.h:614
vtkWordCloud::GetColorDistribution
virtual ColorDistributionContainer GetColorDistribution()
Definition: vtkWordCloud.h:422
vtkWordCloud::BackgroundColorName
std::string BackgroundColorName
Definition: vtkWordCloud.h:588
vtkWordCloud::FileName
std::string FileName
Definition: vtkWordCloud.h:593
vtkWordCloud::GetMaskColorName
virtual std::string GetMaskColorName()
Definition: vtkWordCloud.h:357
vtkWordCloud::~vtkWordCloud
~vtkWordCloud() override=default
vtkWordCloud::AddStopWord
void AddStopWord(std::string word)
Definition: vtkWordCloud.h:494
vtkWordCloud::GetFontFileName
virtual std::string GetFontFileName()
Definition: vtkWordCloud.h:331
vtkWordCloud::vtkWordCloud
vtkWordCloud()
vtkWordCloud::GetReplacementPairs
virtual ReplacementPairsContainer GetReplacementPairs()
Definition: vtkWordCloud.h:476
vtkWordCloud::WordColorName
std::string WordColorName
Definition: vtkWordCloud.h:610
vtkWordCloud::ReplacementPairs
ReplacementPairsContainer ReplacementPairs
Definition: vtkWordCloud.h:605
vtkWordCloud::OrientationDistributionContainer
std::array< double, 2 > OrientationDistributionContainer
Definition: vtkWordCloud.h:198
vtkWordCloud::SizesContainer
std::array< int, 2 > SizesContainer
Definition: vtkWordCloud.h:202
vtkWordCloud::DPI
int DPI
Definition: vtkWordCloud.h:592