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
181VTK_ABI_NAMESPACE_BEGIN
182class VTKINFOVISCORE_EXPORT vtkWordCloud : public vtkImageAlgorithm
183{
184public:
186 void PrintSelf(ostream& os, vtkIndent indent) override;
187
191 static vtkWordCloud* New();
192
193 // Typedefs
194 using ColorDistributionContainer = std::array<double, 2>;
195 using OffsetDistributionContainer = std::array<int, 2>;
196 using OrientationDistributionContainer = std::array<double, 2>;
197 using OrientationsContainer = std::vector<double>;
198 using PairType = std::tuple<std::string, std::string>;
199 using ReplacementPairsContainer = std::vector<PairType>;
200 using SizesContainer = std::array<int, 2>;
201 using StopWordsContainer = std::set<std::string>;
202 using StringContainer = std::vector<std::string>;
203
205
209 virtual SizesContainer GetAdjustedSizes() { return AdjustedSizes; }
210
211#define SetStdContainerMacro(name, container) \
212 virtual void Set##name(container arg) \
213 { \
214 bool changed = false; \
215 if (arg.size() != name.size()) \
216 { \
217 changed = true; \
218 } \
219 else \
220 { \
221 auto a = arg.begin(); \
222 for (auto r : name) \
223 { \
224 if (*a != r) \
225 { \
226 changed = true; \
227 } \
228 a++; \
229 } \
230 } \
231 if (changed) \
232 { \
233 name = arg; \
234 this->Modified(); \
235 } \
236 }
237
239
243 virtual void SetBackgroundColorName(std::string arg)
244 {
245 if (arg != BackgroundColorName)
246 {
247 this->Modified();
248 BackgroundColorName = arg;
249 }
250 }
251 virtual std::string GetBackgroundColorName() { return BackgroundColorName; }
252
254
259 virtual void SetBWMask(bool arg)
260 {
261 if (BWMask != arg)
262 {
263 this->Modified();
264 BWMask = arg;
265 }
266 }
267 virtual bool GetBWMask() { return BWMask; }
268
270
277 virtual void SetColorSchemeName(std::string arg)
278 {
279 if (ColorSchemeName != arg)
280 {
281 this->Modified();
282 ColorSchemeName = arg;
283 }
284 }
285 virtual std::string GetColorSchemeName() { return ColorSchemeName; }
286
288
295 vtkSetMacro(DPI, int);
296 vtkGetMacro(DPI, int);
297
299
304 virtual void SetFileName(VTK_FILEPATH std::string arg)
305 {
306 if (FileName != arg)
307 {
308 this->Modified();
309 FileName = arg;
310 }
311 }
312 virtual std::string GetFileName() VTK_FUTURE_CONST { return FileName; }
313
315
321 virtual void SetFontFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
322 {
323 if (FontFileName != arg)
324 {
325 this->Modified();
326 FontFileName = arg;
327 }
328 }
329 virtual std::string GetFontFileName() VTK_FUTURE_CONST { return FontFileName; }
330
332
337 vtkSetMacro(Gap, int);
338 vtkGetMacro(Gap, int);
339
341
347 virtual void SetMaskColorName(std::string arg)
348 {
349 if (MaskColorName != arg)
350 {
351 this->Modified();
352 MaskColorName = arg;
353 }
354 }
355 virtual std::string GetMaskColorName() { return MaskColorName; }
356
358
368 virtual void SetMaskFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
369 {
370 if (MaskFileName != arg)
371 {
372 this->Modified();
373 MaskFileName = arg;
374 }
375 }
376 virtual std::string GetMaskFileName() VTK_FUTURE_CONST { return MaskFileName; }
377
379
383 vtkSetMacro(MaxFontSize, int);
384 vtkGetMacro(MaxFontSize, int);
385
387
391 vtkSetMacro(MinFontSize, int);
392 vtkGetMacro(MinFontSize, int);
393
395
401 vtkSetMacro(MinFrequency, int);
402 vtkGetMacro(MinFrequency, int);
403
405
410 vtkSetMacro(FontMultiplier, int);
411 vtkGetMacro(FontMultiplier, int);
412
414
420 virtual ColorDistributionContainer GetColorDistribution() { return ColorDistribution; }
421
423
430 virtual OffsetDistributionContainer GetOffsetDistribution() { return OffsetDistribution; }
431
433
441 {
442 return OrientationDistribution;
443 }
444
446
453 void AddOrientation(double arg)
454 {
455 Orientations.push_back(arg);
456 this->Modified();
457 }
458 virtual OrientationsContainer GetOrientations() { return Orientations; }
459
461
469 {
470 ReplacementPairs.push_back(arg);
471 this->Modified();
472 }
473
474 virtual ReplacementPairsContainer GetReplacementPairs() { return ReplacementPairs; }
475
477
482 virtual SizesContainer GetSizes() { return Sizes; }
483
485
492 void AddStopWord(std::string word)
493 {
494 StopWords.insert(word);
495 this->Modified();
496 }
498 {
499 StopWords.clear();
500 this->Modified();
501 }
502 virtual StopWordsContainer GetStopWords() { return StopWords; }
503
505
510 virtual void SetStopListFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
511 {
512 if (StopListFileName != arg)
513 {
514 this->Modified();
515 StopListFileName = arg;
516 }
517 }
518 virtual std::string GetStopListFileName() VTK_FUTURE_CONST { return StopListFileName; }
519
521
526 virtual void SetTitle(std::string arg)
527 {
528 if (Title != arg)
529 {
530 this->Modified();
531 Title = arg;
532 }
533 }
534 virtual std::string GetTitle() { return Title; }
535
537
543 virtual void SetWordColorName(std::string arg)
544 {
545 if (WordColorName != arg)
546 {
547 this->Modified();
548 WordColorName = arg;
549 }
550 }
551 virtual std::string GetWordColorName() { return WordColorName; }
553
557 virtual std::vector<std::string>& GetKeptWords() { return KeptWords; }
558
560
565 virtual std::vector<std::string>& GetSkippedWords() { return SkippedWords; }
566
568
572 virtual std::vector<std::string>& GetStoppedWords() { return StoppedWords; }
573
574protected:
576 ~vtkWordCloud() override = default;
577
579
581
583 int WholeExtent[6];
584
587 bool BWMask;
589 std::string ColorSchemeName;
590 int DPI;
591 std::string FileName;
592 std::string FontFileName;
594 int Gap;
595 std::string MaskColorName;
596 std::string MaskFileName;
606 std::string StopListFileName;
607 std::string Title;
608 std::string WordColorName;
609
610 std::vector<std::string> KeptWords;
611 std::vector<std::string> SkippedWords;
612 std::vector<std::string> StoppedWords;
613
614private:
615 vtkWordCloud(const vtkWordCloud&) = delete;
616 void operator=(const vtkWordCloud&) = delete;
617
618 // Declaring the type of Predicate that accepts 2 pairs and returns a bool
619 typedef std::function<bool(std::pair<std::string, int>, std::pair<std::string, int>)> Comparator;
620
621 std::multiset<std::pair<std::string, int>, Comparator> FindWordsSortedByFrequency(
622 std::string&, vtkWordCloud*);
623 struct ExtentOffset
624 {
625 ExtentOffset(int _x = 0.0, int _y = 0.0)
626 : x(_x)
627 , y(_y)
628 {
629 }
630 int x, y;
631 };
632};
633VTK_ABI_NAMESPACE_END
634#endif
635
636// LocalWords: vtkNamedColors SetMaskColorName
Generic algorithm superclass for image algs.
a simple class to control print indentation
Definition vtkIndent.h:38
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