1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkUniformGridAMR.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 #include "vtkOverlappingAMR.h"
16 #include "vtkUniformGridAMRDataIterator.h"
17 #include "vtkObjectFactory.h"
18 #include "vtkAMRInformation.h"
19 #include "vtkUnsignedCharArray.h"
20 #include "vtkUniformGrid.h"
21 #include "vtkInformationIdTypeKey.h"
22 #include "vtkCellData.h"
23 #include "vtkDataSetAttributes.h"
24 #include <vector>
25
26 vtkStandardNewMacro(vtkOverlappingAMR);
27
28 vtkInformationKeyMacro(vtkOverlappingAMR,NUMBER_OF_BLANKED_POINTS,IdType);
29
30 //----------------------------------------------------------------------------
31 vtkOverlappingAMR::vtkOverlappingAMR() = default;
32
33 //----------------------------------------------------------------------------
34 vtkOverlappingAMR::~vtkOverlappingAMR() = default;
35
36 //----------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)37 void vtkOverlappingAMR::PrintSelf(ostream& os, vtkIndent indent)
38 {
39 this->Superclass::PrintSelf(os,indent);
40 if(this->AMRInfo)
41 {
42 this->AMRInfo->PrintSelf(os,indent);
43 }
44 }
45
46 //----------------------------------------------------------------------------
NewIterator()47 vtkCompositeDataIterator* vtkOverlappingAMR::NewIterator()
48 {
49 vtkUniformGridAMRDataIterator* iter = vtkUniformGridAMRDataIterator::New();
50 iter->SetDataSet( this );
51 return iter;
52 }
53
54 //----------------------------------------------------------------------------
SetRefinementRatio(unsigned int level,int ratio)55 void vtkOverlappingAMR::SetRefinementRatio(unsigned int level,
56 int ratio)
57 {
58 this->AMRInfo->SetRefinementRatio(level,ratio);
59 }
60
61 //----------------------------------------------------------------------------
GetRefinementRatio(unsigned int level)62 int vtkOverlappingAMR::GetRefinementRatio(unsigned int level)
63 {
64 if(!AMRInfo->HasRefinementRatio())
65 {
66 AMRInfo->GenerateRefinementRatio();
67 }
68 return this->AMRInfo->GetRefinementRatio(level);
69 }
70
71
72 //----------------------------------------------------------------------------
GetRefinementRatio(vtkCompositeDataIterator * iter)73 int vtkOverlappingAMR::GetRefinementRatio(vtkCompositeDataIterator* iter)
74 {
75 vtkUniformGridAMRDataIterator *amrIter =
76 vtkUniformGridAMRDataIterator::SafeDownCast( iter );
77
78 unsigned int level = amrIter->GetCurrentLevel();
79 return this->AMRInfo->GetRefinementRatio(level);
80 }
81
82 //----------------------------------------------------------------------------
GenerateParentChildInformation()83 void vtkOverlappingAMR::GenerateParentChildInformation()
84 {
85 this->AMRInfo->GenerateParentChildInformation();
86 }
87
88 //----------------------------------------------------------------------------
89 bool vtkOverlappingAMR::
HasChildrenInformation()90 HasChildrenInformation()
91 {
92 return AMRInfo->HasChildrenInformation();
93 }
94
95 //----------------------------------------------------------------------------
96 unsigned int *vtkOverlappingAMR::
GetParents(unsigned int level,unsigned int index,unsigned int & num)97 GetParents(unsigned int level, unsigned int index, unsigned int& num)
98 {
99 return this->AMRInfo->GetParents(level,index,num);
100 }
101
102 //------------------------------------------------------------------------------
103 unsigned int *vtkOverlappingAMR::
GetChildren(unsigned int level,unsigned int index,unsigned int & num)104 GetChildren(unsigned int level, unsigned int index, unsigned int& num)
105 {
106 return this->AMRInfo->GetChildren(level,index,num);
107 }
108
109 //------------------------------------------------------------------------------
110 void vtkOverlappingAMR::
PrintParentChildInfo(unsigned int level,unsigned int index)111 PrintParentChildInfo(unsigned int level, unsigned int index)
112 {
113 this->AMRInfo->PrintParentChildInfo(level,index);
114 }
115
116 //------------------------------------------------------------------------------
SetAMRBox(unsigned int level,unsigned int id,const vtkAMRBox & box)117 void vtkOverlappingAMR::SetAMRBox(unsigned int level, unsigned int id, const vtkAMRBox& box)
118 {
119 this->AMRInfo->SetAMRBox(level,id,box);
120 }
121
122 //------------------------------------------------------------------------------
GetAMRBox(unsigned int level,unsigned int id)123 const vtkAMRBox& vtkOverlappingAMR::GetAMRBox(unsigned int level, unsigned int id)
124 {
125 const vtkAMRBox& box = this->AMRInfo->GetAMRBox(level,id);
126 if(box.IsInvalid())
127 {
128 vtkErrorMacro("Invalid AMR box");
129 }
130 return box;
131 }
132
133 //------------------------------------------------------------------------------
SetSpacing(unsigned int level,const double spacing[3])134 void vtkOverlappingAMR::SetSpacing(unsigned int level,const double spacing[3])
135 {
136 this->AMRInfo->SetSpacing(level,spacing);
137 }
138
139 //------------------------------------------------------------------------------
GetSpacing(unsigned int level,double spacing[3])140 void vtkOverlappingAMR::GetSpacing(unsigned int level, double spacing[3])
141 {
142 return this->AMRInfo->GetSpacing(level,spacing);
143 }
144
145 //----------------------------------------------------------------------------
GetBounds(unsigned int level,unsigned int id,double * bb)146 void vtkOverlappingAMR::GetBounds(unsigned int level, unsigned int id, double* bb)
147 {
148 this->AMRInfo->GetBounds(level, id, bb);
149 }
150
151 //----------------------------------------------------------------------------
GetOrigin(unsigned int level,unsigned int id,double origin[3])152 void vtkOverlappingAMR::GetOrigin(unsigned int level, unsigned int id, double origin[3])
153 {
154 double bb[6];
155 this->GetBounds(level,id,bb);
156 origin[0] = bb[0];
157 origin[1] = bb[2];
158 origin[2] = bb[4];
159 }
160
161
162 //----------------------------------------------------------------------------
SetOrigin(const double * origin)163 void vtkOverlappingAMR::SetOrigin(const double* origin)
164 {
165 return this->AMRInfo->SetOrigin(origin);
166 }
167
168 //----------------------------------------------------------------------------
GetOrigin()169 double* vtkOverlappingAMR::GetOrigin()
170 {
171 return this->AMRInfo? this->AMRInfo->GetOrigin() : nullptr;
172 }
173
174 //----------------------------------------------------------------------------
SetAMRBlockSourceIndex(unsigned int level,unsigned int id,int sourceId)175 void vtkOverlappingAMR::SetAMRBlockSourceIndex(unsigned int level, unsigned int id, int sourceId)
176 {
177 unsigned int index = this->AMRInfo->GetIndex(level,id);
178 this->AMRInfo->SetAMRBlockSourceIndex(index, sourceId);
179 }
180
181 //----------------------------------------------------------------------------
GetAMRBlockSourceIndex(unsigned int level,unsigned int id)182 int vtkOverlappingAMR::GetAMRBlockSourceIndex(unsigned int level, unsigned int id)
183 {
184 unsigned int index = this->AMRInfo->GetIndex(level,id);
185 return this->AMRInfo->GetAMRBlockSourceIndex(index);
186 }
187
188 //----------------------------------------------------------------------------
Audit()189 void vtkOverlappingAMR::Audit()
190 {
191 this->AMRInfo->Audit();
192
193 int emptyDimension(-1);
194 switch (this->GetGridDescription())
195 {
196 case VTK_YZ_PLANE: emptyDimension = 0; break;
197 case VTK_XZ_PLANE: emptyDimension = 1; break;
198 case VTK_XY_PLANE: emptyDimension = 2; break;
199 }
200
201 vtkSmartPointer<vtkUniformGridAMRDataIterator> iter;
202 iter.TakeReference(vtkUniformGridAMRDataIterator::SafeDownCast(this->NewIterator()));
203 iter->SetSkipEmptyNodes(1);
204 for(iter->GoToFirstItem(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
205 {
206 vtkUniformGrid* grid = vtkUniformGrid::SafeDownCast(iter->GetCurrentDataObject());
207 int hasGhost = grid->HasAnyGhostCells();
208
209 unsigned int level = iter->GetCurrentLevel();
210 unsigned int id = iter->GetCurrentIndex();
211 const vtkAMRBox& box = this->AMRInfo->GetAMRBox(level,id);
212 int dims[3];
213 box.GetNumberOfNodes(dims);
214
215 double spacing[3];
216 this->GetSpacing(level,spacing);
217
218 double origin[3];
219 this->GetOrigin(level,id,origin);
220
221 for(int d = 0; d<3; d++)
222 {
223 if(d==emptyDimension)
224 {
225 if(grid->GetSpacing()[d]!=spacing[d])
226 {
227 vtkErrorMacro("The grid spacing does not match AMRInfo at ("<<level<<", "<<id<<")");
228 }
229 if(!hasGhost && grid->GetOrigin()[d]!=origin[d])
230 {
231 vtkErrorMacro("The grid origin does not match AMRInfo at ("<<level<<", "<<id<<")");
232 }
233 if(!hasGhost && grid->GetDimensions()[d]!=dims[d])
234 {
235 vtkErrorMacro("The grid dimensions does not match AMRInfo at ("<<level<<", "<<id<<")");
236 }
237 }
238 }
239 }
240 }
241
242
FindGrid(double q[3],unsigned int & level,unsigned int & gridId)243 bool vtkOverlappingAMR::FindGrid(double q[3], unsigned int& level, unsigned int& gridId)
244 {
245 return this->AMRInfo->FindGrid(q,level,gridId);
246 }
247