SIVIC API  0.9.26
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
svkLabeledDataMapper.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2009-2014 The Regents of the University of California.
3  * All Rights Reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * • Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * • Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * • None of the names of any campus of the University of California, the name
13  * "The Regents of the University of California," or the names of any of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
26  * OF SUCH DAMAGE.
27  */
28 
29 /*
30  * $URL$
31  * $Rev$
32  * $Author$
33  * $Date$
34  *
35  * This code was copied from vtk-5.6.1's class svkLabeledDataMapper.
36  * There were non-virtual methods that we needed to modify to get
37  * the required behavior.
38  *
39  */
40 
41 /*=========================================================================
42 
43  Program: Visualization Toolkit
44  Module: vtkLabeledDataMapper.h
45 
46  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
47  All rights reserved.
48  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
49 
50  This software is distributed WITHOUT ANY WARRANTY; without even
51  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
52  PURPOSE. See the above copyright notice for more information.
53 
54 =========================================================================*/
55 // .NAME vtkLabeledDataMapper - draw text labels at dataset points
56 // .SECTION Description
57 // vtkLabeledDataMapper is a mapper that renders text at dataset
58 // points. Various items can be labeled including point ids, scalars,
59 // vectors, normals, texture coordinates, tensors, and field data components.
60 //
61 // The format with which the label is drawn is specified using a
62 // printf style format string. The font attributes of the text can
63 // be set through the vtkTextProperty associated to this mapper.
64 //
65 // By default, all the components of multi-component data such as
66 // vectors, normals, texture coordinates, tensors, and multi-component
67 // scalars are labeled. However, you can specify a single component if
68 // you prefer. (Note: the label format specifies the format to use for
69 // a single component. The label is creating by looping over all components
70 // and using the label format to render each component.)
71 
72 // .SECTION Caveats
73 // Use this filter in combination with vtkSelectVisiblePoints if you want
74 // to label only points that are visible. If you want to label cells rather
75 // than points, use the filter vtkCellCenters to generate points at the
76 // center of the cells. Also, you can use the class vtkIdFilter to
77 // generate ids as scalars or field data, which can then be labeled.
78 
79 // .SECTION See Also
80 // vtkMapper2D vtkActor2D vtkTextMapper vtkTextProperty vtkSelectVisiblePoints
81 // vtkIdFilter vtkCellCenters
82 
83 #ifndef __svkLabeledDataMapper_h
84 #define __svkLabeledDataMapper_h
85 
86 #include <vtkMapper2D.h>
87 #include <vector>
88 #include <map>
89 #include <string>
90 #include <svkMriImageData.h>
91 #include <svkVoxelTaggingUtils.h>
92 
93 
94 class vtkDataObject;
95 class vtkDataSet;
96 class vtkTextMapper;
97 class vtkTextProperty;
98 class vtkTransform;
99 
100 #define VTK_LABEL_IDS 0
101 #define VTK_LABEL_SCALARS 1
102 #define VTK_LABEL_VECTORS 2
103 #define VTK_LABEL_NORMALS 3
104 #define VTK_LABEL_TCOORDS 4
105 #define VTK_LABEL_TENSORS 5
106 #define VTK_LABEL_FIELD_DATA 6
107 #define SVK_LABEL_DATA_TAGS 7
108 
109 using namespace std;
110 
111 class svkLabeledDataMapper : public vtkMapper2D
112 {
113  public:
114 
115  // Description:
116  // Instantiate object with %%-#6.3g label format. By default, point ids
117  // are labeled.
118  static svkLabeledDataMapper *New();
119 
120  vtkTypeMacro(svkLabeledDataMapper,vtkMapper2D);
121  void PrintSelf(ostream& os, vtkIndent indent);
122 
123  // Description:
124  // Set/Get the format with which to print the labels. This should
125  // be a printf-style format string.
126  //
127  // By default, the mapper will try to print each component of the
128  // tuple using a sane format: %d for integers, %f for floats, %g for
129  // doubles, %ld for longs, et cetera. If you need a different
130  // format, set it here. You can do things like limit the number of
131  // significant digits, add prefixes/suffixes, basically anything
132  // that printf can do. If you only want to print one component of a
133  // vector, see the ivar LabeledComponent.
134  vtkSetStringMacro(LabelFormat);
135  vtkGetStringMacro(LabelFormat);
136 
137  // Description:
138  // Set/Get the component number to label if the data to print has
139  // more than one component. For example, all the components of
140  // scalars, vectors, normals, etc. are labeled by default
141  // (LabeledComponent=(-1)). However, if this ivar is nonnegative,
142  // then only the one component specified is labeled.
143  vtkSetMacro(LabeledComponent,int);
144  vtkGetMacro(LabeledComponent,int);
145 
146  vtkSetMacro(DisplayTags,bool);
147  vtkGetMacro(DisplayTags,bool);
148 
149  // Description:
150  // Set/Get the field data array to label. This instance variable is
151  // only applicable if field data is labeled. This will clear
152  // FieldDataName when set.
153  void SetFieldDataArray(int arrayIndex);
154  vtkGetMacro(FieldDataArray,int);
155 
156  // Description:
157  // Set/Get the name of the field data array to label. This instance
158  // variable is only applicable if field data is labeled. This will
159  // override FieldDataArray when set.
160  void SetFieldDataName(const char *arrayName);
161  vtkGetStringMacro(FieldDataName);
162 
163  // Description:
164  // Set the input dataset to the mapper. This mapper handles any type of data.
165  virtual void SetInput(vtkDataObject*);
166 
167  // Description:
168  // Use GetInputDataObject() to get the input data object for composite
169  // datasets.
170  vtkDataSet *GetInput();
171 
172  // Description:
173  // Specify which data to plot: IDs, scalars, vectors, normals, texture coords,
174  // tensors, or field data. If the data has more than one component, use
175  // the method SetLabeledComponent to control which components to plot.
176  // The default is VTK_LABEL_IDS.
177  vtkSetMacro(LabelMode, int);
178  vtkGetMacro(LabelMode, int);
179  void SetLabelModeToLabelIds() {this->SetLabelMode(VTK_LABEL_IDS);};
180  void SetLabelModeToLabelScalars() {this->SetLabelMode(VTK_LABEL_SCALARS);};
181  void SetLabelModeToLabelVectors() {this->SetLabelMode(VTK_LABEL_VECTORS);};
182  void SetLabelModeToLabelNormals() {this->SetLabelMode(VTK_LABEL_NORMALS);};
183  void SetLabelModeToLabelTCoords() {this->SetLabelMode(VTK_LABEL_TCOORDS);};
184  void SetLabelModeToLabelTensors() {this->SetLabelMode(VTK_LABEL_TENSORS);};
185  void SetLabelModeToLabelTags() {this->SetLabelMode(SVK_LABEL_DATA_TAGS);};
187  {this->SetLabelMode(VTK_LABEL_FIELD_DATA);};
188 
189  // Description:
190  // Set/Get the text property.
191  // If an integer argument is provided, you may provide different text
192  // properties for different label types. The type is determined by an
193  // optional type input array.
194  virtual void SetLabelTextProperty(vtkTextProperty *p)
195  { this->SetLabelTextProperty(p, 0); }
196  virtual vtkTextProperty* GetLabelTextProperty()
197  { return this->GetLabelTextProperty(0); }
198  virtual void SetLabelTextProperty(vtkTextProperty *p, int type);
199  virtual vtkTextProperty* GetLabelTextProperty(int type);
200 
201  // Description:
202  // Draw the text to the screen at each input point.
203  void RenderOpaqueGeometry(vtkViewport* viewport, vtkActor2D* actor);
204  void RenderOverlay(vtkViewport* viewport, vtkActor2D* actor);
205 
206  // Description:
207  // Release any graphics resources that are being consumed by this actor.
208  virtual void ReleaseGraphicsResources(vtkWindow *);
209 
210  // Description:
211  // The transform to apply to the labels before mapping to 2D.
212  vtkGetObjectMacro(Transform, vtkTransform);
213  void SetTransform(vtkTransform* t);
214 
215  //BTX
218  {
219  WORLD=0,
220  DISPLAY=1
221  };
222  //ETX
223 
224  // Description:
225  // Set/get the coordinate system used for output labels.
226  // The output datasets may have point coordinates reported in the world space or display space.
227  vtkGetMacro(CoordinateSystem,int);
228  vtkSetClampMacro(CoordinateSystem,int,WORLD,DISPLAY);
229  void CoordinateSystemWorld() { this->SetCoordinateSystem( svkLabeledDataMapper::WORLD ); }
230  void CoordinateSystemDisplay() { this->SetCoordinateSystem( svkLabeledDataMapper::DISPLAY ); }
231 
232  // Description:
233  // Return the modified time for this object.
234  virtual unsigned long GetMTime();
235 
236  protected:
239 
240  vtkDataSet *Input;
241 
242  char* LabelFormat;
249 
250  vtkTimeStamp BuildTime;
251 
254  vtkTextMapper** TextMappers;
255  double* LabelPositions;
256  vtkTransform* Transform;
257 
258  virtual int FillInputPortInformation(int, vtkInformation*);
259 
260  void AllocateLabels(int numLabels);
261  void BuildLabels();
262  void BuildLabelsInternal(vtkDataSet*);
263 
264  //BTX
265  class Internals;
267  //ETX
268 
269  private:
270  svkLabeledDataMapper(const svkLabeledDataMapper&); // Not implemented.
271  void operator=(const svkLabeledDataMapper&); // Not implemented.
272 };
273 
274 #endif
275 
int NumberOfLabelsAllocated
Definition: svkLabeledDataMapper.h:253
#define VTK_LABEL_TCOORDS
Definition: svkLabeledDataMapper.h:104
vtkTextMapper ** TextMappers
Definition: svkLabeledDataMapper.h:254
void SetLabelModeToLabelScalars()
Definition: svkLabeledDataMapper.h:180
Coordinates
Coordinate systems that output dataset may use.
Definition: svkLabeledDataMapper.h:217
#define VTK_LABEL_FIELD_DATA
Definition: svkLabeledDataMapper.h:106
vtkTransform * Transform
Definition: svkLabeledDataMapper.h:256
char * FieldDataName
Definition: svkLabeledDataMapper.h:246
int LabelMode
Definition: svkLabeledDataMapper.h:243
virtual vtkTextProperty * GetLabelTextProperty()
Definition: svkLabeledDataMapper.h:196
void SetLabelModeToLabelIds()
Definition: svkLabeledDataMapper.h:179
virtual void SetLabelTextProperty(vtkTextProperty *p)
Definition: svkLabeledDataMapper.h:194
double * LabelPositions
Definition: svkLabeledDataMapper.h:255
Definition: svkLabeledDataMapper.h:111
#define VTK_LABEL_TENSORS
Definition: svkLabeledDataMapper.h:105
#define VTK_LABEL_NORMALS
Definition: svkLabeledDataMapper.h:103
char * LabelFormat
Definition: svkLabeledDataMapper.h:242
int NumberOfLabels
Definition: svkLabeledDataMapper.h:252
#define VTK_LABEL_IDS
Definition: svkLabeledDataMapper.h:100
vtkTimeStamp BuildTime
Definition: svkLabeledDataMapper.h:250
void CoordinateSystemWorld()
Definition: svkLabeledDataMapper.h:229
Output 2-D display coordinates for each label anchor (3 components but only 2 are significant)...
Definition: svkLabeledDataMapper.h:220
Definition: svkLabeledDataMapper.cc:80
void SetLabelModeToLabelTensors()
Definition: svkLabeledDataMapper.h:184
void SetLabelModeToLabelTCoords()
Definition: svkLabeledDataMapper.h:183
bool DisplayTags
Definition: svkLabeledDataMapper.h:248
void SetLabelModeToLabelVectors()
Definition: svkLabeledDataMapper.h:181
void SetLabelModeToLabelFieldData()
Definition: svkLabeledDataMapper.h:186
void CoordinateSystemDisplay()
Definition: svkLabeledDataMapper.h:230
Internals * Implementation
Definition: svkLabeledDataMapper.h:265
int LabeledComponent
Definition: svkLabeledDataMapper.h:244
vtkDataSet * Input
Definition: svkLabeledDataMapper.h:240
#define VTK_LABEL_VECTORS
Definition: svkLabeledDataMapper.h:102
int CoordinateSystem
Definition: svkLabeledDataMapper.h:247
void SetLabelModeToLabelNormals()
Definition: svkLabeledDataMapper.h:182
#define SVK_LABEL_DATA_TAGS
Definition: svkLabeledDataMapper.h:107
Output 3-D world-space coordinates for each label anchor.
Definition: svkLabeledDataMapper.h:219
int FieldDataArray
Definition: svkLabeledDataMapper.h:245
void SetLabelModeToLabelTags()
Definition: svkLabeledDataMapper.h:185
#define VTK_LABEL_SCALARS
Definition: svkLabeledDataMapper.h:101