1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkSetGet.h,v $
6 Date: $Date: 2002/02/01 06:30:42 $
7 Version: $Revision: 1.1.1.1 $
10 Copyright (c) 1993-1998 Ken Martin, Will Schroeder, Bill Lorensen.
12 This software is copyrighted by Ken Martin, Will Schroeder and Bill Lorensen.
13 The following terms apply to all files associated with the software unless
14 explicitly disclaimed in individual files. This copyright specifically does
15 not apply to the related textbook "The Visualization Toolkit" ISBN
16 013199837-4 published by Prentice Hall which is covered by its own copyright.
18 The authors hereby grant permission to use, copy, and distribute this
19 software and its documentation for any purpose, provided that existing
20 copyright notices are retained in all copies and that this notice is included
21 verbatim in any distributions. Additionally, the authors grant permission to
22 modify this software and its documentation for any purpose, provided that
23 such modifications are not distributed without the explicit consent of the
24 authors and that existing copyright notices are retained in all copies. Some
25 of the algorithms implemented by this software are patented, observe all
26 applicable patent law.
28 IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
29 DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
30 OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
31 EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
34 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
35 PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN
36 "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
37 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
40 =========================================================================*/
41 // .NAME SetGet Macros - standard macros for setting/getting instance variables
42 // .SECTION Description
43 // The SetGet macros are used to interface to instance variables
44 // in a standard fashion. This includes properly treating modified time
45 // and printing out debug information.
47 // Macros are available for built-in types; for character strings;
48 // vector arrays of built-in types size 2,3,4; for setting objects; and
49 // debug, warning, and error printout information.
56 // Some constants used throughout code
58 #define VTK_LARGE_FLOAT 1.0e+38F
59 #define VTK_LARGE_INTEGER 2147483647 // 2^31 - 1
61 // These types are returned by GetDataType to indicate pixel type.
65 #define VTK_UNSIGNED_CHAR 3
67 #define VTK_UNSIGNED_SHORT 5
69 #define VTK_UNSIGNED_INT 7
71 #define VTK_UNSIGNED_LONG 9
75 // Some constant required for correct template performance
78 #define VTK_CHAR_MIN -128
79 #define VTK_CHAR_MAX 127
80 #define VTK_UNSIGNED_CHAR_MIN 0
81 #define VTK_UNSIGNED_CHAR_MAX 255
82 #define VTK_SHORT_MIN -32768
83 #define VTK_SHORT_MAX 32767
84 #define VTK_UNSIGNED_SHORT_MIN 0
85 #define VTK_UNSIGNED_SHORT_MAX 65535
86 #define VTK_INT_MIN (-VTK_LARGE_INTEGER-1)
87 #define VTK_INT_MAX VTK_LARGE_INTEGER
88 #define VTK_UNSIGNED_INT_MIN 0
89 #define VTK_UNSIGNED_INT_MAX 4294967295
90 #define VTK_LONG_MIN (-VTK_LARGE_INTEGER-1)
91 #define VTK_LONG_MAX VTK_LARGE_INTEGER
92 #define VTK_UNSIGNED_LONG_MIN 0
93 #define VTK_UNSIGNED_LONG_MAX 4294967295
94 #define VTK_FLOAT_MIN -VTK_LARGE_FLOAT
95 #define VTK_FLOAT_MAX VTK_LARGE_FLOAT
96 #define VTK_DOUBLE_MIN -1.0e+99L
97 #define VTK_DOUBLE_MAX 1.0e+99L
99 // These types are returned to distinguish dataset types
100 #define VTK_POLY_DATA 0
101 #define VTK_STRUCTURED_POINTS 1
102 #define VTK_STRUCTURED_GRID 2
103 #define VTK_RECTILINEAR_GRID 3
104 #define VTK_UNSTRUCTURED_GRID 4
106 // A macro to get the name of a type
107 #define vtkImageScalarTypeNameMacro(type) \
108 (((type) == VTK_VOID) ? "void" : \
109 (((type) == VTK_FLOAT) ? "float" : \
110 (((type) == VTK_INT) ? "int" : \
111 (((type) == VTK_SHORT) ? "short" : \
112 (((type) == VTK_UNSIGNED_SHORT) ? "unsigned short" : \
113 (((type) == VTK_UNSIGNED_CHAR) ? "unsigned char" : \
118 // Set built-in type. Creates member Set"name"() (e.g., SetVisibility());
120 #define vtkSetMacro(name,type) \
121 void Set##name (type _arg) \
123 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << _arg); \
132 // Get built-in type. Creates member Get"name"() (e.g., GetVisibility());
134 #define vtkGetMacro(name,type) \
135 type Get##name () { \
136 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " of " << name ); \
141 // Set character string. Creates member Set"name"()
142 // (e.g., SetFilename(char *));
144 #define vtkSetStringMacro(name) \
145 void Set##name (char* _arg) \
147 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << _arg ); \
148 if ( name && _arg && (!strcmp(name,_arg))) return; \
149 if (name) delete [] name; \
152 name = new char[strlen(_arg)+1]; \
163 // Get character string. Creates member Get"name"()
164 // (e.g., char *GetFilename());
166 #define vtkGetStringMacro(name) \
167 char* Get##name () { \
168 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " of " << name); \
173 // Set built-in type where value is constrained between min/max limits.
174 // Create member Set"name"() (e.q., SetRadius()). #defines are
175 // convienience for clamping open-ended values.
177 #define vtkSetClampMacro(name,type,min,max) \
178 void Set##name (type _arg) \
180 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << _arg ); \
181 if (name != (_arg<min?min:(_arg>max?max:_arg))) \
183 name = (_arg<min?min:(_arg>max?max:_arg)); \
189 // Set pointer to object. Creates method Set"name"() (e.g., SetPoints()).
191 #define vtkSetObjectMacro(name,type) \
192 void Set##name (type* _arg) \
194 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << _arg); \
201 void Set##name (type& _arg) \
207 // Set pointer to object; uses vtkReferenceCount reference counting methodology.
208 // Creates method Set"name"() (e.g., SetPoints()).
210 #define vtkSetReferenceCountedObjectMacro(name,type) \
211 void Set##name (type* _arg) \
213 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << _arg ); \
216 if (name != NULL) name->UnRegister(this); \
218 if (name != NULL) name->Register(this); \
224 // Get pointer to object. Creates member Get"name" (e.g., GetPoints()).
226 #define vtkGetObjectMacro(name,type) \
229 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " #name " address " << name ); \
234 // Create members "name"On() and "name"Off() (e.g., DebugOn() DebugOff()).
235 // Set method must be defined to use this macro.
237 #define vtkBooleanMacro(name,type) \
238 void name##On () { Set##name((type)1);}; \
239 void name##Off () { Set##name((type)0);}
242 // Following set macros for vectors define two members for each macro. The first
243 // allows setting of individual components (e.g, SetColor(float,float,float)),
244 // the second allows setting from an array (e.g., SetColor(float* rgb[3])).
245 // The macros vary in the size of the vector they deal with.
247 #define vtkSetVector2Macro(name,type) \
248 void Set##name (type _arg1, type _arg2) \
250 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to (" << _arg1 << "," << _arg2 << ")"); \
251 if ((name[0] != _arg1)||(name[1] != _arg2)) \
258 void Set##name (type _arg[2]) \
260 Set##name (_arg[0], _arg[1]); \
263 #define vtkGetVector2Macro(name,type) \
266 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " pointer " << name); \
269 void Get##name (type &_arg1, type &_arg2) \
273 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " = (" << _arg1 << "," << _arg2 << ")"); \
275 void Get##name (type _arg[2]) \
277 Get##name (_arg[0], _arg[1]);\
280 #define vtkSetVector3Macro(name,type) \
281 void Set##name (type _arg1, type _arg2, type _arg3) \
283 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to (" << _arg1 << "," << _arg2 << "," << _arg3 << ")"); \
284 if ((name[0] != _arg1)||(name[1] != _arg2)||(name[2] != _arg3)) \
292 void Set##name (type _arg[3]) \
294 Set##name (_arg[0], _arg[1], _arg[2]);\
297 #define vtkGetVector3Macro(name,type) \
300 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " pointer " << name); \
303 void Get##name (type &_arg1, type &_arg2, type &_arg3) \
308 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " = (" << _arg1 << "," << _arg2 << "," << _arg3 << ")"); \
310 void Get##name (type _arg[3]) \
312 Get##name (_arg[0], _arg[1], _arg[2]);\
315 #define vtkSetVector4Macro(name,type) \
316 void Set##name (type _arg1, type _arg2, type _arg3, type _arg4) \
318 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to (" << _arg1 << "," << _arg2 << "," << _arg3 << "," << _arg4 << ")"); \
319 if ((name[0] != _arg1)||(name[1] != _arg2)||(name[2] != _arg3)||(name[3] != _arg4)) \
328 void Set##name (type _arg[4]) \
330 Set##name (_arg[0], _arg[1], _arg[2], _arg[3]);\
333 #define vtkGetVector4Macro(name,type) \
336 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " pointer " << name); \
339 void Get##name (type &_arg1, type &_arg2, type &_arg3, type &_arg4) \
345 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " = (" << _arg1 << "," << _arg2 << "," << _arg3 << "," << _arg4 << ")"); \
347 void Get##name (type _arg[4]) \
349 Get##name (_arg[0], _arg[1], _arg[2], _arg[3]);\
353 // General set vector macro creates a single method that copies specified
354 // number of values into object.
355 // Examples: void SetColor(c,3)
357 #define vtkSetVectorMacro(name,type,count) \
358 void Set##name(type data[]) \
361 for (i=0; i<count; i++) if ( data[i] != name[i] ) break; \
365 for (i=0; i<count; i++) name[i] = data[i]; \
370 // Get vector macro defines two methods. One returns pointer to type
371 // (i.e., array of type). This is for efficiency. The second copies data
372 // into user provided array. This is more object-oriented.
373 // Examples: float *GetColor() and void GetColor(float c[count]).
375 #define vtkGetVectorMacro(name,type,count) \
378 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " pointer " << name); \
381 void Get##name (type data[count]) \
383 for (int i=0; i<count; i++) data[i] = name[i]; \
388 // This macro is used for any output that may not be in an instance method
389 // vtkGenericWarningMacro(<< "this is debug info" << this->SomeVariable);
391 #define vtkGenericWarningMacro(x) \
392 { if (vtkObject::GetGlobalWarningDisplay()) {char *vtkmsgbuff; ostrstream vtkmsg; \
393 vtkmsg << "Generic Warning: In " __FILE__ ", line " << __LINE__ << "\n" x << "\nPress Cancel to supress any further messages." << ends; \
394 vtkmsgbuff = vtkmsg.str(); \
395 if (MessageBox(NULL,vtkmsgbuff,"Debug Info",MB_ICONINFORMATION | MB_OKCANCEL) == IDCANCEL) vtkObject::GlobalWarningDisplayOff(); \
396 vtkmsg.rdbuf()->freeze(0);}}
399 // This macro is used for debug statements in instance methods
400 // vtkDebugMacro(<< "this is debug info" << this->SomeVariable);
402 #ifdef VTK_LEAN_AND_MEAN
403 #define vtkDebugMacro(x)
405 #define vtkDebugMacro(x) \
406 { if (Debug && vtkObject::GetGlobalWarningDisplay()) \
407 { char *vtkmsgbuff; ostrstream vtkmsg; \
408 vtkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" << this->GetClassName() << " (" << this << "): " x << "\nPress Cancel to supress any further messages." << ends; \
409 vtkmsgbuff = vtkmsg.str(); \
410 if (MessageBox(NULL,vtkmsgbuff,"Debug Info",MB_ICONINFORMATION | MB_OKCANCEL) == IDCANCEL) vtkObject::GlobalWarningDisplayOff(); \
411 vtkmsg.rdbuf()->freeze(0);}}
414 // This macro is used to print out warning messages.
415 // vtkWarningMacro(<< "Warning message" << variable);
417 #define vtkWarningMacro(x) \
418 { if (vtkObject::GetGlobalWarningDisplay()) {char *vtkmsgbuff; ostrstream vtkmsg; \
419 vtkmsg << "Warning: In " __FILE__ ", line " << __LINE__ << "\n" << this->GetClassName() << " (" << this << "): " x << "\nPress Cancel to supress any further messages." << ends; \
420 vtkmsgbuff = vtkmsg.str(); \
421 if (MessageBox(NULL,vtkmsgbuff,"Warning",MB_ICONWARNING | MB_OKCANCEL) == IDCANCEL) vtkObject::GlobalWarningDisplayOff(); \
422 vtkmsg.rdbuf()->freeze(0);}}
425 // This macro is used to print out errors
426 // vtkErrorMacro(<< "Error message" << variable);
428 #define vtkErrorMacro(x) \
429 { if (vtkObject::GetGlobalWarningDisplay()) {char *vtkmsgbuff; ostrstream vtkmsg; \
430 vtkmsg << "ERROR: In " __FILE__ ", line " << __LINE__ << "\n" << this->GetClassName() << " (" << this << "): " x << "\nPress Cancel to supress any further messages." << ends; \
431 vtkmsgbuff = vtkmsg.str(); \
432 if (MessageBox(NULL,vtkmsgbuff,"Error",MB_ICONERROR | MB_OKCANCEL) == IDCANCEL) vtkObject::GlobalWarningDisplayOff(); \
433 vtkmsg.rdbuf()->freeze(0); vtkObject::BreakOnError();}}
437 // This macro is used for any output that may not be in an instance method
438 // vtkGenericWarningMacro(<< "this is debug info" << this->SomeVariable);
440 #define vtkGenericWarningMacro(x) \
441 if (vtkObject::GetGlobalWarningDisplay()) cerr << "Generic Warning: In " __FILE__ ", line " << __LINE__ << "\n " x << "\n\n"
444 // This macro is used for debug statements in instance methods
445 // vtkDebugMacro(<< "this is debug info" << this->SomeVariable);
447 #ifdef VTK_LEAN_AND_MEAN
448 #define vtkDebugMacro(x)
450 #define vtkDebugMacro(x) \
451 if (Debug && vtkObject::GetGlobalWarningDisplay()) cerr << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" << this->GetClassName() << " (" << this << "): " x << "\n\n"
454 // This macro is used to print out warning messages.
455 // vtkWarningMacro(<< "Warning message" << variable);
457 #define vtkWarningMacro(x) \
458 if (vtkObject::GetGlobalWarningDisplay()) cerr << "Warning: In " __FILE__ ", line " << __LINE__ << "\n" << this->GetClassName() << " (" << this << "): " x << "\n\n"
461 // This macro is used to print out errors
462 // vtkErrorMacro(<< "Error message" << variable);
464 #define vtkErrorMacro(x) \
465 { if (vtkObject::GetGlobalWarningDisplay()) cerr << "ERROR In " __FILE__ ", line " << __LINE__ << "\n" << this->GetClassName() << " (" << this << "): " x << "\n\n"; vtkObject::BreakOnError();}
469 // This macro is used to quiet compiler warnings about unused parameters
470 // to methods. Only use it when the parameter really shouldn't be used.
471 // Don't use it as a way to shut up the compiler while you take your
472 // sweet time getting around to implementing the method.
474 #define vtkNotUsed(x)
476 #define vtkWorldCoordinateMacro(name) \
477 vtkCoordinate *Get##name##Coordinate () \
479 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " #name "Coordinate address " << name##Coordinate ); \
480 return name##Coordinate; \
482 void Set##name(float x[3]) {this->Set##name(x[0],x[1],x[2]);}; \
483 void Set##name(float x, float y, float z) \
485 this->name##Coordinate->SetCoordinateSystem(VTK_WORLD); \
486 this->name##Coordinate->SetValue(x,y,z); \
490 return this->name##Coordinate->GetValue(); \
493 #define vtkViewportCoordinateMacro(name) \
494 vtkCoordinate *Get##name##Coordinate () \
496 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " #name "Coordinate address " << name##Coordinate ); \
497 return name##Coordinate; \
499 void Set##name(float x[2]) {this->Set##name(x[0],x[1]);}; \
500 void Set##name(float x, float y) \
502 this->name##Coordinate->SetCoordinateSystem(VTK_VIEWPORT); \
503 this->name##Coordinate->SetValue(x,y); \
507 return this->name##Coordinate->GetValue(); \