vtk_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 #include <iostream>
00022 #include <string>
00023 #include <vector>
00024 #include <math.h>
00025 
00026 //#include "../common/CommonVTKRoutines.h"
00027 //#include "../common/CommonTerminalRoutines.h"
00028 //#include "../common/CommonANNRoutines.h"
00029 
00030 #include <vtkRenderer.h>
00031 #include <vtkRenderWindow.h>
00032 
00033 #include <vtkIVExporter.h>
00034 //#include <vtkGL2PSExporter.h>
00035 #include <vtkOOGLExporter.h>
00036 #include <vtkRIBExporter.h>
00037 //#include <vtkPOVExporter.h>
00038 #include <vtkIVExporter.h>
00039 #include <vtkOBJExporter.h>
00040 #include <vtkX3DExporter.h>
00041 
00042 #include <vtkVRMLExporter.h>
00043 
00044 //pcl_visualizer includes
00045 //#include <pcl_visualization/pcl_visualizer.h>
00046 
00047 //terminal_tools includes
00048 #include <terminal_tools/print.h>
00049 #include <terminal_tools/parse.h>
00050 
00051 #include <pcl_vtk_tools/misc.h>
00052 
00053 using namespace std;
00054 using terminal_tools::print_color;
00055 using terminal_tools::print_error;
00056 using terminal_tools::print_error;
00057 using terminal_tools::print_warn;
00058 using terminal_tools::print_info;
00059 using terminal_tools::print_debug;
00060 using terminal_tools::print_value;
00061 using terminal_tools::print_highlight;
00062 using terminal_tools::TT_BRIGHT;
00063 using terminal_tools::TT_RED;
00064 using terminal_tools::TT_GREEN;
00065 using terminal_tools::TT_BLUE;
00066 
00067 #define RENWIN_WIDTH 1200
00068 #define RENWIN_HEIGHT 800
00069 
00070 /* ---[ */
00071 int
00072   main (int argc, char** argv)
00073 {
00074   if (argc < 2)
00075   {
00076     print_error (stderr, "Syntax is: %s input.vtk [output.extension1...N]\n", argv[0]);
00077     fprintf (stderr, "  where the VTK file will be saved in files with the specified extensions\n");
00078     fprintf (stderr, "  supported extensions are: OBJ*, VRML, X3D, IV, RIB*, OOGL\n");
00079     fprintf (stderr, "  * multiple files are produced, please see corresponding documantation\n");
00080     fprintf (stderr, "  (OBJ is easy to check and works with blender - you can use that to convert it)\n");
00081     return (-1);
00082   }
00083   
00084   // Parse the command line arguments for .vtk or .ply files
00085 //   vector<int> pFileIndicesVRML = ParseFileExtensionArgument (argc, argv, ".wrl");
00086 //   vector<int> pFileIndicesX3D = ParseFileExtensionArgument (argc, argv, ".x3d");
00087 //   vector<int> pFileIndicesOBJ = ParseFileExtensionArgument (argc, argv, ".obj");
00088 //   //vector<int> pFileIndicesPOV = ParseFileExtensionArgument (argc, argv, ".pov");
00089 //   vector<int> pFileIndicesRIB = ParseFileExtensionArgument (argc, argv, ".rib");
00090 //   vector<int> pFileIndicesOOGL = ParseFileExtensionArgument (argc, argv, ".oogl");
00091 //   //vector<int> pFileIndicesGL2PS = ParseFileExtensionArgument (argc, argv, ".gl2ps");
00092 
00093   vector<int> p_file_indices_vtk = terminal_tools::parse_file_extension_argument (argc, argv, ".vtk");
00094   vector<int> p_file_indices_iv = terminal_tools::parse_file_extension_argument (argc, argv, ".iv");
00095   
00096   
00097   // Loading VTK file
00098   vtkPolyData* data = reinterpret_cast<vtkPolyData*>(load_poly_data_as_data_set(argv[p_file_indices_vtk.at (0)]));
00099   data->Update ();
00100 
00101   // Print info
00102   print_info (stderr, "Loaded "); print_value (stderr, "%s", argv [p_file_indices_vtk.at (0)]);
00103   fprintf (stderr, " with "); print_value (stderr, "%d", data->GetNumberOfPoints ()); fprintf (stderr, " points and ");
00104   print_value (stderr, "%d", data->GetNumberOfPoints ()); fprintf (stderr, " polygons.\n");
00105 
00106   // Create Renderer
00107   vtkRenderer* ren = vtkRenderer::New ();
00108   //ren->AutomaticLightCreationOff ();
00109 
00110   // Create an actor for the data and add it to the renderer
00111   ren->AddActor (create_actor_from_data_set(data, 0.0, 0.0, 0.0));
00112   
00113   // Create the VTK window
00114   char title[256];
00115   sprintf (title, "VTK exporter");
00116   vtkRenderWindow *renWin = vtkRenderWindow::New ();
00117   renWin->SetWindowName (title);
00118   renWin->AddRenderer (ren);
00119   renWin->SetSize (RENWIN_WIDTH, RENWIN_HEIGHT);
00120 
00121   // Create exporter
00122   vector<vtkExporter*> exporters;
00123   vector<char*> filenames;
00124 
00125 //   if (pFileIndicesVRML.size () > 0)
00126 //   {
00127 //     vtkVRMLExporter* exporter = vtkVRMLExporter::New ();
00128 //     exporter->SetFileName (argv [pFileIndicesVRML.at (0)]);
00129 //     filenames.push_back (argv [pFileIndicesVRML.at (0)]);
00130 //     exporters.push_back (exporter);
00131 //   }
00132 //   if (pFileIndicesX3D.size () > 0)
00133 //   {
00134 //     vtkX3DExporter* exporter = vtkX3DExporter::New ();
00135 //     exporter->SetFileName (argv [pFileIndicesX3D.at (0)]);
00136 //     filenames.push_back (argv [pFileIndicesX3D.at (0)]);
00137 //     exporters.push_back (exporter);
00138 //   }
00139 //   if (pFileIndicesOBJ.size () > 0)
00140 //   {
00141 //     vtkOBJExporter* exporter = vtkOBJExporter::New ();
00142 //     exporter->SetFilePrefix (argv [pFileIndicesOBJ.at (0)]);
00143 //     filenames.push_back (argv [pFileIndicesOBJ.at (0)]);
00144 //     exporters.push_back (exporter);
00145 //   }
00146   if (p_file_indices_iv.size () > 0)
00147     {
00148       vtkIVExporter* exporter = vtkIVExporter::New ();
00149       exporter->SetFileName (argv [p_file_indices_iv.at (0)]);
00150       filenames.push_back (argv [p_file_indices_iv.at (0)]);
00151       exporters.push_back (exporter);
00152     }
00153 //   /*if (pFileIndicesPOV.size () > 0)
00154 //   {
00155 //     vtkPOVExporter* exporter = vtkPOVExporter::New ();
00156 //     exporter->SetFileName (argv [pFileIndicesPOV.at (0)]);
00157 //     filenames.push_back (argv [pFileIndicesPOV.at (0)]);
00158 //     exporters.push_back (exporter);
00159 //   }*/
00160 //   if (pFileIndicesRIB.size () > 0)
00161 //   {
00162 //     vtkRIBExporter* exporter = vtkRIBExporter::New ();
00163 //     exporter->SetFilePrefix (argv [pFileIndicesRIB.at (0)]);
00164 //     filenames.push_back (argv [pFileIndicesRIB.at (0)]);
00165 //     exporters.push_back (exporter);
00166 //   }
00167 //   if (pFileIndicesOOGL.size () > 0)
00168 //   {
00169 //     vtkOOGLExporter* exporter = vtkOOGLExporter::New ();
00170 //     exporter->SetFileName (argv [pFileIndicesOOGL.at (0)]);
00171 //     filenames.push_back (argv [pFileIndicesOOGL.at (0)]);
00172 //     exporters.push_back (exporter);
00173 //   }
00174 //   /*if (pFileIndicesGL2PS.size () > 0)
00175 //   {
00176 //     vtkGL2PSExporter* exporter = vtkGL2PSExporter::New ();
00177 //     exporter->SetFilePrefix (argv [pFileIndicesGL2PS.at (0)]);
00178 //     filenames.push_back (argv [pFileIndicesGL2PS.at (0)]);
00179 //     exporters.push_back (exporter);
00180 //   }*/
00181 
00182   // Saving
00183   for (unsigned i = 0; i < exporters.size (); i++)
00184     {
00185       print_info (stderr, "Writing to "); print_value (stderr, "%s\n", filenames[i]);
00186       //exporter->SetInput (iren->getRenderWindow ());
00187       exporters[i]->SetInput (renWin);
00188       exporters[i]->Write ();
00189     }
00190   fprintf (stderr, "[done]\n");
00191 }
00192 /* ]--- */
 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