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 #include <iostream>
00022 #include <string>
00023 #include <vector>
00024 #include <math.h>
00025 
00026 
00027 
00028 
00029 
00030 #include <vtkRenderer.h>
00031 #include <vtkRenderWindow.h>
00032 
00033 #include <vtkIVExporter.h>
00034 
00035 #include <vtkOOGLExporter.h>
00036 #include <vtkRIBExporter.h>
00037 
00038 #include <vtkIVExporter.h>
00039 #include <vtkOBJExporter.h>
00040 #include <vtkX3DExporter.h>
00041 
00042 #include <vtkVRMLExporter.h>
00043 
00044 
00045 
00046 
00047 
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   
00085 
00086 
00087 
00088 
00089 
00090 
00091 
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   
00098   vtkPolyData* data = reinterpret_cast<vtkPolyData*>(load_poly_data_as_data_set(argv[p_file_indices_vtk.at (0)]));
00099   data->Update ();
00100 
00101   
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   
00107   vtkRenderer* ren = vtkRenderer::New ();
00108   
00109 
00110   
00111   ren->AddActor (create_actor_from_data_set(data, 0.0, 0.0, 0.0));
00112   
00113   
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   
00122   vector<vtkExporter*> exporters;
00123   vector<char*> filenames;
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
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 
00154 
00155 
00156 
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 
00168 
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 
00182   
00183   for (unsigned i = 0; i < exporters.size (); i++)
00184     {
00185       print_info (stderr, "Writing to "); print_value (stderr, "%s\n", filenames[i]);
00186       
00187       exporters[i]->SetInput (renWin);
00188       exporters[i]->Write ();
00189     }
00190   fprintf (stderr, "[done]\n");
00191 }
00192