1 | |
---|
2 | #ifndef LSCE_EXPORTS |
---|
3 | # include "lscereader.hpp" |
---|
4 | #else |
---|
5 | # include "vtkLSCEReader.h" |
---|
6 | #endif //LSCE_EXPORTS |
---|
7 | |
---|
8 | |
---|
9 | // BibliothÚque VTK |
---|
10 | #include "vtkObjectFactory.h" |
---|
11 | #include "vtkInformation.h" |
---|
12 | #include "vtkInformationVector.h" |
---|
13 | #include "vtkStreamingDemandDrivenPipeline.h" |
---|
14 | |
---|
15 | #include <vtkProperty.h> |
---|
16 | #include <vtkDataSetMapper.h> |
---|
17 | #include <vtkActor.h> |
---|
18 | #include <vtkRenderWindow.h> |
---|
19 | #include <vtkRenderer.h> |
---|
20 | #include <vtkRenderWindowInteractor.h> |
---|
21 | #include <vtkLegendScaleActor.h> |
---|
22 | |
---|
23 | #include "vtkMath.h" |
---|
24 | |
---|
25 | #include "inetcdf4_impl.hpp" |
---|
26 | #include "inetcdf4_adv_impl.hpp" |
---|
27 | |
---|
28 | // Type Fortran |
---|
29 | #define ARRAY(valuetype, numdims) boost::shared_ptr<boost::multi_array<valuetype, numdims> > |
---|
30 | |
---|
31 | #define ARRAY_ASSIGN(value, valuetype, numdims, extent)\ |
---|
32 | value.reset(new boost::multi_array<valuetype, numdims>(boost::extents extent)) |
---|
33 | |
---|
34 | #define ARRAY_CREATE(value, valuetype, numdims, extent)\ |
---|
35 | ARRAY(valuetype, numdims) value = \ |
---|
36 | ARRAY(valuetype, numdims)(new boost::multi_array<valuetype, numdims>(boost::extents extent)) |
---|
37 | |
---|
38 | // Type C |
---|
39 | #define ARRAY_C_ASSIGN(value, valuetype, numdims, extent)\ |
---|
40 | value = ARRAY(valuetype, numdims) \ |
---|
41 | (new boost::multi_array<valuetype, numdims>(boost::extents extent, c_storage_order())) |
---|
42 | |
---|
43 | #define ARRAY_C_CREATE(value, valuetype, numdims, extent)\ |
---|
44 | ARRAY_C_ASSIGN(ARRAY(valuetype, numdims) value, valuetype, numdims, extent) |
---|
45 | |
---|
46 | |
---|
47 | #ifndef LSCE_EXPORTS |
---|
48 | namespace xmlioserver |
---|
49 | { |
---|
50 | namespace vtk |
---|
51 | { |
---|
52 | #endif //LSCE_EXPORTS |
---|
53 | |
---|
54 | /// ////////////////////// Définitions ////////////////////// /// |
---|
55 | vtkStandardNewMacro(vtkLSCEReader); |
---|
56 | |
---|
57 | vtkLSCEReader::vtkLSCEReader(void) |
---|
58 | : FileName(), CurGridType(RECTILINEAR), VarNames() |
---|
59 | , A3D(true), ATemporal(true), ACell(true) |
---|
60 | , Reader() |
---|
61 | { |
---|
62 | this->SetNumberOfInputPorts (0); |
---|
63 | this->SetNumberOfOutputPorts(1); |
---|
64 | } |
---|
65 | |
---|
66 | vtkLSCEReader::~vtkLSCEReader(void) |
---|
67 | { |
---|
68 | |
---|
69 | } |
---|
70 | |
---|
71 | ///--------------------------------------------------------------- |
---|
72 | |
---|
73 | void vtkLSCEReader::SetFileName(const vtkStdString & fileName) |
---|
74 | { |
---|
75 | this->FileName = fileName; |
---|
76 | this->Reader = boost::shared_ptr<xmlioserver::io::CINetCDF4Adv> |
---|
77 | (new xmlioserver::io::CINetCDF4Adv(fileName)); |
---|
78 | this->Modified(); |
---|
79 | } |
---|
80 | |
---|
81 | void vtkLSCEReader::SetVariable(const vtkStdString & variable) |
---|
82 | { |
---|
83 | this->RemoveAllSelectedVariables(); |
---|
84 | this->AddVariableToSelection(variable); |
---|
85 | this->Modified(); |
---|
86 | } |
---|
87 | |
---|
88 | const char * vtkLSCEReader::GetFileName(void) const |
---|
89 | { |
---|
90 | return (this->FileName.c_str()); |
---|
91 | } |
---|
92 | |
---|
93 | void vtkLSCEReader::PrintSelf(ostream& os, vtkIndent indent) |
---|
94 | { |
---|
95 | this->Superclass::PrintSelf(os,indent); |
---|
96 | } |
---|
97 | |
---|
98 | //---------------------------------------------------------------- |
---|
99 | void vtkLSCEReader::AddVariableToSelection(const vtkStdString & varName) |
---|
100 | { |
---|
101 | if (this->Reader->isRectilinear(varName)) |
---|
102 | this->SetGridType (RECTILINEAR); |
---|
103 | else if (this->Reader->isCurvilinear(varName)) |
---|
104 | this->SetGridType (CURVILINEAR); |
---|
105 | else |
---|
106 | this->SetGridType (UNSTRUCTURED); |
---|
107 | |
---|
108 | this->VarNames.insert(varName); |
---|
109 | } |
---|
110 | |
---|
111 | void vtkLSCEReader::RemoveSelectedVariable(const vtkStdString & varName) |
---|
112 | { |
---|
113 | std::set<vtkStdString>::iterator it = this->VarNames.find(varName); |
---|
114 | if (it != this->VarNames.end()) this->VarNames.erase(it); |
---|
115 | } |
---|
116 | |
---|
117 | void vtkLSCEReader::RemoveAllSelectedVariables(void) |
---|
118 | { |
---|
119 | this->VarNames.clear(); |
---|
120 | } |
---|
121 | |
---|
122 | const std::set<vtkStdString> & |
---|
123 | vtkLSCEReader::GetSelectedVariables(void) const |
---|
124 | { |
---|
125 | return (this->VarNames); |
---|
126 | } |
---|
127 | |
---|
128 | bool vtkLSCEReader::HasSelectedVariable(void) const |
---|
129 | { |
---|
130 | return (this->VarNames.size() != 0); |
---|
131 | } |
---|
132 | |
---|
133 | //---------------------------------------------------------------- |
---|
134 | |
---|
135 | void vtkLSCEReader::SetGridType (GridType type) |
---|
136 | { |
---|
137 | if ((this->IsUnstructured() && (type == CURVILINEAR)) || |
---|
138 | (this->IsUnstructured() && (type == RECTILINEAR)) || |
---|
139 | (this->IsCurvilinear() && (type == RECTILINEAR))) |
---|
140 | this->RemoveAllSelectedVariables(); |
---|
141 | this->CurGridType = type; |
---|
142 | } |
---|
143 | |
---|
144 | bool vtkLSCEReader::IsUnstructured(void) const |
---|
145 | { |
---|
146 | return (this->CurGridType == UNSTRUCTURED); |
---|
147 | } |
---|
148 | |
---|
149 | bool vtkLSCEReader::IsCurvilinear(void) const |
---|
150 | { |
---|
151 | return (this->CurGridType == CURVILINEAR); |
---|
152 | } |
---|
153 | |
---|
154 | bool vtkLSCEReader::IsRectilinear(void) const |
---|
155 | { |
---|
156 | return (this->CurGridType == RECTILINEAR); |
---|
157 | } |
---|
158 | |
---|
159 | //---------------------------------------------------------------- |
---|
160 | |
---|
161 | void vtkLSCEReader::AcceptTemporalOnly(bool value) |
---|
162 | { |
---|
163 | this->ATemporal = value; |
---|
164 | } |
---|
165 | |
---|
166 | void vtkLSCEReader::Accept3DOnly(bool value) |
---|
167 | { |
---|
168 | this->A3D = value; |
---|
169 | } |
---|
170 | |
---|
171 | void vtkLSCEReader::AcceptCellOnly(bool value) |
---|
172 | { |
---|
173 | this->ACell = value; |
---|
174 | } |
---|
175 | |
---|
176 | //---------------------------------------------------------------- |
---|
177 | |
---|
178 | int vtkLSCEReader::ProcessRequest |
---|
179 | (vtkInformation * request, |
---|
180 | vtkInformationVector ** vtkNotUsed(inputVector), |
---|
181 | vtkInformationVector * outputVector) |
---|
182 | { |
---|
183 | |
---|
184 | if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA())) |
---|
185 | { |
---|
186 | return (this->RequestData(NULL, NULL, outputVector)); |
---|
187 | } |
---|
188 | |
---|
189 | if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA_OBJECT())) |
---|
190 | { |
---|
191 | // return (this->RequestDataObject(NULL, NULL, outputVector)); |
---|
192 | } |
---|
193 | |
---|
194 | if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION())) |
---|
195 | { |
---|
196 | return (this->RequestInformation(NULL, NULL, outputVector)); |
---|
197 | } |
---|
198 | |
---|
199 | if(request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT())) |
---|
200 | { |
---|
201 | return (this->RequestUpdateExtent(NULL, NULL, outputVector)); |
---|
202 | } |
---|
203 | |
---|
204 | return (1); |
---|
205 | } |
---|
206 | |
---|
207 | //---------------------------------------------------------------- |
---|
208 | |
---|
209 | void vtkLSCEReader::ShowVariable(const vtkStdString & filename, |
---|
210 | const vtkStdString & varname) |
---|
211 | { |
---|
212 | vtkSmartPointer<vtkLSCEReader> lscereader = |
---|
213 | vtkSmartPointer<vtkLSCEReader>::New(); |
---|
214 | |
---|
215 | lscereader->SetFileName(filename); |
---|
216 | lscereader->AddVariableToSelection(varname); |
---|
217 | lscereader->Update(); |
---|
218 | |
---|
219 | // Création d'un mappeur et d'un acteur. |
---|
220 | vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New(); |
---|
221 | mapper->SetInputConnection(lscereader->GetOutput()->GetProducerPort()); |
---|
222 | mapper->SetScalarRange (1000, 10000); |
---|
223 | |
---|
224 | vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); |
---|
225 | actor->SetMapper(mapper); |
---|
226 | actor->GetProperty()->SetRepresentationToWireframe(); |
---|
227 | |
---|
228 | // Création d'une fenêtre de rendu. |
---|
229 | vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); |
---|
230 | vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); |
---|
231 | renderWindow->AddRenderer(renderer); |
---|
232 | vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = |
---|
233 | vtkSmartPointer<vtkRenderWindowInteractor>::New(); |
---|
234 | renderWindowInteractor->SetRenderWindow(renderWindow); |
---|
235 | |
---|
236 | |
---|
237 | vtkSmartPointer<vtkLegendScaleActor> legendScaleActor = |
---|
238 | vtkSmartPointer<vtkLegendScaleActor>::New(); |
---|
239 | |
---|
240 | // Ajout de l'acteur à la scÚne. |
---|
241 | renderer->AddActor(actor); |
---|
242 | renderer->AddActor(legendScaleActor); |
---|
243 | |
---|
244 | renderer->GradientBackgroundOn(); |
---|
245 | renderer->SetBackground(1,1,1); |
---|
246 | renderer->SetBackground2(0,0,0); |
---|
247 | |
---|
248 | // Rendu et intéraction |
---|
249 | renderWindow->Render(); |
---|
250 | renderWindowInteractor->Start(); |
---|
251 | } |
---|
252 | |
---|
253 | //---------------------------------------------------------------- |
---|
254 | |
---|
255 | void vtkLSCEReader::CreateRectilinearGrid(vtkRectilinearGrid * grid, |
---|
256 | vtkInformation * outInfo, |
---|
257 | vtkFloatArray * xspacing, |
---|
258 | vtkFloatArray * yspacing, |
---|
259 | vtkFloatArray * zspacing, |
---|
260 | vtkIntArray * dimensions) |
---|
261 | { |
---|
262 | int extent[6] = { 0, dimensions->GetValue(0) - 1 |
---|
263 | , 0, dimensions->GetValue(1) - 1 |
---|
264 | , 0, dimensions->GetValue(2) - 1}; |
---|
265 | outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),extent,6); |
---|
266 | grid->SetExtent (extent); |
---|
267 | grid->SetDimensions (dimensions->GetValue(0), |
---|
268 | dimensions->GetValue(1), |
---|
269 | dimensions->GetValue(2)); |
---|
270 | grid->SetXCoordinates (xspacing); |
---|
271 | grid->SetYCoordinates (yspacing); |
---|
272 | grid->SetZCoordinates (zspacing); |
---|
273 | } |
---|
274 | |
---|
275 | void vtkLSCEReader::CreateStructuredGrid(vtkStructuredGrid * grid, |
---|
276 | vtkInformation * outInfo, |
---|
277 | vtkPoints * points, |
---|
278 | vtkIntArray * dimensions) |
---|
279 | { |
---|
280 | int extent[6] = { 0, dimensions->GetValue(0) - 1 |
---|
281 | , 0, dimensions->GetValue(1) - 1 |
---|
282 | , 0, dimensions->GetValue(2) - 1}; |
---|
283 | outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),extent,6); |
---|
284 | grid->SetExtent (extent); |
---|
285 | grid->SetDimensions (dimensions->GetValue(0), |
---|
286 | dimensions->GetValue(1), |
---|
287 | dimensions->GetValue(2)); |
---|
288 | grid->SetPoints(points); |
---|
289 | } |
---|
290 | |
---|
291 | void vtkLSCEReader::CreateUnstructuredGrid(vtkUnstructuredGrid * grid, |
---|
292 | vtkInformation * outInfo, |
---|
293 | vtkPoints * points, |
---|
294 | vtkCellArray * cells, |
---|
295 | int celltype) |
---|
296 | { |
---|
297 | grid->SetPoints(points); |
---|
298 | grid->SetCells(celltype, cells); |
---|
299 | } |
---|
300 | |
---|
301 | //---------------------------------------------------------------- |
---|
302 | |
---|
303 | void vtkLSCEReader::GetRectilinearConnectivity(int dimZ, int dimY, int dimX, vtkCellArray * cells) |
---|
304 | { |
---|
305 | if (dimZ == 1 && dimY > 1 && dimX > 1) // 2D |
---|
306 | { |
---|
307 | vtkIdType pts[4] ; |
---|
308 | |
---|
309 | for (int i = 0, k = 0; i < (dimX - 1); i++) |
---|
310 | for (int j = 0; j < (dimY - 1); j++, k++) |
---|
311 | { |
---|
312 | pts[0] = i * dimY + j; |
---|
313 | pts[1] = i * dimY + j + 1; |
---|
314 | pts[2] = (i+1) * dimY + j + 1; |
---|
315 | pts[3] = (i+1) * dimY + j; |
---|
316 | cells->InsertNextCell(4, pts); |
---|
317 | } |
---|
318 | } |
---|
319 | else if (dimZ > 1 && dimY > 1 && dimX > 1) // 3D |
---|
320 | { |
---|
321 | vtkIdType pts[8]; |
---|
322 | for (int i = 0, l = 0; i < (dimX - 1); i++) |
---|
323 | for (int j = 0; j < (dimY - 1); j++) |
---|
324 | for (int k = 0; k < (dimZ - 1); k++, l++) |
---|
325 | { |
---|
326 | pts[0] = i * dimY * dimZ + j * dimZ + k; |
---|
327 | pts[1] = i * dimY * dimZ + j * dimZ + k + 1; |
---|
328 | pts[2] = (i+1) * dimY * dimZ + j * dimZ + k + 1; |
---|
329 | pts[3] = (i+1) * dimY * dimZ + j * dimZ + k; |
---|
330 | |
---|
331 | pts[4] = i * dimY * dimZ + (j + 1) * dimZ + k ; |
---|
332 | pts[5] = i * dimY * dimZ + (j + 1) * dimZ + k +1; |
---|
333 | pts[6] = (i+1) * dimY * dimZ + (j + 1) * dimZ + k + 1; |
---|
334 | pts[7] = (i+1) * dimY * dimZ + (j + 1) * dimZ + k ; |
---|
335 | cells->InsertNextCell(8, pts); |
---|
336 | } |
---|
337 | } |
---|
338 | } |
---|
339 | |
---|
340 | //---------------------------------------------------------------- |
---|
341 | |
---|
342 | void vtkLSCEReader::CreateSimpleGrid (int xi, int xf, |
---|
343 | int yi, int yf, |
---|
344 | int zi, int zf, |
---|
345 | vtkFloatArray * xspacing, |
---|
346 | vtkFloatArray * yspacing, |
---|
347 | vtkFloatArray * zspacing, |
---|
348 | vtkIntArray * dimensions) |
---|
349 | { |
---|
350 | dimensions->InsertNextValue (xf - xi + 1); // X |
---|
351 | dimensions->InsertNextValue (yf - yi + 1); // Y |
---|
352 | dimensions->InsertNextValue (zf - zi + 1); // Z |
---|
353 | for (int i = xi; i <= xf; i++) |
---|
354 | xspacing->InsertNextValue (i); |
---|
355 | for (int j = yi; j <= yf; j++) |
---|
356 | yspacing->InsertNextValue (j); |
---|
357 | for (int k = zi; k <= zf; k++) |
---|
358 | zspacing->InsertNextValue (k); |
---|
359 | } |
---|
360 | |
---|
361 | void vtkLSCEReader::CreateSimpleGrid (int xi, int xf, |
---|
362 | int yi, int yf, |
---|
363 | int zi, int zf, |
---|
364 | vtkPoints * points, |
---|
365 | vtkIntArray * dimensions) |
---|
366 | { |
---|
367 | dimensions->InsertNextValue (xf - xi + 1); // X |
---|
368 | dimensions->InsertNextValue (yf - yi + 1); // Y |
---|
369 | dimensions->InsertNextValue (zf - zi + 1); // Z |
---|
370 | for (int i = xi; i <= xf; i++) |
---|
371 | for (int j = yi; j <= yf; j++) |
---|
372 | for (int k = zi; k <= zf; k++) |
---|
373 | points->InsertNextPoint(i, j, k); |
---|
374 | } |
---|
375 | |
---|
376 | void vtkLSCEReader::CreateSimpleGrid (int xi, int xf, |
---|
377 | int yi, int yf, |
---|
378 | int zi, int zf, |
---|
379 | vtkPoints * points, |
---|
380 | vtkCellArray * cells, |
---|
381 | vtkIntArray * dimensions) |
---|
382 | { |
---|
383 | this->CreateSimpleGrid (xi, xf, yi, yf, zi, zf, points, dimensions); |
---|
384 | int dimX = dimensions->GetValue(0), |
---|
385 | dimY = dimensions->GetValue(1), |
---|
386 | dimZ = dimensions->GetValue(2); |
---|
387 | this->GetRectilinearConnectivity(dimZ, dimY, dimX, cells); |
---|
388 | } |
---|
389 | |
---|
390 | //---------------------------------------------------------------- |
---|
391 | void vtkLSCEReader::GetSpacings(const vtkStdString & coordinate, |
---|
392 | bool bounds, vtkFloatArray * spacing) |
---|
393 | { |
---|
394 | std::size_t size = (Reader->getDimensions(&coordinate).begin())->second; |
---|
395 | ARRAY_CREATE(data_arr, float, 1, [1]); |
---|
396 | if (Reader->hasVariable(coordinate)) |
---|
397 | { |
---|
398 | if (bounds) |
---|
399 | { |
---|
400 | if (Reader->hasBounds(coordinate)) |
---|
401 | { // CellData, variable de coordonnée avec attributes bounds. |
---|
402 | vtkStdString boundid = Reader->getBoundsId(coordinate); |
---|
403 | float f; |
---|
404 | Reader->readData(*data_arr, boundid); |
---|
405 | spacing->InsertNextValue (f = (*data_arr)[0]); |
---|
406 | for (std::size_t j = 1; j < (2 * size); j++) // << Super laid |
---|
407 | if (f != (*data_arr)[j]) |
---|
408 | spacing->InsertNextValue (f = (*data_arr)[j]); |
---|
409 | } |
---|
410 | else |
---|
411 | { // CellData, variable de coordonnée sans attributes bounds. |
---|
412 | Reader->readData(*data_arr, coordinate); |
---|
413 | spacing->InsertNextValue ((*data_arr)[0] - ((*data_arr)[1] - (*data_arr)[0])/2); |
---|
414 | for (std::size_t j = 0; j < (size-1); j++) |
---|
415 | spacing->InsertNextValue ((*data_arr)[j] + ((*data_arr)[j+1]-(*data_arr)[j])/2); |
---|
416 | spacing->InsertNextValue ((*data_arr)[size-2] + ((*data_arr)[size-1] - (*data_arr)[size-2])/2); |
---|
417 | } |
---|
418 | } |
---|
419 | else |
---|
420 | { // PointData, variable de coordonnée. |
---|
421 | Reader->readData(*data_arr, coordinate); |
---|
422 | for (std::size_t j = 0; j < (size-1); j++) |
---|
423 | spacing->InsertNextValue ((*data_arr)[j]); |
---|
424 | } |
---|
425 | } |
---|
426 | else |
---|
427 | { |
---|
428 | if (bounds) // CellData, dimension de coordonnée. |
---|
429 | for (float i = -0.5; i < ((float)size + 1.); i = i + 1.) |
---|
430 | spacing->InsertNextValue (i); |
---|
431 | else // PointData, dimension de coordonnée. |
---|
432 | for (float j = 0.; j < (float)size; j = j + 1.) |
---|
433 | spacing->InsertNextValue (j); |
---|
434 | } |
---|
435 | } |
---|
436 | //---------------------------------------------------------------- |
---|
437 | |
---|
438 | void vtkLSCEReader::AddPoint(vtkPoints * points, float * value, bool proj) |
---|
439 | { |
---|
440 | if (proj) |
---|
441 | { |
---|
442 | double h = 1.0; |
---|
443 | double cartesianCoord[3]; |
---|
444 | value[0] = 0.017453292519943295 * value[0]; |
---|
445 | value[1] = 0.017453292519943295 * value[1]; |
---|
446 | |
---|
447 | cartesianCoord[0] = h * cos(value[0]) * cos(value[1]); |
---|
448 | cartesianCoord[1] = h * sin(value[0]) * cos(value[1]); |
---|
449 | cartesianCoord[2] = h * sin(value[1]); |
---|
450 | points->InsertNextPoint (cartesianCoord); |
---|
451 | } |
---|
452 | else |
---|
453 | { |
---|
454 | points->InsertNextPoint (value); |
---|
455 | } |
---|
456 | } |
---|
457 | |
---|
458 | //---------------------------------------------------------------- |
---|
459 | void vtkLSCEReader::GetPoints(const vtkStdString & xcoordinate, |
---|
460 | const vtkStdString & ycoordinate, |
---|
461 | const vtkStdString & zcoordinate, |
---|
462 | bool bounds, bool proj, |
---|
463 | vtkPoints * points, vtkIntArray * dimensions) |
---|
464 | { |
---|
465 | float value[3]; |
---|
466 | bool is2D = true; |
---|
467 | ARRAY_CREATE(xvalue, float, 1, [1]); |
---|
468 | ARRAY_CREATE(yvalue, float, 1, [1]); |
---|
469 | vtkSmartPointer<vtkFloatArray> zspacing = vtkSmartPointer<vtkFloatArray>::New(); |
---|
470 | if (zcoordinate.size() > 0) |
---|
471 | { |
---|
472 | GetSpacings(zcoordinate, bounds, zspacing); |
---|
473 | is2D = false; |
---|
474 | } |
---|
475 | else |
---|
476 | zspacing->InsertNextValue(0); |
---|
477 | |
---|
478 | dimensions->InsertNextValue |
---|
479 | (Reader->getDimensions(&xcoordinate)[Reader->getLonCoordName(xcoordinate)]); |
---|
480 | dimensions->InsertNextValue |
---|
481 | (Reader->getDimensions(&xcoordinate)[Reader->getLatCoordName(xcoordinate)]); |
---|
482 | dimensions->InsertNextValue(zspacing->GetNumberOfTuples()); |
---|
483 | |
---|
484 | if (!bounds) |
---|
485 | { |
---|
486 | Reader->readData(*xvalue, xcoordinate); |
---|
487 | Reader->readData(*yvalue, ycoordinate); |
---|
488 | |
---|
489 | for (int i = 0; i < dimensions->GetValue(0); i++) |
---|
490 | for (int j = 0; j < dimensions->GetValue(1); j++) |
---|
491 | for (int k = 0; k < dimensions->GetValue(2); k++) |
---|
492 | { |
---|
493 | value[0] = (*xvalue)[i*dimensions->GetValue(1) + j]; |
---|
494 | value[1] = (*yvalue)[i*dimensions->GetValue(1) + j]; |
---|
495 | value[2] = zspacing->GetValue(k); |
---|
496 | AddPoint(points, value, proj); |
---|
497 | } |
---|
498 | return; |
---|
499 | } |
---|
500 | |
---|
501 | dimensions->SetValue(0, dimensions->GetValue(0)+1); |
---|
502 | dimensions->SetValue(1, dimensions->GetValue(1)+1); |
---|
503 | |
---|
504 | if (Reader->hasBounds(xcoordinate)) |
---|
505 | { |
---|
506 | vtkStdString boundid = Reader->getBoundsId(xcoordinate); |
---|
507 | Reader->readData(*xvalue, boundid); |
---|
508 | } |
---|
509 | if (Reader->hasBounds(ycoordinate)) |
---|
510 | { |
---|
511 | vtkStdString boundid = Reader->getBoundsId(ycoordinate); |
---|
512 | Reader->readData(*yvalue, boundid); |
---|
513 | } |
---|
514 | int ydim = dimensions->GetValue(0) - 1 , |
---|
515 | xdim = dimensions->GetValue(1) - 1; |
---|
516 | |
---|
517 | for (int i = 0; i <= xdim; i++) |
---|
518 | for (int j = 0; j <= ydim; j++) |
---|
519 | for (int k = 0; k < dimensions->GetValue(2); k++) |
---|
520 | { |
---|
521 | if ((j != ydim) && (i != xdim)) |
---|
522 | { |
---|
523 | value[0] = (*xvalue)[4 * (i * ydim + j) + 0]; |
---|
524 | value[1] = (*yvalue)[4 * (i * ydim + j) + 0]; |
---|
525 | value[2] = zspacing->GetValue(k); |
---|
526 | AddPoint(points, value, proj); |
---|
527 | |
---|
528 | continue; |
---|
529 | } |
---|
530 | else if ((j == ydim) && (i != xdim)) |
---|
531 | { |
---|
532 | value[0] = (*xvalue)[4 * (i * ydim + j - 1) + 1]; |
---|
533 | value[1] = (*yvalue)[4 * (i * ydim + j - 1) + 1]; |
---|
534 | value[2] = zspacing->GetValue(k); |
---|
535 | AddPoint(points, value, proj); |
---|
536 | |
---|
537 | continue; |
---|
538 | } |
---|
539 | else if ((j != ydim) && (i == xdim)) |
---|
540 | { |
---|
541 | value[0] = (*xvalue)[4 * ((i-1) * ydim + j) + 3]; |
---|
542 | value[1] = (*yvalue)[4 * ((i-1) * ydim + j) + 3]; |
---|
543 | value[2] = zspacing->GetValue(k); |
---|
544 | AddPoint(points, value, proj); |
---|
545 | |
---|
546 | continue; |
---|
547 | } |
---|
548 | else if ((j == ydim) && (i == xdim)) |
---|
549 | { |
---|
550 | value[0] = (*xvalue)[4 * ((i-1) * ydim + j - 1) + 2]; |
---|
551 | value[1] = (*yvalue)[4 * ((i-1) * ydim + j - 1) + 2]; |
---|
552 | value[2] = zspacing->GetValue(k); |
---|
553 | AddPoint(points, value, proj); |
---|
554 | |
---|
555 | continue; |
---|
556 | } |
---|
557 | } |
---|
558 | } |
---|
559 | |
---|
560 | //---------------------------------------------------------------- |
---|
561 | |
---|
562 | void vtkLSCEReader::GetCellsAndPoints(const vtkStdString & xcoordinate, |
---|
563 | const vtkStdString & ycoordinate, |
---|
564 | const vtkStdString & zcoordinate, |
---|
565 | bool bounds, bool proj, std::size_t nbvertex, |
---|
566 | vtkCellArray * cells, vtkPoints * points, |
---|
567 | vtkIntArray * dimensions) |
---|
568 | { |
---|
569 | float value[3]; |
---|
570 | double h = 1.0; |
---|
571 | double cartesianCoord[3]; |
---|
572 | vtkIdType pts[nbvertex] ; |
---|
573 | bool is2D = true; |
---|
574 | ARRAY_CREATE(xvalue, float, 1, [1]); |
---|
575 | ARRAY_CREATE(yvalue, float, 1, [1]); |
---|
576 | vtkSmartPointer<vtkFloatArray> zspacing = vtkSmartPointer<vtkFloatArray>::New(); |
---|
577 | if (zcoordinate.size() > 0) |
---|
578 | { |
---|
579 | GetSpacings(zcoordinate, bounds, zspacing); |
---|
580 | is2D = false; |
---|
581 | } |
---|
582 | else |
---|
583 | zspacing->InsertNextValue(0); |
---|
584 | |
---|
585 | std::size_t size = (*Reader->getDimensions(&xcoordinate).begin()).second; |
---|
586 | if (Reader->hasBounds(xcoordinate)) |
---|
587 | { |
---|
588 | vtkStdString boundid = Reader->getBoundsId(xcoordinate); |
---|
589 | Reader->readData(*xvalue, boundid); |
---|
590 | } |
---|
591 | if (Reader->hasBounds(ycoordinate)) |
---|
592 | { |
---|
593 | vtkStdString boundid = Reader->getBoundsId(ycoordinate); |
---|
594 | Reader->readData(*yvalue, boundid); |
---|
595 | } |
---|
596 | |
---|
597 | for (std::size_t u = 0; u < size; u++) |
---|
598 | { |
---|
599 | for (int v = 0; v < zspacing->GetNumberOfTuples(); v++) |
---|
600 | { |
---|
601 | for (std::size_t w = 0; w < nbvertex; w++) |
---|
602 | { |
---|
603 | value[0] = (*xvalue)[nbvertex * u + w]; |
---|
604 | value[1] = (*yvalue)[nbvertex * u + w]; |
---|
605 | value[2] = zspacing->GetValue(v); |
---|
606 | pts[w] = nbvertex * u + w; |
---|
607 | |
---|
608 | if (proj) |
---|
609 | { |
---|
610 | value[0] = 0.017453292519943295 * value[0]; |
---|
611 | value[1] = 0.017453292519943295 * value[1]; |
---|
612 | |
---|
613 | cartesianCoord[0] = h * cos(value[0]) * cos(value[1]); |
---|
614 | cartesianCoord[1] = h * sin(value[0]) * cos(value[1]); |
---|
615 | cartesianCoord[2] = h * sin(value[1]); |
---|
616 | points->InsertPoint (pts[w], cartesianCoord); |
---|
617 | } |
---|
618 | else |
---|
619 | { |
---|
620 | points->InsertPoint (pts[w], value); |
---|
621 | } |
---|
622 | } |
---|
623 | cells->InsertNextCell(nbvertex, pts); |
---|
624 | } |
---|
625 | } |
---|
626 | } |
---|
627 | |
---|
628 | //---------------------------------------------------------------- |
---|
629 | |
---|
630 | void vtkLSCEReader::AddScalarData(vtkDataSet * output, |
---|
631 | const vtkStdString & varname, |
---|
632 | std::size_t record, bool bounds) |
---|
633 | { |
---|
634 | vtkSmartPointer<vtkDoubleArray> data = vtkDoubleArray::New(); |
---|
635 | data->SetName(varname.c_str()); |
---|
636 | ARRAY_CREATE(data_arr, double, 1, [1]); |
---|
637 | Reader->readData(*data_arr, varname); |
---|
638 | Reader->replaceMissingValue(varname, *data_arr, vtkMath::Nan()); |
---|
639 | |
---|
640 | |
---|
641 | data->SetNumberOfValues (data_arr->size()); |
---|
642 | for (std::size_t i = 0; i < data_arr->size(); i++) |
---|
643 | data->SetValue (i, (*data_arr)[i]); |
---|
644 | |
---|
645 | if (bounds) |
---|
646 | { |
---|
647 | output->GetCellData()->AddArray(data); |
---|
648 | output->GetCellData()->SetActiveScalars (varname.c_str()); |
---|
649 | } |
---|
650 | else |
---|
651 | { |
---|
652 | output->GetPointData()->AddArray(data); |
---|
653 | output->GetPointData()->SetActiveScalars (varname.c_str()); |
---|
654 | } |
---|
655 | } |
---|
656 | |
---|
657 | //---------------------------------------------------------------- |
---|
658 | |
---|
659 | int vtkLSCEReader::RequestData |
---|
660 | (vtkInformation * vtkNotUsed(request), |
---|
661 | vtkInformationVector ** vtkNotUsed(inputVector), |
---|
662 | vtkInformationVector * outputVector) |
---|
663 | { |
---|
664 | vtkInformation * outInfo = outputVector->GetInformationObject(0); |
---|
665 | vtkDataSet * output = vtkDataSet::GetData(outInfo); |
---|
666 | |
---|
667 | std::cout << this->CurGridType << std::endl; |
---|
668 | |
---|
669 | if (!output) |
---|
670 | { |
---|
671 | switch (this->CurGridType) |
---|
672 | { |
---|
673 | case(RECTILINEAR) : |
---|
674 | output = vtkRectilinearGrid::New(); |
---|
675 | break; |
---|
676 | case(CURVILINEAR) : |
---|
677 | output = vtkStructuredGrid::New(); |
---|
678 | break; |
---|
679 | default : |
---|
680 | output = vtkUnstructuredGrid::New(); |
---|
681 | break; |
---|
682 | } |
---|
683 | output->SetPipelineInformation(outInfo); |
---|
684 | output->Delete(); |
---|
685 | } |
---|
686 | |
---|
687 | vtkUnstructuredGrid * uoutput = vtkUnstructuredGrid::SafeDownCast(output); |
---|
688 | vtkRectilinearGrid * routput = vtkRectilinearGrid::SafeDownCast(output); |
---|
689 | vtkStructuredGrid * soutput = vtkStructuredGrid::SafeDownCast(output); |
---|
690 | |
---|
691 | if (routput) |
---|
692 | { // Grille rectiliniéaire |
---|
693 | vtkSmartPointer<vtkFloatArray> |
---|
694 | xspacing = vtkSmartPointer<vtkFloatArray>::New(), |
---|
695 | yspacing = vtkSmartPointer<vtkFloatArray>::New(), |
---|
696 | zspacing = vtkSmartPointer<vtkFloatArray>::New(); |
---|
697 | vtkSmartPointer<vtkIntArray> dims = vtkSmartPointer<vtkIntArray>::New(); |
---|
698 | |
---|
699 | //CreateSimpleGrid (-1, 10, -1, 10, -1, 10, xspacing, yspacing, zspacing, dims); |
---|
700 | GetSpacings(Reader->getLonCoordName(*VarNames.begin()), true, xspacing); |
---|
701 | GetSpacings(Reader->getLatCoordName(*VarNames.begin()), true, yspacing); |
---|
702 | GetSpacings(Reader->getVertCoordName(*VarNames.begin()), true, zspacing); |
---|
703 | /*std::cout << zspacing->GetNumberOfTuples() << std::endl;*/ |
---|
704 | |
---|
705 | dims->InsertNextValue(xspacing->GetNumberOfTuples()); |
---|
706 | dims->InsertNextValue(yspacing->GetNumberOfTuples()); |
---|
707 | dims->InsertNextValue(zspacing->GetNumberOfTuples()); |
---|
708 | |
---|
709 | AddScalarData(routput, *VarNames.begin(), 0, true); |
---|
710 | CreateRectilinearGrid(routput, outInfo, xspacing, yspacing, zspacing, dims); |
---|
711 | } |
---|
712 | |
---|
713 | if (soutput) |
---|
714 | { // Grille structurée |
---|
715 | |
---|
716 | vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New(); |
---|
717 | vtkSmartPointer<vtkIntArray> dims = vtkSmartPointer<vtkIntArray>::New(); |
---|
718 | |
---|
719 | //CreateSimpleGrid (-1, 10, -1, 10, -1, 10, pts, dims); |
---|
720 | GetPoints(Reader->getLonCoordName(*VarNames.begin()), |
---|
721 | Reader->getLatCoordName(*VarNames.begin()), |
---|
722 | Reader->getVertCoordName(*VarNames.begin()), false, true, pts, dims); |
---|
723 | |
---|
724 | AddScalarData(soutput, *VarNames.begin(), 0, false); |
---|
725 | CreateStructuredGrid(soutput, outInfo, pts, dims); |
---|
726 | } |
---|
727 | |
---|
728 | if (uoutput) |
---|
729 | { // Grille non-structurée |
---|
730 | |
---|
731 | vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New(); |
---|
732 | vtkSmartPointer<vtkIntArray> dims = vtkSmartPointer<vtkIntArray>::New(); |
---|
733 | vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New(); |
---|
734 | // VTK_QUAD, VTK_HEXAHEDRON, VTK_POLYGON |
---|
735 | //CreateSimpleGrid (0, 12, 0, 12, 0, 12, pts, cells, dims); |
---|
736 | //std::cout << Reader->getVertCoordName(*VarNames.begin()) << std::endl; |
---|
737 | GetCellsAndPoints(Reader->getLonCoordName(*VarNames.begin()), |
---|
738 | Reader->getLatCoordName(*VarNames.begin()), |
---|
739 | Reader->getVertCoordName(*VarNames.begin()), true, true, |
---|
740 | Reader->getNbVertex(*VarNames.begin()), cells, pts, dims); |
---|
741 | |
---|
742 | AddScalarData(uoutput, *VarNames.begin(), 0, true); |
---|
743 | CreateUnstructuredGrid(uoutput, outInfo, pts, cells, VTK_POLYGON); |
---|
744 | |
---|
745 | |
---|
746 | } |
---|
747 | return (1); |
---|
748 | } |
---|
749 | |
---|
750 | int vtkLSCEReader::RequestInformation |
---|
751 | (vtkInformation * vtkNotUsed(request), |
---|
752 | vtkInformationVector ** vtkNotUsed(inputVector), |
---|
753 | vtkInformationVector * outputVector) |
---|
754 | { |
---|
755 | vtkInformation * outInfo = outputVector->GetInformationObject(0); |
---|
756 | vtkDataSet * output = vtkDataSet::GetData(outInfo); |
---|
757 | |
---|
758 | if (true) |
---|
759 | { |
---|
760 | switch (this->CurGridType) |
---|
761 | { |
---|
762 | case(RECTILINEAR) : |
---|
763 | output = vtkRectilinearGrid::New(); |
---|
764 | break; |
---|
765 | case(CURVILINEAR) : |
---|
766 | output = vtkStructuredGrid::New(); |
---|
767 | break; |
---|
768 | default : |
---|
769 | output = vtkUnstructuredGrid::New(); |
---|
770 | break; |
---|
771 | } |
---|
772 | output->SetPipelineInformation(outInfo); |
---|
773 | output->Delete(); |
---|
774 | } |
---|
775 | return (1); |
---|
776 | } |
---|
777 | |
---|
778 | ///--------------------------------------------------------------- |
---|
779 | |
---|
780 | #ifndef LSCE_EXPORTS |
---|
781 | } // namespace vtk |
---|
782 | } // namespace xmlioserver |
---|
783 | #endif //LSCE_EXPORTS |
---|