vtk_to_dxf_exporter.cpp
Go to the documentation of this file.
00001 /*
00002  *  Load and export a VTK 3D point cloud
00003  *  Copywrong (K) 2010 Z.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  *
00019  * $Id: VTKExporter.cc,v 1.0 2010/02/23 12:00:00 zoli Exp $
00020  */
00021 
00022 
00023 #include <iostream>
00024 #include <string>
00025 #include <vector>
00026 #include <math.h>
00027 
00028 //terminal_tools includes
00029 #include <terminal_tools/print.h>
00030 #include <terminal_tools/parse.h>
00031 
00032 //local includes
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   // Parse the command line arguments for .vtk or .ply files
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   // Loading VTK file
00064   vtkPolyData* data = reinterpret_cast<vtkPolyData*>(load_poly_data_as_data_set(argv[p_file_indices_vtk.at (0)]));
00065   //vtkDataSet* data = LoadAsDataSet (argv[pFileIndicesVTK.at(0)]);
00066 
00067   /*vtkPolyDataReader* reader = vtkPolyDataReader::New ();
00068   reader->SetFileName (argv [pFileIndicesVTK.at (0)]);
00069   reader->Update ();
00070   vtkPolyData* data = reader->GetOutput ();*/
00071   data->Update ();
00072 
00073   // Print info
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   // Init mesh
00079   Mesh_t mesh;
00080   //mesh.resize (data->GetNumberOfPolys ());
00081 
00082   // Creating mesh
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; // only first polygon in the pair is used
00092       polypair.first.resize (npts);
00093       // Get the points of the polygon
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   // Writing DXF file
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 /* ]--- */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


pcl_vtk_tools
Author(s): Nico Blodow, Zoltan-Csaba Marton, Dejan Pangercic
autogenerated on Thu May 23 2013 17:19:40