Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #include <iostream>
00024 #include <string>
00025 #include <vector>
00026 #include <math.h>
00027 
00028 
00029 #include <terminal_tools/print.h>
00030 #include <terminal_tools/parse.h>
00031 
00032 
00033 #include "pcl_vtk_tools/misc.h"
00034 #include "pcl_vtk_tools/dxf_writer.h"
00035 
00036 using namespace std;
00037 using terminal_tools::print_color;
00038 using terminal_tools::print_error;
00039 using terminal_tools::print_warn;
00040 using terminal_tools::print_info;
00041 using terminal_tools::print_debug;
00042 using terminal_tools::print_value;
00043 using terminal_tools::print_highlight;
00044 using terminal_tools::TT_BRIGHT;
00045 using terminal_tools::TT_RED;
00046 using terminal_tools::TT_GREEN;
00047 using terminal_tools::TT_BLUE;
00048 
00049 
00050 int
00051   main (int argc, char** argv)
00052 {
00053   if (argc < 2)
00054   {
00055     print_error (stderr, "Syntax is: %s input.vtk output.dxf\n", argv[0]);
00056     return (-1);
00057   }
00058   
00059   
00060   vector<int> p_file_indices_vtk = terminal_tools::parse_file_extension_argument (argc, argv, ".vtk");
00061   vector<int> p_file_indices_dxf = terminal_tools::parse_file_extension_argument (argc, argv, ".dxf");
00062 
00063   
00064   vtkPolyData* data = reinterpret_cast<vtkPolyData*>(load_poly_data_as_data_set(argv[p_file_indices_vtk.at (0)]));
00065   
00066 
00067   
00068 
00069 
00070 
00071   data->Update ();
00072 
00073   
00074   print_info (stderr, "Loaded "); print_value (stderr, "%s", argv [p_file_indices_vtk.at (0)]);
00075   fprintf (stderr, " with "); print_value (stderr, "%d", data->GetNumberOfPoints ()); fprintf (stderr, " points and ");
00076   print_value (stderr, "%d", data->GetNumberOfPoints ()); fprintf (stderr, " polygons.\n");
00077   
00078   
00079   Mesh_t mesh;
00080   
00081 
00082   
00083   vtkPoints *points = data->GetPoints ();
00084   vtkCellArray* polys = data->GetPolys ();
00085   vtkIdType npts, *pts;
00086   int n = 0;
00087   while (polys->GetNextCell (npts, pts))
00088   {
00089     if (npts == 3 || npts == 4)
00090     {
00091       std::pair<Polygon_t, Polygon_t> polypair; 
00092       polypair.first.resize (npts);
00093       
00094       for (int i = 0; i < npts; i++)
00095       {
00096         double p[3];
00097         points->GetPoint (pts[i], p);
00098         polypair.first[i].x = p[0];
00099         polypair.first[i].y = p[1];
00100         polypair.first[i].z = p[2];
00101       }
00102       mesh.push_back (polypair);
00103     }
00104     else
00105       print_warn (stderr, "Skipping cell as it has %d points, and DXF writer can handle only 3 or 4\n", n, npts);
00106     
00107   }
00108 
00109   
00110   print_info (stderr, "Writing "); print_value (stderr, "%d", mesh.size ());
00111   fprintf (stderr, " polygons to "); print_value (stderr, "%s\n", argv [p_file_indices_dxf.at (0)]);
00112   dxfwriter::WriteMesh (mesh, argv [p_file_indices_dxf.at (0)]);
00113   fprintf (stderr, "[done]\n");
00114 }
00115