19 #if defined(__APPLE__) && defined(__clang__)
21 #define VTK_LEGACY_SILENT
24 #pragma clang diagnostic push
25 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
27 #include <vtkVersion.h>
29 #include <vtkSmartPointer.h>
30 #include <vtkPointData.h>
31 #include <vtkCellData.h>
32 #include <vtkCellArray.h>
33 #include <vtkPolyData.h>
34 #include <vtkUnstructuredGrid.h>
36 #include <vtkPolyDataReader.h>
37 #include <vtkXMLPolyDataReader.h>
38 #include <vtkUnstructuredGridReader.h>
39 #include <vtkXMLUnstructuredGridReader.h>
40 #include <vtkDataSetSurfaceFilter.h>
41 #if defined(__APPLE__) && defined(__clang__)
42 #pragma clang diagnostic pop
46 #define IO_TOOLS_EXPORT //"DataStructures/IO_Tools/IO_Tools_export.h"
48 #define IO_TOOLS_EXPORT
54 using namespace StrUtils;
55 using namespace FileUtils;
60 std::ifstream myfile(file_path);
66 getline(myfile, line);
67 if(line.find(
"DATASET") != std::string::npos)
77 throw std::runtime_error(
78 "Reader::getLineContainingDATASET -> unable to open file");
83 template<
typename CoordType,
89 const vtkSmartPointer< vtkPolyData > &poly_data,
90 std::vector< std::vector< CoordType > > &points_coords,
91 std::vector< std::vector< CoordNType > >
93 std::vector< std::vector< CoordCType > > &vertex_color_coords,
94 std::vector< std::vector< IndexType > >
96 std::vector< std::vector< CoordCType > > &lines_color_coords,
97 std::vector< std::vector< IndexType > >
99 std::vector< std::vector< CoordCType > > &face_color_coords,
100 std::vector< std::vector< std::vector< double > > >
103 std::vector< std::string > &field_names)
107 points_coords.clear();
108 normals_coords.clear();
109 vertex_color_coords.clear();
110 line_indices.clear();
111 lines_color_coords.clear();
112 face_indices.clear();
113 face_color_coords.clear();
114 field_attributes.clear();
120 if(poly_data->GetNumberOfStrips() > 0)
122 std::cerr <<
"Reader::read_vtkPolyData -> Warning: triangle strips not "
123 "taken into account yet.\n";
127 assert((poly_data->GetPointData()->GetNormals() == NULL) ||
128 (poly_data->GetNumberOfPoints() >=
129 poly_data->GetPointData()->GetNormals()->GetNumberOfTuples()));
132 if(poly_data->GetNumberOfPoints() > 0)
134 points_coords.reserve(
static_cast< size_t >(
135 poly_data->GetNumberOfPoints()));
137 vtkSmartPointer< vtkPoints > ptr_points = poly_data->GetPoints();
138 vtkSmartPointer< vtkDataArray > ptr_normals =
139 poly_data->GetPointData()->GetNormals();
141 (ptr_normals != NULL &&
142 ptr_points->GetNumberOfPoints() ==
143 ptr_normals->GetNumberOfTuples());
147 normals_coords.reserve(
static_cast< size_t >(
148 poly_data->GetPointData()
150 ->GetNumberOfTuples()));
152 for(vtkIdType
id = 0;
id < ptr_points->GetNumberOfPoints();
id++)
154 std::vector< double > vd(ptr_points->GetPoint(
id),
155 ptr_points->GetPoint(
id) +
158 std::vector< CoordType > final_vc;
159 final_vc.reserve(vd.size());
160 std::vector< double >::iterator it(vd.begin()), ite(vd.end());
161 for(; it != ite; ++it)
162 final_vc.push_back(
static_cast< CoordType
>(*it));
164 points_coords.push_back(final_vc);
168 std::vector< double > vdn(ptr_normals->GetTuple(
id),
169 ptr_normals->GetTuple(
id) +
170 ptr_normals->GetNumberOfComponents());
171 std::vector< CoordNType > final_vcn;
172 final_vcn.reserve(vdn.size());
175 for(; it != ite; ++it)
176 final_vcn.push_back(
static_cast< CoordNType
>(*it));
178 normals_coords.push_back(final_vcn);
184 if(poly_data->GetNumberOfPolys() > 0)
186 face_indices.reserve(
static_cast< size_t >(
187 poly_data->GetNumberOfPolys()));
189 vtkSmartPointer< vtkCellArray > ptr_cell_polygons = poly_data->GetPolys();
191 #if (VTK_MAJOR_VERSION >= 9) // not tested with VTK 8...
192 const vtkIdType *pts_poly =
new vtkIdType[ptr_cell_polygons->GetMaxCellSize()];
194 vtkIdType *pts_poly =
new vtkIdType[ptr_cell_polygons->GetMaxCellSize()];
197 ptr_cell_polygons->InitTraversal();
198 while(ptr_cell_polygons->GetNextCell(
201 std::vector< IndexType > facet_indices(npts);
202 for(vtkIdType i = 0; i < npts; i++)
203 facet_indices[i] =
static_cast< IndexType
>(pts_poly[i]);
205 face_indices.push_back(facet_indices);
212 if(poly_data->GetNumberOfLines() > 0)
214 line_indices.reserve(
static_cast< size_t >(
215 poly_data->GetNumberOfLines()));
217 vtkSmartPointer< vtkCellArray > ptr_cell_lines = poly_data->GetLines();
219 #if (VTK_MAJOR_VERSION >= 9) // not tested with VTK 8...
220 const vtkIdType *pts_line =
new vtkIdType[ptr_cell_lines->GetMaxCellSize()];
222 vtkIdType *pts_line =
new vtkIdType[ptr_cell_lines->GetMaxCellSize()];
225 ptr_cell_lines->InitTraversal();
226 while(ptr_cell_lines->GetNextCell(
229 std::vector< IndexType > line_indices_tmp(npts);
230 for(vtkIdType i = 0; i < npts; i++)
231 line_indices_tmp[i] =
static_cast< IndexType
>(pts_line[i]);
233 line_indices.push_back(line_indices_tmp);
240 vtkFieldData *fd = poly_data->GetFieldData();
243 field_attributes.resize(
static_cast< size_t >(
244 fd->GetNumberOfArrays()));
246 field_names.resize(
static_cast< size_t >(fd->GetNumberOfArrays()));
248 for(
int id_array = 0; id_array < fd->GetNumberOfArrays(); id_array++)
250 field_names[id_array] = fd->GetArrayName(id_array);
252 vtkSmartPointer< vtkDataArray > ptr_data = fd->GetArray(
255 field_attributes[id_array].resize(
256 static_cast< size_t >(ptr_data->GetNumberOfTuples()));
259 for(vtkIdType id_tuple_in_array = 0;
260 id_tuple_in_array < ptr_data->GetNumberOfTuples();
264 field_attributes[id_array][id_tuple_in_array].resize(
265 static_cast< size_t >(ptr_data->GetNumberOfComponents()));
266 std::copy(ptr_data->GetTuple(id_tuple_in_array),
267 ptr_data->GetTuple(id_tuple_in_array) +
268 ptr_data->GetNumberOfComponents(),
270 field_attributes[id_array][id_tuple_in_array].begin());
276 vtkPointData *pd = poly_data->GetPointData();
279 size_t old_nb_e = field_attributes.size();
280 field_attributes.resize(
static_cast< size_t >(
281 old_nb_e + pd->GetNumberOfArrays()));
284 static_cast< size_t >(old_nb_e + pd->GetNumberOfArrays()));
285 for(
int id_array = 0; id_array < pd->GetNumberOfArrays(); id_array++)
287 field_names[id_array + old_nb_e] =
288 std::string(
"POINT_DATA_") + pd->GetArrayName(id_array);
292 vtkSmartPointer< vtkDataArray > ptr_data = pd->GetArray(id_array);
294 field_attributes[id_array + old_nb_e].resize(
295 static_cast< size_t >(ptr_data->GetNumberOfTuples()));
298 for(vtkIdType id_tuple_in_array = 0;
299 id_tuple_in_array < ptr_data->GetNumberOfTuples();
303 field_attributes[id_array + old_nb_e][id_tuple_in_array].resize(
304 static_cast< size_t >(ptr_data->GetNumberOfComponents()));
306 ptr_data->GetTuple(id_tuple_in_array),
307 ptr_data->GetTuple(id_tuple_in_array) +
308 ptr_data->GetNumberOfComponents(),
310 field_attributes[id_array + old_nb_e][id_tuple_in_array].begin());
316 vtkCellData *cd = poly_data->GetCellData();
321 size_t old_nb_e = field_attributes.size();
322 field_attributes.resize(
static_cast< size_t >(
323 old_nb_e + cd->GetNumberOfArrays()));
326 static_cast< size_t >(old_nb_e + cd->GetNumberOfArrays()));
327 for(
int id_array = 0; id_array < cd->GetNumberOfArrays(); id_array++)
329 field_names[old_nb_e + id_array] =
330 std::string(
"CELL_DATA_") + cd->GetArrayName(id_array);
334 vtkSmartPointer< vtkDataArray > ptr_data = cd->GetArray(id_array);
336 field_attributes[old_nb_e + id_array].resize(
337 static_cast< size_t >(ptr_data->GetNumberOfTuples()));
340 for(vtkIdType id_tuple_in_array = 0;
341 id_tuple_in_array < ptr_data->GetNumberOfTuples();
345 field_attributes[old_nb_e + id_array][id_tuple_in_array].resize(
346 static_cast< size_t >(ptr_data->GetNumberOfComponents()));
348 ptr_data->GetTuple(id_tuple_in_array),
349 ptr_data->GetTuple(id_tuple_in_array) +
350 ptr_data->GetNumberOfComponents(),
352 field_attributes[old_nb_e + id_array][id_tuple_in_array].begin());
356 if((line_indices.size() > 0) &&
357 (line_indices[0].size() >
359 (face_indices.size() == 0)
363 std::swap(line_indices, face_indices);
366 if(field_names.size() == field_attributes.size())
368 size_t cpt = 0, nb_e_glob = field_names.size();
369 for(; cpt < nb_e_glob; ++cpt)
371 if(field_names[cpt].find(
"colo") != std::string::npos)
373 if((vertex_color_coords.size() == 0) &&
374 ((field_names[cpt].find(
"vertex") != std::string::npos) ||
375 (field_names[cpt].find(
"point") != std::string::npos)))
377 size_t nb_e = points_coords.size();
378 vertex_color_coords.resize(nb_e);
379 for(
size_t i = 0; i < nb_e; ++i)
381 size_t nb_c = field_attributes[cpt][i].size();
382 vertex_color_coords[i].resize(nb_c);
383 for(
size_t j = 0; j < nb_c; ++j)
384 vertex_color_coords[i][j] =
385 static_cast< CoordCType
>(field_attributes[cpt][i][j]);
393 else if((face_color_coords.size() == 0) &&
394 ((field_names[cpt].find(
"face") != std::string::npos) ||
395 (field_names[cpt].find(
"polygon") != std::string::npos) ||
396 (line_indices.size() == 0)))
398 size_t nb_e = face_indices.size();
399 face_color_coords.resize(nb_e);
400 for(
size_t i = 0; i < nb_e; ++i)
402 size_t nb_c = field_attributes[cpt][i].size();
403 face_color_coords[i].resize(nb_c);
404 for(
size_t j = 0; j < nb_c; ++j)
405 face_color_coords[i][j] =
406 static_cast< CoordCType
>(field_attributes[cpt][i][j]);
414 else if((lines_color_coords.size() == 0) && (line_indices.size() > 0))
416 size_t nb_e = line_indices.size();
417 lines_color_coords.resize(nb_e);
418 for(
size_t i = 0; i < nb_e; ++i)
420 size_t nb_c = field_attributes[cpt][i].size();
421 lines_color_coords[i].resize(nb_c);
422 for(
size_t j = 0; j < nb_c; ++j)
423 lines_color_coords[i][j] =
424 static_cast< CoordCType
>(field_attributes[cpt][i][j]);
432 field_attributes[cpt].clear();
434 size_t last_index = nb_e_glob - 1;
437 std::swap(field_attributes[cpt], field_attributes[last_index]);
438 std::swap(field_names[cpt], field_names[last_index]);
440 field_attributes.resize(last_index);
441 field_names.resize(last_index);
445 else if(field_names[cpt].find(
"norm") != std::string::npos)
447 field_attributes[cpt].clear();
449 size_t last_index = nb_e_glob - 1;
452 std::swap(field_attributes[cpt], field_attributes[last_index]);
453 std::swap(field_names[cpt], field_names[last_index]);
455 field_attributes.resize(last_index);
456 field_names.resize(last_index);
464 template<
typename CoordType,
470 const vtkSmartPointer< vtkUnstructuredGrid > &unstructured_grid,
471 std::vector< std::vector< CoordType > > &points_coords,
472 std::vector< std::vector< CoordNType > >
474 std::vector< std::vector< CoordCType > > &vertex_color_coords,
476 std::vector< std::vector< IndexType > >
478 std::vector< std::vector< CoordCType > > &lines_color_coords,
479 std::vector< std::vector< IndexType > >
481 std::vector< std::vector< CoordCType > > &face_color_coords,
482 std::vector< std::vector< std::vector< double > > >
485 std::vector< std::string > &field_names)
489 points_coords.clear();
490 normals_coords.clear();
491 vertex_color_coords.clear();
492 line_indices.clear();
493 lines_color_coords.clear();
494 face_indices.clear();
495 face_color_coords.clear();
496 field_attributes.clear();
501 (unstructured_grid->GetPointData()->GetNormals() == NULL) ||
502 (unstructured_grid->GetNumberOfPoints() >=
503 unstructured_grid->GetPointData()->GetNormals()->GetNumberOfTuples()));
506 if(unstructured_grid->GetNumberOfPoints() > 0)
508 points_coords.reserve(
static_cast< size_t >(
510 ->GetNumberOfPoints()));
512 vtkSmartPointer< vtkPoints > ptr_points = unstructured_grid->GetPoints();
513 vtkSmartPointer< vtkDataArray > ptr_normals =
514 unstructured_grid->GetPointData()->GetNormals();
516 (ptr_normals != NULL &&
517 ptr_points->GetNumberOfPoints() ==
518 ptr_normals->GetNumberOfTuples());
522 normals_coords.reserve(
static_cast< size_t >(
523 unstructured_grid->GetPointData()
525 ->GetNumberOfTuples()));
527 for(vtkIdType
id = 0;
id < ptr_points->GetNumberOfPoints();
id++)
529 std::vector< double > vd(ptr_points->GetPoint(
id),
530 ptr_points->GetPoint(
id) +
533 std::vector< CoordType > final_vc;
534 final_vc.reserve(vd.size());
535 std::vector< double >::iterator it(vd.begin()), ite(vd.end());
536 for(; it != ite; ++it)
537 final_vc.push_back(
static_cast< CoordType
>(*it));
539 points_coords.push_back(final_vc);
543 std::vector< double > vdn(ptr_normals->GetTuple(
id),
544 ptr_normals->GetTuple(
id) +
545 ptr_normals->GetNumberOfComponents());
546 std::vector< CoordNType > final_vcn;
547 final_vcn.reserve(vdn.size());
550 for(; it != ite; ++it)
551 final_vcn.push_back(
static_cast< CoordNType
>(*it));
553 normals_coords.push_back(final_vcn);
559 if(unstructured_grid->GetNumberOfCells() > 0)
561 face_indices.reserve(
static_cast< size_t >(
562 unstructured_grid->GetNumberOfCells()));
563 line_indices.reserve(
564 static_cast< size_t >(unstructured_grid->GetNumberOfCells()));
566 size_t nb_face_cell = 0, nb_vol_cell = 0;
568 vtkSmartPointer< vtkCellArray > ptr_cell_polygons =
569 unstructured_grid->GetCells();
571 #if (VTK_MAJOR_VERSION >= 9) // not tested with VTK 8...
572 const vtkIdType *pts_poly =
new vtkIdType[ptr_cell_polygons->GetMaxCellSize()];
574 vtkIdType *pts_poly =
new vtkIdType[ptr_cell_polygons->GetMaxCellSize()];
577 ptr_cell_polygons->InitTraversal();
578 vtkIdType cell_id = 0;
579 while(ptr_cell_polygons->GetNextCell(
582 std::vector< IndexType > facet_indices(npts);
583 for(vtkIdType i = 0; i < npts; i++)
585 facet_indices[i] =
static_cast< IndexType
>(pts_poly[i]);
589 switch(unstructured_grid->GetCellType(cell_id))
592 throw std::runtime_error(
"Reader::read_vtkUnstructuredGrid -> vertex "
593 "cells are not managed.");
597 throw std::runtime_error(
598 "Reader::read_vtkUnstructuredGrid -> edge cells are not managed.");
601 face_indices.push_back(facet_indices);
605 face_indices.push_back(facet_indices);
609 face_indices.push_back(facet_indices);
614 line_indices.push_back(facet_indices);
616 std::vector< IndexType > face1, face2, face3, face4;
617 face1.push_back(facet_indices[0]);
618 face1.push_back(facet_indices[1]);
619 face1.push_back(facet_indices[3]);
620 face_indices.push_back(face1);
623 face2.push_back(facet_indices[1]);
624 face2.push_back(facet_indices[2]);
625 face2.push_back(facet_indices[3]);
626 face_indices.push_back(face2);
629 face3.push_back(facet_indices[3]);
630 face3.push_back(facet_indices[2]);
631 face3.push_back(facet_indices[0]);
632 face_indices.push_back(face3);
635 face4.push_back(facet_indices[2]);
636 face4.push_back(facet_indices[1]);
637 face4.push_back(facet_indices[0]);
638 face_indices.push_back(face4);
644 line_indices.push_back(facet_indices);
646 std::vector< IndexType > face1, face2, face3, face4, face5, face6;
647 face1.push_back(facet_indices[0]);
648 face1.push_back(facet_indices[1]);
649 face1.push_back(facet_indices[5]);
650 face1.push_back(facet_indices[4]);
651 face_indices.push_back(face1);
654 face2.push_back(facet_indices[1]);
655 face2.push_back(facet_indices[2]);
656 face2.push_back(facet_indices[6]);
657 face2.push_back(facet_indices[5]);
658 face_indices.push_back(face2);
661 face3.push_back(facet_indices[2]);
662 face3.push_back(facet_indices[3]);
663 face3.push_back(facet_indices[7]);
664 face3.push_back(facet_indices[6]);
665 face_indices.push_back(face3);
668 face4.push_back(facet_indices[3]);
669 face4.push_back(facet_indices[0]);
670 face4.push_back(facet_indices[4]);
671 face4.push_back(facet_indices[7]);
672 face_indices.push_back(face4);
675 face5.push_back(facet_indices[4]);
676 face5.push_back(facet_indices[5]);
677 face5.push_back(facet_indices[6]);
678 face5.push_back(facet_indices[7]);
679 face_indices.push_back(face5);
682 face6.push_back(facet_indices[3]);
683 face6.push_back(facet_indices[2]);
684 face6.push_back(facet_indices[1]);
685 face6.push_back(facet_indices[0]);
686 face_indices.push_back(face6);
696 throw std::runtime_error(
697 "Reader::read_vtkUnstructuredGrid -> cell type is not known.");
702 face_indices.resize(nb_face_cell);
703 line_indices.resize(nb_vol_cell);
709 vtkFieldData *fd = unstructured_grid->GetFieldData();
712 field_attributes.resize(
static_cast< size_t >(
713 fd->GetNumberOfArrays()));
715 field_names.resize(
static_cast< size_t >(fd->GetNumberOfArrays()));
717 for(
int id_array = 0; id_array < fd->GetNumberOfArrays(); id_array++)
719 field_names[id_array] = fd->GetArrayName(id_array);
721 vtkSmartPointer< vtkDataArray > ptr_data = fd->GetArray(
724 field_attributes[id_array].resize(
725 static_cast< size_t >(ptr_data->GetNumberOfTuples()));
728 for(vtkIdType id_tuple_in_array = 0;
729 id_tuple_in_array < ptr_data->GetNumberOfTuples();
733 field_attributes[id_array][id_tuple_in_array].resize(
734 static_cast< size_t >(ptr_data->GetNumberOfComponents()));
735 std::copy(ptr_data->GetTuple(id_tuple_in_array),
736 ptr_data->GetTuple(id_tuple_in_array) +
737 ptr_data->GetNumberOfComponents(),
739 field_attributes[id_array][id_tuple_in_array].begin());
745 vtkPointData *pd = unstructured_grid->GetPointData();
748 size_t old_nb_e = field_attributes.size();
749 field_attributes.resize(
static_cast< size_t >(
750 old_nb_e + pd->GetNumberOfArrays()));
753 static_cast< size_t >(old_nb_e + pd->GetNumberOfArrays()));
754 for(
int id_array = 0; id_array < pd->GetNumberOfArrays(); id_array++)
756 field_names[id_array + old_nb_e] =
757 std::string(
"POINT_DATA_") + pd->GetArrayName(id_array);
761 vtkSmartPointer< vtkDataArray > ptr_data = pd->GetArray(id_array);
763 field_attributes[id_array + old_nb_e].resize(
764 static_cast< size_t >(ptr_data->GetNumberOfTuples()));
767 for(vtkIdType id_tuple_in_array = 0;
768 id_tuple_in_array < ptr_data->GetNumberOfTuples();
772 field_attributes[id_array + old_nb_e][id_tuple_in_array].resize(
773 static_cast< size_t >(ptr_data->GetNumberOfComponents()));
775 ptr_data->GetTuple(id_tuple_in_array),
776 ptr_data->GetTuple(id_tuple_in_array) +
777 ptr_data->GetNumberOfComponents(),
779 field_attributes[id_array + old_nb_e][id_tuple_in_array].begin());
785 vtkCellData *cd = unstructured_grid->GetCellData();
790 size_t old_nb_e = field_attributes.size();
791 field_attributes.resize(
static_cast< size_t >(
792 old_nb_e + cd->GetNumberOfArrays()));
795 static_cast< size_t >(old_nb_e + cd->GetNumberOfArrays()));
796 for(
int id_array = 0; id_array < cd->GetNumberOfArrays(); id_array++)
798 field_names[old_nb_e + id_array] =
799 std::string(
"CELL_DATA_") + cd->GetArrayName(id_array);
803 vtkSmartPointer< vtkDataArray > ptr_data = cd->GetArray(id_array);
805 field_attributes[old_nb_e + id_array].resize(
806 static_cast< size_t >(ptr_data->GetNumberOfTuples()));
809 for(vtkIdType id_tuple_in_array = 0;
810 id_tuple_in_array < ptr_data->GetNumberOfTuples();
814 field_attributes[old_nb_e + id_array][id_tuple_in_array].resize(
815 static_cast< size_t >(ptr_data->GetNumberOfComponents()));
817 ptr_data->GetTuple(id_tuple_in_array),
818 ptr_data->GetTuple(id_tuple_in_array) +
819 ptr_data->GetNumberOfComponents(),
821 field_attributes[old_nb_e + id_array][id_tuple_in_array].begin());
826 if(field_names.size() == field_attributes.size())
828 size_t cpt = 0, nb_e_glob = field_names.size();
829 for(; cpt < nb_e_glob; ++cpt)
831 if(field_names[cpt].find(
"colo") != std::string::npos)
833 if((vertex_color_coords.size() == 0) &&
834 ((field_names[cpt].find(
"vertex") != std::string::npos) ||
835 (field_names[cpt].find(
"point") != std::string::npos)))
837 size_t nb_e = points_coords.size();
838 vertex_color_coords.resize(nb_e);
839 for(
size_t i = 0; i < nb_e; ++i)
841 size_t nb_c = field_attributes[cpt][i].size();
842 vertex_color_coords[i].resize(nb_c);
843 for(
size_t j = 0; j < nb_c; ++j)
844 vertex_color_coords[i][j] =
845 static_cast< CoordCType
>(field_attributes[cpt][i][j]);
853 else if((face_color_coords.size() == 0) &&
854 ((field_names[cpt].find(
"face") != std::string::npos) ||
855 (field_names[cpt].find(
"polygon") != std::string::npos) ||
856 (line_indices.size() == 0)))
858 size_t nb_e = face_indices.size();
859 face_color_coords.resize(nb_e);
860 for(
size_t i = 0; i < nb_e; ++i)
862 size_t nb_c = field_attributes[cpt][i].size();
863 face_color_coords[i].resize(nb_c);
864 for(
size_t j = 0; j < nb_c; ++j)
865 face_color_coords[i][j] =
866 static_cast< CoordCType
>(field_attributes[cpt][i][j]);
874 else if((lines_color_coords.size() == 0) && (line_indices.size() > 0))
876 size_t nb_e = line_indices.size();
877 lines_color_coords.resize(nb_e);
878 for(
size_t i = 0; i < nb_e; ++i)
880 size_t nb_c = field_attributes[cpt][i].size();
881 lines_color_coords[i].resize(nb_c);
882 for(
size_t j = 0; j < nb_c; ++j)
883 lines_color_coords[i][j] =
884 static_cast< CoordCType
>(field_attributes[cpt][i][j]);
892 field_attributes[cpt].clear();
894 size_t last_index = nb_e_glob - 1;
897 std::swap(field_attributes[cpt], field_attributes[last_index]);
898 std::swap(field_names[cpt], field_names[last_index]);
900 field_attributes.resize(last_index);
901 field_names.resize(last_index);
905 else if(field_names[cpt].find(
"norm") != std::string::npos)
907 field_attributes[cpt].clear();
909 size_t last_index = nb_e_glob - 1;
912 std::swap(field_attributes[cpt], field_attributes[last_index]);
913 std::swap(field_names[cpt], field_names[last_index]);
915 field_attributes.resize(last_index);
916 field_names.resize(last_index);
924 template<
typename CoordType,
930 std::string file_path,
931 std::vector< std::vector< CoordType > > &points_coords,
932 std::vector< std::vector< CoordNType > >
934 std::vector< std::vector< CoordCType > > &vertex_color_coords,
936 std::vector< std::vector< IndexType > >
938 std::vector< std::vector< CoordCType > > &lines_color_coords,
939 std::vector< std::vector< IndexType > >
941 std::vector< std::vector< CoordCType > > &face_color_coords,
942 std::vector< std::vector< std::vector< double > > >
945 std::vector< std::string > &field_names,
946 bool if_unstructured_grid_then_take_surface =
false)
950 bool is_a_poly_data =
true;
951 vtkSmartPointer< vtkPolyData > poly_data;
952 vtkSmartPointer< vtkUnstructuredGrid > unstructured_grid;
958 vtkSmartPointer< vtkXMLPolyDataReader > reader =
959 vtkSmartPointer< vtkXMLPolyDataReader >::New();
960 reader->SetFileName(file_path.c_str());
963 poly_data = vtkSmartPointer< vtkPolyData >::New();
964 poly_data->DeepCopy(reader->GetOutput());
968 vtkSmartPointer< vtkXMLUnstructuredGridReader > reader =
969 vtkSmartPointer< vtkXMLUnstructuredGridReader >::New();
970 reader->SetFileName(file_path.c_str());
973 if(if_unstructured_grid_then_take_surface)
975 vtkSmartPointer< vtkDataSetSurfaceFilter > surface_filter =
976 vtkSmartPointer< vtkDataSetSurfaceFilter >::New();
977 #if VTK_MAJOR_VERSION <= 5
978 surfaceFilter->SetInput(reader->GetOutput());
980 surface_filter->SetInputData(reader->GetOutput());
982 surface_filter->Update();
984 poly_data = vtkSmartPointer< vtkPolyData >::New();
985 poly_data->DeepCopy(surface_filter->GetOutput());
989 is_a_poly_data =
false;
990 unstructured_grid = vtkSmartPointer< vtkUnstructuredGrid >::New();
991 unstructured_grid->DeepCopy(reader->GetOutput());
998 if(dataset_line.find(
"POLYDATA") != std::string::npos)
1000 vtkSmartPointer< vtkPolyDataReader > reader =
1001 vtkSmartPointer< vtkPolyDataReader >::New();
1002 reader->SetFileName(file_path.c_str());
1005 poly_data = vtkSmartPointer< vtkPolyData >::New();
1006 poly_data->DeepCopy(reader->GetOutput());
1010 if(dataset_line.find(
"UNSTRUCTURED_GRID") != std::string::npos)
1012 vtkSmartPointer< vtkUnstructuredGridReader > reader =
1013 vtkSmartPointer< vtkUnstructuredGridReader >::New();
1014 reader->SetFileName(file_path.c_str());
1017 if(if_unstructured_grid_then_take_surface)
1019 vtkSmartPointer< vtkDataSetSurfaceFilter > surface_filter =
1020 vtkSmartPointer< vtkDataSetSurfaceFilter >::New();
1021 #if VTK_MAJOR_VERSION <= 5
1022 surfaceFilter->SetInput(reader->GetOutput());
1024 surface_filter->SetInputData(reader->GetOutput());
1026 surface_filter->Update();
1028 poly_data = vtkSmartPointer< vtkPolyData >::New();
1029 poly_data->DeepCopy(surface_filter->GetOutput());
1033 is_a_poly_data =
false;
1034 unstructured_grid = vtkSmartPointer< vtkUnstructuredGrid >::New();
1035 unstructured_grid->DeepCopy(reader->GetOutput());
1040 throw std::runtime_error(
1041 "Reader::read_vtk_or_vtp_or_vtu_file -> file dataset type cannot "
1042 "be processed (neither POLYDATA nor UNSTRUCTURED_GRID)");
1048 throw std::runtime_error(
1049 "Reader::read_vtk_or_vtp_or_vtu_file -> file extension is "
1050 "inappropriate (neither .vtk nor .vtp)");
1058 IndexType >(poly_data,
1061 vertex_color_coords,
1072 IndexType >(unstructured_grid,
1075 vertex_color_coords,