VTK
vtkOBJImporterInternals.h
Go to the documentation of this file.
1 /*=========================================================================
2  Program: Visualization Toolkit
3  Module: vtkOBJImporterInternals.h
4  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
5  All rights reserved.
6  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
7 
8  This software is distributed WITHOUT ANY WARRANTY; without even
9  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10  PURPOSE. See the above copyright notice for more information.
11 =========================================================================*/
12 
13 #ifndef vtkOBJImporterInternals_h
14 #define vtkOBJImporterInternals_h
15 
16 #include <string>
17 #include "vtkOBJImporter.h"
18 #include "vtkPolyDataAlgorithm.h"
19 #include <memory>
20 #include <vector>
21 #include <map>
22 #include "vtkActor.h"
23 
24 const int OBJ_FILENAME_LENGTH = 8192;
25 const int MATERIAL_NAME_SIZE = 8192;
26 
28 {
29  char name[MATERIAL_NAME_SIZE]; // use std::array<char,N> when got {gcc4.7+,vs2012+}
31  double amb[3];
32  double diff[3];
33  double spec[3];
34  double reflect;
35  double refract;
36  double trans;
37  double shiny;
38  double glossy;
39  double refract_index;
40  double get_amb_coeff()
41  {
42  return sqrt( amb[0]*amb[0]+amb[1]*amb[1]+amb[2]*amb[2] );
43  }
44  double get_diff_coeff()
45  {
46  return sqrt( diff[0]*diff[0]+diff[1]*diff[1]+diff[2]*diff[2] );
47  }
48  double get_spec_coeff()
49  {
50  return sqrt( spec[0]*spec[0]+spec[1]*spec[1]+spec[2]*spec[2] );
51  }
52  const char *GetClassName() {return "vtkOBJImportedMaterial";}
54 };
55 
56 
58 
59 struct vtkOBJImportedPolyDataWithMaterial;
60 
62 {
63 public:
64  static vtkOBJPolyDataProcessor *New();
66  virtual void PrintSelf(ostream& os, vtkIndent indent);
67 
68  // Description:
69  // Specify file name of Wavefront .obj file.
70  void SetFileName(const char* arg)
71  { // by default assume prefix.obj => prefix.obj.mtl
72  FileName = std::string(arg);
73  MTLFileName = FileName + ".mtl";
74  }
75  void SetMTLfileName( const char* arg )
76  {
77  MTLFileName = std::string(arg);
78  }
79  void SetTexturePath( const char* arg )
80  {
81  TexturePath = std::string(arg);
82  if(TexturePath.empty())
83  return;
84  char sep = '/';
85 #if defined(_WIN32)
86  sep = '\\';
87 #endif
88  if(TexturePath.at(TexturePath.size()-1) != sep )
89  TexturePath += sep;
90  }
91  const std::string& GetTexturePath( ) const
92  {
93  return TexturePath;
94  }
95 
96  const std::string& GetFileName( ) const
97  {
98  return FileName;
99  }
100 
101  const std::string& GetMTLFileName( ) const
102  {
103  return MTLFileName;
104  }
105 
106  vtkSetMacro(VertexScale,double)
107  vtkGetMacro(VertexScale,double)
108  vtkGetMacro(SuccessParsingFiles,int)
109 
110  virtual vtkPolyData* GetOutput(int idx);
111 
113 
114  std::string GetTextureFilename( int idx ); // return string by index
115 
116  double VertexScale; // scale vertices by this during import
117 
119 
120  // our internal parsing/storage
121  std::vector<vtkOBJImportedPolyDataWithMaterial*> poly_list;
122 
123  // what gets returned to client code via GetOutput()
125 
127 
130 
131  std::vector<vtkOBJImportedMaterial*> ParseOBJandMTL(std::string filename,int& result_code);
132 
133  void ReadVertices(bool gotFirstUseMaterialTag, char *pLine, float xyz, int lineNr, const double v_scale, bool everything_ok, vtkPoints* points, const bool use_scale);
134 protected:
136  ~vtkOBJPolyDataProcessor();
138  vtkInformationVector **, vtkInformationVector *) /*override*/;
139 
140  vtkSetMacro(SuccessParsingFiles,int)
141 
142  std::string FileName; // filename (.obj) being read
143  std::string MTLFileName; // associated .mtl to *.obj, typically it is *.obj.mtl
144  std::string TexturePath;
145  int SuccessParsingFiles;
146 
147 private:
148  vtkOBJPolyDataProcessor(const vtkOBJPolyDataProcessor&); // Not implemented.
149  void operator=(const vtkOBJPolyDataProcessor&); // Not implemented.
150 };
151 
152 class vtkRenderWindow;
153 class vtkRenderer;
154 void bindTexturedPolydataToRenderWindow( vtkRenderWindow* renderWindow,
155  vtkRenderer* renderer,
156  vtkOBJPolyDataProcessor* reader );
157 
158 #endif
159 // VTK-HeaderTest-Exclude: vtkOBJImporterInternals.h
void SetMTLfileName(const char *arg)
represents an object (geometry & properties) in a rendered scene
Definition: vtkActor.h:50
Store vtkAlgorithm input/output information.
const int MATERIAL_NAME_SIZE
const int OBJ_FILENAME_LENGTH
char texture_filename[OBJ_FILENAME_LENGTH]
std::vector< vtkOBJImportedPolyDataWithMaterial * > poly_list
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
abstract specification for renderers
Definition: vtkRenderer.h:63
Hold a reference to a vtkObjectBase instance.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:83
void bindTexturedPolydataToRenderWindow(vtkRenderWindow *renderWindow, vtkRenderer *renderer, vtkOBJPolyDataProcessor *reader)
const std::string & GetMTLFileName() const
std::vector< vtkOBJImportedMaterial * > ParseOBJandMTL(std::string filename, int &result_code)
const std::string & GetFileName() const
std::string GetTextureFilename(int idx)
vtkOBJImportedMaterial * GetMaterial(int k)
Superclass for algorithms that produce only polydata as output.
void SetFileName(const char *arg)
a simple class to control print indentation
Definition: vtkIndent.h:38
std::vector< std::string > outVector_of_textureFilnames
std::vector< vtkSmartPointer< vtkActor > > actor_list
virtual void PrintSelf(ostream &os, vtkIndent indent)
std::map< std::string, vtkOBJImportedMaterial * > mtlName_to_mtlData
create a window for renderers to draw into
const std::string & GetTexturePath() const
void SetTexturePath(const char *arg)
Store zero or more vtkInformation instances.
std::vector< vtkSmartPointer< vtkPolyData > > outVector_of_vtkPolyData
void obj_set_material_defaults(vtkOBJImportedMaterial *mtl)
static vtkOBJPolyDataProcessor * New()
void ReadVertices(bool gotFirstUseMaterialTag, char *pLine, float xyz, int lineNr, const double v_scale, bool everything_ok, vtkPoints *points, const bool use_scale)
vtkPolyData * GetOutput()
represent and manipulate 3D points
Definition: vtkPoints.h:38
char name[MATERIAL_NAME_SIZE]