VTK  9.1.0
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
203class VTKINFOVISCORE_EXPORT vtkWordCloud : public vtkImageAlgorithm
204{
205public:
207 void PrintSelf(ostream& os, vtkIndent indent) override;
208
212 static vtkWordCloud* New();
213
214 // Typedefs
215 using ColorDistributionContainer = std::array<double, 2>;
216 using OffsetDistributionContainer = std::array<int, 2>;
217 using OrientationDistributionContainer = std::array<double, 2>;
218 using OrientationsContainer = std::vector<double>;
219 using PairType = std::tuple<std::string, std::string>;
220 using ReplacementPairsContainer = std::vector<PairType>;
221 using SizesContainer = std::array<int, 2>;
222 using StopWordsContainer = std::set<std::string>;
223 using StringContainer = std::vector<std::string>;
224
226
230 virtual SizesContainer GetAdjustedSizes() { return AdjustedSizes; }
231
232#define SetStdContainerMacro(name, container) \
233 virtual void Set##name(container arg) \
234 { \
235 bool changed = false; \
236 if (arg.size() != name.size()) \
237 { \
238 changed = true; \
239 } \
240 else \
241 { \
242 auto a = arg.begin(); \
243 for (auto r : name) \
244 { \
245 if (*a != r) \
246 { \
247 changed = true; \
248 } \
249 a++; \
250 } \
251 } \
252 if (changed) \
253 { \
254 name = arg; \
255 this->Modified(); \
256 } \
257 }
258
260
264 virtual void SetBackgroundColorName(std::string arg)
265 {
266 if (arg != BackgroundColorName)
267 {
268 this->Modified();
269 BackgroundColorName = arg;
270 }
271 }
272 virtual std::string GetBackgroundColorName() { return BackgroundColorName; }
273
275
280 virtual void SetBWMask(bool arg)
281 {
282 if (BWMask != arg)
283 {
284 this->Modified();
285 BWMask = arg;
286 }
287 }
288 virtual bool GetBWMask() { return BWMask; }
289
291
298 virtual void SetColorSchemeName(std::string arg)
299 {
300 if (ColorSchemeName != arg)
301 {
302 this->Modified();
303 ColorSchemeName = arg;
304 }
305 }
306 virtual std::string GetColorSchemeName() { return ColorSchemeName; }
307
309
316 vtkSetMacro(DPI, int);
317 vtkGetMacro(DPI, int);
318
320
325 virtual void SetFileName(VTK_FILEPATH std::string arg)
326 {
327 if (FileName != arg)
328 {
329 this->Modified();
330 FileName = arg;
331 }
332 }
333 virtual std::string GetFileName() { return FileName; }
334
336
342 virtual void SetFontFileName(VTK_FILEPATH std::string arg)
343 {
344 if (FontFileName != arg)
345 {
346 this->Modified();
347 FontFileName = arg;
348 }
349 }
350 virtual std::string GetFontFileName() { return FontFileName; }
351
353
358 vtkSetMacro(Gap, int);
359 vtkGetMacro(Gap, int);
360
362
368 virtual void SetMaskColorName(std::string arg)
369 {
370 if (MaskColorName != arg)
371 {
372 this->Modified();
373 MaskColorName = arg;
374 }
375 }
376 virtual std::string GetMaskColorName() { return MaskColorName; }
377
379
389 virtual void SetMaskFileName(VTK_FILEPATH std::string arg)
390 {
391 if (MaskFileName != arg)
392 {
393 this->Modified();
394 MaskFileName = arg;
395 }
396 }
397 virtual std::string GetMaskFileName() { return MaskFileName; }
398
400
404 vtkSetMacro(MaxFontSize, int);
405 vtkGetMacro(MaxFontSize, int);
406
408
412 vtkSetMacro(MinFontSize, int);
413 vtkGetMacro(MinFontSize, int);
414
416
422 vtkSetMacro(MinFrequency, int);
423 vtkGetMacro(MinFrequency, int);
424
426
431 vtkSetMacro(FontMultiplier, int);
432 vtkGetMacro(FontMultiplier, int);
433
435
441 virtual ColorDistributionContainer GetColorDistribution() { return ColorDistribution; }
442
444
451 virtual OffsetDistributionContainer GetOffsetDistribution() { return OffsetDistribution; }
452
454
462 {
463 return OrientationDistribution;
464 }
465
467
474 void AddOrientation(double arg)
475 {
476 Orientations.push_back(arg);
477 this->Modified();
478 }
479 virtual OrientationsContainer GetOrientations() { return Orientations; }
480
482
490 {
491 ReplacementPairs.push_back(arg);
492 this->Modified();
493 }
494
495 virtual ReplacementPairsContainer GetReplacementPairs() { return ReplacementPairs; }
496
498
503 virtual SizesContainer GetSizes() { return Sizes; }
504
506
513 void AddStopWord(std::string word)
514 {
515 StopWords.insert(word);
516 this->Modified();
517 }
519 {
520 StopWords.clear();
521 this->Modified();
522 }
523 virtual StopWordsContainer GetStopWords() { return StopWords; }
524
526
531 virtual void SetStopListFileName(VTK_FILEPATH std::string arg)
532 {
533 if (StopListFileName != arg)
534 {
535 this->Modified();
536 StopListFileName = arg;
537 }
538 }
539 virtual std::string GetStopListFileName() { return StopListFileName; }
540
542
547 virtual void SetTitle(std::string arg)
548 {
549 if (Title != arg)
550 {
551 this->Modified();
552 Title = arg;
553 }
554 }
555 virtual std::string GetTitle() { return Title; }
556
558
564 virtual void SetWordColorName(std::string arg)
565 {
566 if (WordColorName != arg)
567 {
568 this->Modified();
569 WordColorName = arg;
570 }
571 }
572 virtual std::string GetWordColorName() { return WordColorName; }
574
578 virtual std::vector<std::string>& GetKeptWords() { return KeptWords; }
579
581
586 virtual std::vector<std::string>& GetSkippedWords() { return SkippedWords; }
587
589
593 virtual std::vector<std::string>& GetStoppedWords() { return StoppedWords; }
594
595protected:
597 ~vtkWordCloud() override = default;
598
600
602
604 int WholeExtent[6];
605
608 bool BWMask;
610 std::string ColorSchemeName;
611 int DPI;
612 std::string FileName;
613 std::string FontFileName;
615 int Gap;
616 std::string MaskColorName;
617 std::string MaskFileName;
627 std::string StopListFileName;
628 std::string Title;
629 std::string WordColorName;
630
631 std::vector<std::string> KeptWords;
632 std::vector<std::string> SkippedWords;
633 std::vector<std::string> StoppedWords;
634
635private:
636 vtkWordCloud(const vtkWordCloud&) = delete;
637 void operator=(const vtkWordCloud&) = delete;
638
639 // Declaring the type of Predicate that accepts 2 pairs and returns a bool
640 typedef std::function<bool(std::pair<std::string, int>, std::pair<std::string, int>)> Comparator;
641
642 std::multiset<std::pair<std::string, int>, Comparator> FindWordsSortedByFrequency(
643 std::string&, vtkWordCloud*);
644 struct ExtentOffset
645 {
646 ExtentOffset(int _x = 0.0, int _y = 0.0)
647 : x(_x)
648 , y(_y)
649 {
650 }
651 int x, y;
652 };
653};
654#endif
655
656// LocalWords: vtkNamedColors SetMaskColorName
Generic algorithm superclass for image algs.
a simple class to control print indentation
Definition: vtkIndent.h:113
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
virtual void Modified()
Update the modification time for this object.
Hold a reference to a vtkObjectBase instance.
generate a word cloud visualization of a text document
Definition: vtkWordCloud.h:204
virtual OrientationsContainer GetOrientations()
Definition: vtkWordCloud.h:479
virtual OffsetDistributionContainer GetOffsetDistribution()
Definition: vtkWordCloud.h:451
virtual void SetFontFileName(VTK_FILEPATH std::string arg)
Set/Get FontFileName, If empty, the built-in Arial font is used().
Definition: vtkWordCloud.h:342
virtual void SetWordColorName(std::string arg)
Set/Get WordColorName, the name of the color for the words().
Definition: vtkWordCloud.h:564
virtual void SetBackgroundColorName(std::string arg)
Set/Get the vtkNamedColors name for the background(MidNightBlue).
Definition: vtkWordCloud.h:264
virtual SizesContainer GetAdjustedSizes()
Return the AdjustedSizes of the resized mask file.
Definition: vtkWordCloud.h:230
static vtkWordCloud * New()
Construct object with vertex cell generation turned off.
virtual void SetFileName(VTK_FILEPATH std::string arg)
Set/Get FileName, the name of the file that contains the text to be processed.
Definition: vtkWordCloud.h:325
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called in response to a REQUEST_DATA request from the executive.
std::vector< PairType > ReplacementPairsContainer
Definition: vtkWordCloud.h:220
virtual void SetTitle(std::string arg)
Set/Get Title, add this word to the document's words and set a high frequency, so that is will be ren...
Definition: vtkWordCloud.h:547
std::string StopListFileName
Definition: vtkWordCloud.h:627
vtkSmartPointer< vtkImageData > ImageData
Definition: vtkWordCloud.h:603
std::array< int, 2 > OffsetDistributionContainer
Definition: vtkWordCloud.h:216
std::string ColorSchemeName
Definition: vtkWordCloud.h:610
SetStdContainerMacro(Orientations, OrientationsContainer)
Set/Add/Get Orientations, a vector of discrete orientations ().
virtual std::vector< std::string > & GetKeptWords()
Get a vector of words that are kept in the final image.
Definition: vtkWordCloud.h:578
virtual void SetColorSchemeName(std::string arg)
Set/Get ColorSchemeName, the name of a color scheme from vtkColorScheme to be used to select colors f...
Definition: vtkWordCloud.h:298
virtual std::string GetWordColorName()
Definition: vtkWordCloud.h:572
virtual void SetMaskColorName(std::string arg)
Set/Get MaskColorName, the name of the color for the mask (black).
Definition: vtkWordCloud.h:368
std::tuple< std::string, std::string > PairType
Definition: vtkWordCloud.h:219
SetStdContainerMacro(StopWords, StopWordsContainer)
Set/Add/Get StopWords, a set of user provided stop words().
std::string MaskFileName
Definition: vtkWordCloud.h:617
std::string WordColorName
Definition: vtkWordCloud.h:629
virtual std::string GetMaskFileName()
Definition: vtkWordCloud.h:397
std::string BackgroundColorName
Definition: vtkWordCloud.h:607
SetStdContainerMacro(ColorDistribution, ColorDistributionContainer)
Set/Get ColorDistribution, the distribution of random colors(.6 1.0), if WordColorName is empty.
std::array< double, 2 > ColorDistributionContainer
Definition: vtkWordCloud.h:215
virtual std::vector< std::string > & GetStoppedWords()
Get a vector of words that were stopped in the final image.
Definition: vtkWordCloud.h:593
std::set< std::string > StopWordsContainer
Definition: vtkWordCloud.h:222
ReplacementPairsContainer ReplacementPairs
Definition: vtkWordCloud.h:624
std::string FileName
Definition: vtkWordCloud.h:612
std::array< double, 2 > OrientationDistributionContainer
Definition: vtkWordCloud.h:217
std::vector< std::string > StringContainer
Definition: vtkWordCloud.h:223
SizesContainer AdjustedSizes
Definition: vtkWordCloud.h:606
std::string FontFileName
Definition: vtkWordCloud.h:613
virtual std::vector< std::string > & GetSkippedWords()
Get a vector of words that are skipped.
Definition: vtkWordCloud.h:586
SetStdContainerMacro(Sizes, SizesContainer)
Set/Get Sizes, the size of the output image(640 480).
OrientationsContainer Orientations
Definition: vtkWordCloud.h:623
virtual std::string GetTitle()
Definition: vtkWordCloud.h:555
virtual SizesContainer GetSizes()
Definition: vtkWordCloud.h:503
OrientationDistributionContainer OrientationDistribution
Definition: vtkWordCloud.h:622
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
Subclasses can reimplement this method to collect information from their inputs and set information f...
SizesContainer Sizes
Definition: vtkWordCloud.h:625
virtual std::string GetFontFileName()
Definition: vtkWordCloud.h:350
virtual void SetMaskFileName(VTK_FILEPATH std::string arg)
Set/Get MaskFileName, the mask file name().
Definition: vtkWordCloud.h:389
std::string Title
Definition: vtkWordCloud.h:628
virtual std::string GetStopListFileName()
Definition: vtkWordCloud.h:539
virtual void SetStopListFileName(VTK_FILEPATH std::string arg)
Set/Get StopListFileName, the name of the file that contains the stop words, one per line.
Definition: vtkWordCloud.h:531
virtual StopWordsContainer GetStopWords()
Definition: vtkWordCloud.h:523
virtual std::string GetFileName()
Definition: vtkWordCloud.h:333
SetStdContainerMacro(OffsetDistribution, OffsetDistributionContainer)
Set/Get OffsetDistribution, the range of uniform random offsets(-size[0]/100.0 -size{1]/100....
virtual std::string GetMaskColorName()
Definition: vtkWordCloud.h:376
std::vector< std::string > SkippedWords
Definition: vtkWordCloud.h:632
std::vector< std::string > KeptWords
Definition: vtkWordCloud.h:631
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
ColorDistributionContainer ColorDistribution
Definition: vtkWordCloud.h:609
void ClearStopWords()
Definition: vtkWordCloud.h:518
SetStdContainerMacro(OrientationDistribution, OrientationDistributionContainer)
Set/Get OrientationDistribution, ranges of random orientations(-20 20).
virtual ColorDistributionContainer GetColorDistribution()
Definition: vtkWordCloud.h:441
virtual std::string GetBackgroundColorName()
Definition: vtkWordCloud.h:272
virtual ReplacementPairsContainer GetReplacementPairs()
Definition: vtkWordCloud.h:495
virtual std::string GetColorSchemeName()
Definition: vtkWordCloud.h:306
StopWordsContainer StopWords
Definition: vtkWordCloud.h:626
~vtkWordCloud() override=default
virtual OrientationDistributionContainer GetOrientationDistribution()
Definition: vtkWordCloud.h:461
std::vector< double > OrientationsContainer
Definition: vtkWordCloud.h:218
void AddReplacementPair(PairType arg)
Definition: vtkWordCloud.h:489
std::vector< std::string > StoppedWords
Definition: vtkWordCloud.h:633
void AddStopWord(std::string word)
Definition: vtkWordCloud.h:513
OffsetDistributionContainer OffsetDistribution
Definition: vtkWordCloud.h:621
virtual bool GetBWMask()
Definition: vtkWordCloud.h:288
virtual void SetBWMask(bool arg)
Set/Get boolean that indicates the mask image is a single channel(false).
Definition: vtkWordCloud.h:280
SetStdContainerMacro(ReplacementPairs, ReplacementPairsContainer)
Set/Add/Get ReplacementPairs, a vector of words that replace the first word with another second word ...
std::string MaskColorName
Definition: vtkWordCloud.h:616
std::array< int, 2 > SizesContainer
Definition: vtkWordCloud.h:221
void AddOrientation(double arg)
Definition: vtkWordCloud.h:474
#define VTK_FILEPATH