13 std::vector<std::vector<vtkVector3d> > polygon_point_list;
20 std::string node_name(
"layer");
24 YAML::Exception yaml_exception(YAML::Mark(),
"Cannot parse " + node_name +
" node");
30 for (
auto iterator_node : layer_node)
34 std::string node_name(
"polygon");
36 if (!iterator_node[node_name])
38 YAML::Exception iterator_node_exception(YAML::Mark(),
"Cannot parse " + node_name +
" node");
39 throw iterator_node_exception;
41 std::vector<vtkVector3d> polygon;
45 for (
auto point_node : polygon_node)
47 std::vector<double> point_values;
49 vtkVector3d point(point_values[0], point_values[1], point_values[2]);
50 polygon.push_back(point);
52 polygon_point_list.push_back(polygon);
56 catch (
const YAML::Exception &e)
58 std::cerr <<
"Problem occurred during parsing YAML file, problem is:\n" << e.msg << endl <<
59 "File name = " << yaml_file << std::endl;
63 vtkSmartPointer<vtkCellArray> polygon_array = vtkSmartPointer<vtkCellArray>::New();
64 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
65 for (
auto polygon_iterator : polygon_point_list)
68 vtkSmartPointer<vtkPolygon> polygon = vtkSmartPointer<vtkPolygon>::New();
69 for (
auto point_iterator : polygon_iterator)
71 polygon->GetPointIds()->InsertNextId(points->GetNumberOfPoints());
72 points->InsertNextPoint(point_iterator.GetData());
74 polygon_array->InsertNextCell(polygon);
77 poly_data->SetPolys(polygon_array);
78 poly_data->SetPoints(points);
85 vtkIdType n_cells = poly_data->GetNumberOfCells();
88 std::cerr <<
"polydataToYamlFile: the polydata is empty" << std::endl;
93 std::ofstream yaml_file_ofstream;
94 yaml_file_ofstream.open(yaml_file);
95 yaml_file_ofstream <<
"---\n" 98 for (vtkIdType cell_id(0); cell_id < n_cells; ++cell_id)
100 vtkIdType n_points = poly_data->GetCell(cell_id)->GetNumberOfPoints();
103 std::cerr <<
"polydataToYamlFile: the polygon " << cell_id <<
" in polydata is empty" << std::endl;
106 yaml_file_ofstream <<
" -\n" 108 for (vtkIdType point_id(0); point_id < n_points; ++point_id)
110 poly_data->GetCell(cell_id)->GetPoints()->GetPoint(point_id, p);
111 yaml_file_ofstream <<
" - point: [" << p[0] <<
", " << p[1] <<
", " << p[2] <<
"]\n";
115 yaml_file_ofstream <<
"---\n";
116 yaml_file_ofstream <<
"\n";
117 yaml_file_ofstream.close();
118 std::cout <<
"File " << yaml_file <<
" was written on the disk" << std::endl;
static bool yamlFileToPolydata(const std::string yaml_file, Polygon poly_data)
bool parseVectorD(const YAML::Node &node, char const *var_name, std::vector< double > &var_value)
const YAML::Node parseNode(const YAML::Node &node, char const *var_name)
vtkSmartPointer< vtkPolyData > Polygon
bool yamlNodeFromFileName(std::string filename, YAML::Node &ynode)
static bool polydataToYamlFile(const std::string yaml_file, const Polygon poly_data)