OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / SGI / util / SGI / include / vtk / vtkSetGet.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkSetGet.h,v $
5   Language:  C++
6   Date:      $Date: 2002/02/01 06:30:42 $
7   Version:   $Revision: 1.1.1.1 $
8
9
10 Copyright (c) 1993-1998 Ken Martin, Will Schroeder, Bill Lorensen.
11
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.
17
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.
27
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.
32
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.
38
39
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.
46 //
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.
50
51 #ifndef __vtkSetGet_h
52 #define __vtkSetGet_h
53 #include <string.h>
54
55 //
56 // Some constants used throughout code
57 //
58 #define VTK_LARGE_FLOAT 1.0e+38F
59 #define VTK_LARGE_INTEGER 2147483647 // 2^31 - 1
60
61 // These types are returned by GetDataType to indicate pixel type.
62 #define VTK_VOID            0
63 #define VTK_BIT             1 
64 #define VTK_CHAR            2
65 #define VTK_UNSIGNED_CHAR   3
66 #define VTK_SHORT           4
67 #define VTK_UNSIGNED_SHORT  5
68 #define VTK_INT             6
69 #define VTK_UNSIGNED_INT    7
70 #define VTK_LONG            8
71 #define VTK_UNSIGNED_LONG   9
72 #define VTK_FLOAT          10
73 #define VTK_DOUBLE         11 
74
75 // Some constant required for correct template performance
76 #define VTK_BIT_MIN 0
77 #define VTK_BIT_MAX 1
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
98
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
105
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" : \
114 "Undefined"))))))
115   
116   
117 //
118 // Set built-in type.  Creates member Set"name"() (e.g., SetVisibility());
119 //
120 #define vtkSetMacro(name,type) \
121 void Set##name (type _arg) \
122   { \
123   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << _arg); \
124   if (name != _arg) \
125     { \
126     name = _arg; \
127     this->Modified(); \
128     } \
129   } 
130
131 //
132 // Get built-in type.  Creates member Get"name"() (e.g., GetVisibility());
133 //
134 #define vtkGetMacro(name,type) \
135 type Get##name () { \
136   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " of " << name ); \
137   return name; \
138   } 
139
140 //
141 // Set character string.  Creates member Set"name"() 
142 // (e.g., SetFilename(char *));
143 //
144 #define vtkSetStringMacro(name) \
145 void Set##name (char* _arg) \
146   { \
147   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << _arg ); \
148   if ( name && _arg && (!strcmp(name,_arg))) return; \
149   if (name) delete [] name; \
150   if (_arg) \
151     { \
152     name = new char[strlen(_arg)+1]; \
153     strcpy(name,_arg); \
154     } \
155    else \
156     { \
157     name = NULL; \
158     } \
159   this->Modified(); \
160   } 
161
162 //
163 // Get character string.  Creates member Get"name"() 
164 // (e.g., char *GetFilename());
165 //
166 #define vtkGetStringMacro(name) \
167 char* Get##name () { \
168   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " of " << name); \
169   return name; \
170   } 
171
172 //
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.
176 //
177 #define vtkSetClampMacro(name,type,min,max) \
178 void Set##name (type _arg) \
179   { \
180   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << _arg ); \
181   if (name != (_arg<min?min:(_arg>max?max:_arg))) \
182     { \
183     name = (_arg<min?min:(_arg>max?max:_arg)); \
184     this->Modified(); \
185     } \
186   } 
187
188 //
189 // Set pointer to object. Creates method Set"name"() (e.g., SetPoints()).
190 //
191 #define vtkSetObjectMacro(name,type) \
192 void Set##name (type* _arg) \
193   { \
194   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << _arg); \
195   if (name != _arg) \
196     { \
197     name = _arg; \
198     this->Modified(); \
199     } \
200   } \
201 void Set##name (type& _arg) \
202   { \
203   Set##name (&_arg);\
204   } 
205
206 //
207 // Set pointer to object; uses vtkReferenceCount reference counting methodology.
208 // Creates method Set"name"() (e.g., SetPoints()).
209 //
210 #define vtkSetReferenceCountedObjectMacro(name,type) \
211 void Set##name (type* _arg) \
212   { \
213   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << _arg ); \
214   if (name != _arg) \
215     { \
216     if (name != NULL) name->UnRegister(this); \
217     name = _arg; \
218     if (name != NULL) name->Register(this); \
219     this->Modified(); \
220     } \
221   } 
222
223 //
224 // Get pointer to object.  Creates member Get"name" (e.g., GetPoints()).
225 //
226 #define vtkGetObjectMacro(name,type) \
227 type *Get##name () \
228   { \
229       vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " #name " address " << name ); \
230   return name; \
231   } 
232
233 //
234 // Create members "name"On() and "name"Off() (e.g., DebugOn() DebugOff()).
235 // Set method must be defined to use this macro.
236 //
237 #define vtkBooleanMacro(name,type) \
238 void name##On () { Set##name((type)1);}; \
239 void name##Off () { Set##name((type)0);}
240
241 //
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.
246 //
247 #define vtkSetVector2Macro(name,type) \
248 void Set##name (type _arg1, type _arg2) \
249   { \
250   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to (" << _arg1 << "," << _arg2 << ")"); \
251   if ((name[0] != _arg1)||(name[1] != _arg2)) \
252     { \
253     this->Modified(); \
254     name[0] = _arg1; \
255     name[1] = _arg2; \
256     } \
257   }; \
258 void Set##name (type _arg[2]) \
259   { \
260   Set##name (_arg[0], _arg[1]); \
261   } 
262
263 #define vtkGetVector2Macro(name,type) \
264 type *Get##name () \
265 { \
266   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " pointer " << name); \
267   return name; \
268 } \
269 void Get##name (type &_arg1, type &_arg2) \
270   { \
271     _arg1 = name[0]; \
272     _arg2 = name[1]; \
273   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " = (" << _arg1 << "," << _arg2 << ")"); \
274   }; \
275 void Get##name (type _arg[2]) \
276   { \
277   Get##name (_arg[0], _arg[1]);\
278   } 
279
280 #define vtkSetVector3Macro(name,type) \
281 void Set##name (type _arg1, type _arg2, type _arg3) \
282   { \
283   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to (" << _arg1 << "," << _arg2 << "," << _arg3 << ")"); \
284   if ((name[0] != _arg1)||(name[1] != _arg2)||(name[2] != _arg3)) \
285     { \
286     this->Modified(); \
287     name[0] = _arg1; \
288     name[1] = _arg2; \
289     name[2] = _arg3; \
290     } \
291   }; \
292 void Set##name (type _arg[3]) \
293   { \
294   Set##name (_arg[0], _arg[1], _arg[2]);\
295   } 
296
297 #define vtkGetVector3Macro(name,type) \
298 type *Get##name () \
299 { \
300   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " pointer " << name); \
301   return name; \
302 } \
303 void Get##name (type &_arg1, type &_arg2, type &_arg3) \
304   { \
305     _arg1 = name[0]; \
306     _arg2 = name[1]; \
307     _arg3 = name[2]; \
308   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " = (" << _arg1 << "," << _arg2 << "," << _arg3 << ")"); \
309   }; \
310 void Get##name (type _arg[3]) \
311   { \
312   Get##name (_arg[0], _arg[1], _arg[2]);\
313   } 
314
315 #define vtkSetVector4Macro(name,type) \
316 void Set##name (type _arg1, type _arg2, type _arg3, type _arg4) \
317   { \
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)) \
320     { \
321     this->Modified(); \
322     name[0] = _arg1; \
323     name[1] = _arg2; \
324     name[2] = _arg3; \
325     name[3] = _arg4; \
326     } \
327   }; \
328 void Set##name (type _arg[4]) \
329   { \
330   Set##name (_arg[0], _arg[1], _arg[2], _arg[3]);\
331   } 
332
333 #define vtkGetVector4Macro(name,type) \
334 type *Get##name () \
335 { \
336   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " pointer " << name); \
337   return name; \
338 } \
339 void Get##name (type &_arg1, type &_arg2, type &_arg3, type &_arg4) \
340   { \
341     _arg1 = name[0]; \
342     _arg2 = name[1]; \
343     _arg3 = name[2]; \
344     _arg4 = name[3]; \
345   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " = (" << _arg1 << "," << _arg2 << "," << _arg3 << "," << _arg4 << ")"); \
346   }; \
347 void Get##name (type _arg[4]) \
348   { \
349   Get##name (_arg[0], _arg[1], _arg[2], _arg[3]);\
350   } 
351
352 //
353 // General set vector macro creates a single method that copies specified
354 // number of values into object.
355 // Examples: void SetColor(c,3)
356 //
357 #define vtkSetVectorMacro(name,type,count) \
358 void Set##name(type data[]) \
359 { \
360   int i; \
361   for (i=0; i<count; i++) if ( data[i] != name[i] ) break; \
362   if ( i < count ) \
363     { \
364     this->Modified(); \
365     for (i=0; i<count; i++) name[i] = data[i]; \
366     } \
367 }
368
369 //
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]).
374 //
375 #define vtkGetVectorMacro(name,type,count) \
376 type *Get##name () \
377 { \
378   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " pointer " << name); \
379   return name; \
380 } \
381 void Get##name (type data[count]) \
382 { \
383   for (int i=0; i<count; i++) data[i] = name[i]; \
384 }
385
386 #ifdef _WIN32
387 //
388 // This macro is used for any output that may not be in an instance method
389 // vtkGenericWarningMacro(<< "this is debug info" << this->SomeVariable);
390 //
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);}}
397
398 //
399 // This macro is used for  debug statements in instance methods
400 // vtkDebugMacro(<< "this is debug info" << this->SomeVariable);
401 //
402 #ifdef VTK_LEAN_AND_MEAN
403 #define vtkDebugMacro(x)
404 #else
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);}}
412 #endif
413 //
414 // This macro is used to print out warning messages.
415 // vtkWarningMacro(<< "Warning message" << variable);
416 //
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);}}
423
424 //
425 // This macro is used to print out errors
426 // vtkErrorMacro(<< "Error message" << variable);
427 //
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();}}
434
435 #else
436 //
437 // This macro is used for any output that may not be in an instance method
438 // vtkGenericWarningMacro(<< "this is debug info" << this->SomeVariable);
439 //
440 #define vtkGenericWarningMacro(x) \
441 if (vtkObject::GetGlobalWarningDisplay()) cerr << "Generic Warning: In " __FILE__ ", line " << __LINE__ << "\n  " x << "\n\n"
442
443 //
444 // This macro is used for  debug statements in instance methods
445 // vtkDebugMacro(<< "this is debug info" << this->SomeVariable);
446 //
447 #ifdef VTK_LEAN_AND_MEAN
448 #define vtkDebugMacro(x)
449 #else
450 #define vtkDebugMacro(x) \
451 if (Debug && vtkObject::GetGlobalWarningDisplay()) cerr << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" << this->GetClassName() << " (" << this << "): " x <<  "\n\n"
452 #endif
453 //
454 // This macro is used to print out warning messages.
455 // vtkWarningMacro(<< "Warning message" << variable);
456 //
457 #define vtkWarningMacro(x) \
458 if (vtkObject::GetGlobalWarningDisplay()) cerr << "Warning: In " __FILE__ ", line " << __LINE__ << "\n" << this->GetClassName() << " (" << this << "): " x << "\n\n"
459
460 //
461 // This macro is used to print out errors
462 // vtkErrorMacro(<< "Error message" << variable);
463 //
464 #define vtkErrorMacro(x) \
465 { if (vtkObject::GetGlobalWarningDisplay()) cerr << "ERROR In " __FILE__ ", line " << __LINE__ << "\n" << this->GetClassName() << " (" << this << "): " x << "\n\n"; vtkObject::BreakOnError();}
466 #endif
467
468 //
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.
473 //
474 #define vtkNotUsed(x)
475
476 #define vtkWorldCoordinateMacro(name) \
477 vtkCoordinate *Get##name##Coordinate () \
478 { \
479     vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " #name "Coordinate address " << name##Coordinate ); \
480     return name##Coordinate; \
481 } \
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) \
484 { \
485     this->name##Coordinate->SetCoordinateSystem(VTK_WORLD); \
486     this->name##Coordinate->SetValue(x,y,z); \
487 } \
488 float *Get##name() \
489 { \
490     return this->name##Coordinate->GetValue(); \
491 }
492
493 #define vtkViewportCoordinateMacro(name) \
494 vtkCoordinate *Get##name##Coordinate () \
495 { \
496     vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " #name "Coordinate address " << name##Coordinate ); \
497     return name##Coordinate; \
498 } \
499 void Set##name(float x[2]) {this->Set##name(x[0],x[1]);}; \
500 void Set##name(float x, float y) \
501 { \
502     this->name##Coordinate->SetCoordinateSystem(VTK_VIEWPORT); \
503     this->name##Coordinate->SetValue(x,y); \
504 } \
505 float *Get##name() \
506 { \
507     return this->name##Coordinate->GetValue(); \
508 }
509
510 #endif