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 #ifndef __VTK_WRAP__
16 
17 #include <string>
18 #include "vtkOBJImporter.h"
19 #include "vtkPolyDataAlgorithm.h"
20 #include <memory>
21 #include <vector>
22 #include <map>
23 #include "vtkActor.h"
24 
26 {
29  double amb[3];
30  double diff[3];
31  double spec[3];
32  double map_Kd_scale[3];
33  double map_Kd_offset[3];
34  int illum;
35  double reflect;
36  double refract;
37  double trans;
38  double specularPower;
39  double glossy;
40  double refract_index;
41  const char *GetClassName() {return "vtkOBJImportedMaterial";}
43 };
44 
45 
47 
48 struct vtkOBJImportedPolyDataWithMaterial;
49 
51 {
52 public:
53  static vtkOBJPolyDataProcessor *New();
55  void PrintSelf(ostream& os, vtkIndent indent) override;
56 
57  // Description:
58  // Specify file name of Wavefront .obj file.
59  void SetFileName(const char* arg)
60  {
61  if (arg == nullptr)
62  {
63  return;
64  }
65  if (!strcmp(this->FileName.c_str(), arg))
66  {
67  return;
68  }
69  FileName = std::string(arg);
70  }
71  void SetMTLfileName( const char* arg )
72  {
73  if (arg == nullptr)
74  {
75  return;
76  }
77  if (!strcmp(this->MTLFileName.c_str(), arg))
78  {
79  return;
80  }
81  MTLFileName = std::string(arg);
82  this->DefaultMTLFileName = false;
83  }
84  void SetTexturePath( const char* arg )
85  {
86  TexturePath = std::string(arg);
87  if(TexturePath.empty())
88  return;
89 #if defined(_WIN32)
90  const char sep = '\\';
91 #else
92  const char sep = '/';
93 #endif
94  if(TexturePath.at(TexturePath.size()-1) != sep )
95  TexturePath += sep;
96  }
97  const std::string& GetTexturePath( ) const
98  {
99  return TexturePath;
100  }
101 
102  const std::string& GetFileName( ) const
103  {
104  return FileName;
105  }
106 
107  const std::string& GetMTLFileName( ) const
108  {
109  return MTLFileName;
110  }
111 
112  vtkSetMacro(VertexScale,double)
113  vtkGetMacro(VertexScale,double)
114  vtkGetMacro(SuccessParsingFiles,int)
115 
116  virtual vtkPolyData* GetOutput(int idx);
117 
118  vtkOBJImportedMaterial* GetMaterial(int k);
119 
120  std::string GetTextureFilename( int idx ); // return string by index
121 
122  double VertexScale; // scale vertices by this during import
123 
124  std::vector<vtkOBJImportedMaterial*> parsedMTLs;
125  std::map<std::string,vtkOBJImportedMaterial*> mtlName_to_mtlData;
126 
127  // our internal parsing/storage
128  std::vector<vtkOBJImportedPolyDataWithMaterial*> poly_list;
129 
130  // what gets returned to client code via GetOutput()
131  std::vector<vtkSmartPointer<vtkPolyData> > outVector_of_vtkPolyData;
132 
133  std::vector<vtkSmartPointer<vtkActor> > actor_list;
135 
136  std::vector<vtkOBJImportedMaterial*> ParseOBJandMTL(std::string filename,int& result_code);
137 
138  void ReadVertices(bool gotFirstUseMaterialTag, char *pLine, float xyz, int lineNr, const double v_scale, bool everything_ok, vtkPoints* points, const bool use_scale);
139 protected:
141  ~vtkOBJPolyDataProcessor() override;
142  int RequestData(vtkInformation *,
143  vtkInformationVector **, vtkInformationVector *) override /*override*/;
144 
145  vtkSetMacro(SuccessParsingFiles,int)
146 
147  std::string FileName; // filename (.obj) being read
148  std::string MTLFileName; // associated .mtl to *.obj, typically it is *.obj.mtl
149  bool DefaultMTLFileName; // tells whether default of *.obj.mtl to be used
150  std::string TexturePath;
151  int SuccessParsingFiles;
152 
153 private:
155  void operator=(const vtkOBJPolyDataProcessor&) = delete;
156 };
157 
158 class vtkRenderWindow;
159 class vtkRenderer;
160 void bindTexturedPolydataToRenderWindow( vtkRenderWindow* renderWindow,
161  vtkRenderer* renderer,
162  vtkOBJPolyDataProcessor* reader );
163 
164 #endif
165 #endif
166 // VTK-HeaderTest-Exclude: vtkOBJImporterInternals.h
void SetMTLfileName(const char *arg)
Store vtkAlgorithm input/output information.
std::vector< vtkOBJImportedPolyDataWithMaterial * > poly_list
abstract specification for renderers
Definition: vtkRenderer.h:63
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
void bindTexturedPolydataToRenderWindow(vtkRenderWindow *renderWindow, vtkRenderer *renderer, vtkOBJPolyDataProcessor *reader)
const std::string & GetMTLFileName() const
const std::string & GetFileName() const
Superclass for algorithms that produce only polydata as output.
a simple class to control print indentation
Definition: vtkIndent.h:39
std::vector< vtkOBJImportedMaterial * > parsedMTLs
std::vector< vtkSmartPointer< vtkActor > > actor_list
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)
represent and manipulate 3D points
Definition: vtkPoints.h:39