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
193class VTKINFOVISCORE_EXPORT vtkWordCloud : public vtkImageAlgorithm
194{
195public:
197 void PrintSelf(ostream& os, vtkIndent indent) override;
198
202 static vtkWordCloud* New();
203
204 // Typedefs
205 using ColorDistributionContainer = std::array<double, 2>;
206 using OffsetDistributionContainer = std::array<int, 2>;
207 using OrientationDistributionContainer = std::array<double, 2>;
208 using OrientationsContainer = std::vector<double>;
209 using PairType = std::tuple<std::string, std::string>;
210 using ReplacementPairsContainer = std::vector<PairType>;
211 using SizesContainer = std::array<int, 2>;
212 using StopWordsContainer = std::set<std::string>;
213 using StringContainer = std::vector<std::string>;
214
216
220 virtual SizesContainer GetAdjustedSizes() { return AdjustedSizes; }
221
222#define SetStdContainerMacro(name, container) \
223 virtual void Set##name(container arg) \
224 { \
225 bool changed = false; \
226 if (arg.size() != name.size()) \
227 { \
228 changed = true; \
229 } \
230 else \
231 { \
232 auto a = arg.begin(); \
233 for (auto r : name) \
234 { \
235 if (*a != r) \
236 { \
237 changed = true; \
238 } \
239 a++; \
240 } \
241 } \
242 if (changed) \
243 { \
244 name = arg; \
245 this->Modified(); \
246 } \
247 }
248
250
254 virtual void SetBackgroundColorName(std::string arg)
255 {
256 if (arg != BackgroundColorName)
257 {
258 this->Modified();
259 BackgroundColorName = arg;
260 }
261 }
262 virtual std::string GetBackgroundColorName() { return BackgroundColorName; }
263
265
270 virtual void SetBWMask(bool arg)
271 {
272 if (BWMask != arg)
273 {
274 this->Modified();
275 BWMask = arg;
276 }
277 }
278 virtual bool GetBWMask() { return BWMask; }
279
281
288 virtual void SetColorSchemeName(std::string arg)
289 {
290 if (ColorSchemeName != arg)
291 {
292 this->Modified();
293 ColorSchemeName = arg;
294 }
295 }
296 virtual std::string GetColorSchemeName() { return ColorSchemeName; }
297
299
306 vtkSetMacro(DPI, int);
307 vtkGetMacro(DPI, int);
308
310
315 virtual void SetFileName(VTK_FILEPATH std::string arg)
316 {
317 if (FileName != arg)
318 {
319 this->Modified();
320 FileName = arg;
321 }
322 }
323 virtual std::string GetFileName() { return FileName; }
324
326
332 virtual void SetFontFileName(VTK_FILEPATH std::string arg)
333 {
334 if (FontFileName != arg)
335 {
336 this->Modified();
337 FontFileName = arg;
338 }
339 }
340 virtual std::string GetFontFileName() { return FontFileName; }
341
343
348 vtkSetMacro(Gap, int);
349 vtkGetMacro(Gap, int);
350
352
358 virtual void SetMaskColorName(std::string arg)
359 {
360 if (MaskColorName != arg)
361 {
362 this->Modified();
363 MaskColorName = arg;
364 }
365 }
366 virtual std::string GetMaskColorName() { return MaskColorName; }
367
369
379 virtual void SetMaskFileName(VTK_FILEPATH std::string arg)
380 {
381 if (MaskFileName != arg)
382 {
383 this->Modified();
384 MaskFileName = arg;
385 }
386 }
387 virtual std::string GetMaskFileName() { return MaskFileName; }
388
390
394 vtkSetMacro(MaxFontSize, int);
395 vtkGetMacro(MaxFontSize, int);
396
398
402 vtkSetMacro(MinFontSize, int);
403 vtkGetMacro(MinFontSize, int);
404
406
412 vtkSetMacro(MinFrequency, int);
413 vtkGetMacro(MinFrequency, int);
414
416
421 vtkSetMacro(FontMultiplier, int);
422 vtkGetMacro(FontMultiplier, int);
423
425
431 virtual ColorDistributionContainer GetColorDistribution() { return ColorDistribution; }
432
434
441 virtual OffsetDistributionContainer GetOffsetDistribution() { return OffsetDistribution; }
442
444
452 {
453 return OrientationDistribution;
454 }
455
457
464 void AddOrientation(double arg)
465 {
466 Orientations.push_back(arg);
467 this->Modified();
468 }
469 virtual OrientationsContainer GetOrientations() { return Orientations; }
470
472
480 {
481 ReplacementPairs.push_back(arg);
482 this->Modified();
483 }
484
485 virtual ReplacementPairsContainer GetReplacementPairs() { return ReplacementPairs; }
486
488
493 virtual SizesContainer GetSizes() { return Sizes; }
494
496
503 void AddStopWord(std::string word)
504 {
505 StopWords.insert(word);
506 this->Modified();
507 }
509 {
510 StopWords.clear();
511 this->Modified();
512 }
513 virtual StopWordsContainer GetStopWords() { return StopWords; }
514
516
521 virtual void SetStopListFileName(VTK_FILEPATH std::string arg)
522 {
523 if (StopListFileName != arg)
524 {
525 this->Modified();
526 StopListFileName = arg;
527 }
528 }
529 virtual std::string GetStopListFileName() { return StopListFileName; }
530
532
537 virtual void SetTitle(std::string arg)
538 {
539 if (Title != arg)
540 {
541 this->Modified();
542 Title = arg;
543 }
544 }
545 virtual std::string GetTitle() { return Title; }
546
548
554 virtual void SetWordColorName(std::string arg)
555 {
556 if (WordColorName != arg)
557 {
558 this->Modified();
559 WordColorName = arg;
560 }
561 }
562 virtual std::string GetWordColorName() { return WordColorName; }
564
568 virtual std::vector<std::string>& GetKeptWords() { return KeptWords; }
569
571
576 virtual std::vector<std::string>& GetSkippedWords() { return SkippedWords; }
577
579
583 virtual std::vector<std::string>& GetStoppedWords() { return StoppedWords; }
584
585protected:
587 ~vtkWordCloud() override = default;
588
590
592
594 int WholeExtent[6];
595
598 bool BWMask;
600 std::string ColorSchemeName;
601 int DPI;
602 std::string FileName;
603 std::string FontFileName;
605 int Gap;
606 std::string MaskColorName;
607 std::string MaskFileName;
617 std::string StopListFileName;
618 std::string Title;
619 std::string WordColorName;
620
621 std::vector<std::string> KeptWords;
622 std::vector<std::string> SkippedWords;
623 std::vector<std::string> StoppedWords;
624
625private:
626 vtkWordCloud(const vtkWordCloud&) = delete;
627 void operator=(const vtkWordCloud&) = delete;
628
629 // Declaring the type of Predicate that accepts 2 pairs and returns a bool
630 typedef std::function<bool(std::pair<std::string, int>, std::pair<std::string, int>)> Comparator;
631
632 std::multiset<std::pair<std::string, int>, Comparator> FindWordsSortedByFrequency(
633 std::string&, vtkWordCloud*);
634 struct ExtentOffset
635 {
636 ExtentOffset(int _x = 0.0, int _y = 0.0)
637 : x(_x)
638 , y(_y)
639 {
640 }
641 int x, y;
642 };
643};
644#endif
645
646// LocalWords: vtkNamedColors SetMaskColorName
Generic algorithm superclass for image algs.
a simple class to control print indentation
Definition vtkIndent.h:43
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
virtual OrientationsContainer GetOrientations()
virtual OffsetDistributionContainer GetOffsetDistribution()
virtual void SetFontFileName(VTK_FILEPATH std::string arg)
Set/Get FontFileName, If empty, the built-in Arial font is used().
virtual void SetWordColorName(std::string arg)
Set/Get WordColorName, the name of the color for the words().
virtual void SetBackgroundColorName(std::string arg)
Set/Get the vtkNamedColors name for the background(MidNightBlue).
virtual SizesContainer GetAdjustedSizes()
Return the AdjustedSizes of the resized mask file.
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.
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called in response to a REQUEST_DATA request from the executive.
std::vector< PairType > ReplacementPairsContainer
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...
std::string StopListFileName
vtkSmartPointer< vtkImageData > ImageData
std::array< int, 2 > OffsetDistributionContainer
std::string ColorSchemeName
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.
virtual void SetColorSchemeName(std::string arg)
Set/Get ColorSchemeName, the name of a color scheme from vtkColorScheme to be used to select colors f...
virtual std::string GetWordColorName()
virtual void SetMaskColorName(std::string arg)
Set/Get MaskColorName, the name of the color for the mask (black).
std::tuple< std::string, std::string > PairType
SetStdContainerMacro(StopWords, StopWordsContainer)
Set/Add/Get StopWords, a set of user provided stop words().
std::string MaskFileName
std::string WordColorName
virtual std::string GetMaskFileName()
std::string BackgroundColorName
SetStdContainerMacro(ColorDistribution, ColorDistributionContainer)
Set/Get ColorDistribution, the distribution of random colors(.6 1.0), if WordColorName is empty.
std::array< double, 2 > ColorDistributionContainer
virtual std::vector< std::string > & GetStoppedWords()
Get a vector of words that were stopped in the final image.
std::set< std::string > StopWordsContainer
ReplacementPairsContainer ReplacementPairs
std::string FileName
std::array< double, 2 > OrientationDistributionContainer
std::vector< std::string > StringContainer
SizesContainer AdjustedSizes
std::string FontFileName
virtual std::vector< std::string > & GetSkippedWords()
Get a vector of words that are skipped.
SetStdContainerMacro(Sizes, SizesContainer)
Set/Get Sizes, the size of the output image(640 480).
OrientationsContainer Orientations
virtual std::string GetTitle()
virtual SizesContainer GetSizes()
OrientationDistributionContainer OrientationDistribution
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
Subclasses can reimplement this method to collect information from their inputs and set information f...
SizesContainer Sizes
virtual std::string GetFontFileName()
virtual void SetMaskFileName(VTK_FILEPATH std::string arg)
Set/Get MaskFileName, the mask file name().
std::string Title
virtual std::string GetStopListFileName()
virtual void SetStopListFileName(VTK_FILEPATH std::string arg)
Set/Get StopListFileName, the name of the file that contains the stop words, one per line.
virtual StopWordsContainer GetStopWords()
virtual std::string GetFileName()
SetStdContainerMacro(OffsetDistribution, OffsetDistributionContainer)
Set/Get OffsetDistribution, the range of uniform random offsets(-size[0]/100.0 -size{1]/100....
virtual std::string GetMaskColorName()
std::vector< std::string > SkippedWords
std::vector< std::string > KeptWords
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
ColorDistributionContainer ColorDistribution
void ClearStopWords()
SetStdContainerMacro(OrientationDistribution, OrientationDistributionContainer)
Set/Get OrientationDistribution, ranges of random orientations(-20 20).
virtual ColorDistributionContainer GetColorDistribution()
virtual std::string GetBackgroundColorName()
virtual ReplacementPairsContainer GetReplacementPairs()
virtual std::string GetColorSchemeName()
StopWordsContainer StopWords
~vtkWordCloud() override=default
virtual OrientationDistributionContainer GetOrientationDistribution()
std::vector< double > OrientationsContainer
void AddReplacementPair(PairType arg)
std::vector< std::string > StoppedWords
void AddStopWord(std::string word)
OffsetDistributionContainer OffsetDistribution
virtual bool GetBWMask()
virtual void SetBWMask(bool arg)
Set/Get boolean that indicates the mask image is a single channel(false).
SetStdContainerMacro(ReplacementPairs, ReplacementPairsContainer)
Set/Add/Get ReplacementPairs, a vector of words that replace the first word with another second word ...
std::string MaskColorName
std::array< int, 2 > SizesContainer
void AddOrientation(double arg)
#define VTK_FILEPATH