00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkStructuredVisibilityConstraint.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00028 #ifndef __vtkStructuredVisibilityConstraint_h 00029 #define __vtkStructuredVisibilityConstraint_h 00030 00031 #include "vtkObject.h" 00032 00033 #include "vtkUnsignedCharArray.h" // Needed for inline methods. 00034 00035 class VTK_COMMON_EXPORT vtkStructuredVisibilityConstraint : public vtkObject 00036 { 00037 public: 00038 static vtkStructuredVisibilityConstraint *New(); 00039 00040 vtkTypeMacro(vtkStructuredVisibilityConstraint,vtkObject); 00041 void PrintSelf(ostream& os, vtkIndent indent); 00042 00044 unsigned char IsVisible(vtkIdType id); 00045 00049 void Blank(vtkIdType id); 00050 00052 void UnBlank(vtkIdType id); 00053 00055 00056 vtkGetVectorMacro(Dimensions,int,3); 00058 00061 void Initialize(int dims[3]); 00062 00064 00065 void SetVisibilityById(vtkUnsignedCharArray* vis); 00066 vtkGetObjectMacro(VisibilityById, vtkUnsignedCharArray); 00068 00071 void ShallowCopy(vtkStructuredVisibilityConstraint* src); 00072 00074 void DeepCopy(vtkStructuredVisibilityConstraint* src); 00075 00077 00079 unsigned char IsConstrained() 00080 { 00081 return this->VisibilityById ? 1 : 0; 00082 } 00084 00085 protected: 00086 vtkStructuredVisibilityConstraint(); 00087 ~vtkStructuredVisibilityConstraint(); 00088 00089 vtkUnsignedCharArray* VisibilityById; 00090 int Dimensions[3]; 00091 vtkIdType NumberOfIds; 00092 unsigned char Initialized; 00093 00094 private: 00095 vtkStructuredVisibilityConstraint(const vtkStructuredVisibilityConstraint&); // Not implemented. 00096 void operator=(const vtkStructuredVisibilityConstraint&); // Not implemented. 00097 }; 00098 00099 //---------------------------------------------------------------------------- 00100 // These methods are inline for efficiency. 00101 00102 //---------------------------------------------------------------------------- 00103 inline unsigned char vtkStructuredVisibilityConstraint::IsVisible( 00104 vtkIdType id) 00105 { 00106 vtkUnsignedCharArray* vis = this->VisibilityById; 00107 return vis ? vis->GetValue(id) : 1; 00108 } 00109 00110 //---------------------------------------------------------------------------- 00111 inline void vtkStructuredVisibilityConstraint::Blank(vtkIdType id) 00112 { 00113 vtkUnsignedCharArray* vis = this->VisibilityById; 00114 if (!vis) 00115 { 00116 this->VisibilityById = vtkUnsignedCharArray::New(); 00117 vis = this->VisibilityById; 00118 this->VisibilityById->SetNumberOfTuples(this->NumberOfIds); 00119 for (int i=0; i<this->NumberOfIds; ++i) 00120 { 00121 this->VisibilityById->SetValue(i, 1); 00122 } 00123 } 00124 vis->SetValue(id, 0); 00125 } 00126 00127 //---------------------------------------------------------------------------- 00128 inline void vtkStructuredVisibilityConstraint::UnBlank(vtkIdType id) 00129 { 00130 vtkUnsignedCharArray* vis = this->VisibilityById; 00131 if (!vis) 00132 { 00133 return; 00134 } 00135 vis->SetValue(id, 1); 00136 } 00137 00138 //---------------------------------------------------------------------------- 00139 inline void vtkStructuredVisibilityConstraint::Initialize(int dims[3]) 00140 { 00141 if (this->Initialized) 00142 { 00143 return; 00144 } 00145 for (int i=0; i<3; i++) 00146 { 00147 this->Dimensions[i] = dims[i]; 00148 } 00149 this->NumberOfIds = static_cast<vtkIdType>(dims[0])* 00150 static_cast<vtkIdType>(dims[1])* 00151 static_cast<vtkIdType>(dims[2]); 00152 this->Initialized = 1; 00153 } 00154 00155 #endif 00156