VTK  9.4.20241103
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
191VTK_ABI_NAMESPACE_BEGIN
192class VTKINFOVISCORE_EXPORT vtkWordCloud : public vtkImageAlgorithm
193{
194public:
196 void PrintSelf(ostream& os, vtkIndent indent) override;
197
201 static vtkWordCloud* New();
202
203 // Typedefs
204 using ColorDistributionContainer = std::array<double, 2>;
205 using OffsetDistributionContainer = std::array<int, 2>;
206 using OrientationDistributionContainer = std::array<double, 2>;
207 using OrientationsContainer = std::vector<double>;
208 using PairType = std::tuple<std::string, std::string>;
209 using ReplacementPairsContainer = std::vector<PairType>;
210 using SizesContainer = std::array<int, 2>;
211 using StopWordsContainer = std::set<std::string>;
212 using StringContainer = std::vector<std::string>;
213
215
219 virtual SizesContainer GetAdjustedSizes() { return AdjustedSizes; }
220
221#define SetStdContainerMacro(name, container) \
222 virtual void Set##name(container arg) \
223 { \
224 bool changed = false; \
225 if (arg.size() != name.size()) \
226 { \
227 changed = true; \
228 } \
229 else \
230 { \
231 auto a = arg.begin(); \
232 for (auto r : name) \
233 { \
234 if (*a != r) \
235 { \
236 changed = true; \
237 } \
238 a++; \
239 } \
240 } \
241 if (changed) \
242 { \
243 name = arg; \
244 this->Modified(); \
245 } \
246 }
247
249
253 virtual void SetBackgroundColorName(std::string arg)
254 {
255 if (arg != BackgroundColorName)
256 {
257 this->Modified();
258 BackgroundColorName = arg;
259 }
260 }
261 virtual std::string GetBackgroundColorName() { return BackgroundColorName; }
262
264
269 virtual void SetBWMask(bool arg)
270 {
271 if (BWMask != arg)
272 {
273 this->Modified();
274 BWMask = arg;
275 }
276 }
277 virtual bool GetBWMask() { return BWMask; }
278
280
287 virtual void SetColorSchemeName(std::string arg)
288 {
289 if (ColorSchemeName != arg)
290 {
291 this->Modified();
292 ColorSchemeName = arg;
293 }
294 }
295 virtual std::string GetColorSchemeName() { return ColorSchemeName; }
296
298
305 vtkSetMacro(DPI, int);
306 vtkGetMacro(DPI, int);
307
309
314 virtual void SetFileName(VTK_FILEPATH std::string arg)
315 {
316 if (FileName != arg)
317 {
318 this->Modified();
319 FileName = arg;
320 }
321 }
322 virtual std::string GetFileName() VTK_FUTURE_CONST { return FileName; }
323
325
331 virtual void SetFontFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
332 {
333 if (FontFileName != arg)
334 {
335 this->Modified();
336 FontFileName = arg;
337 }
338 }
339 virtual std::string GetFontFileName() VTK_FUTURE_CONST { return FontFileName; }
340
342
347 vtkSetMacro(Gap, int);
348 vtkGetMacro(Gap, int);
349
351
357 virtual void SetMaskColorName(std::string arg)
358 {
359 if (MaskColorName != arg)
360 {
361 this->Modified();
362 MaskColorName = arg;
363 }
364 }
365 virtual std::string GetMaskColorName() { return MaskColorName; }
366
368
378 virtual void SetMaskFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
379 {
380 if (MaskFileName != arg)
381 {
382 this->Modified();
383 MaskFileName = arg;
384 }
385 }
386 virtual std::string GetMaskFileName() VTK_FUTURE_CONST { return MaskFileName; }
387
389
393 vtkSetMacro(MaxFontSize, int);
394 vtkGetMacro(MaxFontSize, int);
395
397
401 vtkSetMacro(MinFontSize, int);
402 vtkGetMacro(MinFontSize, int);
403
405
411 vtkSetMacro(MinFrequency, int);
412 vtkGetMacro(MinFrequency, int);
413
415
420 vtkSetMacro(FontMultiplier, int);
421 vtkGetMacro(FontMultiplier, int);
422
424
430 virtual ColorDistributionContainer GetColorDistribution() { return ColorDistribution; }
431
433
440 virtual OffsetDistributionContainer GetOffsetDistribution() { return OffsetDistribution; }
441
443
451 {
452 return OrientationDistribution;
453 }
454
456
463 void AddOrientation(double arg)
464 {
465 Orientations.push_back(arg);
466 this->Modified();
467 }
468 virtual OrientationsContainer GetOrientations() { return Orientations; }
469
471
479 {
480 ReplacementPairs.push_back(arg);
481 this->Modified();
482 }
483
484 virtual ReplacementPairsContainer GetReplacementPairs() { return ReplacementPairs; }
485
487
492 virtual SizesContainer GetSizes() { return Sizes; }
493
495
502 void AddStopWord(std::string word)
503 {
504 StopWords.insert(word);
505 this->Modified();
506 }
508 {
509 StopWords.clear();
510 this->Modified();
511 }
512 virtual StopWordsContainer GetStopWords() { return StopWords; }
513
515
520 virtual void SetStopListFileName(VTK_FILEPATH VTK_FUTURE_CONST std::string arg)
521 {
522 if (StopListFileName != arg)
523 {
524 this->Modified();
525 StopListFileName = arg;
526 }
527 }
528 virtual std::string GetStopListFileName() VTK_FUTURE_CONST { return StopListFileName; }
529
531
536 virtual void SetTitle(std::string arg)
537 {
538 if (Title != arg)
539 {
540 this->Modified();
541 Title = arg;
542 }
543 }
544 virtual std::string GetTitle() { return Title; }
545
547
553 virtual void SetWordColorName(std::string arg)
554 {
555 if (WordColorName != arg)
556 {
557 this->Modified();
558 WordColorName = arg;
559 }
560 }
561 virtual std::string GetWordColorName() { return WordColorName; }
563
567 virtual std::vector<std::string>& GetKeptWords() { return KeptWords; }
568
570
575 virtual std::vector<std::string>& GetSkippedWords() { return SkippedWords; }
576
578
582 virtual std::vector<std::string>& GetStoppedWords() { return StoppedWords; }
583
584protected:
586 ~vtkWordCloud() override = default;
587
589
591
593 int WholeExtent[6];
594
597 bool BWMask;
599 std::string ColorSchemeName;
600 int DPI;
601 std::string FileName;
602 std::string FontFileName;
604 int Gap;
605 std::string MaskColorName;
606 std::string MaskFileName;
616 std::string StopListFileName;
617 std::string Title;
618 std::string WordColorName;
619
620 std::vector<std::string> KeptWords;
621 std::vector<std::string> SkippedWords;
622 std::vector<std::string> StoppedWords;
623
624private:
625 vtkWordCloud(const vtkWordCloud&) = delete;
626 void operator=(const vtkWordCloud&) = delete;
627
628 // Declaring the type of Predicate that accepts 2 pairs and returns a bool
629 typedef std::function<bool(std::pair<std::string, int>, std::pair<std::string, int>)> Comparator;
630
631 std::multiset<std::pair<std::string, int>, Comparator> FindWordsSortedByFrequency(
632 std::string&, vtkWordCloud*);
633 struct ExtentOffset
634 {
635 ExtentOffset(int _x = 0.0, int _y = 0.0)
636 : x(_x)
637 , y(_y)
638 {
639 }
640 int x, y;
641 };
642};
643VTK_ABI_NAMESPACE_END
644#endif
645
646// LocalWords: vtkNamedColors SetMaskColorName
Generic algorithm superclass for image algs.
a simple class to control print indentation
Definition vtkIndent.h:108
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