VTK  9.3.0
vtkWordCloud.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3#ifndef vtkWordCloud_h
4#define vtkWordCloud_h
5
6#include "vtkImageAlgorithm.h"
7#include "vtkImageData.h" // For ImageData
8#include "vtkInfovisCoreModule.h" // For export macro
9#include "vtkSmartPointer.h" // For SmartPointer
10
11#include <array> // For stl array
12#include <functional> // for function
13#include <set> // for stl multiset
14#include <string> // For stl string
15#include <vector> // For stl vector
16
172VTK_ABI_NAMESPACE_BEGIN
173class VTKINFOVISCORE_EXPORT vtkWordCloud : public vtkImageAlgorithm
174{
175public:
177 void PrintSelf(ostream& os, vtkIndent indent) override;
178
182 static vtkWordCloud* New();
183
184 // Typedefs
185 using ColorDistributionContainer = std::array<double, 2>;
186 using OffsetDistributionContainer = std::array<int, 2>;
187 using OrientationDistributionContainer = std::array<double, 2>;
188 using OrientationsContainer = std::vector<double>;
189 using PairType = std::tuple<std::string, std::string>;
190 using ReplacementPairsContainer = std::vector<PairType>;
191 using SizesContainer = std::array<int, 2>;
192 using StopWordsContainer = std::set<std::string>;
193 using StringContainer = std::vector<std::string>;
194
196
200 virtual SizesContainer GetAdjustedSizes() { return AdjustedSizes; }
201
202#define SetStdContainerMacro(name, container) \
203 virtual void Set##name(container arg) \
204 { \
205 bool changed = false; \
206 if (arg.size() != name.size()) \
207 { \
208 changed = true; \
209 } \
210 else \
211 { \
212 auto a = arg.begin(); \
213 for (auto r : name) \
214 { \
215 if (*a != r) \
216 { \
217 changed = true; \
218 } \
219 a++; \
220 } \
221 } \
222 if (changed) \
223 { \
224 name = arg; \
225 this->Modified(); \
226 } \
227 }
228
230
234 virtual void SetBackgroundColorName(std::string arg)
235 {
236 if (arg != BackgroundColorName)
237 {
238 this->Modified();
239 BackgroundColorName = arg;
240 }
241 }
242 virtual std::string GetBackgroundColorName() { return BackgroundColorName; }
243
245
250 virtual void SetBWMask(bool arg)
251 {
252 if (BWMask != arg)
253 {
254 this->Modified();
255 BWMask = arg;
256 }
257 }
258 virtual bool GetBWMask() { return BWMask; }
259
261
268 virtual void SetColorSchemeName(std::string arg)
269 {
270 if (ColorSchemeName != arg)
271 {
272 this->Modified();
273 ColorSchemeName = arg;
274 }
275 }
276 virtual std::string GetColorSchemeName() { return ColorSchemeName; }
277
279
286 vtkSetMacro(DPI, int);
287 vtkGetMacro(DPI, int);
288
290
295 virtual void SetFileName(VTK_FILEPATH std::string arg)
296 {
297 if (FileName != arg)
298 {
299 this->Modified();
300 FileName = arg;
301 }
302 }
303 virtual std::string GetFileName() VTK_FUTURE_CONST { return FileName; }
304
306
312 virtual void SetFontFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
313 {
314 if (FontFileName != arg)
315 {
316 this->Modified();
317 FontFileName = arg;
318 }
319 }
320 virtual std::string GetFontFileName() VTK_FUTURE_CONST { return FontFileName; }
321
323
328 vtkSetMacro(Gap, int);
329 vtkGetMacro(Gap, int);
330
332
338 virtual void SetMaskColorName(std::string arg)
339 {
340 if (MaskColorName != arg)
341 {
342 this->Modified();
343 MaskColorName = arg;
344 }
345 }
346 virtual std::string GetMaskColorName() { return MaskColorName; }
347
349
359 virtual void SetMaskFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
360 {
361 if (MaskFileName != arg)
362 {
363 this->Modified();
364 MaskFileName = arg;
365 }
366 }
367 virtual std::string GetMaskFileName() VTK_FUTURE_CONST { return MaskFileName; }
368
370
374 vtkSetMacro(MaxFontSize, int);
375 vtkGetMacro(MaxFontSize, int);
376
378
382 vtkSetMacro(MinFontSize, int);
383 vtkGetMacro(MinFontSize, int);
384
386
392 vtkSetMacro(MinFrequency, int);
393 vtkGetMacro(MinFrequency, int);
394
396
401 vtkSetMacro(FontMultiplier, int);
402 vtkGetMacro(FontMultiplier, int);
403
405
411 virtual ColorDistributionContainer GetColorDistribution() { return ColorDistribution; }
412
414
421 virtual OffsetDistributionContainer GetOffsetDistribution() { return OffsetDistribution; }
422
424
432 {
433 return OrientationDistribution;
434 }
435
437
444 void AddOrientation(double arg)
445 {
446 Orientations.push_back(arg);
447 this->Modified();
448 }
449 virtual OrientationsContainer GetOrientations() { return Orientations; }
450
452
460 {
461 ReplacementPairs.push_back(arg);
462 this->Modified();
463 }
464
465 virtual ReplacementPairsContainer GetReplacementPairs() { return ReplacementPairs; }
466
468
473 virtual SizesContainer GetSizes() { return Sizes; }
474
476
483 void AddStopWord(std::string word)
484 {
485 StopWords.insert(word);
486 this->Modified();
487 }
489 {
490 StopWords.clear();
491 this->Modified();
492 }
493 virtual StopWordsContainer GetStopWords() { return StopWords; }
494
496
501 virtual void SetStopListFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
502 {
503 if (StopListFileName != arg)
504 {
505 this->Modified();
506 StopListFileName = arg;
507 }
508 }
509 virtual std::string GetStopListFileName() VTK_FUTURE_CONST { return StopListFileName; }
510
512
517 virtual void SetTitle(std::string arg)
518 {
519 if (Title != arg)
520 {
521 this->Modified();
522 Title = arg;
523 }
524 }
525 virtual std::string GetTitle() { return Title; }
526
528
534 virtual void SetWordColorName(std::string arg)
535 {
536 if (WordColorName != arg)
537 {
538 this->Modified();
539 WordColorName = arg;
540 }
541 }
542 virtual std::string GetWordColorName() { return WordColorName; }
544
548 virtual std::vector<std::string>& GetKeptWords() { return KeptWords; }
549
551
556 virtual std::vector<std::string>& GetSkippedWords() { return SkippedWords; }
557
559
563 virtual std::vector<std::string>& GetStoppedWords() { return StoppedWords; }
564
565protected:
567 ~vtkWordCloud() override = default;
568
570
572
574 int WholeExtent[6];
575
578 bool BWMask;
580 std::string ColorSchemeName;
581 int DPI;
582 std::string FileName;
583 std::string FontFileName;
585 int Gap;
586 std::string MaskColorName;
587 std::string MaskFileName;
597 std::string StopListFileName;
598 std::string Title;
599 std::string WordColorName;
600
601 std::vector<std::string> KeptWords;
602 std::vector<std::string> SkippedWords;
603 std::vector<std::string> StoppedWords;
604
605private:
606 vtkWordCloud(const vtkWordCloud&) = delete;
607 void operator=(const vtkWordCloud&) = delete;
608
609 // Declaring the type of Predicate that accepts 2 pairs and returns a bool
610 typedef std::function<bool(std::pair<std::string, int>, std::pair<std::string, int>)> Comparator;
611
612 std::multiset<std::pair<std::string, int>, Comparator> FindWordsSortedByFrequency(
613 std::string&, vtkWordCloud*);
614 struct ExtentOffset
615 {
616 ExtentOffset(int _x = 0.0, int _y = 0.0)
617 : x(_x)
618 , y(_y)
619 {
620 }
621 int x, y;
622 };
623};
624VTK_ABI_NAMESPACE_END
625#endif
626
627// LocalWords: vtkNamedColors SetMaskColorName
Generic algorithm superclass for image algs.
a simple class to control print indentation
Definition vtkIndent.h:29
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 SetWordColorName(std::string arg)
Set/Get WordColorName, the name of the color for the words().
virtual std::string GetMaskFileName() VTK_FUTURE_CONST
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...
virtual std::string GetFontFileName() VTK_FUTURE_CONST
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
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
virtual std::string GetStopListFileName() VTK_FUTURE_CONST
std::string FileName
virtual void SetStopListFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
Set/Get StopListFileName, the name of the file that contains the stop words, one per line.
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.
virtual std::string GetFileName() VTK_FUTURE_CONST
virtual void SetMaskFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
Set/Get MaskFileName, the mask file name().
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
std::string Title
virtual StopWordsContainer GetStopWords()
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).
virtual void SetFontFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
Set/Get FontFileName, If empty, the built-in Arial font is used().
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